--- a/src/video/win32_v.cpp Wed Jun 13 12:05:56 2007 +0000
+++ b/src/video/win32_v.cpp Tue Jun 19 07:21:01 2007 +0000
@@ -9,6 +9,7 @@
#include "../variables.h"
#include "../win32.h"
#include "../window.h"
+#include "../blitter/factory.hpp"
#include "win32_v.h"
#include <windows.h>
#include <tchar.h>
@@ -16,26 +17,26 @@
static struct {
HWND main_wnd;
HBITMAP dib_sect;
- Pixel *bitmap_bits;
- Pixel *buffer_bits;
- Pixel *alloced_bits;
+ void *buffer_bits;
HPALETTE gdi_palette;
int width;
int height;
int width_org;
int height_org;
+ bool minimized;
bool fullscreen;
- bool double_size;
bool has_focus;
bool running;
} _wnd;
bool _force_full_redraw;
-bool _double_size;
bool _window_maximize;
uint _display_hz;
uint _fullscreen_bpp;
static uint16 _bck_resolution[2];
+#if !defined(WINCE)
+static DEVMODE _fullscreen_dm;
+#endif
#if !defined(UNICODE)
uint _codepage;
#endif
@@ -63,6 +64,10 @@
static void UpdatePalette(HDC dc, uint start, uint count)
{
+ /* We can only update the palette in 8bpp for now */
+ /* TODO -- We need support for other bpps too! */
+ if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() != 8) return;
+
RGBQUAD rgb[256];
uint i;
@@ -136,11 +141,6 @@
static void ClientSizeChanged(int w, int h)
{
- if (_wnd.double_size) {
- w /= 2;
- h /= 2;
- }
-
// allocate new dib section of the new size
if (AllocateDibSection(w, h)) {
// mark all palette colors dirty
@@ -319,11 +319,6 @@
DrawMouseCursor();
}
- if (_wnd.double_size) {
- x /= 2;
- y /= 2;
- }
-
if (_cursor.fix_at) {
int dx = x - _cursor.pos.x;
int dy = y - _cursor.pos.y;
@@ -334,10 +329,6 @@
pt.x = _cursor.pos.x;
pt.y = _cursor.pos.y;
- if (_wnd.double_size) {
- pt.x *= 2;
- pt.y *= 2;
- }
ClientToScreen(hwnd, &pt);
SetCursorPos(pt.x, pt.y);
}
@@ -400,13 +391,6 @@
* WM_KEYDOWN only handles CTRL+ commands and special keys like VK_LEFT, etc. */
if (keycode == 0 || (keycode > WKC_PAUSE && GB(keycode, 13, 4) == 0)) return 0;
- if (keycode == ('D' | WKC_CTRL) && !_wnd.fullscreen) {
- _double_size ^= 1;
- _wnd.double_size = _double_size;
- ClientSizeChanged(_wnd.width, _wnd.height);
- MarkWholeScreenDirty();
- }
-
HandleKeypress(0 | (keycode << 16));
return 0;
}
@@ -432,7 +416,8 @@
break;
case WM_SIZE:
- if (wParam != SIZE_MINIMIZED) {
+ _wnd.minimized = (wParam == SIZE_MINIMIZED);
+ if (!_wnd.minimized) {
/* Set maximized flag when we maximize (obviously), but also when we
* switched to fullscreen from a maximized state */
_window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
@@ -455,16 +440,8 @@
w = r->right - r->left - (r2.right - r2.left);
h = r->bottom - r->top - (r2.bottom - r2.top);
- if (_wnd.double_size) {
- w /= 2;
- h /= 2;
- }
w = clamp(w, 64, MAX_SCREEN_WIDTH);
h = clamp(h, 64, MAX_SCREEN_HEIGHT);
- if (_wnd.double_size) {
- w *= 2;
- h *= 2;
- }
SetRect(&r2, 0, 0, w, h);
AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
@@ -534,6 +511,21 @@
case WM_ACTIVATEAPP:
_wnd.has_focus = (wParam != 0);
+#if !defined(WINCE)
+ if (_wnd.fullscreen) {
+ if (_wnd.has_focus && _wnd.minimized) {
+ /* Restore the game window */
+ ShowWindow(hwnd, SW_RESTORE);
+ ChangeDisplaySettings(&_fullscreen_dm, CDS_FULLSCREEN);
+ /* Force palette update */
+ SendMessage(hwnd, WM_QUERYNEWPALETTE, 0, 0);
+ } else if (!_wnd.has_focus && !_wnd.minimized) {
+ /* Minimise the window and restore desktop */
+ ShowWindow(hwnd, SW_MINIMIZE);
+ ChangeDisplaySettings(NULL, 0);
+ }
+ }
+#endif
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
@@ -567,8 +559,6 @@
{
_fullscreen = full_screen;
- _wnd.double_size = _double_size && !full_screen;
-
// recreate window?
if ((full_screen || _wnd.fullscreen) && _wnd.main_wnd) {
DestroyWindow(_wnd.main_wnd);
@@ -579,21 +569,22 @@
/* WinCE is always fullscreen */
#else
if (full_screen) {
- DEVMODE settings;
+ /* Make sure we are always at least the screen-depth of the blitter */
+ if (_fullscreen_bpp < BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) _fullscreen_bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
- memset(&settings, 0, sizeof(settings));
- settings.dmSize = sizeof(settings);
- settings.dmFields =
+ memset(&_fullscreen_dm, 0, sizeof(_fullscreen_dm));
+ _fullscreen_dm.dmSize = sizeof(_fullscreen_dm);
+ _fullscreen_dm.dmFields =
(_fullscreen_bpp != 0 ? DM_BITSPERPEL : 0) |
DM_PELSWIDTH |
DM_PELSHEIGHT |
(_display_hz != 0 ? DM_DISPLAYFREQUENCY : 0);
- settings.dmBitsPerPel = _fullscreen_bpp;
- settings.dmPelsWidth = _wnd.width_org;
- settings.dmPelsHeight = _wnd.height_org;
- settings.dmDisplayFrequency = _display_hz;
+ _fullscreen_dm.dmBitsPerPel = _fullscreen_bpp;
+ _fullscreen_dm.dmPelsWidth = _wnd.width_org;
+ _fullscreen_dm.dmPelsHeight = _wnd.height_org;
+ _fullscreen_dm.dmDisplayFrequency = _display_hz;
- if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
+ if (ChangeDisplaySettings(&_fullscreen_dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
MakeWindow(false);
return;
}
@@ -649,49 +640,37 @@
{
BITMAPINFO *bi;
HDC dc;
+ int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
w = clamp(w, 64, MAX_SCREEN_WIDTH);
h = clamp(h, 64, MAX_SCREEN_HEIGHT);
+ if (bpp == 0) error("Can't use a blitter that blits 0 bpp for normal visuals");
+
if (w == _screen.width && h == _screen.height)
return false;
_screen.width = w;
_screen.pitch = ALIGN(w, 4);
_screen.height = h;
-
- if (_wnd.alloced_bits) {
- free(_wnd.alloced_bits);
- _wnd.alloced_bits = NULL;
- }
-
bi = (BITMAPINFO*)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- if (_wnd.double_size) {
- w = ALIGN(w, 4);
- _wnd.alloced_bits = _wnd.buffer_bits = (Pixel *)malloc(w * h * sizeof(Pixel));
- w *= 2;
- h *= 2;
- }
-
bi->bmiHeader.biWidth = _wnd.width = w;
bi->bmiHeader.biHeight = -(_wnd.height = h);
bi->bmiHeader.biPlanes = 1;
- bi->bmiHeader.biBitCount = 8;
+ bi->bmiHeader.biBitCount = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
bi->bmiHeader.biCompression = BI_RGB;
if (_wnd.dib_sect) DeleteObject(_wnd.dib_sect);
dc = GetDC(0);
- _wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.bitmap_bits, NULL, 0);
+ _wnd.dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID**)&_wnd.buffer_bits, NULL, 0);
if (_wnd.dib_sect == NULL) error("CreateDIBSection failed");
ReleaseDC(0, dc);
- if (!_wnd.double_size) _wnd.buffer_bits = _wnd.bitmap_bits;
-
return true;
}
@@ -723,7 +702,7 @@
* Doesn't really matter since we don't pass a string anyways, but still
* a letdown */
for (i = 0; EnumDisplaySettingsA(NULL, i, &dm) != 0; i++) {
- if (dm.dmBitsPerPel == 8 && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
+ if (dm.dmBitsPerPel == BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() && IS_INT_INSIDE(dm.dmPelsWidth, 640, MAX_SCREEN_WIDTH + 1) &&
IS_INT_INSIDE(dm.dmPelsHeight, 480, MAX_SCREEN_HEIGHT + 1)) {
uint j;
@@ -786,43 +765,13 @@
#if !defined(WINCE)
if (_wnd.fullscreen) ChangeDisplaySettings(NULL, 0);
#endif
- if (_wnd.double_size) {
- _cur_resolution[0] *= 2;
- _cur_resolution[1] *= 2;
- }
-
MyShowCursor(true);
}
-// simple upscaler by 2
-static void filter(int left, int top, int width, int height)
-{
- uint p = _screen.pitch;
- const Pixel *s = _wnd.buffer_bits + top * p + left;
- Pixel *d = _wnd.bitmap_bits + top * p * 4 + left * 2;
-
- for (; height > 0; height--) {
- int i;
-
- for (i = 0; i != width; i++) {
- d[i * 2] = d[i * 2 + 1] = d[i * 2 + p * 2] = d[i * 2 + 1 + p * 2] = s[i];
- }
- s += p;
- d += p * 4;
- }
-}
-
static void Win32GdiMakeDirty(int left, int top, int width, int height)
{
RECT r = { left, top, left + width, top + height };
- if (_wnd.double_size) {
- filter(left, top, width, height);
- r.left *= 2;
- r.top *= 2;
- r.right *= 2;
- r.bottom *= 2;
- }
InvalidateRect(_wnd.main_wnd, &r, FALSE);
}