1 /* === S I N F 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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "state_fill.h"
33 #include <sinfg/context.h>
35 #include "dialog_color.h"
36 #include "event_mouse.h"
37 #include "event_layerclick.h"
39 #include "canvasview.h"
40 #include <sinfgapp/main.h>
44 /* === U S I N G =========================================================== */
48 using namespace sinfg;
49 using namespace studio;
51 /* === M A C R O S ========================================================= */
53 /* === C L A S S E S & S T R U C T S ======================================= */
55 class studio::StateFill_Context
57 CanvasView *canvas_view;
58 CanvasView::IsWorking is_working;
61 StateFill_Context(CanvasView *canvas_view);
64 Smach::event_result event_stop_handler(const Smach::event& x);
66 Smach::event_result event_refresh_handler(const Smach::event& x);
68 Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
71 etl::handle<CanvasView> get_canvas_view()const{return canvas_view;}
72 etl::handle<sinfgapp::CanvasInterface> get_canvas_interface()const{return canvas_view->canvas_interface();}
73 sinfg::Canvas::Handle get_canvas()const{return canvas_view->get_canvas();}
74 WorkArea * get_work_area()const{return canvas_view->get_work_area();}
77 }; // END of class StateFill_Context
79 /* === G L O B A L S ======================================================= */
81 StateFill studio::state_fill;
83 /* === P R O C E D U R E S ================================================= */
85 /* === M E T H O D S ======================================================= */
87 StateFill::StateFill():
88 Smach::state<StateFill_Context>("fill")
90 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateFill_Context::event_stop_handler));
91 insert(event_def(EVENT_STOP,&StateFill_Context::event_stop_handler));
92 insert(event_def(EVENT_REFRESH,&StateFill_Context::event_refresh_handler));
93 insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateFill_Context::event_workarea_layer_clicked_handler));
96 StateFill::~StateFill()
100 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
101 canvas_view(canvas_view),
102 is_working(*canvas_view)
104 sinfg::info("Enterted Fill State");
105 canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
107 App::toolbox->refresh();
110 StateFill_Context::~StateFill_Context()
112 sinfg::info("Left Fill State");
113 canvas_view->work_area->reset_cursor();
114 App::toolbox->refresh();
118 StateFill_Context::event_stop_handler(const Smach::event& x)
120 sinfg::info("STATE FILL: Received Stop Event");
121 throw Smach::egress_exception();
122 // canvas_view->get_smach().pop_state();
123 // return Smach::RESULT_ACCEPT;
127 StateFill_Context::event_refresh_handler(const Smach::event& x)
129 sinfg::info("STATE FILL: Received Refresh Event");
130 canvas_view->work_area->queue_render_preview();
131 return Smach::RESULT_ACCEPT;
135 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
137 sinfg::info("STATE FILL: Received layer clicked Event");
138 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
142 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
143 return Smach::RESULT_ACCEPT;
147 //sinfgapp::Action::Handle action(sinfgapp::Action::create("value_desc_set"));
148 sinfgapp::ValueDesc value_desc(event.layer,"color");
150 if(!get_canvas_interface()->change_value(value_desc,ValueBase(sinfgapp::Main::get_foreground_color())))
152 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
153 return Smach::RESULT_ERROR;
158 action->set_param("canvas",get_canvas());
159 action->set_param("canvas_interface",get_canvas_interface());
160 action->set_param("value_desc",value_desc);
161 action->set_param("time",get_canvas_interface()->get_time());
162 //action->set_param("layer",event.layer);
163 //if(!action->set_param("param",String("color")))
164 // sinfg::error("LayerParamConnect didn't like \"param\"");
165 if(!action->set_param("new_value",ValueBase(sinfgapp::Main::get_foreground_color())))
166 sinfg::error("LayerParamConnect didn't like \"foreground_color\"");
168 if(!get_canvas_interface()->get_instance()->perform_action(action))
170 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
171 return Smach::RESULT_ERROR;
173 get_canvas_view()->get_ui_interface()->task(_("Idle"));
175 return Smach::RESULT_ACCEPT;