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