summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-11-18 00:14:43 +0000
committerDarkvater <Darkvater@openttd.org>2006-11-18 00:14:43 +0000
commit1a87a33911c26b69a1143709410a7837d84e24cd (patch)
tree75a3954c33043c724e452fafd6ef0b60291b6eb6
parent20cf41522e61a34b97f7f24487dd67231a929bef (diff)
downloadopenttd-1a87a33911c26b69a1143709410a7837d84e24cd.tar.xz
(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)
-rw-r--r--console.c2
-rw-r--r--misc_gui.c19
-rw-r--r--mixer.c9
-rw-r--r--stdafx.h9
-rw-r--r--viewport.c8
-rw-r--r--win32.c4
-rw-r--r--window.c41
-rw-r--r--window.h2
8 files changed, 43 insertions, 51 deletions
diff --git a/console.c b/console.c
index 98f6619b2..6cffe2b6c 100644
--- a/console.c
+++ b/console.c
@@ -296,7 +296,7 @@ void IConsoleResize(void)
_iconsole_win->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
_iconsole_win->width = _screen.width;
break;
- default: break;
+ default: return;
}
MarkWholeScreenDirty();
diff --git a/misc_gui.c b/misc_gui.c
index 2d2429fcf..beb3e4c4e 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -541,7 +541,7 @@ static void ErrmsgWndProc(Window *w, WindowEvent *e)
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 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
_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 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y)
} 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 @@ void DrawEditBox(Window *w, querystr_d *string, int wid)
/* 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);
diff --git a/mixer.c b/mixer.c
index 91390ff73..5b97afbf9 100644
--- a/mixer.c
+++ b/mixer.c
@@ -89,15 +89,6 @@ void MxMixSamples(void *buffer, uint samples)
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)
diff --git a/stdafx.h b/stdafx.h
index 1db6ed38e..e22a2494b 100644
--- 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()
diff --git a/viewport.c b/viewport.c
index 6d6f5cf58..feed484fd 100644
--- a/viewport.c
+++ b/viewport.c
@@ -165,7 +165,7 @@ void AssignWindowViewport(Window *w, int x, int y,
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 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom
// 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 void ViewportDrawChk(ViewPort *vp, int left, int top, int right, int bott
}
}
-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 @@ static inline void ViewportDraw(ViewPort *vp, int left, int top, int right, int
ViewportDrawChk(vp, left, top, right, bottom);
}
-void DrawWindowViewport(Window *w)
+void DrawWindowViewport(const Window *w)
{
DrawPixelInfo *dpi = _cur_dpi;
diff --git a/win32.c b/win32.c
index b8e34c4d5..4a14b65c9 100644
--- a/win32.c
+++ b/win32.c
@@ -637,7 +637,6 @@ static inline void dir_free(DIR *d)
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 @@ DIR *opendir(const char *path)
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 @@ void DeterminePaths(void)
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);
diff --git a/window.c b/window.c
index 5f20555ff..ec3589951 100644
--- a/window.c
+++ b/window.c
@@ -197,7 +197,6 @@ static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
}
}
-
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 DeleteWindowByClass(WindowClass cls)
}
}
-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 @@ void DeletePlayerWindows(PlayerID pi)
}
}
- /* 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 @@ void ChangeWindowOwner(PlayerID old_player, PlayerID new_player)
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 @@ static inline bool IsVitalWindow(const Window *w)
* 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 @@ static Window *LocalAllocateWindow(
}
// 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 @@ static bool IsGoodAutoPlace2(int left, int top)
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 @@ Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number)
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 @@ void UpdateWindows(void)
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);
}
}
diff --git a/window.h b/window.h
index 03f3589bd..9c9f29c74 100644
--- a/window.h
+++ b/window.h
@@ -632,7 +632,7 @@ Window *AllocateWindow(
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.