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