summaryrefslogtreecommitdiff
path: root/docs/faq/gtkfaq.sgml
diff options
context:
space:
mode:
authorPST 1998 Shawn T. Amundson <amundson@gimp.org>1998-03-02 00:32:52 +0000
committerShawn Amundson <amundson@src.gnome.org>1998-03-02 00:32:52 +0000
commitf6f1ce01c6b33fe75e32c7e76ef5e7fc9ce494ab (patch)
treedca8f578054ea33fd2973ee3eb6d6d38e4a60342 /docs/faq/gtkfaq.sgml
parent80fd0a0c0068cd09d120e1a74df26cf82004a491 (diff)
downloadgdk-pixbuf-f6f1ce01c6b33fe75e32c7e76ef5e7fc9ce494ab.tar.gz
Required changes for version change to 0.99.4
Sun Mar 1 15:18:38 PST 1998 Shawn T. Amundson <amundson@gimp.org> * Required changes for version change to 0.99.4 * gtk/gtktree.[ch]: patch from J. Bolliet to correct some bugs * gtk/testgtk.c: added test here from J. Bolliet, removed testtree * gtk/clist: gtk-abilleira-981602-0, allows gtk_clist_set_pixmap and gtk_clist_set_pixtext to not require a mask * gdk/gdkdraw.c,gdk.h: gtk-trow-980217-0 adds gdk_draw_lines and fixes some things about gdk_draw_polygon
Diffstat (limited to 'docs/faq/gtkfaq.sgml')
-rw-r--r--docs/faq/gtkfaq.sgml54
1 files changed, 54 insertions, 0 deletions
diff --git a/docs/faq/gtkfaq.sgml b/docs/faq/gtkfaq.sgml
index b8efe3c4a..8daeaf7d7 100644
--- a/docs/faq/gtkfaq.sgml
+++ b/docs/faq/gtkfaq.sgml
@@ -696,6 +696,60 @@ uses glib (see below), it will be more portable and safer to use on multiple pla
<!-- Examples, anybody? I've been mulling some over. NF -->
+<sect1>How do I use color allocation?
+<p>
+One of the nice things about GDK is that it's based on top of Xlib; this is also
+a problem, especially in the area of color management. If you want to use color
+in your program (drawing a rectangle or such, your code should look something like
+this:
+<tscreen>
+<verb>
+{
+ GdkColor *color;
+ int width, height;
+ GtkWidget *widget;
+
+ ...
+
+ /* first, create a GC to draw on */
+ gc = gdk_gc_new(widget->window);
+
+ /* find proper dimensions for rectangle */
+ gdk_window_get_size(widget->window, &width, &height);
+
+ /* the color we want to use */
+ color = (GdkColor *)malloc(sizeof(GdkColor));
+
+ /* red, green, and blue are passed values, indicating the RGB triple
+ * of the color we want to draw. Note that the values of the RGB components
+ * within the GdkColor are taken from 0 to 65535, not 0 to 255.
+ */
+ color->red = red * (65535/255);
+ color->green = green * (65535/255);
+ color->blue = blue * (65535/255);
+
+ /* the pixel value indicates the index in the colormap of the color.
+ * it is simply a combination of the RGB values we set earlier
+ */
+ color->pixel = (gulong)(red*65536 + green*256 + blue);
+
+ /* However, the pixel valule is only truly valid on 24-bit (TrueColor)
+ * displays. Therefore, this call is required so that GDK and X can
+ * give us the closest color available in the colormap
+ */
+ gdk_color_alloc(gtk_widget_get_colormap(widget), color);
+
+ /* set the foreground to our color */
+ gdk_gc_set_foreground(gc, color);
+
+ /* draw the rectangle */
+ gdk_draw_rectangle(widget->window, gc, 1, 0, 0, width, height);
+
+ ...
+}
+</verb>
+</tscreen>
+
<!-- ***************************************************************** -->
<sect>About glib
<!-- ***************************************************************** -->