Beispiel #1
0
void menubar_create(menubar_t *m)
{
	memset(m,0,sizeof(menubar_t));

	m->info.type = G_MENUBAR;
	m->info.x = 0;
	m->info.y = 0;
	m->info.w = 256;
	m->info.h = 14;
	m->info.draw = (drawfunc_t)menubar_draw;
	m->info.event = (eventfunc_t)menubar_event;

	//this needs to be configurable, passed thru in a struct
	menu_create(&m->menus[0],"\x1",4,recentitems);
	menu_create(&m->menus[1],"Game",m->menus[0].info.x + m->menus[0].info.w + 4,gameitems);
	menu_create(&m->menus[2],"Config",m->menus[1].info.x + m->menus[1].info.w + 4,configitems);
	menu_create(&m->menus[3],"Cheat",m->menus[2].info.x + m->menus[2].info.w + 4,miscitems);
	menu_create(&m->menus[4],"Debug",m->menus[3].info.x + m->menus[3].info.w + 4,debugitems);
	button_create(&m->buttons[0],"x",(256 - 9) - 3,3,click_quit);
	button_create(&m->buttons[1],"\x9",(256 - 33) - 1,3,click_minimize);
	button_create(&m->buttons[2],"\x8",(256 - 21) - 3,3,click_togglefullscreen);
	load_create(&m->load);
	video_create(&m->video);
	input_create(&m->input);
	gui_input_create(&m->guiinput);
	sound_create(&m->sound);
	devices_create(&m->devices);
	palette_create(&m->palette);
	options_create(&m->options);
	mappers_create(&m->mappers);
	paths_create(&m->paths);
	supported_mappers_create(&m->supported_mappers);
	rom_info_create(&m->rom_info);
	tracer_create(&m->tracer);
	memory_viewer_create(&m->memory_viewer);
	nt_create(&m->nametable_viewer);
	pt_create(&m->patterntable_viewer);
	about_create(&m->about);

	m->menus[0].click = click_recent;
	m->menus[1].click = click_game;
	m->menus[2].click = click_config;
	m->menus[3].click = click_debug;
	m->menus[4].click = click_misc;
	m->menus[0].user = m;
	m->menus[1].user = m;
	m->menus[2].user = m;
	m->menus[3].user = m;
	m->menus[4].user = m;

	//'hack' to update the 'freeze data' caption
	click_freezedata();
	click_freezedata();
}
Beispiel #2
0
//fonction d'affichage du menu
int menu_main()
{
	// 0. déclaration des ressources
	BITMAP* back = NULL;
	BITMAP* buffer = NULL;
	t_button* game = NULL;
	t_button* quit = NULL;
	//t_button* options = NULL;
	int ret;

	// 1. chargement du fond :
	back = load_bitmap_check("res/menu/menu_fond.bmp");

	// 2. création de la bitmap générale :
	buffer = create_bitmap(back->w, back->h);

	// 3. création des bouttons :
	game = button_create("res/menu/b_main_jouer_off.bmp", "res/menu/b_main_jouer_on.bmp", 100, 100);
	quit = button_create("res/menu/b_main_quitter_off.bmp", "res/menu/b_main_quitter_on.bmp", 800, 600);
	//option = button_create_m("res/menu/b_main_options_off.bmp", "res/menu/b_main_options_on.bmp", 300, 500);

	// 4. lancement de la routine d'affichage :
	do {
		// 4.1 on met à jouer les bouttons 
		button_maj(game);
		button_maj(quit);
		//button_maj(options);

		// 4.2 on blit les images sur le buffer :
		blit(back, buffer, 0, 0, 0, 0, back->w, back->h);
		button_blit(game, buffer);
		button_blit(quit, buffer);

		// 4.3 on test si un des bouttons a été cliqué :
		ret = 0;
		if(button_is_clicked(game)) ret = GAME;
		if(button_is_clicked(quit)) ret = QUIT;
		//if(button_is_clicked(option)) option();

		// 4.4 on affiche le menu à l'écran :
		stretch_blit(buffer, screen, 0, 0, buffer->w, buffer->h, 0, 0, SCREEN_W, SCREEN_H);

	}while(ret == 0);

	// 5. on détruit les images :
	destroy_bitmap(back);
	destroy_bitmap(buffer);
	button_destroy(quit);
	button_destroy(game);

	// 6. on retourne la valeur de l'utilisateur
	return ret;
}
Beispiel #3
0
widget_t*
calib_screen_create()
{
  calib_screen_t* s = calloc(1, sizeof(calib_screen_t));

  s->widget = widget_create(NULL, &calib_widget_class, s, display_rect);
  widget_set_background(s->widget, BLACK);

  rect_t rect = {
      .x = 15,
      .y = 15,
      .width = 56,
      .height = 56,
  };
  s->complete_button = button_create(s->widget, rect, img_left, WHITE, BLACK, complete_calib);
  widget_hide(s->complete_button);
  button_set_up_bg_color(s->complete_button, BLACK);
  button_set_up_icon_color(s->complete_button, WHITE);
  button_set_down_bg_color(s->complete_button, BLACK);
  button_set_down_icon_color(s->complete_button, LIGHT_GRAY);
  button_set_disabled_bg_color(s->complete_button, BLACK);
  button_set_disabled_icon_color(s->complete_button, DARK_GRAY);

  rect.x = 320 - 56 - 15;
  rect.y = 240 - 56 - 15;
  s->recal_button = button_create(s->widget, rect, img_update, WHITE, BLACK, restart_calib);
  widget_hide(s->recal_button);
  button_set_up_bg_color(s->recal_button, BLACK);
  button_set_up_icon_color(s->recal_button, WHITE);
  button_set_down_bg_color(s->recal_button, BLACK);
  button_set_down_icon_color(s->recal_button, LIGHT_GRAY);
  button_set_disabled_bg_color(s->recal_button, BLACK);
  button_set_disabled_icon_color(s->recal_button, DARK_GRAY);

  rect.x = 50;
  rect.y = 100;
  rect.width = 175;
  s->lbl_instructions = label_create(s->widget, rect, "Touch and hold the marker until it turns green", font_opensans_regular_18, WHITE, 3);

  gui_msg_subscribe(MSG_TOUCH_INPUT, s->widget);

  return s->widget;
}

static void
calib_widget_destroy(widget_t* w)
{
  calib_screen_t* s = widget_get_instance_data(w);
  gui_msg_unsubscribe(MSG_TOUCH_INPUT, s->widget);
  free(s);
}
Beispiel #4
0
void rom_info_create(rom_info_t *m)
{
    int x,y,i;

    memset(m,0,sizeof(rom_info_t));

    m->info.type = G_WINDOW;
    x = m->info.x = 7;
    y = m->info.y = 30;
    m->info.w = 243;
    m->info.h = 120;
    m->info.draw = (drawfunc_t)rom_info_draw;
    m->info.event = (eventfunc_t)rom_info_event;

    button_create(&m->donebtn,"X",x+m->info.w-10,y,0);

    x += 3;
    y += 2 + 11;

    for(i=0; i<10; i++) {
        text_create(&m->labels[i],x,y,"A");
        text_create(&m->labels[i+10],x+(10*6),y,"B");
        y += 10;
    }
}
Beispiel #5
0
void mappers_create(mappers_t *m)
{
	int x,y;
	u8 dip = 0;

	memset(m,0,sizeof(mappers_t));

	m->info.type = G_WINDOW;
	x = m->info.x = 20;
	y = m->info.y = 40;
	m->info.w = 200;
	m->info.h = 100;
	m->info.draw = (drawfunc_t)mappers_draw;
	m->info.event = (eventfunc_t)mappers_event;

	button_create(&m->donebtn,"Done",x+m->info.w-(6*6),124,0);

	x += 3;
	y += 2 + 11;

	text_create(&m->label,x,y,"Nothing to configure.");

	//mapper 105 controls
	text_create(&m->m105_label,x,y,"Time Limit");
	checkbox_create(&m->m105_check[0],x,y+10*1,"DIP1",(dip >> 0) & 1,click_mapper105_check0);
	checkbox_create(&m->m105_check[1],x,y+10*2,"DIP2",(dip >> 1) & 1,click_mapper105_check1);
	checkbox_create(&m->m105_check[2],x,y+10*3,"DIP3",(dip >> 2) & 1,click_mapper105_check2);
	checkbox_create(&m->m105_check[3],x,y+10*4,"DIP4",(dip >> 3) & 1,click_mapper105_check3);
}
Beispiel #6
0
void video_create(video_t *m)
{
    int i,x,y;

    memset(m,0,sizeof(video_t));

    m->info.type = G_WINDOW;
    x = m->info.x = 15;
    y = m->info.y = 40;
    m->info.w = 220;
    m->info.h = 110;
    m->info.draw = (drawfunc_t)video_draw;
    m->info.event = (eventfunc_t)video_event;

    button_create(&m->donebtn,"Done",x+m->info.w-(6*6)+2,136,0);

    radiogroup_create(&m->filter,x+2,y+12,"Video Filter",config.filter,filter_caps,changed_filter);

    if(config.windowed == 0)
        i = config.fullscreen + 4;
    else
        i = config.windowscale - 1;
    radiogroup_create(&m->videomode,x+2+84,y+12,"Video Mode",i,videomode_caps,changed_videomode);

    m->filter.user = m;

    x += 3;
    y += 2 + 11;
}
Beispiel #7
0
void user_init(void) {
    uart_set_baud(0, 115200);

    wifi_init();
    if (button_create(BUTTON_PIN, button_callback)) {
        printf("Failed to initialize button\n");
    }
    homekit_server_init(&config);
}
Beispiel #8
0
static GtkWidget *
toolbar_new(gint type)
{
    GtkWidget *button;
    GtkWidget *hbox;
    GList *prop_buttons = NULL;
    GtkSizeGroup *sg;

    /*
     * Set uim-toolbar-save-default-im? #t in ~/.uim enable this if you'd like to
     * save default IM into ~/.uim.d/custom/custom-global.scm upon system global
     * IM switch.  However, using uim-custom consumes quite amount of memory, and
     * requires additional startup time.
     */
    if (uim_scm_symbol_value_bool("uim-toolbar-save-default-im?"))
        custom_enabled = (gboolean)uim_custom_enable();

    helper_toolbar_check_custom();
    init_icon();

    /* create widgets */
#if GTK_CHECK_VERSION(3, 2, 0)
    hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
#else
    hbox = gtk_hbox_new(FALSE, 0);
#endif

    im_menu = gtk_menu_new();
    prop_menu = gtk_menu_new();
    right_click_menu = right_click_menu_create();
    sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);

    /* prop menu button */
    button = button_create(hbox, sg, "uim-icon", " x", type);

    gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);

    prop_buttons = g_list_append(prop_buttons, button);

    g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_PROP_BUTTONS, prop_buttons);
    g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_SIZE_GROUP, sg);
    g_object_set_data(G_OBJECT(hbox), OBJECT_DATA_TOOLBAR_TYPE,
                      GINT_TO_POINTER(type));

    uim_fd = -1;

    if (type != TYPE_ICON) {
        /* delay initialization until getting "embedded" signal */
        uim_toolbar_check_helper_connection(hbox);
        uim_helper_client_get_prop_list();
        uim_toolbar_get_im_list();
    }

    return hbox;
}
Beispiel #9
0
/** @copydoc widgetdata::draw_func */
static void widget_draw(widgetdata *widget)
{
    SDL_Rect box;
    size_t i;

    /* Create the skill list. */
    if (!list_skills) {
        list_skills = list_create(5, 4, 8);
        list_skills->post_column_func = list_post_column;
        list_skills->row_color_func = list_row_color;
        list_skills->row_selected_func = NULL;
        list_skills->row_highlight_func = NULL;
        list_skills->surface = widget->surface;
        list_skills->row_height_adjust = INVENTORY_ICON_SIZE;
        list_set_font(list_skills, NULL);
        list_scrollbar_enable(list_skills);
        list_set_column(list_skills, 0, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 1, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 2, INVENTORY_ICON_SIZE, 0, NULL, -1);
        list_set_column(list_skills, 3, INVENTORY_ICON_SIZE, 0, NULL, -1);
        skill_list_reload();

        for (i = 0; i < BUTTON_NUM; i++) {
            button_create(&buttons[i]);
            buttons[i].texture = texture_get(TEXTURE_TYPE_CLIENT, "button_round");
            buttons[i].texture_pressed = texture_get(TEXTURE_TYPE_CLIENT, "button_round_down");
            buttons[i].texture_over = texture_get(TEXTURE_TYPE_CLIENT, "button_round_over");
        }
    }

    if (widget->redraw) {
        box.h = 0;
        box.w = widget->w;
        text_show(widget->surface, FONT_SERIF12, "Skills", 0, 3, COLOR_HGOLD, TEXT_ALIGN_CENTER, &box);
        list_set_parent(list_skills, widget->x, widget->y);
        list_show(list_skills, 10, 2);

        for (i = 0; i < BUTTON_NUM; i++) {
            buttons[i].surface = widget->surface;
            button_set_parent(&buttons[i], widget->x, widget->y);
        }

        buttons[BUTTON_CLOSE].x = widget->w - texture_surface(buttons[BUTTON_CLOSE].texture)->w - 4;
        buttons[BUTTON_CLOSE].y = 4;
        button_show(&buttons[BUTTON_CLOSE], "X");

        buttons[BUTTON_HELP].x = widget->w - texture_surface(buttons[BUTTON_HELP].texture)->w * 2 - 4;
        buttons[BUTTON_HELP].y = 4;
        button_show(&buttons[BUTTON_HELP], "?");
    }
}
Beispiel #10
0
/** @copydoc widgetdata::background_func */
static void widget_background(widgetdata *widget, int draw)
{
    size_t i;

    /* Create the party list. */
    if (!list_party) {
        list_party = list_create(12, 2, 8);
        list_party->handle_enter_func = list_handle_enter;
        list_party->text_flags = TEXT_MARKUP;
        list_party->row_highlight_func = list_row_highlight;
        list_party->row_selected_func = list_row_selected;
        list_scrollbar_enable(list_party);
        list_set_column(list_party, 0, 130, 7, NULL, -1);
        list_set_column(list_party, 1, 60, 7, NULL, -1);
        list_party->header_height = 6;

        for (i = 0; i < BUTTON_NUM; i++) {
            button_create(&buttons[i]);

            if (i == BUTTON_CLOSE || i == BUTTON_HELP) {
                buttons[i].texture = texture_get(TEXTURE_TYPE_CLIENT, "button_round");
                buttons[i].texture_pressed = texture_get(TEXTURE_TYPE_CLIENT, "button_round_down");
                buttons[i].texture_over = texture_get(TEXTURE_TYPE_CLIENT, "button_round_over");
            } else if (i == BUTTON_PARTIES || i == BUTTON_MEMBERS) {
                buttons[i].flags = TEXT_MARKUP;
            }
        }

        widget->redraw = 1;
        list_contents = -1;
    }

    if (!widget->redraw) {
        widget->redraw = list_need_redraw(list_party);
    }

    if (!widget->redraw) {
        for (i = 0; i < BUTTON_NUM; i++) {
            if (button_need_redraw(&buttons[i])) {
                widget->redraw = 1;
                break;
            }
        }
    }
}
Beispiel #11
0
void sound_create(sound_t *m)
{
	int x,y;
	u8 channels = config.soundchannels;

	memset(m,0,sizeof(sound_t));

	m->info.type = G_WINDOW;
	x = m->info.x = 50;
	y = m->info.y = 50;
	m->info.w = 150;
	m->info.h = 93;
	m->info.draw = (drawfunc_t)sound_draw;
	m->info.event = (eventfunc_t)sound_event;

	button_create(&m->donebtn,"Done",x+m->info.w-(6*6),y + m->info.h - 15,0);

	x += 3;
	y += 3;

	checkbox_create(&m->enabled,x+2,y+12,"Enabled",config.soundenabled,click_soundenabled);

	y += 8 + 5;

	text_create(&m->tc,x+2,y+12+8*0,"Channels enabled:");
	x += 5;
	checkbox_create(&m->sq1,x+2,y+12+9*1,"Square 1",(channels & 1) ? 1 : 0,click_sq1);
	checkbox_create(&m->sq2,x+2,y+12+9*2,"Square 2",(channels & 2) ? 1 : 0,click_sq2);
	checkbox_create(&m->tri,x+2,y+12+9*3,"Triangle",(channels & 4) ? 1 : 0,click_tri);
	checkbox_create(&m->noise,x+2,y+12+9*4,"Noise",(channels & 8) ? 1 : 0,click_noise);
	checkbox_create(&m->dmc,x+2,y+12+9*5,"DMC",(channels & 0x10) ? 1 : 0,click_dmc);
	checkbox_create(&m->ext,x+2,y+12+9*6,"External",(channels & 0x20) ? 1 : 0,click_ext);

	m->enabled.user = m;
	m->sq1.user = m;
	m->sq2.user = m;
	m->tri.user = m;
	m->noise.user = m;
	m->dmc.user = m;
	m->ext.user = m;

	x += 3;
	y += 2 + 11;
}
Beispiel #12
0
/**
 * Initialize one mplayer widget.
 */
void widget_mplayer_init(widgetdata *widget)
{
    widget->draw_func = widget_draw;
    widget->background_func = widget_background;
    widget->event_func = widget_event;
    widget->deinit_func = widget_deinit;

    for (size_t i = 0; i < BUTTON_NUM; i++) {
        button_create(&buttons[i]);

        if (i == BUTTON_BLACKLIST || i == BUTTON_HELP || i == BUTTON_CLOSE) {
            buttons[i].texture = texture_get(TEXTURE_TYPE_CLIENT,
                    "button_round");
            buttons[i].texture_pressed = texture_get(TEXTURE_TYPE_CLIENT,
                    "button_round_down");
            buttons[i].texture_over = texture_get(TEXTURE_TYPE_CLIENT,
                    "button_round_over");
        }
    }
}
Beispiel #13
0
ErrorScreen *errorscreen_create(Display *display, const gchar *message, GError **err) {
	g_return_val_if_fail(err == NULL || *err == NULL, NULL);
	g_assert(display != NULL);

	ErrorScreen *error = g_new0(ErrorScreen, 1);
	error->display = display;
	error->screen = screen_create(error, errorscreen_quark());
	error->screen->update = errorscreen_update;
	error->screen->process_event = errorscreen_process_event;
	error->screen->free = errorscreen_free_from_entity;

	// Create a semi-transparent background
	error->background = rect_osd_create(display, 0, 0, screenWidth, screenHeight, NULL, err);
	if (error->background == NULL) {
		errorscreen_free(error);
		return NULL;
	}
	rect_osd_set_opacity(error->background, 80);
	rect_osd_set_alignment(error->background, ALIGN_CENTER, ALIGN_MIDDLE);

	const Renderable* parent = rect_osd_get_renderable(error->background);

	// Create a pause message
	error->message = text_osd_create(display, message, parent, err);
	if (error->message == NULL) {
		errorscreen_free(error);
		return NULL;
	}
	text_osd_set_alignment(error->message, ALIGN_CENTER, ALIGN_MIDDLE);
	text_osd_set_position(error->message, 0, -20);
	text_osd_set_size(error->message, 240, 7);
	text_osd_set_color(error->message, 220, 220, 220);

	error->quit = button_create(display, "Quit", 90, 80, 60, 15, &errorscreen_on_quit, parent, err);
	if (error->quit == NULL) {
		errorscreen_free(error);
		return NULL;
	}

	return error;
}
Beispiel #14
0
static GtkWidget *
prop_button_create(GtkWidget *widget, const gchar *icon_name,
                   const gchar *label, const gchar *tip_text)
{
    GtkWidget *button;
    GtkSizeGroup *sg;
    gint type;

    sg = g_object_get_data(G_OBJECT(widget), OBJECT_DATA_SIZE_GROUP);
    type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget),
                           OBJECT_DATA_TOOLBAR_TYPE));

    button = button_create(widget, sg, icon_name, label, type);

    gtk_widget_set_tooltip_text(button, tip_text);

    g_signal_connect(G_OBJECT(button), "button-release-event",
                     G_CALLBACK(prop_button_released), widget);

    return button;
}
Beispiel #15
0
void about_create(about_t *m)
{
	int i,x,y;

	memset(m,0,sizeof(about_t));

	m->info.type = G_WINDOW;
	x = m->info.x = 40;
	y = m->info.y = 20;
	m->info.w = 201;
	m->info.h = 140;
	m->info.draw = (drawfunc_t)about_draw;
	m->info.event = (eventfunc_t)about_event;

	button_create(&m->donebtn,"Done",x+m->info.w-(6*6),y+m->info.h-15,0);

	memset(m->text,0,sizeof(text_t) * 12);

	for(i=0;lines[i];i++)
		text_create(&m->text[i],x+3,y+12+8*i,lines[i]);

}
Beispiel #16
0
void options_create(options_t *m)
{
	int x,y;

	memset(m,0,sizeof(options_t));

	m->info.type = G_WINDOW;
	x = m->info.x = 20;
	y = m->info.y = 40;
	m->info.w = 200;
	m->info.h = 100;
	m->info.draw = (drawfunc_t)options_draw;
	m->info.event = (eventfunc_t)options_event;

	button_create(&m->donebtn,"Done",x+m->info.w-(6*6),124,0);

	radiogroup_create(&m->fdsbios,x+3,y+12,"CD Bios",/*config.cdbios*/0,cdbios_caps,changed_cdbios);

	checkbox_create(&m->showinfo,x+3,y+40,"Show ROM Name/FPS at top",config.showinfo,click_showinfo);

	x += 3;
	y += 2 + 11;
}
Beispiel #17
0
widget_t*
home_screen_create()
{
  home_screen_t* s = calloc(1, sizeof(home_screen_t));

  s->sample_timestamp = chTimeNow();

  s->screen = widget_create(NULL, &home_widget_class, s, display_rect);
  widget_set_background(s->screen, BLACK);

  rect_t rect = {
      .x      = TILE_X(0),
      .y      = TILE_Y(0),
      .width  = TILE_SPAN(3),
      .height = TILE_SPAN(2),
  };
  s->stage_widget = widget_create(s->screen, NULL, NULL, rect);
  widget_set_background(s->stage_widget, GREEN);

  rect.x = TILE_X(3);
  rect.width = TILE_SPAN(1);
  rect.height = TILE_SPAN(1);
  s->sensors[SENSOR_1].button = button_create(s->screen, rect, img_temp_med, WHITE, STEEL, click_sensor_button);

  rect.y = TILE_Y(1);
  s->sensors[SENSOR_2].button = button_create(s->screen, rect, img_temp_med, WHITE, STEEL, click_sensor_button);

  rect.x = TILE_X(0);
  rect.y = TILE_Y(2);
  s->outputs[OUTPUT_1].button = button_create(s->screen, rect, img_plug, WHITE, STEEL, click_output_button);

  rect.x = TILE_X(1);
  s->outputs[OUTPUT_2].button = button_create(s->screen, rect, img_plug, WHITE, STEEL, click_output_button);

  rect.x = TILE_X(2);
  s->conn_button = button_create(s->screen, rect, img_signal, RED, STEEL, click_conn_button);

  rect.x = TILE_X(3);
  s->settings_button = button_create(s->screen, rect, img_settings, WHITE, COBALT, click_settings_button);

  rect.x = 0;
  rect.width = TILE_SPAN(3);
  s->sensors[SENSOR_1].quantity_widget = quantity_widget_create(s->stage_widget, rect, app_cfg_get_temp_unit());
  widget_disable(s->sensors[SENSOR_1].quantity_widget);

  s->sensors[SENSOR_2].quantity_widget = quantity_widget_create(s->stage_widget, rect, app_cfg_get_temp_unit());
  widget_disable(s->sensors[SENSOR_2].quantity_widget);

  place_quantity_widgets(s);

  set_output_settings(s, OUTPUT_1,
      temp_control_get_output_function(OUTPUT_1));
  set_output_settings(s, OUTPUT_2,
      temp_control_get_output_function(OUTPUT_2));

  gui_msg_subscribe(MSG_SENSOR_SAMPLE, s->screen);
  gui_msg_subscribe(MSG_SENSOR_TIMEOUT, s->screen);
  gui_msg_subscribe(MSG_OUTPUT_STATUS, s->screen);
  gui_msg_subscribe(MSG_TEMP_UNIT, s->screen);
  gui_msg_subscribe(MSG_NET_STATUS, s->screen);
  gui_msg_subscribe(MSG_API_STATUS, s->screen);
  gui_msg_subscribe(MSG_CONTROLLER_SETTINGS, s->screen);
  gui_msg_subscribe(MSG_API_CONTROLLER_SETTINGS, s->screen);

  return s->screen;
}

void
home_screen_destroy(widget_t* w)
{
  home_screen_t* s = widget_get_instance_data(w);

  gui_msg_unsubscribe(MSG_SENSOR_SAMPLE, s->screen);
  gui_msg_unsubscribe(MSG_SENSOR_TIMEOUT, s->screen);
  gui_msg_unsubscribe(MSG_OUTPUT_STATUS, s->screen);
  gui_msg_unsubscribe(MSG_TEMP_UNIT, s->screen);
  gui_msg_unsubscribe(MSG_NET_STATUS, s->screen);
  gui_msg_unsubscribe(MSG_API_STATUS, s->screen);
  gui_msg_unsubscribe(MSG_CONTROLLER_SETTINGS, s->screen);
  gui_msg_unsubscribe(MSG_API_CONTROLLER_SETTINGS, s->screen);

  free(s);
}
Beispiel #18
0
static void preference_init(void)
{
    list_t sound_list = NULL;
    list_t video_list = NULL;
    point2d_t dummy_pos = {0, 0};

    int* opt1 = malloc(sizeof(int));
    *opt1 = 0;
    int* opt2 = malloc(sizeof(int));
    *opt2 = 1;
    int* opt3 = malloc(sizeof(int));
    *opt3 = 2;

    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( ui_event_mouse_func );
    winsys_set_motion_func( ui_event_motion_func );
    winsys_set_passive_motion_func( ui_event_motion_func );
    
    sound_list = create_list();
    list_elem_t last_sound = get_list_tail( sound_list );
    last_sound = insert_list_elem( sound_list, last_sound, (list_elem_data_t) opt1);
    if (getparam_sound_enabled() == *opt1)
        cur_sound = last_sound;
    last_sound = insert_list_elem( sound_list, last_sound, (list_elem_data_t) opt2);
    if (getparam_sound_enabled() == *opt2)
        cur_sound = last_sound;

    video_list = create_list();
    list_elem_t last_video = get_list_tail( video_list );
    last_video = insert_list_elem( video_list, last_video, (list_elem_data_t) opt1);
    if (getparam_video_quality() == *opt1)
        cur_video = last_video;
    last_video = insert_list_elem( video_list, last_video, (list_elem_data_t) opt2);
    if (getparam_video_quality() == *opt2)
        cur_video = last_video;
    last_video = insert_list_elem( video_list, last_video, (list_elem_data_t) opt3);    
    if (getparam_video_quality() == *opt3)
        cur_video = last_video;

    chancel_btn = button_create( dummy_pos,
                             80 * mWidth / 480, 48 * mHeight / 320, 
                             "button_label", 
                             (mWidth>320)?"Back":"<< " );
    button_set_hilit_font_binding( chancel_btn, "button_label_hilit" );
    button_set_visible( chancel_btn, True );
    button_set_click_event_cb( chancel_btn, chancel_click_cb, NULL );
    
    save_btn = button_create( dummy_pos,
                                 80 * mWidth / 480, 48 * mHeight / 320,
                                 "button_label",
                                 (mWidth>320)?"Save":" >>" );
    button_set_hilit_font_binding( save_btn, "button_label_hilit" );
    button_set_disabled_font_binding( save_btn, "button_label_disabled" );
    button_set_visible( save_btn, True );
    button_set_click_event_cb( save_btn, save_click_cb, NULL );

    sound_listbox = listbox_create( dummy_pos,
                                   120 * mHeight / 320, 44 * mHeight / 320,
                                   "listbox_item",
                                   sound_list,
                                   sound_list_elem_to_string_func );
    
    listbox_set_current_item( sound_listbox, cur_sound );
    
    listbox_set_item_change_event_cb( sound_listbox, 
                                     sound_listbox_item_change_cb, 
                                     NULL );
    
    listbox_set_visible( sound_listbox, True );


    
    video_listbox = listbox_create( dummy_pos,
                                 120 * mHeight / 320, 44 * mHeight / 320,
                                 "listbox_item",
                                 video_list,
                                 video_list_elem_to_string_func );
    
    listbox_set_current_item( video_listbox, cur_video );
    
    listbox_set_item_change_event_cb( video_listbox, 
                                     video_listbox_item_change_cb, 
                                     NULL );
    
    listbox_set_visible( video_listbox, True );
    
    play_music( "start_screen" );
}
Beispiel #19
0
/*! 
  Creates a new listbox
  \return  The new listbox object
  \author  jfpatry
  \date    Created:  2000-09-17
  \date    Modified: 2000-09-17
*/
listbox_t* listbox_create( point2d_t pos, scalar_t w, scalar_t h, 
			   char *font_binding, list_t item_list,
			   listbox_list_elem_to_string_fptr_t func )
{
    listbox_t *listbox;
    char *binding;
    point2d_t ll;
    point2d_t ur;

    listbox = (listbox_t*)malloc( sizeof(listbox_t) );

    check_assertion( listbox != NULL, "out of memory" );

    listbox->pos = pos;
    listbox->w = w;
    listbox->h = h;
    listbox->arrow_width = DEFAULT_ARROW_REGION_WIDTH;
    listbox->border_width = DEFAULT_BORDER_WIDTH;
    listbox->text_pad = DEFAULT_TEXT_PAD;
    listbox->arrow_vert_separation = DEFAULT_ARROW_VERT_SEPARATION;
    listbox->font_binding = font_binding;
    listbox->border_colour = ui_foreground_colour;
    listbox->background_colour = ui_background_colour; 

    /* Create up arrow button */
    listbox->up_button = button_create( 
	make_point2d( 0, 0 ), /* position will be set later */
	DEFAULT_ARROW_BUTTON_WIDTH,
	(mWidth>320)?DEFAULT_ARROW_BUTTON_HEIGHT:DEFAULT_ARROW_BUTTON_HEIGHT/2,
	NULL,
	NULL );

    binding = "listbox_arrows";

    ll = make_point2d( 0.0/64.0, 16.0/64.0 );
    ur = make_point2d( 32.0/64.0, 32.0/64.0 );
    button_set_image( listbox->up_button, binding, ll, ur, white );

    ll = make_point2d( 32.0/64.0, 16.0/64.0 );
    ur = make_point2d( 64.0/64.0, 32.0/64.0 );
    button_set_disabled_image( listbox->up_button, binding, ll, ur, 
			       white );

    ll = make_point2d( 32.0/64.0, 48.0/64.0 );
    ur = make_point2d( 64.0/64.0, 64.0/64.0 );
    button_set_hilit_image( listbox->up_button, binding, ll, ur, 
			    white );

    ll = make_point2d( 0.0/64.0, 48.0/64.0 );
    ur = make_point2d( 32.0/64.0, 64.0/64.0 );
    button_set_clicked_image( listbox->up_button, binding, ll, ur, 
			      white );


    button_set_click_event_cb( listbox->up_button, 
			       listbox_arrow_click_cb,
			       listbox );

    /* Create down arrow button */
    listbox->down_button = button_create( 
	make_point2d( 0, 0 ), /* position will be set later */
	DEFAULT_ARROW_BUTTON_WIDTH,
	(mWidth>320)?DEFAULT_ARROW_BUTTON_HEIGHT:DEFAULT_ARROW_BUTTON_HEIGHT/2,
	NULL,
	NULL );

    binding = "listbox_arrows";

    ll = make_point2d( 0.0/64.0, 0.0/64.0 );
    ur = make_point2d( 32.0/64.0, 16.0/64.0 );
    button_set_image( listbox->down_button, binding, ll, ur, white );

    ll = make_point2d( 32.0/64.0, 0.0/64.0 );
    ur = make_point2d( 64.0/64.0, 16.0/64.0 );
    button_set_disabled_image( listbox->down_button, binding, ll, ur, 
			       white );

    ll = make_point2d( 32.0/64.0, 32.0/64.0 );
    ur = make_point2d( 64.0/64.0, 48.0/64.0 );
    button_set_hilit_image( listbox->down_button, binding, ll, ur, 
			    white );

    ll = make_point2d( 0.0/64.0, 32.0/64.0 );
    ur = make_point2d( 32.0/64.0, 48.0/64.0 );
    button_set_clicked_image( listbox->down_button, binding, ll, ur, 
			      white );

    button_set_click_event_cb( listbox->down_button, 
			       listbox_arrow_click_cb,
			       listbox );

    button_set_click_event_cb( listbox->down_button, 
			       listbox_arrow_click_cb,
			       listbox );

    listbox->item_change_cb = NULL;
    listbox->item_change_cb_userdata = NULL;

    listbox->item_list = item_list;
    listbox->cur_item = get_list_head( listbox->item_list );

    listbox->label_gen_func = func;

    listbox->visible = False;
    listbox->active = False;

    update_button_enabled_states( listbox );

    update_button_positions( listbox );

    return listbox;
}
static void game_type_select_init(void)
{
    point2d_t dummy_pos = {0, 0};

    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( ui_event_mouse_func );
    winsys_set_motion_func( ui_event_motion_func );
    winsys_set_passive_motion_func( ui_event_motion_func );

    enter_event_btn = button_create( dummy_pos,
				     300 * mHeight / 320, 40 * mHeight / 320, 
				     "button_label", 
				     "Challenge" );
    button_set_hilit_font_binding( enter_event_btn, "button_label_hilit" );
    button_set_visible( enter_event_btn, True );
    button_set_click_event_cb( enter_event_btn, enter_event_click_cb, NULL );

    practice_btn = button_create( dummy_pos,
				  300 * mHeight / 320, 40 * mHeight / 320,
				  "button_label",
				  //"World challenge" );
				  "Freestyle" );
    button_set_hilit_font_binding( practice_btn, "button_label_hilit" );
    button_set_visible( practice_btn, True );
    button_set_click_event_cb( practice_btn, practice_click_cb, NULL );

    preference_btn = button_create( dummy_pos,
				  300 * mHeight / 320, 40 * mHeight / 320,
				  "button_label",
				  "Preference" );
    button_set_hilit_font_binding( preference_btn, "button_label_hilit" );
    button_set_visible( preference_btn, True );
    button_set_click_event_cb( preference_btn, preference_click_cb, NULL );

    credits_btn = button_create( dummy_pos,
				  300 * mHeight / 320, 40 * mHeight / 320,
				  "button_label",
				  "Credits" );
    button_set_hilit_font_binding( credits_btn, "button_label_hilit" );
    button_set_visible( credits_btn, True );
    button_set_click_event_cb( credits_btn, credits_click_cb, NULL );

    help_btn = button_create( dummy_pos,
				  300 * mHeight / 320, 40 * mHeight / 320,
				  "button_label",
				  "Help" );
    button_set_hilit_font_binding( help_btn, "button_label_hilit" );
    button_set_visible( help_btn, True );
    button_set_click_event_cb( help_btn, help_click_cb, NULL );

    quit_btn = button_create( dummy_pos,
			      300 * mHeight / 320, 40 * mHeight / 320,
			      "button_label",
			      "Quit" );
    button_set_hilit_font_binding( quit_btn, "button_label_hilit" );
    button_set_visible( quit_btn, True );
    button_set_click_event_cb( quit_btn, quit_click_cb, NULL );
    /*
    rankings_btn = button_create( dummy_pos,
                             300, 40,
                             "button_label",
                             "World rankings" );
    button_set_hilit_font_binding( rankings_btn, "button_label_hilit" );
    button_set_visible( rankings_btn, True );
    button_set_click_event_cb( rankings_btn, rankings_click_cb, NULL );
    
    pref_btn = button_create( dummy_pos,
                             300, 40,
                             "button_label",
                             "Settings" );
    button_set_hilit_font_binding( pref_btn, "button_label_hilit" );
    button_set_visible( pref_btn, True );
    button_set_click_event_cb( pref_btn, pref_click_cb, NULL );
    */

    play_music( "start_screen" );
}
Beispiel #21
0
void
textentry_screen_show(textentry_format_t format, text_handler_t text_handler, void* user_data)
{
  int i;
  textentry_screen_t* screen = calloc(1, sizeof(textentry_screen_t));

  screen->text_handler = text_handler;
  screen->user_data = user_data;

  switch (format) {
    case TXT_FMT_IP:
      screen->btn_layout = btn_layout_numeric;
      screen->num_rows = NUM_ROWS_NUMERIC;
      break;

    default:
    case TXT_FMT_ANY:
      screen->btn_layout = btn_layout_all;
      screen->num_rows = NUM_ROWS_ALL;
      break;
  }

  screen->widget = widget_create(NULL, &textentry_screen_widget_class, screen, display_rect);

  rect_t rect = {
      .x = 7,
      .y = 5,
      .width = 48,
      .height = 48,
  };
  widget_t* back_btn = button_create(screen->widget, rect, img_cancel, WHITE, BLACK, back_button_clicked);
  button_set_up_bg_color(back_btn, BLACK);
  button_set_up_icon_color(back_btn, WHITE);
  button_set_down_bg_color(back_btn, BLACK);
  button_set_down_icon_color(back_btn, LIGHT_GRAY);
  button_set_disabled_bg_color(back_btn, BLACK);
  button_set_disabled_icon_color(back_btn, DARK_GRAY);

  rect.x = 7;
  rect.y = 65;
  for (i = 0; i < NUM_VISIBLE_ROWS; ++i) {
    int j;
    for (j = 0; j < NUM_BUTTONS_PER_ROW; ++j) {
      widget_t* b = button_create(screen->widget, rect, img_circle, WHITE, BLACK, char_button_clicked);
      button_set_font(b, font_opensans_regular_22);
      button_set_up_bg_color(b, BLACK);
      button_set_up_icon_color(b, WHITE);
      button_set_down_bg_color(b, BLACK);
      button_set_down_icon_color(b, LIGHT_GRAY);
      button_set_disabled_bg_color(b, BLACK);
      button_set_disabled_icon_color(b, DARK_GRAY);

      screen->buttons[i][j] = b;
      rect.x += 52;
    }
    rect.y += 58;
    rect.x = 7;
  }

  rect.x = 268;
  rect.y = 5;
  widget_t* b = button_create(screen->widget, rect, img_check, WHITE, BLACK, ok_button_clicked);
  button_set_up_bg_color(b, BLACK);
  button_set_up_icon_color(b, WHITE);
  button_set_down_bg_color(b, BLACK);
  button_set_down_icon_color(b, LIGHT_GRAY);
  button_set_disabled_bg_color(b, BLACK);
  button_set_disabled_icon_color(b, DARK_GRAY);

  rect.y = 65;
  b = button_create(screen->widget, rect, img_backspace, WHITE, BLACK, backspace_button_clicked);
  button_set_up_bg_color(b, BLACK);
  button_set_up_icon_color(b, WHITE);
  button_set_down_bg_color(b, BLACK);
  button_set_down_icon_color(b, LIGHT_GRAY);
  button_set_disabled_bg_color(b, BLACK);
  button_set_disabled_icon_color(b, DARK_GRAY);

  rect.y += 58;
  b = button_create(screen->widget, rect, img_up, WHITE, BLACK, up_button_clicked);
  button_set_up_bg_color(b, BLACK);
  button_set_up_icon_color(b, WHITE);
  button_set_down_bg_color(b, BLACK);
  button_set_down_icon_color(b, LIGHT_GRAY);
  button_set_disabled_bg_color(b, BLACK);
  button_set_disabled_icon_color(b, DARK_GRAY);

  rect.y += 58;
  b = button_create(screen->widget, rect, img_down, WHITE, BLACK, down_button_clicked);
  button_set_up_bg_color(b, BLACK);
  button_set_up_icon_color(b, WHITE);
  button_set_down_bg_color(b, BLACK);
  button_set_down_icon_color(b, LIGHT_GRAY);
  button_set_disabled_bg_color(b, BLACK);
  button_set_disabled_icon_color(b, DARK_GRAY);

  update_input_buttons(screen);

  rect.x = 60;
  rect.y = 8;
  rect.width = 200;
  screen->text_label = label_create(screen->widget, rect, "", font_opensans_regular_22, WHITE, 2);
  widget_set_background(screen->text_label, LIGHT_GRAY);

  gui_push_screen(screen->widget);
}

static void
update_input_buttons(textentry_screen_t* screen)
{
  int i;
  for (i = 0; i < NUM_VISIBLE_ROWS; ++i) {
    btn_row_t* row = &screen->btn_layout[screen->row_idx + i];

    int j;
    for (j = 0; j < NUM_BUTTONS_PER_ROW; ++j) {
      widget_t* btn = screen->buttons[i][j];
      const char* btn_text = (*row)[j];

      if (btn_text == NULL)
        widget_hide(btn);
      else {
        if (*btn_text == ' ')
          button_set_icon(btn, img_space);
        else
          button_set_icon(btn, img_circle);

        button_set_text(btn, btn_text);
        widget_show(btn);
      }
    }
  }
}
Beispiel #22
0

widget_t*
button_list_screen_create(
    widget_t* screen,
    char* title,
    button_event_handler_t back_handler,
    void* user_data)
{
  rect_t rect = {
      .x = 15,
      .y = 15,
      .width = 56,
      .height = 56,
  };
  widget_t* b = button_create(screen, rect, img_left, WHITE, BLACK, back_handler);
  widget_set_user_data(b, user_data);

  rect.x = 85;
  rect.y = 26;
  rect.width = 220;
  label_create(screen, rect, title, font_opensans_regular_22, WHITE, 1);

  rect.x = 5;
  rect.y = 85;
  rect.width = 300;
  rect.height = 160;
  widget_t* lb = listbox_create(screen, rect, 76);

  return lb;
}
Beispiel #23
0
int key_gui_callback(enum event_type event,void *data)
{
	static unsigned char flag = 0;

	gui_message gui_msg_tmp =
	{
		100,
		80,
		150,
		120,
		"main_window",
		"/sdcard/main.bmp",
		0,
		0,
		__GUI_WIDGET_MODE_0     | /* pic mode , with caption */
		__GUI_WIDGET_TYPE_OCT   | /* right angle mode */
		__GUI_WIDGET_FRAME_NONE | /* without frame */
		__GUI_WIDGET_THEME_0    | /* theme 0 */
		__GUI_WIDGET_HANDLE      /* no ues */
	};

	struct gui_msg_t b1_msg = {
			10,
			80,
			50,
			30,
	};

	if(flag != 0)
	{
		return ERR;
	}
	flag = 1;
	/* create the default create */
	window_create(&window_handler_key,&gui_msg_tmp,NULL);

	button_create(&window_handler_key,&b1_msg,NULL);

	b1_msg.x = 80;

	button_create(&window_handler_key,&b1_msg,NULL);

	refresh_now(&window_handler_key);

	gui_msg_tmp.x = 120;
	gui_msg_tmp.y = 20;
	gui_msg_tmp.xsize = 170;
	gui_msg_tmp.ysize = 80;

	b1_msg.x = 10;
	b1_msg.y = 40;

	gui_msg_tmp.mode &=~ __GUI_WIDGET_HANDLE;//as same

	window_create(&window_handler_t,&gui_msg_tmp,NULL);
	button_create(&window_handler_t,&b1_msg,NULL);
	b1_msg.x = 110;
	button_create(&window_handler_t,&b1_msg,NULL);

	refresh_now(&window_handler_t);

	return 0;
}
Beispiel #24
0
/*! 
 Sets the widget positions and draws other on-screen goo 
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void set_widget_positions_and_draw_decorations()
{
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    int box_width, box_height, box_max_y;
    int x_org, y_org;
    char *string;
    font_t *font;
    char *current_course;
    int text_width, asc, desc;
    GLuint texobj;
    
    /* set the dimensions of the box in which all widgets should fit */
#ifdef __APPLE__
    box_width = w;
    box_height = 200 * mHeight / 320;
    box_max_y = h - 128 * mHeight / 320;
    x_org = 10 * mHeight / 320;
    y_org = box_height/2 * mHeight / 320;
    
    if ( y_org + box_height > box_max_y ) {
        y_org = box_max_y - box_height + 50 * mHeight / 320;
    }
    
    button_set_position( 
                        back_btn,
                        make_point2d( 0,
                                     0 ) );
    
    button_set_position(
                        start_btn,
                        make_point2d( box_width - button_get_width( start_btn ),
                                     0 ) );
    
    listbox_set_position(
                         race_listbox,
                         make_point2d( 160 * mHeight / 320,
                                       box_height/2.0+40 * mHeight / 320 ) );
#ifdef __APPLE__    
    textarea_set_position( 
                          desc_ta,
                          make_point2d( 1000,
                                        1000 ) );
#else
    textarea_set_position( 
                          desc_ta,
                          make_point2d( x_org,
                                       y_org + 66 * mHeight / 320 ) );
#endif
    
    if ( g_game.practicing || 
        ( cup_complete &&
         conditions_ssbtn &&
         wind_ssbtn &&
         snow_ssbtn &&
         mirror_ssbtn ) ) 
    {
        ssbutton_set_position(
                              conditions_ssbtn,
                              make_point2d( x_org + box_width - 4*36 + 4,
                                           y_org + 151 ) );
        
        ssbutton_set_position(
                              wind_ssbtn,
                              make_point2d( x_org + box_width - 3*36 + 4 ,
                                           y_org + 151 ) );
        
        ssbutton_set_position(
                              snow_ssbtn,
                              make_point2d( x_org + box_width - 2*36 + 4,
                                           y_org + 151 ) );
        
        ssbutton_set_position(
                              mirror_ssbtn,
                              make_point2d( x_org + box_width - 1*36 + 4,
                                           y_org + 151 ) );
        
#else
        box_width = 460;
        box_height = 310;
        box_max_y = h - 128;
        x_org = w/2 - box_width/2;
        y_org = h/2 - box_height/2;
        
        if ( y_org + box_height > box_max_y ) {
            y_org = box_max_y - box_height;
        }
        
        button_set_position( 
                            back_btn,
                            make_point2d( x_org + 131 - button_get_width( back_btn )/2.0,
                                         42 ) );
        
        button_set_position(
                            start_btn,
                            make_point2d( x_org + 343 - button_get_width( start_btn )/2.0,
                                         42 ) );
        
        listbox_set_position(
                             race_listbox,
                             make_point2d( x_org,
                                          y_org + 221 ) );
        
        textarea_set_position( 
                              desc_ta,
                              make_point2d( x_org,
                                           y_org + 66 ) );
        
        if ( g_game.practicing || 
            ( cup_complete &&
             conditions_ssbtn &&
             wind_ssbtn &&
             snow_ssbtn &&
             mirror_ssbtn ) ) 
        {
            ssbutton_set_position(
                                  conditions_ssbtn,
                                  make_point2d( x_org + box_width - 4*36 + 4,
                                               y_org + 181 ) );
            
            ssbutton_set_position(
                                  wind_ssbtn,
                                  make_point2d( x_org + box_width - 3*36 + 4 ,
                                               y_org + 181 ) );
            
            ssbutton_set_position(
                                  snow_ssbtn,
                                  make_point2d( x_org + box_width - 2*36 + 4,
                                               y_org + 181 ) );
            
            ssbutton_set_position(
                                  mirror_ssbtn,
                                  make_point2d( x_org + box_width - 1*36 + 4,
                                               y_org + 181 ) );
#endif
        } else {
            /* Draw tux life icons */
            GLuint texobj;
            int i;
            
            glPushMatrix();
            {
#ifdef __APPLE__
                glTranslatef( 10 * mHeight / 320,
                             60 * mHeight / 320,
                             0 );
#else
                glTranslatef( x_org + box_width - 4*36 + 4,
                             y_org + 181,
                             0 );
#endif
                
                
                check_assertion( INIT_NUM_LIVES == 4, 
                                "Assumption about number of lives invalid -- "
                                "need to recode this part" );
                
                if ( !get_texture_binding( "tux_life", &texobj ) ) {
                    texobj = 0;
                }
                
                glBindTexture( GL_TEXTURE_2D, texobj );
                
                for ( i=0; i<4; i++ ) {
                    point2d_t ll, ur;
                    if ( plyr->lives > i ) {
                        ll = make_point2d( 0, 0.5 );
                        ur = make_point2d( 1, 1 );
                    } else {
                        ll = make_point2d( 0, 0 );
                        ur = make_point2d( 1, 0.5 );
                    }
                    
                    glBegin( GL_QUADS );
                    {
                        glTexCoord2f( ll.x, ll.y );
                        glVertex2f( 0, 0 );
                        
                        glTexCoord2f( ur.x, ll.y );
                        glVertex2f( 32 * mHeight / 320, 0 );
                        
                        glTexCoord2f( ur.x, ur.y );
                        glVertex2f( 32 * mHeight / 320, 32 * mHeight / 320 );
                        
                        glTexCoord2f( ll.x, ur.y );
                        glVertex2f( 0, 32 * mHeight / 320 );
                    }
                    glEnd();
                    glTranslatef( 36 * mHeight / 320, 0, 0 );
                }
            }
            glPopMatrix();
        }

#ifndef __APPLE__ // We don't care about that stuff

        /* Draw other stuff */
        if ( !get_font_binding( "menu_label", &font ) ) {
            print_warning( IMPORTANT_WARNING,
                          "Couldn't get font for binding menu_label" );
        } else {
            bind_font_texture( font );
            string = "Select a race";
            get_font_metrics( font, string, &text_width,  &asc, &desc );
            
            glPushMatrix();
            {
                glTranslatef( x_org + box_width/2.0 - text_width/2.0,
                             y_org + 310 - asc, 
                             0 );
                
                draw_string( font, string );
            }
            glPopMatrix();
        }
        /* Draw text indicating race requirements (if race not completed), 
         or results in race if race completed. */
        draw_status_msg( x_org, y_org, box_width, box_height );

#else

        /* Draw text indicating race requirements (if race not completed), 
         or results in race if race completed. */
        draw_status_msg( x_org, y_org, box_width, box_height );

#endif


        /* Draw preview */
        if ( g_game.practicing ) {
            list_elem_t elem;
            open_course_data_t *data;
            
            elem = listbox_get_current_item( race_listbox );
            data = (open_course_data_t*) get_list_elem_data( elem );
            current_course = data->course;
        } else {
            list_elem_t elem;
            race_data_t *data;
            
            elem = listbox_get_current_item( race_listbox );
            data = (race_data_t*) get_list_elem_data( elem );
            current_course = data->course;
        }
        
        glDisable( GL_TEXTURE_2D );
        
        glColor4f( 0.0, 0.0, 0.0, 0.3 );
        
#ifdef __APPLE__
        float margin = 4.f * mHeight / 320;
        float yoffset = 26 * mHeight / 320 + 30 * mHeight / 320;
        glBegin( GL_QUADS );
        {
            glVertex2f( x_org, y_org + yoffset );
            glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset );
            glVertex2f( x_org + 140 * mHeight / 320, y_org + yoffset+107 * mHeight / 320 );
            glVertex2f( x_org, y_org + yoffset+107 * mHeight / 320 );
        }
        glEnd();
#else
        glBegin( GL_QUADS );
        {
            glVertex2f( x_org+box_width-140, y_org+66 );
            glVertex2f( x_org+box_width, y_org+66 );
            glVertex2f( x_org+box_width, y_org+66+107 );
            glVertex2f( x_org+box_width-140, y_org+66+107 );
        }
        glEnd();
#endif

        glColor4f( 1.0, 1.0, 1.0, 1.0 );
        glEnable( GL_TEXTURE_2D );
        
        if ( !get_texture_binding( current_course, &texobj ) ) {
            if ( !get_texture_binding( "no_preview", &texobj ) ) {
                texobj = 0;
            }
        }
        
        glBindTexture( GL_TEXTURE_2D, texobj );
        
#ifdef __APPLE__
        glBegin( GL_QUADS );
        {
            glTexCoord2d( 0, 0);
            glVertex2f( x_org + margin, y_org + yoffset+margin );
            
            glTexCoord2d( 1, 0);
            glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin );
            
            glTexCoord2d( 1, 1);
            glVertex2f( x_org + 140 * mHeight / 320 - margin, y_org + yoffset+margin+99 * mHeight / 320 );
            
            glTexCoord2d( 0, 1);
            glVertex2f( x_org + margin, y_org + yoffset+margin+99 * mHeight / 320 );
        }
        glEnd();
        
#else
        glBegin( GL_QUADS );
        {
            glTexCoord2d( 0, 0);
            glVertex2f( x_org+box_width-136, y_org+70 );
            
            glTexCoord2d( 1, 0);
            glVertex2f( x_org+box_width-4, y_org+70 );
            
            glTexCoord2d( 1, 1);
            glVertex2f( x_org+box_width-4, y_org+70+99 );
            
            glTexCoord2d( 0, 1);
            glVertex2f( x_org+box_width-136, y_org+70+99 );
        }
        glEnd();
#endif
    }
    
    
    /*---------------------------------------------------------------------------*/
    /*! 
     Mode initialization function
     \author  jfpatry
     \date    Created:  2000-09-24
     \date    Modified: 2000-09-24
     */
    static void race_select_init(void)
    {
        listbox_list_elem_to_string_fptr_t conv_func = NULL;
        point2d_t dummy_pos = {0, 0};
        int i;
        
        winsys_set_display_func( main_loop );
        winsys_set_idle_func( main_loop );
        winsys_set_reshape_func( reshape );
        winsys_set_mouse_func( ui_event_mouse_func );
        winsys_set_motion_func( ui_event_motion_func );
        winsys_set_passive_motion_func( ui_event_motion_func );
        
        plyr = get_player_data( local_player() );
        
        /* Setup the race list */
        if ( g_game.practicing ) {
            g_game.current_event = "__Practice_Event__";
            g_game.current_cup = "__Practice_Cup__";
            race_list = get_open_courses_list();
            conv_func = get_name_from_open_course_data;
            cup_data = NULL;
            last_completed_race = NULL;
            event_data = NULL;
        } else {
            event_data = (event_data_t*) get_list_elem_data( 
                                                            get_event_by_name( g_game.current_event ) );
            check_assertion( event_data != NULL,
                            "Couldn't find current event." );
            cup_data = (cup_data_t*) get_list_elem_data(
                                                        get_event_cup_by_name( event_data, g_game.current_cup ) );
            check_assertion( cup_data != NULL,
                            "Couldn't find current cup." );
            race_list = get_cup_race_list( cup_data );
            conv_func = get_name_from_race_data;
        }
        
        /* Unless we're coming back from a race, initialize the race data to 
         defaults.
         */
        if ( g_game.prev_mode != GAME_OVER ) {
            /* Make sure we don't play previously loaded course */
            cup_complete = False;
            
            /* Initialize the race data */
            cur_elem = get_list_head( race_list );
            
            if ( g_game.practicing ) {
                g_game.race.course = NULL;
                g_game.race.name = NULL;
                g_game.race.description = NULL;
                
                for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
                    g_game.race.herring_req[i] = 0;
                    g_game.race.time_req[i] = 0;
                    g_game.race.score_req[i] = 0;
                }
                
                g_game.race.mirrored = False;
                g_game.race.conditions = RACE_CONDITIONS_SUNNY;
                g_game.race.windy = False;
                g_game.race.snowing = False;
            } else {
                /* Not practicing */
                
                race_data_t *data;
                data = (race_data_t*) get_list_elem_data( cur_elem );
                g_game.race = *data;
                
                if ( is_cup_complete( event_data, 
                                     get_event_cup_by_name( 
                                                           event_data, 
                                                           g_game.current_cup ) ) )
                {
                    cup_complete = True;
                    last_completed_race = get_list_tail( race_list );
                } else {
                    cup_complete = False;
                    last_completed_race = NULL;
                }
            }
        } else {
            /* Back from a race */
            if ( !g_game.race_aborted ) {
                update_race_results();
            }
            
            if (!g_game.practicing && !cup_complete) {
                if ( was_current_race_won() ) {
                    update_for_won_race();
                    
                    /* Advance to next race */
                    if ( cur_elem != get_list_tail( race_list ) ) {
                        cur_elem = get_next_list_elem( race_list, cur_elem );
                    }
                } else {
                    /* lost race */
                    plyr->lives -= 1;
                }
                print_debug( DEBUG_GAME_LOGIC, "Current lives: %d", plyr->lives );
            }
        }
        
        back_btn = button_create( dummy_pos,
                                 80 * mWidth / 480, 48 * mHeight / 320, 
                                 "button_label", 
                                 (mWidth>320)?"Back":"<< " );
        button_set_hilit_font_binding( back_btn, "button_label_hilit" );
        button_set_visible( back_btn, True );
        button_set_click_event_cb( back_btn, back_click_cb, NULL );
        
        start_btn = button_create( dummy_pos,
                                  80 * mWidth / 480, 48 * mHeight / 320,
                                  "button_label",
                                  (mWidth>320)?"Race":" >>" );
        button_set_hilit_font_binding( start_btn, "button_label_hilit" );
        button_set_disabled_font_binding( start_btn, "button_label_disabled" );
        button_set_visible( start_btn, True );
        button_set_click_event_cb( start_btn, start_click_cb, NULL );
        
#ifdef __APPLE__
        race_listbox = listbox_create( dummy_pos,
                                      mWidth - 170 * mHeight / 320, 44 * mHeight / 320,
                                      "course_name_label",
                                      race_list,
                                      conv_func );
        
#else
        race_listbox = listbox_create( dummy_pos,
                                      460 * mHeight / 320, 44 * mHeight / 320,
                                      "listbox_item",
                                      race_list,
                                      conv_func );
        
#endif
        
        
        listbox_set_current_item( race_listbox, cur_elem );
        
        listbox_set_item_change_event_cb( race_listbox, 
                                         race_listbox_item_change_cb, 
                                         NULL );
        
        listbox_set_visible( race_listbox, True );
        
        /* 
         * Create text area 
         */
#ifdef __APPLE__
        desc_ta = textarea_create( dummy_pos,
                                  150, 147,
                                  "race_description",
                                  "" );
        
#else
        desc_ta = textarea_create( dummy_pos,
                                  312, 107,
                                  "race_description",
                                  "" );
        
#endif
        
        if ( g_game.practicing ) {
            open_course_data_t *data;
            data = (open_course_data_t*) get_list_elem_data( cur_elem );
            textarea_set_text( desc_ta, data->description );
        } else {
            race_data_t *data;
            data = (race_data_t*) get_list_elem_data( cur_elem );
            textarea_set_text( desc_ta, data->description );
        }
        
        textarea_set_visible( desc_ta, True );
        
        
        /* 
         * Create state buttons - only if practicing or if cup_complete
         */
        
        if ( g_game.practicing || cup_complete ) {
            /* mirror */
            mirror_ssbtn = ssbutton_create( dummy_pos,
                                           32, 32,
                                           2 );
            ssbutton_set_state_image( mirror_ssbtn, 
                                     0, 
                                     "mirror_button",
                                     make_point2d( 0.0/64.0, 32.0/64.0 ),
                                     make_point2d( 32.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state_image( mirror_ssbtn, 
                                     1, 
                                     "mirror_button",
                                     make_point2d( 32.0/64.0, 32.0/64.0 ),
                                     make_point2d( 64.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored );
#ifdef __APPLE__
            ssbutton_set_visible( mirror_ssbtn, False );
#else
            ssbutton_set_visible( mirror_ssbtn, True );
#endif
            
            /* conditions */
            conditions_ssbtn = ssbutton_create( dummy_pos,
                                               32, 32,
                                               4 );

            float border = 2.0;
            ssbutton_set_state_image( conditions_ssbtn, 
                                     0, 
                                     "conditions_button",
                                     make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ),
                                     make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ),
                                     white );
            
            ssbutton_set_state_image( conditions_ssbtn, 
                                     1, 
                                     "conditions_button",
                                     make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ),
                                     make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ),
                                     white );
            
            ssbutton_set_state_image( conditions_ssbtn, 
                                     2, 
                                     "conditions_button",
                                     make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ),
                                     make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ),
                                     white );

            ssbutton_set_state_image( conditions_ssbtn, 
                                     3, 
                                     "conditions_button",
                                     make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ),
                                     make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ),
                                     white );
            
            ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions );
            ssbutton_set_visible( conditions_ssbtn, True );

#ifdef __APPLE__
            ssbutton_set_visible( conditions_ssbtn, False );
#else
            ssbutton_set_visible( conditions_ssbtn, True );
#endif
            
            /* wind */
            wind_ssbtn = ssbutton_create( dummy_pos,
                                         32, 32,
                                         2 );
            ssbutton_set_state_image( wind_ssbtn, 
                                     0, 
                                     "wind_button",
                                     make_point2d( 0.0/64.0, 32.0/64.0 ),
                                     make_point2d( 32.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state_image( wind_ssbtn, 
                                     1, 
                                     "wind_button",
                                     make_point2d( 32.0/64.0, 32.0/64.0 ),
                                     make_point2d( 64.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy );
#ifdef __APPLE__
            ssbutton_set_visible( wind_ssbtn, False );
#else
            ssbutton_set_visible( wind_ssbtn, True );
#endif
            
            /* snow */
            snow_ssbtn = ssbutton_create( dummy_pos,
                                         32, 32,
                                         2 );
            ssbutton_set_state_image( snow_ssbtn, 
                                     0, 
                                     "snow_button",
                                     make_point2d( 0.0/64.0, 32.0/64.0 ),
                                     make_point2d( 32.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state_image( snow_ssbtn, 
                                     1, 
                                     "snow_button",
                                     make_point2d( 32.0/64.0, 32.0/64.0 ),
                                     make_point2d( 64.0/64.0, 64.0/64.0 ),
                                     white );
            
            ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing );
#ifdef __APPLE__
            ssbutton_set_visible( snow_ssbtn, False );
#else
            ssbutton_set_visible( snow_ssbtn, True );
#endif
            /* XXX snow button doesn't do anything, so disable for now */
            ssbutton_set_enabled( snow_ssbtn, False );
            
            /* Can't change conditions if in cup mode */
            if ( !g_game.practicing ) {
                ssbutton_set_enabled( conditions_ssbtn, False );
                ssbutton_set_enabled( wind_ssbtn, False );
                ssbutton_set_enabled( snow_ssbtn, False );
                ssbutton_set_enabled( mirror_ssbtn, False );
            }
            
        } else {
            conditions_ssbtn = NULL;
            wind_ssbtn = NULL;
            snow_ssbtn = NULL;
            mirror_ssbtn = NULL;
        }
        
        update_race_data();
        update_button_enabled_states();
        
        play_music( "start_screen" );
    }
Beispiel #25
0
/**
 * Show the main GUI after starting the client -- servers list, chat box,
 * connecting to server, etc.
 */
void intro_show(void)
{
    SDL_Surface *texture;
    int x, y;
    size_t server_count;
    server_struct *node;
    char buf[MAX_BUF];
    SDL_Rect box;

    sound_start_bg_music("intro.ogg", setting_get_int(OPT_CAT_SOUND, OPT_VOLUME_MUSIC), -1);

    texture = TEXTURE_CLIENT("intro");

    /* Background */
    surface_show(ScreenSurface, 0, 0, NULL, texture);
    textwin_show(ScreenSurface, texture->w, 1, ScreenSurface->w - texture->w - 2, ScreenSurface->h - 3);

    /* Calculate whether to show the eyes or not. Blinks every
     * EYES_BLINK_TIME ticks, then waits EYES_BLINK_DELAY ticks until
     * showing the eyes again. */
    if (SDL_GetTicks() - eyes_blink_ticks >= (eyes_draw ? EYES_BLINK_TIME : EYES_BLINK_DELAY)) {
        eyes_blink_ticks = SDL_GetTicks();
        eyes_draw++;
    }

    if (eyes_draw) {
        SDL_Rect src_box;

        src_box.x = 0;
        src_box.y = eyes_draw - 1;
        src_box.w = TEXTURE_CLIENT("eyes")->w;
        src_box.h = TEXTURE_CLIENT("eyes")->h;
        surface_show(ScreenSurface, texture->w - 90, 310 + src_box.y, &src_box, TEXTURE_CLIENT("eyes"));

        if (eyes_draw > 1) {
            eyes_draw++;

            if (eyes_draw > src_box.h) {
                eyes_draw = 1;
            }
        }
    }

    texture = TEXTURE_CLIENT("servers_bg");
    x = 15;
    y = ScreenSurface->h - texture->h - 5;
    surface_show(ScreenSurface, x, y, NULL, texture);

    server_count = server_get_count();

    /* Create the buttons. */
    if (!list_servers) {
        button_create(&button_play);
        button_create(&button_refresh);
        button_create(&button_server);
        button_create(&button_settings);
        button_create(&button_update);
        button_create(&button_help);
        button_create(&button_credits);
        button_create(&button_quit);
    }

    /* List doesn't exist or the count changed? Create new list. */
    if (!list_servers || last_server_count != server_count) {
        size_t i;

        /* Remove it if it exists already. */
        if (list_servers) {
            list_remove(list_servers);
        }

        /* Create the servers list. */
        list_servers = list_create(11, 3, 8);
        list_servers->handle_enter_func = list_handle_enter;
        list_servers->handle_esc_func = list_handle_esc;
        list_servers->text_color_hook = list_text_color;
        list_scrollbar_enable(list_servers);
        list_set_column(list_servers, 0, 295, 7, "Server", -1);
        list_set_column(list_servers, 1, 50, 9, "Port", 1);
        list_set_column(list_servers, 2, 46, 7, "Players", 1);

        /* Add the servers to the list. */
        for (i = 0; i < server_count; i++) {
            node = server_get_id(i);

            list_add(list_servers, i, 0, node->name);
            snprintf(VS(buf),
                     "%d",
                     node->port_crypto == -1 ? node->port : node->port_crypto);
            list_add(list_servers, i, 1, buf);

            if (node->player >= 0) {
                snprintf(buf, sizeof(buf), "%d", node->player);
            } else {
                strcpy(buf, "-");
            }

            list_add(list_servers, i, 2, buf);
        }

        /* Store the new count. */
        last_server_count = server_count;
    }

    /* Actually draw the list. */
    list_show(list_servers, x + 12, y + 8);
    node = server_get_id(list_servers->row_selected - 1);

    /* Do we have any selected server? If so, show its version and
     * description. */
    if (node) {
        snprintf(buf, sizeof(buf), "Version: %s", node->version);
        text_show_shadow(ScreenSurface, FONT_ARIAL10, buf, x + 13, y + 185, COLOR_HGOLD, COLOR_BLACK, 0, NULL);

        box.w = 410;
        box.h = 48;
        text_show(ScreenSurface, FONT_ARIAL10, node->desc, x + 13, y + 197, COLOR_WHITE, TEXT_WORD_WRAP | TEXT_MARKUP, &box);
    }

    /* Show whether we are connecting to the metaserver or not. */
    if (ms_connecting(-1)) {
        text_show_shadow(ScreenSurface, FONT_ARIAL10, "Connecting to metaserver, please wait...", x + 105, y + 8, COLOR_HGOLD, COLOR_BLACK, 0, NULL);
    } else {
        text_show_shadow(ScreenSurface, FONT_ARIAL10, "Select a secure server.", x + 196, y + 8, COLOR_GREEN, COLOR_BLACK, 0, NULL);
    }

    texture = TEXTURE_CLIENT("servers_bg_over");
    surface_show(ScreenSurface, x, y, NULL, texture);

    x += texture->w + 20;
    texture = TEXTURE_CLIENT("news_bg");
    surface_show(ScreenSurface, x, y, NULL, texture);

    box.w = texture->w;
    box.h = 0;
    text_show_shadow(ScreenSurface, FONT_SERIF12, "Game News", x, y + 10, COLOR_HGOLD, COLOR_BLACK, TEXT_ALIGN_CENTER, &box);

    /* No list yet, make one and start downloading the data. */
    if (!list_news) {
        /* Start downloading. */
        news_request = curl_request_create(clioption_settings.game_news_url,
                                           CURL_PKEY_TRUST_ULTIMATE);
        curl_request_start_get(news_request);

        list_news = list_create(18, 1, 8);
        list_news->focus = 0;
        list_news->handle_enter_func = list_handle_enter;
        list_news->handle_esc_func = list_handle_esc;
        list_set_column(list_news, 0, 150, 7, NULL, -1);
        list_set_font(list_news, FONT_ARIAL10);
    }

    /* Download in progress? */
    if (news_request != NULL) {
        curl_state_t state = curl_request_get_state(news_request);
        /* Finished downloading, parse the data. */
        if (state == CURL_STATE_OK) {
            char *body = curl_request_get_body(news_request, NULL);
            if (body != NULL) {
                uint32_t i = 0;
                char *cp = strtok(body, "\n");
                while (cp != NULL) {
                    list_add(list_news, i++, 0, cp);
                    cp = strtok(NULL, "\n");
                }
            }
        }

        /* Finished downloading or there was an error: clean up in either
         * case. */
        if (state != CURL_STATE_INPROGRESS) {
            curl_request_free(news_request);
            news_request = NULL;
        }
    }

    /* Show the news list. */
    list_show(list_news, x + 13, y + 10);

    button_play.x = button_refresh.x = button_server.x = button_settings.x = button_update.x = button_help.x = button_credits.x = button_quit.x = 489;
    y += 2;

    button_play.y = y + 10;
    button_show(&button_play, "Play");

    button_refresh.y = y + 35;
    button_show(&button_refresh, "Refresh");

    button_server.y = y + 60;
    button_show(&button_server, "Server");

    button_settings.y = y + 86;
    button_show(&button_settings, "Settings");

    button_update.y = y + 110;
    button_show(&button_update, "Update");

    button_help.y = y + 135;
    button_show(&button_help, "Help");

    button_credits.y = y + 160;
    button_show(&button_credits, "Credits");

    button_quit.y = y + 224;
    button_show(&button_quit, "Quit");

    if (clioption_settings.connect[0] && cpl.state < ST_STARTCONNECT) {
        size_t i;

        for (i = 0; i < server_count; i++) {
            node = server_get_id(i);

            if (strcasecmp(clioption_settings.connect[0], node->name) == 0) {
                list_servers->row_selected = i + 1;

                if (!clioption_settings.reconnect) {
                    efree(clioption_settings.connect[0]);
                    clioption_settings.connect[0] = NULL;
                }

                event_push_key_once(SDLK_RETURN, 0);
                break;
            }
        }
    }
}
Beispiel #26
0
widget_t*
listbox_create(widget_t* parent, rect_t rect, int item_height)
{
  listbox_t* l = calloc(1, sizeof(listbox_t));

  widget_t* lb = widget_create(parent, NULL, l, rect);

  l->pos = 0;
  l->item_height = item_height;

  rect_t container_rect = {
      .x = 0,
      .y = 0,
      .width = rect.width - 52,
      .height = rect.height
  };
  l->item_container = widget_create(lb, &listbox_widget_class, l, container_rect);

  int button_pad = (rect.height - (2 * 52)) / 3;
  rect_t button_rect = {
      .x = rect.width - 52,
      .y = button_pad,
      .width = 52,
      .height = 52
  };
  l->up_button = button_create(lb, button_rect, img_up, WHITE, BLACK, up_button_event);
  button_set_up_bg_color(l->up_button, BLACK);
  button_set_up_icon_color(l->up_button, WHITE);
  button_set_down_bg_color(l->up_button, BLACK);
  button_set_down_icon_color(l->up_button, LIGHT_GRAY);
  button_set_disabled_bg_color(l->up_button, BLACK);
  button_set_disabled_icon_color(l->up_button, DARK_GRAY);

  button_rect.y += 52 + button_pad;
  l->dn_button = button_create(lb, button_rect, img_down, WHITE, BLACK, down_button_event);
  button_set_up_bg_color(l->dn_button, BLACK);
  button_set_up_icon_color(l->dn_button, WHITE);
  button_set_down_bg_color(l->dn_button, BLACK);
  button_set_down_icon_color(l->dn_button, LIGHT_GRAY);
  button_set_disabled_bg_color(l->dn_button, BLACK);
  button_set_disabled_icon_color(l->dn_button, DARK_GRAY);

  return lb;
}

void
listbox_clear(widget_t* lb)
{
  listbox_t* l = widget_get_instance_data(lb);
  while (1) {
    widget_t* w = widget_get_child(l->item_container, 0);
    if (w == NULL)
      break;

    widget_unparent(w);
    widget_destroy(w);
  }
  widget_invalidate(lb);
}

static void
listbox_destroy(widget_t* w)
{
  listbox_t* l = widget_get_instance_data(w);
  free(l);
}
Beispiel #27
0
/*! 
 Mode initialization function
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void race_select_init(void)
{
    listbox_list_elem_to_string_fptr_t conv_func = NULL;
    point2d_t dummy_pos = {0, 0};
    int i;
    
    winsys_set_display_func( main_loop );
    winsys_set_idle_func( main_loop );
    winsys_set_reshape_func( reshape );
    winsys_set_mouse_func( ui_event_mouse_func );
    winsys_set_motion_func( ui_event_motion_func );
    winsys_set_passive_motion_func( ui_event_motion_func );
    
    plyr = get_player_data( local_player() );
    
    /* Setup the race list */
    if ( g_game.practicing ) {
        g_game.current_event = "__Practice_Event__";
        g_game.current_cup = "__Practice_Cup__";
        if(g_game.is_speed_only_mode)
            race_list = get_speed_courses_list();
        else
            race_list = get_score_courses_list();
        conv_func = get_name_from_open_course_data;
        cup_data = NULL;
        last_completed_race = NULL;
        event_data = NULL;
    } else {
        event_data = (event_data_t*) get_list_elem_data( 
                                                        get_event_by_name( g_game.current_event ) );
        check_assertion( event_data != NULL,
                        "Couldn't find current event." );
        cup_data = (cup_data_t*) get_list_elem_data(
                                                    get_event_cup_by_name( event_data, g_game.current_cup ) );
        check_assertion( cup_data != NULL,
                        "Couldn't find current cup." );
        race_list = get_cup_race_list( cup_data );
        conv_func = get_name_from_race_data;
    }
    
    /* Unless we're coming back from a race, initialize the race data to 
     defaults.
     */
    if ( g_game.prev_mode != GAME_OVER ) {
        /* Make sure we don't play previously loaded course */
        cup_complete = False;
        
        /* Initialize the race data */
        cur_elem = get_list_head( race_list );
        
        if ( g_game.practicing ) {
            g_game.race.course = NULL;
            g_game.race.name = NULL;
            g_game.race.description = NULL;
            
            for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
                g_game.race.herring_req[i] = 0;
                g_game.race.time_req[i] = 0;
                g_game.race.score_req[i] = 0;
            }
            
            g_game.race.mirrored = False;
            g_game.race.conditions = RACE_CONDITIONS_SUNNY;
            g_game.race.windy = False;
            g_game.race.snowing = False;
        } else {
            /* Not practicing */
            
            race_data_t *data;
            data = (race_data_t*) get_list_elem_data( cur_elem );
            g_game.race = *data;
            
            if ( is_cup_complete( event_data, 
                                 get_event_cup_by_name( 
                                                       event_data, 
                                                       g_game.current_cup ) ) )
            {
                cup_complete = True;
                last_completed_race = get_list_tail( race_list );
            } else {
                cup_complete = False;
                last_completed_race = NULL;
            }
        }
    } else {
        /* Back from a race */
        if ( !g_game.race_aborted ) {
            update_race_results();
        }
        
    }
    
    back_btn = button_create( dummy_pos,
                             150, 40, 
                             "button_label", 
                             Localize("Back","") );
    button_set_hilit_font_binding( back_btn, "button_label_hilit" );
    button_set_visible( back_btn, True );
    button_set_click_event_cb( back_btn, back_click_cb, NULL );
    
    start_btn = button_create( dummy_pos,
                              150, 40,
                              "button_label",
                              Localize("Race!","") );
    button_set_hilit_font_binding( start_btn, "button_label_hilit" );
    button_set_disabled_font_binding( start_btn, "button_label_disabled" );
    button_set_visible( start_btn, True );
    button_set_click_event_cb( start_btn, start_click_cb, NULL );
    
#ifdef __APPLE__
    race_listbox = listbox_create( dummy_pos,
                                  300, 44,
                                  "course_name_label",
                                  race_list,
                                  conv_func );
    
#else
    race_listbox = listbox_create( dummy_pos,
                                  460, 44,
                                  "listbox_item",
                                  race_list,
                                  conv_func );
    
#endif
    
    
    listbox_set_current_item( race_listbox, cur_elem );
    
    listbox_set_item_change_event_cb( race_listbox, 
                                     race_listbox_item_change_cb, 
                                     NULL );
    
    listbox_set_visible( race_listbox, True );
    
    /* 
     * Create text area 
     */
#ifdef __APPLE__
    desc_ta = textarea_create( dummy_pos,
                              170, 147,
                              "race_description",
                              "" );
    
#else
    desc_ta = textarea_create( dummy_pos,
                              312, 107,
                              "race_description",
                              "" );
    
#endif
    
    if ( g_game.practicing ) {
        open_course_data_t *data;
        data = (open_course_data_t*) get_list_elem_data( cur_elem );
        textarea_set_text( desc_ta, data->description );
    } else {
        race_data_t *data;
        data = (race_data_t*) get_list_elem_data( cur_elem );
        textarea_set_text( desc_ta, data->description );
    }
    
    textarea_set_visible( desc_ta, True );
    
    
    /* 
     * Create state buttons - only if practicing or if cup_complete
     */
    
    if ( g_game.practicing || cup_complete ) {
        /* mirror */
        mirror_ssbtn = ssbutton_create( dummy_pos,
                                       32, 32,
                                       2 );
        ssbutton_set_state_image( mirror_ssbtn, 
                                 0, 
                                 "mirror_button",
                                 make_point2d( 0.0/64.0, 32.0/64.0 ),
                                 make_point2d( 32.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state_image( mirror_ssbtn, 
                                 1, 
                                 "mirror_button",
                                 make_point2d( 32.0/64.0, 32.0/64.0 ),
                                 make_point2d( 64.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state( mirror_ssbtn, (int)g_game.race.mirrored );
#ifdef __APPLE__
        ssbutton_set_visible( mirror_ssbtn, False );
#else
        ssbutton_set_visible( mirror_ssbtn, True );
#endif
        
        /* conditions */
        conditions_ssbtn = ssbutton_create( dummy_pos,
                                           32, 32,
                                           4 );
        
        float border = 2.0;
        ssbutton_set_state_image( conditions_ssbtn, 
                                 0, 
                                 "conditions_button",
                                 make_point2d( (0.0 + border)/64.0, (32.0 + border)/64.0 ),
                                 make_point2d( (32.0 - border)/64.0, (64.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state_image( conditions_ssbtn, 
                                 1, 
                                 "conditions_button",
                                 make_point2d( (32.0 + border)/64.0, (0.0 + border)/64.0 ),
                                 make_point2d( (64.0 - border)/64.0, (32.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state_image( conditions_ssbtn, 
                                 2, 
                                 "conditions_button",
                                 make_point2d( (32.0 + border)/64.0, (32.0 + border)/64.0 ),
                                 make_point2d( (64.0 - border)/64.0, (64.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state_image( conditions_ssbtn, 
                                 3, 
                                 "conditions_button",
                                 make_point2d( (0.0 + border)/64.0, (0.0 + border)/64.0 ),
                                 make_point2d( (32.0 - border)/64.0, (32.0 - border)/64.0 ),
                                 white );
        
        ssbutton_set_state( conditions_ssbtn, (int)g_game.race.conditions );
        ssbutton_set_visible( conditions_ssbtn, True );
        
#ifdef __APPLE__
        ssbutton_set_visible( conditions_ssbtn, False );
#else
        ssbutton_set_visible( conditions_ssbtn, True );
#endif
        
        /* wind */
        wind_ssbtn = ssbutton_create( dummy_pos,
                                     32, 32,
                                     2 );
        ssbutton_set_state_image( wind_ssbtn, 
                                 0, 
                                 "wind_button",
                                 make_point2d( 0.0/64.0, 32.0/64.0 ),
                                 make_point2d( 32.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state_image( wind_ssbtn, 
                                 1, 
                                 "wind_button",
                                 make_point2d( 32.0/64.0, 32.0/64.0 ),
                                 make_point2d( 64.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state( wind_ssbtn, (int)g_game.race.windy );
#ifdef __APPLE__
        ssbutton_set_visible( wind_ssbtn, False );
#else
        ssbutton_set_visible( wind_ssbtn, True );
#endif
        
        /* snow */
        snow_ssbtn = ssbutton_create( dummy_pos,
                                     32, 32,
                                     2 );
        ssbutton_set_state_image( snow_ssbtn, 
                                 0, 
                                 "snow_button",
                                 make_point2d( 0.0/64.0, 32.0/64.0 ),
                                 make_point2d( 32.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state_image( snow_ssbtn, 
                                 1, 
                                 "snow_button",
                                 make_point2d( 32.0/64.0, 32.0/64.0 ),
                                 make_point2d( 64.0/64.0, 64.0/64.0 ),
                                 white );
        
        ssbutton_set_state( snow_ssbtn, (int)g_game.race.snowing );
#ifdef __APPLE__
        ssbutton_set_visible( snow_ssbtn, False );
#else
        ssbutton_set_visible( snow_ssbtn, True );
#endif
        /* XXX snow button doesn't do anything, so disable for now */
        ssbutton_set_enabled( snow_ssbtn, False );
        
        /* Can't change conditions if in cup mode */
        if ( !g_game.practicing ) {
            ssbutton_set_enabled( conditions_ssbtn, False );
            ssbutton_set_enabled( wind_ssbtn, False );
            ssbutton_set_enabled( snow_ssbtn, False );
            ssbutton_set_enabled( mirror_ssbtn, False );
        }
        
    } else {
        conditions_ssbtn = NULL;
        wind_ssbtn = NULL;
        snow_ssbtn = NULL;
        mirror_ssbtn = NULL;
    }
    
    update_race_data();
    update_button_enabled_states();
    
    play_music( "start_screen" );
}
Beispiel #28
0
void
videoplay_create (void)
{
    videoplay = g_new0 (VideoPlay, 1);
    videoplay->is_fullscreen = FALSE;
    videoplay->is_hide = TRUE;
    videoplay->seek_lock = FALSE;
    videoplay->status = VIDEOPLAY_STATUS_NULL;
    videoplay->video_name = NULL;

    videoplay->container = gtk_frame_new (NULL);
    gtk_widget_show (videoplay->container);

    videoplay->vbox = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (videoplay->vbox);
    gtk_container_add (GTK_CONTAINER (videoplay->container), videoplay->vbox);

    videoplay->frame = gtk_aspect_frame_new (NULL, 0.5, 0.5, 1.33333, FALSE);
    gtk_box_pack_start (GTK_BOX (videoplay->vbox), videoplay->frame, TRUE,
			TRUE, 0);
    gtk_widget_show (videoplay->frame);

    videoplay->mplayer = gtk_mplayer_new ();
    gtk_container_add (GTK_CONTAINER (videoplay->frame), videoplay->mplayer);
    gtk_widget_show (videoplay->mplayer);

    gtk_signal_connect (GTK_OBJECT (videoplay->mplayer), "play",
			GTK_SIGNAL_FUNC (cb_mplayer_play), videoplay);
    gtk_signal_connect (GTK_OBJECT (videoplay->mplayer), "stop",
			GTK_SIGNAL_FUNC (cb_mplayer_stop), videoplay);
    gtk_signal_connect (GTK_OBJECT (videoplay->mplayer), "pause",
			GTK_SIGNAL_FUNC (cb_mplayer_pause), videoplay);
    gtk_signal_connect (GTK_OBJECT (videoplay->mplayer), "position_changed",
			GTK_SIGNAL_FUNC (cb_mplayer_pos_changed), videoplay);

    GTK_WIDGET_SET_FLAGS (GTK_WIDGET (videoplay->frame), GTK_CAN_FOCUS);

    videoplay->hbox = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (videoplay->hbox);
    gtk_box_pack_start (GTK_BOX (videoplay->vbox), videoplay->hbox, FALSE,
			FALSE, 10);

    videoplay->button_tooltips = gtk_tooltips_new ();

    videoplay->button_vbox = gtk_vbox_new (FALSE, 0);
    gtk_box_pack_start (GTK_BOX (videoplay->hbox), videoplay->button_vbox,
			FALSE, FALSE, 10);
    gtk_widget_show (videoplay->button_vbox);

    videoplay->button_hbox = gtk_hbox_new (FALSE, 0);
    gtk_box_pack_start (GTK_BOX (videoplay->button_vbox),
			videoplay->button_hbox, FALSE, FALSE, 10);
    gtk_widget_show (videoplay->button_hbox);

    videoplay->play_btn =
	button_create (videoplay->button_hbox, (gchar **) play_xpm, FALSE,
		       videoplay->button_tooltips, _("Play"),
		       GTK_SIGNAL_FUNC (cb_videoplay_play), videoplay);
    gtk_widget_set_usize (videoplay->play_btn, 30, 30);
    videoplay->pause_btn =
	button_create (videoplay->button_hbox, (gchar **) pause_xpm, FALSE,
		       videoplay->button_tooltips, _("Pause"),
		       GTK_SIGNAL_FUNC (cb_videoplay_pause), videoplay);
    gtk_widget_set_usize (videoplay->pause_btn, 30, 30);
    videoplay->stop_btn =
	button_create (videoplay->button_hbox, (gchar **) stop_xpm, FALSE,
		       videoplay->button_tooltips, _("Stop"),
		       GTK_SIGNAL_FUNC (cb_videoplay_stop), videoplay);
    gtk_widget_set_usize (videoplay->stop_btn, 30, 30);
    videoplay->previous_btn =
	button_create (videoplay->button_hbox, (gchar **) prev_xpm, FALSE,
		       videoplay->button_tooltips, _("Previous"),
		       GTK_SIGNAL_FUNC (cb_videoplay_prev), videoplay);
    gtk_widget_set_usize (videoplay->previous_btn, 30, 30);
    videoplay->next_btn =
	button_create (videoplay->button_hbox, (gchar **) next_xpm, FALSE,
		       videoplay->button_tooltips, _("Next"),
		       GTK_SIGNAL_FUNC (cb_videoplay_next), videoplay);
    gtk_widget_set_usize (videoplay->next_btn, 30, 30);

    videoplay->seek_vbox = gtk_vbox_new (FALSE, 0);
    gtk_box_pack_start (GTK_BOX (videoplay->hbox), videoplay->seek_vbox, TRUE,
			TRUE, 0);
    gtk_widget_show (videoplay->seek_vbox);

    videoplay->seek_adj =
	gtk_adjustment_new (0.0, 0.0, 100.0, 0.01, 1.0, 1.0);

    GTK_ADJUSTMENT (videoplay->seek_adj)->value = 0;

    videoplay->seek = gtk_hscale_new (GTK_ADJUSTMENT (videoplay->seek_adj));
    gtk_widget_show (videoplay->seek);
    gtk_box_pack_start (GTK_BOX (videoplay->seek_vbox), videoplay->seek, TRUE,
			TRUE, 10);
    gtk_scale_set_draw_value (GTK_SCALE (videoplay->seek), FALSE);
    gtk_range_set_update_policy (GTK_RANGE (videoplay->seek),
				 GTK_UPDATE_CONTINUOUS);

    videoplay->seek_label = gtk_label_new ("00:00:00");
    gtk_box_pack_start (GTK_BOX (videoplay->seek_vbox), videoplay->seek_label,
			TRUE, TRUE, 0);
    gtk_widget_show (videoplay->seek_label);

    gtk_signal_connect (GTK_OBJECT (videoplay->seek_adj), "value_changed",
			GTK_SIGNAL_FUNC (cb_seekbar_value_changed),
			videoplay);
}