Update types for better extension

This commit is contained in:
daleclack 2022-05-04 13:10:14 +08:00
parent 5f5650169c
commit a90a9cec4f
2 changed files with 24 additions and 6 deletions

View File

@ -63,7 +63,7 @@ Drawing::Drawing()
drag->set_button(GDK_BUTTON_PRIMARY); drag->set_button(GDK_BUTTON_PRIMARY);
drag->signal_drag_begin().connect(sigc::mem_fun(*this, &Drawing::drag_begin)); 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_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 // Create a Surface
surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 480); surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 600, 480);
@ -106,7 +106,7 @@ bool Drawing::draw_event(const Cairo::RefPtr<Cairo::Context> &context)
return true; 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(); double size = scale.get_value();
auto cr = Cairo::Context::create(surface); 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); cr->set_line_width(size * 2);
// Use Line for main drawing // Use Line for main drawing
if (begin) if (process == DrawProcess::Begin)
{ {
x1 = x; x1 = x;
y1 = y; y1 = y;
@ -142,6 +142,7 @@ void Drawing::draw_brush(double x, double y, bool begin)
cr.clear(); cr.clear();
break; break;
case DrawMode::Line: case DrawMode::Line:
break; break;
} }
draw_area.queue_draw(); draw_area.queue_draw();
@ -165,7 +166,7 @@ void Drawing::drag_begin(double x, double y)
// The Begin // The Begin
start_x = x; start_x = x;
start_y = y; start_y = y;
draw_brush(x, y, true); draw_brush(x, y, DrawProcess::Begin);
} }
void Drawing::drag_progress(double x, double y) 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); 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() void Drawing::color_set()
{ {
m_color = color_btn.get_rgba(); m_color = color_btn.get_rgba();

View File

@ -2,9 +2,19 @@
#include <gtkmm.h> #include <gtkmm.h>
// 4 Draw modes: default(free draw), circle, line, rectangle
enum class DrawMode{ enum class DrawMode{
Default, 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 class Drawing : public Gtk::Window
@ -33,7 +43,7 @@ class Drawing : public Gtk::Window
// Signal Handlers // Signal Handlers
bool draw_event(const Cairo::RefPtr<Cairo::Context> &context); bool draw_event(const Cairo::RefPtr<Cairo::Context> &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(); void button_press();
@ -41,6 +51,8 @@ class Drawing : public Gtk::Window
void drag_progress(double x, double y); void drag_progress(double x, double y);
void drag_end(double x, double y);
void color_set(); void color_set();
public: public: