Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.08 / src / gtkmm / dock_info.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dock_info.cpp
3 **      \brief Dock Info File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "dock_info.h"
34 #include "canvasview.h"
35 #include "workarea.h"
36
37 #include <synfig/canvas.h>
38 #include <synfig/color.h>               // for gamma_in()
39 #include <synfig/context.h>
40
41 #include <gtkmm/separator.h>
42 #include <gtkmm/invisible.h>
43
44 #include "general.h"
45
46 #endif
47
48 /* === U S I N G =========================================================== */
49
50 using namespace std;
51 using namespace etl;
52 using namespace synfig;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 /* === M E T H O D S ======================================================= */
61
62 /* === E N T R Y P O I N T ================================================= */
63
64 void studio::Dock_Info::on_mouse_move()
65 {
66         Point pos = get_canvas_view()->work_area->get_cursor_pos();
67
68         Distance xv(pos[0],Distance::SYSTEM_UNITS);
69         xv.convert(App::distance_system, get_canvas_view()->get_canvas()->rend_desc());
70
71         Distance yv(pos[1],Distance::SYSTEM_UNITS);
72         yv.convert(App::distance_system, get_canvas_view()->get_canvas()->rend_desc());
73
74         //get the color and set the labels
75
76         x.set_text(xv.get_string(3));
77         y.set_text(yv.get_string(3));
78
79         Color c = get_canvas_view()->get_canvas()->get_context().get_color(pos);
80         float cr = c.get_r(),cg = c.get_g(), cb = c.get_b();
81
82         if(use_colorspace_gamma())
83         {
84                 cr = gamma_in(cr);
85                 cg = gamma_in(cg);
86                 cb = gamma_in(cb);
87         }
88
89         r.set_text(strprintf("%.1f%%",cr*100));
90         g.set_text(strprintf("%.1f%%",cg*100));
91         b.set_text(strprintf("%.1f%%",cb*100));
92         a.set_text(strprintf("%.1f%%",c.get_a()*100));
93 }
94
95 studio::Dock_Info::Dock_Info()
96 :Dock_CanvasSpecific("info",_("Info"),Gtk::StockID("synfig-info"))
97 {
98         set_use_scrolled(false);
99
100         Gtk::Table *table = manage(new Gtk::Table);
101
102         //pos labels
103         table->attach(*manage(new Gtk::Label(_("X: "))),0,1,0,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
104         table->attach(*manage(new Gtk::Label(_("Y: "))),0,1,2,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
105
106         //pos
107         table->attach(x,1,2,0,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
108         table->attach(y,1,2,2,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
109
110         //separator
111         table->attach(*manage(new Gtk::VSeparator),2,3,0,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
112
113         //color label
114         table->attach(*manage(new Gtk::Label(_("R: "))),3,4,0,1,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
115         table->attach(*manage(new Gtk::Label(_("G: "))),3,4,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
116         table->attach(*manage(new Gtk::Label(_("B: "))),3,4,2,3,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
117         table->attach(*manage(new Gtk::Label(_("A: "))),3,4,3,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
118
119         //color
120         table->attach(r,4,5,0,1,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
121         table->attach(g,4,5,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
122         table->attach(b,4,5,2,3,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
123         table->attach(a,4,5,3,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
124
125         table->attach(*manage(new Gtk::Label),0,5,4,5);
126
127         table->show_all();
128
129         add(*table);
130 }
131
132 studio::Dock_Info::~Dock_Info()
133 {
134 }
135
136 void studio::Dock_Info::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
137 {
138         mousecon.disconnect();
139
140         if(canvas_view && canvas_view->get_work_area())
141         {
142                 mousecon = get_canvas_view()->work_area->signal_cursor_moved().connect(sigc::mem_fun(*this,&Dock_Info::on_mouse_move));
143         }
144 }