Build rectanglular blines in the same handedness as all the other shapes.
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_fill.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file state_fill.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "state_fill.h"
33 #include "workarea.h"
34 #include <synfig/context.h>
35 #include "app.h"
36 #include "dialog_color.h"
37 #include "event_mouse.h"
38 #include "event_layerclick.h"
39 #include "toolbox.h"
40 #include "canvasview.h"
41 #include <synfigapp/main.h>
42
43 #include "general.h"
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace studio;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === C L A S S E S & S T R U C T S ======================================= */
57
58 class studio::StateFill_Context
59 {
60         CanvasView *canvas_view;
61         CanvasView::IsWorking is_working;
62
63 public:
64         StateFill_Context(CanvasView *canvas_view);
65         ~StateFill_Context();
66
67         Smach::event_result event_stop_handler(const Smach::event& x);
68
69         Smach::event_result event_refresh_handler(const Smach::event& x);
70
71         Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
72
73
74         etl::handle<CanvasView> get_canvas_view()const{return canvas_view;}
75         etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view->canvas_interface();}
76         synfig::Canvas::Handle get_canvas()const{return canvas_view->get_canvas();}
77         WorkArea * get_work_area()const{return canvas_view->get_work_area();}
78
79
80 }; // END of class StateFill_Context
81
82 /* === G L O B A L S ======================================================= */
83
84 StateFill studio::state_fill;
85
86 /* === P R O C E D U R E S ================================================= */
87
88 /* === M E T H O D S ======================================================= */
89
90 StateFill::StateFill():
91         Smach::state<StateFill_Context>("fill")
92 {
93         insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateFill_Context::event_stop_handler));
94         insert(event_def(EVENT_STOP,&StateFill_Context::event_stop_handler));
95         insert(event_def(EVENT_REFRESH,&StateFill_Context::event_refresh_handler));
96         insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateFill_Context::event_workarea_layer_clicked_handler));
97 }
98
99 StateFill::~StateFill()
100 {
101 }
102
103 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
104         canvas_view(canvas_view),
105         is_working(*canvas_view)
106 {
107         synfig::info("Entered Fill State");
108         canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
109
110         App::toolbox->refresh();
111 }
112
113 StateFill_Context::~StateFill_Context()
114 {
115         synfig::info("Left Fill State");
116         canvas_view->work_area->reset_cursor();
117         App::toolbox->refresh();
118 }
119
120 Smach::event_result
121 StateFill_Context::event_stop_handler(const Smach::event& /*x*/)
122 {
123         synfig::info("STATE FILL: Received Stop Event");
124         throw Smach::egress_exception();
125 //      canvas_view->get_smach().pop_state();
126 //      return Smach::RESULT_ACCEPT;
127 }
128
129 Smach::event_result
130 StateFill_Context::event_refresh_handler(const Smach::event& /*x*/)
131 {
132         synfig::info("STATE FILL: Received Refresh Event");
133         canvas_view->work_area->queue_render_preview();
134         return Smach::RESULT_ACCEPT;
135 }
136
137 Smach::event_result
138 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
139 {
140         synfig::info("STATE FILL: Received layer clicked Event");
141         const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
142
143         if(!event.layer)
144         {
145                 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
146                 return Smach::RESULT_ACCEPT;
147         }
148
149
150         //synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_set"));
151         synfigapp::ValueDesc value_desc(event.layer,"color");
152
153         if(!get_canvas_interface()->change_value(value_desc,ValueBase(synfigapp::Main::get_foreground_color())))
154         {
155                 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
156                 return Smach::RESULT_ERROR;
157         }
158         /*
159         assert(action);
160
161         action->set_param("canvas",get_canvas());
162         action->set_param("canvas_interface",get_canvas_interface());
163         action->set_param("value_desc",value_desc);
164         action->set_param("time",get_canvas_interface()->get_time());
165         //action->set_param("layer",event.layer);
166         //if(!action->set_param("param",String("color")))
167         //      synfig::error("LayerParamConnect didn't like \"param\"");
168         if(!action->set_param("new_value",ValueBase(synfigapp::Main::get_foreground_color())))
169                 synfig::error("LayerParamConnect didn't like \"foreground_color\"");
170
171         if(!get_canvas_interface()->get_instance()->perform_action(action))
172         {
173                 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
174                 return Smach::RESULT_ERROR;
175         }
176         get_canvas_view()->get_ui_interface()->task(_("Idle"));
177         */
178         return Smach::RESULT_ACCEPT;
179 }