1
0
Fork 0

(svn r7616) -Cleanup:

-(re)set _rename_[id/what] to -1 to catch invalid calls (main_gui.c)
 -Only invalidate widget of pause/ff instead of whole window (main_gui.c)
 -Remove numbering from WE_ and WC_ as it's not needed, also remove
  non-existing windowclasses (window.h, openttd.h)
 -Give names to some of the enums (window.h)
 -In UninitWindowSystem not only free malloc'd widgets, but also reset the z-array (window.c)
 -Some coding style, comments, etc.
release/0.6
Darkvater 2006-12-29 13:59:48 +00:00
parent 5bb559a978
commit 649b25bd11
6 changed files with 124 additions and 124 deletions

View File

@ -43,8 +43,8 @@
#include "network_gui.h" #include "network_gui.h"
#include "industry.h" #include "industry.h"
static int _rename_id; static int _rename_id = 1;
static int _rename_what; static int _rename_what = -1;
static byte _terraform_size = 1; static byte _terraform_size = 1;
RailType _last_built_railtype; RailType _last_built_railtype;
@ -90,10 +90,12 @@ void HandleOnEditText(WindowEvent *e)
} else { } else {
NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX); NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX);
} }
break; } break;
}
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
default: NOT_REACHED();
} }
_rename_id = _rename_what = -1;
} }
/** /**
@ -1840,12 +1842,12 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
case WE_MOUSELOOP: case WE_MOUSELOOP:
if (IsWindowWidgetLowered(w, 0) != !!_pause) { if (IsWindowWidgetLowered(w, 0) != !!_pause) {
ToggleWidgetLoweredState(w, 0); ToggleWidgetLoweredState(w, 0);
SetWindowDirty(w); InvalidateWidget(w, 0);
} }
if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) { if (IsWindowWidgetLowered(w, 1) != !!_fast_forward) {
ToggleWidgetLoweredState(w, 1); ToggleWidgetLoweredState(w, 1);
SetWindowDirty(w); InvalidateWidget(w, 1);
} }
break; break;
@ -2371,7 +2373,7 @@ void SetupColorsAndInitialWindow(void)
{ {
uint i; uint i;
Window *w; Window *w;
int width,height; int width, height;
for (i = 0; i != 16; i++) { for (i = 0; i != 16; i++) {
const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i); const byte *b = GetNonSprite(PALETTE_RECOLOR_START + i);

View File

@ -491,8 +491,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
_network_join_status = NETWORK_JOIN_STATUS_PROCESSING; _network_join_status = NETWORK_JOIN_STATUS_PROCESSING;
InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
// The map is done downloading, load it /* The map is done downloading, load it */
// Load the map
if (!SafeSaveOrLoad(filename, SL_LOAD, GM_NORMAL)) { if (!SafeSaveOrLoad(filename, SL_LOAD, GM_NORMAL)) {
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; _switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;

View File

@ -2483,9 +2483,7 @@ static void SafeInfo(byte *buf, int len)
info = name + name_len + 1; info = name + name_len + 1;
info_len = ttd_strnlen(info, len); info_len = ttd_strnlen(info, len);
if (info_len < len) { if (info_len < len) _cur_grfconfig->info = TranslateTTDPatchCodes(info);
_cur_grfconfig->info = TranslateTTDPatchCodes(info);
}
} }
} }

161
openttd.h
View File

@ -365,87 +365,86 @@ typedef struct {
enum { enum {
WC_MAIN_WINDOW = 0x00, WC_MAIN_WINDOW,
WC_MAIN_TOOLBAR = 0x01, WC_MAIN_TOOLBAR,
WC_STATUS_BAR = 0x02, WC_STATUS_BAR,
WC_BUILD_TOOLBAR = 0x03, WC_BUILD_TOOLBAR,
WC_NEWS_WINDOW = 0x04, WC_NEWS_WINDOW,
WC_TOWN_DIRECTORY = 0x05, WC_TOWN_DIRECTORY,
WC_STATION_LIST = 0x06, WC_STATION_LIST,
WC_TOWN_VIEW = 0x07, WC_TOWN_VIEW,
WC_SMALLMAP = 0x08, WC_SMALLMAP,
WC_TRAINS_LIST = 0x09, WC_TRAINS_LIST,
WC_ROADVEH_LIST = 0x0A, WC_ROADVEH_LIST,
WC_SHIPS_LIST = 0x0B, WC_SHIPS_LIST,
WC_AIRCRAFT_LIST = 0x0C, WC_AIRCRAFT_LIST,
WC_VEHICLE_VIEW = 0x0D, WC_VEHICLE_VIEW,
WC_VEHICLE_DETAILS = 0x0E, WC_VEHICLE_DETAILS,
WC_VEHICLE_REFIT = 0x0F, WC_VEHICLE_REFIT,
WC_VEHICLE_ORDERS = 0x10, WC_VEHICLE_ORDERS,
WC_STATION_VIEW = 0x11, WC_STATION_VIEW,
WC_VEHICLE_DEPOT = 0x12, WC_VEHICLE_DEPOT,
WC_BUILD_VEHICLE = 0x13, WC_BUILD_VEHICLE,
WC_BUILD_BRIDGE = 0x14, WC_BUILD_BRIDGE,
WC_ERRMSG = 0x15, WC_ERRMSG,
WC_ASK_ABANDON_GAME = 0x16, WC_ASK_ABANDON_GAME,
WC_QUIT_GAME = 0x17, WC_QUIT_GAME,
WC_BUILD_STATION = 0x18, WC_BUILD_STATION,
WC_BUS_STATION = 0x19, WC_BUS_STATION,
WC_TRUCK_STATION = 0x1A, WC_TRUCK_STATION,
WC_BUILD_DEPOT = 0x1B, WC_BUILD_DEPOT,
WC_COMPANY = 0x1D, WC_COMPANY,
WC_FINANCES = 0x1E, WC_FINANCES,
WC_PLAYER_COLOR = 0x1F, WC_PLAYER_COLOR,
WC_QUERY_STRING = 0x20, WC_QUERY_STRING,
WC_SAVELOAD = 0x21, WC_SAVELOAD,
WC_SELECT_GAME = 0x22, WC_SELECT_GAME,
WC_TOOLBAR_MENU = 0x24, WC_TOOLBAR_MENU,
WC_INCOME_GRAPH = 0x25, WC_INCOME_GRAPH,
WC_OPERATING_PROFIT = 0x26, WC_OPERATING_PROFIT,
WC_TOOLTIPS = 0x27, WC_TOOLTIPS,
WC_INDUSTRY_VIEW = 0x28, WC_INDUSTRY_VIEW,
WC_PLAYER_FACE = 0x29, WC_PLAYER_FACE,
WC_LAND_INFO = 0x2A, WC_LAND_INFO,
WC_TOWN_AUTHORITY = 0x2B, WC_TOWN_AUTHORITY,
WC_SUBSIDIES_LIST = 0x2C, WC_SUBSIDIES_LIST,
WC_GRAPH_LEGEND = 0x2D, WC_GRAPH_LEGEND,
WC_DELIVERED_CARGO = 0x2E, WC_DELIVERED_CARGO,
WC_PERFORMANCE_HISTORY = 0x2F, WC_PERFORMANCE_HISTORY,
WC_COMPANY_VALUE = 0x30, WC_COMPANY_VALUE,
WC_COMPANY_LEAGUE = 0x31, WC_COMPANY_LEAGUE,
WC_BUY_COMPANY = 0x32, WC_BUY_COMPANY,
WC_PAYMENT_RATES = 0x33, WC_PAYMENT_RATES,
WC_ENGINE_PREVIEW = 0x35, WC_ENGINE_PREVIEW,
WC_MUSIC_WINDOW = 0x36, WC_MUSIC_WINDOW,
WC_MUSIC_TRACK_SELECTION = 0x37, WC_MUSIC_TRACK_SELECTION,
WC_SCEN_LAND_GEN = 0x38, // also used for landscaping toolbar WC_SCEN_LAND_GEN,
WC_ASK_RESET_LANDSCAPE = 0x39, WC_SCEN_TOWN_GEN,
WC_SCEN_TOWN_GEN = 0x3A, WC_SCEN_INDUSTRY,
WC_SCEN_INDUSTRY = 0x3B, WC_SCEN_BUILD_ROAD,
WC_SCEN_BUILD_ROAD = 0x3C, WC_BUILD_TREES,
WC_BUILD_TREES = 0x3D, WC_SEND_NETWORK_MSG,
WC_SEND_NETWORK_MSG = 0x3E, WC_DROPDOWN_MENU,
WC_DROPDOWN_MENU = 0x3F, WC_BUILD_INDUSTRY,
WC_BUILD_INDUSTRY = 0x40, WC_GAME_OPTIONS,
WC_GAME_OPTIONS = 0x41, WC_NETWORK_WINDOW,
WC_NETWORK_WINDOW = 0x42, WC_INDUSTRY_DIRECTORY,
WC_INDUSTRY_DIRECTORY = 0x43, WC_MESSAGE_HISTORY,
WC_MESSAGE_HISTORY = 0x44, WC_CHEATS,
WC_CHEATS = 0x45, WC_PERFORMANCE_DETAIL,
WC_PERFORMANCE_DETAIL = 0x46, WC_CONSOLE,
WC_CONSOLE = 0x47, WC_EXTRA_VIEW_PORT,
WC_EXTRA_VIEW_PORT = 0x48, WC_CLIENT_LIST,
WC_CLIENT_LIST = 0x49, WC_NETWORK_STATUS_WINDOW,
WC_NETWORK_STATUS_WINDOW = 0x4A, WC_CUSTOM_CURRENCY,
WC_CUSTOM_CURRENCY = 0x4B, WC_REPLACE_VEHICLE,
WC_REPLACE_VEHICLE = 0x4C, WC_HIGHSCORE,
WC_HIGHSCORE = 0x4D, WC_ENDSCREEN,
WC_ENDSCREEN = 0x4E, WC_SIGN_LIST,
WC_SIGN_LIST = 0x4F, WC_GENERATE_LANDSCAPE,
WC_GENERATE_LANDSCAPE = 0x50, WC_GENERATE_PROGRESS_WINDOW,
WC_GENERATE_PROGRESS_WINDOW = 0x51, WC_OK_CANCEL_QUERY,
WC_OK_CANCEL_QUERY = 0x52, WC_DEPOT_SELL_ALL,
WC_DEPOT_SELL_ALL = 0x53,
}; };

View File

@ -875,13 +875,15 @@ void InitWindowSystem(void)
void UnInitWindowSystem(void) void UnInitWindowSystem(void)
{ {
Window* const *wz; Window **wz;
// delete all malloced widgets /* Delete all malloced widgets, and reset z-array */
FOR_ALL_WINDOWS(wz) { FOR_ALL_WINDOWS(wz) {
free((*wz)->widget); free((*wz)->widget);
(*wz)->widget = NULL; (*wz)->widget = NULL;
(*wz)->widget_count = 0; (*wz)->widget_count = 0;
*wz = NULL;
} }
_last_z_window = _z_windows;
} }
void ResetWindowSystem(void) void ResetWindowSystem(void)

View File

@ -86,33 +86,33 @@ typedef enum FrameFlags {
void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags); void DrawFrameRect(int left, int top, int right, int bottom, int color, FrameFlags flags);
enum WindowEventCodes { enum WindowEventCodes {
WE_CLICK = 0, WE_CREATE,
WE_PAINT = 1, WE_DESTROY,
WE_MOUSELOOP = 2, WE_PAINT,
WE_TICK = 3, WE_KEYPRESS,
WE_4 = 4, WE_CLICK,
WE_TIMEOUT = 5, WE_RCLICK,
WE_PLACE_OBJ = 6, WE_MOUSEOVER,
WE_ABORT_PLACE_OBJ = 7, WE_MOUSELOOP,
WE_DESTROY = 8, WE_MOUSEWHEEL,
WE_ON_EDIT_TEXT = 9, WE_TICK,
WE_POPUPMENU_SELECT = 10, WE_4,
WE_POPUPMENU_OVER = 11, WE_TIMEOUT,
WE_DRAGDROP = 12, WE_PLACE_OBJ,
WE_PLACE_DRAG = 13, WE_ABORT_PLACE_OBJ,
WE_PLACE_MOUSEUP = 14, WE_ON_EDIT_TEXT,
WE_PLACE_PRESIZE = 15, WE_ON_EDIT_TEXT_CANCEL,
WE_DROPDOWN_SELECT = 16, WE_POPUPMENU_SELECT,
WE_RCLICK = 17, WE_POPUPMENU_OVER,
WE_KEYPRESS = 18, WE_DRAGDROP,
WE_CREATE = 19, WE_PLACE_DRAG,
WE_MOUSEOVER = 20, WE_PLACE_MOUSEUP,
WE_ON_EDIT_TEXT_CANCEL = 21, WE_PLACE_PRESIZE,
WE_RESIZE = 22, WE_DROPDOWN_SELECT,
WE_MESSAGE = 23, WE_RESIZE,
WE_SCROLL = 24, WE_MESSAGE,
WE_MOUSEWHEEL = 25, WE_SCROLL,
WE_INVALIDATE_DATA = 26, WE_INVALIDATE_DATA,
}; };
struct WindowEvent { struct WindowEvent {
@ -263,7 +263,7 @@ typedef struct WindowDesc {
WindowProc *proc; WindowProc *proc;
} WindowDesc; } WindowDesc;
enum { enum WindowDefaultFlag {
WDF_STD_TOOLTIPS = 1, /* use standard routine when displaying tooltips */ WDF_STD_TOOLTIPS = 1, /* use standard routine when displaying tooltips */
WDF_DEF_WIDGET = 2, /* default widget control for some widgets in the on click event */ WDF_DEF_WIDGET = 2, /* default widget control for some widgets in the on click event */
WDF_STD_BTN = 4, /* default handling for close and drag widgets (widget no 0 and 1) */ WDF_STD_BTN = 4, /* default handling for close and drag widgets (widget no 0 and 1) */
@ -274,7 +274,7 @@ enum {
}; };
/* can be used as x or y coordinates to cause a specific placement */ /* can be used as x or y coordinates to cause a specific placement */
enum { enum WindowDefaultPosition {
WDP_AUTO = -1, ///< Find a place automatically WDP_AUTO = -1, ///< Find a place automatically
WDP_CENTER = -2, ///< Center the window (left/right or top/bottom) WDP_CENTER = -2, ///< Center the window (left/right or top/bottom)
WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar WDP_ALIGN_TBR = -3, ///< Align the right side of the window with the right side of the main toolbar