MCPcopy Create free account
hub / github.com/VitalAudio/visage / DragDropTarget

Class DragDropTarget

examples/Showcase/examples_frame.cpp:135–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133};
134
135class DragDropTarget : public visage::Frame {
136public:
137 void draw(visage::Canvas& canvas) override {
138 canvas.setColor(DarkBackgroundColor);
139 canvas.roundedRectangle(0, 0, width(), height(), height() / 16);
140
141 canvas.setColor(TextColor);
142
143 const visage::Font font(height() / 4, resources::fonts::Lato_Regular_ttf);
144 if (dragging_)
145 canvas.text("Dragging " + filename_, font, visage::Font::kCenter, 0, 0, width(), height());
146 else if (dropped_)
147 canvas.text("Dropped " + filename_, font, visage::Font::kCenter, 0, 0, width(), height());
148 else
149 canvas.text("Drag destination", font, visage::Font::kCenter, 0, 0, width(), height());
150 }
151
152 bool receivesDragDropFiles() override { return true; }
153 std::string dragDropFileExtensionRegex() override { return ".*"; }
154
155 void dragFilesEnter(const std::vector<std::string>& paths) override {
156 dragging_ = true;
157 dropped_ = false;
158 filename_ = visage::fileName(paths[0]);
159 redraw();
160 }
161
162 void dragFilesExit() override {
163 dragging_ = false;
164 redraw();
165 }
166
167 void dropFiles(const std::vector<std::string>& paths) override {
168 dragging_ = false;
169 dropped_ = true;
170 redraw();
171 }
172
173private:
174 std::string filename_;
175 bool dragging_ = false;
176 bool dropped_ = false;
177};
178
179class DragDropExample : public visage::Frame {
180public:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected