80f60601056f53bdb6de9eeb56a2a4a3f926a291
[synfig.git] / synfig-studio / trunk / 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 **
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.
14 **
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.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "dock_info.h"
33 #include "canvasview.h"
34 #include "workarea.h"
35
36 #include <synfig/canvas.h>
37 #include <synfig/color.h>               // for gamma_in()
38 #include <synfig/context.h>
39
40 #include <gtkmm/separator.h>
41 #include <gtkmm/invisible.h>
42
43 #endif
44
45 /* === U S I N G =========================================================== */
46
47 using namespace std;
48 using namespace etl;
49 using namespace synfig;
50
51 /* === M A C R O S ========================================================= */
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 /* === E N T R Y P O I N T ================================================= */
60
61 void studio::Dock_Info::on_mouse_move()
62 {
63         Point pos = get_canvas_view()->work_area->get_cursor_pos();
64
65         Distance xv(pos[0],Distance::SYSTEM_UNITS);
66         xv.convert(App::distance_system, get_canvas_view()->get_canvas()->rend_desc());
67
68         Distance yv(pos[1],Distance::SYSTEM_UNITS);
69         yv.convert(App::distance_system, get_canvas_view()->get_canvas()->rend_desc());
70
71         //get the color and set the labels
72
73         x.set_text(xv.get_string(3));
74         y.set_text(yv.get_string(3));
75
76         Color c = get_canvas_view()->get_canvas()->get_context().get_color(pos);
77         float cr = c.get_r(),cg = c.get_g(), cb = c.get_b();
78
79         if(use_colorspace_gamma())
80         {
81                 cr = gamma_in(cr);
82                 cg = gamma_in(cg);
83                 cb = gamma_in(cb);
84         }
85
86         r.set_text(strprintf("%.1f%%",cr*100));
87         g.set_text(strprintf("%.1f%%",cg*100));
88         b.set_text(strprintf("%.1f%%",cb*100));
89         a.set_text(strprintf("%.1f%%",c.get_a()*100));
90 }
91
92 studio::Dock_Info::Dock_Info()
93 :Dock_CanvasSpecific("info",_("Info"),Gtk::StockID("synfig-info"))
94 {
95         set_use_scrolled(false);
96
97         Gtk::Table *table = manage(new Gtk::Table);
98
99         //pos labels
100         table->attach(*manage(new Gtk::Label(_("X: "))),0,1,0,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
101         table->attach(*manage(new Gtk::Label(_("Y: "))),0,1,2,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
102
103         //pos
104         table->attach(x,1,2,0,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
105         table->attach(y,1,2,2,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
106
107         //separator
108         table->attach(*manage(new Gtk::VSeparator),2,3,0,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
109
110         //color label
111         table->attach(*manage(new Gtk::Label(_("R: "))),3,4,0,1,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
112         table->attach(*manage(new Gtk::Label(_("G: "))),3,4,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
113         table->attach(*manage(new Gtk::Label(_("B: "))),3,4,2,3,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
114         table->attach(*manage(new Gtk::Label(_("A: "))),3,4,3,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
115
116         //color
117         table->attach(r,4,5,0,1,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
118         table->attach(g,4,5,1,2,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
119         table->attach(b,4,5,2,3,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
120         table->attach(a,4,5,3,4,Gtk::EXPAND|Gtk::FILL,Gtk::SHRINK|Gtk::FILL);
121
122         table->attach(*manage(new Gtk::Label),0,5,4,5);
123
124         table->show_all();
125
126         add(*table);
127 }
128
129 studio::Dock_Info::~Dock_Info()
130 {
131 }
132
133 void studio::Dock_Info::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
134 {
135         mousecon.disconnect();
136
137         if(canvas_view && canvas_view->get_work_area())
138         {
139                 mousecon = get_canvas_view()->work_area->signal_cursor_moved().connect(sigc::mem_fun(*this,&Dock_Info::on_mouse_move));
140         }
141 }