Update types for better extension
This commit is contained in:
parent
5f5650169c
commit
a90a9cec4f
|
@ -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<Cairo::Context> &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();
|
||||
|
|
|
@ -2,9 +2,19 @@
|
|||
|
||||
#include <gtkmm.h>
|
||||
|
||||
// 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<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();
|
||||
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue