void calculate_position(panel *np) { int sswidth, ssheight, minx, miny; ENTER; if (0) { //if (np->curdesk < np->wa_len/4) { minx = np->workarea[np->curdesk*4 + 0]; miny = np->workarea[np->curdesk*4 + 1]; sswidth = np->workarea[np->curdesk*4 + 2]; ssheight = np->workarea[np->curdesk*4 + 3]; } else { minx = miny = 0; sswidth = gdk_screen_width(); ssheight = gdk_screen_height(); } if (np->edge == EDGE_TOP || np->edge == EDGE_BOTTOM) { np->aw = np->width; np->ax = minx; calculate_width(sswidth, np->widthtype, np->allign, np->margin, &np->aw, &np->ax); np->ah = np->height; np->ah = MIN(PANEL_HEIGHT_MAX, np->ah); np->ah = MAX(PANEL_HEIGHT_MIN, np->ah); np->ay = miny + ((np->edge == EDGE_TOP) ? 0 : (ssheight - np->ah)); } else { np->ah = np->width; np->ay = miny; calculate_width(ssheight, np->widthtype, np->allign, np->margin, &np->ah, &np->ay); np->aw = np->height; np->aw = MIN(PANEL_HEIGHT_MAX, np->aw); np->aw = MAX(PANEL_HEIGHT_MIN, np->aw); np->ax = minx + ((np->edge == EDGE_LEFT) ? 0 : (sswidth - np->aw)); } DBG("%s - x=%d y=%d w=%d h=%d\n", __FUNCTION__, np->ax, np->ay, np->aw, np->ah); RET(); }
void calculate_position(Panel *np) { GdkScreen *screen; GdkRectangle marea; ENTER; /* FIXME: Why this doesn't work? */ /* if you are still going to use this, be sure to update it to take into account multiple monitors */ if (0) { // if (np->curdesk < np->wa_len/4) { marea.x = np->workarea[np->curdesk*4 + 0]; marea.y = np->workarea[np->curdesk*4 + 1]; marea.width = np->workarea[np->curdesk*4 + 2]; marea.height = np->workarea[np->curdesk*4 + 3]; } else { screen = gtk_widget_get_screen(np->topgwin); g_assert(np->monitor >= 0 && np->monitor < gdk_screen_get_n_monitors(screen)); gdk_screen_get_monitor_geometry(screen,np->monitor,&marea); } if (np->edge == EDGE_TOP || np->edge == EDGE_BOTTOM) { np->aw = np->width; np->ax = marea.x; calculate_width(marea.width, np->widthtype, np->allign, np->margin, &np->aw, &np->ax); np->ah = ((( ! np->autohide) || (np->visible)) ? np->height : np->height_when_hidden); np->ay = marea.y + ((np->edge == EDGE_TOP) ? 0 : (marea.height - np->ah)); } else { np->ah = np->width; np->ay = marea.y; calculate_width(marea.height, np->widthtype, np->allign, np->margin, &np->ah, &np->ay); np->aw = ((( ! np->autohide) || (np->visible)) ? np->height : np->height_when_hidden); np->ax = marea.x + ((np->edge == EDGE_LEFT) ? 0 : (marea.width - np->aw)); } //g_debug("%s - x=%d y=%d w=%d h=%d\n", __FUNCTION__, np->ax, np->ay, np->aw, np->ah); RET(); }
void Menu::process_action(const MenuAction& menuaction) { int last_active_item = active_item; switch(menuaction) { case MENU_ACTION_UP: do { if (active_item > 0) --active_item; else active_item = int(items.size())-1; } while (items[active_item]->skippable() && (active_item != last_active_item)); break; case MENU_ACTION_DOWN: do { if(active_item < int(items.size())-1 ) ++active_item; else active_item = 0; } while (items[active_item]->skippable() && (active_item != last_active_item)); break; case MENU_ACTION_BACK: if(on_back_action()) { MenuManager::instance().pop_menu(); } return; break; default: break; } if (items[active_item]->no_other_action()) { items[active_item]->process_action(menuaction); return; } items[active_item]->process_action(menuaction); if(items[active_item]->changes_width()) { calculate_width(); } if(menuaction == MENU_ACTION_HIT) { menu_action(*items[active_item]); } }
MenuItem& Menu::add_item(std::unique_ptr<MenuItem> new_item, int pos_) { items.insert(items.begin()+pos_,std::move(new_item)); MenuItem& item = *items[pos_]; /* When the item is inserted before the selected item, the * same menu item should be still selected. */ if (active_item >= pos_) { active_item++; } calculate_width(); return item; }
/* Add an item to a menu */ MenuItem& Menu::add_item(std::unique_ptr<MenuItem> new_item) { items.push_back(std::move(new_item)); MenuItem& item = *items.back(); /* If a new menu is being built, the active item shouldn't be set to * something that isn't selectable. Set the active_item to the first * selectable item added. */ if (active_item == -1 && !item.skippable()) { active_item = static_cast<int>(items.size()) - 1; } calculate_width(); return item; }
void calculate_position(panel *np, int distance,int distancefrom) { int sswidth, ssheight, minx, miny, distancex, distancey; GdkScreen *screen; GdkDisplay *display; GdkRectangle *monitorGeometry; ENTER; display = gdk_display_get_default (); screen = gdk_display_get_screen(display,0); monitorGeometry = (GdkRectangle*) malloc(sizeof(GdkRectangle)); if (np->monitor >= gdk_screen_get_n_monitors(screen)) { np->monitor = 0; ERR("trayer: monitor parameter isn't valid, reseting value to 0\n"); } gdk_screen_get_monitor_geometry(screen,np->monitor,monitorGeometry); sswidth = monitorGeometry->width; ssheight = monitorGeometry->height; minx = monitorGeometry->x; miny = monitorGeometry->y; free(monitorGeometry); if (distancefrom == DISTANCEFROM_TOP || distancefrom == DISTANCEFROM_BOTTOM) { distancex = 0; distancey = (distancefrom == DISTANCEFROM_TOP) ? distance : -distance; } else { distancex = (distancefrom == DISTANCEFROM_LEFT) ? distance : -distance; distancey = 0; } if (np->edge == EDGE_TOP || np->edge == EDGE_BOTTOM) { np->aw = np->width; np->ax = minx + distancex; calculate_width(sswidth, np->widthtype, np->allign, np->margin, &np->aw, &np->ax); np->ah = np->height; np->ah = MIN(PANEL_HEIGHT_MAX, np->ah); np->ah = MAX(PANEL_HEIGHT_MIN, np->ah); np->ay = miny + ((np->edge == EDGE_TOP) ? distancey : (ssheight - np->ah - distancey)); } else { np->ah = np->width; np->ay = miny + distancey; calculate_width(ssheight, np->widthtype, np->allign, np->margin, &np->ah, &np->ay); np->aw = np->height; np->aw = MIN(PANEL_HEIGHT_MAX, np->aw); np->aw = MAX(PANEL_HEIGHT_MIN, np->aw); np->ax = minx + ((np->edge == EDGE_LEFT) ? distancex : (sswidth - np->aw - distancex)); } DBG("%s - x=%d y=%d w=%d h=%d\n", __FUNCTION__, np->ax, np->ay, np->aw, np->ah); RET(); }
static void calculate_optimum_size(GtkWidget * area, gint size) { const GameParams *game_params = get_game_params(); GdkPoint points[MAX_POINTS]; Polygon poly; gint new_size; gint fixedwidth; /* Size of fixed part (digits + spacing) */ gint variablewidth; /* Size of variable part (polygons) */ if (game_params == NULL) return; guimap_scale_with_radius(&bogus_map, size); if (bogus_map.hex_radius <= MIN_HEX_RADIUS) return; fixedwidth = 0; variablewidth = 0; poly.points = points; if (game_params->num_build_type[BUILD_ROAD] > 0) { poly.num_points = MAX_POINTS; guimap_road_polygon(&bogus_map, NULL, &poly); calculate_width(area, &poly, stock_num_roads(), &fixedwidth, &variablewidth); } if (game_params->num_build_type[BUILD_SHIP] > 0) { poly.num_points = MAX_POINTS; guimap_ship_polygon(&bogus_map, NULL, &poly); calculate_width(area, &poly, stock_num_ships(), &fixedwidth, &variablewidth); } if (game_params->num_build_type[BUILD_BRIDGE] > 0) { poly.num_points = MAX_POINTS; guimap_bridge_polygon(&bogus_map, NULL, &poly); calculate_width(area, &poly, stock_num_bridges(), &fixedwidth, &variablewidth); } if (game_params->num_build_type[BUILD_SETTLEMENT] > 0) { poly.num_points = MAX_POINTS; guimap_settlement_polygon(&bogus_map, NULL, &poly); calculate_width(area, &poly, stock_num_settlements(), &fixedwidth, &variablewidth); } if (game_params->num_build_type[BUILD_CITY] > 0) { poly.num_points = MAX_POINTS; guimap_city_polygon(&bogus_map, NULL, &poly); calculate_width(area, &poly, stock_num_cities(), &fixedwidth, &variablewidth); } if (game_params->num_build_type[BUILD_CITY_WALL] > 0) { poly.num_points = MAX_POINTS; guimap_city_wall_polygon(&bogus_map, NULL, &poly); calculate_width(area, &poly, stock_num_city_walls(), &fixedwidth, &variablewidth); } new_size = bogus_map.hex_radius * (area->allocation.width - 75 - fixedwidth) / variablewidth; if (new_size < bogus_map.hex_radius) { calculate_optimum_size(area, new_size); } }
void Menu::event(const SDL_Event& ev) { items[active_item]->event(ev); switch(ev.type) { case SDL_KEYDOWN: case SDL_TEXTINPUT: if(((ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_BACKSPACE) || ev.type == SDL_TEXTINPUT) && items[active_item]->changes_width()) { // Changed item value? Let's recalculate width: calculate_width(); } break; case SDL_MOUSEBUTTONDOWN: if(ev.button.button == SDL_BUTTON_LEFT) { Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); if (mouse_pos.x > pos.x - get_width() / 2.0f && mouse_pos.x < pos.x + get_width() / 2.0f && mouse_pos.y > pos.y - get_height() / 2.0f && mouse_pos.y < pos.y + get_height() / 2.0f) { process_action(MENU_ACTION_HIT); } } break; case SDL_MOUSEMOTION: { Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); float x = mouse_pos.x; float y = mouse_pos.y; if(x > pos.x - get_width()/2 && x < pos.x + get_width()/2 && y > pos.y - get_height()/2 && y < pos.y + get_height()/2) { int new_active_item = static_cast<int> ((y - (pos.y - get_height()/2)) / 24); /* only change the mouse focus to a selectable item */ if (!items[new_active_item]->skippable()) active_item = new_active_item; if(MouseCursor::current()) MouseCursor::current()->set_state(MC_LINK); } else { if(MouseCursor::current()) MouseCursor::current()->set_state(MC_NORMAL); } } break; default: break; } }
/* this function is 40% of the file * it HAS to be simplified */ void rtl_table_print(rtl_table_t * table) { /* Initialize variables............. */ int i, j; int *width_arr = calculate_width(table); int wide = 0; int check_size = 0; int wall_space = 0; int align = table->options[2]; bool has_colors = 0; bool is_enumerated = 0; bool is_transparent = 0; /* * Check table properties, colors, transparency etc. */ if (table->options[1] == RTL_TABLE_COLORFUL) has_colors = 1; if (table->options[1] == RTL_TABLE_TRANSPARENT) is_transparent = 1; if (table->options[3] == RTL_TABLE_ENUMERATE) is_enumerated = 1; /*---------------------------------------------------*/ /* * Get overall table width, add together biggest strings from all * rows, + 4 for each because of default cell spacing */ for (i = 0; i < table->col_dimension; i++) { wide += width_arr[i] + 4; } /* On top of this, add */ wide += table->col_dimension - 1; /* ......Should table be enumerated?............................ */ if (is_enumerated) { for (i = 0; i < table->col_dimension; i++) { if (align == RTL_TABLE_LEFT) { if (i == 0) { ms(1, ' '); } else { ms(width_arr[i] + 4, ' '); } printf("%i", i); } else if (align == RTL_TABLE_RIGHT) { ms(width_arr[i] + 4, ' '); printf("%i", i); } else if (align == RTL_TABLE_CENTER) { if (i == 0) { ms(width_arr[0] + 3, ' '); } else { ms((width_arr[i]) + 4, ' '); } printf("%i", i); } } printf("\n"); if (!is_transparent) printf(" "); if (table->row_dimension > 10 && table->row_dimension < 100) { wall_space = 1; } else if (table->row_dimension > 100 && table->row_dimension < 1000) { wall_space = 2; } else if (table->row_dimension > 1000 && table->row_dimension < 10000) { wall_space = 3; } } /*------------------------------------------------------------------------------*/ /* ......Check for transparency...................... */ if (!is_transparent) { ms(wall_space, ' '); printf("+"); ms(wide, '-'); printf("+\n"); } /*------------------------------------------------------*/ /* ......Make proper space aligning if table is enumerated......... */ for (i = 0; i < table->row_dimension; i++) { if (is_enumerated) { switch (wall_space) { case 1: if (i < 10) { ms(wall_space, ' '); } break; case 2: if (i < 10) { ms(wall_space, ' '); } else if (i < 100 && i >= 10) { ms(wall_space - 1, ' '); } break; case 3: if (i < 10) { ms(wall_space, ' '); } else if (i < 100 && i >= 10) { ms(wall_space - 1, ' '); } else if (i < 1000 && i >= 100) { ms(wall_space - 2, ' '); } break; default: break; } printf("%i", i); } /*-----------------------------------------------------------------*/ filler_p(table); /* * Start main printing * loop....................................................... * .......................... */ for (j = 0; j < table->col_dimension; j++) { switch (align) { case RTL_TABLE_LEFT: if (has_colors || is_transparent) { printf("%s", table->info[i][j].color); printf("%s", table->info[i][j].str); ms(table->info[i][j].cell_width, ' '); printf("%s", RTL_TABLE_DEFAULT); } else { printf("%s", table->info[i][j].str); ms(table->info[i][j].cell_width, ' '); } filler_p(table); break; case RTL_TABLE_RIGHT: if (has_colors || is_transparent) { printf("%s", table->info[i][j].color); ms(table->info[i][j].cell_width, ' '); printf("%s", table->info[i][j].str); printf("%s", RTL_TABLE_DEFAULT); } else { ms(table->info[i][j].cell_width, ' '); printf("%s", table->info[i][j].str); } filler_p(table); break; case RTL_TABLE_CENTER: check_size = (table->info[i][j].cell_width + table->info[i][j].width + table->info[i][j].cell_width); if (check_size < table->info[i][j].max_cell_w) { if (has_colors || is_transparent) { printf("%s", table->info[i][j].color); ms(table->info[i][j].cell_width, ' '); printf("%s", table->info[i][j].str); ms(table->info[i][j].cell_width + table->info[i][j].max_cell_w - check_size, ' '); printf("%s", RTL_TABLE_DEFAULT); } else { ms(table->info[i][j].cell_width, ' '); printf("%s", table->info[i][j].str); ms(table->info[i][j].cell_width + table->info[i][j].max_cell_w - check_size, ' '); } } else { if (has_colors || is_transparent) { printf("%s", table->info[i][j].color); ms(table->info[i][j].cell_width, ' '); printf("%s", table->info[i][j].str); ms(table->info[i][j].cell_width, ' '); printf("%s", RTL_TABLE_DEFAULT); } else { ms(table->info[i][j].cell_width, ' '); printf("%s", table->info[i][j].str); ms(table->info[i][j].cell_width, ' '); } } filler_p(table); break; } } printf("\n"); } /*--------------------------------------------------------------------------------------------------------*/ if (is_enumerated) { ms(wall_space, ' '); printf(" "); } if (!is_transparent) { printf("+"); ms(wide, '-'); printf("+"); } else { ms(3, ' '); } putchar('\n'); /*Turn off option flags */ has_colors = 0; is_enumerated = 0; is_transparent = 0; /* FREE CONTAINER */ free(width_arr); }