Renderer fixes and improvements.
This commit is contained in:
239
src/win/win_ui.c
239
src/win/win_ui.c
@@ -28,6 +28,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
#include <86box/plat.h>
|
||||
#include <86box/86box.h>
|
||||
#include <86box/config.h>
|
||||
#include "../cpu/cpu.h"
|
||||
@@ -38,7 +39,6 @@
|
||||
#include <86box/nvr.h>
|
||||
#include <86box/video.h>
|
||||
#include <86box/vid_ega.h> // for update_overscan
|
||||
#include <86box/plat.h>
|
||||
#include <86box/plat_midi.h>
|
||||
#include <86box/plat_dynld.h>
|
||||
#include <86box/ui.h>
|
||||
@@ -373,6 +373,85 @@ plat_power_off(void)
|
||||
}
|
||||
|
||||
|
||||
/* Catch WM_INPUT messages for 'current focus' window. */
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
static LRESULT CALLBACK
|
||||
#else
|
||||
static BOOL CALLBACK
|
||||
#endif
|
||||
input_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_INPUT:
|
||||
if (infocus) {
|
||||
UINT size = 0;
|
||||
PRAWINPUT raw = NULL;
|
||||
|
||||
/* Here we read the raw input data */
|
||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
||||
raw = (PRAWINPUT)malloc(size);
|
||||
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw, &size, sizeof(RAWINPUTHEADER)) == size) {
|
||||
switch(raw->header.dwType)
|
||||
{
|
||||
case RIM_TYPEKEYBOARD:
|
||||
keyboard_handle(raw);
|
||||
break;
|
||||
case RIM_TYPEMOUSE:
|
||||
win_mouse_handle(raw);
|
||||
break;
|
||||
case RIM_TYPEHID:
|
||||
win_joystick_handle(raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(raw);
|
||||
}
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
infocus = 1;
|
||||
#ifndef NO_KEYBOARD_HOOK
|
||||
if (! hook_enabled) {
|
||||
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
|
||||
LowLevelKeyboardProc,
|
||||
GetModuleHandle(NULL),
|
||||
0);
|
||||
hook_enabled = 1;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
infocus = 0;
|
||||
plat_mouse_capture(0);
|
||||
#ifndef NO_KEYBOARD_HOOK
|
||||
if (hook_enabled) {
|
||||
UnhookWindowsHookEx(hKeyboardHook);
|
||||
hook_enabled = 0;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
pclog("video_fullscreen = %i\n", video_fullscreen);
|
||||
if (! video_fullscreen)
|
||||
plat_mouse_capture(1);
|
||||
break;
|
||||
|
||||
case WM_MBUTTONUP:
|
||||
if (mouse_get_buttons() < 3)
|
||||
plat_mouse_capture(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return(1);
|
||||
/* return(CallWindowProc((WNDPROC)input_orig_proc,
|
||||
hwnd, message, wParam, lParam)); */
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
static LRESULT CALLBACK
|
||||
MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
@@ -383,6 +462,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
int temp_x, temp_y;
|
||||
|
||||
if (input_proc(hwnd, message, wParam, lParam) == 0)
|
||||
return(0);
|
||||
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
SetTimer(hwnd, TIMER_1SEC, 1000, NULL);
|
||||
@@ -571,6 +653,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X+scale, MF_UNCHECKED);
|
||||
scale = LOWORD(wParam) - IDM_VID_SCALE_1X;
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X+scale, MF_CHECKED);
|
||||
reset_screen_size();
|
||||
device_force_redraw();
|
||||
video_force_resize_set(1);
|
||||
config_save();
|
||||
@@ -716,11 +799,10 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
GetWindowRect(hwndSBAR, &rect);
|
||||
sbar_height = rect.bottom - rect.top;
|
||||
rect_p = (RECT*)lParam;
|
||||
if (vid_resize) {
|
||||
if (vid_resize)
|
||||
MoveWindow(hwnd, rect_p->left, rect_p->top, rect_p->right - rect_p->left, rect_p->bottom - rect_p->top, TRUE);
|
||||
} else if (!user_resize) {
|
||||
else if (!user_resize)
|
||||
doresize = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
@@ -773,6 +855,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
plat_vidapi_enable(1);
|
||||
|
||||
plat_vidapi_enable(0);
|
||||
plat_vidapi_enable(1);
|
||||
|
||||
config_save();
|
||||
break;
|
||||
|
||||
@@ -939,7 +1024,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
|
||||
case WM_ACTIVATE:
|
||||
if (wParam != WA_INACTIVE) {
|
||||
if ((wParam != WA_INACTIVE) && !(video_fullscreen & 2)) {
|
||||
video_force_resize_set(1);
|
||||
plat_vidapi_enable(0);
|
||||
plat_vidapi_enable(1);
|
||||
@@ -966,6 +1051,38 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
static LRESULT CALLBACK
|
||||
SubWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_LBUTTONUP:
|
||||
if (! video_fullscreen)
|
||||
plat_mouse_capture(1);
|
||||
break;
|
||||
|
||||
case WM_MBUTTONUP:
|
||||
if (mouse_get_buttons() < 3)
|
||||
plat_mouse_capture(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return(DefWindowProc(hwnd, message, wParam, lParam));
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
static LRESULT CALLBACK
|
||||
SDLMainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (input_proc(hwnd, message, wParam, lParam) == 0)
|
||||
return(0);
|
||||
|
||||
return(DefWindowProc(hwnd, message, wParam, lParam));
|
||||
}
|
||||
|
||||
|
||||
static LRESULT CALLBACK
|
||||
SDLSubWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
return(DefWindowProc(hwnd, message, wParam, lParam));
|
||||
}
|
||||
@@ -1056,6 +1173,14 @@ ui_init(int nCmdShow)
|
||||
return(2);
|
||||
wincl.lpszClassName = SUB_CLASS_NAME;
|
||||
wincl.lpfnWndProc = SubWindowProcedure;
|
||||
if (! RegisterClassEx(&wincl))
|
||||
return(2);
|
||||
wincl.lpszClassName = SDL_CLASS_NAME;
|
||||
wincl.lpfnWndProc = SDLMainWindowProcedure;
|
||||
if (! RegisterClassEx(&wincl))
|
||||
return(2);
|
||||
wincl.lpszClassName = SDL_SUB_CLASS_NAME;
|
||||
wincl.lpfnWndProc = SDLSubWindowProcedure;
|
||||
if (! RegisterClassEx(&wincl))
|
||||
return(2);
|
||||
|
||||
@@ -1128,9 +1253,6 @@ ui_init(int nCmdShow)
|
||||
}
|
||||
keyboard_getkeymap();
|
||||
|
||||
/* Set up the main window for RawInput. */
|
||||
plat_set_input(hwndMain);
|
||||
|
||||
/* Load the accelerator table */
|
||||
haccel = LoadAccelerators(hinstance, ACCEL_NAME);
|
||||
if (haccel == NULL) {
|
||||
@@ -1149,7 +1271,7 @@ ui_init(int nCmdShow)
|
||||
ghMutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
/* Create the Machine Rendering window. */
|
||||
hwndRender = CreateWindow(L"STATIC", NULL, WS_CHILD|SS_BITMAP,
|
||||
hwndRender = CreateWindow(/*L"STATIC"*/ SUB_CLASS_NAME, NULL, WS_CHILD|SS_BITMAP,
|
||||
0, 0, 1, 1, hwnd, NULL, hinstance, NULL);
|
||||
MoveWindow(hwndRender, 0, 0, scrnsz_x, scrnsz_y, TRUE);
|
||||
|
||||
@@ -1241,6 +1363,8 @@ ui_init(int nCmdShow)
|
||||
/* Close down the emulator. */
|
||||
do_stop();
|
||||
|
||||
UnregisterClass(SDL_SUB_CLASS_NAME, hinstance);
|
||||
UnregisterClass(SDL_CLASS_NAME, hinstance);
|
||||
UnregisterClass(SUB_CLASS_NAME, hinstance);
|
||||
UnregisterClass(CLASS_NAME, hinstance);
|
||||
|
||||
@@ -1384,100 +1508,3 @@ plat_mouse_capture(int on)
|
||||
mouse_capture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Catch WM_INPUT messages for 'current focus' window. */
|
||||
static LONG_PTR input_orig_proc;
|
||||
static HWND input_orig_hwnd = NULL;
|
||||
#if defined(__amd64__) || defined(__aarch64__)
|
||||
static LRESULT CALLBACK
|
||||
#else
|
||||
static BOOL CALLBACK
|
||||
#endif
|
||||
input_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_INPUT:
|
||||
if (infocus) {
|
||||
UINT size = 0;
|
||||
PRAWINPUT raw = NULL;
|
||||
|
||||
/* Here we read the raw input data */
|
||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
||||
raw = (PRAWINPUT)malloc(size);
|
||||
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, raw, &size, sizeof(RAWINPUTHEADER)) == size) {
|
||||
switch(raw->header.dwType)
|
||||
{
|
||||
case RIM_TYPEKEYBOARD:
|
||||
keyboard_handle(raw);
|
||||
break;
|
||||
case RIM_TYPEMOUSE:
|
||||
win_mouse_handle(raw);
|
||||
break;
|
||||
case RIM_TYPEHID:
|
||||
win_joystick_handle(raw);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(raw);
|
||||
}
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
infocus = 1;
|
||||
#ifndef NO_KEYBOARD_HOOK
|
||||
if (! hook_enabled) {
|
||||
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
|
||||
LowLevelKeyboardProc,
|
||||
GetModuleHandle(NULL),
|
||||
0);
|
||||
hook_enabled = 1;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
infocus = 0;
|
||||
plat_mouse_capture(0);
|
||||
#ifndef NO_KEYBOARD_HOOK
|
||||
if (hook_enabled) {
|
||||
UnhookWindowsHookEx(hKeyboardHook);
|
||||
hook_enabled = 0;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
if (! video_fullscreen)
|
||||
plat_mouse_capture(1);
|
||||
break;
|
||||
|
||||
case WM_MBUTTONUP:
|
||||
if (mouse_get_buttons() < 3)
|
||||
plat_mouse_capture(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
return(CallWindowProc((WNDPROC)input_orig_proc,
|
||||
hwnd, message, wParam, lParam));
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/* Set up a handler for the 'currently active' window. */
|
||||
void
|
||||
plat_set_input(HWND h)
|
||||
{
|
||||
/* If needed, rest the old one first. */
|
||||
if (input_orig_hwnd != NULL) {
|
||||
SetWindowLongPtr(input_orig_hwnd, GWLP_WNDPROC,
|
||||
(LONG_PTR)input_orig_proc);
|
||||
}
|
||||
|
||||
/* Redirect the window procedure so we can catch WM_INPUT. */
|
||||
input_orig_proc = GetWindowLongPtr(h, GWLP_WNDPROC);
|
||||
input_orig_hwnd = h;
|
||||
SetWindowLongPtr(h, GWLP_WNDPROC, (LONG_PTR)&input_proc);
|
||||
ImmAssociateContext(h, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user