Code

height=12
[inkscape.git] / src / ui / widget / color-preview.cpp
1 /** \file
2  * Implemenmtation of a simple color preview widget
3  *
4  * Author:
5  *   Lauris Kaplinski <lauris@kaplinski.com>
6  *   Ralf Stephan <ralf@ark.in-berlin.de>
7  *
8  * Copyright (C) 2001-2005 Authors
9  * Copyright (C) 2001 Ximian, Inc.
10  *
11  * Released under GNU GPL, read the file 'COPYING' for more information
12  */
14 #include "display/nr-plain-stuff-gdk.h"
15 #include "color-preview.h"
17 #define SPCP_DEFAULT_WIDTH 32
18 #define SPCP_DEFAULT_HEIGHT 12
20 namespace Inkscape {
21     namespace UI {
22         namespace Widget {
24 ColorPreview::ColorPreview (guint32 rgba)
25 {
26     _rgba = rgba;
27     set_flags (Gtk::NO_WINDOW);
28 }
30 void
31 ColorPreview::on_size_request (Gtk::Requisition *req)
32 {
33     req->width = SPCP_DEFAULT_WIDTH;
34     req->height = SPCP_DEFAULT_HEIGHT;
35 }
37 void
38 ColorPreview::on_size_allocate (Gtk::Allocation &all)
39 {
40     set_allocation (all);
41     if (is_drawable())
42         queue_draw();
43 }
45 bool
46 ColorPreview::on_expose_event (GdkEventExpose *event)
47 {
48     if (is_drawable())
49         paint (&event->area);
51     return true;
52 }
54 void
55 ColorPreview::setRgba32 (guint32 rgba)
56 {
57     _rgba = rgba;
59     if (is_drawable())
60         queue_draw();
61 }
63 void
64 ColorPreview::paint (GdkRectangle *area)
65 {
66     GdkRectangle warea, carea;
67     GdkRectangle wpaint, cpaint;
68     gint w2;
70     const Gtk::Allocation& allocation = get_allocation();
71     warea.x = allocation.get_x();
72     warea.y = allocation.get_y();
73     warea.width = allocation.get_width();
74     warea.height = allocation.get_height();
76     if (!gdk_rectangle_intersect (area, &warea, &wpaint)) 
77         return;
79     /* Transparent area */
81     w2 = warea.width / 2;
83     carea.x = warea.x;
84     carea.y = warea.y;
85     carea.width = w2;
86     carea.height = warea.height;
88     if (gdk_rectangle_intersect (area, &carea, &cpaint)) {
89         nr_gdk_draw_rgba32_solid (get_window()->gobj(), 
90                                     get_style()->get_black_gc()->gobj(),
91                                     cpaint.x, cpaint.y,
92                                     cpaint.width, cpaint.height,
93                                     _rgba);
94     }
96     /* Solid area */
98     carea.x = warea.x + w2;
99     carea.y = warea.y;
100     carea.width = warea.width - w2;
101     carea.height = warea.height;
103     if (gdk_rectangle_intersect (area, &carea, &cpaint)) {
104         nr_gdk_draw_rgba32_solid (get_window()->gobj(), 
105                                           get_style()->get_black_gc()->gobj(),
106                                           cpaint.x, cpaint.y,
107                                           cpaint.width, cpaint.height,
108                                           _rgba | 0xff);
109     }
112 }}}
114 /*
115   Local Variables:
116   mode:c++
117   c-file-style:"stroustrup"
118   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119   indent-tabs-mode:nil
120   fill-column:99
121   End:
122 */