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"
34 #include <synfig/context.h>
36 #include "dialog_color.h"
37 #include "event_mouse.h"
38 #include "event_layerclick.h"
40 #include "canvasview.h"
41 #include <synfigapp/main.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
52 using namespace studio;
54 /* === M A C R O S ========================================================= */
56 /* === C L A S S E S & S T R U C T S ======================================= */
58 class studio::StateFill_Context
60 CanvasView *canvas_view;
61 CanvasView::IsWorking is_working;
64 StateFill_Context(CanvasView *canvas_view);
67 Smach::event_result event_stop_handler(const Smach::event& x);
69 Smach::event_result event_refresh_handler(const Smach::event& x);
71 Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
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();}
80 }; // END of class StateFill_Context
82 /* === G L O B A L S ======================================================= */
84 StateFill studio::state_fill;
86 /* === P R O C E D U R E S ================================================= */
88 /* === M E T H O D S ======================================================= */
90 StateFill::StateFill():
91 Smach::state<StateFill_Context>("fill")
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));
99 StateFill::~StateFill()
103 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
104 canvas_view(canvas_view),
105 is_working(*canvas_view)
107 synfig::info("Entered Fill State");
108 canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
110 App::toolbox->refresh();
113 StateFill_Context::~StateFill_Context()
115 synfig::info("Left Fill State");
116 canvas_view->work_area->reset_cursor();
117 App::toolbox->refresh();
121 StateFill_Context::event_stop_handler(const Smach::event& /*x*/)
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;
130 StateFill_Context::event_refresh_handler(const Smach::event& /*x*/)
132 synfig::info("STATE FILL: Received Refresh Event");
133 canvas_view->work_area->queue_render_preview();
134 return Smach::RESULT_ACCEPT;
138 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
140 synfig::info("STATE FILL: Received layer clicked Event");
141 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
145 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
146 return Smach::RESULT_ACCEPT;
150 //synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_set"));
151 synfigapp::ValueDesc value_desc(event.layer,"color");
153 if(!get_canvas_interface()->change_value(value_desc,ValueBase(synfigapp::Main::get_foreground_color())))
155 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
156 return Smach::RESULT_ERROR;
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\"");
171 if(!get_canvas_interface()->get_instance()->perform_action(action))
173 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
174 return Smach::RESULT_ERROR;
176 get_canvas_view()->get_ui_interface()->task(_("Idle"));
178 return Smach::RESULT_ACCEPT;