aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2023-01-02 08:10:43 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2023-01-02 08:10:43 +0100
commitf5c83d0609d2fd2030a2339a4a7d75d96fdf1b15 (patch)
tree4daf0f82129cfdb8a97578cfa03dded6e5e08c12
parent31c332da9ab426daa73b68772d0ef9c1b0744a50 (diff)
Simplify editor events processing
-rw-r--r--examples/wxWidgets/main.cpp10
-rw-r--r--src/CGEditor.cpp10
-rw-r--r--src/CGEditor.hpp6
3 files changed, 17 insertions, 9 deletions
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp
index 9d5274a..7d2f59e 100644
--- a/examples/wxWidgets/main.cpp
+++ b/examples/wxWidgets/main.cpp
@@ -71,15 +71,9 @@ private:
Refresh();
}
- // Now handle event
- bool redraw=false;
+ // Now handle generated events from last user inputs
Update();
- for(const cgeditor::Event &e: status.Events){
- HandleEvent(e);
- redraw=true;
- }
- status.Events.clear();
- if(redraw){
+ if(ProcessEvents()){
Refresh();
}
}
diff --git a/src/CGEditor.cpp b/src/CGEditor.cpp
index 737db39..2da0520 100644
--- a/src/CGEditor.cpp
+++ b/src/CGEditor.cpp
@@ -92,4 +92,14 @@ void CGEditor::DrawComponent(Component *c) {
}
}
+bool CGEditor::ProcessEvents(){
+ bool processed=false;
+ for(const cgeditor::Event &e: status.Events){
+ HandleEvent(e);
+ processed=true;
+ }
+ status.Events.clear();
+ return processed;
+}
+
} // namespace cgeditor \ No newline at end of file
diff --git a/src/CGEditor.hpp b/src/CGEditor.hpp
index e463170..e113325 100644
--- a/src/CGEditor.hpp
+++ b/src/CGEditor.hpp
@@ -23,10 +23,14 @@ class CGEditor {
protected:
Status status;
- ///@brief Draw the Chess Game Editor on the canvas using current status
+ /// @brief Draw the Chess Game Editor on the canvas using current status
void Draw();
+ /// @brief Process the events generated during the drawing
+ bool ProcessEvents();
/// @brief Draw an element on the canvas
virtual void DrawElement(const Element &) = 0;
+ /// @brief Handle event that occured during editor drawing
+ virtual void HandleEvent(const Event &) = 0;
public:
CGEditor();