Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc3 / 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 #endif
45
46 /* === U S I N G =========================================================== */
47
48 using namespace std;
49 using namespace etl;
50 using namespace synfig;
51
52 /* === M A C R O S ========================================================= */
53
54 /* === G L O B A L S ======================================================= */
55
56 /* === P R O C E D U R E S ================================================= */
57
58 /* === M E T H O D S ======================================================= */
59
60 /* === E N T R Y P O I N T ================================================= */
61
62 void studio::Dock_Info::on_mouse_move()
63 {
64         Point pos = get_canvas_view()->work_area->get_cursor_pos();
65
66         Distance xv(pos[0],Distance::SYSTEM_UNITS);
67         xv.convert(App::distance_system, get_canvas_view()->get_canvas()->rend_desc());
68
69         Distance yv(pos[1],Distance::SYSTEM_UNITS);
70         yv.convert(App::distance_system, get_canvas_view()->get_canvas()->rend_desc());
71
72         //get the color and set the labels
73
74         x.set_text(xv.get_string(3));
75         y.set_text(yv.get_string(3));
76
77         Color c = get_canvas_view()->get_canvas()->get_context().get_color(pos);
78         float cr = c.get_r(),cg = c.get_g(), cb = c.get_b();
79
80         if(use_colorspace_gamma())
81         {
82                 cr = gamma_in(cr);
83                 cg = gamma_in(cg);
84                 cb = gamma_in(cb);
85         }
86
87         r.set_text(strprintf("%.1f%%",cr*100));
88         g.set_text(strprintf("%.1f%%",cg*100));
89         b.set_text(strprintf("%.1f%%",cb*100));
90         a.set_text(strprintf("%.1f%%",c.get_a()*100));
91 }
92
93 studio::Dock_Info::Dock_Info()
94 :Dock_CanvasSpecific("info",_("Info"),Gtk::StockID("synfig-info"))
95 {
96         set_use_scrolled(false);
97
98         Gtk::Table *table = manage(new Gtk::Table);
99
100         //pos labels
101         table->attach(*manage(new Gtk::Label(_("X: "))),0,1,0,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
102         table->attach(*manage(new Gtk::Label(_("Y: "))),0,1,2,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
103
104         //pos
105         table->attach(x,1,2,0,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
106         table->attach(y,1,2,2,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
107
108         //separator
109         table->attach(*manage(new Gtk::VSeparator),2,3,0,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
110
111         //color label
112         table->attach(*manage(new Gtk::Label(_("R: "))),3,4,0,1,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
113         table->attach(*manage(new Gtk::Label(_("G: "))),3,4,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
114         table->attach(*manage(new Gtk::Label(_("B: "))),3,4,2,3,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
115         table->attach(*manage(new Gtk::Label(_("A: "))),3,4,3,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
116
117         //color
118         table->attach(r,4,5,0,1,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
119         table->attach(g,4,5,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
120         table->attach(b,4,5,2,3,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
121         table->attach(a,4,5,3,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
122
123         table->attach(*manage(new Gtk::Label),0,5,4,5);
124
125         table->show_all();
126
127         add(*table);
128 }
129
130 studio::Dock_Info::~Dock_Info()
131 {
132 }
133
134 void studio::Dock_Info::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
135 {
136         mousecon.disconnect();
137
138         if(canvas_view && canvas_view->get_work_area())
139         {
140                 mousecon = get_canvas_view()->work_area->signal_cursor_moved().connect(sigc::mem_fun(*this,&Dock_Info::on_mouse_move));
141         }
142 }