Update of /cvsroot/netrek/client/netrekxp/src In directory sc8-pr-cvs16:/tmp/cvs-serv8621/src Modified Files: data.c defaults.c local.c map.c mswindow.c Log Message: This patch adds the ability to resize local/map windows on the fly, and fixes some of the problems that came up while doing this. Added code to WM_EXITSIZEMOVE case in main windows proc, that handles changing TWINSIDE/GWINSIDE, reinitializing things that need it (such as SDB and star array), and changing critical window sizes that need to be redone (team select windows, quit window - both based on TWINSIDE). Netrekrc option mainResizeable now allows local/map to be resized too, giving these windows a WS_THICKFRAME border. Variable redrawall and struct stars are now globally defined. New defines to limit # of star sectors and # of stars in a sector. Fixed a bunch of places where view was statically defined, as TWINSIDE can now change during gameplay. Fixed a few places where rounding errors were occuring due to parentheses. Moved initialization of mainResizeable and mainTitleBar into defaults.c as defaults are now called before windows initialization. Fixed a few mistakes in the free resources routine for SDB. Index: mswindow.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/mswindow.c,v retrieving revision 1.58 retrieving revision 1.59 diff -u -d -r1.58 -r1.59 --- mswindow.c 8 Apr 2007 22:36:41 -0000 1.58 +++ mswindow.c 9 Apr 2007 02:52:31 -0000 1.59 @@ -640,11 +640,13 @@ SelectObject (localSDB->mem_dc, localSDB->old_bmp); DeleteObject (localSDB->mem_bmp); ReleaseDC (((Window *)localSDB->window)->hwnd, localSDB->win_dc); + DeleteDC (localSDB->mem_dc); free (localSDB); SelectObject (mapSDB->mem_dc, mapSDB->old_bmp); DeleteObject (mapSDB->mem_bmp); - DeleteDC (mapSDB->win_dc); + ReleaseDC (((Window *)mapSDB->window)->hwnd, mapSDB->win_dc); + DeleteDC (mapSDB->mem_dc); free (mapSDB); //WinKey Kill Library Stop @@ -1137,8 +1139,6 @@ sprintf (title_buff, "Netrek @ %s", serverName); } // WS_THICKFRAME adds resizing frame to window without adding titlebar - mainResizeable = booleanDefault ("mainResizeable", mainResizeable); - mainTitleBar = booleanDefault ("mainTitleBar", mainTitleBar); SpecialStyle |= WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU; if (mainResizeable) SpecialStyle |= WS_THICKFRAME; @@ -1166,6 +1166,12 @@ WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; parentwin = &myroot; } + else if (strncmp (name, "local", 5) == 0 || strncmp (name, "map", 3) == 0) + { + s = name; + if (mainResizeable) + SpecialStyle = WS_THICKFRAME; + } else s = name; @@ -1960,6 +1966,57 @@ //Disable possibility to move internal windows GET_STRUCT_PTR; + // Adjust TWINSIDE and GWINSIDE + // Reinitialize whatever is necessary (so many things are created based on + // a fixed TWINSIDE) + // Redo critical windows + // Clear window + if (windowMove && (Window *) w != NULL && win->hwnd == ((Window *) w)->hwnd) + { + TWINSIDE = MAX(win->ClipRect.bottom, win->ClipRect.right); + + // Have to reinitialize SDB + SelectObject (localSDB->mem_dc, localSDB->old_bmp); + DeleteObject (localSDB->mem_bmp); + ReleaseDC (((Window *)localSDB->window)->hwnd, localSDB->win_dc); + DeleteDC (localSDB->mem_dc); + free (localSDB); + localSDB = W_InitSDB (w); + // and stars + free (stars); + initStars(); + + // All windows based on TWINSIDE are out of position now, but the team + // select/quit windows are now the wrong size too, so we need to redo them + for (i = 0; i < 4; i++) + { + W_UnmapWindow (teamWin[i]); + teamWin[i] = W_MakeWindow (teamshort[1 << i], i * (TWINSIDE / 5), TWINSIDE - (TWINSIDE / 5), + (TWINSIDE / 5), (TWINSIDE / 5), w, 1, foreColor); + } + W_UnmapWindow (qwin); + qwin = W_MakeWindow ("quit", 4 * (TWINSIDE / 5), TWINSIDE - (TWINSIDE / 5), (TWINSIDE / 5), + (TWINSIDE / 5), w, 1, foreColor); + + W_FastClear = 1; + if (viewBox) + redrawall = 1; + } + else if (windowMove && (Window *) mapw != NULL && win->hwnd == ((Window *) mapw)->hwnd) + { + GWINSIDE = MAX(win->ClipRect.bottom, win->ClipRect.right); + + // Have to reinitialize SDB + SelectObject (mapSDB->mem_dc, mapSDB->old_bmp); + DeleteObject (mapSDB->mem_bmp); + ReleaseDC (((Window *)mapSDB->window)->hwnd, mapSDB->win_dc); + DeleteDC (mapSDB->mem_dc); + free (mapSDB); + mapSDB = W_InitSDB (mapw); + + redrawall = 1; + } + /* this has to be the same as for WM_ENTERSIZEMOVE */ if (windowMove || (win->hwnd == ((Window *) baseWin)->hwnd) || Index: local.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/local.c,v retrieving revision 1.89 retrieving revision 1.90 diff -u -d -r1.89 -r1.90 --- local.c 7 Apr 2007 11:35:27 -0000 1.89 +++ local.c 9 Apr 2007 02:52:31 -0000 1.90 @@ -58,12 +58,6 @@ static int cloak_phases = 0; #endif -/* Background Stars Definitions */ -struct _star { - int s_x, s_y; - int s_color; -}; - static void redrawStarSector(int sectorx, int sectory); #define scaleLocal(pt) ((pt)/scaleFactor + (TWINSIDE/2)) @@ -73,8 +67,6 @@ /* Max range at which other's torps can be seen, used in scaling sound volume */ #define SOUND_MAXRANGE (int)(sqrt)(INFORANGE * INFORANGE/2) -static struct _star stars[10][10][16]; - /* Function Defininitions */ #ifdef SOUND @@ -130,11 +122,22 @@ initStars() { register int i, j, k; + int imax, jmax, kmax; + + imax = 5 * STARSIDE / TWINSIDE + 1; + if (imax > MAXSECTORS) + imax = MAXSECTORS; + jmax = 5 * STARSIDE / TWINSIDE + 1; + if (jmax > MAXSECTORS) + jmax = MAXSECTORS; + kmax = 16 * TWINSIDE / STARSIDE * TWINSIDE / STARSIDE; + if (kmax > MAXSTARS) + kmax = MAXSTARS; /* Star density: 16 stars per 20000 x 20000 galactic region */ - for (i = 0; i < (5 * STARSIDE / TWINSIDE + 1); i++) { - for (j = 0; j < (5 * STARSIDE / TWINSIDE + 1); j++) { - for (k = 0; k < (16 * (TWINSIDE / STARSIDE) * (TWINSIDE / STARSIDE)); k++) { + for (i = 0; i < imax; i++) { + for (j = 0; j < jmax; j++) { + for (k = 0; k < kmax; k++) { stars[i][j][k].s_x = RANDOM() % 20000 * TWINSIDE / STARSIDE; stars[i][j][k].s_y = RANDOM() % 20000 * TWINSIDE / STARSIDE; stars[i][j][k].s_color = randcolor(); @@ -147,8 +150,8 @@ void DrawStars() { - const int fullview = TWINSIDE * SCALE; - const int view = TWINSIDE * SCALE / 2; + int fullview = TWINSIDE * SCALE; + int view = TWINSIDE * SCALE / 2; /* note: cpp symbols in expressions (TWINSIDE*SCALE) will be precalculated by any C optimizer @@ -239,8 +242,8 @@ static void redrawStarSector (int sectorx, int sectory) { - const int fullview = TWINSIDE * SCALE; - const int view = TWINSIDE * SCALE / 2; + int fullview = TWINSIDE * SCALE; + int view = TWINSIDE * SCALE / 2; register int i, dx, dy, dxx, dyy; register int xbase = sectorx * fullview; register int ybase = sectory * fullview; @@ -300,7 +303,7 @@ } dxx = (int) (Cos[mydir] * streaklength / 10); dyy = (int) (Sin[mydir] * streaklength / 10); - for (i = 0, s = star_sector; i < (16 * (TWINSIDE / STARSIDE) * (TWINSIDE / STARSIDE)); i++, s++) + for (i = 0, s = star_sector; i < (16 * TWINSIDE / STARSIDE * TWINSIDE / STARSIDE); i++, s++) { if (s->s_x + xbase > GWIDTH || s->s_y + ybase > GWIDTH) continue; @@ -323,7 +326,7 @@ return; } } - for (i = 0, s = star_sector; i < (16 * (TWINSIDE / STARSIDE) * (TWINSIDE / STARSIDE)); i++, s++) + for (i = 0, s = star_sector; i < (16 * TWINSIDE / STARSIDE * TWINSIDE / STARSIDE); i++, s++) { if (s->s_x + xbase > GWIDTH || s->s_y + ybase > GWIDTH) continue; @@ -523,7 +526,7 @@ { register int dx, dy; register struct planet *l; - const int view = scaleFactor * TWINSIDE / 2 + BMP_PLANET_WIDTH * SCALE / 2; + int view = scaleFactor * TWINSIDE / 2 + BMP_PLANET_WIDTH * SCALE / 2; for (l = planets + MAXPLANETS - 1; l >= planets; --l) { @@ -704,7 +707,7 @@ int buflen = 1; static int ph_col = 0; static int scaled_ph_col = 0; - const int view = scaleFactor * TWINSIDE / 2 + BMP_SHIELD_WIDTH * SCALE / 2; + int view = scaleFactor * TWINSIDE / 2 + BMP_SHIELD_WIDTH * SCALE / 2; int dx, dy, px, py, wx, wy, tx, ty, lx, ly; int new_dx, new_dy; int startx, starty, endx, endy; @@ -1919,7 +1922,7 @@ int torpCount; int torpTeam; int frame; - const int view = scaleFactor * TWINSIDE / 2; + int view = scaleFactor * TWINSIDE / 2; for (t = torps, j = players; j != players + MAXPLAYER; t += MAXTORP, ++j) { @@ -2157,7 +2160,7 @@ { register struct plasmatorp *pt; register int dx, dy; - const int view = scaleFactor * TWINSIDE / 2; + int view = scaleFactor * TWINSIDE / 2; int ptorpTeam; int frame; @@ -2381,11 +2384,11 @@ { register struct player *j; register int dx, dy; - const int view = scaleFactor * TWINSIDE / 2; + int view = scaleFactor * TWINSIDE / 2; #ifdef HOCKEY_LINES register struct s_line *sl; - const int HALF_WINSIDE = TWINSIDE / 2; + int HALF_WINSIDE = TWINSIDE / 2; int ex, ey, sx, sy; #endif @@ -2459,10 +2462,10 @@ if ( infoRange && TWINSIDE > (INFORANGE * SCALE / scaleFactor) && !(me->p_x < 0 || me->p_x > GWIDTH)) { - const int LEFT = (TWINSIDE / 2) - (INFORANGE / 2) * SCALE / scaleFactor; - const int RIGHT = (TWINSIDE / 2) + (INFORANGE / 2) * SCALE / scaleFactor; - const int TOP = (TWINSIDE / 2) - (INFORANGE / 2) * SCALE / scaleFactor; - const int BOTTOM = (TWINSIDE / 2) + (INFORANGE / 2) * SCALE / scaleFactor; + int LEFT = (TWINSIDE / 2) - (INFORANGE / 2) * SCALE / scaleFactor; + int RIGHT = (TWINSIDE / 2) + (INFORANGE / 2) * SCALE / scaleFactor; + int TOP = (TWINSIDE / 2) - (INFORANGE / 2) * SCALE / scaleFactor; + int BOTTOM = (TWINSIDE / 2) + (INFORANGE / 2) * SCALE / scaleFactor; long dist; Index: defaults.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/defaults.c,v retrieving revision 1.71 retrieving revision 1.72 diff -u -d -r1.71 -r1.72 --- defaults.c 7 Apr 2007 05:43:26 -0000 1.71 +++ defaults.c 9 Apr 2007 02:52:31 -0000 1.72 @@ -258,7 +258,7 @@ }, {"mainResizeable", &mainResizeable, RC_BOOL, { - "Make main window resizeable", + "Make main window + local/map windows resizeable", NULL } }, @@ -1673,6 +1673,8 @@ timerType = T_SHIP; doubleBuffering = booleanDefault ("doubleBuffering", doubleBuffering); + mainResizeable = booleanDefault ("mainResizeable", mainResizeable); + mainTitleBar = booleanDefault ("mainTitleBar", mainTitleBar); allowWheelActions = booleanDefault ("allowWheelActions", allowWheelActions); richText = booleanDefault ("richText", richText); newQuit = booleanDefault ("newQuit", newQuit); Index: data.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v retrieving revision 1.80 retrieving revision 1.81 diff -u -d -r1.80 -r1.81 --- data.c 7 Apr 2007 05:17:38 -0000 1.80 +++ data.c 9 Apr 2007 02:52:31 -0000 1.81 @@ -31,6 +31,7 @@ struct message *messages; struct mctl *mctl; struct memory universe; +struct _star stars[MAXSECTORS][MAXSECTORS][MAXSTARS]; int TWINSIDE = 500; /* Size of tactical window */ int GWINSIDE = 500; /* Size of galactic window */ @@ -97,6 +98,7 @@ time_t rdelay = 0; /* time stamp for refitting */ time_t tdelay = 0; /* time stamp for T mode extension */ int showPlanetNames = 1; +int redrawall = 1; int autoQuit = 60; int showStats = 0; int showHints = 1; Index: map.c =================================================================== RCS file: /cvsroot/netrek/client/netrekxp/src/map.c,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- map.c 8 Apr 2007 22:36:41 -0000 1.46 +++ map.c 9 Apr 2007 02:52:31 -0000 1.47 @@ -69,13 +69,10 @@ /* * Global Variables: * - * redrawall -- Erase and redraw the galactic? Must be true - * on first map() call. * redrawPlayer[] -- Flag for each player on whether their position * on the galactic is not out of date. */ -int redrawall = 1; unsigned char redrawPlayer[MAXPLAYER];