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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include <gtkmm/dialog.h>
32 #include <gtkmm/entry.h>
34 #include <synfig/valuenode_dynamiclist.h>
36 #include "state_stroke.h"
37 #include "canvasview.h"
40 #include <synfig/valuenode_bline.h>
41 #include <ETL/hermite>
42 #include <ETL/calculus>
44 #include "event_mouse.h"
45 #include "event_layerclick.h"
47 #include <synfigapp/main.h>
51 /* === U S I N G =========================================================== */
55 using namespace synfig;
56 using namespace studio;
58 /* === M A C R O S ========================================================= */
60 /* === G L O B A L S ======================================================= */
62 StateStroke studio::state_stroke;
64 /* === C L A S S E S & S T R U C T S ======================================= */
66 class studio::StateStroke_Context : public sigc::trackable
68 etl::handle<CanvasView> canvas_view_;
69 CanvasView::IsWorking is_working;
71 Duckmatic::Push duckmatic_push;
73 etl::smart_ptr<std::list<synfig::Point> > stroke_data;
75 etl::smart_ptr<std::list<synfig::Real> > width_data;
77 Gdk::ModifierType modifier;
81 Smach::event_result event_stop_handler(const Smach::event& x);
83 Smach::event_result event_refresh_handler(const Smach::event& x);
85 Smach::event_result event_mouse_up_handler(const Smach::event& x);
87 Smach::event_result event_mouse_draw_handler(const Smach::event& x);
88 Smach::event_result event_refresh_tool_options(const Smach::event& x);
90 StateStroke_Context(CanvasView* canvas_view);
92 ~StateStroke_Context();
94 const etl::handle<CanvasView>& get_canvas_view()const{return canvas_view_;}
95 etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view_->canvas_interface();}
96 synfig::Canvas::Handle get_canvas()const{return canvas_view_->get_canvas();}
97 WorkArea * get_work_area()const{return canvas_view_->get_work_area();}
99 }; // END of class StateStroke_Context
102 /* === M E T H O D S ======================================================= */
104 StateStroke::StateStroke():
105 Smach::state<StateStroke_Context>("stroke")
107 insert(event_def(EVENT_STOP,&StateStroke_Context::event_stop_handler));
108 insert(event_def(EVENT_REFRESH,&StateStroke_Context::event_refresh_handler));
109 // insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateStroke_Context::event_mouse_down_handler));
110 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_UP,&StateStroke_Context::event_mouse_up_handler));
111 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DRAG,&StateStroke_Context::event_mouse_draw_handler));
112 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateStroke_Context::event_refresh_tool_options));
115 StateStroke::~StateStroke()
120 StateStroke_Context::StateStroke_Context(CanvasView* canvas_view):
121 canvas_view_(canvas_view),
122 is_working(*canvas_view),
123 duckmatic_push(get_work_area())
128 get_work_area()->add_stroke(stroke_data, synfigapp::Main::get_foreground_color());
130 synfig::info("Now Scribbling...");
133 StateStroke_Context::~StateStroke_Context()
135 duckmatic_push.restore();
137 App::toolbox->refresh();
138 synfig::info("No longer scribbling");
140 // Send the stroke data to whatever previously called this state.
141 if(stroke_data->size()>=2)
142 get_canvas_view()->get_smach().process_event(EventStroke(stroke_data,width_data,modifier));
146 StateStroke_Context::event_refresh_tool_options(const Smach::event& x)
148 return Smach::RESULT_ACCEPT;
152 StateStroke_Context::event_stop_handler(const Smach::event& x)
154 throw Smach::pop_exception();
158 StateStroke_Context::event_refresh_handler(const Smach::event& x)
160 return Smach::RESULT_ACCEPT;
164 StateStroke_Context::event_mouse_up_handler(const Smach::event& x)
166 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
171 modifier=event.modifier;
172 throw Smach::pop_exception();
175 case BUTTON_RIGHT: // Intercept the right-button click to short-circut the pop-up menu
176 return Smach::RESULT_ACCEPT;
179 return Smach::RESULT_OK;
184 StateStroke_Context::event_mouse_draw_handler(const Smach::event& x)
186 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
191 stroke_data->push_back(event.pos);
192 width_data->push_back(event.pressure);
193 get_work_area()->queue_draw();
194 return Smach::RESULT_ACCEPT;
197 case BUTTON_RIGHT: // Intercept the right-button click to short-circut the pop-up menu
198 return Smach::RESULT_ACCEPT;
201 return Smach::RESULT_OK;