Using GtkPreview/gtk_preview_draw_row
- From: Eden Li <tile primenet com>
- To: gtk-list redhat com
- Subject: Using GtkPreview/gtk_preview_draw_row
- Date: Mon, 5 Jul 1999 21:03:25 +0000 (GMT)
I can't seem to get this GtkPreview to work right, and there is limited
documentation for it. Here is a brief explanation of what I need and what
I get.
What I need to do is create a swatch of color that can be packed
like a GtkWidget. I read the gtkcolorsel source and saw how it did this,
but when I put something similar to what it has into my code, it doesn't work.
All I get is a black square. Here's what I'm doing currently:
-------
#define SWATCH_HEIGHT 15
#define SWATCH_WIDTH 20
( this is a function, it's argument is a GdkColor* called col )
guchar c[3], data[SWATCH_WIDTH * 3];
guint i, j, y, x;
/* see above about col */
c[0] = (guchar) (((gdouble)((gdouble)col->red / 65535.0)) * 255.0);
c[1] = (guchar) (((gdouble)((gdouble)col->green / 65535.0)) * 255.0);
c[2] = (guchar) (((gdouble)((gdouble)col->blue / 65535.0)) * 255.0);
swatch = gtk_preview_new (GTK_PREVIEW_COLOR);
gtk_container_add (GTK_CONTAINER (win), swatch);
gtk_preview_size (GTK_PREVIEW (swatch), SWATCH_WIDTH, SWATCH_HEIGHT);
gtk_preview_set_expand (GTK_PREVIEW (swatch), FALSE);
for (y = 0; y < SWATCH_HEIGHT; y++)
for (x = 0, j = 0; x < SWATCH_WIDTH; x++)
for (i = 0; i < 3; i++)
data[j++] = c[i];
gtk_preview_draw_row (GTK_PREVIEW (swatch), data, 0, SWATCH_HEIGHT,
SWATCH_WIDTH);
gtk_widget_queue_draw (swatch);
gtk_widget_show (swatch);
------------
I then return swatch from this function and pack it into a widget. I've
tried isolating this into a simple test program (consisting of a window
and a preview) and swapping the order of the gtk_widget_show and
gtk_widget_queue_draw functions to no avail. Can anyone offer any
insight?
BTW, I've already checked the values of c, they look correct (i.e. it's
not turning out to be all 0s). I also tried setting data to all 50s,
and I still get just a black square.
Eden Li
tile@linuxgames.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]