mirror of
https://github.com/86Box/86Box.git
synced 2026-02-23 18:08:20 -07:00
Re-worked mouse code to be devices (to allow for configuration.)
Re-worked the system pathnames (pc.c), renamed cfg_path to usr_path. Other small things here and there. Logitech bus mouse re-worked, should be OK now.
This commit is contained in:
103
src/win/win_mouse.cpp
Normal file
103
src/win/win_mouse.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||
* running old operating systems and software designed for IBM
|
||||
* PC systems and compatibles from 1981 through fairly recent
|
||||
* system designs based on the PCI bus.
|
||||
*
|
||||
* This file is part of the 86Box distribution.
|
||||
*
|
||||
* Mouse interface to host device.
|
||||
*
|
||||
* Version: @(#)win_mouse.cpp 1.0.6 2017/11/25
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
*
|
||||
* Copyright 2008-2017 Sarah Walker.
|
||||
* Copyright 2016,2017 Miran Grca.
|
||||
*/
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#include <dinput.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "../86Box.h"
|
||||
#include "../mouse.h"
|
||||
#include "../plat.h"
|
||||
#include "win.h"
|
||||
|
||||
|
||||
int mouse_capture;
|
||||
|
||||
|
||||
static LPDIRECTINPUT8 lpdi;
|
||||
static LPDIRECTINPUTDEVICE8 lpdi_mouse = NULL;
|
||||
static DIMOUSESTATE mousestate;
|
||||
|
||||
|
||||
void
|
||||
win_mouse_init(void)
|
||||
{
|
||||
atexit(win_mouse_close);
|
||||
|
||||
mouse_capture = 0;
|
||||
|
||||
if (FAILED(DirectInput8Create(hinstance, DIRECTINPUT_VERSION,
|
||||
IID_IDirectInput8A, (void **) &lpdi, NULL)))
|
||||
fatal("plat_mouse_init: DirectInputCreate failed\n");
|
||||
|
||||
if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdi_mouse, NULL)))
|
||||
fatal("plat_mouse_init: CreateDevice failed\n");
|
||||
|
||||
if (FAILED(lpdi_mouse->SetCooperativeLevel(hwndMain,
|
||||
DISCL_FOREGROUND | (video_fullscreen ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE))))
|
||||
fatal("plat_mouse_init: SetCooperativeLevel failed\n");
|
||||
|
||||
if (FAILED(lpdi_mouse->SetDataFormat(&c_dfDIMouse)))
|
||||
fatal("plat_mouse_init: SetDataFormat failed\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
win_mouse_close(void)
|
||||
{
|
||||
if (lpdi_mouse != NULL) {
|
||||
lpdi_mouse->Release();
|
||||
lpdi_mouse = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mouse_poll(void)
|
||||
{
|
||||
static int buttons = 0;
|
||||
static int x = 0, y = 0, z = 0;
|
||||
int b;
|
||||
|
||||
if (FAILED(lpdi_mouse->GetDeviceState(sizeof(DIMOUSESTATE),
|
||||
(LPVOID)&mousestate))) {
|
||||
lpdi_mouse->Acquire();
|
||||
lpdi_mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);
|
||||
}
|
||||
|
||||
if (mouse_capture || video_fullscreen) {
|
||||
if (x != mousestate.lX || y != mousestate.lY || z != mousestate.lZ) {
|
||||
mouse_x += mousestate.lX;
|
||||
mouse_y += mousestate.lY;
|
||||
mouse_z += mousestate.lZ/120;
|
||||
|
||||
x = mousestate.lX;
|
||||
y = mousestate.lY;
|
||||
z = mousestate.lZ/120;
|
||||
}
|
||||
|
||||
b = 0;
|
||||
if (mousestate.rgbButtons[0] & 0x80) b |= 1;
|
||||
if (mousestate.rgbButtons[1] & 0x80) b |= 2;
|
||||
if (mousestate.rgbButtons[2] & 0x80) b |= 4;
|
||||
if (buttons != b) {
|
||||
mouse_buttons = b;
|
||||
buttons = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user