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>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === C L A S S E S & S T R U C T S ======================================= */
56 class studio::StateEyedrop_Context
58 CanvasView *canvas_view;
59 CanvasView::IsWorking is_working;
62 StateEyedrop_Context(CanvasView *canvas_view);
63 ~StateEyedrop_Context();
65 Smach::event_result event_stop_handler(const Smach::event& x);
67 Smach::event_result event_refresh_handler(const Smach::event& x);
69 Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
71 }; // END of class StateEyedrop_Context
73 /* === G L O B A L S ======================================================= */
75 StateEyedrop studio::state_eyedrop;
77 /* === P R O C E D U R E S ================================================= */
79 /* === M E T H O D S ======================================================= */
81 StateEyedrop::StateEyedrop():
82 Smach::state<StateEyedrop_Context>("eyedrop")
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));
90 StateEyedrop::~StateEyedrop()
94 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
95 canvas_view(canvas_view),
96 is_working(*canvas_view)
98 synfig::info("Enterted Eyedrop State");
99 canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
101 App::toolbox->refresh();
104 StateEyedrop_Context::~StateEyedrop_Context()
106 synfig::info("Left Eyedrop State");
107 canvas_view->work_area->reset_cursor();
108 App::toolbox->refresh();
112 StateEyedrop_Context::event_stop_handler(const Smach::event& /*x*/)
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;
121 StateEyedrop_Context::event_refresh_handler(const Smach::event& /*x*/)
123 synfig::info("STATE EYEDROP: Received Refresh Event");
124 canvas_view->work_area->queue_render_preview();
125 return Smach::RESULT_ACCEPT;
129 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
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)
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;
140 return Smach::RESULT_OK;