Xfce
Foundation Classes |
|||
« Main Page | Index | |||
Color SelectionThe color selection widget is, not
surprisingly, a widget for
interactive selection of colors. This composite widget lets the user
select a color by manipulating RGB (Red, Green, Blue) and HSV (Hue,
Saturation, Value) triples. This is done either by adjusting single
values with sliders or entries, or by picking the desired color from a
hue-saturation wheel/value bar. Optionally, the opacity of the color
can
also be set.
The color selection widget currently emits only one signal, color_changed, which is emitted whenever the current color in the widget changes, either when the user changes it or if it's set explicitly through Gtk::ColorSelection::set_color(). Lets have a look at what the color selection widget has to offer us. The widget comes in two flavours: Gtk::ColorSelection and Gtk::ColorSelectionDialog. ColorSelection(); You'll probably not be using this
constructor directly. It creates an
orphan ColorSelection widget which you'll have to parent yourself. The
ColorSelection widget inherits from the Gtk::VBox.
ColorSelectionDialog(); These are the most common color
selection constructors. Both
constructors create a ColorSelectionDialog, the first with the default
title which is just the program name and the second with the 'title'
specified. A ColorSelectionDialog consists of a Frame containing a
ColorSelection widget, an HSeparator and an HBox with three buttons,
"Ok", "Cancel" and "Help". You can reach these buttons by using one of
the corresponding accessors:
Gtk::Button* ok_button() const; The color selection widget
supports adjusting the opacity of a color
(also known as the alpha channel). This is disabled by default. Calling
the following method with 'has_opacity' set to true
enables opacity. Likewise, has_opacity set to false
will disable opacity.
void
set_has_opacity_control(bool has_opacity); You can set the current color
explicitly by calling
Gtk::ColorSelection::set_current_color() with a reference to a
Gdk::Color. Setting the opacity (alpha channel) is done with
Gtk::ColorSelection::set_current_alpha(). The alpha value should be
between 0 (fully transparent) and 65636 (fully opaque).
void
set_current_color(const Gdk::Color&
color); When you need to query the current color, typically when you've received a 'color_changed' signal, you use these methods: Gdk::Color
get_current_color() const; Color Selection ExampleHere's a simple example
demonstrating the use of the
ColorSelectionDialog. The program displays a window containing a
drawing
area. Clicking on it opens a color selection dialog, and changing the
color in the color selection dialog changes the background color of the
window.
The header file for the Color
Selection example is
<colorselection.hh>:
#include <xfc/main.hh> and then source file is <colorselection.cc>: #include "colorselection.hh" Compiling Color Selection
If you compiled and installed XFC yourself, you will find the source
code for Color Selection in the
<examples/colorselection> source directory along with a Makefile.
If
XFC came pre-installed, or you installed it from an RPM package, you
will
find the source code in the
</usr/share/doc/xfcui-X.X/examples/colorselection> subdirectory.
In
this case you will have to create the Makefile yourself (replace X.X
with the
version number of the libXFCui library you have installed). |
Copyright © 2004-2005 The XFC Development Team | Top |
XFC
4.4 |