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