Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc1 / 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 #endif
44
45 /* === U S I N G =========================================================== */
46
47 using namespace std;
48 using namespace etl;
49 using namespace synfig;
50 using namespace studio;
51
52 /* === M A C R O S ========================================================= */
53
54 /* === C L A S S E S & S T R U C T S ======================================= */
55
56 class studio::StateEyedrop_Context
57 {
58         CanvasView *canvas_view;
59         CanvasView::IsWorking is_working;
60
61 public:
62         StateEyedrop_Context(CanvasView *canvas_view);
63         ~StateEyedrop_Context();
64
65         Smach::event_result event_stop_handler(const Smach::event& x);
66
67         Smach::event_result event_refresh_handler(const Smach::event& x);
68
69         Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
70
71 }; // END of class StateEyedrop_Context
72
73 /* === G L O B A L S ======================================================= */
74
75 StateEyedrop studio::state_eyedrop;
76
77 /* === P R O C E D U R E S ================================================= */
78
79 /* === M E T H O D S ======================================================= */
80
81 StateEyedrop::StateEyedrop():
82         Smach::state<StateEyedrop_Context>("eyedrop")
83 {
84         insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateEyedrop_Context::event_stop_handler));
85         insert(event_def(EVENT_STOP,&StateEyedrop_Context::event_stop_handler));
86         insert(event_def(EVENT_REFRESH,&StateEyedrop_Context::event_refresh_handler));
87         insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateEyedrop_Context::event_workarea_mouse_button_down_handler));
88 }
89
90 StateEyedrop::~StateEyedrop()
91 {
92 }
93
94 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
95         canvas_view(canvas_view),
96         is_working(*canvas_view)
97 {
98         synfig::info("Enterted Eyedrop State");
99         canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
100
101         App::toolbox->refresh();
102 }
103
104 StateEyedrop_Context::~StateEyedrop_Context()
105 {
106         synfig::info("Left Eyedrop State");
107         canvas_view->work_area->reset_cursor();
108         App::toolbox->refresh();
109 }
110
111 Smach::event_result
112 StateEyedrop_Context::event_stop_handler(const Smach::event& /*x*/)
113 {
114         synfig::info("STATE EYEDROP: Received Stop Event");
115         throw Smach::egress_exception();
116 //      canvas_view->get_smach().pop_state();
117 //      return Smach::RESULT_ACCEPT;
118 }
119
120 Smach::event_result
121 StateEyedrop_Context::event_refresh_handler(const Smach::event& /*x*/)
122 {
123         synfig::info("STATE EYEDROP: Received Refresh Event");
124         canvas_view->work_area->queue_render_preview();
125         return Smach::RESULT_ACCEPT;
126 }
127
128 Smach::event_result
129 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
130 {
131         synfig::info("STATE EYEDROP: Received mouse button down Event");
132         const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
133         if(event.button==BUTTON_LEFT)
134         {
135                 Color color(canvas_view->get_canvas()->get_context().get_color(event.pos));
136                 synfigapp::Main::set_foreground_color(color);
137                 studio::App::dialog_color->set_color(color);
138                 return Smach::RESULT_ACCEPT;
139         }
140         return Smach::RESULT_OK;
141 }