// FIXME: we have to set the gui dimensions before creating the optlayout because there's not a good place to put the continue/cancel init aside from here. this is part of a general problem of not really being able to resize anything void optlayout_create (EntComponent comp, EntSpeech speech) { struct optlayout * layout = xph_alloc (sizeof (struct optlayout)); layout->options = dynarr_create (2, sizeof (Entity)); component_setData (comp, layout); Entity this = component_entityAttached (comp); int x, y, w, h, hm, vm, fontHeight; gui_xy (this, &x, &y); gui_wh (this, &w, &h); gui_vhMargin (this, &hm, &vm); fontHeight = fontLineHeight (); layout->confirm = entity_create (); component_instantiate ("gui", layout->confirm); component_instantiate ("clickable", layout->confirm); component_instantiate ("input", layout->confirm); component_instantiate ("textlabel", layout->confirm); entity_refresh (layout->confirm); gui_place (layout->confirm, x, y + h - (vm * 2 + fontHeight), w / 2, fontHeight + vm); gui_setFrame (layout->confirm, this); clickable_setClickCallback (layout->confirm, NULL); textlabel_set (layout->confirm, "Continue", ALIGN_CENTRE, x, y + h - (vm * 2 + fontHeight), w / 2); layout->cancel = entity_create (); component_instantiate ("gui", layout->cancel); component_instantiate ("clickable", layout->cancel); component_instantiate ("input", layout->cancel); component_instantiate ("textlabel", layout->cancel); entity_refresh (layout->cancel); gui_place (layout->cancel, x + w / 2, y + h - (vm * 2 + fontHeight), w / 2, fontHeight + vm); gui_setFrame (layout->cancel, this); clickable_setClickCallback (layout->cancel, optlayout_cancelCallback); textlabel_set (layout->cancel, "Cancel", ALIGN_CENTRE, x + w / 2, y + h - (vm * 2 + fontHeight), w / 2); }
int handle_cashier(GladeXML* s_glade_personal_information_xml, GladeXML* s_glade_account_status_xml, GladeXML* s_glade_exit_cashier_xml, GtkLayout* screen, int init) { if (init) { s_personal_information_window = gui_get_widget(s_glade_personal_information_xml, "personal_information_window"); g_assert(s_personal_information_window); set_nil_draw_focus(s_personal_information_window); if(screen) gtk_layout_put(screen, s_personal_information_window, 0, 0); s_account_status_window = gui_get_widget(s_glade_account_status_xml, "account_status_window"); g_assert(s_account_status_window); if(screen) gtk_layout_put(screen, s_account_status_window, 0, 0); s_exit_cashier_window = gui_get_widget(s_glade_exit_cashier_xml, "exit_cashier_window"); g_assert(s_exit_cashier_window); if(screen) gtk_layout_put(screen, s_exit_cashier_window, 0, 0); s_exit_button = GTK_BUTTON(gui_get_widget(s_glade_exit_cashier_xml, "exit_cashier")); g_assert(s_exit_button); { static const char* entries[ENTRIES_CNT] = { "entry_player_id", "entry_email", }; int i; for (i = 0; i < ENTRIES_CNT; i++) s_entries[i] = gui_get_widget(s_glade_personal_information_xml, entries[i]); } { static const char* labels[LABELS_CNT] = { "money_one_available", "money_one_in_game", "money_one_total", "money_two_available", "money_two_in_game", "money_two_total" }; int i; for (i = 0; i < LABELS_CNT; i++) s_labels[i] = gui_get_widget(s_glade_account_status_xml, labels[i]); } GUI_BRANCH(s_glade_exit_cashier_xml, on_exit_cashier_clicked); gtk_widget_hide(s_personal_information_window); gtk_widget_hide(s_account_status_window); gtk_widget_hide(s_exit_cashier_window); } char* showhide = get_string(); char* fields[20]; char** pfields = fields; int i = get_int(); int fields_cnt = 0; if(i > 0) { g_message("cashier got %d entries", i); while (i-- > 0) { char* str = get_string(); if (fields_cnt < 20) fields[fields_cnt++] = str; } for (i = 0; i < ENTRIES_CNT; i++) { char* str = *pfields++; gtk_entry_set_text(GTK_ENTRY(s_entries[i]), str); } { char* str = *pfields++; GtkTextView* address = GTK_TEXT_VIEW(gui_get_widget(s_glade_personal_information_xml, "entry_mailing_address")); GtkTextBuffer* buffer = gtk_text_view_get_buffer(address); gtk_text_buffer_set_text(buffer, str, -1); } for (i = 0; i < LABELS_CNT; i++) { char* str = *pfields++; gtk_label_set_text(GTK_LABEL(s_labels[i]), str); } for (i = 0; i < fields_cnt; i++) { g_free(fields[i]); } } if(!strcmp(showhide, "show")) { /* * calculate windows position */ int screen_width = gui_width(screen); int screen_height = gui_height(screen); /* * should be based on the size of the windows ... */ int top_left_x = (screen_width - 913) / 2; int top_left_y = (screen_height - 450) / 2; int account_status_x = top_left_x + 381; int exit_cashier_y = top_left_y + 320; s_personal_information_position.x = top_left_x; s_personal_information_position.y = top_left_y; s_account_status_position.x = account_status_x; s_account_status_position.y = top_left_y; s_exit_cashier_position.x = top_left_x; s_exit_cashier_position.y = exit_cashier_y; { char* label = get_string(); gtk_button_set_label(s_exit_button, label); g_free(label); } { //moneyone GtkWidget* sl = gui_get_widget(s_glade_account_status_xml, "money_one_name"); char* label = get_string(); gtk_label_set_text(GTK_LABEL(sl), label); g_free(label); } { //moneytwo GtkWidget* sl = gui_get_widget(s_glade_account_status_xml, "money_two_name"); char* label = get_string(); gtk_label_set_text(GTK_LABEL(sl), label); g_free(label); } if ((screen != NULL) || (s_cashier_shown == 0)) { gui_place(s_personal_information_window, &s_personal_information_position, screen); gui_place(s_account_status_window, &s_account_status_position, screen); gui_place(s_exit_cashier_window, &s_exit_cashier_position, screen); s_cashier_shown = 1; } } else { if (screen != NULL) { hide_cashier(); } } g_free(showhide); return TRUE; }
int handle_lobby(GladeXML* g_lobby_xml, GladeXML* g_table_info_xml, GladeXML* g_lobby_tabs_xml, GladeXML* g_cashier_button_xml, GladeXML* g_clock_xml, GtkLayout* screen, int init) { static int s_selected_table = 0; s_screen = screen; if(init) { textdomain ("poker2d"); int i; s_lobby_xml = g_lobby_xml; s_lobby_window = gui_get_widget(g_lobby_xml, "lobby_window"); g_assert(s_lobby_window); set_nil_draw_focus(s_lobby_window); if(screen) gtk_layout_put(screen, s_lobby_window, 0, 0); s_notebook = GTK_NOTEBOOK(gui_get_widget(g_lobby_xml, "notebook")); g_assert(s_notebook); for(i = 0; i < VARIANTS_COUNT; i++) { char tmp[32]; s_variants_store[i] = gtk_list_store_new(12, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); snprintf(tmp, 32, "%s_treeview", s_variants_names[i]); GtkTreeView* treeview = GTK_TREE_VIEW(gui_get_widget(g_lobby_xml, tmp)); GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview); g_signal_connect(selection, "changed", (GCallback)on_lobby_list_treeview_selection_changed, &s_selected_table); s_variants_selection[i] = selection; g_signal_connect(treeview, "row-activated", (GCallback)on_row_activated, &s_selected_table); gtk_tree_view_set_rules_hint(treeview, TRUE); gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(s_variants_store[i])); GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new(); #define TABLE_COLUMN_ID 0 #define TABLE_COLUMN_MY 1 { GtkTreeViewColumn* column = gtk_tree_view_column_new(); GtkCellRenderer* pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); gtk_tree_view_append_column(treeview, column); gtk_tree_view_column_set_title(column, gettext("My") ); gtk_tree_view_column_pack_start(column, pixbuf_renderer, TRUE); gtk_tree_view_column_add_attribute(column, pixbuf_renderer, "pixbuf", TABLE_COLUMN_MY); } { GError* error = 0; gchar* filename; filename = glade_xml_relative_file(g_lobby_xml, "table_bullet_my.png"); if(g_file_test(filename, G_FILE_TEST_EXISTS)) { pixbuf_table_my = gdk_pixbuf_new_from_file(filename, &error); if(pixbuf_table_my == NULL) { GtkIconTheme* theme = gtk_icon_theme_get_default(); error = 0; pixbuf_table_my = gtk_icon_theme_load_icon(theme, "stock_book_open", 16, 0, &error); if (!pixbuf_table_my) { g_warning ("Couldn't load icon: %s", error->message); } } } g_free(filename); } #define SET_COLUMN(TITLE, INDEX) \ { \ GtkTreeViewColumn* column = gtk_tree_view_column_new(); \ gtk_tree_view_append_column(treeview, column); \ gtk_tree_view_column_set_title(column, TITLE); \ gtk_tree_view_column_pack_start(column, text_renderer, TRUE); \ gtk_tree_view_column_add_attribute(column, text_renderer, "text", INDEX); \ } #define TABLE_COLUMN_NAME 2 SET_COLUMN( gettext("Name"), TABLE_COLUMN_NAME); #define TABLE_COLUMN_STRUCTURE 3 SET_COLUMN( gettext("Structure"), TABLE_COLUMN_STRUCTURE); #define TABLE_COLUMN_SEATS 4 SET_COLUMN( gettext("Seats"), TABLE_COLUMN_SEATS); #define TABLE_COLUMN_AVG_POT 5 SET_COLUMN( gettext("Avg.pot"), TABLE_COLUMN_AVG_POT); #define TABLE_COLUMN_HANDS_PER_HOUR 6 SET_COLUMN( gettext("Hands/h"), TABLE_COLUMN_HANDS_PER_HOUR); #define TABLE_COLUMN_PERCENT_FLOP 7 SET_COLUMN( gettext("Flop%"), TABLE_COLUMN_PERCENT_FLOP); #define TABLE_COLUMN_PLAYING 8 SET_COLUMN( gettext("Playing"), TABLE_COLUMN_PLAYING); #define TABLE_COLUMN_OBSERVING 9 #define TABLE_COLUMN_WAITING 10 #define TABLE_COLUMN_TIMEOUT 11 #undef SET_COLUMN } s_players_label = GTK_LABEL(gui_get_widget(g_lobby_xml, "players_label")); s_tables_label = GTK_LABEL(gui_get_widget(g_lobby_xml, "tables_label")); GUI_BRANCH(g_lobby_xml, on_all_radio_clicked); GUI_BRANCH(g_lobby_xml, on_money_one_radio_clicked); GUI_BRANCH(g_lobby_xml, on_money_two_radio_clicked); s_table_info_window = gui_get_widget(g_table_info_xml, "table_info_window"); g_assert(s_table_info_window); if(screen) gtk_layout_put(screen, s_table_info_window, 0, 0); { s_players_store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); GtkTreeView* treeview = GTK_TREE_VIEW(gui_get_widget(g_table_info_xml, "players_treeview")); gtk_tree_view_set_rules_hint(treeview, TRUE); gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(s_players_store)); GtkCellRenderer* text_renderer = gtk_cell_renderer_text_new(); #define PLAYERS_COLUMN_NAME 0 { GtkTreeViewColumn* column = gtk_tree_view_column_new(); gtk_tree_view_append_column(treeview, column); gtk_tree_view_column_set_title(column, gettext("Players") ); gtk_tree_view_column_pack_start(column, text_renderer, TRUE); gtk_tree_view_column_add_attribute(column, text_renderer, "text", 0); } #define PLAYERS_COLUMN_CHIPS 1 { GtkTreeViewColumn* column = gtk_tree_view_column_new(); gtk_tree_view_append_column(treeview, column); gtk_tree_view_column_set_title(column, gettext("Chips") ); gtk_tree_view_column_pack_start(column, text_renderer, TRUE); gtk_tree_view_column_add_attribute(column, text_renderer, "text", 1); } #define PLAYERS_COLUMN_FLAG 2 } s_go_to_label = GTK_LABEL(glade_xml_get_widget(g_table_info_xml, "label_go_to")); s_go_to_button = GTK_BUTTON(glade_xml_get_widget(g_table_info_xml, "button_go_to")); g_signal_connect(GTK_OBJECT(s_go_to_button), "clicked", (GtkSignalFunc)on_go_to_clicked, &s_selected_table); s_lobby_tabs_window = gui_get_widget(g_lobby_tabs_xml, "lobby_tabs_window"); g_assert(s_lobby_tabs_window); gtk_widget_set_size_request(s_lobby_tabs_window, gui_width(screen), -1); if(screen) gtk_layout_put(screen, s_lobby_tabs_window, 0, 0); GUI_BRANCH(g_lobby_tabs_xml, on_table_toggled); GUI_BRANCH(g_lobby_tabs_xml, on_tourney_toggled); s_cashier_button_window = gui_get_widget(g_cashier_button_xml, "cashier_button_window"); g_assert(s_cashier_button_window); if(screen) gtk_layout_put(screen, s_cashier_button_window, 0, 0); s_cashier_button = GTK_BUTTON(gui_get_widget(g_cashier_button_xml, "cashier_button")); g_assert(s_cashier_button); GUI_BRANCH(g_cashier_button_xml, on_cashier_button_pressed); s_clock_window = gui_get_widget(g_clock_xml, "clock_window"); g_assert(s_clock_window); if(screen) gtk_layout_put(screen, s_clock_window, 0, 0); s_clock_label = gui_get_widget(g_clock_xml, "clock_label"); close_lobby(); } char* tag = get_string(); if(!strcmp(tag, "show")) { g_lobby_tab_state = lobby; { char* label = get_string(); gtk_button_set_label(s_cashier_button, label); g_free(label); } if (screen != NULL || s_lobby_shown == 0) { // // calculate windows position // int screen_width = gui_width(screen); int screen_height = gui_height(screen); int top_left_x = (screen_width - 1000) / 2; int top_left_y = (screen_height - 450) / 2; { static position_t position; position.x = screen_width - 610; position.y = top_left_y; gui_place(s_lobby_window, &position, screen); } { static position_t position; position.x = top_left_x; position.y = top_left_y; gui_place(s_table_info_window, &position, screen); } { static position_t position; position.x = 0; position.y = 33; gui_place(s_lobby_tabs_window, &position, screen); } { static position_t position; position.x = top_left_x; position.y = top_left_y + 435; gui_place(s_cashier_button_window, &position, screen); } s_lobby_shown = 1; } { gui_bottom_right(s_clock_window, screen); } s_selected_table = 0; { char* type = get_string(); if(!strcmp(type, "holdem")) { gtk_notebook_set_current_page(s_notebook, VARIANT_HOLDEM); } else if(!strcmp(type, "omaha")) { gtk_notebook_set_current_page(s_notebook, VARIANT_OMAHA); } else if(!strcmp(type, "omaha8")) { gtk_notebook_set_current_page(s_notebook, VARIANT_OMAHA8); } else if(!strcmp(type, "7stud")) { gtk_notebook_set_current_page(s_notebook, VARIANT_7STUD); } GtkToggleButton* button = GTK_TOGGLE_BUTTON(gui_get_widget(g_lobby_tabs_xml, type)); g_assert(button); gtk_toggle_button_set_active(button, TRUE); g_free(type); } { char* currency_serial = get_string(); char* button; GtkWidget* radio; if(!strcmp(currency_serial, "money_two")) { button = "money_two_radio"; } else if(!strcmp(currency_serial, "money_one")) { button = "money_one_radio"; } else { button = "all_radio"; } { //moneyone GtkWidget* sl = gui_get_widget(g_lobby_xml, "money_one_radio"); char* label = get_string(); gtk_button_set_label(GTK_BUTTON(sl), label); g_free(label); } { //moneytwo GtkWidget* sl = gui_get_widget(g_lobby_xml, "money_two_radio"); char* label = get_string(); gtk_button_set_label(GTK_BUTTON(sl), label); g_free(label); } s_disable_buttons = 1; radio = gui_get_widget(s_lobby_xml, button); g_assert(radio); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); s_disable_buttons = 0; g_free(currency_serial); } } else if(!strcmp(tag, "hide")) { g_lobby_tab_state = none; close_lobby(); } else if(!strcmp(tag, "info")) { char* players_count = get_string(); char* tables_count = get_string(); gtk_label_set_text(s_players_label, players_count); gtk_label_set_text(s_tables_label, tables_count); g_free(players_count); g_free(tables_count); } else if(!strcmp(tag, "holdem") || !strcmp(tag, "omaha") || !strcmp(tag, "omaha8") || !strcmp(tag, "7stud")) { int selected = get_int(); int rows = get_int(); int i; int variant_index = VARIANT_HOLDEM; if(!strcmp(tag, "holdem")) { variant_index = VARIANT_HOLDEM; } else if(!strcmp(tag, "omaha")) { variant_index = VARIANT_OMAHA; } else if(!strcmp(tag, "omaha8")) { variant_index = VARIANT_OMAHA8; } else if(!strcmp(tag, "7stud")) { variant_index = VARIANT_7STUD; } gtk_list_store_clear(s_variants_store[variant_index]); for(i = 0; i < rows; i++) { int id = get_int(); GtkTreeIter iter; gtk_list_store_append(s_variants_store[variant_index], &iter); gtk_list_store_set(s_variants_store[variant_index], &iter, TABLE_COLUMN_ID, id, -1); if(selected == id) gtk_tree_selection_select_iter(s_variants_selection[variant_index], &iter); { char* my = get_string(); GdkPixbuf* pixbuf = 0; if(!strcmp(my, "yes")) { pixbuf = pixbuf_table_my; } gtk_list_store_set(s_variants_store[variant_index], &iter, TABLE_COLUMN_MY, pixbuf, -1); } #define SET_COLUMN(INDEX) \ { \ char* content = get_string(); \ gtk_list_store_set(s_variants_store[variant_index], &iter, INDEX, content, -1); \ g_free(content); \ } SET_COLUMN(TABLE_COLUMN_NAME); SET_COLUMN(TABLE_COLUMN_STRUCTURE); SET_COLUMN(TABLE_COLUMN_SEATS); SET_COLUMN(TABLE_COLUMN_AVG_POT); SET_COLUMN(TABLE_COLUMN_HANDS_PER_HOUR); SET_COLUMN(TABLE_COLUMN_PERCENT_FLOP); SET_COLUMN(TABLE_COLUMN_PLAYING); SET_COLUMN(TABLE_COLUMN_OBSERVING); SET_COLUMN(TABLE_COLUMN_WAITING); SET_COLUMN(TABLE_COLUMN_TIMEOUT); #undef SET_COLUMN } s_selected_table = selected; if(!selected) { gtk_list_store_clear(s_players_store); gtk_widget_set_sensitive(GTK_WIDGET(s_go_to_button), FALSE); } } else if(!strcmp(tag, "players")) { int players_count = get_int(); int i; gtk_label_set_text(s_go_to_label, gettext("GO TO TABLE") ); gtk_widget_set_sensitive(GTK_WIDGET(s_go_to_button), TRUE); gtk_list_store_clear(s_players_store); for(i = 0; i < players_count; i++) { char* name = get_string(); char* chips = get_string(); int flag = get_int(); GtkTreeIter iter; gtk_list_store_append(s_players_store, &iter); gtk_list_store_set(s_players_store, &iter, PLAYERS_COLUMN_NAME, name, PLAYERS_COLUMN_CHIPS, chips, PLAYERS_COLUMN_FLAG, flag, -1); g_free(name); g_free(chips); } } // // set clock time // { time_t _time; char date_buffer[8]; time(&_time); struct tm* _tm = gmtime(&_time); snprintf(date_buffer, sizeof (date_buffer), "%02d:%02d", _tm->tm_hour, _tm->tm_min); gtk_label_set_text(GTK_LABEL(s_clock_label), date_buffer); } g_free(tag); return TRUE; }