-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split out gui.cpp into separate files
- Loading branch information
Showing
17 changed files
with
462 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/gui/resources/fonts.h |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#include "drag_handler.h" | ||
#include "tasks.h" | ||
|
||
void gui::drag_handler::DragTarget::dragEnter(os::DragEvent& ev) { | ||
// v.dropResult(os::DropOperation::None); // TODO: what does this do? is it needed? | ||
|
||
drag_position = ev.position(); | ||
dragging = true; | ||
} | ||
|
||
void gui::drag_handler::DragTarget::dragLeave(os::DragEvent& ev) { | ||
// todo: not triggering on windows? | ||
drag_position = ev.position(); | ||
dragging = false; | ||
} | ||
|
||
void gui::drag_handler::DragTarget::drag(os::DragEvent& ev) { | ||
drag_position = ev.position(); | ||
} | ||
|
||
void gui::drag_handler::DragTarget::drop(os::DragEvent& ev) { | ||
ev.acceptDrop(true); | ||
|
||
if (ev.dataProvider()->contains(os::DragDataItemType::Paths)) { | ||
std::vector<std::string> paths = ev.dataProvider()->getPaths(); | ||
tasks::add_files(paths); | ||
} | ||
|
||
dragging = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
#pragma once | ||
|
||
namespace gui::drag_handler { | ||
inline bool dragging = false; | ||
inline gfx::Point drag_position; | ||
|
||
class DragTarget : public os::DragTarget { | ||
public: | ||
void dragEnter(os::DragEvent& ev) override; | ||
void dragLeave(os::DragEvent& ev) override; | ||
void drag(os::DragEvent& ev) override; | ||
void drop(os::DragEvent& ev) override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
#include "event_handler.h" | ||
|
||
#include "gui.h" | ||
|
||
#include "ui/keys.h" | ||
|
||
bool gui::event_handler::process_event(const os::Event& ev) { | ||
switch (ev.type()) { | ||
case os::Event::CloseApp: | ||
case os::Event::CloseWindow: { | ||
closing = true; | ||
return false; | ||
} | ||
|
||
case os::Event::ResizeWindow: | ||
break; | ||
|
||
case os::Event::MouseMove: { | ||
keys::on_mouse_move( | ||
ev.position(), | ||
ev.modifiers(), | ||
ev.pointerType(), | ||
ev.pressure() | ||
); | ||
return true; | ||
} | ||
|
||
case os::Event::MouseDown: { | ||
keys::on_mouse_down( | ||
ev.position(), | ||
ev.button(), | ||
ev.modifiers(), | ||
ev.pointerType(), | ||
ev.pressure() | ||
); | ||
return true; | ||
} | ||
|
||
case os::Event::MouseUp: { | ||
keys::on_mouse_up( | ||
ev.position(), | ||
ev.button(), | ||
ev.modifiers(), | ||
ev.pointerType() | ||
); | ||
return true; | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool gui::event_handler::generate_messages_from_os_events(bool rendered_last) { // https://github.com/aseprite/aseprite/blob/45c2a5950445c884f5d732edc02989c3fb6ab1a6/src/ui/manager.cpp#L393 | ||
bool processed_an_event = false; | ||
|
||
double timeout; | ||
if (rendered_last) // an animation is playing or something, so be quick | ||
timeout = 0.0; | ||
else // nothing's happening so take your time - but still be fast enough for the ui to update occasionally to see if it wants to render | ||
timeout = 1.f / 60; | ||
|
||
while (true) { | ||
os::Event event; | ||
|
||
event_queue->getEvent(event, timeout); | ||
|
||
if (event.type() == os::Event::None) | ||
break; | ||
|
||
if (process_event(event)) | ||
processed_an_event = true; | ||
|
||
timeout = 0.0; // i think this is correct, allow blocking for first event but any subsequent one should be instant | ||
} | ||
|
||
return processed_an_event; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#pragma once | ||
|
||
namespace gui::event_handler { | ||
bool process_event(const os::Event& ev); | ||
bool generate_messages_from_os_events(bool rendered_last); | ||
} |
Oops, something went wrong.