void TileViewer_Layout(t_app_tile_viewer *app, bool setup) { al_set_target_bitmap(app->box->gfx_buffer); al_clear_to_color(COLOR_SKIN_WINDOW_BACKGROUND); if (setup) { // Add closebox widget widget_closebox_add(app->box, (t_widget_callback)TileViewer_Switch); // Create invisible buttons for hovering/selecting palette app->tiles_display_zone = widget_button_add(app->box, &app->tiles_display_frame, 1, TileViewer_SelectedTile_Select, FONTID_NONE, NULL); widget_button_add(app->box, &app->tiles_display_frame, 2, (t_widget_callback)TileViewer_Change_Palette, FONTID_NONE, NULL); } if (setup) { t_frame frame; frame.SetPos(100, 2); frame.SetSize(4*6, 7); static const int step_count = 4; app->vram_addr_tms9918_scrollbar = widget_scrollbar_add(app->box, WIDGET_SCROLLBAR_TYPE_HORIZONTAL, &frame, &step_count, &app->vram_addr_tms9918_current, 1, NULL); } // Separators al_draw_line(0, app->tiles_display_frame.pos.y-1+0.5f, app->tiles_display_frame.size.x, app->tiles_display_frame.pos.y-1+0.5f, COLOR_SKIN_WINDOW_SEPARATORS, 0); al_draw_line(0, 13+app->tiles_display_frame.size.y+0.5f, app->tiles_display_frame.size.x, 13+app->tiles_display_frame.size.y+0.5f, COLOR_SKIN_WINDOW_SEPARATORS, 0); // Rectangle enclosing current/selected tile const t_frame* fr = &app->tile_selected_frame; gui_rect(LOOK_THIN, fr->pos.x, fr->pos.y, fr->pos.x + 11, fr->pos.y + 11, COLOR_SKIN_WIDGET_GENERIC_BORDER); }
static gui_bool color_picker(struct gui_panel_layout *panel, struct color_picker* control, const char *name, struct gui_color *color) { int i; gui_byte *iter; gui_bool ret = gui_true; struct gui_panel_layout popup; gui_panel_popup_begin(panel, &popup, GUI_POPUP_STATIC, gui_rect(10, 100, 280, 280), gui_vec2(0,0)); { if (gui_panel_header(&popup, "Color", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) { gui_panel_popup_close(&popup); return gui_false; } gui_panel_row_dynamic(&popup, 30, 2); gui_panel_label(&popup, name, GUI_TEXT_LEFT); gui_panel_button_color(&popup, control->color, GUI_BUTTON_DEFAULT); iter = &control->color.r; gui_panel_row_dynamic(&popup, 30, 2); for (i = 0; i < 4; ++i, iter++) { gui_float t = *iter; t = gui_panel_slider(&popup, 0, t, 255, 10); *iter = (gui_byte)t; *iter = (gui_byte)gui_panel_spinner_int(&popup, 0, *iter, 255, 1, NULL); } gui_panel_row_dynamic(&popup, 30, 3); gui_panel_spacing(&popup, 1); if (gui_panel_button_text(&popup, "ok", GUI_BUTTON_DEFAULT)) { gui_panel_popup_close(&popup); *color = control->color; ret = gui_false; } if (gui_panel_button_text(&popup, "cancel", GUI_BUTTON_DEFAULT)) { gui_panel_popup_close(&popup); ret = gui_false; } } gui_panel_popup_end(panel, &popup); control->active = (gui_state)ret; return ret; }
void gui_draw() { // If we were asked to redraw everything, redraw the background as well if (gui.info.must_redraw == TRUE) gui_draw_background(); al_set_target_bitmap(gui_buffer); for (int i = gui.boxes_count - 1; i >= 0; i--) { t_gui_box* b = gui.boxes_z_ordered[i]; const t_frame bb = b->frame; const v2i bb_min = bb.GetMin(); const v2i bb_max = bb.GetMax(); if (!(b->flags & GUI_BOX_FLAGS_ACTIVE)) continue; // Draw widgets for (t_list* widgets = b->widgets; widgets != NULL; widgets = widgets->next) { t_widget *w = (t_widget *)widgets->elem; if (w->enabled && w->type != WIDGET_TYPE_CLOSEBOX) if (w->redraw_func != NULL) w->redraw_func(w); } // Blit content switch (b->type) { case GUI_BOX_TYPE_STANDARD: al_set_target_bitmap(gui_buffer); al_draw_bitmap_region(b->gfx_buffer, 0, 0, bb.size.x + 1, bb.size.y + 1, bb.pos.x, bb.pos.y, 0x0000); break; case GUI_BOX_TYPE_GAME: gamebox_draw(b, screenbuffer); break; } // Draw borders al_set_target_bitmap(gui_buffer); gui_rect(LOOK_ROUND, bb.pos.x - 2, bb.pos.y - 20, bb.pos.x + bb.size.x + 2, bb.pos.y + bb.size.y + 2, COLOR_SKIN_WINDOW_BORDER); al_draw_line(bb.pos.x, bb.pos.y - 1.5f, bb.pos.x + bb.size.x + 1, bb.pos.y - 1.5f, COLOR_SKIN_WINDOW_BORDER, 0); al_draw_line(bb.pos.x, bb.pos.y - 0.5f, bb.pos.x + bb.size.x + 1, bb.pos.y - 0.5f, COLOR_SKIN_WINDOW_BORDER, 0); // Draw resize widget (invisible for game window) if (b->flags & GUI_BOX_FLAGS_ALLOW_RESIZE) { const bool is_resizing = (gui.mouse.focus == GUI_FOCUS_BOX && gui.mouse.focus_box == b && gui.mouse.focus_is_resizing); if (b->type != GUI_BOX_TYPE_GAME || is_resizing) { const int sz = 9; // display size is 9, interaction is 12 const ALLEGRO_COLOR color = is_resizing ? COLOR_SKIN_WINDOW_TEXT_HIGHLIGHT : COLOR_SKIN_WINDOW_TITLEBAR_TEXT_UNACTIVE; al_draw_filled_triangle(bb_max.x+2, bb_max.y+2, bb_max.x+2-sz, bb_max.y+2, bb_max.x+2, bb_max.y+2-sz, color); } } // Draw title bar { t_frame titlebar_frame; titlebar_frame.pos.x = bb.pos.x; titlebar_frame.pos.y = bb.pos.y - 18; titlebar_frame.size.x = bb.size.x; titlebar_frame.size.y = 15; SkinGradient_DrawHorizontal(&Skins_GetCurrentSkin()->gradient_window_titlebar, gui_buffer, &titlebar_frame); // Draw title bar text, with wrapping // Is window the focused one? const ALLEGRO_COLOR color = (i == 0) ? COLOR_SKIN_WINDOW_TITLEBAR_TEXT : COLOR_SKIN_WINDOW_TITLEBAR_TEXT_UNACTIVE; Font_SetCurrent(FONTID_LARGE); if (Font_TextWidth(FONTID_CUR, b->title) <= (bb.size.x - 8)) { Font_Print (FONTID_CUR, b->title, bb.pos.x + 4, bb.pos.y - 17, color); } else { // FIXME-OPT: shit code. char title[256]; int len = strlen(b->title); strcpy(title, b->title); while (Font_TextWidth(FONTID_CUR, title) > (bb.size.x - 17)) title[--len] = EOSTR; strcat(title, ".."); Font_Print(FONTID_CUR, title, bb.pos.x + 4, bb.pos.y - 17, color); } // Draw widgets for (t_list* widgets = b->widgets; widgets != NULL; widgets = widgets->next) { t_widget *w = (t_widget *)widgets->elem; if (w->enabled && w->type == WIDGET_TYPE_CLOSEBOX) if (w->redraw_func != NULL) w->redraw_func(w); } } } // Redraw menus on top of the desktop gui_redraw_menus(); // Update applets that comes after the redraw gui_update_applets_after_redraw(); // Clear global redrawing flag and makes mouse reappear gui.info.must_redraw = FALSE; }
/* ----------------------------------------------------------------- * RUN * ----------------------------------------------------------------- */ static void run_demo(struct demo_gui *gui) { struct gui_panel_layout layout; struct state *state = &gui->state; struct gui_panel_layout tab; struct gui_config *config = &gui->config; /* first panel */ gui_panel_begin(&layout, &gui->panel); { /* header */ gui->running = !gui_panel_header(&layout, "Demo", GUI_CLOSEABLE|GUI_MINIMIZABLE, GUI_CLOSEABLE, GUI_HEADER_RIGHT); /* menubar */ gui_panel_menubar_begin(&layout); { gui_int sel; gui_panel_row_begin(&layout, GUI_STATIC, 25, 2); { gui_panel_row_push(&layout, config->font.width(config->font.userdata, "__FILE__", 8)); sel = gui_panel_menu(&layout, "FILE", file_items, LEN(file_items), 25, 100, &state->file_open, gui_vec2(0,0)); switch (sel) { case MENU_FILE_OPEN: fprintf(stdout, "[Menu:File] open clicked!\n"); break; case MENU_FILE_CLOSE: fprintf(stdout, "[Menu:File] close clicked!\n"); break; case MENU_FILE_QUIT: fprintf(stdout, "[Menu:File] quit clicked!\n"); break; case GUI_NONE: default: break; } gui_panel_row_push(&layout, config->font.width(config->font.userdata, "__EDIT__", 8)); sel = gui_panel_menu(&layout, "EDIT", edit_items, LEN(edit_items), 25, 100, &state->edit_open, gui_vec2(0,0)); switch (sel) { case MENU_EDIT_COPY: fprintf(stdout, "[Menu:Edit] copy clicked!\n"); break; case MENU_EDIT_CUT: fprintf(stdout, "[Menu:Edit] cut clicked!\n"); break; case MENU_EDIT_DELETE: fprintf(stdout, "[Menu:Edit] delete clicked!\n"); break; case MENU_EDIT_PASTE: fprintf(stdout, "[Menu:Edit] paste clicked!\n"); break; case GUI_NONE: default: break; } } gui_panel_row_end(&layout); } gui_panel_menubar_end(&layout); /* panel style configuration */ if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Style", &state->config_tab)) { if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Options", &state->flag_tab)) { update_flags(&layout); gui_panel_layout_pop(&layout); } if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Properties", &state->style_tab)) { properties_tab(&layout, config); gui_panel_layout_pop(&layout); } if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Rounding", &state->round_tab)) { round_tab(&layout, config); gui_panel_layout_pop(&layout); } if (gui_panel_layout_push(&layout, GUI_LAYOUT_NODE, "Color", &state->color_tab)) { color_tab(&layout, state, config); gui_panel_layout_pop(&layout); } gui_panel_layout_pop(&layout); } /* widgets examples */ if (gui_panel_layout_push(&layout, GUI_LAYOUT_TAB, "Widgets", &state->widget_tab)) { widget_panel(&layout, state); gui_panel_layout_pop(&layout); } /* popup panel */ if (state->popup) { gui_panel_popup_begin(&layout, &tab, GUI_POPUP_STATIC, gui_rect(20, 100, 220, 150), gui_vec2(0,0)); { if (gui_panel_header(&tab, "Popup", GUI_CLOSEABLE, GUI_CLOSEABLE, GUI_HEADER_LEFT)) { gui_panel_popup_close(&tab); state->popup = gui_false; } gui_panel_row_dynamic(&tab, 30, 1); gui_panel_label(&tab, "Are you sure you want to exit?", GUI_TEXT_LEFT); gui_panel_row_dynamic(&tab, 30, 4); gui_panel_spacing(&tab, 1); if (gui_panel_button_text(&tab, "Yes", GUI_BUTTON_DEFAULT)) { gui_panel_popup_close(&tab); state->popup = gui_false; } if (gui_panel_button_text(&tab, "No", GUI_BUTTON_DEFAULT)) { gui_panel_popup_close(&tab); state->popup = gui_false; } } gui_panel_popup_end(&layout, &tab); } { /* shelf + graphes */ static const char *shelfs[] = {"Histogram", "Lines"}; gui_panel_row_dynamic(&layout, 180, 1); state->shelf_selection = gui_panel_shelf_begin(&layout, &tab, shelfs, LEN(shelfs), state->shelf_selection, state->shelf); graph_panel(&tab, state->shelf_selection); state->shelf = gui_panel_shelf_end(&layout, &tab); } /* tables */ gui_panel_row_dynamic(&layout, 180, 1); gui_panel_group_begin(&layout, &tab, "Table", state->table); table_panel(&tab); state->table = gui_panel_group_end(&layout, &tab); { /* tree */ struct gui_tree tree; gui_panel_row_dynamic(&layout, 250, 1); gui_panel_tree_begin(&layout, &tree, "Tree", 20, state->tree); upload_tree(&state->test, &tree, &state->test.root); state->tree = gui_panel_tree_end(&layout, &tree); } } gui_panel_end(&layout, &gui->panel); /* second panel */ gui_panel_begin(&layout, &gui->sub); { enum {EASY, HARD}; gui_panel_header(&layout, "Show", GUI_CLOSEABLE, 0, GUI_HEADER_LEFT); gui_panel_row_static(&layout, 30, 80, 1); if (gui_panel_button_text(&layout, "button", GUI_BUTTON_DEFAULT)) { /* event handling */ } gui_panel_row_dynamic(&layout, 30, 2); if (gui_panel_option(&layout, "easy", state->op == EASY)) state->op = EASY; if (gui_panel_option(&layout, "hard", state->op == HARD)) state->op = HARD; } gui_panel_end(&layout, &gui->sub); }
void GUIController::draw_gui_recursive (PlaceableObject *root, const std::shared_ptr<CameraObject> &camera, const Color4f &parent_color, DTint stencil) { GUIObject *gui = checked_cast<GUIObject*>(root); Rectangle gui_rect(0.0F,1.0F,0.0F,1.0F); DTboolean use_stencil = false; std::list<PlaceableObject*> c = root->children(); if (gui) { // Check for transparent Color4f color = parent_color * gui->color(); if (color.a <= 0.0F) return; // Check for no scale if (gui->scale() == Vector3(0.0F,0.0F,0.0F)) return; // Get Rectangle gui_rect = gui->screen_rectangle(); // Check if we need to stencil use_stencil = c.size() > 0; if (use_stencil) { ++stencil; gui->draw_gui_mask(camera); } System::renderer()->set_stencil_ref(stencil); gui->draw_gui(camera, parent_color); } c.sort(CompareDraw()); for (auto &i : c) { GUIObject *gui_child = checked_cast<GUIObject*>(i); if (gui_child) { // Get Rectangle Rectangle gui_child_rect = gui_child->screen_rectangle(); if (!gui_rect.is_touching(gui_child_rect)) continue; draw_gui_recursive(gui_child, camera, parent_color * gui_child->color(), stencil ); } else { draw_gui_recursive(i, camera, parent_color, stencil); } } if (gui) { System::renderer()->set_stencil_ref(stencil); gui->post_draw_gui(camera, parent_color); if (use_stencil) { gui->draw_gui_unmask(camera); } } }