initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_fill.cpp
1 /* === S I N F 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "state_fill.h"
32 #include "workarea.h"
33 #include <sinfg/context.h>
34 #include "app.h"
35 #include "dialog_color.h"
36 #include "event_mouse.h"
37 #include "event_layerclick.h"
38 #include "toolbox.h"
39 #include "canvasview.h"
40 #include <sinfgapp/main.h>
41
42 #endif
43
44 /* === U S I N G =========================================================== */
45
46 using namespace std;
47 using namespace etl;
48 using namespace sinfg;
49 using namespace studio;
50
51 /* === M A C R O S ========================================================= */
52
53 /* === C L A S S E S & S T R U C T S ======================================= */
54
55 class studio::StateFill_Context
56 {
57         CanvasView *canvas_view;
58         CanvasView::IsWorking is_working;
59
60 public:
61         StateFill_Context(CanvasView *canvas_view);
62         ~StateFill_Context();
63         
64         Smach::event_result event_stop_handler(const Smach::event& x);
65
66         Smach::event_result event_refresh_handler(const Smach::event& x);
67
68         Smach::event_result event_workarea_layer_clicked_handler(const Smach::event& x);
69
70
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();}
75
76
77 }; // END of class StateFill_Context
78
79 /* === G L O B A L S ======================================================= */
80
81 StateFill studio::state_fill;
82
83 /* === P R O C E D U R E S ================================================= */
84
85 /* === M E T H O D S ======================================================= */
86
87 StateFill::StateFill():
88         Smach::state<StateFill_Context>("fill")
89 {
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));
94 }       
95
96 StateFill::~StateFill()
97 {
98 }
99
100 StateFill_Context::StateFill_Context(CanvasView *canvas_view):
101         canvas_view(canvas_view),
102         is_working(*canvas_view)
103 {
104         sinfg::info("Enterted Fill State");
105         canvas_view->work_area->set_cursor(Gdk::CROSSHAIR);
106         
107         App::toolbox->refresh();
108 }
109
110 StateFill_Context::~StateFill_Context()
111 {
112         sinfg::info("Left Fill State");
113         canvas_view->work_area->reset_cursor();
114         App::toolbox->refresh();
115 }
116
117 Smach::event_result
118 StateFill_Context::event_stop_handler(const Smach::event& x)
119 {
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;
124 }
125
126 Smach::event_result
127 StateFill_Context::event_refresh_handler(const Smach::event& x)
128 {
129         sinfg::info("STATE FILL: Received Refresh Event");
130         canvas_view->work_area->queue_render_preview();
131         return Smach::RESULT_ACCEPT;
132 }
133
134 Smach::event_result
135 StateFill_Context::event_workarea_layer_clicked_handler(const Smach::event& x)
136 {
137         sinfg::info("STATE FILL: Received layer clicked Event");
138         const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
139
140         if(!event.layer)
141         {
142                 get_canvas_view()->get_ui_interface()->warning(_("No layer here"));
143                 return Smach::RESULT_ACCEPT;
144         }
145
146         
147         //sinfgapp::Action::Handle action(sinfgapp::Action::create("value_desc_set"));
148         sinfgapp::ValueDesc value_desc(event.layer,"color");
149
150         if(!get_canvas_interface()->change_value(value_desc,ValueBase(sinfgapp::Main::get_foreground_color())))
151         {
152                 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
153                 return Smach::RESULT_ERROR;
154         }
155         /*
156         assert(action);
157         
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\"");
167         
168         if(!get_canvas_interface()->get_instance()->perform_action(action))
169         {
170                 get_canvas_view()->get_ui_interface()->warning(_("Unable to set layer color"));
171                 return Smach::RESULT_ERROR;
172         }
173         get_canvas_view()->get_ui_interface()->task(_("Idle"));
174         */
175         return Smach::RESULT_ACCEPT;
176 }