/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ gui_wnd_t* gui_pbwnd_create(int x, int y, int w, int h, gui_wgt_evt_cb_t* p_cb) { gui_wnd_t* p_wnd; gui_widget_t* p_wgt; int xx; int yy; int i; p_wnd = gui_wnd_create(NULL, "pbwnd", x, y, w, h, 0); REQUIRE(p_wnd != NULL); p_wnd->set_cfg(p_wnd, "caption", "Player Board"); p_wnd->set_cfg(p_wnd, "bg_image", "data/Map-H.png"); p_wnd->set_cfg = gui_pbwnd_set_cfg; p_wnd->bg_color = GLX_RGBA(0x00, 0x00, 0x00, 0xFF); p_wnd->border = TRUE; p_wnd->border_color = GLX_RGBA(0x00, 0x00, 0x00, 0xFF); /* Create card widgets */ xx = 160; yy = 9; for (i=0;i<6;i++) { p_wgt = gui_widget_create(card_widget_names[i], "image", xx, yy, 131, 181); p_wgt->visible = FALSE; p_wgt->set_cfg(p_wgt, "cb_fn", p_cb); p_wnd->add_widget(p_wnd, p_wgt); xx += 150; } /* Create politician widgets */ xx = 10; yy = 341; for (i=0;i<5;i++) { p_wgt = gui_widget_create(politician_widget_names[i], "image", xx, yy, 129, 129); p_wgt->visible = FALSE; p_wgt->set_cfg(p_wgt, "image", politicians_image_path[i]); p_wgt->set_cfg(p_wgt, "cb_fn", p_cb); p_wnd->add_widget(p_wnd, p_wgt); xx += 131; } /* Create vocation widgets */ xx = 676; yy = 406; for (i=0;i<8;i++) { p_wgt = gui_widget_create(vocation_widget_names[i], "image", xx, yy, 44, 44); p_wgt->visible = FALSE; p_wgt->set_cfg(p_wgt, "image", vocations_image_path[i]); p_wgt->set_cfg(p_wgt, "cb_fn", p_cb); p_wnd->add_widget(p_wnd, p_wgt); xx += 45; } return p_wnd; }
/* ==================================================================== Create a framed progress bar. ==================================================================== */ GuiWidget *gui_progressbar_create( GuiWidget *parent, int x, int y, int width, int height, void (*user_event_handler)(GuiWidget*,GuiEvent*), int max, int value ) { GuiWidget *widget = gui_widget_create( parent, GUI_PROGRESSBAR, x, y, width, height, default_event_handler, user_event_handler ); /* create surface, wallpaper and frame it */ widget->surface = stk_surface_create( SDL_SWSURFACE, width, height ); SDL_SetColorKey( widget->surface, 0,0 ); stk_surface_apply_wallpaper( widget->surface, 0,0,-1,-1, gui_theme->widget_wallpaper, -1 ); widget->border = stk_surface_apply_frame( widget->surface, 0, 0, -1, -1, gui_theme->widget_frame ); /* size w/o border */ widget->width -= 2 * widget->border; widget->height -= 2 * widget->border; /* set value */ widget->spec.progressbar.max = max; gui_progressbar_set_value( widget, value ); /* done */ return widget; }
GuiWidget* gui_radiogroup_create( GuiWidget *parent, int x, int y, int width, int height, int with_frame, void (*user_event_handler)(GuiWidget*,GuiEvent*), int item_count, char **items, int min, int max ) { int px, py, i, j, gap = 4; GuiWidget *widget = gui_widget_create( parent, GUI_RADIOGROUP, x, y, width, height, default_event_handler, user_event_handler ); /* events */ gui_widget_enable_event( widget, GUI_CLICKED ); /* create surface, wallpaper and frame it */ widget->surface = stk_surface_create( SDL_SWSURFACE, width, height ); SDL_SetColorKey( widget->surface, 0,0 ); stk_surface_apply_wallpaper( widget->surface, 0,0,-1,-1, gui_theme->widget_wallpaper, -1 ); if ( with_frame ) widget->border = stk_surface_apply_frame( widget->surface, 0, 0, -1, -1, gui_theme->widget_frame ); /* size w/o border */ widget->width -= 2 * widget->border; widget->height -= 2 * widget->border; /* various */ widget->spec.radiogroup.size = item_count; widget->spec.radiogroup.min = min; widget->spec.radiogroup.max = max; widget->spec.radiogroup.single_check = -1; /* compute offset of single items */ widget->spec.radiogroup.offset = (height - 2 * widget->border) / item_count; /* position of first checkbox */ widget->spec.radiogroup.x = widget->border + gap; widget->spec.radiogroup.y = widget->border + (widget->spec.radiogroup.offset - gui_theme->checkbox_size) / 2; /* add empty checkboxes and labels */ gui_theme->label_font->align = STK_FONT_ALIGN_CENTER_Y; px = widget->spec.radiogroup.x; py = widget->spec.radiogroup.y; for ( i = 0, j = 0; i < widget->spec.radiogroup.size; i++, py += widget->spec.radiogroup.offset, j++ ) { stk_surface_blit( gui_theme->checkbox, 0, 0, gui_theme->checkbox_size, gui_theme->checkbox_size, widget->surface, px, py ); stk_font_write( gui_theme->label_font, widget->surface, px + gui_theme->checkbox_size + gap, py + gui_theme->checkbox_size/2, -1, items[j] ); } /* create empty checkers */ widget->spec.radiogroup.checks = calloc( item_count, sizeof( int ) ); if ( widget->spec.radiogroup.checks == 0 ) GUI_ABORT( "Out Of Memory" ); return widget; }
/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ gui_wnd_t* gui_gbwnd_create(int x, int y, int w, int h, gui_wgt_evt_cb_t* p_cb) { gui_wnd_t* p_wnd; gui_widget_t* p_wgt; p_wnd = gui_wnd_create(NULL, "gbwnd", x, y, w, h, 0); REQUIRE(p_wnd != NULL); p_wnd->bg_color = GLX_RGBA(0x00, 0x00, 0x00, 0xFF); //p_wnd->set_cfg(p_wnd, "bg_image", "data/wood_bg.png"); /* Create board widget */ p_wgt = gui_widget_create("board", "board", 0, 0, p_wnd->w, p_wnd->h); REQUIRE(p_wgt != NULL); p_wgt->evt_cb = p_cb; p_wnd->add_widget(p_wnd, p_wgt); return p_wnd; }