1 /* === S Y N F I G ========================================================= */
2 /*! \file state_eyedrop.cpp
3 ** \brief Template File
5 ** $Id: state_eyedrop.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "state_eyedrop.h"
33 #include <synfig/context.h>
35 #include "dialog_color.h"
36 #include "event_mouse.h"
37 #include "event_layerclick.h"
39 #include "canvasview.h"
40 #include <synfigapp/main.h>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
49 using namespace studio;
51 /* === M A C R O S ========================================================= */
53 /* === C L A S S E S & S T R U C T S ======================================= */
55 class studio::StateEyedrop_Context
57 CanvasView *canvas_view;
58 CanvasView::IsWorking is_working;
61 StateEyedrop_Context(CanvasView *canvas_view);
62 ~StateEyedrop_Context();
64 Smach::event_result event_stop_handler(const Smach::event& x);
66 Smach::event_result event_refresh_handler(const Smach::event& x);
68 Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
70 }; // END of class StateEyedrop_Context
72 /* === G L O B A L S ======================================================= */
74 StateEyedrop studio::state_eyedrop;
76 /* === P R O C E D U R E S ================================================= */
78 /* === M E T H O D S ======================================================= */
80 StateEyedrop::StateEyedrop():
81 Smach::state<StateEyedrop_Context>("eyedrop")
83 insert(event_def(EVENT_LAYER_SELECTION_CHANGED,&StateEyedrop_Context::event_stop_handler));
84 insert(event_def(EVENT_STOP,&StateEyedrop_Context::event_stop_handler));
85 insert(event_def(EVENT_REFRESH,&StateEyedrop_Context::event_refresh_handler));
86 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateEyedrop_Context::event_workarea_mouse_button_down_handler));
89 StateEyedrop::~StateEyedrop()
93 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
94 canvas_view(canvas_view),
95 is_working(*canvas_view)
97 synfig::info("Enterted Eyedrop State");
98 canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
100 App::toolbox->refresh();
103 StateEyedrop_Context::~StateEyedrop_Context()
105 synfig::info("Left Eyedrop State");
106 canvas_view->work_area->reset_cursor();
107 App::toolbox->refresh();
111 StateEyedrop_Context::event_stop_handler(const Smach::event& x)
113 synfig::info("STATE EYEDROP: Received Stop Event");
114 throw Smach::egress_exception();
115 // canvas_view->get_smach().pop_state();
116 // return Smach::RESULT_ACCEPT;
120 StateEyedrop_Context::event_refresh_handler(const Smach::event& x)
122 synfig::info("STATE EYEDROP: Received Refresh Event");
123 canvas_view->work_area->queue_render_preview();
124 return Smach::RESULT_ACCEPT;
128 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
130 synfig::info("STATE EYEDROP: Received mouse button down Event");
131 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
132 if(event.button==BUTTON_LEFT)
134 Color color(canvas_view->get_canvas()->get_context().get_color(event.pos));
135 synfigapp::Main::set_foreground_color(color);
136 studio::App::dialog_color->set_color(color);
137 return Smach::RESULT_ACCEPT;
139 return Smach::RESULT_OK;