1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "device/keys.hh"
|
---|
10 | #include "device/event.hh"
|
---|
11 | #include "device/kernel.hh"
|
---|
12 | #include "main/win_main.hh"
|
---|
13 |
|
---|
14 | #include "video/win32/win32_input.hh"
|
---|
15 | #include "video/display.hh"
|
---|
16 | #include "image/context.hh"
|
---|
17 |
|
---|
18 | class gdi_input : public win32_input_class
|
---|
19 | {
|
---|
20 | public:
|
---|
21 | gdi_input() : win32_input_class(0) {}
|
---|
22 | virtual void redraw(int x1, int y1, int x2, int y2);
|
---|
23 | virtual void resize(sw32 w, sw32 h);
|
---|
24 | };
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 | // void win32_display_class::get_desktop_format(i4_pixel_format &fmt)
|
---|
29 | // {
|
---|
30 |
|
---|
31 | // save = GetPixel(hdc,0,0);
|
---|
32 | // SetPixel(hdc,0,0,RGB(0x08,0x08,0x08));
|
---|
33 | // color = GetPixel(hdc,0,0) & 0xffffff;
|
---|
34 |
|
---|
35 | // switch (color)
|
---|
36 | // {
|
---|
37 | // //
|
---|
38 | // // 0x000000 = 5-5-5
|
---|
39 | // //
|
---|
40 |
|
---|
41 | // case 0x000000:
|
---|
42 |
|
---|
43 | // desktop_R_bitmask = 0x007c00;
|
---|
44 | // desktop_G_bitmask = 0x0003e0;
|
---|
45 | // desktop_B_bitmask = 0x00001f;
|
---|
46 | // break;
|
---|
47 |
|
---|
48 | // //
|
---|
49 | // // 0x000800 = 5-6-5
|
---|
50 | // //
|
---|
51 |
|
---|
52 | // case 0x000800:
|
---|
53 |
|
---|
54 | // desktop_R_bitmask = 0x00f800;
|
---|
55 | // desktop_G_bitmask = 0x0007e0;
|
---|
56 | // desktop_B_bitmask = 0x00001f;
|
---|
57 | // break;
|
---|
58 |
|
---|
59 | // //
|
---|
60 | // // 0x080808 = 8-8-8
|
---|
61 | // //
|
---|
62 |
|
---|
63 | // case 0x080808:
|
---|
64 |
|
---|
65 | // desktop_R_bitmask = 0xff0000;
|
---|
66 | // desktop_G_bitmask = 0x00ff00;
|
---|
67 | // desktop_B_bitmask = 0x0000ff;
|
---|
68 | // break;
|
---|
69 |
|
---|
70 | // default:
|
---|
71 |
|
---|
72 | // if ((desktop_bpp == 15) || (desktop_bpp == 16))
|
---|
73 | // {
|
---|
74 | // desktop_R_bitmask = 0x00f800;
|
---|
75 | // desktop_G_bitmask = 0x0007e0;
|
---|
76 | // desktop_B_bitmask = 0x00001f;
|
---|
77 | // }
|
---|
78 | // break;
|
---|
79 | // }
|
---|
80 |
|
---|
81 | // SetPixel(hdc,0,0,save);
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | class win32_display_class : public i4_display_class
|
---|
86 | {
|
---|
87 | public:
|
---|
88 | gdi_input input;
|
---|
89 |
|
---|
90 | i4_draw_context_class *context;
|
---|
91 | i4_image_class *backbuf;
|
---|
92 | HBITMAP bitmap;
|
---|
93 |
|
---|
94 | i4_image_class *get_screen() { return backbuf; }
|
---|
95 | i4_draw_context_class *get_context() { return context; }
|
---|
96 |
|
---|
97 | virtual i4_image_class *create_image(int w, int h, i4_bool in_vram, const i4_pal *pal)
|
---|
98 | {
|
---|
99 | return i4_create_image(w,h,pal);
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | void flush()
|
---|
104 | {
|
---|
105 | PAINTSTRUCT paint_s;
|
---|
106 | HDC dc;
|
---|
107 | dc=GetDC(input.get_window_handle());
|
---|
108 |
|
---|
109 |
|
---|
110 | SelectObject(dc,bitmap);
|
---|
111 |
|
---|
112 | HDC hdcMem = CreateCompatibleDC(dc);
|
---|
113 | bitmap = SelectObject(hdcMem,bitmap);
|
---|
114 |
|
---|
115 |
|
---|
116 | for (i4_rect_list_class::area_iter a=context->single_dirty->list.begin();
|
---|
117 | a!=context->single_dirty->list.end();
|
---|
118 | ++a)
|
---|
119 | context->both_dirty->add_area(a->x1, a->y1, a->x2, a->y2);
|
---|
120 |
|
---|
121 | context->single_dirty->delete_list();
|
---|
122 |
|
---|
123 | context->both_dirty->intersect_area(0,0,width()-1,height()-1);
|
---|
124 |
|
---|
125 |
|
---|
126 |
|
---|
127 | a=context->both_dirty->list.begin();
|
---|
128 | for (;a!=context->both_dirty->list.end();++a)
|
---|
129 | BitBlt(dc,a->x1,a->y1,
|
---|
130 | a->x2-a->x1+1,a->y2-a->y1+1,
|
---|
131 | hdcMem,a->x1,a->y1,SRCCOPY);
|
---|
132 |
|
---|
133 | // this is to reduce the flicker of the mouse cursor
|
---|
134 | POINT p;
|
---|
135 | GetCursorPos(&p);
|
---|
136 | SetCursorPos(p.x, p.y);
|
---|
137 |
|
---|
138 | context->both_dirty->delete_list();
|
---|
139 | bitmap = SelectObject(hdcMem,bitmap); // windows says to do this
|
---|
140 |
|
---|
141 | DeleteDC(hdcMem);
|
---|
142 |
|
---|
143 | ReleaseDC(input.get_window_handle(), dc);
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | w16 width() const { return backbuf->width(); }
|
---|
149 | w16 height() const { return backbuf->height(); }
|
---|
150 |
|
---|
151 |
|
---|
152 | i4_display_class::mode cur_mode, tmp_mode;
|
---|
153 |
|
---|
154 | i4_display_class::mode *current_mode() { return &cur_mode; }
|
---|
155 |
|
---|
156 |
|
---|
157 | i4_display_class::mode *get_first_mode(int driver_id)
|
---|
158 | {
|
---|
159 | strcpy(tmp_mode.name, "GDI window");
|
---|
160 | tmp_mode.flags=mode::BACK_BUFFER | mode::RESOLUTION_DETERMINED_ON_OPEN;
|
---|
161 | tmp_mode.xres=tmp_mode.yres=0;
|
---|
162 |
|
---|
163 | tmp_mode.bits_per_pixel=16;
|
---|
164 | tmp_mode.red_mask=31<<10;
|
---|
165 | tmp_mode.green_mask=31<<5;
|
---|
166 | tmp_mode.blue_mask=31<<0;
|
---|
167 |
|
---|
168 | return &tmp_mode;
|
---|
169 | }
|
---|
170 |
|
---|
171 | virtual mode *get_next_mode() { return 0; }
|
---|
172 |
|
---|
173 | i4_image_class *lock_frame_buffer(i4_frame_buffer_type type,
|
---|
174 | i4_frame_access_type access)
|
---|
175 | {
|
---|
176 | return backbuf;
|
---|
177 | }
|
---|
178 |
|
---|
179 | void unlock_frame_buffer(i4_frame_buffer_type type) { ; }
|
---|
180 |
|
---|
181 | i4_bool create_bmp(int w, int h)
|
---|
182 | {
|
---|
183 | cur_mode.xres=w;
|
---|
184 | cur_mode.xres=h;
|
---|
185 |
|
---|
186 | if (context)
|
---|
187 | delete context;
|
---|
188 | context=new i4_draw_context_class(0,0, w-1, h-1);
|
---|
189 | context->both_dirty=new i4_rect_list_class;
|
---|
190 | context->single_dirty=new i4_rect_list_class;
|
---|
191 |
|
---|
192 | HDC dc=GetDC(input.get_window_handle());
|
---|
193 |
|
---|
194 | BITMAPINFOHEADER bmp;
|
---|
195 | memset(&bmp, 0, sizeof(bmp));
|
---|
196 | bmp.biSize=sizeof(bmp);
|
---|
197 |
|
---|
198 | bmp.biWidth=w;
|
---|
199 | bmp.biHeight=-h;
|
---|
200 | bmp.biPlanes=1;
|
---|
201 | bmp.biBitCount=16;
|
---|
202 | bmp.biCompression=BI_RGB;
|
---|
203 | bmp.biSizeImage=w*h*2;
|
---|
204 |
|
---|
205 | BITMAPINFO bmp_info;
|
---|
206 | memcpy(&bmp_info, &bmp, sizeof(bmp));
|
---|
207 |
|
---|
208 | void *data_address;
|
---|
209 |
|
---|
210 | bitmap=CreateDIBSection(dc,
|
---|
211 | &bmp_info, DIB_RGB_COLORS,
|
---|
212 | &data_address, // where bitmap's data will be stored
|
---|
213 | 0, // don't use a file
|
---|
214 | 0);
|
---|
215 |
|
---|
216 | backbuf->w=w;
|
---|
217 | backbuf->bpl=w*2;
|
---|
218 | backbuf->h=h;
|
---|
219 | backbuf->data=data_address;
|
---|
220 |
|
---|
221 | if (!bitmap)
|
---|
222 | {
|
---|
223 | i4_warning("Error CreateDIBSection failed!");
|
---|
224 | input.destroy_window();
|
---|
225 | return i4_F;
|
---|
226 | }
|
---|
227 |
|
---|
228 | return i4_T;
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 | i4_bool initialize_mode()
|
---|
233 | {
|
---|
234 | memcpy(&cur_mode, &tmp_mode, sizeof(tmp_mode));
|
---|
235 | if (!input.create_window(0,0, cur_mode.xres, cur_mode.yres, this, i4_F))
|
---|
236 | return i4_F;
|
---|
237 |
|
---|
238 | int x,y,w,h;
|
---|
239 | input.get_window_area(x,y,w,h);
|
---|
240 | cur_mode.xres=w;
|
---|
241 | cur_mode.yres=h;
|
---|
242 |
|
---|
243 |
|
---|
244 | i4_pixel_format fmt;
|
---|
245 | fmt.red_mask=cur_mode.red_mask;
|
---|
246 | fmt.green_mask=cur_mode.green_mask;
|
---|
247 | fmt.blue_mask=cur_mode.blue_mask;
|
---|
248 | fmt.alpha_mask=0;
|
---|
249 | fmt.pixel_depth=I4_16BIT;
|
---|
250 | fmt.calc_shift();
|
---|
251 |
|
---|
252 | pal=i4_pal_man.register_pal(&fmt);
|
---|
253 | backbuf=i4_create_image(cur_mode.xres, cur_mode.yres, pal,
|
---|
254 | 0, cur_mode.xres*2);
|
---|
255 |
|
---|
256 | return create_bmp(cur_mode.xres, cur_mode.yres);
|
---|
257 | }
|
---|
258 |
|
---|
259 | i4_bool close()
|
---|
260 | {
|
---|
261 | if (backbuf)
|
---|
262 | {
|
---|
263 | input.destroy_window();
|
---|
264 | delete backbuf;
|
---|
265 | DeleteObject(bitmap);
|
---|
266 | delete context;
|
---|
267 | return i4_T;
|
---|
268 | }
|
---|
269 |
|
---|
270 |
|
---|
271 | return i4_F;
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 | virtual i4_bool set_mouse_shape(i4_cursor_class *cursor) { return i4_F; }
|
---|
277 |
|
---|
278 |
|
---|
279 | virtual i4_bool display_busy() const { return i4_F; }
|
---|
280 |
|
---|
281 | win32_display_class()
|
---|
282 | {
|
---|
283 | backbuf=0;
|
---|
284 | context=0;
|
---|
285 | }
|
---|
286 |
|
---|
287 | void init()
|
---|
288 | {
|
---|
289 | i4_display_list_struct *s=new i4_display_list_struct;
|
---|
290 | s->add_to_list("Windowed GDI", 0, this, i4_display_list);
|
---|
291 | }
|
---|
292 |
|
---|
293 | virtual i4_refresh_type update_model() { return I4_BLT_REFRESH; }
|
---|
294 | virtual i4_bool lock_mouse_in_place(i4_bool yes_no) { return i4_F; }
|
---|
295 | };
|
---|
296 |
|
---|
297 | win32_display_class win32_display_instance;
|
---|
298 |
|
---|
299 |
|
---|
300 | void gdi_input::redraw(int x1, int y1, int x2, int y2)
|
---|
301 | {
|
---|
302 | if (win32_display_instance.backbuf)
|
---|
303 | win32_display_instance.context->both_dirty->add_area(x1,y1,x2,y2);
|
---|
304 | }
|
---|
305 |
|
---|
306 | void gdi_input::resize(sw32 w, sw32 h)
|
---|
307 | {
|
---|
308 | if (win32_display_instance.backbuf)
|
---|
309 | {
|
---|
310 | w=(w+3)&(~3);
|
---|
311 | win32_display_class *wi=&win32_display_instance;
|
---|
312 | DeleteObject(wi->bitmap);
|
---|
313 | wi->create_bmp(w,h);
|
---|
314 | }
|
---|
315 | }
|
---|