Mercurial > hg > openttd
changeset 4435:b10955b9482b draft
(svn r6205) -CodeChange : use a switch case instead of a cascade of if
-CodeChange : rename var Engine *e to Engine *eng, since we have WindowEvent *e in same fnct
-CodeChange : fix a broken tabulation on a switch case. SOme breathing spaces too
author | belugas <belugas@openttd.org> |
---|---|
date | Tue, 29 Aug 2006 00:17:47 +0000 |
parents | 1a5cc10eaae0 |
children | 983a6976027c |
files | road_gui.c ship_gui.c smallmap_gui.c |
diffstat | 3 files changed, 111 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/road_gui.c +++ b/road_gui.c @@ -233,16 +233,24 @@ case WE_PLACE_DRAG: { int sel_method; - if (e->place.userdata == 1) { - sel_method = VPM_FIX_X; - _place_road_flag = (_place_road_flag&~2) | ((e->place.pt.y&8)>>2); - } else if (e->place.userdata == 2) { - sel_method = VPM_FIX_Y; - _place_road_flag = (_place_road_flag&~2) | ((e->place.pt.x&8)>>2); - } else if (e->place.userdata == 4) { - sel_method = VPM_X_AND_Y; - } else { - sel_method = VPM_X_OR_Y; + switch (e->place.userdata) { + case 1: + sel_method = VPM_FIX_X; + _place_road_flag = (_place_road_flag & ~2) | ((e->place.pt.y & 8) >> 2); + break; + + case 2: + sel_method = VPM_FIX_Y; + _place_road_flag = (_place_road_flag & ~2) | ((e->place.pt.x & 8) >> 2); + break; + + case 4: + sel_method = VPM_X_AND_Y; + break; + + default: + sel_method = VPM_X_OR_Y; + break; } VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, sel_method);
--- a/ship_gui.c +++ b/ship_gui.c @@ -328,11 +328,11 @@ { int count = 0; int num = NUM_SHIP_ENGINES; - const Engine *e = GetEngine(SHIP_ENGINES_INDEX); + const Engine *eng = GetEngine(SHIP_ENGINES_INDEX); do { - if (HASBIT(e->player_avail, _local_player)) count++; - } while (++e,--num); + if (HASBIT(eng->player_avail, _local_player)) count++; + } while (++eng,--num); SetVScrollCount(w, count); } @@ -340,7 +340,7 @@ { int num = NUM_SHIP_ENGINES; - const Engine *e = GetEngine(SHIP_ENGINES_INDEX); + const Engine *eng = GetEngine(SHIP_ENGINES_INDEX); int x = 2; int y = 15; int sel = WP(w,buildtrain_d).sel_index; @@ -349,7 +349,7 @@ EngineID selected_id = INVALID_ENGINE; do { - if (HASBIT(e->player_avail, _local_player)) { + if (HASBIT(eng->player_avail, _local_player)) { if (sel==0) selected_id = engine_id; if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) { DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10); @@ -358,7 +358,7 @@ } sel--; } - } while (++engine_id, ++e,--num); + } while (++engine_id, ++eng,--num); WP(w,buildtrain_d).sel_engine = selected_id;
--- a/smallmap_gui.c +++ b/smallmap_gui.c @@ -806,108 +806,108 @@ static void SmallMapWindowProc(Window *w, WindowEvent *e) { switch (e->event) { - case WE_PAINT: { - const uint16 *tbl; - int x,y,y_org; - DrawPixelInfo new_dpi; - - /* draw the window */ - SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); - DrawWindowWidgets(w); + case WE_PAINT: { + const uint16 *tbl; + int x, y, y_org; + DrawPixelInfo new_dpi; - /* draw the legend */ - tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; - x = 4; - y_org = w->height - 44 - 11; - y = y_org; - for (;;) { - GfxFillRect(x, y + 1, x + 8, y + 5, 0); - GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]); - DrawString(x + 11, y, tbl[1], 0); - - tbl += 2; - y += 6; + /* draw the window */ + SetDParam(0, STR_00E5_CONTOURS + _smallmap_type); + DrawWindowWidgets(w); - if (tbl[0] == 0xFFFF) { - break; - } else if (tbl[0] & 0x100) { - x += 123; - y = y_org; - } - } - - if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11)) - return; - - DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns); - } break; + /* draw the legend */ + tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)]; + x = 4; + y_org = w->height - 44 - 11; + y = y_org; + for (;;) { + GfxFillRect(x, y + 1, x + 8, y + 5, 0); + GfxFillRect(x + 1, y + 2, x + 7, y + 4, (byte)tbl[0]); + DrawString(x + 11, y, tbl[1], 0); - case WE_CLICK: - switch (e->click.widget) { - case 4: { // Map window - Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); - Point pt; - int x, y; + tbl += 2; + y += 6; - pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); - x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); - y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); - - /* If you press twice on a place in the smallmap, center there */ - if (WP(w2, vp_d).scrollpos_x == x && WP(w2, vp_d).scrollpos_y == y) { - SmallMapCenterOnCurrentPos(w); - } else { - WP(w2, vp_d).scrollpos_x = x; - WP(w2, vp_d).scrollpos_y = y; + if (tbl[0] == 0xFFFF) { + break; + } else if (tbl[0] & 0x100) { + x += 123; + y = y_org; + } } - SetWindowDirty(w); + if (!FillDrawPixelInfo(&new_dpi, 3, 17, w->width - 28 + 22, w->height - 64 - 11)) + return; + + DrawSmallMap(&new_dpi, w, _smallmap_type, _smallmap_show_towns); } break; - case 5: // Show land contours - case 6: // Show vehicles - case 7: // Show industries - case 8: // Show transport routes - case 9: // Show vegetation - case 10: // Show land owners - w->click_state &= ~(1<<5|1<<6|1<<7|1<<8|1<<9|1<<10); - w->click_state |= 1 << e->click.widget; - _smallmap_type = e->click.widget - 5; + case WE_CLICK: + switch (e->click.widget) { + case 4: { // Map window + Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); + Point pt; + int x, y; + + pt = RemapCoords(WP(w,smallmap_d).scroll_x, WP(w,smallmap_d).scroll_y, 0); + x = pt.x + ((_cursor.pos.x - w->left + 2) << 4) - (w2->viewport->virtual_width >> 1); + y = pt.y + ((_cursor.pos.y - w->top - 16) << 4) - (w2->viewport->virtual_height >> 1); + + /* If you press twice on a place in the smallmap, center there */ + if (WP(w2, vp_d).scrollpos_x == x && WP(w2, vp_d).scrollpos_y == y) { + SmallMapCenterOnCurrentPos(w); + } else { + WP(w2, vp_d).scrollpos_x = x; + WP(w2, vp_d).scrollpos_y = y; + } + + SetWindowDirty(w); + } break; - SetWindowDirty(w); - SndPlayFx(SND_15_BEEP); - break; + case 5: // Show land contours + case 6: // Show vehicles + case 7: // Show industries + case 8: // Show transport routes + case 9: // Show vegetation + case 10: // Show land owners + w->click_state &= ~( 1 << 5 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 9 | 1 << 10); + w->click_state |= 1 << e->click.widget; + _smallmap_type = e->click.widget - 5; + + SetWindowDirty(w); + SndPlayFx(SND_15_BEEP); + break; - case 11: // Center the smallmap again - SmallMapCenterOnCurrentPos(w); + case 11: // Center the smallmap again + SmallMapCenterOnCurrentPos(w); + + SetWindowDirty(w); + SndPlayFx(SND_15_BEEP); + break; - SetWindowDirty(w); - SndPlayFx(SND_15_BEEP); + case 12: // Toggle town names + w->click_state ^= (1 << 12); + _smallmap_show_towns = (w->click_state >> 12) & 1; + + SetWindowDirty(w); + SndPlayFx(SND_15_BEEP); + break; + } break; - case 12: // Toggle town names - w->click_state ^= (1 << 12); - _smallmap_show_towns = (w->click_state >> 12) & 1; - - SetWindowDirty(w); - SndPlayFx(SND_15_BEEP); + case WE_RCLICK: + if (e->click.widget == 4) { + if (_scrolling_viewport) return; + _scrolling_viewport = true; + _cursor.delta.x = 0; + _cursor.delta.y = 0; + } break; - } - break; - case WE_RCLICK: - if (e->click.widget == 4) { - if (_scrolling_viewport) return; - _scrolling_viewport = true; - _cursor.delta.x = 0; - _cursor.delta.y = 0; - } - break; - - case WE_MOUSELOOP: - /* update the window every now and then */ - if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); - break; + case WE_MOUSELOOP: + /* update the window every now and then */ + if ((++w->vscroll.pos & 0x1F) == 0) SetWindowDirty(w); + break; case WE_SCROLL: { int x;