1 /* === S Y N F I G ========================================================= */
2 /*! \file state_eyedrop.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "state_eyedrop.h"
33 #include "state_normal.h"
35 #include <synfig/context.h>
37 #include "dialogs/dialog_color.h"
38 #include "event_mouse.h"
39 #include "event_layerclick.h"
41 #include "canvasview.h"
42 #include <synfigapp/main.h>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 /* === C L A S S E S & S T R U C T S ======================================= */
59 class studio::StateEyedrop_Context
61 CanvasView *canvas_view;
62 CanvasView::IsWorking is_working;
65 StateEyedrop_Context(CanvasView *canvas_view);
66 ~StateEyedrop_Context();
68 Smach::event_result event_stop_handler(const Smach::event& x);
70 Smach::event_result event_refresh_handler(const Smach::event& x);
72 Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
74 }; // END of class StateEyedrop_Context
76 /* === G L O B A L S ======================================================= */
78 StateEyedrop studio::state_eyedrop;
80 /* === P R O C E D U R E S ================================================= */
82 /* === M E T H O D S ======================================================= */
84 StateEyedrop::StateEyedrop():
85 Smach::state<StateEyedrop_Context>("eyedrop")
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));
93 StateEyedrop::~StateEyedrop()
97 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
98 canvas_view(canvas_view),
99 is_working(*canvas_view)
101 synfig::info("Entered Eyedrop State");
102 canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
104 App::toolbox->refresh();
107 StateEyedrop_Context::~StateEyedrop_Context()
109 synfig::info("Left Eyedrop State");
110 canvas_view->work_area->reset_cursor();
111 App::toolbox->refresh();
115 StateEyedrop_Context::event_stop_handler(const Smach::event& /*x*/)
117 //synfig::info("STATE EYEDROP: Received Stop Event");
118 //throw Smach::egress_exception();
120 return Smach::RESULT_OK;
121 // canvas_view->get_smach().pop_state();
122 // return Smach::RESULT_ACCEPT;
126 StateEyedrop_Context::event_refresh_handler(const Smach::event& /*x*/)
128 synfig::info("STATE EYEDROP: Received Refresh Event");
129 canvas_view->work_area->queue_render_preview();
130 return Smach::RESULT_ACCEPT;
134 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
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)
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;
145 return Smach::RESULT_OK;