PCem
view src/win-mouse.cc @ 154:d0d530adce12
Initial port to Linux (using Allegro).
64-bit fixes.
Some changes to aid portability.
A few other tweaks.
| author | TomW |
|---|---|
| date | Thu Sep 04 21:07:24 2014 +0100 |
| parents | 457f666b38c1 |
| children |
line source
1 #define DIRECTINPUT_VERSION 0x0700
2 #include <dinput.h>
3 #include "plat-mouse.h"
4 #include "win.h"
6 extern "C" int video_fullscreen;
8 extern "C" void fatal(const char *format, ...);
9 extern "C" void pclog(const char *format, ...);
11 extern "C" void mouse_init();
12 extern "C" void mouse_close();
13 extern "C" void mouse_poll_host();
14 extern "C" void mouse_get_mickeys(int *x, int *y);
16 static LPDIRECTINPUT lpdi;
17 static LPDIRECTINPUTDEVICE lpdi_mouse = NULL;
18 static DIMOUSESTATE mousestate;
19 static int mouse_x = 0, mouse_y = 0;
20 int mouse_buttons = 0;
22 void mouse_init()
23 {
24 atexit(mouse_close);
26 if (FAILED(DirectInputCreate(hinstance, DIRECTINPUT_VERSION, &lpdi, NULL)))
27 fatal("mouse_init : DirectInputCreate failed\n");
28 if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdi_mouse, NULL)))
29 fatal("mouse_init : CreateDevice failed\n");
30 if (FAILED(lpdi_mouse->SetCooperativeLevel(ghwnd, DISCL_FOREGROUND | (video_fullscreen ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE))))
31 fatal("mouse_init : SetCooperativeLevel failed\n");
32 if (FAILED(lpdi_mouse->SetDataFormat(&c_dfDIMouse)))
33 fatal("mouse_init : SetDataFormat failed\n");
34 if (FAILED(lpdi_mouse->Acquire()))
35 fatal("mouse_init : Acquire failed\n");
36 }
38 void mouse_close()
39 {
40 if (lpdi_mouse)
41 {
42 lpdi_mouse->Release();
43 lpdi_mouse = NULL;
44 }
45 }
47 void mouse_poll_host()
48 {
49 if (FAILED(lpdi_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate)))
50 {
51 lpdi_mouse->Acquire();
52 lpdi_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);
53 }
54 mouse_buttons = 0;
55 if (mousestate.rgbButtons[0] & 0x80)
56 mouse_buttons |= 1;
57 if (mousestate.rgbButtons[1] & 0x80)
58 mouse_buttons |= 2;
59 if (mousestate.rgbButtons[2] & 0x80)
60 mouse_buttons |= 4;
61 mouse_x += mousestate.lX;
62 mouse_y += mousestate.lY;
63 if (!mousecapture && !video_fullscreen)
64 mouse_x = mouse_y = mouse_buttons = 0;
65 }
67 void mouse_get_mickeys(int *x, int *y)
68 {
69 *x = mouse_x;
70 *y = mouse_y;
71 mouse_x = mouse_y = 0;
72 }
