PCem

view src/win-mouse.cc @ 124:457f666b38c1

Keyboard now uses raw input. Should fix international keyboard. Based on patch from Battler.
author TomW
date Fri Jul 11 20:35:37 2014 +0100
parents f85939140905
children d0d530adce12
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 poll_mouse();
14 extern "C" void position_mouse(int x, int y);
15 extern "C" void get_mouse_mickeys(int *x, int *y);
17 static LPDIRECTINPUT lpdi;
18 static LPDIRECTINPUTDEVICE lpdi_mouse = NULL;
19 static DIMOUSESTATE mousestate;
20 static int mouse_x = 0, mouse_y = 0;
21 int mouse_b = 0;
23 void mouse_init()
24 {
25 atexit(mouse_close);
27 if (FAILED(DirectInputCreate(hinstance, DIRECTINPUT_VERSION, &lpdi, NULL)))
28 fatal("mouse_init : DirectInputCreate failed\n");
29 if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdi_mouse, NULL)))
30 fatal("mouse_init : CreateDevice failed\n");
31 if (FAILED(lpdi_mouse->SetCooperativeLevel(ghwnd, DISCL_FOREGROUND | (video_fullscreen ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE))))
32 fatal("mouse_init : SetCooperativeLevel failed\n");
33 if (FAILED(lpdi_mouse->SetDataFormat(&c_dfDIMouse)))
34 fatal("mouse_init : SetDataFormat failed\n");
35 if (FAILED(lpdi_mouse->Acquire()))
36 fatal("mouse_init : Acquire failed\n");
37 }
39 void mouse_close()
40 {
41 if (lpdi_mouse)
42 {
43 lpdi_mouse->Release();
44 lpdi_mouse = NULL;
45 }
46 }
48 void poll_mouse()
49 {
50 if (FAILED(lpdi_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate)))
51 {
52 lpdi_mouse->Acquire();
53 lpdi_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);
54 }
55 mouse_b = 0;
56 if (mousestate.rgbButtons[0] & 0x80)
57 mouse_b |= 1;
58 if (mousestate.rgbButtons[1] & 0x80)
59 mouse_b |= 2;
60 if (mousestate.rgbButtons[2] & 0x80)
61 mouse_b |= 4;
62 mouse_x += mousestate.lX;
63 mouse_y += mousestate.lY;
64 if (!mousecapture && !video_fullscreen)
65 mouse_x = mouse_y = mouse_b = 0;
66 }
68 void position_mouse(int x, int y)
69 {
70 }
72 void get_mouse_mickeys(int *x, int *y)
73 {
74 *x = mouse_x;
75 *y = mouse_y;
76 mouse_x = mouse_y = 0;
77 }