1 /* === S Y N F I G ========================================================= */
2 /*! \file state_stroke.cpp
3 ** \brief Template File
5 ** $Id: state_stroke.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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>
52 /* === U S I N G =========================================================== */
56 using namespace synfig;
57 using namespace studio;
59 /* === M A C R O S ========================================================= */
61 /* === G L O B A L S ======================================================= */
63 StateStroke studio::state_stroke;
65 /* === C L A S S E S & S T R U C T S ======================================= */
67 class studio::StateStroke_Context : public sigc::trackable
69 etl::handle<CanvasView> canvas_view_;
70 CanvasView::IsWorking is_working;
72 Duckmatic::Push duckmatic_push;
74 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
76 etl::smart_ptr<std::list<synfig::Real> > width_data;
78 Gdk::ModifierType modifier;
82 Smach::event_result event_stop_handler(const Smach::event& x);
84 Smach::event_result event_refresh_handler(const Smach::event& x);
86 Smach::event_result event_mouse_up_handler(const Smach::event& x);
88 Smach::event_result event_mouse_draw_handler(const Smach::event& x);
89 Smach::event_result event_refresh_tool_options(const Smach::event& x);
91 StateStroke_Context(CanvasView* canvas_view);
93 ~StateStroke_Context();
95 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
96 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
97 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
98 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
100 }; // END of class StateStroke_Context
103 /* === M E T H O D S ======================================================= */
105 StateStroke::StateStroke():
106 Smach::state<StateStroke_Context>("stroke")
108 insert(event_def(EVENT_STOP,&StateStroke_Context::event_stop_handler));
109 insert(event_def(EVENT_REFRESH,&StateStroke_Context::event_refresh_handler));
110 // insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStroke_Context::event_mouse_down_handler));
111 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStroke_Context::event_mouse_up_handler));
112 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStroke_Context::event_mouse_draw_handler));
113 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStroke_Context::event_refresh_tool_options));
116 StateStroke::~StateStroke()
121 StateStroke_Context::StateStroke_Context(CanvasView* canvas_view):
122 canvas_view_(canvas_view),
123 is_working(*canvas_view),
124 duckmatic_push(get_work_area())
129 get_work_area()->add_stroke(stroke_data, synfigapp::Main::get_foreground_color());
131 synfig::info("Now Scribbling...");
134 StateStroke_Context::~StateStroke_Context()
136 duckmatic_push.restore();
138 App::toolbox->refresh();
139 synfig::info("No longer scribbling");
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-circut the pop-up menu
177 return Smach::RESULT_ACCEPT;
180 return Smach::RESULT_OK;
185 StateStroke_Context::event_mouse_draw_handler(const Smach::event& x)
187 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
192 stroke_data->push_back(event.pos);
193 width_data->push_back(event.pressure);
194 get_work_area()->queue_draw();
195 return Smach::RESULT_ACCEPT;
198 case BUTTON_RIGHT: // Intercept the right-button click to short-circut the pop-up menu
199 return Smach::RESULT_ACCEPT;
202 return Smach::RESULT_OK;