1 /* === S Y N F I G ========================================================= */
2 /*! \file state_fill.cpp
3 ** \brief Template File
5 ** $Id: state_fill.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === C L A S S E S & S T R U C T S ======================================= */
56 class studio::StateFill_Context
58 CanvasView *canvas_view;
59 CanvasView::IsWorking is_working;
62 StateFill_Context(CanvasView *canvas_view);
65 Smach::event_result event_stop_handler(const Smach::event& x);
67 Smach::event_result event_refresh_handler(const Smach::event& x);
69 Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
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();}
78 }; // END of class StateFill_Context
80 /* === G L O B A L S ======================================================= */
82 StateFill studio::state_fill;
84 /* === P R O C E D U R E S ================================================= */
86 /* === M E T H O D S ======================================================= */
88 StateFill::StateFill():
89 Smach::state<StateFill_Context>("fill")
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));
97 StateFill::~StateFill()
101 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
102 canvas_view(canvas_view),
103 is_working(*canvas_view)
105 synfig::info("Enterted Fill State");
106 canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
108 App::toolbox->refresh();
111 StateFill_Context::~StateFill_Context()
113 synfig::info("Left Fill State");
114 canvas_view->work_area->reset_cursor();
115 App::toolbox->refresh();
119 StateFill_Context::event_stop_handler(const Smach::event& x)
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;
128 StateFill_Context::event_refresh_handler(const Smach::event& x)
130 synfig::info("STATE FILL: Received Refresh Event");
131 canvas_view->work_area->queue_render_preview();
132 return Smach::RESULT_ACCEPT;
136 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
138 synfig::info("STATE FILL: Received layer clicked Event");
139 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
143 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
144 return Smach::RESULT_ACCEPT;
148 //synfigapp::Action::Handle action(synfigapp::Action::create("value_desc_set"));
149 synfigapp::ValueDesc value_desc(event.layer,"color");
151 if(!get_canvas_interface()->change_value(value_desc,ValueBase(synfigapp::Main::get_foreground_color())))
153 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
154 return Smach::RESULT_ERROR;
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\"");
169 if(!get_canvas_interface()->get_instance()->perform_action(action))
171 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
172 return Smach::RESULT_ERROR;
174 get_canvas_view()->get_ui_interface()->task(_("Idle"));
176 return Smach::RESULT_ACCEPT;