Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.09 / src / gtkmm / state_eyedrop.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file state_eyedrop.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "state_eyedrop.h"
33 #include "workarea.h"
34 #include <synfig/context.h>
35 #include "app.h"
36 #include "dialog_color.h"
37 #include "event_mouse.h"
38 #include "event_layerclick.h"
39 #include "toolbox.h"
40 #include "canvasview.h"
41 #include <synfigapp/main.h>
42
43 #include "general.h"
44
45 #endif
46
47 /* === U S I N G =========================================================== */
48
49 using namespace std;
50 using namespace etl;
51 using namespace synfig;
52 using namespace studio;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === C L A S S E S & S T R U C T S ======================================= */
57
58 class studio::StateEyedrop_Context
59 {
60         CanvasView *canvas_view;
61         CanvasView::IsWorking is_working;
62
63 public:
64         StateEyedrop_Context(CanvasView *canvas_view);
65         ~StateEyedrop_Context();
66
67         Smach::event_result event_stop_handler(const Smach::event& x);
68
69         Smach::event_result event_refresh_handler(const Smach::event& x);
70
71         Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
72
73 }; // END of class StateEyedrop_Context
74
75 /* === G L O B A L S ======================================================= */
76
77 StateEyedrop studio::state_eyedrop;
78
79 /* === P R O C E D U R E S ================================================= */
80
81 /* === M E T H O D S ======================================================= */
82
83 StateEyedrop::StateEyedrop():
84         Smach::state<StateEyedrop_Context>("eyedrop")
85 {
86         insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateEyedrop_Context::event_stop_handler));
87         insert(event_def(EVENT_STOP,&StateEyedrop_Context::event_stop_handler));
88         insert(event_def(EVENT_REFRESH,&StateEyedrop_Context::event_refresh_handler));
89         insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateEyedrop_Context::event_workarea_mouse_button_down_handler));
90 }
91
92 StateEyedrop::~StateEyedrop()
93 {
94 }
95
96 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
97         canvas_view(canvas_view),
98         is_working(*canvas_view)
99 {
100         synfig::info("Entered Eyedrop State");
101         canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
102
103         App::toolbox->refresh();
104 }
105
106 StateEyedrop_Context::~StateEyedrop_Context()
107 {
108         synfig::info("Left Eyedrop State");
109         canvas_view->work_area->reset_cursor();
110         App::toolbox->refresh();
111 }
112
113 Smach::event_result
114 StateEyedrop_Context::event_stop_handler(const Smach::event& /*x*/)
115 {
116         synfig::info("STATE EYEDROP: Received Stop Event");
117         throw Smach::egress_exception();
118 //      canvas_view->get_smach().pop_state();
119 //      return Smach::RESULT_ACCEPT;
120 }
121
122 Smach::event_result
123 StateEyedrop_Context::event_refresh_handler(const Smach::event& /*x*/)
124 {
125         synfig::info("STATE EYEDROP: Received Refresh Event");
126         canvas_view->work_area->queue_render_preview();
127         return Smach::RESULT_ACCEPT;
128 }
129
130 Smach::event_result
131 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
132 {
133         synfig::info("STATE EYEDROP: Received mouse button down Event");
134         const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
135         if(event.button==BUTTON_LEFT)
136         {
137                 Color color(canvas_view->get_canvas()->get_context().get_color(event.pos));
138                 synfigapp::Main::set_foreground_color(color);
139                 studio::App::dialog_color->set_color(color);
140                 return Smach::RESULT_ACCEPT;
141         }
142         return Smach::RESULT_OK;
143 }