Update to latest ZWidget
This commit is contained in:
parent
6dd59c7787
commit
d24d5ae2c8
16 changed files with 578 additions and 36 deletions
|
|
@ -24,11 +24,14 @@ static void CheckInitSDL()
|
|||
static InitSDL initsdl;
|
||||
}
|
||||
|
||||
SDL2DisplayWindow::SDL2DisplayWindow(DisplayWindowHost* windowHost) : WindowHost(windowHost)
|
||||
SDL2DisplayWindow::SDL2DisplayWindow(DisplayWindowHost* windowHost, bool popupWindow) : WindowHost(windowHost)
|
||||
{
|
||||
CheckInitSDL();
|
||||
|
||||
int result = SDL_CreateWindowAndRenderer(320, 200, SDL_WINDOW_HIDDEN /*| SDL_WINDOW_ALLOW_HIGHDPI*/, &WindowHandle, &RendererHandle);
|
||||
unsigned int flags = SDL_WINDOW_HIDDEN /*| SDL_WINDOW_ALLOW_HIGHDPI*/;
|
||||
if (popupWindow)
|
||||
flags |= SDL_WINDOW_BORDERLESS;
|
||||
int result = SDL_CreateWindowAndRenderer(320, 200, flags, &WindowHandle, &RendererHandle);
|
||||
if (result != 0)
|
||||
throw std::runtime_error(std::string("Unable to create SDL window:") + SDL_GetError());
|
||||
|
||||
|
|
@ -174,6 +177,24 @@ Rect SDL2DisplayWindow::GetWindowFrame() const
|
|||
return Rect::xywh(x / uiscale, y / uiscale, w / uiscale, h / uiscale);
|
||||
}
|
||||
|
||||
Point SDL2DisplayWindow::MapFromGlobal(const Point& pos) const
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
double uiscale = GetDpiScale();
|
||||
SDL_GetWindowPosition(WindowHandle, &x, &y);
|
||||
return Point(pos.x - x / uiscale, pos.y - y / uiscale);
|
||||
}
|
||||
|
||||
Point SDL2DisplayWindow::MapToGlobal(const Point& pos) const
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
double uiscale = GetDpiScale();
|
||||
SDL_GetWindowPosition(WindowHandle, &x, &y);
|
||||
return Point(pos.x + x / uiscale, pos.y + y / uiscale);
|
||||
}
|
||||
|
||||
Size SDL2DisplayWindow::GetClientSize() const
|
||||
{
|
||||
int w = 0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
class SDL2DisplayWindow : public DisplayWindow
|
||||
{
|
||||
public:
|
||||
SDL2DisplayWindow(DisplayWindowHost* windowHost);
|
||||
SDL2DisplayWindow(DisplayWindowHost* windowHost, bool popupWindow);
|
||||
~SDL2DisplayWindow();
|
||||
|
||||
void SetWindowTitle(const std::string& text) override;
|
||||
|
|
@ -45,6 +45,9 @@ public:
|
|||
std::string GetClipboardText() override;
|
||||
void SetClipboardText(const std::string& text) override;
|
||||
|
||||
Point MapFromGlobal(const Point& pos) const override;
|
||||
Point MapToGlobal(const Point& pos) const override;
|
||||
|
||||
void* GetNativeHandle() override { return WindowHandle; }
|
||||
|
||||
static void DispatchEvent(const SDL_Event& event);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ static std::wstring to_utf16(const std::string& str)
|
|||
return result;
|
||||
}
|
||||
|
||||
Win32DisplayWindow::Win32DisplayWindow(DisplayWindowHost* windowHost) : WindowHost(windowHost)
|
||||
Win32DisplayWindow::Win32DisplayWindow(DisplayWindowHost* windowHost, bool popupWindow) : WindowHost(windowHost)
|
||||
{
|
||||
Windows.push_front(this);
|
||||
WindowsIterator = Windows.begin();
|
||||
|
|
@ -74,7 +74,18 @@ Win32DisplayWindow::Win32DisplayWindow(DisplayWindowHost* windowHost) : WindowHo
|
|||
// WS_CAPTION shows the caption (yay! actually a flag that does what it says it does!)
|
||||
// WS_SYSMENU shows the min/max/close buttons
|
||||
// WS_THICKFRAME makes the window resizable
|
||||
CreateWindowEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, L"ZWidgetWindow", L"", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this);
|
||||
|
||||
DWORD style = 0, exstyle = 0;
|
||||
if (popupWindow)
|
||||
{
|
||||
style = WS_POPUP;
|
||||
}
|
||||
else
|
||||
{
|
||||
exstyle = WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME;
|
||||
style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
|
||||
}
|
||||
CreateWindowEx(exstyle, L"ZWidgetWindow", L"", style, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this);
|
||||
|
||||
/*
|
||||
RAWINPUTDEVICE rid;
|
||||
|
|
@ -246,6 +257,26 @@ Rect Win32DisplayWindow::GetWindowFrame() const
|
|||
return Rect(box.left / dpiscale, box.top / dpiscale, box.right / dpiscale, box.bottom / dpiscale);
|
||||
}
|
||||
|
||||
Point Win32DisplayWindow::MapFromGlobal(const Point& pos) const
|
||||
{
|
||||
double dpiscale = GetDpiScale();
|
||||
POINT point = {};
|
||||
point.x = (LONG)std::round(pos.x / dpiscale);
|
||||
point.y = (LONG)std::round(pos.y / dpiscale);
|
||||
ScreenToClient(WindowHandle, &point);
|
||||
return Point(point.x * dpiscale, point.y * dpiscale);
|
||||
}
|
||||
|
||||
Point Win32DisplayWindow::MapToGlobal(const Point& pos) const
|
||||
{
|
||||
double dpiscale = GetDpiScale();
|
||||
POINT point = {};
|
||||
point.x = (LONG)std::round(pos.x * dpiscale);
|
||||
point.y = (LONG)std::round(pos.y * dpiscale);
|
||||
ClientToScreen(WindowHandle, &point);
|
||||
return Point(point.x / dpiscale, point.y / dpiscale);
|
||||
}
|
||||
|
||||
Size Win32DisplayWindow::GetClientSize() const
|
||||
{
|
||||
RECT box = {};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class Win32DisplayWindow : public DisplayWindow
|
||||
{
|
||||
public:
|
||||
Win32DisplayWindow(DisplayWindowHost* windowHost);
|
||||
Win32DisplayWindow(DisplayWindowHost* windowHost, bool popupWindow);
|
||||
~Win32DisplayWindow();
|
||||
|
||||
void SetWindowTitle(const std::string& text) override;
|
||||
|
|
@ -53,6 +53,9 @@ public:
|
|||
std::string GetClipboardText() override;
|
||||
void SetClipboardText(const std::string& text) override;
|
||||
|
||||
Point MapFromGlobal(const Point& pos) const override;
|
||||
Point MapToGlobal(const Point& pos) const override;
|
||||
|
||||
Point GetLParamPos(LPARAM lparam) const;
|
||||
|
||||
void* GetNativeHandle() override { return reinterpret_cast<void*>(WindowHandle); }
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#include "win32/win32displaywindow.h"
|
||||
|
||||
std::unique_ptr<DisplayWindow> DisplayWindow::Create(DisplayWindowHost* windowHost)
|
||||
std::unique_ptr<DisplayWindow> DisplayWindow::Create(DisplayWindowHost* windowHost, bool popupWindow)
|
||||
{
|
||||
return std::make_unique<Win32DisplayWindow>(windowHost);
|
||||
return std::make_unique<Win32DisplayWindow>(windowHost, popupWindow);
|
||||
}
|
||||
|
||||
void DisplayWindow::ProcessEvents()
|
||||
|
|
@ -43,7 +43,7 @@ void DisplayWindow::StopTimer(void* timerID)
|
|||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
std::unique_ptr<DisplayWindow> DisplayWindow::Create(DisplayWindowHost* windowHost)
|
||||
std::unique_ptr<DisplayWindow> DisplayWindow::Create(DisplayWindowHost* windowHost, bool popupWindow)
|
||||
{
|
||||
throw std::runtime_error("DisplayWindow::Create not implemented");
|
||||
}
|
||||
|
|
@ -82,9 +82,9 @@ void DisplayWindow::StopTimer(void* timerID)
|
|||
|
||||
#include "sdl2/sdl2displaywindow.h"
|
||||
|
||||
std::unique_ptr<DisplayWindow> DisplayWindow::Create(DisplayWindowHost* windowHost)
|
||||
std::unique_ptr<DisplayWindow> DisplayWindow::Create(DisplayWindowHost* windowHost, bool popupWindow)
|
||||
{
|
||||
return std::make_unique<SDL2DisplayWindow>(windowHost);
|
||||
return std::make_unique<SDL2DisplayWindow>(windowHost, popupWindow);
|
||||
}
|
||||
|
||||
void DisplayWindow::ProcessEvents()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue