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"
34 #include <synfig/context.h>
36 #include "dialog_color.h"
37 #include "event_mouse.h"
38 #include "event_layerclick.h"
40 #include "canvasview.h"
41 #include <synfigapp/main.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
52 using namespace studio;
54 /* === M A C R O S ========================================================= */
56 /* === C L A S S E S & S T R U C T S ======================================= */
58 class studio::StateEyedrop_Context
60 CanvasView *canvas_view;
61 CanvasView::IsWorking is_working;
64 StateEyedrop_Context(CanvasView *canvas_view);
65 ~StateEyedrop_Context();
67 Smach::event_result event_stop_handler(const Smach::event& x);
69 Smach::event_result event_refresh_handler(const Smach::event& x);
71 Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
73 }; // END of class StateEyedrop_Context
75 /* === G L O B A L S ======================================================= */
77 StateEyedrop studio::state_eyedrop;
79 /* === P R O C E D U R E S ================================================= */
81 /* === M E T H O D S ======================================================= */
83 StateEyedrop::StateEyedrop():
84 Smach::state<StateEyedrop_Context>("eyedrop")
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));
92 StateEyedrop::~StateEyedrop()
96 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
97 canvas_view(canvas_view),
98 is_working(*canvas_view)
100 synfig::info("Entered Eyedrop State");
101 canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
103 App::toolbox->refresh();
106 StateEyedrop_Context::~StateEyedrop_Context()
108 synfig::info("Left Eyedrop State");
109 canvas_view->work_area->reset_cursor();
110 App::toolbox->refresh();
114 StateEyedrop_Context::event_stop_handler(const Smach::event& /*x*/)
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;
123 StateEyedrop_Context::event_refresh_handler(const Smach::event& /*x*/)
125 synfig::info("STATE EYEDROP: Received Refresh Event");
126 canvas_view->work_area->queue_render_preview();
127 return Smach::RESULT_ACCEPT;
131 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
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)
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;
142 return Smach::RESULT_OK;