aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md10
-rw-r--r--examples/wxWidgets/main.cpp16
-rw-r--r--src/CGEditor.cpp6
-rw-r--r--src/CGEditor.hpp2
4 files changed, 15 insertions, 19 deletions
diff --git a/README.md b/README.md
index fdbac72..2b2772c 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,21 @@
[![license](https://img.shields.io/badge/License-LGPL_v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
# cgeditor: Chess Game Editor
-cgeditor is a dependency-free chess game editor library written in C++. It can be used with any library that provides 2D canvas drawing and mouse inputs features.
+cgeditor is a dependency-free chess game editor library written in C++. It can be used with any library that provides 2D canvas drawing and mouse/keyboard events.
# Features
-- Show move,move number, variations, NAGs, comments etc.
-- *Delete*, *Promote* and *Set as main line* features
+- Show move, move number, variations, NAGs, comments etc.
+- *Delete*, *Promote* and *Set as main line* menu entries
- Handle pieces icons
- Its graphical appareance is entirely customizable
# Architecture
-To run cgeditor you need to extend 2 classes:
+To run cgeditor 2 classes need to be extended:
- CGEditor (To draw and handle events)
- CGEHalfMove (The data structure displayed by the editor)
+See example for more informations.
+
# Example
An example based on *wxWidgets* is available in the `examples/` folder:
![wxWidgets](examples/wxWidgets/demo.gif)
diff --git a/examples/wxWidgets/main.cpp b/examples/wxWidgets/main.cpp
index 35a3100..9d5274a 100644
--- a/examples/wxWidgets/main.cpp
+++ b/examples/wxWidgets/main.cpp
@@ -12,7 +12,6 @@
*/
class MyFrame : public wxFrame, public cgeditor::CGEditor {
wxPaintDC *dc;
- bool NeedRedraw = false;
public:
MyFrame()
@@ -72,10 +71,16 @@ private:
Refresh();
}
- // Should another draw of CGEditor be made?
- if (NeedRedraw) {
+ // Now handle event
+ bool redraw=false;
+ Update();
+ for(const cgeditor::Event &e: status.Events){
+ HandleEvent(e);
+ redraw=true;
+ }
+ status.Events.clear();
+ if(redraw){
Refresh();
- NeedRedraw = false;
}
}
@@ -163,7 +168,6 @@ private:
else if (e.type == cgeditor::Event::Type::Promote) {
str = "Promote";
static_cast<MyHalfMove *>(e.move)->MyHalfMove::Promote();
- NeedRedraw = true;
} else if (e.type == cgeditor::Event::Type::Delete) {
str = "Delete";
if (e.move->Parent != NULL) {
@@ -172,11 +176,9 @@ private:
} else {
CGEditor::status.Moves = NULL;
}
- NeedRedraw = true;
} else if (e.type == cgeditor::Event::Type::SetAsMainline) {
str = "Set as main line";
static_cast<MyHalfMove *>(e.move)->MyHalfMove::SetAsMainline();
- NeedRedraw = true;
} else if (e.type == cgeditor::Event::Type::Goto) {
str = "Goto move";
}
diff --git a/src/CGEditor.cpp b/src/CGEditor.cpp
index 4edf95e..737db39 100644
--- a/src/CGEditor.cpp
+++ b/src/CGEditor.cpp
@@ -40,12 +40,6 @@ void CGEditor::Draw() {
DrawComponent(SBH);
DrawComponent(ME);
- // Handle events
- for (Event &e : status.Events) {
- HandleEvent(e);
- }
- status.Events.clear();
-
// Update mouse events
status.LeftClick = false;
status.RightClick = false;
diff --git a/src/CGEditor.hpp b/src/CGEditor.hpp
index d30d05e..e463170 100644
--- a/src/CGEditor.hpp
+++ b/src/CGEditor.hpp
@@ -27,8 +27,6 @@ protected:
void Draw();
/// @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();