my log
[synfig.git] / synfig-studio / trunk / src / gtkmm / state_eyedrop.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file state_eyedrop.cpp
3 **      \brief Template File
4 **
5 **      $Id: state_eyedrop.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "state_eyedrop.h"
32 #include "workarea.h"
33 #include <synfig/context.h>
34 #include "app.h"
35 #include "dialog_color.h"
36 #include "event_mouse.h"
37 #include "event_layerclick.h"
38 #include "toolbox.h"
39 #include "canvasview.h"
40 #include <synfigapp/main.h>
41
42 #endif
43
44 /* === U S I N G =========================================================== */
45
46 using namespace std;
47 using namespace etl;
48 using namespace synfig;
49 using namespace studio;
50
51 /* === M A C R O S ========================================================= */
52
53 /* === C L A S S E S & S T R U C T S ======================================= */
54
55 class studio::StateEyedrop_Context
56 {
57         CanvasView *canvas_view;
58         CanvasView::IsWorking is_working;
59
60 public:
61         StateEyedrop_Context(CanvasView *canvas_view);
62         ~StateEyedrop_Context();
63         
64         Smach::event_result event_stop_handler(const Smach::event& x);
65
66         Smach::event_result event_refresh_handler(const Smach::event& x);
67
68         Smach::event_result event_workarea_mouse_button_down_handler(const Smach::event& x);
69
70 }; // END of class StateEyedrop_Context
71
72 /* === G L O B A L S ======================================================= */
73
74 StateEyedrop studio::state_eyedrop;
75
76 /* === P R O C E D U R E S ================================================= */
77
78 /* === M E T H O D S ======================================================= */
79
80 StateEyedrop::StateEyedrop():
81         Smach::state<StateEyedrop_Context>("eyedrop")
82 {
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));
87 }       
88
89 StateEyedrop::~StateEyedrop()
90 {
91 }
92
93 StateEyedrop_Context::StateEyedrop_Context(CanvasView *canvas_view):
94         canvas_view(canvas_view),
95         is_working(*canvas_view)
96 {
97         synfig::info("Enterted Eyedrop State");
98         canvas_view->work_area->set_cursor(Gdk::Cursor(Gdk::CROSSHAIR));
99         
100         App::toolbox->refresh();
101 }
102
103 StateEyedrop_Context::~StateEyedrop_Context()
104 {
105         synfig::info("Left Eyedrop State");
106         canvas_view->work_area->reset_cursor();
107         App::toolbox->refresh();
108 }
109
110 Smach::event_result
111 StateEyedrop_Context::event_stop_handler(const Smach::event& x)
112 {
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;
117 }
118
119 Smach::event_result
120 StateEyedrop_Context::event_refresh_handler(const Smach::event& x)
121 {
122         synfig::info("STATE EYEDROP: Received Refresh Event");
123         canvas_view->work_area->queue_render_preview();
124         return Smach::RESULT_ACCEPT;
125 }
126
127 Smach::event_result
128 StateEyedrop_Context::event_workarea_mouse_button_down_handler(const Smach::event& x)
129 {
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)
133         {
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;
138         }
139         return Smach::RESULT_OK;
140 }