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