1 /* === S Y N F I G ========================================================= */
2 /*! \file state_fill.cpp
3 ** \brief Template File
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 "state_fill.h"
33 #include "state_normal.h"
35 #include <synfig/context.h>
37 #include "dialog_color.h"
38 #include "event_mouse.h"
39 #include "event_layerclick.h"
41 #include "canvasview.h"
42 #include <synfigapp/main.h>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 /* === C L A S S E S & S T R U C T S ======================================= */
59 class studio::StateFill_Context
61 CanvasView *canvas_view;
62 CanvasView::IsWorking is_working;
65 StateFill_Context(CanvasView *canvas_view);
68 Smach::event_result event_stop_handler(const Smach::event& x);
70 Smach::event_result event_refresh_handler(const Smach::event& x);
72 Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
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();}
81 }; // END of class StateFill_Context
83 /* === G L O B A L S ======================================================= */
85 StateFill studio::state_fill;
87 /* === P R O C E D U R E S ================================================= */
89 /* === M E T H O D S ======================================================= */
91 StateFill::StateFill():
92 Smach::state<StateFill_Context>("fill")
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));
100 StateFill::~StateFill()
104 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
105 canvas_view(canvas_view),
106 is_working(*canvas_view)
108 synfig::info("Entered Fill State");
109 canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
111 App::toolbox->refresh();
114 StateFill_Context::~StateFill_Context()
116 synfig::info("Left Fill State");
117 canvas_view->work_area->reset_cursor();
118 App::toolbox->refresh();
122 StateFill_Context::event_stop_handler(const Smach::event& /*x*/)
124 synfig::info("STATE FILL: Received Stop Event");
125 //throw Smach::egress_exception();
127 return Smach::RESULT_OK;
128 // canvas_view->get_smach().pop_state();
129 // return Smach::RESULT_ACCEPT;
133 StateFill_Context::event_refresh_handler(const Smach::event& /*x*/)
135 synfig::info("STATE FILL: Received Refresh Event");
136 canvas_view->work_area->queue_render_preview();
137 return Smach::RESULT_ACCEPT;
141 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
143 synfig::info("STATE FILL: Received layer clicked Event");
144 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
148 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
149 return Smach::RESULT_ACCEPT;
153 //synfigapp::Action::Handle action(synfigapp::Action::create("ValueDescSet"));
154 synfigapp::ValueDesc value_desc(event.layer,"color");
156 if(!get_canvas_interface()->change_value(value_desc,ValueBase(synfigapp::Main::get_fill_color())))
158 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
159 return Smach::RESULT_ERROR;
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\"");
174 if(!get_canvas_interface()->get_instance()->perform_action(action))
176 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
177 return Smach::RESULT_ERROR;
179 get_canvas_view()->get_ui_interface()->task(_("Idle"));
181 return Smach::RESULT_ACCEPT;