static void menu_renderer_on_focus_in(struct menu_observer *observer) { struct menu_renderer *self = b6_cast_of(observer, struct menu_renderer, menu_observer); struct menu_entry_renderer *e = get_current_menu_entry_renderer(self); add_renderer_observer(self->renderer, &e->renderer_observer); }
int initialize_menu_renderer(struct menu_renderer *self, struct renderer *renderer, const struct b6_clock *clock, const char *skin_id) { static const struct renderer_observer_ops h_renderer_observer_ops = { .on_render = menu_renderer_image_on_render_h, }; static const struct renderer_observer_ops v_renderer_observer_ops = { .on_render = menu_renderer_image_on_render_v, }; static const struct renderer_observer_ops renderer_observer_ops = { .on_render = menu_renderer_on_render, }; struct renderer_base *root; self->renderer = renderer; self->clock = clock; self->menu = NULL; root = get_renderer_base(renderer); if (make_font(&self->normal_font, skin_id, MENU_NORMAL_FONT_DATA_ID)) return -1; make_font(&self->bright_font, skin_id, MENU_BRIGHT_FONT_DATA_ID); if ((self->background = create_renderer_tile(renderer, root, 0, 0, 640, 480, NULL))) set_renderer_tile_texture(self->background, make_texture( renderer, skin_id, MENU_BACKGROUND_DATA_ID)); initialize_menu_renderer_image(&self->title, renderer, self->clock, 70, -118, 500, 150, 32, 3e-4, skin_id, MENU_TITLE_DATA_ID, &v_renderer_observer_ops); initialize_menu_renderer_image(&self->pacman, renderer, self->clock, 640, 328, 96, 96, 440, 4e-4, skin_id, MENU_PACMAN_DATA_ID, &h_renderer_observer_ops); initialize_menu_renderer_image(&self->ghost, renderer, self->clock, -100, 304, 100, 124, 100, 4e-4, skin_id, MENU_GHOST_DATA_ID, &h_renderer_observer_ops); add_renderer_observer(self->renderer, setup_renderer_observer( &self->renderer_observer, "menu_renderer", &renderer_observer_ops)); return 0; }
static int initialize_menu_renderer_image( struct menu_renderer_image *self, struct renderer *renderer, const struct b6_clock *clock, float x, float y, float w, float h, float pos, float speed, const char *skin_id, const char *data_id, const struct renderer_observer_ops *ops) { struct renderer_base *root = get_renderer_base(renderer); struct renderer_texture *texture[2]; struct data_entry *entry; struct image_data *data; struct rgba rgba; self->base = NULL; if (get_image_data(skin_id, data_id, NULL, &entry, &data)) return -1; initialize_rgba(&rgba, data->w, data->h); copy_rgba(data->rgba, *data->x, *data->y, data->w, data->h, &rgba, 0, 0); texture[0] = create_renderer_texture_or_die(renderer, &rgba); make_shadow_rgba(&rgba); texture[1] = create_renderer_texture_or_die(renderer, &rgba); finalize_rgba(&rgba); self->base = create_renderer_base_or_die(renderer, root, "base", x, y); self->tile[1] = create_renderer_tile_or_die( renderer, create_renderer_base_or_die(renderer, self->base, "shadow", 3, 3), 0, 0, w, h, texture[1]); self->tile[0] = create_renderer_tile_or_die( renderer, create_renderer_base_or_die(renderer, self->base, "image", 0, 0), 0, 0, w, h, texture[0]); put_image_data(entry, data); if (ops->on_render == menu_renderer_image_on_render_v) setup_linear(&self->linear, clock, self->base->y, pos, speed); else setup_linear(&self->linear, clock, self->base->x, pos, speed); add_renderer_observer(renderer, setup_renderer_observer( &self->renderer_observer, data_id, ops)); return 0; }
static int hall_of_fame_phase_init(struct phase *up, const struct phase *prev) { static const struct controller_observer_ops controller_observer_ops = { .on_key_pressed = on_key_pressed, .on_text_input = on_text_input, }; static const struct renderer_observer_ops renderer_observer_ops = { .on_render = on_render, }; struct hall_of_fame_phase *self = b6_cast_of(up, struct hall_of_fame_phase, up); struct renderer *renderer = get_engine_renderer(up->engine); struct renderer_base *root; unsigned short int font_w, font_h; struct hall_of_fame_iterator iter; struct data_entry *entry; struct istream *is; const char *skin_id = hof_skin ? hof_skin : get_skin_id(); int i; self->array = open_hall_of_fame(&up->engine->hall_of_fame, up->engine->layout_provider->id, up->engine->game_config->entry.id); if (!self->array) return -1; if (b6_utf8_is_empty(&self->name.utf8)) { struct b6_utf8 utf8; if (user || (user = get_user_name())) b6_utf8_from_ascii(&utf8, user); else b6_clone_utf8(&utf8, B6_UTF8("PLAYER")); b6_clear_utf8_string(&self->name); b6_extend_utf8_string(&self->name, &utf8); } self->entry = NULL; self->quit = 0; if (prev == lookup_phase(B6_UTF8("game"))) { struct game_result game_result; get_last_game_result(up->engine, &game_result); self->entry = amend_hall_of_fame(self->array, game_result.level + 1, game_result.score); if (!self->entry) self->quit = 1; else alter_hall_of_fame_entry(self->entry, &self->name.utf8); } root = get_renderer_base(renderer); if (make_font(&self->font, skin_id, HOF_FONT_DATA_ID)) return -1; font_w = get_fixed_font_width(&self->font); font_h = get_fixed_font_height(&self->font); if ((self->background = create_renderer_tile(renderer, root, 0, 0, 640, 480, NULL))) set_renderer_tile_texture(self->background, make_texture( renderer, skin_id, HOF_BACKGROUND_DATA_ID)); if ((self->panel = create_renderer_tile(renderer, root, 0, 0, 112, 480, NULL))) set_renderer_tile_texture(self->panel, make_texture( renderer, skin_id, HOF_PANEL_DATA_ID)); for (i = 0; i < b6_card_of(self->label); i += 1) { const unsigned short int u = 2 + 32 * font_w, v = 2 + font_h; const float x = 96, y = 50 + i * 40; const float w = 2 + 32 * 16, h = 2 + 16; initialize_toolkit_label(&self->label[i], renderer, &self->font, u, v, root, x, y, w, h); enable_toolkit_label_shadow(&self->label[i]); } reset_hall_of_fame_iterator(&iter, self->array); for (i = 0; i < b6_card_of(self->label); i += 1) { struct b6_json_object *entry; if (!hall_of_fame_iterator_has_next(&iter)) break; entry = hall_of_fame_iterator_get_next(&iter); if (entry == self->entry) self->rank = i; setup_label(self, i, entry); } for (; i < b6_card_of(self->label); i += 1) hide_toolkit_label(&self->label[i]); if (self->entry) { float x = self->label[self->rank].image[0].tile->x + (16 + self->name.utf8.nchars) * 16; float y = self->label[self->rank].image[0].tile->y; self->cursor_base = create_renderer_base_or_die(renderer, root, "cursor", x, y); initialize_toolkit_label(&self->cursor_label, renderer, &self->font, 16, 16, self->cursor_base, 1, 1, 16, 16); enable_toolkit_label_shadow(&self->cursor_label); set_toolkit_label(&self->cursor_label, &b6_utf8_char['#']); } else self->cursor_base = NULL; add_renderer_observer(renderer, setup_renderer_observer( &self->renderer_observer, "hof", &renderer_observer_ops)); add_controller_observer(get_engine_controller(up->engine), setup_controller_observer( &self->controller_observer, &controller_observer_ops)); self->music = 0; initialize_fade_io(&self->fade_io, "hof_fade_io", renderer, up->engine->clock, 0., 1., 5e-6); if (self->quit) { set_fade_io_target(&self->fade_io, 0.); return 0; } if ((entry = lookup_data(skin_id, audio_data_type, HOF_MUSIC_DATA_ID)) && (is = get_data(entry))) { int retval = up->engine->mixer->ops->load_music_from_stream( up->engine->mixer, is); if (!retval) { play_music(up->engine->mixer); self->music = 1; } else log_w(_s("could not load background music")); put_data(entry, is); } else log_w(_s("cannot find background music")); return 0; }