2015 ソフトウェア設計及び演習用の班Wiki
15::gr11::widget.c
#include "gtk_lib.h" #include "widget.h" // メインループを終わるコールバック関数 void cb_button_clicked (GtkWidget *button, gpointer user_data){ gtk_main_quit (); } // windowにあるウィジェットを消す void vbox_destroy(){ gtk_widget_destroy(vbox); } // スタート画面 GtkWidget *start(GtkWidget *window){ Max_widget = 4; Max_hbox = 1; GtkWidget *widget[Max_widget]; widget[0] = my_image_new("title4.png"); widget[1] = gtk_button_new_with_label("スタート"); g_signal_connect(G_OBJECT(widget[1]), "clicked", G_CALLBACK(gtk_main_quit), NULL); widget[2] = gtk_button_new_with_label("練習問題"); g_signal_connect(G_OBJECT(widget[2]), "clicked", G_CALLBACK(practice_button_clicked), NULL); widget[3] = gtk_button_new_with_label("終了"); g_signal_connect(G_OBJECT(widget[3]), "clicked", G_CALLBACK(app_quit), NULL); vbox = gtk_vbox_new(FALSE, 15); gtk_container_add(GTK_CONTAINER(window), vbox); { int i, j; for(i=0; i<Max_widget; i+=Max_hbox) { hbox = gtk_hbox_new(TRUE, 15); gtk_container_add(GTK_CONTAINER(vbox), hbox); for(j=i; j<i+Max_hbox && j<Max_widget; j++) { gtk_box_pack_start(GTK_BOX(hbox), widget[j], TRUE, TRUE, 0); } } } return window; } // 科目画面 GtkWidget *kamoku(GtkWidget *window, char png[], int item[]){ Max_widget = 5; Max_hbox = 1; GtkWidget *widget[Max_widget]; widget[0] = my_image_new (png); widget[1] = gtk_button_new_with_label("制限時間 2倍"); if(item[2] == 1){ g_signal_connect(G_OBJECT(widget[1]), "clicked", G_CALLBACK(item_button_clicked), "1"); } widget[2] = gtk_button_new_with_label("選択肢 2つ"); if(item[1] == 1){ g_signal_connect(G_OBJECT(widget[2]), "clicked", G_CALLBACK(item_button_clicked), "2"); } widget[3] = gtk_button_new_with_label("取得単位 2倍"); if(item[0] == 1){ g_signal_connect(G_OBJECT(widget[3]), "clicked", G_CALLBACK(item_button_clicked), "3"); } widget[4] = gtk_button_new_with_label("問題 START"); g_signal_connect(G_OBJECT(widget[4]), "clicked", G_CALLBACK(cb_button_clicked), NULL); vbox = gtk_vbox_new(FALSE, 15); gtk_container_add(GTK_CONTAINER(window), vbox); { int i, j; for(i=0; i<Max_widget; i+=Max_hbox) { hbox = gtk_hbox_new(TRUE, 15); gtk_container_add(GTK_CONTAINER(vbox), hbox); for(j=i; j<i+Max_hbox && j<Max_widget; j++) { gtk_box_pack_start(GTK_BOX(hbox), widget[j], TRUE, TRUE, 0); } } } return window; } // 正解画面 GtkWidget *seikai(GtkWidget *window){ vbox = gtk_vbox_new (FALSE, 2); gtk_container_add (GTK_CONTAINER (window), vbox); { GtkWidget *image; GtkWidget *button; image = my_image_new ("seikai.png"); gtk_box_pack_start (GTK_BOX (vbox), image, TRUE, TRUE, 0); button = gtk_button_new_with_label ("Next"); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_button_clicked), NULL); } return window; } // 正解画面(練習問題) GtkWidget *seikai_pra(GtkWidget *window){ vbox = gtk_vbox_new (FALSE, 2); gtk_container_add (GTK_CONTAINER (window), vbox); { GtkWidget *image; GtkWidget *button; image = my_image_new ("seikai_pra.png"); gtk_box_pack_start (GTK_BOX (vbox), image, TRUE, TRUE, 0); button = gtk_button_new_with_label ("ホーム画面へ"); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_button_clicked), NULL); } return window; } // 不正解画面 GtkWidget *huseikai(GtkWidget *window){ vbox = gtk_vbox_new (FALSE, 2); gtk_container_add (GTK_CONTAINER (window), vbox); { GtkWidget *image; GtkWidget *button; image = my_image_new ("huseikai.png"); gtk_box_pack_start (GTK_BOX (vbox), image, TRUE, TRUE, 0); button = gtk_button_new_with_label ("Next"); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_button_clicked), NULL); } return window; } // プログラム終了 void app_quit(){ exit(1); }
最終更新日:2015/07/17 12:51:54