source: Daodan/src/Daodan_Win32.c@ 983

Last change on this file since 983 was 838, checked in by alloc, 12 years ago

Daodan:

  • Fixes #40
  • Moved configuration parsing (ini, command line) into its own file
File size: 4.3 KB
Line 
1#include <windows.h>
2
3#include "Daodan.h"
4#include "Daodan_Config.h"
5#include "Daodan_Win32.h"
6
7#include "BFW_Utility.h"
8#include "Oni.h"
9
10
11// LIrPlatform_Terminate wrapper. Removes any cursor clipping we've done. Doing
12// this is required for Windows 98 :-D
13void ONICALL DD_LIrPlatform_Terminate(void)
14{
15 ClipCursor(NULL);
16 LIrPlatform_Terminate();
17}
18
19// LIrPlatform_Mode_Set wrapper. Clips cursor to window bounds to
20// prevent loosing focus (mostly on Linux).
21void ONICALL DD_LIrPlatform_Mode_Set(unsigned int active_mode)
22{
23 DDmAssert(ONgPlatformData.Window);
24
25 if (active_mode)
26 {
27 RECT rc;
28 POINT pt;
29
30 pt.x = 0;
31 pt.y = 0;
32
33 if (GetClientRect(ONgPlatformData.Window, &rc) &&
34 ClientToScreen(ONgPlatformData.Window, &pt))
35 {
36 rc.left += pt.x;
37 rc.top += pt.y;
38 rc.right += pt.x;
39 rc.bottom += pt.y;
40
41 ClipCursor(&rc);
42 }
43 }
44 else
45 {
46 ClipCursor(NULL);
47 }
48
49 LIrPlatform_Mode_Set(active_mode);
50}
51
52BOOL WINAPI DD_GetCursorPos(LPPOINT lpPoint)
53{
54 DDmAssert(ONgPlatformData.Window);
55
56 return GetCursorPos(lpPoint) && ScreenToClient(ONgPlatformData.Window, lpPoint);
57}
58
59BOOL WINAPI DD_SetCursorPos(int X, int Y)
60{
61 POINT pt;
62 pt.x = X;
63 pt.y = Y;
64
65 DDmAssert(ONgPlatformData.Window);
66
67 return ClientToScreen(ONgPlatformData.Window, &pt) && SetCursorPos(pt.x, pt.y);
68}
69
70static LRESULT CALLBACK DD_ONrPlatform_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
71{
72 switch (uMsg)
73 {
74 case WM_SYSCOMMAND:
75 if (wParam == SC_SCREENSAVE)
76 {
77 // Prevent screen saver from starting when Oni has focus.
78 return 0;
79 }
80 break;
81
82 case WM_PAINT:
83 {
84 PAINTSTRUCT ps;
85 BeginPaint(hWnd, &ps);
86 // Oni does a useless PatBlt here.
87 EndPaint(hWnd, &ps);
88 return 0;
89 }
90
91 case WM_CLOSE:
92 // There's no way to reliably terminate a modal dialog.
93 // The following condition is (almost) always true.
94 if (WMgActive)
95 exit(0);
96
97 ONgTerminateGame = UUcTrue;
98 return 0;
99
100 case WM_SETCURSOR:
101 // If a mouse is inside our client area, we hide cursor (always),
102 // otherwise we ask DefWindowProc to set an appropriate arrow for us.
103 if (LOWORD(lParam) == HTCLIENT)
104 {
105 SetCursor(NULL);
106 return TRUE;
107 }
108
109 break;
110 }
111
112 return ONrPlatform_WindowProc(hWnd, uMsg, wParam, lParam);
113}
114
115
116UUtError ONICALL DD_ONrPlatform_Initialize(ONtPlatformData *PlatformData)
117{
118 WNDCLASSEX WndClass;
119 RECT Rect;
120 const int Width = 640, Height = 480;
121 DWORD window_style, window_style_ex;
122
123 PlatformData->Instance = ONgInstance;
124 PlatformData->Window = NULL;
125
126 if (FindWindow("ONI ", "ONI "))
127 {
128 AUrMessageBox(1, "Daodan: There is already an instance of the game running.");
129 exit(0);
130 }
131
132 WndClass.cbSize = sizeof(WndClass);
133 WndClass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
134 WndClass.cbClsExtra = 0;
135 WndClass.cbWndExtra = 0;
136 WndClass.hInstance = PlatformData->Instance;
137 WndClass.hCursor = NULL; // To debug: LoadCursor(NULL, IDC_ARROW);
138 WndClass.hIcon = LoadIcon(ONgInstance, MAKEINTRESOURCE(103));
139 WndClass.hIconSm = LoadIcon(ONgInstance, MAKEINTRESOURCE(103));
140 WndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
141 WndClass.lpszMenuName = NULL;
142 WndClass.lpszMenuName = NULL;
143 WndClass.lpszClassName = "ONI ";
144 WndClass.lpfnWndProc = DD_ONrPlatform_WindowProc;
145
146 RegisterClassEx(&WndClass);
147
148 if (M3gResolutionSwitch)
149 {
150 // Do not allow border and topmost flag for a fullscreen window.
151 window_style = WS_POPUP;
152 window_style_ex = 0;
153 }
154 else
155 {
156 window_style = (opt_border) ? WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_DLGFRAME | WS_MINIMIZEBOX : WS_POPUP;
157 window_style_ex = (opt_topmost) ? WS_EX_TOPMOST : 0;
158 }
159
160 Rect.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (Width / 2);
161 Rect.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (Height / 2);
162 Rect.right = Rect.left + Width;
163 Rect.bottom = Rect.top + Height;
164 AdjustWindowRectEx(&Rect, window_style, FALSE, window_style_ex);
165
166 PlatformData->Window = CreateWindowEx(window_style_ex, WndClass.lpszClassName, "ONI ", window_style,
167 Rect.left, Rect.top, Rect.right - Rect.left, Rect.bottom - Rect.top,
168 NULL, NULL, PlatformData->Instance, NULL);
169
170 ShowWindow(PlatformData->Window, SW_SHOWNORMAL);
171 UpdateWindow(PlatformData->Window);
172
173 return UUcError_None;
174 }
175
Note: See TracBrowser for help on using the repository browser.