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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include <gtkmm/dialog.h>
33 #include <gtkmm/entry.h>
35 #include <synfig/valuenode_dynamiclist.h>
37 #include "state_stroke.h"
38 #include "canvasview.h"
41 #include <synfig/valuenode_bline.h>
42 #include <ETL/hermite>
43 #include <ETL/calculus>
45 #include "event_mouse.h"
46 #include "event_layerclick.h"
48 #include <synfigapp/main.h>
54 /* === U S I N G =========================================================== */
58 using namespace synfig;
59 using namespace studio;
61 /* === M A C R O S ========================================================= */
63 /* === G L O B A L S ======================================================= */
65 StateStroke studio::state_stroke;
67 /* === C L A S S E S & S T R U C T S ======================================= */
69 class studio::StateStroke_Context : public sigc::trackable
71 etl::handle<CanvasView> canvas_view_;
72 CanvasView::IsWorking is_working;
74 Duckmatic::Push duckmatic_push;
76 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
78 etl::smart_ptr<std::list<synfig::Real> > width_data;
80 Gdk::ModifierType modifier;
84 Smach::event_result event_stop_handler(const Smach::event& x);
86 Smach::event_result event_refresh_handler(const Smach::event& x);
88 Smach::event_result event_mouse_up_handler(const Smach::event& x);
90 Smach::event_result event_mouse_draw_handler(const Smach::event& x);
91 Smach::event_result event_refresh_tool_options(const Smach::event& x);
93 StateStroke_Context(CanvasView* canvas_view);
95 ~StateStroke_Context();
97 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
98 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
99 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
100 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
102 }; // END of class StateStroke_Context
105 /* === M E T H O D S ======================================================= */
107 StateStroke::StateStroke():
108 Smach::state<StateStroke_Context>("stroke")
110 insert(event_def(EVENT_STOP,&StateStroke_Context::event_stop_handler));
111 insert(event_def(EVENT_REFRESH,&StateStroke_Context::event_refresh_handler));
112 // insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStroke_Context::event_mouse_down_handler));
113 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStroke_Context::event_mouse_up_handler));
114 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStroke_Context::event_mouse_draw_handler));
115 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStroke_Context::event_refresh_tool_options));
118 StateStroke::~StateStroke()
123 StateStroke_Context::StateStroke_Context(CanvasView* canvas_view):
124 canvas_view_(canvas_view),
125 is_working(*canvas_view),
126 duckmatic_push(get_work_area())
131 get_work_area()->add_stroke(stroke_data, synfigapp::Main::get_foreground_color());
133 synfig::info("Now Scribbling...");
136 StateStroke_Context::~StateStroke_Context()
138 duckmatic_push.restore();
140 App::toolbox->refresh();
141 synfig::info("No longer scribbling");
143 // Send the stroke data to whatever previously called this state.
144 if(stroke_data->size()>=2)
145 get_canvas_view()->get_smach().process_event(EventStroke(stroke_data,width_data,modifier));
149 StateStroke_Context::event_refresh_tool_options(const Smach::event& /*x*/)
151 return Smach::RESULT_ACCEPT;
155 StateStroke_Context::event_stop_handler(const Smach::event& /*x*/)
157 throw Smach::pop_exception();
161 StateStroke_Context::event_refresh_handler(const Smach::event& /*x*/)
163 return Smach::RESULT_ACCEPT;
167 StateStroke_Context::event_mouse_up_handler(const Smach::event& x)
169 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
174 modifier=event.modifier;
175 throw Smach::pop_exception();
178 case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
179 printf("%s:%d BUTTON_RIGHT\n", __FILE__, __LINE__);
180 if (!getenv("SYNFIG_ENABLE_POPUP_MENU_IN_ALL_TOOLS"))
181 return Smach::RESULT_ACCEPT;
184 return Smach::RESULT_OK;
189 StateStroke_Context::event_mouse_draw_handler(const Smach::event& x)
191 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
196 stroke_data->push_back(event.pos);
197 width_data->push_back(event.pressure);
198 get_work_area()->queue_draw();
199 return Smach::RESULT_ACCEPT;
202 case BUTTON_RIGHT: // Intercept the right-button click to short-circuit the pop-up menu
203 printf("%s:%d BUTTON_RIGHT\n", __FILE__, __LINE__);
204 if (!getenv("SYNFIG_ENABLE_POPUP_MENU_IN_ALL_TOOLS"))
205 return Smach::RESULT_ACCEPT;
208 return Smach::RESULT_OK;