Add actions (add to group, ,remove from group, export, un-export, set layer descripti...
[synfig.git] / synfig-studio / 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 "state_normal.h"
34 #include "workarea.h"
35 #include <synfig/context.h>
36 #include "app.h"
37 #include "dialog_color.h"
38 #include "event_mouse.h"
39 #include "event_layerclick.h"
40 #include "toolbox.h"
41 #include "canvasview.h"
42 #include <synfigapp/main.h>
43
44 #include "general.h"
45
46 #endif
47
48 /* === U S I N G =========================================================== */
49
50 using namespace std;
51 using namespace etl;
52 using namespace synfig;
53 using namespace studio;
54
55 /* === M A C R O S ========================================================= */
56
57 /* === C L A S S E S & S T R U C T S ======================================= */
58
59 class studio::StateFill_Context
60 {
61         CanvasView *canvas_view;
62         CanvasView::IsWorking is_working;
63
64 public:
65         StateFill_Context(CanvasView *canvas_view);
66         ~StateFill_Context();
67
68         Smach::event_result event_stop_handler(const Smach::event& x);
69
70         Smach::event_result event_refresh_handler(const Smach::event& x);
71
72         Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
73
74
75         etl::handle<CanvasView> get_canvas_view()const{return canvas_view;}
76         etl::handle<synfigapp::CanvasInterface> get_canvas_interface()const{return canvas_view->canvas_interface();}
77         synfig::Canvas::Handle get_canvas()const{return canvas_view->get_canvas();}
78         WorkArea * get_work_area()const{return canvas_view->get_work_area();}
79
80
81 }; // END of class StateFill_Context
82
83 /* === G L O B A L S ======================================================= */
84
85 StateFill studio::state_fill;
86
87 /* === P R O C E D U R E S ================================================= */
88
89 /* === M E T H O D S ======================================================= */
90
91 StateFill::StateFill():
92         Smach::state<StateFill_Context>("fill")
93 {
94         insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateFill_Context::event_stop_handler));
95         insert(event_def(EVENT_STOP,&StateFill_Context::event_stop_handler));
96         insert(event_def(EVENT_REFRESH,&StateFill_Context::event_refresh_handler));
97         insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateFill_Context::event_workarea_layer_clicked_handler));
98 }
99
100 StateFill::~StateFill()
101 {
102 }
103
104 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
105         canvas_view(canvas_view),
106         is_working(*canvas_view)
107 {
108         synfig::info("Entered Fill State");
109         canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
110
111         App::toolbox->refresh();
112 }
113
114 StateFill_Context::~StateFill_Context()
115 {
116         synfig::info("Left Fill State");
117         canvas_view->work_area->reset_cursor();
118         App::toolbox->refresh();
119 }
120
121 Smach::event_result
122 StateFill_Context::event_stop_handler(const Smach::event& /*x*/)
123 {
124         synfig::info("STATE FILL: Received Stop Event");
125         //throw Smach::egress_exception();
126         throw &state_normal;
127         return Smach::RESULT_OK;
128 //      canvas_view->get_smach().pop_state();
129 //      return Smach::RESULT_ACCEPT;
130 }
131
132 Smach::event_result
133 StateFill_Context::event_refresh_handler(const Smach::event& /*x*/)
134 {
135         synfig::info("STATE FILL: Received Refresh Event");
136         canvas_view->work_area->queue_render_preview();
137         return Smach::RESULT_ACCEPT;
138 }
139
140 Smach::event_result
141 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
142 {
143         synfig::info("STATE FILL: Received layer clicked Event");
144         const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
145
146         if(!event.layer)
147         {
148                 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
149                 return Smach::RESULT_ACCEPT;
150         }
151
152
153         //synfigapp::Action::Handle action(synfigapp::Action::create("ValueDescSet"));
154         synfigapp::ValueDesc value_desc(event.layer,"color");
155
156         if(!get_canvas_interface()->change_value(value_desc,ValueBase(synfigapp::Main::get_fill_color())))
157         {
158                 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
159                 return Smach::RESULT_ERROR;
160         }
161         /*
162         assert(action);
163
164         action->set_param("canvas",get_canvas());
165         action->set_param("canvas_interface",get_canvas_interface());
166         action->set_param("value_desc",value_desc);
167         action->set_param("time",get_canvas_interface()->get_time());
168         //action->set_param("layer",event.layer);
169         //if(!action->set_param("param",String("color")))
170         //      synfig::error("LayerParamConnect didn't like \"param\"");
171         if(!action->set_param("new_value",ValueBase(synfigapp::Main::get_fill_color())))
172                 synfig::error("LayerParamConnect didn't like \"fill_color\"");
173
174         if(!get_canvas_interface()->get_instance()->perform_action(action))
175         {
176                 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
177                 return Smach::RESULT_ERROR;
178         }
179         get_canvas_view()->get_ui_interface()->task(_("Idle"));
180         */
181         return Smach::RESULT_ACCEPT;
182 }