void screen_deactivated() { const screen_t* screen = get_active_screen(); if (screen != NULL && screen->deactivated != NULL) { (*screen->deactivated)(); } }
void screen_key_down(int key) { const screen_t* screen = get_active_screen(); if (screen != NULL && screen->key_down != NULL) { (*screen->key_down)(key); } }
void screen_pointer_move(int pointer, float x, float y) { ui_pointer_move(&ui, pointer, x, y); const screen_t* screen = get_active_screen(); if (screen != NULL && screen->pointer_move != NULL) { (*screen->pointer_move)(pointer, x, y); } }
void screen_update(long dt) { ui_update(&ui, dt); const screen_t* screen = get_active_screen(); if (screen != NULL && screen->update != NULL) { (*screen->update)(dt); } }
void screen_render(struct gfx_t* gfx, const struct camera_t* camera) { ui_render(&ui, gfx, camera); const screen_t* screen = get_active_screen(); if (screen != NULL && screen->render != NULL) { (*screen->render)(gfx, camera); } }
void screen_resize(int width, int height) { ui_resize(&ui, width, height); const screen_t* screen = get_active_screen(); if (screen != NULL && screen->resize != NULL) { (*screen->resize)(width, height); } }
void screen_key_up(int key) { const screen_t* screen = get_active_screen(); if (screen != NULL && screen->key_up != NULL) { (*screen->key_up)(key); } else if (key == KEY_BACK) { pop_screen(); } }
static void draw_area_ui_object (ui_object *obj) { float x, y, x1, y1, x2, y2; int redraw_flag = FALSE, masked, width, height, pitch; font_types font_id; area_ui_object *area; struct SCREEN *old_active_screen, *memory_graphic; unsigned short int *graphic; struct ZOOMABLE_GRAPHIC *zoomable_graphic; unsigned char *data; ui_object *parent; if (get_ui_object_redraw (obj)) { area = (area_ui_object *) obj->data; //debug_log ("AR_DRAW: drawing area %f, %f %f, %f", area->x, area->y, area->x_size, area->y_size); x1 = area->x; y1 = area->y; x2 = x1 + area->x_size; y2 = y1 + area->y_size; old_active_screen = get_active_screen (); if (get_ui_object_active_screen (obj)) { set_active_screen (get_ui_object_active_screen (obj)); } else { set_active_screen (video_screen); } if (lock_screen (active_screen)) { switch (get_ui_object_graphic_type (obj)) { case UI_OBJECT_GRAPHIC: { if (!get_ui_object_clear (obj)) { graphic = get_ui_object_graphic (obj); ui_draw_graphic (x1, y1, x2, y2, graphic); redraw_flag = TRUE; } else { parent = get_ui_object_parent (obj); if (parent) { graphic = get_ui_object_graphic (parent); ui_draw_part_graphic (x1, y1, x2, y2, x1, y1, graphic); redraw_flag = TRUE; } } break; } case UI_OBJECT_MEMORY_GRAPHIC: { memory_graphic = get_ui_object_memory_graphic (obj); if (lock_screen (memory_graphic)) { width = get_screen_width (memory_graphic); height = get_screen_height (memory_graphic); data = get_screen_data (memory_graphic); pitch = get_screen_pitch (memory_graphic); masked = get_ui_object_clear (obj); ui_draw_memory_graphic (obj, x1, y1, x2, y2, width, height, pitch, masked); unlock_screen (memory_graphic); } redraw_flag = TRUE; break; } case UI_OBJECT_ALPHA_GRAPHIC: { if (!get_ui_object_clear (obj)) { graphic = get_ui_object_graphic (obj); ui_draw_alpha_graphic (x1, y1, x2, y2, graphic); redraw_flag = TRUE; } else { parent = get_ui_object_parent (obj); if (parent) { graphic = get_ui_object_graphic (parent); ui_draw_part_alpha_graphic (x1, y1, x2, y2, x1, y1, graphic); redraw_flag = TRUE; } } break; } case UI_OBJECT_ZOOMABLE_PALETTE_GRAPHIC: { if (!get_ui_object_clear (obj)) { zoomable_graphic = get_ui_object_zoomable_palette_graphic (obj); draw_zoomable_graphic (zoomable_graphic, area->cx, area->cy, x1, y1, x2, y2, area->zoom); redraw_flag = TRUE; } break; } case UI_OBJECT_NO_GRAPHIC: default: { if (!get_ui_object_clear (obj)) { ui_draw_area (x1, y1, x2, y2); redraw_flag = TRUE; } } } // text position if (get_ui_object_text (obj)) { font_id = get_ui_font (); set_ui_font (get_ui_object_font (obj)); get_text_position (&x, &y, x1, y1, x2, y2, obj); ui_display_text (get_ui_object_text (obj), x, y); set_ui_font (font_id); redraw_flag = TRUE; } if (redraw_flag) { set_ui_repaint_area (x1 + ui_x_origin, y1 + ui_y_origin, x2 + ui_x_origin + 1, y2 + ui_y_origin + 1); } unlock_screen (active_screen); } set_active_screen (old_active_screen); area->redraw --; call_ui_object_draw_function (obj, NULL); } }
static void draw_button_ui_object (ui_object *obj) { float // px1, // py1, x, //y, //vp_x1, //vp_y1, //vp_x2, //vp_y2, x_size, y_size, x_origin, y_origin, x1, y1, x2, y2; //nx1, //ny1, //nx2, //ny2; int redraw_flag = FALSE; // width, // height, // pitch; struct SCREEN *old_active_screen; // *memory_graphic; // unsigned short // *graphic; // unsigned char // *data; // ui_object // *parent; button_ui_object *button; button = obj->button; if (get_ui_object_redraw (obj)) { if (get_ui_object_autosize (obj)) { ui_object_autosize (obj); } //debug_log ("BU_DRAW: drawing button %f, %f %f, %f", button->area.x, button->area.y, button->area.x_size, button->area.y_size); //x1 = get_ui_object_x (obj); //y1 = get_ui_object_y (obj); x_size = get_ui_object_x_size (obj); y_size = get_ui_object_y_size (obj); x_origin = get_ui_object_x_origin (obj); y_origin = get_ui_object_y_origin (obj); ui_set_origin (x_origin, y_origin); //x2 = x1 + x_size;// - 1; //y2 = y1 + y_size;// - 1; x1 = get_ui_object_x (obj); y1 = get_ui_object_y (obj); x1 += x_origin; y1 += y_origin; x2 = x1 + get_ui_object_x_size (obj); y2 = y1 + get_ui_object_y_size (obj); old_active_screen = get_active_screen (); if (get_ui_object_active_screen (obj)) { set_active_screen (get_ui_object_active_screen (obj)); } else { set_active_screen (video_screen); } // debug set_active_screen (video_screen); // debug // if (lock_screen (active_screen)) { // memory_graphic = get_ui_object_memory_graphic (obj); if (!get_ui_object_clear (obj)) { switch (get_ui_object_graphic_type (obj)) { case UI_OBJECT_TEXTURE_GRAPHIC: { texture_graphic *graphic; if ((get_ui_object_state (obj) == UI_OBJECT_STATE_ON) && (get_ui_object_selected_texture_graphic (obj))) { graphic = get_ui_object_selected_texture_graphic (obj); } else if ((get_ui_object_highlighted (obj)) && (get_ui_object_highlighted_texture_graphic (obj))) { graphic = get_ui_object_highlighted_texture_graphic (obj); } else { graphic = get_ui_object_texture_graphic (obj); } if (graphic) { rgb_colour colour; real_colour text_colour; colour = get_ui_object_colour ( obj ); text_colour.red = colour.r; text_colour.green = colour.g; text_colour.blue = colour.b; text_colour.alpha = colour.a; ui_draw_texture_graphic (x1, y1, x2, y2, graphic, text_colour); } else { ui_draw_area (0, 0, x2 - x1, y2 - y1, obj); } break; } /* case UI_OBJECT_GRAPHIC: { if (get_ui_object_state (obj) == UI_OBJECT_STATE_ON) { graphic = get_ui_object_graphic (obj); ui_draw_graphic (x1, y1, x2, y2, graphic); redraw_flag = TRUE; } else { parent = get_ui_object_parent (obj); if (parent) { graphic = get_ui_object_graphic (parent); px1 = get_ui_object_x (parent); py1 = get_ui_object_y (parent); x1 -= px1; x2 -= px1; y1 -= py1; y2 -= py1; ui_draw_part_graphic (x1, y1, x2, y2, x1, y1, graphic); redraw_flag = TRUE; } } break; } case UI_OBJECT_MEMORY_GRAPHIC: { memory_graphic = get_ui_object_memory_graphic (obj); if (lock_screen (memory_graphic)) { width = get_screen_width (memory_graphic); height = get_screen_height (memory_graphic); data = get_screen_data (memory_graphic); pitch = get_screen_pitch (memory_graphic); ui_draw_memory_graphic (obj, x1, y1, x2, y2, width, height, pitch, FALSE); unlock_screen (memory_graphic); } redraw_flag = TRUE; break; } case UI_OBJECT_ALPHA_GRAPHIC: { if (!get_ui_object_clear (obj)) { graphic = get_ui_object_graphic (obj); ui_draw_alpha_graphic (x1, y1, x2, y2, graphic); redraw_flag = TRUE; } else { parent = get_ui_object_parent (obj); if (parent) { graphic = get_ui_object_graphic (parent); ui_draw_part_alpha_graphic (x1, y1, x2, y2, x1, y1, graphic); redraw_flag = TRUE; } } break; } */ case UI_OBJECT_NO_GRAPHIC: default: { int state; state = get_ui_object_state (obj); if ((state == UI_OBJECT_STATE_OFF) && (get_ui_object_highlighted (obj))) { state = UI_OBJECT_STATE_HIGHLIGHTED; } ui_draw_button (x1, y1, x2, y2, state); redraw_flag = TRUE; } } } if (get_ui_object_text (obj)) { const char *text_ptr; int count; float y3; ui_save_current_font (); ui_set_object_font (obj); // count number of lines spanned text_ptr = get_ui_object_text (obj); count = 0; while (text_ptr) { count ++; text_ptr = strchr (text_ptr, '\n'); // if found, step over it and display the next part of string if (text_ptr) { text_ptr ++; } } // now draw text text_ptr = get_ui_object_text (obj); get_text_y_position (&y3, y1, y2, text_ptr, get_ui_object_text_justify (obj), count); while (text_ptr) { get_text_x_position (&x, x1, x2, text_ptr, get_ui_object_text_justify (obj)); ui_display_text (text_ptr, x, y3); y3 += ui_get_font_height (); // check for carriage return text_ptr = strchr (text_ptr, '\n'); // if found, step over it and display the next part of string if (text_ptr) { text_ptr ++; } } ui_restore_current_font (); redraw_flag = TRUE; } if (redraw_flag) { set_ui_repaint_area (x1 - 1, y1 - 1, x2 + 1, y2 + 1); } // unlock_screen (active_screen); } set_active_screen (old_active_screen); button->area.redraw --; call_ui_object_draw_function (obj, NULL); } }
int update() { if (get_active_screen() == NULL) { return 1; } timestamp_t current = {0}; timestamp_set(¤t); long dt = timestamp_diff(¤t, &timer); if (dt > 0) { timer = current; screen_update(dt); } long fps_dt = timestamp_diff(¤t, &fps_timer); LOGD("DT: %ld", fps_dt); if (fps_dt > 500) { fps = frames * 1000.0f / (float)fps_dt; fps_timer = current; frames = 0; LOGI("FPS: %.2f", fps); } else { ++frames; } char fps_str[32] = {0}; sprintf(fps_str, "FPS: %.2f", fps); const rect_t fps_rect = { 8.0f, 8.0f, 256.0f, 32.0f }; const rgba_t fps_color = { 1.0f, 0.0f, 0.0f, 0.8f }; mat4f_t transform = {0}; mat4_mult(&transform, &camera.proj, &camera.view); rect_t screen = { 0, 0, screen_size.x, screen_size.y }; rgba_t color = {0.7f, 0.7f, 0.0f, 1.0f }; gfx_set_target(gfx, "test_target", &screen); gfx_enable_depth_buffer(gfx, 1); gfx_clear(gfx); screen_render(gfx, &camera); gfx_set_shader(gfx, "text"); gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform); draw_text(fps_str, &fps_rect, 0.0f, 4.9f, &fps_color); gfx_flush(gfx); static int take_screenshot = 0; if (take_screenshot && frames == 0) { take_screenshot = 0; image_t* img = NULL; if (gfx_take_screenshot(gfx, &img) == 0) { image_save_to_png(img, "screenshot.png"); image_free(img); } } gfx_set_target(gfx, NULL, &screen); gfx_enable_depth_buffer(gfx, 0); gfx_clear(gfx); int32_t sampler = 0; rect_t uv = { 0, screen.height/buffer_size.y, screen.width/buffer_size.x, -screen.height/buffer_size.y }; gfx_set_shader(gfx, "postprocess"); gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform); gfx_set_uniform_1i(gfx, "uTex", 1, &sampler); gfx_set_texture(gfx, "test_texture", sampler); gfx_render_textured_rect(gfx, &screen, 1.0f, &uv); gfx_set_texture(gfx, NULL, sampler); gfx_flush(gfx); return 0; }
void draw_high_score_table (void) { char buffer [256]; int loop, length; screen *old_active_screen; pilot_score_type *item; old_active_screen = get_active_screen (); set_active_screen ( video_screen ); if ( lock_screen ( active_screen ) ) { // // draw leaderboard // for (loop = 0; loop < NUM_TABLE_ENTRIES; loop ++) { item = &pilot_high_score_table [loop]; if (item->valid) { set_ui_font_type (UI_FONT_ARIAL_14); if (item->side == ENTITY_SIDE_BLUE_FORCE) { set_ui_font_colour (ui_colour_blue); } else { set_ui_font_colour (ui_colour_orange); } length = ui_get_string_length (item->name); sprintf (buffer, "%s : %d", item->name, item->kills); // print text assuming game-exit overlay is 640x480 centred in the screen whatever res. ui_display_text (buffer, get_integer_screen_x_mid () - length, iy_640_480 + 180 + (loop * (ui_get_font_height () + 1))); } } // // update flash timer // flash_timer += (FLASH_RATE * get_delta_time ()); flash_timer = frac (flash_timer); unlock_screen ( active_screen ); } set_active_screen ( old_active_screen ); }