void menu_draw_buffer(menu_t *menu){ if(menu->buffer == NULL){ menu_create_buffer(menu); } SDL_Rect fill_rect; fill_rect.x = 0; fill_rect.y = 0; fill_rect.w = menu->buffer->w; fill_rect.h = menu->buffer->h; SDL_FillRect(menu->buffer, &fill_rect, 0x666666FF); fill_rect.x += 2; fill_rect.y += 2; fill_rect.w -= 4; fill_rect.h -= 4; SDL_FillRect(menu->buffer, &fill_rect, 0x333333FF); int x = 10; int y = 4; int h = font_get_height(menu->game->font); for(uint32_t i=0; i<MENU_MAX_OPTIONS; i++){ if(menu->options[i] != NULL){ font_draw_string(menu->game->font, menu->options[i]->label, x, y, menu->buffer); } if(i == menu->selection){ font_draw_string(menu->game->font, ">", x-6, y, menu->buffer); } y += h; } }
void menu_create_buffer(menu_t *menu){ #ifdef DEBUG if(menu->buffer != NULL){ printf("MEMORY LEAK: MENU BUFFER OVER-WRITE\n"); } #endif int32_t x = 0; int32_t w = 0; int32_t h = 0; for(uint32_t i=0; i<MENU_MAX_OPTIONS; i++){ if(menu->options[i] != NULL){ x = font_get_width(menu->font, menu->options[i]->label); if(x > w){ w = x; } h += font_get_height(menu->font); } } w += 20; h += 8; menu->buffer = create_surface(w,h); }
static void gameover_render(void) { font_printf_centered(fb, 0, "GAME OVER"); font_printf_centered(fb, fb->height/2-font_get_height()/2-font_get_height(), "Your Score:"); font_printf_centered(fb, fb->height/2-font_get_height()/2+font_get_height(), "%lld", score); }