1 /* === S Y N F I G ========================================================= */
2 /*! \file state_stroke.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include <gtkmm/dialog.h>
34 #include <gtkmm/entry.h>
36 #include <synfig/valuenode_dynamiclist.h>
38 #include "state_stroke.h"
39 #include "canvasview.h"
42 #include <synfig/valuenode_bline.h>
43 #include <ETL/hermite>
44 #include <ETL/calculus>
46 #include "event_mouse.h"
47 #include "event_layerclick.h"
49 #include <synfigapp/main.h>
55 /* === U S I N G =========================================================== */
59 using namespace synfig;
60 using namespace studio;
62 /* === M A C R O S ========================================================= */
64 /* === G L O B A L S ======================================================= */
66 StateStroke studio::state_stroke;
68 /* === C L A S S E S & S T R U C T S ======================================= */
70 class studio::StateStroke_Context : public sigc::trackable
72 etl::handle<CanvasView> canvas_view_;
73 CanvasView::IsWorking is_working;
75 Duckmatic::Push duckmatic_push;
77 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
79 etl::smart_ptr<std::list<synfig::Real> > width_data;
81 Gdk::ModifierType modifier;
85 Smach::event_result event_stop_handler(const Smach::event& x);
87 Smach::event_result event_refresh_handler(const Smach::event& x);
89 Smach::event_result event_mouse_up_handler(const Smach::event& x);
91 Smach::event_result event_mouse_draw_handler(const Smach::event& x);
92 Smach::event_result event_refresh_tool_options(const Smach::event& x);
94 StateStroke_Context(CanvasView* canvas_view);
96 ~StateStroke_Context();
98 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
99 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
100 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
101 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
103 }; // END of class StateStroke_Context
106 /* === M E T H O D S ======================================================= */
108 StateStroke::StateStroke():
109 Smach::state<StateStroke_Context>("stroke")
111 insert(event_def(EVENT_STOP,&StateStroke_Context::event_stop_handler));
112 insert(event_def(EVENT_REFRESH,&StateStroke_Context::event_refresh_handler));
113 // insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStroke_Context::event_mouse_down_handler));
114 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStroke_Context::event_mouse_up_handler));
115 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStroke_Context::event_mouse_draw_handler));
116 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStroke_Context::event_refresh_tool_options));
119 StateStroke::~StateStroke()
124 StateStroke_Context::StateStroke_Context(CanvasView* canvas_view):
125 canvas_view_(canvas_view),
126 is_working(*canvas_view),
127 duckmatic_push(get_work_area())
132 get_work_area()->add_stroke(stroke_data, synfigapp::Main::get_foreground_color());
135 StateStroke_Context::~StateStroke_Context()
137 duckmatic_push.restore();
139 App::toolbox->refresh();
141 // Send the stroke data to whatever previously called this state.
142 if(stroke_data->size()>=2)
143 get_canvas_view()->get_smach().process_event(EventStroke(stroke_data,width_data,modifier));
147 StateStroke_Context::event_refresh_tool_options(const Smach::event& /*x*/)
149 return Smach::RESULT_ACCEPT;
153 StateStroke_Context::event_stop_handler(const Smach::event& /*x*/)
155 throw Smach::pop_exception();
159 StateStroke_Context::event_refresh_handler(const Smach::event& /*x*/)
161 return Smach::RESULT_ACCEPT;
165 StateStroke_Context::event_mouse_up_handler(const Smach::event& x)
167 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
172 modifier=event.modifier;
173 throw Smach::pop_exception();
176 case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
177 printf("%s:%d BUTTON_RIGHT\n", __FILE__, __LINE__);
178 if (!getenv("SYNFIG_ENABLE_POPUP_MENU_IN_ALL_TOOLS"))
179 return Smach::RESULT_ACCEPT;
182 return Smach::RESULT_OK;
187 StateStroke_Context::event_mouse_draw_handler(const Smach::event& x)
189 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
194 stroke_data->push_back(event.pos);
195 width_data->push_back(event.pressure);
196 get_work_area()->queue_draw();
197 return Smach::RESULT_ACCEPT;
200 case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
201 printf("%s:%d BUTTON_RIGHT\n", __FILE__, __LINE__);
202 if (!getenv("SYNFIG_ENABLE_POPUP_MENU_IN_ALL_TOOLS"))
203 return Smach::RESULT_ACCEPT;
206 return Smach::RESULT_OK;