From a90a9cec4fef9969d1f3b18832dd6bb1e965ebff Mon Sep 17 00:00:00 2001 From: daleclack Date: Wed, 4 May 2022 13:10:14 +0800 Subject: [PATCH] Update types for better extension --- Gtkmm3/gtk129_drawing2/src/drawing.cc | 14 ++++++++++---- Gtkmm3/gtk129_drawing2/src/drawing.hh | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Gtkmm3/gtk129_drawing2/src/drawing.cc b/Gtkmm3/gtk129_drawing2/src/drawing.cc index 76e66a6..40c448a 100644 --- a/Gtkmm3/gtk129_drawing2/src/drawing.cc +++ b/Gtkmm3/gtk129_drawing2/src/drawing.cc @@ -63,7 +63,7 @@ Drawing::Drawing() drag->set_button(GDK_BUTTON_PRIMARY); drag->signal_drag_begin().connect(sigc::mem_fun(*this, &Drawing::drag_begin)); drag->signal_drag_update().connect(sigc::mem_fun(*this, &Drawing::drag_progress)); - drag->signal_drag_end().connect(sigc::mem_fun(*this, &Drawing::drag_progress)); + drag->signal_drag_end().connect(sigc::mem_fun(*this, &Drawing::drag_end)); // Create a Surface surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 480); @@ -106,7 +106,7 @@ bool Drawing::draw_event(const Cairo::RefPtr &context) return true; } -void Drawing::draw_brush(double x, double y, bool begin) +void Drawing::draw_brush(double x, double y, DrawProcess process) { double size = scale.get_value(); auto cr = Cairo::Context::create(surface); @@ -120,7 +120,7 @@ void Drawing::draw_brush(double x, double y, bool begin) cr->set_line_width(size * 2); // Use Line for main drawing - if (begin) + if (process == DrawProcess::Begin) { x1 = x; y1 = y; @@ -142,6 +142,7 @@ void Drawing::draw_brush(double x, double y, bool begin) cr.clear(); break; case DrawMode::Line: + break; } draw_area.queue_draw(); @@ -165,7 +166,7 @@ void Drawing::drag_begin(double x, double y) // The Begin start_x = x; start_y = y; - draw_brush(x, y, true); + draw_brush(x, y, DrawProcess::Begin); } void Drawing::drag_progress(double x, double y) @@ -174,6 +175,11 @@ void Drawing::drag_progress(double x, double y) draw_brush(x + start_x, y + start_y); } +void Drawing::drag_end(double x, double y){ + // Progress and end + draw_brush(x + start_x, y + start_y); +} + void Drawing::color_set() { m_color = color_btn.get_rgba(); diff --git a/Gtkmm3/gtk129_drawing2/src/drawing.hh b/Gtkmm3/gtk129_drawing2/src/drawing.hh index fa053c4..e0043f5 100644 --- a/Gtkmm3/gtk129_drawing2/src/drawing.hh +++ b/Gtkmm3/gtk129_drawing2/src/drawing.hh @@ -2,9 +2,19 @@ #include +// 4 Draw modes: default(free draw), circle, line, rectangle enum class DrawMode{ Default, - Line + Circle, + Line, + Rectangle +}; + +// Flage for process of drawing +enum class DrawProcess{ + Begin, // The beginning of draw + Update, // The Process(Position update) + End // The end of draw }; class Drawing : public Gtk::Window @@ -33,7 +43,7 @@ class Drawing : public Gtk::Window // Signal Handlers bool draw_event(const Cairo::RefPtr &context); - void draw_brush(double x, double y, bool begin = false); + void draw_brush(double x, double y, DrawProcess process = DrawProcess::Update); void button_press(); @@ -41,6 +51,8 @@ class Drawing : public Gtk::Window void drag_progress(double x, double y); + void drag_end(double x, double y); + void color_set(); public: