From 07262b2e6e1c5ba27ebdcbe71d34b4a2fe2249f1 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 28 Feb 2003 20:45:23 +0000 Subject: [PATCH] Also add samples (and documentation while am doing this) to Color, as it is again, not obvious how to use it svn path=/trunk/gtk-sharp/; revision=12071 --- doc/en/Gdk/Color.xml | 140 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 14 deletions(-) diff --git a/doc/en/Gdk/Color.xml b/doc/en/Gdk/Color.xml index 7109313ae..2234b3db2 100644 --- a/doc/en/Gdk/Color.xml +++ b/doc/en/Gdk/Color.xml @@ -7,8 +7,36 @@ Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details. - To be added - To be added + Describes an allocated or unallocated color. + + + The Gdk.Color structure is used to describe an allocated or + unallocated color. Unallocated colors only have the red, + green and blue ushort values initialized. Colors are + allocated using the + method. After a color is allocated the value in the field is valid. + + + + DrawRedLine (Gdk.Drawable drawable) + { + Gdk.GC gc = new Gdk.GC (drawable); + + Gdk.Color red_color = new Gdk.Color (0xff, 0, 0); + + // Use the system colormap, easy. + Gdk.Colormap colormap = Gdk.Colormap.System; + + colormap.AllocColor (red_color, true, true); + + // Now you can use it + drawable.DrawLine (gc, 0, 0, 100, 100); + } + + + System.ValueType @@ -36,8 +64,20 @@ - To be added - To be added + Pixel value for the color + + + Colors are specified in Gdk by their red, green and blue + elements. But before the color can be used, the color + has to be allocated in a given colormap. The value of the + allocation is stored in this pixel field and it is the + token used to render the color. + + + The pixel value is initialized when using the method. + + @@ -48,8 +88,8 @@ - To be added - To be added + Red element of the color + @@ -60,8 +100,8 @@ - To be added - To be added + Green element of the color + @@ -72,8 +112,8 @@ - To be added - To be added + Blue element of the color. + @@ -99,6 +139,28 @@ mapped into the 16-bit value space. This is just a convenience routine to initialize this structure. + + To use the Gdk.Color you must allocate it within the + current colormap. + + + + DrawRedLine (Gdk.Drawable drawable) + { + Gdk.GC gc = new Gdk.GC (drawable); + + Gdk.Color red_color = new Gdk.Color (0xff, 0, 0); + + // Use the system colormap, easy. + Gdk.Colormap colormap = Gdk.Colormap.System; + + colormap.AllocColor (red_color, true, true); + + // Now you can use it + drawable.DrawLine (gc, 0, 0, 100, 100); + } + + @@ -118,6 +180,24 @@ Use this constructor to create new color values based on an existing color from a . + + + DrawRedLine (Gdk.Drawable drawable) + { + Gdk.GC gc = new Gdk.GC (drawable); + + Gdk.Color red_color = new Gdk.Color (0xff, 0, 0); + + // Use the system colormap, easy. + Gdk.Colormap colormap = Gdk.Colormap.System; + + colormap.AllocColor (red_color, true, true); + + // Now you can use it + drawable.DrawLine (gc, 0, 0, 100, 100); + } + + @@ -133,10 +213,42 @@ To be added - To be added: an object of type 'string' - To be added: an object of type 'Gdk.Color&' - To be added: an object of type 'int' - To be added + A string specification for the color. + A structure where the colors are generated + Non-zero on success + + + Parses a textual specification of a color and fill in the + red, green, and blue fields of the Gdk.Color structure. + The color is not allocated, you must call + yourself. + + + The text string can be in any of the forms accepted by + XParseColor; these include name for a color from rgb.txt, + such as DarkSlateGray, or a hex specification such as + 305050. + + + + DrawRedLine (Gdk.Drawable drawable) + { + Gdk.GC gc = new Gdk.GC (drawable); + Gdk.Color red_color; + Gdk.Color.Parse ("red", ref red_color); + + // Use the system colormap, easy. + Gdk.Colormap colormap = Gdk.Colormap.System; + + colormap.AllocColor (red_color, true, true); + + // Now you can use it + drawable.DrawLine (gc, 0, 0, 100, 100); + } + + +