[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Expose event?



Havoc Pennington wrote:

> Check out the "scribble" example in the GTK tutorial. Just do all your
> drawing from the expose event handler; it will work fine.
> 
> You can't draw until you get the first expose_event, that's the
> definitive moment in time when drawing is allowed. Realization isn't
> enough.

 I do my init stuff on the "draw" event, and my update stuff on the
"expose_event".. in this case, I create a SDL surface (SDL is a library
for real time graphics designed for videogames)

 What are the differences of these events? I was believing it is better
off If I use expose to manage the update stuff and draw to init the
stuff. I attach a surface using the drawarea window, and it works
well...

 I'll do some futher research to know exactly which events are
happening...

 Butr, If I move all to the expose_event, it doesnt init the stuff (in
this case, attach a sdl surface over a gtkdrawarea)

 those are the callbacks:

/* Create the SDL_Surface when the drawarea is visible */
gboolean cbDrawAreaDraw (GtkWidget *widget, gpointer data)
{
  dkScreen *screen;

	if (! GTK_IS_WIDGET(widget))
	{
		DK_ERROR ("given widget isnt a real widget");
		return (FALSE);
	}

	screen = screen_get_active ();

	if (!screen)
	{
		DK_ERROR ("screen not valid");
		return (FALSE);
	}

	if ( !screen_sdl_attach (screen) )
	{
		DK_ERROR ("unable to attach SDL surface");
		return (FALSE);
	}

	return (TRUE);
}

/* update the surface */
gboolean cbDrawAreaExpose (GtkWidget *widget, GdkEventExpose *event,
gpointer data)
{

  dkScreen *screen;
  SDL_Rect dest;

	if (! GTK_IS_WIDGET(widget))
	{
		DK_ERROR ("given widget isnt a real widget");
		return (FALSE);
	}

	screen = screen_get_active ();

	if (!screen)
	{
		DK_ERROR ("screen not valid");
		return (FALSE);
	}

	if ( GTK_WIDGET_VISIBLE (widget) && (screen->surface) )
	{
		dest.x = event->area.x;
		dest.y = event->area.y;
		dest.w = event->area.width;
		dest.h = event->area.height;

		SDL_UpdateRects (screen->surface, 1, &dest);
	}

	return (TRUE);
}


-- 
signed
          derethor of centolos





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]