[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Making a GtkPreview work
- From: Straker Skunk <straker fox mit edu>
- To: gtk-app-devel-list redhat com
- Subject: Making a GtkPreview work
- Date: Sun, 3 Oct 1999 03:39:39 -0400 (EDT)
Hello,
I'm writing up a dialog which shows off a color gradient in a GtkPreview,
very much like the Gimp's Gradient Editor. What I have is almost identical
in execution structure to the code in gimp-1.0.4/app/gradient.c, and yet,
it does not draw the gradient.
(It does draw the gradient when the window is resized, but then, it draws
it at the smaller size it should have had beforehand. Before the window is
resized, there is nothing visible in the preview area save for the standard
background color)
Could someone please tell me what I might have left out? I've already
gleaned all that I could from the Gimp code, and haven't had much success.
In pseudo-pseudocode, the initialization routine goes like this:
preview_init()
{
create_preview_widget(); /* make it, pack it, show it */
connect_expose_event_of_preview_widget_to_callback();
}
and then, the callback which catches expose_event:
/* the actual code for this one is way down at the bottom,
* if that helps */
expose_event_cb()
{
/* widget->allocation.width / .height */
get_allocation_size_of_preview_widget();
/* GTK_PREVIEW(widget)->buffer_width / ->buffer_height */
get_buffer_size_of_preview_widget();
if (allocation_size == buffer_size)
return; /* already initialized and drawn */
/* Do this with gtk_preview_size() */
set_preview_size_to_allocation_size();
generate_gradient_image_in_a_memory_buffer();
/* Do this with gtk_preview_draw_row() in a for loop */
copy_image_into_preview_widget();
/* Do this with gtk_widget_draw() */
make_GTK_explictly_draw_the_preview_widget();
}
Any help will be greatly appreciated.
--Straker
P.S.: As an aside, would anyone know what's all this about preview widgets
not being able to shrink? What explains that?
//,, //,,
//=================// ////// ////// //==================================\\
Straker Skunk / ////// ////// / Skunks are such wonderful
<skunk@mit.edu> / ////// ////// / creatures... soft, and cuddly,
-- -- -- -- -- --\ \\\\\\ \\\\\\ \ and if you annoy them they
Daniel Richard G. \ \\\\\\ \\\\\\ \ make you stink like hell
========--====--==-\ \\\\\\ \\\\\\ \---------------=--==--====--========
//mit.edu/straker / ////// ////// / Furry|Course VI-3|MIT Class of 2001
//skunk.mit.edu / ////// ////// / 80% Beaver 90% Penguin 100% SKUNK!!!
\\===============// ////// ////// //====================================//
''// ''//
/* This is the callback which catches expose_event */
int
gradient_draw( GtkWidget *preview_w, GdkEvent *ev_expose )
{
double x;
int width, height;
int prev_width, prev_height;
int i;
unsigned char *rowbuf;
width = preview_w->allocation.width;
height = preview_w->allocation.height;
prev_width = GTK_PREVIEW(preview_w)->buffer_width;
prev_height = GTK_PREVIEW(preview_w)->buffer_height;
if ((width == prev_width) && (height == prev_height)) {
/* Gradient has already been drawn */
return FALSE;
}
/* Preview widget has changed size (or is being initialized for
* the first time) */
gtk_preview_size( GTK_PREVIEW(preview_w), width, height );
/* Create one row of white gradient */
rowbuf = xmalloc( 3 * width * sizeof(unsigned char) );
for (i = 0; i < width; i++) {
x = (double)i / (double)(width - 1);
rowbuf[3 * i] = (unsigned char)(255.0 * x);
rowbuf[3 * i + 1] = (unsigned char)(255.0 * x);
rowbuf[3 * i + 2] = (unsigned char)(255.0 * x);
}
/* Draw gradient */
for (i = 0; i < height; i++)
gtk_preview_draw_row( GTK_PREVIEW(preview_w), rowbuf, 0, i, width );
xfree( rowbuf );
gtk_widget_draw( preview_w, NULL );
return FALSE;
}
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]