Added GUI, some menus dont work yet.
Fixed uniform scaling. Removed splash screen.
This commit is contained in:
@@ -53,8 +53,6 @@ set(SOURCE_FILES
|
||||
SpaceCadetPinball/Sound.cpp
|
||||
SpaceCadetPinball/Sound.h
|
||||
SpaceCadetPinball/SpaceCadetPinball.cpp
|
||||
SpaceCadetPinball/splash.cpp
|
||||
SpaceCadetPinball/splash.h
|
||||
SpaceCadetPinball/TBall.cpp
|
||||
SpaceCadetPinball/TBall.h
|
||||
SpaceCadetPinball/TBlocker.cpp
|
||||
@@ -138,7 +136,23 @@ set(SOURCE_FILES
|
||||
SpaceCadetPinball/winmain.cpp
|
||||
SpaceCadetPinball/winmain.h
|
||||
SpaceCadetPinball/zdrv.cpp
|
||||
SpaceCadetPinball/zdrv.h)
|
||||
SpaceCadetPinball/zdrv.h
|
||||
SpaceCadetPinball/imconfig.h
|
||||
SpaceCadetPinball/imgui_internal.h
|
||||
SpaceCadetPinball/imgui.cpp
|
||||
SpaceCadetPinball/imgui.h
|
||||
SpaceCadetPinball/imgui_sdl.cpp
|
||||
SpaceCadetPinball/imgui_sdl.h
|
||||
SpaceCadetPinball/imgui_draw.cpp
|
||||
SpaceCadetPinball/imgui_widgets.cpp
|
||||
SpaceCadetPinball/imgui_tables.cpp
|
||||
SpaceCadetPinball/imgui_demo.cpp
|
||||
SpaceCadetPinball/imgui_impl_sdl.cpp
|
||||
SpaceCadetPinball/imgui_impl_sdl.h
|
||||
SpaceCadetPinball/imstb_textedit.h
|
||||
SpaceCadetPinball/imstb_rectpack.h
|
||||
SpaceCadetPinball/imstb_truetype.h
|
||||
)
|
||||
|
||||
add_executable(SpaceCadetPinball ${SOURCE_FILES})
|
||||
|
||||
|
||||
@@ -20,8 +20,31 @@
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x86" ]
|
||||
},
|
||||
{
|
||||
"name": "x86-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Release",
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x86" ],
|
||||
"variables": []
|
||||
},
|
||||
{
|
||||
"name": "x64-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Release",
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"variables": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -9,15 +9,8 @@
|
||||
|
||||
|
||||
int fullscrn::screen_mode;
|
||||
HWND fullscrn::hWnd;
|
||||
tagRECT fullscrn::WindowRect1, fullscrn::WindowRect2;
|
||||
rectangle_type fullscrn::WHRect;
|
||||
int fullscrn::fullscrn_flag1;
|
||||
int fullscrn::display_changed;
|
||||
int fullscrn::ChangeDisplay, fullscrn::ignoreNextDisplayChangeFg;
|
||||
int fullscrn::trick = 1;
|
||||
int fullscrn::MenuEnabled;
|
||||
HMENU fullscrn::MenuHandle;
|
||||
|
||||
int fullscrn::resolution = 0;
|
||||
int fullscrn::maxResolution = 0;
|
||||
const resolution_info fullscrn::resolution_array[3] =
|
||||
@@ -28,45 +21,12 @@ const resolution_info fullscrn::resolution_array[3] =
|
||||
};
|
||||
float fullscrn::ScaleX = 1;
|
||||
float fullscrn::ScaleY = 1;
|
||||
float fullscrn::OffsetX = 0;
|
||||
float fullscrn::OffsetY = 0;
|
||||
int fullscrn::OffsetX = 0;
|
||||
int fullscrn::OffsetY = 0;
|
||||
|
||||
void fullscrn::init(int width, int height, int isFullscreen, HWND winHandle, HMENU menuHandle, int changeDisplay)
|
||||
void fullscrn::init()
|
||||
{
|
||||
WHRect.XPosition = 0;
|
||||
WHRect.YPosition = 0;
|
||||
ChangeDisplay = changeDisplay;
|
||||
hWnd = winHandle;
|
||||
MenuHandle = menuHandle;
|
||||
WHRect.Width = width;
|
||||
WHRect.Height = height;
|
||||
|
||||
GetWindowRect(GetDesktopWindow(), &fullscrn::WindowRect1);
|
||||
int widht2 = width + 2 * GetSystemMetrics(SM_CXBORDER);
|
||||
int height2 = height + 2 * GetSystemMetrics(SM_CYBORDER);
|
||||
int menuHeight = GetSystemMetrics(SM_CYMENU);
|
||||
int captionHeight = GetSystemMetrics(SM_CYCAPTION);
|
||||
int borderHeight = WindowRect1.bottom - WindowRect1.top - height2;
|
||||
|
||||
WindowRect2.bottom = borderHeight / 2 - 2 + height2 + 4;
|
||||
WindowRect2.right = (WindowRect1.right - WindowRect1.left - widht2) / 2 - 2 + widht2 + 4;
|
||||
WindowRect2.left = (WindowRect1.right - WindowRect1.left - widht2) / 2 - 2;
|
||||
WindowRect2.top = borderHeight / 2 - (captionHeight + menuHeight) - 2;
|
||||
|
||||
/*RECT client{0,0,width,height};
|
||||
AdjustWindowRect(&client, winmain::WndStyle, true);*/
|
||||
MoveWindow(
|
||||
hWnd,
|
||||
(WindowRect1.right - WindowRect1.left - widht2) / 2 - 2,
|
||||
WindowRect2.top,
|
||||
WindowRect2.right - WindowRect2.left + 10,
|
||||
WindowRect2.bottom - WindowRect2.top + 10,
|
||||
0);
|
||||
// Todo: WH + 10 hack: original request 640x480 window but somehow receives 650x490, even thought spyxx says it is 640x480
|
||||
fullscrn_flag1 = 0;
|
||||
|
||||
window_size_changed();
|
||||
//assertm(ScaleX == 1 && ScaleY == 1, "Wrong default client size");
|
||||
}
|
||||
|
||||
void fullscrn::shutdown()
|
||||
@@ -83,72 +43,26 @@ int fullscrn::set_screen_mode(int isFullscreen)
|
||||
screen_mode = isFullscreen;
|
||||
if (isFullscreen)
|
||||
{
|
||||
if (IsWindowVisible(hWnd))
|
||||
GetWindowRect(hWnd, &WindowRect2);
|
||||
enableFullscreen();
|
||||
BYTE1(fullscrn_flag1) |= 0x80u;
|
||||
InvalidateRect(hWnd, nullptr, 1);
|
||||
set_menu_mode(0);
|
||||
result = disableWindowFlagsDisDlg();
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
disableFullscreen();
|
||||
BYTE1(fullscrn_flag1) |= 0x80u;
|
||||
InvalidateRect(hWnd, nullptr, 1);
|
||||
set_menu_mode(1);
|
||||
result = RedrawWindow(nullptr, nullptr, nullptr, 0x185u);
|
||||
result = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int fullscrn::disableWindowFlagsDisDlg()
|
||||
{
|
||||
long style = GetWindowLongA(hWnd, -16);
|
||||
return SetWindowLongA(hWnd, -16, style & ~(WS_CAPTION | WS_THICKFRAME));
|
||||
}
|
||||
|
||||
int fullscrn::setWindowFlagsDisDlg()
|
||||
{
|
||||
int style = GetWindowLongA(hWnd, -16);
|
||||
return SetWindowLongA(hWnd, -16, style | WS_CAPTION | WS_THICKFRAME);
|
||||
}
|
||||
|
||||
int fullscrn::enableFullscreen()
|
||||
{
|
||||
tagRECT Rect{};
|
||||
DEVMODEA DevMode{};
|
||||
|
||||
if (ChangeDisplay && !display_changed)
|
||||
if (!display_changed)
|
||||
{
|
||||
DevMode.dmSize = sizeof DevMode;
|
||||
DevMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
||||
DevMode.dmPelsWidth = resolution_array[resolution].ScreenWidth;
|
||||
DevMode.dmPelsHeight = resolution_array[resolution].ScreenHeight;
|
||||
DevMode.dmBitsPerPel = 32;
|
||||
disableWindowFlagsDisDlg();
|
||||
if (trick)
|
||||
{
|
||||
GetWindowRect(GetDesktopWindow(), &Rect);
|
||||
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, Rect.right - Rect.left + 1,
|
||||
Rect.bottom - Rect.top + 1, SWP_NOREDRAW);
|
||||
}
|
||||
ignoreNextDisplayChangeFg = 1;
|
||||
LONG changeDispResult = ChangeDisplaySettingsA(&DevMode, CDS_FULLSCREEN);
|
||||
if (changeDispResult == DISP_CHANGE_RESTART)
|
||||
{
|
||||
DevMode.dmFields &= ~DM_BITSPERPEL;
|
||||
ignoreNextDisplayChangeFg = 1;
|
||||
changeDispResult = ChangeDisplaySettingsA(&DevMode, CDS_FULLSCREEN);
|
||||
}
|
||||
display_changed = changeDispResult == DISP_CHANGE_SUCCESSFUL;
|
||||
SDL_SetWindowFullscreen(winmain::MainWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
display_changed = 1;
|
||||
if (display_changed)
|
||||
return 1;
|
||||
}
|
||||
GetWindowRect(GetDesktopWindow(), &Rect);
|
||||
disableWindowFlagsDisDlg();
|
||||
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, Rect.right - Rect.left + 1, Rect.bottom - Rect.top + 1, SWP_NOREDRAW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -156,154 +70,13 @@ int fullscrn::disableFullscreen()
|
||||
{
|
||||
if (display_changed)
|
||||
{
|
||||
SDL_SetWindowFullscreen(winmain::MainWindow, 0);
|
||||
display_changed = 0;
|
||||
ignoreNextDisplayChangeFg = 1;
|
||||
ChangeDisplaySettingsA(nullptr, CDS_FULLSCREEN);
|
||||
if (trick)
|
||||
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
|
||||
}
|
||||
setWindowFlagsDisDlg();
|
||||
SetWindowPos(
|
||||
hWnd,
|
||||
HWND_TOP,
|
||||
WindowRect2.left,
|
||||
WindowRect2.top,
|
||||
WindowRect2.right - WindowRect2.left,
|
||||
WindowRect2.bottom - WindowRect2.top,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool fullscrn::set_menu_mode(int menuEnabled)
|
||||
{
|
||||
BOOL result;
|
||||
|
||||
MenuEnabled = menuEnabled;
|
||||
GetWindowCenter();
|
||||
if (MenuEnabled)
|
||||
{
|
||||
fullscrn_flag1 |= 2u;
|
||||
InvalidateRect(hWnd, nullptr, 1);
|
||||
result = SetMenu(hWnd, MenuHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
fullscrn_flag1 |= 1u;
|
||||
InvalidateRect(hWnd, nullptr, 1);
|
||||
result = SetMenu(hWnd, nullptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void fullscrn::GetWindowCenter()
|
||||
{
|
||||
int yPos;
|
||||
tagRECT Rect{};
|
||||
|
||||
if (screen_mode)
|
||||
{
|
||||
GetWindowRect(GetDesktopWindow(), &Rect);
|
||||
render::vscreen.XPosition = (Rect.right - render::vscreen.Width - Rect.left) / 2;
|
||||
yPos = (Rect.bottom - render::vscreen.Height - Rect.top) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
render::vscreen.XPosition = 0;
|
||||
yPos = GetSystemMetrics(15);
|
||||
}
|
||||
render::vscreen.YPosition = yPos;
|
||||
if (MenuEnabled)
|
||||
render::vscreen.YPosition -= GetSystemMetrics(15);
|
||||
}
|
||||
|
||||
void fullscrn::force_redraw()
|
||||
{
|
||||
BYTE1(fullscrn_flag1) |= 0x80u;
|
||||
}
|
||||
|
||||
|
||||
void fullscrn::center_in(HWND parent, HWND child)
|
||||
{
|
||||
LONG right;
|
||||
tagRECT childRect{}, parentRect{}, desktopRect{};
|
||||
|
||||
GetWindowRect(parent, &parentRect);
|
||||
GetWindowRect(child, &childRect);
|
||||
GetWindowRect(GetDesktopWindow(), &desktopRect);
|
||||
if (display_changed)
|
||||
{
|
||||
desktopRect.bottom = 480;
|
||||
desktopRect.left = 0;
|
||||
desktopRect.top = 0;
|
||||
right = 640;
|
||||
desktopRect.right = 640;
|
||||
parentRect.left = 0;
|
||||
parentRect.top = 0;
|
||||
parentRect.right = 640;
|
||||
parentRect.bottom = 480;
|
||||
}
|
||||
else
|
||||
{
|
||||
right = desktopRect.right;
|
||||
}
|
||||
|
||||
int childHeight = childRect.bottom - childRect.top;
|
||||
int smthWidth = parentRect.left + (parentRect.right + childRect.left - childRect.right - parentRect.left) / 2;
|
||||
int smthHeight = parentRect.top + (parentRect.bottom + childRect.top - childRect.bottom - parentRect.top) / 2;
|
||||
if (childRect.right - childRect.left + smthWidth > right)
|
||||
smthWidth = right - (childRect.right - childRect.left);
|
||||
if (childHeight + smthHeight > desktopRect.bottom)
|
||||
smthHeight = desktopRect.bottom - childHeight;
|
||||
if (smthWidth < desktopRect.left)
|
||||
smthWidth = desktopRect.left;
|
||||
if (smthHeight < desktopRect.top)
|
||||
smthHeight = desktopRect.top;
|
||||
MoveWindow(child, smthWidth, smthHeight, childRect.right - childRect.left, childRect.bottom - childRect.top, 0);
|
||||
}
|
||||
|
||||
int fullscrn::displaychange()
|
||||
{
|
||||
int result = 0;
|
||||
if (ignoreNextDisplayChangeFg)
|
||||
{
|
||||
ignoreNextDisplayChangeFg = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (screen_mode && display_changed)
|
||||
{
|
||||
display_changed = 0;
|
||||
screen_mode = 0;
|
||||
setWindowFlagsDisDlg();
|
||||
BYTE1(fullscrn_flag1) |= 0x80u;
|
||||
InvalidateRect(hWnd, nullptr, 1);
|
||||
set_menu_mode(1);
|
||||
SetWindowPos(
|
||||
hWnd,
|
||||
HWND_TOP,
|
||||
WindowRect2.left,
|
||||
WindowRect2.top,
|
||||
WindowRect2.right - WindowRect2.left,
|
||||
WindowRect2.bottom - WindowRect2.top,
|
||||
SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE);
|
||||
result = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowPos(
|
||||
hWnd,
|
||||
HWND_TOP,
|
||||
WindowRect2.left,
|
||||
WindowRect2.top,
|
||||
WindowRect2.right - WindowRect2.left,
|
||||
WindowRect2.bottom - WindowRect2.top,
|
||||
SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
center_in(GetDesktopWindow(), hWnd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void fullscrn::activate(int flag)
|
||||
{
|
||||
if (screen_mode)
|
||||
@@ -311,76 +84,10 @@ void fullscrn::activate(int flag)
|
||||
if (!flag)
|
||||
{
|
||||
set_screen_mode(0);
|
||||
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fullscrn::fillRect(int right, int bottom, int left, int top)
|
||||
{
|
||||
RECT rc;
|
||||
auto brush = CreateSolidBrush(0);
|
||||
if (brush)
|
||||
{
|
||||
auto dc = winmain::_GetDC(hWnd);
|
||||
if (dc)
|
||||
{
|
||||
auto prevBrush = SelectObject(dc, brush);
|
||||
rc.right = left + right + 1;
|
||||
rc.bottom = top + bottom + 1;
|
||||
rc.left = left;
|
||||
rc.top = top;
|
||||
FillRect(dc, &rc, brush);
|
||||
SelectObject(dc, prevBrush);
|
||||
ReleaseDC(hWnd, dc);
|
||||
}
|
||||
DeleteObject(brush);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned fullscrn::convert_mouse_pos(unsigned int mouseXY)
|
||||
{
|
||||
uint16_t x = mouseXY & 0xffFF - render::vscreen.XPosition;
|
||||
uint16_t y = (mouseXY >> 16) - render::vscreen.YPosition;
|
||||
return x | y << 16;
|
||||
}
|
||||
|
||||
void fullscrn::getminmaxinfo(MINMAXINFO* maxMin)
|
||||
{
|
||||
/*Block down-scaling lower than min resolution*/
|
||||
maxMin->ptMinTrackSize = POINT
|
||||
{
|
||||
resolution_array[0].ScreenWidth / 2,
|
||||
resolution_array[0].ScreenHeight / 2
|
||||
};
|
||||
}
|
||||
|
||||
void fullscrn::paint()
|
||||
{
|
||||
int menuHeight;
|
||||
if (screen_mode)
|
||||
{
|
||||
if ((fullscrn_flag1 & 0x8000) == 0 && fullscrn_flag1)
|
||||
{
|
||||
if (fullscrn_flag1 & 1)
|
||||
{
|
||||
menuHeight = GetSystemMetrics(SM_CYMENU);
|
||||
fillRect(WindowRect1.right - 1, menuHeight, 0, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (MenuEnabled)
|
||||
menuHeight = GetSystemMetrics(SM_CYMENU);
|
||||
else
|
||||
menuHeight = 0;
|
||||
fillRect(WindowRect1.right, menuHeight + WindowRect1.bottom, 0, 0);
|
||||
}
|
||||
}
|
||||
render::paint();
|
||||
fullscrn_flag1 = 0;
|
||||
}
|
||||
|
||||
int fullscrn::GetResolution()
|
||||
{
|
||||
return resolution;
|
||||
@@ -432,16 +139,8 @@ int fullscrn::get_screen_resolution()
|
||||
|
||||
void fullscrn::window_size_changed()
|
||||
{
|
||||
/*No scaling in fullscreen mode*/
|
||||
if (display_changed)
|
||||
{
|
||||
ScaleY = ScaleX = 1;
|
||||
OffsetX = OffsetY = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int width, height;
|
||||
SDL_GetWindowSize(winmain::MainWindow, &width, &height);
|
||||
SDL_GetRendererOutputSize(winmain::Renderer, &width, &height);
|
||||
auto res = &resolution_array[resolution];
|
||||
ScaleX = static_cast<float>(width) / res->TableWidth;
|
||||
ScaleY = static_cast<float>(height) / res->TableHeight;
|
||||
@@ -450,13 +149,13 @@ void fullscrn::window_size_changed()
|
||||
if (options::Options.UniformScaling)
|
||||
{
|
||||
ScaleY = ScaleX = min(ScaleX, ScaleY);
|
||||
OffsetX = floor((width - res->TableWidth * ScaleX) / 2);
|
||||
OffsetY = floor((height - res->TableHeight * ScaleY) / 2);
|
||||
auto dc = GetDC(hWnd);
|
||||
if (dc)
|
||||
{
|
||||
BitBlt(dc, 0, 0, width, height, dc, 0, 0, BLACKNESS);
|
||||
ReleaseDC(hWnd, dc);
|
||||
}
|
||||
OffsetX = static_cast<int>(floor((width - res->TableWidth * ScaleX) / 2));
|
||||
OffsetY = static_cast<int>(floor((height - res->TableHeight * ScaleY) / 2));
|
||||
}
|
||||
|
||||
gdrv::DestinationRect = SDL_Rect
|
||||
{
|
||||
OffsetX, OffsetY,
|
||||
width - OffsetX * 2, height - OffsetY * 2
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
#pragma once
|
||||
#include "maths.h"
|
||||
|
||||
#define BYTEn(x, n) (*((unsigned char*)&(x)+n))
|
||||
#define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0)
|
||||
#define BYTE2(x) BYTEn(x, 2)
|
||||
|
||||
|
||||
struct resolution_info
|
||||
{
|
||||
@@ -18,32 +12,18 @@ struct resolution_info
|
||||
class fullscrn
|
||||
{
|
||||
public:
|
||||
|
||||
static int screen_mode;
|
||||
static HWND hWnd;
|
||||
static tagRECT WindowRect1, WindowRect2;
|
||||
static rectangle_type WHRect;
|
||||
static int fullscrn_flag1;
|
||||
static int display_changed;
|
||||
static int ChangeDisplay, ignoreNextDisplayChangeFg;
|
||||
static int trick;
|
||||
static const resolution_info resolution_array[3];
|
||||
static float ScaleX;
|
||||
static float ScaleY;
|
||||
static float OffsetX;
|
||||
static float OffsetY;
|
||||
static int OffsetX;
|
||||
static int OffsetY;
|
||||
|
||||
static void init(int width, int height, int isFullscreen, HWND winHandle, HMENU menuHandle, int changeDisplay);
|
||||
static void init();
|
||||
static void shutdown();
|
||||
static int set_screen_mode(int isFullscreen);
|
||||
static void force_redraw();
|
||||
static void center_in(HWND parent, HWND child);
|
||||
static int displaychange();
|
||||
static void activate(int flag);
|
||||
static unsigned convert_mouse_pos(unsigned int mouseXY);
|
||||
static void getminmaxinfo(MINMAXINFO* maxMin);
|
||||
static void paint();
|
||||
static bool set_menu_mode(int menuEnabled);
|
||||
static int GetResolution();
|
||||
static void SetResolution(int resolution);
|
||||
static int GetMaxResolution();
|
||||
@@ -52,15 +32,9 @@ public:
|
||||
static int get_screen_resolution();
|
||||
static void window_size_changed();
|
||||
private :
|
||||
static int MenuEnabled;
|
||||
static HMENU MenuHandle;
|
||||
static int resolution;
|
||||
static int maxResolution;
|
||||
|
||||
static void GetWindowCenter();
|
||||
static int disableWindowFlagsDisDlg();
|
||||
static int setWindowFlagsDisDlg();
|
||||
static int enableFullscreen();
|
||||
static int disableFullscreen();
|
||||
static void fillRect(int right, int bottom, int left, int top);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "gdrv.h"
|
||||
|
||||
#include "fullscrn.h"
|
||||
#include "memory.h"
|
||||
#include "render.h"
|
||||
#include "winmain.h"
|
||||
@@ -9,6 +10,7 @@ SDL_Texture* gdrv::vScreenTex = nullptr;
|
||||
char* gdrv::vScreenPixels = nullptr;
|
||||
int gdrv::vScreenWidth, gdrv::vScreenHeight;
|
||||
ColorRgba gdrv::current_palette[256]{};
|
||||
SDL_Rect gdrv::DestinationRect{};
|
||||
|
||||
int gdrv::init(int width, int height)
|
||||
{
|
||||
@@ -297,6 +299,6 @@ void gdrv::BlitScreen()
|
||||
&pitch
|
||||
);
|
||||
std::memcpy(lockedPixels, vScreenPixels, vScreenWidth * vScreenHeight * 4);
|
||||
SDL_UnlockTexture(vScreenTex);
|
||||
SDL_RenderCopyEx(winmain::Renderer, vScreenTex, nullptr, nullptr, 0, nullptr, SDL_FLIP_VERTICAL);
|
||||
SDL_UnlockTexture(vScreenTex);
|
||||
SDL_RenderCopyEx(winmain::Renderer, vScreenTex, nullptr, &DestinationRect, 0, nullptr, SDL_FLIP_VERTICAL);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ struct gdrv_bitmap8
|
||||
int Height;
|
||||
int Stride;
|
||||
BitmapType BitmapType;
|
||||
int Color6;
|
||||
int XPosition;
|
||||
int YPosition;
|
||||
};
|
||||
@@ -49,6 +48,8 @@ struct LOGPALETTEx256 : LOGPALETTE
|
||||
class gdrv
|
||||
{
|
||||
public:
|
||||
static SDL_Rect DestinationRect;
|
||||
|
||||
static int init(int width, int height);
|
||||
static int uninit();
|
||||
static void get_focus();
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
int high_score::dlg_enter_name;
|
||||
int high_score::dlg_score;
|
||||
int high_score::dlg_position;
|
||||
LPCSTR high_score::default_name;
|
||||
char high_score::default_name[32]{};
|
||||
high_score_struct* high_score::dlg_hst;
|
||||
bool high_score::ShowDialog = false;
|
||||
|
||||
winhelp_entry high_score::help[21]
|
||||
{
|
||||
@@ -167,7 +168,7 @@ void high_score::show_high_score_dialog(high_score_struct* table)
|
||||
dlg_enter_name = 0;
|
||||
dlg_score = 0;
|
||||
dlg_hst = table;
|
||||
DialogBoxParamA(nullptr, "dlg_highscores", nullptr, HighScore, 0);
|
||||
ShowDialog = true;
|
||||
}
|
||||
|
||||
void high_score::show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCSTR defaultName)
|
||||
@@ -176,126 +177,99 @@ void high_score::show_and_set_high_score_dialog(high_score_struct* table, int sc
|
||||
dlg_score = score;
|
||||
dlg_hst = table;
|
||||
dlg_enter_name = 1;
|
||||
default_name = defaultName;
|
||||
/*while (DialogBoxParamA(winmain::hinst, "dlg_highscores", winmain::hwnd_frame, HighScore, 0))
|
||||
{
|
||||
}*/
|
||||
strncpy_s(default_name, defaultName, 32);
|
||||
ShowDialog = true;
|
||||
}
|
||||
|
||||
INT_PTR high_score::HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
void high_score::RenderHighScoreDialog()
|
||||
{
|
||||
HWND parent;
|
||||
int nIDDlgItem;
|
||||
CHAR String1[256];
|
||||
CHAR name[32];
|
||||
|
||||
switch (msg)
|
||||
if (ShowDialog == true)
|
||||
{
|
||||
case WM_CLOSE:
|
||||
SendMessageA(hWnd, WM_COMMAND, WM_DESTROY, 0);
|
||||
break;
|
||||
case WM_HELP:
|
||||
WinHelpA(static_cast<HWND>(reinterpret_cast<HELPINFO*>(lParam)->hItemHandle), "pinball.hlp", HELP_WM_HELP,
|
||||
(ULONG_PTR)help);
|
||||
break;
|
||||
case WM_CONTEXTMENU:
|
||||
WinHelpA((HWND)wParam, "pinball.hlp", HELP_CONTEXTMENU, (ULONG_PTR)help);
|
||||
break;
|
||||
case WM_INITDIALOG:
|
||||
show_high_scores(hWnd, dlg_hst);
|
||||
for (nIDDlgItem = DLG_HIGHSCORES_EditName1; nIDDlgItem < 611; ++nIDDlgItem)
|
||||
ShowDialog = false;
|
||||
if (dlg_position == -1)
|
||||
{
|
||||
ShowWindow(GetDlgItem(hWnd, nIDDlgItem), 0);
|
||||
dlg_enter_name = 0;
|
||||
return;
|
||||
}
|
||||
if (dlg_enter_name == 1)
|
||||
ImGui::OpenPopup("High Scores");
|
||||
}
|
||||
|
||||
bool unused_open = true;
|
||||
if (ImGui::BeginPopupModal("High Scores", &unused_open, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
if (ImGui::BeginTable("table1", 3, 0))
|
||||
{
|
||||
if (dlg_position == -1)
|
||||
char buf[36];
|
||||
ImGui::TableSetupColumn("Rank");
|
||||
ImGui::TableSetupColumn("Name");
|
||||
ImGui::TableSetupColumn("Score");
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
high_score_struct* tablePtr = dlg_hst;
|
||||
for (int row = 0; row < 5; row++)
|
||||
{
|
||||
dlg_enter_name = 0;
|
||||
return 1;
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
_itoa_s(row, buf, 10);
|
||||
ImGui::TextUnformatted(buf);
|
||||
|
||||
auto score = tablePtr->Score;
|
||||
ImGui::TableNextColumn();
|
||||
if (dlg_enter_name == 1 && dlg_position == row)
|
||||
{
|
||||
score = dlg_score;
|
||||
ImGui::PushItemWidth(200);
|
||||
ImGui::InputText("", default_name, IM_ARRAYSIZE(default_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::TextUnformatted(tablePtr->Name);
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
score::string_format(score, buf);
|
||||
ImGui::TextUnformatted(buf);
|
||||
|
||||
tablePtr++;
|
||||
}
|
||||
HWND nameTextBox = GetDlgItem(hWnd, dlg_position + DLG_HIGHSCORES_EditName1);
|
||||
ShowWindow(nameTextBox, 5);
|
||||
EnableWindow(nameTextBox, 1);
|
||||
SetFocus(nameTextBox);
|
||||
if (default_name)
|
||||
{
|
||||
SetWindowTextA(nameTextBox, default_name);
|
||||
SendMessageA(nameTextBox, EM_SETSEL, 0, -1);
|
||||
}
|
||||
SendMessageA(nameTextBox, EM_SETLIMITTEXT, 31u, 0);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
else
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::Button("Ok"))
|
||||
{
|
||||
SetFocus(hWnd);
|
||||
}
|
||||
parent = GetParent(hWnd);
|
||||
if (parent)
|
||||
fullscrn::center_in(parent, hWnd);
|
||||
return 0;
|
||||
case WM_COMMAND:
|
||||
switch (wParam)
|
||||
{
|
||||
case DLG_HIGHSCORES_Ok:
|
||||
if (dlg_enter_name != 1)
|
||||
{
|
||||
break;
|
||||
if (dlg_enter_name)
|
||||
{
|
||||
default_name[31] = 0;
|
||||
place_new_score_into(dlg_hst, dlg_score, default_name, dlg_position);
|
||||
}
|
||||
GetDlgItemTextA(hWnd, dlg_position + DLG_HIGHSCORES_EditName1, name, 32);
|
||||
name[31] = 0;
|
||||
place_new_score_into(dlg_hst, dlg_score, name, dlg_position);
|
||||
break;
|
||||
case DLG_HIGHSCORES_Cancel:
|
||||
break;
|
||||
case DLG_HIGHSCORES_Clear:
|
||||
lstrcpyA(String1, pinball::get_rc_string(41, 0));
|
||||
if (MessageBoxA(hWnd, pinball::get_rc_string(40, 0), String1, MB_DEFBUTTON2 | MB_OKCANCEL) == 1)
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Cancel"))
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Clear"))
|
||||
ImGui::OpenPopup("Confirm");
|
||||
if (ImGui::BeginPopupModal("Confirm", nullptr, ImGuiWindowFlags_MenuBar))
|
||||
{
|
||||
ImGui::TextUnformatted(pinball::get_rc_string(40, 0));
|
||||
if (ImGui::Button("OK", ImVec2(120, 0)))
|
||||
{
|
||||
clear_table(dlg_hst);
|
||||
if (dlg_enter_name)
|
||||
EndDialog(hWnd, 1);
|
||||
else
|
||||
EndDialog(hWnd, 0);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
ImGui::SetItemDefaultFocus();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Cancel", ImVec2(120, 0)))
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
dlg_enter_name = 0;
|
||||
EndDialog(hWnd, 0);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void high_score::show_high_scores(HWND hDlg, high_score_struct* table)
|
||||
{
|
||||
high_score_struct* tablePtr = table;
|
||||
int nextPosition = 0;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
if (dlg_enter_name == 1 && dlg_position == i)
|
||||
{
|
||||
hsdlg_show_score(hDlg, " ", dlg_score, i);
|
||||
nextPosition = 1;
|
||||
}
|
||||
hsdlg_show_score(hDlg, tablePtr->Name, tablePtr->Score, i + nextPosition);
|
||||
++tablePtr;
|
||||
}
|
||||
}
|
||||
|
||||
void high_score::hsdlg_show_score(HWND hDlg, LPCSTR name, int score, int position)
|
||||
{
|
||||
CHAR scoreStr[36];
|
||||
if (position < 5)
|
||||
{
|
||||
score::string_format(score, scoreStr);
|
||||
if (scoreStr[0])
|
||||
{
|
||||
SetWindowTextA(GetDlgItem(hDlg, position + DLG_HIGHSCORES_StaticName1), name);
|
||||
SetWindowTextA(GetDlgItem(hDlg, position + DLG_HIGHSCORES_Score1), scoreStr);
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,13 @@ public:
|
||||
|
||||
static void show_high_score_dialog(high_score_struct* table);
|
||||
static void show_and_set_high_score_dialog(high_score_struct* table, int score, int pos, LPCSTR defaultName);
|
||||
static INT_PTR __stdcall HighScore(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static void show_high_scores(HWND hDlg, high_score_struct* table);
|
||||
static void hsdlg_show_score(HWND hDlg, LPCSTR name, int score, int position);
|
||||
static void RenderHighScoreDialog();
|
||||
private :
|
||||
static int dlg_enter_name;
|
||||
static int dlg_score;
|
||||
static int dlg_position;
|
||||
static LPCSTR default_name;
|
||||
static char default_name[32];
|
||||
static high_score_struct* dlg_hst;
|
||||
static winhelp_entry help[21];
|
||||
static bool ShowDialog;
|
||||
};
|
||||
|
||||
123
SpaceCadetPinball/imconfig.h
Normal file
123
SpaceCadetPinball/imconfig.h
Normal file
@@ -0,0 +1,123 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
|
||||
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
|
||||
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
|
||||
//-----------------------------------------------------------------------------
|
||||
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
|
||||
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
|
||||
//-----------------------------------------------------------------------------
|
||||
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
|
||||
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
|
||||
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
|
||||
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
//---- Define assertion handler. Defaults to calling assert().
|
||||
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
|
||||
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
|
||||
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
|
||||
|
||||
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
|
||||
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
|
||||
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
|
||||
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
|
||||
//#define IMGUI_API __declspec( dllexport )
|
||||
//#define IMGUI_API __declspec( dllimport )
|
||||
|
||||
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
|
||||
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
//---- Disable all of Dear ImGui or don't implement standard windows.
|
||||
// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp.
|
||||
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
|
||||
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended.
|
||||
//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger window: ShowMetricsWindow() will be empty.
|
||||
|
||||
//---- Don't implement some functions to reduce linkage requirements.
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
|
||||
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
|
||||
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
|
||||
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
|
||||
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
|
||||
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
|
||||
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
|
||||
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
|
||||
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
|
||||
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
|
||||
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
|
||||
|
||||
//---- Include imgui_user.h at the end of imgui.h as a convenience
|
||||
//#define IMGUI_INCLUDE_IMGUI_USER_H
|
||||
|
||||
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
|
||||
//#define IMGUI_USE_BGRA_PACKED_COLOR
|
||||
|
||||
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
|
||||
//#define IMGUI_USE_WCHAR32
|
||||
|
||||
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
|
||||
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
|
||||
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
|
||||
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
|
||||
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
|
||||
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
|
||||
|
||||
//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
|
||||
// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf.
|
||||
// #define IMGUI_USE_STB_SPRINTF
|
||||
|
||||
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
|
||||
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
|
||||
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
|
||||
//#define IMGUI_ENABLE_FREETYPE
|
||||
|
||||
//---- Use stb_truetype to build and rasterize the font atlas (default)
|
||||
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
|
||||
//#define IMGUI_ENABLE_STB_TRUETYPE
|
||||
|
||||
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
|
||||
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
|
||||
/*
|
||||
#define IM_VEC2_CLASS_EXTRA \
|
||||
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
|
||||
operator MyVec2() const { return MyVec2(x,y); }
|
||||
|
||||
#define IM_VEC4_CLASS_EXTRA \
|
||||
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
|
||||
operator MyVec4() const { return MyVec4(x,y,z,w); }
|
||||
*/
|
||||
|
||||
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
|
||||
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
|
||||
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
|
||||
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
|
||||
//#define ImDrawIdx unsigned int
|
||||
|
||||
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
|
||||
//struct ImDrawList;
|
||||
//struct ImDrawCmd;
|
||||
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
|
||||
//#define ImDrawCallback MyImDrawCallback
|
||||
|
||||
//---- Debug Tools: Macro to break in Debugger
|
||||
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
|
||||
//#define IM_DEBUG_BREAK IM_ASSERT(0)
|
||||
//#define IM_DEBUG_BREAK __debugbreak()
|
||||
|
||||
//---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
|
||||
// (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
|
||||
// This adds a small runtime cost which is why it is not enabled by default.
|
||||
//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
|
||||
|
||||
//---- Debug Tools: Enable slower asserts
|
||||
//#define IMGUI_DEBUG_PARANOID
|
||||
|
||||
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
|
||||
/*
|
||||
namespace ImGui
|
||||
{
|
||||
void MyFunction(const char* name, const MyMatrix44& v);
|
||||
}
|
||||
*/
|
||||
11866
SpaceCadetPinball/imgui.cpp
Normal file
11866
SpaceCadetPinball/imgui.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2904
SpaceCadetPinball/imgui.h
Normal file
2904
SpaceCadetPinball/imgui.h
Normal file
File diff suppressed because it is too large
Load Diff
7652
SpaceCadetPinball/imgui_demo.cpp
Normal file
7652
SpaceCadetPinball/imgui_demo.cpp
Normal file
File diff suppressed because it is too large
Load Diff
4177
SpaceCadetPinball/imgui_draw.cpp
Normal file
4177
SpaceCadetPinball/imgui_draw.cpp
Normal file
File diff suppressed because it is too large
Load Diff
443
SpaceCadetPinball/imgui_impl_sdl.cpp
Normal file
443
SpaceCadetPinball/imgui_impl_sdl.cpp
Normal file
@@ -0,0 +1,443 @@
|
||||
// dear imgui: Platform Backend for SDL2
|
||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
||||
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||
// (Prefer SDL 2.0.5+ for full feature support.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
|
||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||
// Missing features:
|
||||
// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 2021-08-17: Calling io.AddFocusEvent() on SDL_WINDOWEVENT_FOCUS_GAINED/SDL_WINDOWEVENT_FOCUS_LOST.
|
||||
// 2021-07-29: Inputs: MousePos is correctly reported when the host platform window is hovered but not focused (using SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, requires SDL 2.0.5+)
|
||||
// 2021-06-29: *BREAKING CHANGE* Removed 'SDL_Window* window' parameter to ImGui_ImplSDL2_NewFrame() which was unnecessary.
|
||||
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
|
||||
// 2021-03-22: Rework global mouse pos availability check listing supported platforms explicitly, effectively fixing mouse access on Raspberry Pi. (#2837, #3950)
|
||||
// 2020-05-25: Misc: Report a zero display-size when window is minimized, to be consistent with other backends.
|
||||
// 2020-02-20: Inputs: Fixed mapping for ImGuiKey_KeyPadEnter (using SDL_SCANCODE_KP_ENTER instead of SDL_SCANCODE_RETURN2).
|
||||
// 2019-12-17: Inputs: On Wayland, use SDL_GetMouseState (because there is no global mouse state).
|
||||
// 2019-12-05: Inputs: Added support for ImGuiMouseCursor_NotAllowed mouse cursor.
|
||||
// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
|
||||
// 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
|
||||
// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
|
||||
// 2018-12-21: Inputs: Workaround for Android/iOS which don't seem to handle focus related calls.
|
||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
||||
// 2018-11-14: Changed the signature of ImGui_ImplSDL2_ProcessEvent() to take a 'const SDL_Event*'.
|
||||
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
|
||||
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
|
||||
// 2018-06-08: Misc: Extracted imgui_impl_sdl.cpp/.h away from the old combined SDL2+OpenGL/Vulkan examples.
|
||||
// 2018-06-08: Misc: ImGui_ImplSDL2_InitForOpenGL() now takes a SDL_GLContext parameter.
|
||||
// 2018-05-09: Misc: Fixed clipboard paste memory leak (we didn't call SDL_FreeMemory on the data returned by SDL_GetClipboardText).
|
||||
// 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
|
||||
// 2018-02-16: Inputs: Added support for mouse cursors, honoring ImGui::GetMouseCursor() value.
|
||||
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
||||
// 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
|
||||
// 2018-02-05: Misc: Using SDL_GetPerformanceCounter() instead of SDL_GetTicks() to be able to handle very high framerate (1000+ FPS).
|
||||
// 2018-02-05: Inputs: Keyboard mapping is using scancodes everywhere instead of a confusing mixture of keycodes and scancodes.
|
||||
// 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
|
||||
// 2018-01-19: Inputs: When available (SDL 2.0.4+) using SDL_CaptureMouse() to retrieve coordinates outside of client area when dragging. Otherwise (SDL 2.0.3 and before) testing for SDL_WINDOW_INPUT_FOCUS instead of SDL_WINDOW_MOUSE_FOCUS.
|
||||
// 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
|
||||
// 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
|
||||
// 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
|
||||
// SDL
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
|
||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1
|
||||
#else
|
||||
#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 0
|
||||
#endif
|
||||
#define SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH SDL_VERSION_ATLEAST(2,0,5)
|
||||
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
|
||||
|
||||
// SDL Data
|
||||
struct ImGui_ImplSDL2_Data
|
||||
{
|
||||
SDL_Window* Window;
|
||||
Uint64 Time;
|
||||
bool MousePressed[3];
|
||||
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
|
||||
char* ClipboardTextData;
|
||||
bool MouseCanUseGlobalState;
|
||||
|
||||
ImGui_ImplSDL2_Data() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
|
||||
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
|
||||
// FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
|
||||
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
|
||||
static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData()
|
||||
{
|
||||
return ImGui::GetCurrentContext() ? (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData : NULL;
|
||||
}
|
||||
|
||||
// Functions
|
||||
static const char* ImGui_ImplSDL2_GetClipboardText(void*)
|
||||
{
|
||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||
if (bd->ClipboardTextData)
|
||||
SDL_free(bd->ClipboardTextData);
|
||||
bd->ClipboardTextData = SDL_GetClipboardText();
|
||||
return bd->ClipboardTextData;
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL2_SetClipboardText(void*, const char* text)
|
||||
{
|
||||
SDL_SetClipboardText(text);
|
||||
}
|
||||
|
||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
|
||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
// If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field.
|
||||
bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
if (event->wheel.x > 0) io.MouseWheelH += 1;
|
||||
if (event->wheel.x < 0) io.MouseWheelH -= 1;
|
||||
if (event->wheel.y > 0) io.MouseWheel += 1;
|
||||
if (event->wheel.y < 0) io.MouseWheel -= 1;
|
||||
return true;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
if (event->button.button == SDL_BUTTON_LEFT) { bd->MousePressed[0] = true; }
|
||||
if (event->button.button == SDL_BUTTON_RIGHT) { bd->MousePressed[1] = true; }
|
||||
if (event->button.button == SDL_BUTTON_MIDDLE) { bd->MousePressed[2] = true; }
|
||||
return true;
|
||||
}
|
||||
case SDL_TEXTINPUT:
|
||||
{
|
||||
io.AddInputCharactersUTF8(event->text.text);
|
||||
return true;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
int key = event->key.keysym.scancode;
|
||||
IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
|
||||
io.KeysDown[key] = (event->type == SDL_KEYDOWN);
|
||||
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
|
||||
io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
|
||||
io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
|
||||
#ifdef _WIN32
|
||||
io.KeySuper = false;
|
||||
#else
|
||||
io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
||||
io.AddFocusEvent(true);
|
||||
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
||||
io.AddFocusEvent(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ImGui_ImplSDL2_Init(SDL_Window* window)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IM_ASSERT(io.BackendPlatformUserData == NULL && "Already initialized a platform backend!");
|
||||
|
||||
// Check and store if we are on a SDL backend that supports global mouse position
|
||||
// ("wayland" and "rpi" don't support it, but we chose to use a white-list instead of a black-list)
|
||||
bool mouse_can_use_global_state = false;
|
||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||
const char* sdl_backend = SDL_GetCurrentVideoDriver();
|
||||
const char* global_mouse_whitelist[] = { "windows", "cocoa", "x11", "DIVE", "VMAN" };
|
||||
for (int n = 0; n < IM_ARRAYSIZE(global_mouse_whitelist); n++)
|
||||
if (strncmp(sdl_backend, global_mouse_whitelist[n], strlen(global_mouse_whitelist[n])) == 0)
|
||||
mouse_can_use_global_state = true;
|
||||
#endif
|
||||
|
||||
// Setup backend capabilities flags
|
||||
ImGui_ImplSDL2_Data* bd = IM_NEW(ImGui_ImplSDL2_Data)();
|
||||
io.BackendPlatformUserData = (void*)bd;
|
||||
io.BackendPlatformName = "imgui_impl_sdl";
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||
|
||||
bd->Window = window;
|
||||
bd->MouseCanUseGlobalState = mouse_can_use_global_state;
|
||||
|
||||
// Keyboard mapping. Dear ImGui will use those indices to peek into the io.KeysDown[] array.
|
||||
io.KeyMap[ImGuiKey_Tab] = SDL_SCANCODE_TAB;
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = SDL_SCANCODE_LEFT;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = SDL_SCANCODE_RIGHT;
|
||||
io.KeyMap[ImGuiKey_UpArrow] = SDL_SCANCODE_UP;
|
||||
io.KeyMap[ImGuiKey_DownArrow] = SDL_SCANCODE_DOWN;
|
||||
io.KeyMap[ImGuiKey_PageUp] = SDL_SCANCODE_PAGEUP;
|
||||
io.KeyMap[ImGuiKey_PageDown] = SDL_SCANCODE_PAGEDOWN;
|
||||
io.KeyMap[ImGuiKey_Home] = SDL_SCANCODE_HOME;
|
||||
io.KeyMap[ImGuiKey_End] = SDL_SCANCODE_END;
|
||||
io.KeyMap[ImGuiKey_Insert] = SDL_SCANCODE_INSERT;
|
||||
io.KeyMap[ImGuiKey_Delete] = SDL_SCANCODE_DELETE;
|
||||
io.KeyMap[ImGuiKey_Backspace] = SDL_SCANCODE_BACKSPACE;
|
||||
io.KeyMap[ImGuiKey_Space] = SDL_SCANCODE_SPACE;
|
||||
io.KeyMap[ImGuiKey_Enter] = SDL_SCANCODE_RETURN;
|
||||
io.KeyMap[ImGuiKey_Escape] = SDL_SCANCODE_ESCAPE;
|
||||
io.KeyMap[ImGuiKey_KeyPadEnter] = SDL_SCANCODE_KP_ENTER;
|
||||
io.KeyMap[ImGuiKey_A] = SDL_SCANCODE_A;
|
||||
io.KeyMap[ImGuiKey_C] = SDL_SCANCODE_C;
|
||||
io.KeyMap[ImGuiKey_V] = SDL_SCANCODE_V;
|
||||
io.KeyMap[ImGuiKey_X] = SDL_SCANCODE_X;
|
||||
io.KeyMap[ImGuiKey_Y] = SDL_SCANCODE_Y;
|
||||
io.KeyMap[ImGuiKey_Z] = SDL_SCANCODE_Z;
|
||||
|
||||
io.SetClipboardTextFn = ImGui_ImplSDL2_SetClipboardText;
|
||||
io.GetClipboardTextFn = ImGui_ImplSDL2_GetClipboardText;
|
||||
io.ClipboardUserData = NULL;
|
||||
|
||||
// Load mouse cursors
|
||||
bd->MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
bd->MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
||||
bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
||||
bd->MouseCursors[ImGuiMouseCursor_Hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
|
||||
bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo info;
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWindowWMInfo(window, &info))
|
||||
io.ImeWindowHandle = info.info.win.window;
|
||||
#else
|
||||
(void)window;
|
||||
#endif
|
||||
|
||||
// Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't emit the event.
|
||||
// Without this, when clicking to gain focus, our widgets wouldn't activate even though they showed as hovered.
|
||||
// (This is unfortunately a global SDL setting, so enabling it might have a side-effect on your application.
|
||||
// It is unlikely to make a difference, but if your app absolutely needs to ignore the initial on-focus click:
|
||||
// you can ignore SDL_MOUSEBUTTONDOWN events coming right after a SDL_WINDOWEVENT_FOCUS_GAINED)
|
||||
#if SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH
|
||||
SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context)
|
||||
{
|
||||
IM_UNUSED(sdl_gl_context); // Viewport branch will need this.
|
||||
return ImGui_ImplSDL2_Init(window);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
|
||||
{
|
||||
#if !SDL_HAS_VULKAN
|
||||
IM_ASSERT(0 && "Unsupported");
|
||||
#endif
|
||||
return ImGui_ImplSDL2_Init(window);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
|
||||
{
|
||||
#if !defined(_WIN32)
|
||||
IM_ASSERT(0 && "Unsupported");
|
||||
#endif
|
||||
return ImGui_ImplSDL2_Init(window);
|
||||
}
|
||||
|
||||
bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window)
|
||||
{
|
||||
return ImGui_ImplSDL2_Init(window);
|
||||
}
|
||||
|
||||
void ImGui_ImplSDL2_Shutdown()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||
|
||||
if (bd->ClipboardTextData)
|
||||
SDL_free(bd->ClipboardTextData);
|
||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
|
||||
SDL_FreeCursor(bd->MouseCursors[cursor_n]);
|
||||
|
||||
io.BackendPlatformName = NULL;
|
||||
io.BackendPlatformUserData = NULL;
|
||||
IM_DELETE(bd);
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
|
||||
{
|
||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
ImVec2 mouse_pos_prev = io.MousePos;
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
|
||||
// Update mouse buttons
|
||||
int mouse_x_local, mouse_y_local;
|
||||
Uint32 mouse_buttons = SDL_GetMouseState(&mouse_x_local, &mouse_y_local);
|
||||
io.MouseDown[0] = bd->MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
|
||||
io.MouseDown[1] = bd->MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
|
||||
io.MouseDown[2] = bd->MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
|
||||
bd->MousePressed[0] = bd->MousePressed[1] = bd->MousePressed[2] = false;
|
||||
|
||||
// Obtain focused and hovered window. We forward mouse input when focused or when hovered (and no other window is capturing)
|
||||
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
|
||||
SDL_Window* focused_window = SDL_GetKeyboardFocus();
|
||||
SDL_Window* hovered_window = SDL_HAS_MOUSE_FOCUS_CLICKTHROUGH ? SDL_GetMouseFocus() : NULL; // This is better but is only reliably useful with SDL 2.0.5+ and SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH.
|
||||
SDL_Window* mouse_window = NULL;
|
||||
if (hovered_window && bd->Window == hovered_window)
|
||||
mouse_window = hovered_window;
|
||||
else if (focused_window && bd->Window == focused_window)
|
||||
mouse_window = focused_window;
|
||||
|
||||
// SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside
|
||||
SDL_CaptureMouse(ImGui::IsAnyMouseDown() ? SDL_TRUE : SDL_FALSE);
|
||||
#else
|
||||
// SDL 2.0.3 and non-windowed systems: single-viewport only
|
||||
SDL_Window* mouse_window = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) ? bd->Window : NULL;
|
||||
#endif
|
||||
|
||||
if (mouse_window == NULL)
|
||||
return;
|
||||
|
||||
// Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||||
if (io.WantSetMousePos)
|
||||
SDL_WarpMouseInWindow(bd->Window, (int)mouse_pos_prev.x, (int)mouse_pos_prev.y);
|
||||
|
||||
// Set Dear ImGui mouse position from OS position + get buttons. (this is the common behavior)
|
||||
if (bd->MouseCanUseGlobalState)
|
||||
{
|
||||
// Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
|
||||
// Unlike local position obtained earlier this will be valid when straying out of bounds.
|
||||
int mouse_x_global, mouse_y_global;
|
||||
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
|
||||
int window_x, window_y;
|
||||
SDL_GetWindowPosition(mouse_window, &window_x, &window_y);
|
||||
io.MousePos = ImVec2((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
|
||||
}
|
||||
else
|
||||
{
|
||||
io.MousePos = ImVec2((float)mouse_x_local, (float)mouse_y_local);
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL2_UpdateMouseCursor()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
||||
return;
|
||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||
|
||||
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
||||
{
|
||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||
SDL_ShowCursor(SDL_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show OS mouse cursor
|
||||
SDL_SetCursor(bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
|
||||
SDL_ShowCursor(SDL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
static void ImGui_ImplSDL2_UpdateGamepads()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
|
||||
return;
|
||||
|
||||
// Get gamepad
|
||||
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
|
||||
if (!game_controller)
|
||||
{
|
||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
return;
|
||||
}
|
||||
|
||||
// Update gamepad inputs
|
||||
#define MAP_BUTTON(NAV_NO, BUTTON_NO) { io.NavInputs[NAV_NO] = (SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0) ? 1.0f : 0.0f; }
|
||||
#define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
|
||||
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
||||
MAP_BUTTON(ImGuiNavInput_Activate, SDL_CONTROLLER_BUTTON_A); // Cross / A
|
||||
MAP_BUTTON(ImGuiNavInput_Cancel, SDL_CONTROLLER_BUTTON_B); // Circle / B
|
||||
MAP_BUTTON(ImGuiNavInput_Menu, SDL_CONTROLLER_BUTTON_X); // Square / X
|
||||
MAP_BUTTON(ImGuiNavInput_Input, SDL_CONTROLLER_BUTTON_Y); // Triangle / Y
|
||||
MAP_BUTTON(ImGuiNavInput_DpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT); // D-Pad Left
|
||||
MAP_BUTTON(ImGuiNavInput_DpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); // D-Pad Right
|
||||
MAP_BUTTON(ImGuiNavInput_DpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP); // D-Pad Up
|
||||
MAP_BUTTON(ImGuiNavInput_DpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN); // D-Pad Down
|
||||
MAP_BUTTON(ImGuiNavInput_FocusPrev, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
|
||||
MAP_BUTTON(ImGuiNavInput_FocusNext, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
|
||||
MAP_BUTTON(ImGuiNavInput_TweakSlow, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
|
||||
MAP_BUTTON(ImGuiNavInput_TweakFast, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
|
||||
MAP_ANALOG(ImGuiNavInput_LStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
#undef MAP_BUTTON
|
||||
#undef MAP_ANALOG
|
||||
}
|
||||
|
||||
void ImGui_ImplSDL2_NewFrame()
|
||||
{
|
||||
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
|
||||
IM_ASSERT(bd != NULL && "Did you call ImGui_ImplSDL2_Init()?");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// Setup display size (every frame to accommodate for window resizing)
|
||||
int w, h;
|
||||
int display_w, display_h;
|
||||
SDL_GetWindowSize(bd->Window, &w, &h);
|
||||
if (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_MINIMIZED)
|
||||
w = h = 0;
|
||||
SDL_GL_GetDrawableSize(bd->Window, &display_w, &display_h);
|
||||
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||
if (w > 0 && h > 0)
|
||||
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
|
||||
|
||||
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
|
||||
static Uint64 frequency = SDL_GetPerformanceFrequency();
|
||||
Uint64 current_time = SDL_GetPerformanceCounter();
|
||||
io.DeltaTime = bd->Time > 0 ? (float)((double)(current_time - bd->Time) / frequency) : (float)(1.0f / 60.0f);
|
||||
bd->Time = current_time;
|
||||
|
||||
ImGui_ImplSDL2_UpdateMousePosAndButtons();
|
||||
ImGui_ImplSDL2_UpdateMouseCursor();
|
||||
|
||||
// Update game controllers (if enabled and available)
|
||||
ImGui_ImplSDL2_UpdateGamepads();
|
||||
}
|
||||
34
SpaceCadetPinball/imgui_impl_sdl.h
Normal file
34
SpaceCadetPinball/imgui_impl_sdl.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// dear imgui: Platform Backend for SDL2
|
||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
||||
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
|
||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||
// Missing features:
|
||||
// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
|
||||
struct SDL_Window;
|
||||
typedef union SDL_Event SDL_Event;
|
||||
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter
|
||||
#endif
|
||||
2745
SpaceCadetPinball/imgui_internal.h
Normal file
2745
SpaceCadetPinball/imgui_internal.h
Normal file
File diff suppressed because it is too large
Load Diff
676
SpaceCadetPinball/imgui_sdl.cpp
Normal file
676
SpaceCadetPinball/imgui_sdl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
17
SpaceCadetPinball/imgui_sdl.h
Normal file
17
SpaceCadetPinball/imgui_sdl.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
struct ImDrawData;
|
||||
struct SDL_Renderer;
|
||||
|
||||
namespace ImGuiSDL
|
||||
{
|
||||
// Call this to initialize the SDL renderer device that is internally used by the renderer.
|
||||
void Initialize(SDL_Renderer* renderer, int windowWidth, int windowHeight);
|
||||
// Call this before destroying your SDL renderer or ImGui to ensure that proper cleanup is done. This doesn't do anything critically important though,
|
||||
// so if you're fine with small memory leaks at the end of your application, you can even omit this.
|
||||
void Deinitialize();
|
||||
|
||||
// Call this every frame after ImGui::Render with ImGui::GetDrawData(). This will use the SDL_Renderer provided to the interfrace with Initialize
|
||||
// to draw the contents of the draw data to the screen.
|
||||
void Render(ImDrawData* drawData);
|
||||
}
|
||||
4049
SpaceCadetPinball/imgui_tables.cpp
Normal file
4049
SpaceCadetPinball/imgui_tables.cpp
Normal file
File diff suppressed because it is too large
Load Diff
8208
SpaceCadetPinball/imgui_widgets.cpp
Normal file
8208
SpaceCadetPinball/imgui_widgets.cpp
Normal file
File diff suppressed because it is too large
Load Diff
639
SpaceCadetPinball/imstb_rectpack.h
Normal file
639
SpaceCadetPinball/imstb_rectpack.h
Normal file
File diff suppressed because it is too large
Load Diff
1449
SpaceCadetPinball/imstb_textedit.h
Normal file
1449
SpaceCadetPinball/imstb_textedit.h
Normal file
File diff suppressed because it is too large
Load Diff
4903
SpaceCadetPinball/imstb_truetype.h
Normal file
4903
SpaceCadetPinball/imstb_truetype.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -95,6 +95,7 @@ void options::init(HMENU menuHandle)
|
||||
Options.RightTableBumpKey = Options.RightTableBumpKeyDft;
|
||||
Options.Players = 1;
|
||||
Options.BottomTableBumpKey = Options.BottomTableBumpKeyDft;
|
||||
Options.UniformScaling = true;
|
||||
/*Options.Sounds = get_int(nullptr, "Sounds", Options.Sounds);
|
||||
Options.Music = get_int(nullptr, "Music", Options.Music);
|
||||
Options.Average = get_int(nullptr, "Average", Options.Average);
|
||||
@@ -341,7 +342,7 @@ void options::toggle(UINT uIDCheckItem)
|
||||
Options.UniformScaling ^= true;
|
||||
menu_check(Menu1_WindowUniformScale, Options.UniformScaling);
|
||||
fullscrn::window_size_changed();
|
||||
fullscrn::paint();
|
||||
pb::paint();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -387,7 +388,7 @@ void options::init_resolution()
|
||||
|
||||
void options::keyboard()
|
||||
{
|
||||
DialogBoxParamA(nullptr, "KEYMAPPER", nullptr, KeyMapDlgProc, 0);
|
||||
//DialogBoxParamA(nullptr, "KEYMAPPER", nullptr, KeyMapDlgProc, 0);
|
||||
}
|
||||
|
||||
INT_PTR _stdcall options::KeyMapDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
#include "SDL.h"
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
//https://github.com/ocornut/imgui 7b913db1ce9dd2fd98e5790aa59974dd4496be3b
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
//https://github.com/Tyyppi77/imgui_sdl 01deb04b102b6a1c15c7fdec1977a2c96a885e6f
|
||||
#include "imgui_sdl.h"
|
||||
|
||||
//typedef const char* LPCSTR;
|
||||
//typedef int HINSTANCE;
|
||||
//typedef int HWND;
|
||||
|
||||
@@ -1,304 +0,0 @@
|
||||
#include "pch.h"
|
||||
#include "splash.h"
|
||||
|
||||
|
||||
#include "memory.h"
|
||||
#include "pinball.h"
|
||||
|
||||
HINSTANCE splash::HInstance;
|
||||
HGDIOBJ splash::OriginalDcBitmap = nullptr;
|
||||
|
||||
splash_struct* splash::splash_screen(HINSTANCE hInstance, LPCSTR bmpName1, LPCSTR bmpName2)
|
||||
{
|
||||
WNDCLASSA WndClass{};
|
||||
tagRECT Rect{};
|
||||
|
||||
auto splashStruct = memory::allocate<splash_struct>();
|
||||
if (!splashStruct)
|
||||
return nullptr;
|
||||
|
||||
lstrcpyA(splashStruct->BmpName1, bmpName1);
|
||||
lstrcpyA(splashStruct->BmpName2, bmpName2);
|
||||
if (!HInstance)
|
||||
{
|
||||
HInstance = hInstance;
|
||||
WndClass.style = 0;
|
||||
WndClass.lpfnWndProc = splash_message_handler;
|
||||
WndClass.cbClsExtra = 0;
|
||||
WndClass.cbWndExtra = 4;
|
||||
WndClass.hInstance = hInstance;
|
||||
WndClass.hIcon = nullptr;
|
||||
WndClass.hCursor = LoadCursorA(nullptr, IDC_ARROW);
|
||||
WndClass.hbrBackground = nullptr;
|
||||
WndClass.lpszMenuName = "";
|
||||
WndClass.lpszClassName = "3DPB_SPLASH_CLASS";
|
||||
RegisterClassA(&WndClass);
|
||||
}
|
||||
splashStruct->Bitmap = nullptr;
|
||||
HWND windowHandle = CreateWindowExA(0, "3DPB_SPLASH_CLASS", "", 0x80000000, -10, -10, 1, 1,
|
||||
nullptr, nullptr, HInstance, nullptr);
|
||||
splashStruct->WindowHandle = windowHandle;
|
||||
if (!windowHandle)
|
||||
{
|
||||
memory::free(splashStruct);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SetWindowLongPtrA(windowHandle, -21, reinterpret_cast<LONG_PTR>(splashStruct));
|
||||
GetWindowRect(GetDesktopWindow(), &Rect);
|
||||
splash_bitmap_setup(splashStruct);
|
||||
//MoveWindow(splashStruct->WindowHandle, 0, 0, Rect.right - Rect.left, Rect.bottom - Rect.top, 0);
|
||||
|
||||
/*Mod - less intrusive splash*/
|
||||
auto centerX = (Rect.right - Rect.left - splashStruct->Width) / 2;
|
||||
auto CenterY = (Rect.bottom - Rect.top - splashStruct->Height) / 2;
|
||||
MoveWindow(splashStruct->WindowHandle, centerX, CenterY, splashStruct->Width, splashStruct->Height, 0);
|
||||
|
||||
ShowWindow(splashStruct->WindowHandle, 8);
|
||||
SetFocus(splashStruct->WindowHandle);
|
||||
UpdateWindow(splashStruct->WindowHandle);
|
||||
return splashStruct;
|
||||
}
|
||||
|
||||
void splash::splash_bitmap_setup(splash_struct* splashStruct)
|
||||
{
|
||||
HBITMAP bmpHandle2;
|
||||
BITMAP bmp{};
|
||||
|
||||
HBITMAP bmpHandle1 = nullptr;
|
||||
HDC desktopDC = GetDC(GetDesktopWindow());
|
||||
if (desktopDC)
|
||||
{
|
||||
splashStruct->DrawingContext = CreateCompatibleDC(desktopDC);
|
||||
bmpHandle1 = CreateCompatibleBitmap(desktopDC, 10, 10);
|
||||
ReleaseDC(splashStruct->WindowHandle, desktopDC);
|
||||
if (bmpHandle1)
|
||||
{
|
||||
if (splashStruct->DrawingContext)
|
||||
{
|
||||
OriginalDcBitmap = SelectObject(splashStruct->DrawingContext, bmpHandle1);
|
||||
if ((GetDeviceCaps(splashStruct->DrawingContext, RASTERCAPS) & RC_PALETTE) != 0
|
||||
|| GetDeviceCaps(splashStruct->DrawingContext, NUMCOLORS) >= 256)
|
||||
{
|
||||
bmpHandle2 = load_title_bitmap(HInstance, splashStruct->DrawingContext, splashStruct->BmpName1, 10,
|
||||
236, &splashStruct->Palette);
|
||||
}
|
||||
else
|
||||
{
|
||||
bmpHandle2 = LoadBitmapA(HInstance, splashStruct->BmpName2);
|
||||
splashStruct->Palette = nullptr;
|
||||
}
|
||||
splashStruct->Bitmap = bmpHandle2;
|
||||
|
||||
if (bmpHandle2)
|
||||
{
|
||||
SelectObject(splashStruct->DrawingContext, bmpHandle2);
|
||||
DeleteObject(bmpHandle1);
|
||||
GetObjectA(splashStruct->Bitmap, sizeof(BITMAP), &bmp);
|
||||
splashStruct->Width = bmp.bmWidth;
|
||||
splashStruct->Height = bmp.bmHeight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetLastError();
|
||||
}
|
||||
}
|
||||
|
||||
if (splashStruct->Palette)
|
||||
DeleteObject(splashStruct->Palette);
|
||||
if (splashStruct->WindowHandle)
|
||||
DestroyWindow(splashStruct->WindowHandle);
|
||||
if (bmpHandle1)
|
||||
DeleteObject(bmpHandle1);
|
||||
if (splashStruct->DrawingContext)
|
||||
DeleteDC(splashStruct->DrawingContext);
|
||||
splashStruct->Bitmap = nullptr;
|
||||
}
|
||||
|
||||
HBITMAP splash::load_title_bitmap(HMODULE hModule, HDC hdc, LPCSTR lpName, UINT iStart, int iEnd, HPALETTE* palettePtr)
|
||||
{
|
||||
LOGPALETTEx256 plpal;
|
||||
|
||||
auto resH = FindResourceA(hModule, lpName, RT_BITMAP);
|
||||
if (!resH)
|
||||
return nullptr;
|
||||
auto resHGlobal = LoadResource(hModule, resH);
|
||||
if (!resHGlobal)
|
||||
return nullptr;
|
||||
|
||||
auto bmp = static_cast<BITMAPINFO*>(LockResource(resHGlobal));
|
||||
int numColors = bmp->bmiHeader.biClrUsed;
|
||||
if (!numColors)
|
||||
numColors = 1 << LOBYTE(bmp->bmiHeader.biBitCount);
|
||||
if (bmp->bmiHeader.biBitCount > 4u)
|
||||
{
|
||||
*palettePtr = splash_init_palette(&plpal);
|
||||
if (*palettePtr)
|
||||
{
|
||||
int cEntries = 0;
|
||||
if (iEnd > 0)
|
||||
{
|
||||
auto dst = &plpal.palPalEntry[iStart];
|
||||
auto src = &bmp->bmiColors[0];
|
||||
for (; cEntries < iEnd && cEntries < numColors; ++cEntries)
|
||||
{
|
||||
dst->peRed = src->rgbRed;
|
||||
dst->peGreen = src->rgbGreen;
|
||||
dst->peBlue = src->rgbBlue;
|
||||
dst->peFlags = 4;
|
||||
src++;
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
SetPaletteEntries(*palettePtr, iStart, cEntries, &plpal.palPalEntry[iStart]);
|
||||
SelectPalette(hdc, *palettePtr, 0);
|
||||
RealizePalette(hdc);
|
||||
}
|
||||
}
|
||||
|
||||
auto resBmp = CreateDIBitmap(hdc, &bmp->bmiHeader, 4u, &bmp->bmiColors[numColors], bmp, 0);
|
||||
FreeResource(resHGlobal);
|
||||
return resBmp;
|
||||
}
|
||||
|
||||
HPALETTE splash::splash_init_palette(LOGPALETTE* plpal)
|
||||
{
|
||||
plpal->palVersion = 768;
|
||||
plpal->palNumEntries = 256;
|
||||
auto hPalette = CreatePalette(static_cast<const LOGPALETTE*>(plpal));
|
||||
auto dc = GetDC(GetDesktopWindow());
|
||||
GetDeviceCaps(dc, RASTERCAPS);
|
||||
if (GetDeviceCaps(dc, SIZEPALETTE) != 256)
|
||||
{
|
||||
if (hPalette)
|
||||
DeleteObject(hPalette);
|
||||
ReleaseDC(GetDesktopWindow(), dc);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SetSystemPaletteUse(dc, 2u);
|
||||
SetSystemPaletteUse(dc, 1u);
|
||||
auto hPal = SelectPalette(dc, hPalette, 0);
|
||||
RealizePalette(dc);
|
||||
SelectPalette(dc, hPal, 0);
|
||||
RealizePalette(dc);
|
||||
GetSystemPaletteEntries(dc, 0, 256u, plpal->palPalEntry);
|
||||
ReleaseDC(GetDesktopWindow(), dc);
|
||||
|
||||
auto dst = &plpal->palPalEntry[0];
|
||||
for (auto index = 256; index; --index)
|
||||
{
|
||||
dst->peFlags = 0;
|
||||
dst++;
|
||||
}
|
||||
|
||||
dst = &plpal->palPalEntry[10];
|
||||
for (auto index = 10; index < 246; ++index)
|
||||
{
|
||||
dst->peRed = index;
|
||||
dst->peGreen = index;
|
||||
dst->peBlue = index;
|
||||
dst->peFlags = 4;
|
||||
dst++;
|
||||
}
|
||||
ResizePalette(hPalette, 256u);
|
||||
SetPaletteEntries(hPalette, 0, 256u, plpal->palPalEntry);
|
||||
return hPalette;
|
||||
}
|
||||
|
||||
void splash::splash_paint(splash_struct* splashStruct, HDC dc)
|
||||
{
|
||||
tagRECT Rect{};
|
||||
|
||||
if (splashStruct->Bitmap)
|
||||
{
|
||||
GetWindowRect(GetDesktopWindow(), &Rect);
|
||||
splashStruct->CenterX = (Rect.right - Rect.left - splashStruct->Width) / 2;
|
||||
splashStruct->CenterY = (Rect.bottom - Rect.top - splashStruct->Height) / 2;
|
||||
SelectPalette(dc, splashStruct->Palette, 0);
|
||||
RealizePalette(dc);
|
||||
SelectPalette(splashStruct->DrawingContext, splashStruct->Palette, 0);
|
||||
RealizePalette(splashStruct->DrawingContext);
|
||||
/*BitBlt(dc, splashStruct->CenterX, splashStruct->CenterY, splashStruct->Width,
|
||||
splashStruct->Height, splashStruct->DrawingContext, 0, 0, SRCCOPY);*/
|
||||
|
||||
/*Mod - less intrusive splash*/
|
||||
BitBlt(dc, 0, 0, splashStruct->Width, splashStruct->Height,
|
||||
splashStruct->DrawingContext, 0, 0, SRCCOPY);
|
||||
}
|
||||
}
|
||||
|
||||
void splash::splash_destroy(splash_struct* splashStruct)
|
||||
{
|
||||
if (splashStruct)
|
||||
{
|
||||
if (splashStruct->WindowHandle)
|
||||
{
|
||||
DestroyWindow(splashStruct->WindowHandle);
|
||||
splashStruct->WindowHandle = nullptr;
|
||||
|
||||
if (splashStruct->Palette)
|
||||
DeleteObject(splashStruct->Palette);
|
||||
splashStruct->Palette = nullptr;
|
||||
|
||||
if (splashStruct->DrawingContext)
|
||||
{
|
||||
if (OriginalDcBitmap)
|
||||
SelectObject(splashStruct->DrawingContext, OriginalDcBitmap);
|
||||
DeleteDC(splashStruct->DrawingContext);
|
||||
}
|
||||
if (splashStruct->Bitmap)
|
||||
DeleteObject(splashStruct->Bitmap);
|
||||
}
|
||||
memory::free(splashStruct);
|
||||
}
|
||||
if (HInstance)
|
||||
{
|
||||
UnregisterClassA("3DPB_SPLASH_CLASS", HInstance);
|
||||
HInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void splash::splash_hide(splash_struct* splashStruct)
|
||||
{
|
||||
if (splashStruct && splashStruct->WindowHandle)
|
||||
{
|
||||
HDC dc = GetDC(splashStruct->WindowHandle);
|
||||
BitBlt(dc, 0, 0, splashStruct->CenterX, splashStruct->CenterY, dc, 0, 0, 0x42u);
|
||||
ReleaseDC(splashStruct->WindowHandle, dc);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT splash::splash_message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
tagPAINTSTRUCT Paint{};
|
||||
|
||||
switch (Msg)
|
||||
{
|
||||
case WM_PAINT:
|
||||
{
|
||||
auto splashStruct = reinterpret_cast<splash_struct*>(GetWindowLongPtrA(hWnd, -21));
|
||||
BeginPaint(hWnd, &Paint);
|
||||
EndPaint(hWnd, &Paint);
|
||||
auto dc = GetDC(hWnd);
|
||||
if (dc)
|
||||
{
|
||||
if (splashStruct)
|
||||
{
|
||||
BitBlt(dc, 0, 0, 10000, 10000, dc, 0, 0, BLACKNESS);
|
||||
splash_paint(splashStruct, dc);
|
||||
}
|
||||
ReleaseDC(hWnd, dc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_ERASEBKGND:
|
||||
break;
|
||||
default:
|
||||
return DefWindowProcA(hWnd, Msg, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
struct LOGPALETTEx256;
|
||||
|
||||
struct splash_struct
|
||||
{
|
||||
HWND WindowHandle;
|
||||
HPALETTE Palette;
|
||||
HBITMAP Bitmap;
|
||||
HDC DrawingContext;
|
||||
int Width;
|
||||
int Height;
|
||||
int CenterX;
|
||||
int CenterY;
|
||||
char BmpName1[200];
|
||||
char BmpName2[200];
|
||||
};
|
||||
|
||||
|
||||
class splash
|
||||
{
|
||||
public:
|
||||
static splash_struct* splash_screen(HINSTANCE hInstance, LPCSTR bmpName1, LPCSTR bmpName2);
|
||||
static void splash_bitmap_setup(splash_struct* splashStruct);
|
||||
static HBITMAP load_title_bitmap(HMODULE hModule, HDC hdc, LPCSTR lpName, UINT iStart, int iEnd,
|
||||
HPALETTE* palettePtr);
|
||||
static HPALETTE splash_init_palette(LOGPALETTE* plpal);
|
||||
static void splash_paint(splash_struct* splashStruct, HDC dc);
|
||||
static void splash_destroy(splash_struct* splashStruct);
|
||||
static void splash_hide(splash_struct* splashStruct);
|
||||
static LRESULT __stdcall splash_message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
private:
|
||||
static HINSTANCE HInstance;
|
||||
static HGDIOBJ OriginalDcBitmap;
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,14 +8,13 @@ public:
|
||||
static int single_step;
|
||||
static SDL_Window* MainWindow;
|
||||
static SDL_Renderer* Renderer;
|
||||
static ImGuiIO* ImIO;
|
||||
|
||||
static int WinMain(LPCSTR lpCmdLine);
|
||||
static LRESULT CALLBACK message_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
static int event_handler(const SDL_Event* event);
|
||||
static void memalloc_failure();
|
||||
static int ProcessWindowMessages();
|
||||
static HDC _GetDC(HWND hWnd);
|
||||
static int a_dialog(HINSTANCE hInstance, HWND hWnd);
|
||||
static void a_dialog();
|
||||
static void end_pause();
|
||||
static void new_game();
|
||||
static void pause();
|
||||
@@ -29,6 +28,8 @@ private:
|
||||
static gdrv_bitmap8 gfr_display;
|
||||
static HCURSOR mouse_hsave;
|
||||
static bool restart;
|
||||
|
||||
static HDC _BeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint);
|
||||
static bool ShowAboutDialog;
|
||||
static bool ShowImGuiDemo;
|
||||
|
||||
static void RenderUi();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user