2016 ソフトウェア設計及び演習用の班Wiki
16::gr11::signal_callback.c
#include "signal_callback.h" void on_window_destroy(GtkObject* object, gtk_app_t* gtk_app) { gtk_main_quit(); } int on_configure_event(GtkWidget* draw_area, GdkEventConfigure* event, gtk_app_t* gtk_app) { int i; GError* error = NULL; GdkPixbuf* image = NULL; const gchar* pic_filename[5] = { "res/black.png", "res/white.png", "res/bgcolor.png", "res/vlabel.png", "res/hlabel.png" }; srand(time(NULL)); for (i = 0; i < 5; ++i) { image = gdk_pixbuf_new_from_file(pic_filename[i], &error); if (error) { g_warning(G_STRLOC ": load image error:%s\n", error->message); error = NULL; } gdk_pixbuf_render_pixmap_and_mask_for_colormap(image, gdk_colormap_get_system(), >k_app->piece[i], >k_app->piece_mask[i], 0x7f); } if (gtk_app->pixmap) g_object_unref(gtk_app->pixmap); gtk_app->pixmap = gdk_pixmap_new(draw_area->window, draw_area->allocation.width, draw_area->allocation.height, -1); gdk_draw_drawable(gtk_app->pixmap, draw_area->style->fg_gc[GTK_WIDGET_STATE(draw_area)], gtk_app->piece[2], 0, 0, 0, 0, draw_area->allocation.width, draw_area->allocation.height); gdk_draw_drawable(gtk_app->pixmap, draw_area->style->fg_gc[GTK_WIDGET_STATE(draw_area)], gtk_app->piece[3], 0, 0, 0, YOFFSET + YBORDER, XOFFSET, BOARD_HEIGHT); gdk_draw_drawable(gtk_app->pixmap, draw_area->style->fg_gc[GTK_WIDGET_STATE(draw_area)], gtk_app->piece[3], 0, 0, XOFFSET + 2 * XBORDER + BOARD_HEIGHT, YOFFSET + YBORDER, XOFFSET, BOARD_HEIGHT); gdk_draw_drawable(gtk_app->pixmap, draw_area->style->fg_gc[GTK_WIDGET_STATE(draw_area)], gtk_app->piece[4], 0, 0, XOFFSET + XBORDER, 0, BOARD_WIDTH, YOFFSET); gdk_draw_drawable(gtk_app->pixmap, draw_area->style->fg_gc[GTK_WIDGET_STATE(draw_area)], gtk_app->piece[4], 0, 0, XOFFSET + XBORDER, YOFFSET + 2 * YBORDER + BOARD_HEIGHT, BOARD_WIDTH, YOFFSET); gdk_draw_rectangle(gtk_app->pixmap, draw_area->style->black_gc, FALSE, 0, 0, BOARD_WIDTH + 2 * XBORDER + 2 * XOFFSET - 1, BOARD_HEIGHT + 2 * YBORDER + 2 * YOFFSET - 1); gdk_draw_rectangle(gtk_app->pixmap, draw_area->style->black_gc, FALSE, XOFFSET, YOFFSET, BOARD_WIDTH + 2 * XBORDER - 1, BOARD_HEIGHT + 2 * YBORDER - 1); gdk_draw_rectangle(gtk_app->pixmap, draw_area->style->black_gc, FALSE, XOFFSET - 1, YOFFSET - 1, BOARD_WIDTH + 2 * XBORDER + 1, BOARD_HEIGHT + 2 * YBORDER + 1); gdk_draw_rectangle(gtk_app->pixmap, draw_area->style->black_gc, FALSE, XOFFSET + XBORDER, YOFFSET + YBORDER, BOARD_WIDTH - 1, BOARD_HEIGHT - 1); for (i = 1; i < XMAX; ++i) { gdk_draw_line(gtk_app->pixmap, draw_area->style->black_gc, XOFFSET + XBORDER + i * BOARD_WIDTH / XMAX - 1, YOFFSET + YBORDER, XOFFSET + XBORDER + i * BOARD_WIDTH / XMAX - 1, YOFFSET + YBORDER + BOARD_HEIGHT - 1); gdk_draw_line(gtk_app->pixmap, draw_area->style->black_gc, XOFFSET + XBORDER, YOFFSET + YBORDER + i * BOARD_HEIGHT / YMAX - 1, XOFFSET + XBORDER + BOARD_WIDTH - 1, YOFFSET + YBORDER + i * BOARD_HEIGHT / YMAX - 1); } g_object_unref(image); return 0; } int on_expose_event(GtkWidget* draw_area, GdkEventExpose* event, gtk_app_t* gtk_app) { show_pixmap(gtk_app); return 0; }
最終更新日:2016/08/02 16:48:10