TachyonUI 1.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_clipboard.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <string_view>
6#include <vector>
7
8namespace tachyon
9{
12
16 {
17 uint32_t width = 0;
18 uint32_t height = 0;
19 std::vector<uint8_t> rgba;
20
22 bool Empty() const { return width == 0 || height == 0 || rgba.size() != size_t(width) * height * 4; }
23 };
24
29 {
30 public:
31 virtual ~IClipboard() = default;
32
34 virtual std::string Get() const = 0;
36 virtual void Set(std::string_view text) = 0;
37
39 virtual bool HasImage() const { return false; }
41 virtual ClipboardImage GetImage() const { return {}; }
44 virtual bool SetImage(const ClipboardImage& image) { (void)image; return false; }
45 };
46
48 class LocalClipboard final : public IClipboard
49 {
50 public:
51 std::string Get() const override { return m_text; }
52 void Set(std::string_view text) override { m_text = text; m_image = {}; }
53
54 bool HasImage() const override { return !m_image.Empty(); }
55 ClipboardImage GetImage() const override { return m_image; }
56 bool SetImage(const ClipboardImage& image) override
57 {
58 if (image.Empty())
59 return false;
60 m_image = image;
61 m_text.clear();
62 return true;
63 }
64
65 private:
66 std::string m_text;
67 ClipboardImage m_image;
68 };
69
70}
The clipboard text editors copy to and paste from, and images go through; GUIApplication::SetClipboar...
Definition gui_clipboard.h:29
virtual ClipboardImage GetImage() const
The clipboard's image; an empty one when it holds none, or it can't be read.
Definition gui_clipboard.h:41
virtual void Set(std::string_view text)=0
Puts UTF-8 text on the clipboard.
virtual std::string Get() const =0
The clipboard's text, UTF-8; empty when it holds none.
virtual ~IClipboard()=default
virtual bool HasImage() const
Whether the clipboard holds an image. A clipboard without images says no.
Definition gui_clipboard.h:39
virtual bool SetImage(const ClipboardImage &image)
Puts an image on the clipboard.
Definition gui_clipboard.h:44
A clipboard inside the process, not shared with other applications.
Definition gui_clipboard.h:49
ClipboardImage GetImage() const override
The clipboard's image; an empty one when it holds none, or it can't be read.
Definition gui_clipboard.h:55
bool SetImage(const ClipboardImage &image) override
Puts an image on the clipboard.
Definition gui_clipboard.h:56
void Set(std::string_view text) override
Puts UTF-8 text on the clipboard.
Definition gui_clipboard.h:52
bool HasImage() const override
Whether the clipboard holds an image. A clipboard without images says no.
Definition gui_clipboard.h:54
std::string Get() const override
The clipboard's text, UTF-8; empty when it holds none.
Definition gui_clipboard.h:51
Definition gui_logging.h:24
An image on the clipboard: RGBA, 8 bits a channel, alpha not premultiplied, rows from the top.
Definition gui_clipboard.h:16
bool Empty() const
No image: no size, or not as many bytes as the size needs.
Definition gui_clipboard.h:22
std::vector< uint8_t > rgba
width * height * 4 bytes
Definition gui_clipboard.h:19
uint32_t height
Definition gui_clipboard.h:18
uint32_t width
Definition gui_clipboard.h:17