1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_color.cpp
3 ** \brief Template File
5 ** $Id: widget_color.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "widget_color.h"
35 #include <gtkmm/drawingarea.h>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 #define use_colorspace_gamma() App::use_colorspace_gamma
49 #define colorspace_gamma() (2.2f)
50 #define gamma_in(x) ((x>0)?pow((float)x,1.0f/colorspace_gamma()):-pow((float)-x,1.0f/colorspace_gamma()))
51 #define gamma_out(x) ((x>0)?pow((float)x,colorspace_gamma()):-pow((float)-x,colorspace_gamma()))
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
58 studio::colorconv_synfig2gdk(const synfig::Color &c_)
60 const synfig::Color c(c_.clamped());
63 256*App::gamma.r_F32_to_U8(c.get_r()),
64 256*App::gamma.g_F32_to_U8(c.get_g()),
65 256*App::gamma.b_F32_to_U8(c.get_b())
71 studio::render_color_to_window(const Glib::RefPtr<Gdk::Drawable>& window,const Gdk::Rectangle& ca,const synfig::Color &color)
73 const int height(ca.get_height());
74 const int width(ca.get_width());
76 const int square_size(height/2);
78 Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(window));
80 if(color.get_alpha()!=1.0)
82 // In this case we need to render the alpha squares
84 const Color bg1(Color::blend(color,Color(0.75, 0.75, 0.75),1.0).clamped());
85 const Color bg2(Color::blend(color,Color(0.5, 0.5, 0.5),1.0).clamped());
87 Gdk::Color gdk_c1(colorconv_synfig2gdk(bg1));
88 Gdk::Color gdk_c2(colorconv_synfig2gdk(bg2));
91 for(int i=0;i<width;i+=square_size)
93 const int square_width(min(square_size,width-i));
97 gc->set_rgb_fg_color(gdk_c1);
98 window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), square_width, square_size);
100 gc->set_rgb_fg_color(gdk_c2);
101 window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+square_size, square_width, square_size);
106 gc->set_rgb_fg_color(gdk_c2);
107 window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y(), square_width, square_size);
109 gc->set_rgb_fg_color(gdk_c1);
110 window->draw_rectangle(gc, true, ca.get_x()+i, ca.get_y()+square_size, square_width, square_size);
117 // In this case we have a solid color to use
118 Gdk::Color gdk_c1(colorconv_synfig2gdk(color));
120 gc->set_rgb_fg_color(gdk_c1);
121 window->draw_rectangle(gc, true, ca.get_x(), ca.get_y(), width-1, height-1);
123 gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
124 window->draw_rectangle(gc, false, ca.get_x()+1, ca.get_y()+1, width-3, height-3);
125 gc->set_rgb_fg_color(Gdk::Color("#000000"));
126 window->draw_rectangle(gc, false, ca.get_x(), ca.get_y(), width-1, height-1);
129 /* === C L A S S E S ======================================================= */
132 /* === M E T H O D S ======================================================= */
134 Widget_Color::Widget_Color()
136 color=Color(0,0,0,0);
137 set_size_request(-1,16);
139 signal_expose_event().connect(sigc::mem_fun(*this, &studio::Widget_Color::redraw));
140 add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
144 Widget_Color::~Widget_Color()
149 Widget_Color::set_value(const synfig::Color &data)
151 assert(data.is_valid());
156 const synfig::Color &
157 Widget_Color::get_value()
159 assert(color.is_valid());
164 Widget_Color::on_event(GdkEvent *event)
168 case GDK_BUTTON_PRESS:
169 if(event->button.button==1)
174 if(event->button.button==3)
188 Widget_Color::redraw(GdkEventExpose*bleh)
190 //Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(get_window()));
192 const int h(get_height());
193 const int w(get_width());
195 render_color_to_window(get_window(),Gdk::Rectangle(0,0,w,h),color);