Mercurial > hg > openttd
changeset 5120:dc7d90903438 draft
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
instead of _windows loop (viewport.c), remove dump-code (mixer.c), MSVC6 borkdness
in stdafx.h, constness (viewport.c), variable localization (win32.c), comments (window.c)
author | Darkvater <Darkvater@openttd.org> |
---|---|
date | Sat, 18 Nov 2006 00:14:43 +0000 |
parents | 60d061daf0f4 |
children | b5a7dad5ee34 |
files | console.c misc_gui.c mixer.c stdafx.h viewport.c win32.c window.c window.h |
diffstat | 8 files changed, 43 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/console.c +++ b/console.c @@ -296,7 +296,7 @@ _iconsole_win->height = _screen.height - ICON_BOTTOM_BORDERWIDTH; _iconsole_win->width = _screen.width; break; - default: break; + default: return; } MarkWholeScreenDirty();
--- a/misc_gui.c +++ b/misc_gui.c @@ -541,7 +541,7 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y) { Window *w; - ViewPort *vp; + const ViewPort *vp; Point pt; DeleteWindowById(WC_ERRMSG, 0); @@ -553,15 +553,13 @@ _errmsg_message_2 = msg_2; COPY_OUT_DPARAM(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params)); _errmsg_duration = _patches.errmsg_duration; - if (!_errmsg_duration) - return; + if (!_errmsg_duration) return; if (_errmsg_message_1 != STR_013B_OWNED_BY || GetDParamX(_errmsg_decode_params,2) >= 8) { if ( (x|y) != 0) { pt = RemapCoords2(x, y); - for (w = _windows; w->window_class != WC_MAIN_WINDOW; w++) {} - vp = w->viewport; + vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; // move x pos to opposite corner pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left; @@ -579,8 +577,7 @@ } else { if ( (x|y) != 0) { pt = RemapCoords2(x, y); - for (w = _windows; w->window_class != WC_MAIN_WINDOW; w++) {} - vp = w->viewport; + vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport; pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334); pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137); } else { @@ -1013,10 +1010,10 @@ /* Limit the drawing of the string inside the widget boundaries */ if (!FillDrawPixelInfo(&dpi, - wi->left + 4, - wi->top + 1, - wi->right - wi->left - 4, - wi->bottom - wi->top - 1) + wi->left + 4, + wi->top + 1, + wi->right - wi->left - 4, + wi->bottom - wi->top - 1) ) return; GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215);
--- a/mixer.c +++ b/mixer.c @@ -89,15 +89,6 @@ if (mc->samples_left == 0) MxCloseChannel(mc); } } - - #if 0 - { - static FILE *out = NULL; - if (out == NULL) - out = fopen("d:\\dump.raw", "wb"); - fwrite(buffer, samples * 4, 1, out); - } - #endif } MixerChannel *MxAllocateChannel(void)
--- a/stdafx.h +++ b/stdafx.h @@ -102,16 +102,11 @@ # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers # pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data # pragma warning(disable: 4761) // integral size mismatch in argument : conversion supplied -# if _MSC_VER < 1300 // MSVC 6 borkdness -# pragma warning(disable: 4018) // 'expression' : signed/unsigned mismatch -# pragma warning(disable: 4305) // 'identifier' : truncation from 'type1' to 'type2' -# pragma warning(disable: 4786) // 'identifier' : identifier was truncated to '255' characters in the browser information -# endif /* _MSC_VER < 1300 */ + # if _MSC_VER >= 1400 // MSVC 2005 safety checks # pragma warning(disable: 4996) // 'strdup' was declared deprecated # define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions -# pragma comment(linker, "/NODEFAULTLIB:LIBC.LIB") - // allow linking to non-recompiled libs +# pragma comment(linker, "/NODEFAULTLIB:LIBCMT.LIB") // allow linking to non-recompiled libs # endif /* _MSC_VER >= 1400 */ # include <malloc.h> // alloca()
--- a/viewport.c +++ b/viewport.c @@ -165,7 +165,7 @@ static Point _vp_move_offs; -static void DoSetViewportPosition(Window *w, int left, int top, int width, int height) +static void DoSetViewportPosition(const Window *w, int left, int top, int width, int height) { for (; w < _last_window; w++) { if (left + width > w->left && @@ -1271,7 +1271,7 @@ // Make sure we don't draw a too big area at a time. // If we do, the sprite memory will overflow. -static void ViewportDrawChk(ViewPort *vp, int left, int top, int right, int bottom) +static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom) { if (((bottom - top) * (right - left) << vp->zoom) > 180000) { if ((bottom - top) > (right - left)) { @@ -1293,7 +1293,7 @@ } } -static inline void ViewportDraw(ViewPort *vp, int left, int top, int right, int bottom) +static inline void ViewportDraw(const ViewPort *vp, int left, int top, int right, int bottom) { if (right <= vp->left || bottom <= vp->top) return; @@ -1310,7 +1310,7 @@ ViewportDrawChk(vp, left, top, right, bottom); } -void DrawWindowViewport(Window *w) +void DrawWindowViewport(const Window *w) { DrawPixelInfo *dpi = _cur_dpi;
--- a/win32.c +++ b/win32.c @@ -637,7 +637,6 @@ DIR *opendir(const char *path) { - char search_path[MAX_PATH]; DIR *d; UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box DWORD fa = GetFileAttributes(path); @@ -645,6 +644,7 @@ if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) { d = dir_calloc(); if (d != NULL) { + char search_path[MAX_PATH]; /* build search path for FindFirstFile */ snprintf(search_path, lengthof(search_path), "%s" PATHSEP "*", path); d->hFind = FindFirstFile(search_path, &d->fd); @@ -893,7 +893,7 @@ GetCurrentDirectory(MAX_PATH - 1, cfg); cfg[0] = toupper(cfg[0]); - s = strchr(cfg, 0); + s = strchr(cfg, '\0'); if (s[-1] != '\\') strcpy(s, "\\"); _path.save_dir = str_fmt("%ssave", cfg);
--- a/window.c +++ b/window.c @@ -197,7 +197,6 @@ } } - static void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom); void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) @@ -348,12 +347,16 @@ } } -void DeletePlayerWindows(PlayerID pi) +/** Delete all windows of a player. We identify windows of a player + * by looking at the caption colour. If it is equal to the player ID + * then we say the window belongs to the player and should be deleted + * @param id PlayerID player identifier */ +void DeletePlayerWindows(PlayerID id) { Window *w; for (w = _windows; w != _last_window;) { - if (w->caption_color == pi) { + if (w->caption_color == id) { DeleteWindow(w); w = _windows; } else { @@ -361,11 +364,15 @@ } } - /* Also delete the player specific windows, that haven't got the caption set */ - DeleteWindowById(WC_BUY_COMPANY, pi); + /* Also delete the player specific windows, that don't have a player-colour */ + DeleteWindowById(WC_BUY_COMPANY, id); } -/* Change the owner of all the windows one player can take over from another player (like vehicle view windows) */ +/** Change the owner of all the windows one player can take over from another + * player in the case of a company merger. Do not change ownership of windows + * that need to be deleted once takeover is complete + * @param old_player PlayerID of original owner of the window + * @param new_player PlayerID of the new owner of the window */ void ChangeWindowOwner(PlayerID old_player, PlayerID new_player) { Window *w; @@ -381,6 +388,7 @@ if (w->window_class == WC_AIRCRAFT_LIST) continue; if (w->window_class == WC_BUY_COMPANY) continue; if (w->window_class == WC_COMPANY) continue; + w->caption_color = new_player; } } @@ -411,7 +419,9 @@ * there are certain windows that always need to be on-top; these include * - Toolbar, Statusbar (always on) * - New window, Chatbar (only if open) + * The window is marked dirty for a repaint if the window is actually moved * @param w window that is put into the foreground + * @return pointer to the window, can be different! */ static Window *BringWindowToFront(Window *w) { @@ -548,7 +558,7 @@ } // Set up window properties - memset(w, 0, sizeof(Window)); + memset(w, 0, sizeof(*w)); w->window_class = cls; w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border w->caption_color = 0xFF; @@ -639,10 +649,8 @@ width = _awap_r.width; height = _awap_r.height; - if (left < -(width>>2) || left > _screen.width - (width>>1)) - return false; - if (top < 22 || top > _screen.height - (height>>2)) - return false; + if (left < -(width>>2) || left > _screen.width - (width>>1)) return false; + if (top < 22 || top > _screen.height - (height>>2)) return false; // Make sure it is not obscured by any window. for (w = _windows; w != _last_window; w++) { @@ -799,14 +807,16 @@ return w; } +/** Do a search for a window at specific coordinates. For this we start + * at the topmost window, obviously and work our way down to the bottom + * @return a pointer to the found window if any, NULL otherwise */ Window *FindWindowFromPt(int x, int y) { Window *w; for (w = _last_window; w != _windows;) { --w; - if (IS_INSIDE_1D(x, w->left, w->width) && - IS_INSIDE_1D(y, w->top, w->height)) { + if (IS_INSIDE_1D(x, w->left, w->width) && IS_INSIDE_1D(y, w->top, w->height)) { return w; } } @@ -1641,9 +1651,8 @@ w--; if (w->flags4 & WF_WHITE_BORDER_MASK) { w->flags4 -= WF_WHITE_BORDER_ONE; - if (!(w->flags4 & WF_WHITE_BORDER_MASK)) { - SetWindowDirty(w); - } + + if (!(w->flags4 & WF_WHITE_BORDER_MASK)) SetWindowDirty(w); } }
--- a/window.h +++ b/window.h @@ -632,7 +632,7 @@ Window *AllocateWindowDesc(const WindowDesc *desc); Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number); -void DrawWindowViewport(Window *w); +void DrawWindowViewport(const Window *w); /** * Sets the enabled/disabled status of a widget.