expose event



duh... sorry.

here's the file.
#include "xfuncs.h"

void init_widgets(GameControl* gamec) {

	MAP_WINDOW = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(MAP_WINDOW),QUEST_WINDOW_TITLE);
	gtk_container_set_border_width(GTK_CONTAINER(MAP_WINDOW),0);

	gtk_widget_set_events(MAP_WINDOW,GDK_KEY_PRESS_MASK    | GDK_KEY_RELEASE_MASK | 
	                                 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
	gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"delete_event",GTK_SIGNAL_FUNC(delete_event),NULL); 
	gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"destroy",GTK_SIGNAL_FUNC(destroy),NULL);
	gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"key_press_event",GTK_SIGNAL_FUNC(key_press_event),NULL);
	gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"key_release_event",GTK_SIGNAL_FUNC(key_release_event),NULL);
	gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"button_press_event",GTK_SIGNAL_FUNC(button_press_event),NULL);
	gtk_signal_connect(GTK_OBJECT(MAP_WINDOW),"button_release_event",GTK_SIGNAL_FUNC(button_release_event),NULL);
	
	MAP_BOX = gtk_vbox_new(FALSE,0);

	get_map_menu(gamec);
	gtk_box_pack_start(GTK_BOX(MAP_BOX),MAP_MENU,FALSE,TRUE,0);
	gtk_widget_show(MAP_MENU);

	MAP_DRAWING_AREA = gtk_drawing_area_new();
	gtk_drawing_area_size(GTK_DRAWING_AREA(MAP_DRAWING_AREA), 480, 480);
	gtk_box_pack_start(GTK_BOX(MAP_BOX),MAP_DRAWING_AREA,TRUE,TRUE,0);
	gtk_signal_connect(GTK_OBJECT(MAP_DRAWING_AREA),"configure_event",GTK_SIGNAL_FUNC(configure_event),gamec);
	gtk_signal_connect_after(GTK_OBJECT(MAP_DRAWING_AREA),"expose_event",GTK_SIGNAL_FUNC(expose_event),gamec);
	gtk_widget_show(MAP_DRAWING_AREA);
	
	gtk_container_add(GTK_CONTAINER(MAP_WINDOW),MAP_BOX);
	gtk_widget_show(MAP_BOX);
	
	gtk_widget_show(MAP_WINDOW);

	g_timeout_add(GAME_CYCLE_TIME,(GtkFunction)do_cycle,gamec);

}

void print_update_stack(GameControl* gamec) {
	
	GList* walker = MAP_UPDATE;

	g_print("update stack:\n");

	while(walker != NULL) {

		if(walker->data != NULL) {
			
			g_print("(%d,%d)\n",((Coords*)walker->data)->x,((Coords*)walker->data)->y);

		}

		walker = walker->next;

	}

}

void print_cycle_cnt(GameControl* gamec) {

	g_print("%d\n",CYCLE_CNT);
}

void repaint_drawing_area(GameControl* gamec) {

	GdkRectangle update_rect;
	
	make_area(gamec,TRUE);

	update_rect.x = 0;
	update_rect.y = 0;
	update_rect.width = MAP_DRAWING_AREA->allocation.width;
	update_rect.height = MAP_DRAWING_AREA->allocation.height;
	
	gtk_widget_draw(MAP_DRAWING_AREA,&update_rect);

}

void get_map_menu(GameControl* gamec) {

	GtkItemFactory *item_factory;
	GtkAccelGroup *accel_group;
	GtkItemFactoryEntry menu_items[] = {
		{"/_File",NULL,NULL,0,"<Branch>"},
		{"/File/_New","<control>N",NULL,0,NULL},
		{"/File/_Open","<control>O",NULL,0,NULL},
		{"/File/_Save","<control>S",NULL,0,NULL},
		{"/File/Save _As",NULL,NULL,0,NULL},
		{"/File/sep1",NULL,NULL,0,"<Separator>"},
		{"/File/Quit","<control>Q",gtk_main_quit,0,NULL},
		{"/_Debug",NULL,NULL,0,"<Branch>"},
		{"/Debug/Print Cycle",NULL,print_cycle_cnt,0,NULL},
		{"/Debug/Print Update Stack",NULL,print_update_stack,0,NULL},
		{"/_Help",NULL,NULL,0,"<LastBranch>"},
		{"/_Help/About",NULL,NULL,0,NULL},
	};
	gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);

	accel_group = gtk_accel_group_new ();
	item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR,"<main>",accel_group);

	gtk_item_factory_create_items(item_factory,nmenu_items,menu_items,gamec);
	gtk_accel_group_attach(accel_group, GTK_OBJECT(MAP_WINDOW));
	
	MAP_MENU = gtk_item_factory_get_widget(item_factory,"<main>");

}

gint delete_event(GtkWidget *widget,GdkEvent *event,gpointer data) {

	g_print("delete event occurred\n");

	/* turn TRUE into FALSE and the window will get destroyed */
	return FALSE;

}

gint expose_event(GtkWidget *widget,GdkEventExpose *event,GameControl* gamec) {

	g_print("expose event at (%d,%d)->(%d,%d)\n",
	        event->area.x,event->area.y,event->area.x+event->area.width,event->area.y+event->area.height);

	return TRUE;

}


gint configure_event(GtkWidget *widget,GdkEventConfigure *event,GameControl* gamec) {

	gint x,y;

	g_print("configure event occurred\n");
	
	if(MAP_AREA != NULL) {

		gdk_pixmap_unref(MAP_AREA);

	} 

	MAP_AREA = gdk_pixmap_new(widget->window,widget->allocation.width,widget->allocation.height,-1);
	
	for(y = AREA_OY;y<=(AREA_OY+(widget->allocation.height/TILE_SIZE));y++)
	for(x = AREA_OX;x<=(AREA_OX+(widget->allocation.width/TILE_SIZE));x++) {

		add_update(gamec,x,y);

	}

	return TRUE;

}
            
void destroy(GtkWidget *widget,gpointer data) {

	g_print("destroy event occurred\n");
	gtk_main_quit();

}

void key_press_event(GtkWidget *widget,GdkEventKey* event,gpointer data) {
	
	g_print("key with keyval %d pressed (%s)\n",event->keyval,event->string);

}

void key_release_event(GtkWidget *widget,GdkEventKey* event,gpointer data) {
	
	g_print("key with keyval %d released\n",event->keyval);

}

void button_press_event(GtkWidget *widget,GdkEventButton* event,gpointer data) {

	g_print("button%d pressed\n",event->button);
	
}

void button_release_event(GtkWidget *widget,GdkEventButton* event,gpointer data) {

	g_print("button%d released\n",event->button);

}


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