2016 ソフトウェア設計及び演習用の班Wiki
g01::itemtest.c
- アイテムのプロトタイプテスト
- 指定した範囲以外を押してしまうとタイトル画面に戻ってしまうのを直したい。
- while文だとウィンドウがしぬ
- #include <gtk/gtk.h> #include <stdlib.h> #include "proto.h"
int module; int eventnum; int end = 0; static gboolean cb_expose_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { if(module == 3){
cb_expose_event_event(widget, event, user_data);
return FALSE; } if(module == 2){
cb_expose_play_event(widget, event, user_data);
return FALSE; } if(module == 1){
cb_expose_start_event(widget, event, user_data);
return FALSE; } }
static gboolean cb_mouse_press(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { if(module == 3){ cb_mouse_event_press(widget, event, user_data); }
if(module == 2){ cb_mouse_play_press(widget, event, user_data); }
if(module == 1){ cb_mouse_start_press(widget, event, user_data); } }
void event(GtkWidget *window) { module = 3;
gtk_widget_show_all(event0(window)); gtk_main(); gtk_widget_destroy(canvas);
gtk_widget_show_all(event1(window)); gtk_main(); gtk_widget_destroy(canvas);
return; }
GtkWidget *event0(GtkWidget *window) { eventnum = 0; canvas = gtk_drawing_area_new (); gtk_container_add (GTK_CONTAINER(window), canvas);
g_signal_connect (G_OBJECT(canvas), "expose_event", G_CALLBACK (cb_expose_event), NULL);
gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(cb_mouse_press), NULL);
return window; }
GtkWidget *event1(GtkWidget *window) {
canvas = gtk_drawing_area_new (); gtk_container_add (GTK_CONTAINER(window), canvas);
LOOP: g_signal_connect (G_OBJECT(canvas), "expose_event", G_CALLBACK (cb_expose_event), NULL); gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK); g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(cb_mouse_press), NULL); end: return window; }
void cb_expose_event_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data) { GdkWindow *drawable = widget->window; cairo_t *cr; cairo_surface_t *surface;
cr = gdk_cairo_create(drawable);
if(ganchan.commandnum 3 && eventnum 0){
surface = cairo_image_surface_create_from_png("index.png");
cairo_set_source_surface(cr, surface, 0.0, 0.0);
cairo_paint(cr);
ganchan.commandnum 0;
}else if(ganchan.commandnum 3 && eventnum == 1){
surface = cairo_image_surface_create_from_png("st2.png");
cairo_set_source_surface(cr, surface, 0.0, 0.0);
cairo_paint(cr);
ganchan.knowledge += 5;
}
}
void cb_mouse_event_press(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
if(event->x >= 600&& event->x <=1611){ if(event->y >=70 && event->y <=244){ eventnum = 1; } } else { goto LOOP; } gtk_main_quit(); }
最終更新日:2016/06/17 10:46:51