From ea16d0ffca58637972e480e2204e620473d67d46 Mon Sep 17 00:00:00 2001 From: elasota Date: Mon, 18 May 2020 02:03:17 -0400 Subject: [PATCH] More window chrome improvements --- GpApp/Link.cpp | 4 +- GpApp/Map.cpp | 4 +- GpApp/RoomInfo.cpp | 2 +- GpApp/Settings.cpp | 9 +- GpApp/Tools.cpp | 2 +- GpApp/WindowUtils.cpp | 10 + GpCommon/IGpDisplayDriver.h | 14 +- .../DrawQuadPaletteP_D3D11.cpp | 105 +++--- .../GpDisplayDriverD3D11.cpp | 59 ++- GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h | 10 +- PortabilityLayer/DialogManager.cpp | 60 ++- PortabilityLayer/MenuManager.cpp | 16 +- PortabilityLayer/PLButtonWidget.cpp | 350 +++++++++++++++--- PortabilityLayer/PLButtonWidget.h | 29 +- PortabilityLayer/PLCheckboxWidget.cpp | 113 ------ PortabilityLayer/PLCheckboxWidget.h | 6 +- PortabilityLayer/PLCore.h | 16 - PortabilityLayer/PLEditboxWidget.cpp | 2 +- PortabilityLayer/PLEditboxWidget.h | 2 +- PortabilityLayer/PLIconWidget.cpp | 2 +- PortabilityLayer/PLIconWidget.h | 2 +- PortabilityLayer/PLImageWidget.cpp | 2 +- PortabilityLayer/PLImageWidget.h | 2 +- PortabilityLayer/PLInvisibleWidget.cpp | 2 +- PortabilityLayer/PLInvisibleWidget.h | 2 +- PortabilityLayer/PLLabelWidget.cpp | 2 +- PortabilityLayer/PLLabelWidget.h | 2 +- PortabilityLayer/PLPopupMenuWidget.cpp | 28 +- PortabilityLayer/PLPopupMenuWidget.h | 2 +- PortabilityLayer/PLRadioButtonWidget.cpp | 112 ------ PortabilityLayer/PLRadioButtonWidget.h | 2 +- PortabilityLayer/PLRegions.h | 18 + PortabilityLayer/PLScrollBarWidget.cpp | 2 +- PortabilityLayer/PLScrollBarWidget.h | 2 +- PortabilityLayer/PLWidgets.h | 6 +- PortabilityLayer/PortabilityLayer.vcxproj | 3 +- .../PortabilityLayer.vcxproj.filters | 21 +- PortabilityLayer/WindowManager.cpp | 197 +++++++++- PortabilityLayer/WindowManager.h | 4 + ShaderSrc/DrawQuadPaletteP.hlsl | 3 +- ShaderSrc/DrawQuadPixelConstants.h | 4 + 41 files changed, 804 insertions(+), 429 deletions(-) delete mode 100644 PortabilityLayer/PLCheckboxWidget.cpp delete mode 100644 PortabilityLayer/PLRadioButtonWidget.cpp create mode 100644 PortabilityLayer/PLRegions.h create mode 100644 ShaderSrc/DrawQuadPixelConstants.h diff --git a/GpApp/Link.cpp b/GpApp/Link.cpp index 232e4df..855fc46 100644 --- a/GpApp/Link.cpp +++ b/GpApp/Link.cpp @@ -244,12 +244,12 @@ void OpenLinkWindow (void) basicState.m_text.Set(4, "Link"); basicState.m_window = linkWindow; - linkControl = PortabilityLayer::ButtonWidget::Create(basicState); + linkControl = PortabilityLayer::ButtonWidget::Create(basicState, nullptr); basicState.m_rect = Rect::Create(5, 5, 25, 59); basicState.m_text.Set(6, "Unlink"); basicState.m_window = linkWindow; - unlinkControl = PortabilityLayer::ButtonWidget::Create(basicState); + unlinkControl = PortabilityLayer::ButtonWidget::Create(basicState, nullptr); linkWindow->DrawControls(); diff --git a/GpApp/Map.cpp b/GpApp/Map.cpp index 218a049..1d750f5 100644 --- a/GpApp/Map.cpp +++ b/GpApp/Map.cpp @@ -430,7 +430,7 @@ void OpenMapWindow (void) state.m_window = mapWindow; state.m_max = kMaxNumRoomsH - mapRoomsWide; state.m_state = mapLeftRoom; - mapHScroll = PortabilityLayer::ScrollBarWidget::Create(state); + mapHScroll = PortabilityLayer::ScrollBarWidget::Create(state, nullptr); } if (mapHScroll == nil) @@ -443,7 +443,7 @@ void OpenMapWindow (void) state.m_window = mapWindow; state.m_max = kMaxNumRoomsV - mapRoomsHigh; state.m_state = mapTopRoom; - mapVScroll = PortabilityLayer::ScrollBarWidget::Create(state); + mapVScroll = PortabilityLayer::ScrollBarWidget::Create(state, nullptr); } if (mapVScroll == nil) diff --git a/GpApp/RoomInfo.cpp b/GpApp/RoomInfo.cpp index 9f5b8ba..8c4cdf2 100644 --- a/GpApp/RoomInfo.cpp +++ b/GpApp/RoomInfo.cpp @@ -474,7 +474,7 @@ void DoRoomInfo(void) state.m_resID = kBackgroundsMenuID; state.m_enabled = true; - PortabilityLayer::PopupMenuWidget *roomPopupWidget = PortabilityLayer::PopupMenuWidget::Create(state); + PortabilityLayer::PopupMenuWidget *roomPopupWidget = PortabilityLayer::PopupMenuWidget::Create(state, nullptr); roomInfoDialog->ReplaceWidget(kRoomPopupItem - 1, roomPopupWidget); if (HouseHasOriginalPicts()) diff --git a/GpApp/Settings.cpp b/GpApp/Settings.cpp index d6c415f..ec9fcb7 100644 --- a/GpApp/Settings.cpp +++ b/GpApp/Settings.cpp @@ -17,6 +17,7 @@ #include "Externs.h" #include "Environ.h" #include "House.h" +#include "WindowManager.h" #define kMainPrefsDialID 1012 @@ -1237,6 +1238,10 @@ void DoSettingsMain (void) leaving = false; nextRestartChange = false; + + Window* exclWindow = prefDlg->GetWindow(); + + PortabilityLayer::WindowManager::GetInstance()->SwapExclusiveWindow(exclWindow); // Push exclusive window while (!leaving) { @@ -1284,7 +1289,9 @@ void DoSettingsMain (void) break; } } - + + PortabilityLayer::WindowManager::GetInstance()->SwapExclusiveWindow(exclWindow); // Pop exclusive window + prefDlg->Destroy(); if (nextRestartChange) diff --git a/GpApp/Tools.cpp b/GpApp/Tools.cpp index 0b16cd9..d199a44 100644 --- a/GpApp/Tools.cpp +++ b/GpApp/Tools.cpp @@ -330,7 +330,7 @@ void OpenToolsWindow (void) state.m_resID = 141; state.m_window = toolsWindow; - classPopUp = PortabilityLayer::PopupMenuWidget::Create(state); + classPopUp = PortabilityLayer::PopupMenuWidget::Create(state, nullptr); } toolsWindow->DrawControls(); diff --git a/GpApp/WindowUtils.cpp b/GpApp/WindowUtils.cpp index 533847a..b714b99 100644 --- a/GpApp/WindowUtils.cpp +++ b/GpApp/WindowUtils.cpp @@ -18,6 +18,7 @@ WindowPtr mssgWindow; +WindowPtr mssgWindowExclusiveStack; //============================================================== Functions @@ -129,6 +130,10 @@ void OpenMessageWindow (const PLPasStr &title) surface->SetSystemFont(12, 0); } + + mssgWindowExclusiveStack = mssgWindow; + + wm->SwapExclusiveWindow(mssgWindowExclusiveStack); // Push exclusive window } //-------------------------------------------------------------- SetMessageWindowMessage @@ -161,6 +166,11 @@ void SetMessageWindowMessage (StringPtr message, const PortabilityLayer::RGBACol void CloseMessageWindow (void) { + PortabilityLayer::WindowManager::GetInstance()->SwapExclusiveWindow(mssgWindowExclusiveStack); // Pop exclusive window + assert(mssgWindowExclusiveStack == mssgWindow); + + mssgWindowExclusiveStack = nullptr; + CloseThisWindow(&mssgWindow); } diff --git a/GpCommon/IGpDisplayDriver.h b/GpCommon/IGpDisplayDriver.h index 332cd97..315cd59 100644 --- a/GpCommon/IGpDisplayDriver.h +++ b/GpCommon/IGpDisplayDriver.h @@ -6,6 +6,13 @@ struct IGpDisplayDriverSurface; struct IGpCursor; +struct GpDisplayDriverSurfaceEffects +{ + GpDisplayDriverSurfaceEffects(); + + bool m_darken; +}; + // Display drivers are responsible for timing and calling the game tick function. struct IGpDisplayDriver { @@ -16,7 +23,7 @@ public: virtual void GetDisplayResolution(unsigned int *width, unsigned int *height, GpPixelFormat_t *bpp) = 0; virtual IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, GpPixelFormat_t pixelFormat) = 0; - virtual void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height) = 0; + virtual void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) = 0; virtual IGpCursor *LoadCursor(bool isColor, int cursorID) = 0; virtual void SetCursor(IGpCursor *cursor) = 0; @@ -28,3 +35,8 @@ public: virtual void RequestToggleFullScreen(uint32_t timestamp) = 0; }; + +inline GpDisplayDriverSurfaceEffects::GpDisplayDriverSurfaceEffects() + : m_darken(false) +{ +} diff --git a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp index 7585d83..633c1d8 100644 --- a/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp +++ b/GpDisplayDriver_D3D11/CompiledShaders/DrawQuadPaletteP_D3D11.cpp @@ -1,56 +1,67 @@ static unsigned char gs_shaderData[] = { - 68, 88, 66, 67, 75, 29, 59, 91, 67, 226, 130, 211, 218, 1, 246, - 35, 4, 77, 147, 90, 1, 0, 0, 0, 4, 3, 0, 0, 5, 0, - 0, 0, 52, 0, 0, 0, 224, 0, 0, 0, 56, 1, 0, 0, 108, - 1, 0, 0, 136, 2, 0, 0, 82, 68, 69, 70, 164, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0, - 0, 0, 4, 255, 255, 0, 137, 0, 0, 122, 0, 0, 0, 92, 0, + 68, 88, 66, 67, 162, 86, 191, 155, 118, 151, 0, 3, 108, 83, 21, + 32, 68, 243, 178, 112, 1, 0, 0, 0, 176, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, 112, 1, 0, 0, 200, 1, 0, 0, 252, + 1, 0, 0, 52, 3, 0, 0, 82, 68, 69, 70, 52, 1, 0, 0, + 1, 0, 0, 0, 180, 0, 0, 0, 3, 0, 0, 0, 28, 0, 0, + 0, 0, 4, 255, 255, 0, 137, 0, 0, 12, 1, 0, 0, 124, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, - 107, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, + 139, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 255, 255, 255, 255, 1, 0, 0, 0, 1, 0, 0, 0, 13, 0, - 0, 0, 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, 117, 114, - 101, 0, 112, 97, 108, 101, 116, 116, 101, 84, 101, 120, 116, 117, 114, - 101, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, - 32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, - 109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73, - 83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, - 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, - 0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, - 3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, - 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, - 78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, - 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, - 84, 0, 171, 171, 83, 72, 68, 82, 20, 1, 0, 0, 64, 0, 0, - 0, 69, 0, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, - 0, 0, 68, 68, 0, 0, 88, 16, 0, 4, 0, 112, 16, 0, 1, - 0, 0, 0, 85, 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, - 1, 0, 0, 0, 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, - 0, 104, 0, 0, 2, 1, 0, 0, 0, 65, 0, 0, 5, 50, 0, - 16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 27, - 0, 0, 5, 50, 0, 16, 0, 0, 0, 0, 0, 70, 0, 16, 0, - 0, 0, 0, 0, 54, 0, 0, 8, 194, 0, 16, 0, 0, 0, 0, - 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 45, 0, 0, 7, 242, 0, 16, 0, 0, - 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, - 0, 0, 0, 0, 54, 0, 0, 8, 226, 0, 16, 0, 0, 0, 0, - 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 45, 0, 0, 7, 242, 0, 16, 0, 0, - 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, - 1, 0, 0, 0, 54, 0, 0, 5, 114, 32, 16, 0, 0, 0, 0, - 0, 70, 2, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 130, 32, - 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 62, - 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 9, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, + 0, 0, 154, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 115, 117, 114, 102, 97, 99, 101, 84, 101, 120, 116, + 117, 114, 101, 0, 112, 97, 108, 101, 116, 116, 101, 84, 101, 120, 116, + 117, 114, 101, 0, 83, 68, 114, 97, 119, 81, 117, 97, 100, 80, 105, + 120, 101, 108, 67, 111, 110, 115, 116, 97, 110, 116, 115, 0, 171, 171, + 154, 0, 0, 0, 1, 0, 0, 0, 204, 0, 0, 0, 16, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, 2, 0, 0, 0, 252, 0, 0, 0, 0, + 0, 0, 0, 99, 111, 110, 115, 116, 97, 110, 116, 115, 95, 77, 111, + 100, 117, 108, 97, 116, 105, 111, 110, 0, 171, 171, 171, 1, 0, 3, + 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, + 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, 49, 0, 73, 83, 71, 78, 80, 0, 0, + 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, + 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 83, 86, 95, + 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, + 82, 68, 0, 171, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, 1, + 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, + 0, 83, 86, 95, 84, 65, 82, 71, 69, 84, 0, 171, 171, 83, 72, + 68, 82, 48, 1, 0, 0, 64, 0, 0, 0, 76, 0, 0, 0, 89, + 0, 0, 4, 70, 142, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 68, 68, 0, + 0, 88, 16, 0, 4, 0, 112, 16, 0, 1, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 101, + 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0, 2, + 1, 0, 0, 0, 65, 0, 0, 5, 50, 0, 16, 0, 0, 0, 0, + 0, 70, 16, 16, 0, 1, 0, 0, 0, 27, 0, 0, 5, 50, 0, + 16, 0, 0, 0, 0, 0, 70, 0, 16, 0, 0, 0, 0, 0, 54, + 0, 0, 8, 194, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 45, 0, 0, 7, 242, 0, 16, 0, 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 54, + 0, 0, 8, 226, 0, 16, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, + 0, 45, 0, 0, 7, 242, 0, 16, 0, 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, 70, 126, 16, 0, 1, 0, 0, 0, 54, + 0, 0, 5, 130, 0, 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, + 0, 0, 128, 63, 56, 0, 0, 8, 242, 32, 16, 0, 0, 0, 0, + 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 142, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, + 0, 0, 0, 9, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; namespace GpBinarizedShaders diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp index 4b1846c..80ea0a6 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp @@ -17,6 +17,8 @@ #pragma comment (lib, "d3d11.lib") +static GpDisplayDriverSurfaceEffects gs_defaultEffects; + namespace GpBinarizedShaders { extern const unsigned char *g_drawQuadV_D3D11[2]; @@ -284,6 +286,20 @@ bool GpDisplayDriverD3D11::InitResources(uint32_t virtualWidth, uint32_t virtual return false; } + // Quad pixel constant buffer + { + D3D11_BUFFER_DESC bufferDesc; + bufferDesc.ByteWidth = sizeof(DrawQuadPixelConstants); + bufferDesc.Usage = D3D11_USAGE_DYNAMIC; + bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bufferDesc.MiscFlags = 0; + bufferDesc.StructureByteStride = 0; + + if (m_device->CreateBuffer(&bufferDesc, nullptr, m_drawQuadPixelConstantBuffer.GetMutablePtr()) != S_OK) + return false; + } + // Quad index buffer { const uint16_t indexBufferData[] = { 0, 1, 2, 1, 3, 2 }; @@ -1025,8 +1041,11 @@ IGpDisplayDriverSurface *GpDisplayDriverD3D11::CreateSurface(size_t width, size_ return GpDisplayDriverSurfaceD3D11::Create(m_device, m_deviceContext, width, height, pixelFormat); } -void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height) +void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) { + if (!effects) + effects = &gs_defaultEffects; + ID3D11Buffer *vbPtr = m_quadVertexBuffer; UINT vbStride = sizeof(float) * 2; UINT zero = 0; @@ -1039,21 +1058,36 @@ void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t const float twoDivWidth = 2.0f / static_cast(m_windowWidthVirtual); const float negativeTwoDivHeight = -2.0f / static_cast(m_windowHeightVirtual); - DrawQuadVertexConstants constantsData; - constantsData.m_ndcOriginX = static_cast(x) * twoDivWidth - 1.0f; - constantsData.m_ndcOriginY = static_cast(y) * negativeTwoDivHeight + 1.0f; - constantsData.m_ndcWidth = static_cast(width) * twoDivWidth; - constantsData.m_ndcHeight = static_cast(height) * negativeTwoDivHeight; + DrawQuadVertexConstants vConstantsData; + vConstantsData.m_ndcOriginX = static_cast(x) * twoDivWidth - 1.0f; + vConstantsData.m_ndcOriginY = static_cast(y) * negativeTwoDivHeight + 1.0f; + vConstantsData.m_ndcWidth = static_cast(width) * twoDivWidth; + vConstantsData.m_ndcHeight = static_cast(height) * negativeTwoDivHeight; - constantsData.m_surfaceDimensionX = static_cast(d3d11Surface->GetWidth()); - constantsData.m_surfaceDimensionY = static_cast(d3d11Surface->GetHeight()); + vConstantsData.m_surfaceDimensionX = static_cast(d3d11Surface->GetWidth()); + vConstantsData.m_surfaceDimensionY = static_cast(d3d11Surface->GetHeight()); - D3D11_MAPPED_SUBRESOURCE mappedConstants; - if (m_deviceContext->Map(m_drawQuadVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedConstants) == S_OK) + D3D11_MAPPED_SUBRESOURCE vMappedConstants; + if (m_deviceContext->Map(m_drawQuadVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &vMappedConstants) == S_OK) { - memcpy(mappedConstants.pData, &constantsData, sizeof(constantsData)); + memcpy(vMappedConstants.pData, &vConstantsData, sizeof(vConstantsData)); m_deviceContext->Unmap(m_drawQuadVertexConstantBuffer, 0); } + + DrawQuadPixelConstants pConstantsData; + for (int i = 0; i < 4; i++) + pConstantsData.m_modulation[i] = 1.0f; + + if (effects->m_darken) + for (int i = 0; i < 3; i++) + pConstantsData.m_modulation[i] = 0.5f; + + D3D11_MAPPED_SUBRESOURCE pMappedConstants; + if (m_deviceContext->Map(m_drawQuadPixelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &pMappedConstants) == S_OK) + { + memcpy(pMappedConstants.pData, &pConstantsData, sizeof(pConstantsData)); + m_deviceContext->Unmap(m_drawQuadPixelConstantBuffer, 0); + } } m_deviceContext->IASetVertexBuffers(0, 1, &vbPtr, &vbStride, &zero); @@ -1071,6 +1105,9 @@ void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t }; m_deviceContext->PSSetSamplers(0, sizeof(samplerStates) / sizeof(samplerStates[0]), samplerStates); + ID3D11Buffer *psConstants = m_drawQuadPixelConstantBuffer; + m_deviceContext->PSSetConstantBuffers(0, 1, &psConstants); + GpPixelFormat_t pixelFormat = d3d11Surface->GetPixelFormat(); if (pixelFormat == GpPixelFormats::k8BitStandard || pixelFormat == GpPixelFormats::k8BitCustom) { diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h index 5b90763..2ad77ed 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.h @@ -29,6 +29,7 @@ struct ID3D11Texture1D; struct ID3D11Texture2D; struct ID3D11VertexShader; + class GpDisplayDriverD3D11 : public IGpDisplayDriver { public: @@ -38,7 +39,7 @@ public: void GetDisplayResolution(unsigned int *width, unsigned int *height, GpPixelFormat_t *bpp) override; IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, GpPixelFormat_t pixelFormat) override; - void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height) override; + void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override; IGpCursor *LoadCursor(bool isColor, int cursorID) override; void SetCursor(IGpCursor *cursor) override; @@ -62,9 +63,15 @@ private: float m_surfaceDimensionX; float m_surfaceDimensionY; + float m_unused[2]; }; + struct DrawQuadPixelConstants + { + float m_modulation[4]; + }; + struct ScaleQuadPixelConstants { float m_dx; @@ -106,6 +113,7 @@ private: GpComPtr m_drawQuadRGBPixelShader; GpComPtr m_scaleQuadPixelShader; GpComPtr m_drawQuadVertexConstantBuffer; + GpComPtr m_drawQuadPixelConstantBuffer; GpComPtr m_scaleQuadPixelConstantBuffer; GpComPtr m_drawQuadDepthStencilState; GpComPtr m_nearestNeighborSamplerState; diff --git a/PortabilityLayer/DialogManager.cpp b/PortabilityLayer/DialogManager.cpp index e0bbe9a..7a2b924 100644 --- a/PortabilityLayer/DialogManager.cpp +++ b/PortabilityLayer/DialogManager.cpp @@ -21,6 +21,7 @@ #include "PLTimeTaggedVOSEvent.h" #include "PLWidgets.h" #include "QDPixMap.h" +#include "Rect2i.h" #include "ResTypeID.h" #include "SharedTypes.h" #include "UTF8.h" @@ -107,6 +108,8 @@ namespace PortabilityLayer static void MakeStringSubstitutions(uint8_t *outStr, const uint8_t *inStr, const DialogTextSubstitutions *substitutions); + int16_t ExecuteModalInDarkenStack(DialogFilterFunc_t filterFunc); + Window *m_window; DialogItem *m_items; size_t m_numItems; @@ -334,6 +337,19 @@ namespace PortabilityLayer } int16_t DialogImpl::ExecuteModal(DialogFilterFunc_t filterFunc) + { + Window *exclWindow = this->GetWindow(); + + WindowManager::GetInstance()->SwapExclusiveWindow(exclWindow); + + int16_t result = ExecuteModalInDarkenStack(filterFunc); + + WindowManager::GetInstance()->SwapExclusiveWindow(exclWindow); + + return result; + } + + int16_t DialogImpl::ExecuteModalInDarkenStack(DialogFilterFunc_t filterFunc) { Window *window = this->GetWindow(); Widget *capturingWidget = nullptr; @@ -367,6 +383,18 @@ namespace PortabilityLayer } else { + if (evt.IsLMouseDownEvent()) + { + const GpMouseInputEvent &mouseEvent = evt.m_vosEvent.m_event.m_mouseInputEvent; + + Rect2i windowFullRect = WindowManager::GetInstance()->GetWindowFullRect(window); + if (!windowFullRect.Contains(Vec2i(mouseEvent.m_x, mouseEvent.m_y))) + { + PortabilityLayer::HostSystemServices::GetInstance()->Beep(); + continue; + } + } + const size_t numItems = this->m_numItems; for (size_t i = 0; i < numItems; i++) { @@ -432,28 +460,40 @@ namespace PortabilityLayer switch (templateItem.m_serializedType) { case SerializedDialogItemTypeCodes::kButton: - widget = ButtonWidget::Create(basicState); + { + ButtonWidget::AdditionalData addlData; + addlData.m_buttonStyle = ButtonWidget::kButtonStyle_Button; + widget = ButtonWidget::Create(basicState, &addlData); + } break; case SerializedDialogItemTypeCodes::kLabel: - widget = LabelWidget::Create(basicState); + widget = LabelWidget::Create(basicState, nullptr); break; case SerializedDialogItemTypeCodes::kIcon: - widget = IconWidget::Create(basicState); + widget = IconWidget::Create(basicState, nullptr); break; case SerializedDialogItemTypeCodes::kImage: - widget = ImageWidget::Create(basicState); + widget = ImageWidget::Create(basicState, nullptr); break; case SerializedDialogItemTypeCodes::kCheckBox: - widget = CheckboxWidget::Create(basicState); + { + ButtonWidget::AdditionalData addlData; + addlData.m_buttonStyle = ButtonWidget::kButtonStyle_CheckBox; + widget = ButtonWidget::Create(basicState, &addlData); + } break; case SerializedDialogItemTypeCodes::kRadioButton: - widget = RadioButtonWidget::Create(basicState); + { + ButtonWidget::AdditionalData addlData; + addlData.m_buttonStyle = ButtonWidget::kButtonStyle_Radio; + widget = ButtonWidget::Create(basicState, &addlData); + } break; case SerializedDialogItemTypeCodes::kEditBox: - widget = EditboxWidget::Create(basicState); + widget = EditboxWidget::Create(basicState, nullptr); break; default: - widget = InvisibleWidget::Create(basicState); + widget = InvisibleWidget::Create(basicState, nullptr); break; } @@ -613,9 +653,11 @@ namespace PortabilityLayer const Rect rect = header.m_rect.ToRect(); const int16_t style = header.m_style; + Dialog *dialog = LoadDialogFromTemplate(header.m_itemsResID, rect, header.m_visible != 0, header.m_hasCloseBox != 0, header.m_referenceConstant, positionSpec, behindWindow, PLPasStr(titlePStr), substitutions); + dlogH.Dispose(); - return LoadDialogFromTemplate(header.m_itemsResID, rect, header.m_visible != 0, header.m_hasCloseBox != 0, header.m_referenceConstant, positionSpec, behindWindow, PLPasStr(titlePStr), substitutions); + return dialog; } Dialog *DialogManagerImpl::LoadDialogFromTemplate(int16_t templateResID, const Rect &rect, bool visible, bool hasCloseBox, uint32_t referenceConstant, uint16_t positionSpec, Window *behindWindow, const PLPasStr &title, const DialogTextSubstitutions *substitutions) diff --git a/PortabilityLayer/MenuManager.cpp b/PortabilityLayer/MenuManager.cpp index 3d779c6..5d03007 100644 --- a/PortabilityLayer/MenuManager.cpp +++ b/PortabilityLayer/MenuManager.cpp @@ -963,7 +963,7 @@ namespace PortabilityLayer const PixMap *pixMap = *m_menuBarGraf->m_port.GetPixMap(); const size_t width = pixMap->m_rect.right - pixMap->m_rect.left; const size_t height = pixMap->m_rect.bottom - pixMap->m_rect.top; - displayDriver->DrawSurface(m_menuBarGraf->m_ddSurface, 0, 0, width, height); + displayDriver->DrawSurface(m_menuBarGraf->m_ddSurface, 0, 0, width, height, nullptr); } } @@ -988,7 +988,7 @@ namespace PortabilityLayer yCoordinate = popupPosition.m_y; } - displayDriver->DrawSurface(renderedMenu->m_ddSurface, xCoordinate, yCoordinate, pixMap->m_rect.right, pixMap->m_rect.bottom); + displayDriver->DrawSurface(renderedMenu->m_ddSurface, xCoordinate, yCoordinate, pixMap->m_rect.right, pixMap->m_rect.bottom, nullptr); } } @@ -1263,6 +1263,18 @@ namespace PortabilityLayer { assert(initialItem < menu->numMenuItems); m_popupPosition.m_y -= static_cast(menu->menuItems[initialItem].layoutYOffset); + + if (m_popupPosition.m_y < static_cast(kMenuBarHeight)) + m_popupPosition.m_y = kMenuBarHeight; + else + { + int32_t popupBottom = m_popupPosition.m_y + menu->layoutFinalHeight; + + unsigned int displayHeight = 0; + PortabilityLayer::HostDisplayDriver::GetInstance()->GetDisplayResolution(nullptr, &displayHeight, nullptr); + if (popupBottom > static_cast(displayHeight)) + m_popupPosition.m_y -= popupBottom - static_cast(displayHeight); + } } RenderMenu(menu); diff --git a/PortabilityLayer/PLButtonWidget.cpp b/PortabilityLayer/PLButtonWidget.cpp index 92ec3ba..e8a10d7 100644 --- a/PortabilityLayer/PLButtonWidget.cpp +++ b/PortabilityLayer/PLButtonWidget.cpp @@ -1,139 +1,165 @@ #include "PLButtonWidget.h" #include "PLCore.h" #include "PLControlDefinitions.h" +#include "PLRegions.h" #include "PLTimeTaggedVOSEvent.h" #include "PLStandardColors.h" #include "FontFamily.h" #include "SimpleGraphic.h" +#include + static const int kLightGray = 238; static const int kMidGray = 221; +static const int kMidDarkGray = 170; static const int kDarkGray = 102; +#ifdef CLR +#undef CLR +#endif + +#define CLR(n) { n, n, n, 255} + static const PortabilityLayer::RGBAColor gs_buttonTopLeftCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, - { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 255, 255, 255, 255 } + CLR(0), CLR(0), CLR(0), + CLR(0), CLR(0), CLR(kMidGray), + CLR(0), CLR(kMidGray), CLR(255) }; static const PortabilityLayer::RGBAColor gs_buttonTopRightCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 } + CLR(0), CLR(0), CLR(0), + CLR(kMidGray), CLR(0), CLR(0), + CLR(255), CLR(kMidGray), CLR(0) }; static const PortabilityLayer::RGBAColor gs_buttonBottomLeftCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 255, 255, 255, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } + CLR(0), CLR(kMidGray), CLR(255), + CLR(0), CLR(0), CLR(kMidGray), + CLR(0), CLR(0), CLR(0) }; static const PortabilityLayer::RGBAColor gs_buttonBottomRightCornerGraphicPixels[] = { - { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } + CLR(kMidGray), CLR(kDarkGray), CLR(0), + CLR(kDarkGray), CLR(0), CLR(0), + CLR(0), CLR(0), CLR(0) }; // Pressed static const PortabilityLayer::RGBAColor gs_buttonPressedTopLeftCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { 0, 0, 0, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 } + CLR(0), CLR(0), CLR(0), + CLR(0), CLR(0), CLR(kDarkGray), + CLR(0), CLR(kDarkGray), CLR(kDarkGray) }; static const PortabilityLayer::RGBAColor gs_buttonPressedTopRightCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 } + CLR(0), CLR(0), CLR(0), + CLR(kDarkGray), CLR(0), CLR(0), + CLR(kDarkGray), CLR(kDarkGray), CLR(0) }; static const PortabilityLayer::RGBAColor gs_buttonPressedBottomLeftCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } + CLR(0), CLR(kDarkGray), CLR(kDarkGray), + CLR(0), CLR(0), CLR(kDarkGray), + CLR(0), CLR(0), CLR(0) }; static const PortabilityLayer::RGBAColor gs_buttonPressedBottomRightCornerGraphicPixels[] = { - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 } + CLR(kDarkGray), CLR(kDarkGray), CLR(0), + CLR(kDarkGray), CLR(0), CLR(0), + CLR(0), CLR(0), CLR(0) }; // Disabled static const PortabilityLayer::RGBAColor gs_buttonDisabledTopLeftCornerGraphicPixels[] = { - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 } + CLR(kDarkGray), CLR(kDarkGray), CLR(kDarkGray), + CLR(kDarkGray), CLR(kDarkGray), CLR(kLightGray), + CLR(kDarkGray), CLR(kLightGray), CLR(kLightGray) }; static const PortabilityLayer::RGBAColor gs_buttonDisabledTopRightCornerGraphicPixels[] = { - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { kLightGray, kLightGray, kLightGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { kLightGray, kLightGray, kLightGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 } + CLR(kDarkGray), CLR(kDarkGray), CLR(kDarkGray), + CLR(kLightGray), CLR(kDarkGray), CLR(kDarkGray), + CLR(kLightGray), CLR(kLightGray), CLR(kDarkGray) }; static const PortabilityLayer::RGBAColor gs_buttonDisabledBottomLeftCornerGraphicPixels[] = { - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 } + CLR(kDarkGray), CLR(kLightGray), CLR(kLightGray), + CLR(kDarkGray), CLR(kDarkGray), CLR(kLightGray), + CLR(kDarkGray), CLR(kDarkGray), CLR(kDarkGray) }; static const PortabilityLayer::RGBAColor gs_buttonDisabledBottomRightCornerGraphicPixels[] = { - { kLightGray, kLightGray, kLightGray, 255 }, { kLightGray, kLightGray, kLightGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { kLightGray, kLightGray, kLightGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 } + CLR(kLightGray), CLR(kLightGray), CLR(kDarkGray), + CLR(kLightGray), CLR(kDarkGray), CLR(kDarkGray), + CLR(kDarkGray), CLR(kDarkGray), CLR(kDarkGray) }; // Default boundary static const PortabilityLayer::RGBAColor gs_buttonDefaultTopLeftCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, - { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, + CLR(0), CLR(0), CLR(0), CLR(0), CLR(0), + CLR(0), CLR(0), CLR(0), CLR(0), CLR(255), + CLR(0), CLR(0), CLR(0), CLR(255), CLR(kMidGray), + CLR(0), CLR(0), CLR(255), CLR(kMidGray), CLR(kMidGray), + CLR(0), CLR(255), CLR(kMidGray), CLR(kMidGray), CLR(0), }; static const PortabilityLayer::RGBAColor gs_buttonDefaultTopRightCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, + CLR(0), CLR(0), CLR(0), CLR(0), CLR(0), + CLR(255), CLR(0), CLR(0), CLR(0), CLR(0), + CLR(kMidGray), CLR(kMidGray), CLR(0), CLR(0), CLR(0), + CLR(kMidGray), CLR(kMidGray), CLR(kMidGray), CLR(0), CLR(0), + CLR(0), CLR(kMidGray), CLR(kMidGray), CLR(kDarkGray), CLR(0), }; static const PortabilityLayer::RGBAColor gs_buttonDefaultBottomLeftCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { 255, 255, 255, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, + CLR(0), CLR(255), CLR(kMidGray), CLR(kMidGray), CLR(0), + CLR(0), CLR(0), CLR(kMidGray), CLR(kMidGray), CLR(kMidGray), + CLR(0), CLR(0), CLR(0), CLR(kMidGray), CLR(kMidGray), + CLR(0), CLR(0), CLR(0), CLR(0), CLR(kDarkGray), + CLR(0), CLR(0), CLR(0), CLR(0), CLR(0), }; static const PortabilityLayer::RGBAColor gs_buttonDefaultBottomRightCornerGraphicPixels[] = { - { 0, 0, 0, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, - { kMidGray, kMidGray, kMidGray, 255 }, { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kMidGray, kMidGray, kMidGray, 255 }, { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { kDarkGray, kDarkGray, kDarkGray, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, - { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, { 0, 0, 0, 255 }, + CLR(0), CLR(kMidGray), CLR(kMidGray), CLR(kDarkGray), CLR(0), + CLR(kMidGray), CLR(kMidGray), CLR(kDarkGray), CLR(0), CLR(0), + CLR(kMidGray), CLR(kDarkGray), CLR(0), CLR(0), CLR(0), + CLR(kDarkGray), CLR(0), CLR(0), CLR(0), CLR(0), + CLR(0), CLR(0), CLR(0), CLR(0), CLR(0), +}; + +static const PortabilityLayer::RGBAColor gs_buttonRadioGraphicPixels[] = +{ + CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0), + CLR(0),CLR(0),CLR(0),CLR(255),CLR(255),CLR(255),CLR(255),CLR(255),CLR(255),CLR(0),CLR(0),CLR(0), + CLR(0),CLR(0),CLR(255),CLR(255),CLR(kLightGray),CLR(kLightGray),CLR(kLightGray),CLR(kLightGray),CLR(kMidGray),CLR(kMidGray),CLR(0),CLR(0), + CLR(0),CLR(255),CLR(255),CLR(kLightGray),CLR(kLightGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kDarkGray),CLR(0), + CLR(0),CLR(255),CLR(kLightGray),CLR(kLightGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidDarkGray),CLR(kDarkGray),CLR(0), + CLR(0),CLR(255),CLR(kLightGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidDarkGray),CLR(kDarkGray),CLR(0), + CLR(0),CLR(255),CLR(kLightGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidDarkGray),CLR(kDarkGray),CLR(0), + CLR(0),CLR(255),CLR(kLightGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidDarkGray),CLR(kMidDarkGray),CLR(kDarkGray),CLR(0), + CLR(0),CLR(255),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidGray),CLR(kMidDarkGray),CLR(kMidDarkGray),CLR(kDarkGray),CLR(kDarkGray),CLR(0), + CLR(0),CLR(0),CLR(kMidGray),CLR(kMidGray),CLR(kMidDarkGray),CLR(kMidDarkGray),CLR(kMidDarkGray),CLR(kMidDarkGray),CLR(kDarkGray),CLR(kDarkGray),CLR(0),CLR(0), + CLR(0),CLR(0),CLR(0),CLR(kDarkGray),CLR(kDarkGray),CLR(kDarkGray),CLR(kDarkGray),CLR(kDarkGray),CLR(kDarkGray),CLR(0),CLR(0),CLR(0), + CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0),CLR(0), }; @@ -179,13 +205,23 @@ static const uint8_t gs_buttonDefaultTopRightGraphicMask[] = { 0x86, 0x39, 0xEF, static const uint8_t gs_buttonDefaultBottomLeftGraphicMask[] = { 0xFB, 0xCE, 0x30, 0xFF }; static const uint8_t gs_buttonDefaultBottomRightGraphicMask[] = { 0xFF, 0xB9, 0x88, 0x7F }; +static const uint8_t gs_buttonRadioGraphicMask[] = { 0x1f, 0x83, 0xFC, 0x7F, 0xEF, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xF7, 0xFE, 0x3F, 0xC1, 0xF8 }; +static PortabilityLayer::SimpleGraphicInstanceRGBA<12, 12> gs_buttonRadioGraphic(gs_buttonRadioGraphicPixels); + namespace PortabilityLayer { + + ButtonWidget::AdditionalData::AdditionalData() + : m_buttonStyle(kButtonStyle_Button) + { + } + ButtonWidget::ButtonWidget(const WidgetBasicState &state) : WidgetSpec(state) , m_text(state.m_text) , m_haveHighlightOverride(false) + , m_buttonStyle(kButtonStyle_Button) { } @@ -214,7 +250,14 @@ namespace PortabilityLayer void ButtonWidget::OnEnabledChanged() { - DrawControl(m_window->GetDrawSurface()); + if (m_window) + DrawControl(m_window->GetDrawSurface()); + } + + void ButtonWidget::OnStateChanged() + { + if (m_window) + DrawControl(m_window->GetDrawSurface()); } int16_t ButtonWidget::Capture(const Point &pos, WidgetUpdateCallback_t callback) @@ -254,9 +297,12 @@ namespace PortabilityLayer } } - bool ButtonWidget::Init(const WidgetBasicState &state) + bool ButtonWidget::Init(const WidgetBasicState &state, const void *additionalDataPtr) { - (void)state; + const AdditionalData &additionalData = *static_cast(additionalDataPtr); + + m_buttonStyle = additionalData.m_buttonStyle; + return true; } @@ -265,7 +311,36 @@ namespace PortabilityLayer DrawControlInternal(surface, false); } + + void ButtonWidget::SetString(const PLPasStr &str) + { + m_text = PascalStr<255>(str); + } + + PLPasStr ButtonWidget::GetString() const + { + return m_text.ToShortStr(); + } + void ButtonWidget::DrawControlInternal(DrawSurface *surface, bool inverted) + { + switch (m_buttonStyle) + { + case kButtonStyle_Button: + DrawAsButton(surface, inverted); + break; + case kButtonStyle_CheckBox: + DrawAsCheck(surface, inverted); + break; + case kButtonStyle_Radio: + DrawAsRadio(surface, inverted); + break; + default: + break; + } + } + + void ButtonWidget::DrawAsButton(DrawSurface *surface, bool inverted) { const Rect rect = m_rect; @@ -370,6 +445,163 @@ namespace PortabilityLayer surface->DrawString(Point::Create(x, y), m_text.ToShortStr(), true); } + void ButtonWidget::DrawAsCheck(DrawSurface *surface, bool inverted) + { + if (!m_rect.IsValid()) + return; + + surface->SetForeColor(StdColors::White()); + surface->FillRect(m_rect); + + uint16_t checkFrameSize = std::min(12, std::min(m_rect.Width(), m_rect.Height())); + int16_t top = (m_rect.top + m_rect.bottom - static_cast(checkFrameSize)) / 2; + + const Rect checkRect = Rect::Create(top, m_rect.left, top + static_cast(checkFrameSize), m_rect.left + static_cast(checkFrameSize)); + + RGBAColor checkColor; + RGBAColor checkEraseColor; + RGBAColor textColor; + if (!m_enabled) + { + surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); + surface->FillRect(checkRect); + surface->SetForeColor(RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255)); + surface->FillRect(checkRect.Inset(1, 1)); + + checkColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + checkEraseColor = RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255); + textColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + } + else if (inverted) + { + surface->SetForeColor(StdColors::Black()); + surface->FillRect(checkRect); + surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); + surface->FillRect(checkRect.Inset(1, 1)); + + checkColor = StdColors::White(); + checkEraseColor = RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255); + textColor = StdColors::Black(); + } + else + { + surface->SetForeColor(StdColors::Black()); + surface->FillRect(checkRect); + surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); + surface->FillRect(checkRect.Inset(1, 1)); + + surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); + surface->FillRect(Rect::Create(checkRect.top + 2, checkRect.right - 2, checkRect.bottom - 2, checkRect.right - 1)); + surface->FillRect(Rect::Create(checkRect.bottom - 2, checkRect.left + 2, checkRect.bottom - 1, checkRect.right - 1)); + + surface->SetForeColor(StdColors::White()); + surface->FillRect(Rect::Create(checkRect.top + 1, checkRect.left + 1, checkRect.top + 2, checkRect.right - 2)); + surface->FillRect(Rect::Create(checkRect.top + 2, checkRect.left + 1, checkRect.bottom - 2, checkRect.left + 2)); + + checkColor = StdColors::Black(); + checkEraseColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + textColor = StdColors::Black(); + } + + if (m_state) + { + const Rect checkmarkRect = checkRect.Inset(3, 3); + + if (checkmarkRect.IsValid()) + { + surface->SetForeColor(checkColor); + surface->FillRect(checkmarkRect); + + if (checkmarkRect.Width() >= 5) + { + int32_t eraseSpan = checkmarkRect.Width() - 4; + int16_t coordinateOffset = 0; + + surface->SetForeColor(checkEraseColor); + + while (eraseSpan > 0) + { + surface->FillRect(Rect::Create(checkmarkRect.top + coordinateOffset, checkmarkRect.left + 2 + coordinateOffset, checkmarkRect.top + 1 + coordinateOffset, checkmarkRect.right - 2 - coordinateOffset)); + surface->FillRect(Rect::Create(checkmarkRect.top + 2 + coordinateOffset, checkmarkRect.left + coordinateOffset, checkmarkRect.bottom - 2 - coordinateOffset, checkmarkRect.left + 1 + coordinateOffset)); + surface->FillRect(Rect::Create(checkmarkRect.bottom - 1 - coordinateOffset, checkmarkRect.left + 2 + coordinateOffset, checkmarkRect.bottom - coordinateOffset, checkmarkRect.right - 2 - coordinateOffset)); + surface->FillRect(Rect::Create(checkmarkRect.top + 2 + coordinateOffset, checkmarkRect.right - 1 - coordinateOffset, checkmarkRect.bottom - 2 - coordinateOffset, checkmarkRect.right - coordinateOffset)); + + eraseSpan -= 2; + coordinateOffset++; + } + } + } + } + + surface->SetForeColor(textColor); + + surface->SetSystemFont(12, FontFamilyFlag_Bold); + int32_t textV = (m_rect.top + m_rect.bottom + surface->MeasureFontAscender()) / 2; + surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true); + } + + + void ButtonWidget::DrawAsRadio(DrawSurface *surface, bool inverted) + { + if (!m_rect.IsValid()) + return; + + surface->SetForeColor(StdColors::White()); + surface->FillRect(m_rect); + + uint16_t checkFrameSize = std::min(12, std::min(m_rect.Width(), m_rect.Height())); + int16_t top = (m_rect.top + m_rect.bottom - static_cast(checkFrameSize)) / 2; + + const Rect checkRect = Rect::Create(top, m_rect.left, top + static_cast(checkFrameSize), m_rect.left + static_cast(checkFrameSize)); + + RGBAColor radioColor; + RGBAColor textColor; + if (!m_enabled) + { + surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); + surface->FillEllipse(checkRect); + surface->SetForeColor(RGBAColor::Create(kLightGray, kLightGray, kLightGray, 255)); + surface->FillEllipse(checkRect.Inset(1, 1)); + + radioColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + textColor = RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255); + } + else if (inverted) + { + surface->SetForeColor(StdColors::Black()); + surface->FillEllipse(checkRect); + surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); + surface->FillEllipse(checkRect.Inset(1, 1)); + + radioColor = StdColors::Black(); + textColor = StdColors::Black(); + } + else + { + gs_buttonRadioGraphic.DrawToPixMapWithMask(surface->m_port.GetPixMap(), gs_buttonRadioGraphicMask, checkRect.left, checkRect.top); + + radioColor = StdColors::Black(); + textColor = StdColors::Black(); + } + + if (m_state) + { + const Rect checkmarkRect = checkRect.Inset(3, 3); + + if (checkmarkRect.IsValid()) + { + surface->SetForeColor(radioColor); + surface->FillEllipse(checkmarkRect); + } + } + + surface->SetForeColor(textColor); + + surface->SetSystemFont(12, FontFamilyFlag_Bold); + int32_t textV = (m_rect.top + m_rect.bottom + surface->MeasureFontAscender()) / 2; + surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true); + } + void ButtonWidget::DrawDefaultButtonChrome(const Rect &rectRef, DrawSurface *surface) { const Rect rect = rectRef; diff --git a/PortabilityLayer/PLButtonWidget.h b/PortabilityLayer/PLButtonWidget.h index a2d365b..26af111 100644 --- a/PortabilityLayer/PLButtonWidget.h +++ b/PortabilityLayer/PLButtonWidget.h @@ -8,18 +8,32 @@ namespace PortabilityLayer class ButtonWidget final : public WidgetSpec { public: + enum ButtonStyle + { + kButtonStyle_Button, + kButtonStyle_CheckBox, + kButtonStyle_Radio, + }; + + struct AdditionalData + { + AdditionalData(); + + ButtonStyle m_buttonStyle; + }; + explicit ButtonWidget(const WidgetBasicState &state); - bool Init(const WidgetBasicState &state) override; - + bool Init(const WidgetBasicState &state, const void *additionalData) override; void DrawControl(DrawSurface *surface) override; + void SetString(const PLPasStr &str) override; + PLPasStr GetString() const override; + WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override; - void OnEnabledChanged() override; - + void OnStateChanged() override; int16_t Capture(const Point &pos, WidgetUpdateCallback_t callback) override; - void SetHighlightStyle(int16_t style, bool enabled) override; static void DrawDefaultButtonChrome(const Rect &rect, DrawSurface *surface); @@ -27,7 +41,12 @@ namespace PortabilityLayer private: void DrawControlInternal(DrawSurface *surface, bool inverted); + void DrawAsButton(DrawSurface *surface, bool inverted); + void DrawAsRadio(DrawSurface *surface, bool inverted); + void DrawAsCheck(DrawSurface *surface, bool inverted); + PascalStr<255> m_text; + ButtonStyle m_buttonStyle; bool m_haveHighlightOverride; }; } diff --git a/PortabilityLayer/PLCheckboxWidget.cpp b/PortabilityLayer/PLCheckboxWidget.cpp deleted file mode 100644 index c7fe504..0000000 --- a/PortabilityLayer/PLCheckboxWidget.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "PLCheckboxWidget.h" -#include "PLStandardColors.h" -#include "FontFamily.h" -#include "PLTimeTaggedVOSEvent.h" - -#include - -namespace PortabilityLayer -{ - CheckboxWidget::CheckboxWidget(const WidgetBasicState &state) - : WidgetSpec(state) - , m_text(state.m_text) - , m_haveMouseDown(false) - { - } - - CheckboxWidget::~CheckboxWidget() - { - } - - bool CheckboxWidget::Init(const WidgetBasicState &state) - { - (void)state; - - return true; - } - - void CheckboxWidget::DrawControl(DrawSurface *surface) - { - if (!m_rect.IsValid()) - return; - - surface->SetForeColor(StdColors::White()); - surface->FillRect(m_rect); - - uint16_t checkFrameSize = std::min(12, std::min(m_rect.Width(), m_rect.Height())); - int16_t top = (m_rect.top + m_rect.bottom - static_cast(checkFrameSize)) / 2; - - surface->SetForeColor(StdColors::Black()); - const Rect checkRect = Rect::Create(top, m_rect.left, top + static_cast(checkFrameSize), m_rect.left + static_cast(checkFrameSize)); - surface->FillRect(checkRect); - - surface->SetForeColor(StdColors::White()); - surface->FillRect(checkRect.Inset(1, 1)); - - if (m_state) - { - surface->SetForeColor(StdColors::Black()); - surface->DrawLine(Point::Create(checkRect.left + 1, checkRect.top + 1), Point::Create(checkRect.right - 2, checkRect.bottom - 2)); - surface->DrawLine(Point::Create(checkRect.right - 2, checkRect.top + 1), Point::Create(checkRect.left + 1, checkRect.bottom - 2)); - } - - surface->SetForeColor(StdColors::Black()); - surface->SetSystemFont(12, FontFamilyFlag_Bold); - int32_t textV = (m_rect.top + m_rect.bottom + surface->MeasureFontAscender()) / 2; - surface->DrawString(Point::Create(m_rect.left + checkFrameSize + 2, textV), m_text.ToShortStr(), true); - } - - void CheckboxWidget::SetString(const PLPasStr &str) - { - m_text = PascalStr<255>(str); - } - - PLPasStr CheckboxWidget::GetString() const - { - return m_text.ToShortStr(); - } - - void CheckboxWidget::OnStateChanged() - { - if (m_window) - DrawControl(&m_window->m_surface); - } - - WidgetHandleState_t CheckboxWidget::ProcessEvent(const TimeTaggedVOSEvent &evt) - { - if (!m_visible || !m_enabled) - return WidgetHandleStates::kIgnored; - - if (m_haveMouseDown) - { - if (evt.IsLMouseUpEvent()) - { - m_haveMouseDown = false; - - const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); - if (m_rect.Contains(pt)) - return WidgetHandleStates::kActivated; - else - return WidgetHandleStates::kIgnored; - } - - return WidgetHandleStates::kCaptured; - } - else - { - if (evt.IsLMouseDownEvent()) - { - const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); - - if (m_rect.Contains(pt)) - { - m_haveMouseDown = true; - return WidgetHandleStates::kCaptured; - } - else - return WidgetHandleStates::kIgnored; - } - } - - return WidgetHandleStates::kIgnored; - } -} diff --git a/PortabilityLayer/PLCheckboxWidget.h b/PortabilityLayer/PLCheckboxWidget.h index 3038cb6..14b1d6d 100644 --- a/PortabilityLayer/PLCheckboxWidget.h +++ b/PortabilityLayer/PLCheckboxWidget.h @@ -11,17 +11,21 @@ namespace PortabilityLayer CheckboxWidget(const WidgetBasicState &state); ~CheckboxWidget(); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void DrawControl(DrawSurface *surface) override; void SetString(const PLPasStr &str) override; PLPasStr GetString() const override; void OnStateChanged() override; + void OnEnabledChanged() override; + int16_t Capture(const Point &pos, WidgetUpdateCallback_t callback) override; WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt); private: + void DrawControlInternal(DrawSurface *surface, bool inverted); + PascalStr<255> m_text; bool m_haveMouseDown; }; diff --git a/PortabilityLayer/PLCore.h b/PortabilityLayer/PLCore.h index 506cd76..d021e1d 100644 --- a/PortabilityLayer/PLCore.h +++ b/PortabilityLayer/PLCore.h @@ -199,22 +199,6 @@ typedef WindowPtr WindowRef; // wtf? struct KeyDownStates; -namespace RegionIDs -{ - enum RegionID - { - kNone, - - kMenuBar = 1, - kContent, - kTitleBar, - kClose, - kResize, - }; -} - -typedef RegionIDs::RegionID RegionID_t; - static const int everyEvent = -1; static const int iBeamCursor = 1; diff --git a/PortabilityLayer/PLEditboxWidget.cpp b/PortabilityLayer/PLEditboxWidget.cpp index 84676d2..6532ed9 100644 --- a/PortabilityLayer/PLEditboxWidget.cpp +++ b/PortabilityLayer/PLEditboxWidget.cpp @@ -42,7 +42,7 @@ namespace PortabilityLayer mm->Release(m_chars); } - bool EditboxWidget::Init(const WidgetBasicState &state) + bool EditboxWidget::Init(const WidgetBasicState &state, const void *additionalData) { PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance(); m_capacity = 255; diff --git a/PortabilityLayer/PLEditboxWidget.h b/PortabilityLayer/PLEditboxWidget.h index 96be815..707b77e 100644 --- a/PortabilityLayer/PLEditboxWidget.h +++ b/PortabilityLayer/PLEditboxWidget.h @@ -14,7 +14,7 @@ namespace PortabilityLayer EditboxWidget(const WidgetBasicState &state); ~EditboxWidget(); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void DrawControl(DrawSurface *surface) override; void SetString(const PLPasStr &str) override; diff --git a/PortabilityLayer/PLIconWidget.cpp b/PortabilityLayer/PLIconWidget.cpp index 354ac22..3a281f6 100644 --- a/PortabilityLayer/PLIconWidget.cpp +++ b/PortabilityLayer/PLIconWidget.cpp @@ -21,7 +21,7 @@ namespace PortabilityLayer PixMapImpl::Destroy(m_iconMask); } - bool IconWidget::Init(const WidgetBasicState &state) + bool IconWidget::Init(const WidgetBasicState &state, const void *additionalData) { PL_DEAD(str); diff --git a/PortabilityLayer/PLIconWidget.h b/PortabilityLayer/PLIconWidget.h index ae6dff9..85bc67b 100644 --- a/PortabilityLayer/PLIconWidget.h +++ b/PortabilityLayer/PLIconWidget.h @@ -13,7 +13,7 @@ namespace PortabilityLayer IconWidget(const WidgetBasicState &state); ~IconWidget() override; - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void DrawControl(DrawSurface *surface) override; diff --git a/PortabilityLayer/PLImageWidget.cpp b/PortabilityLayer/PLImageWidget.cpp index 7a0e0ee..4d4b779 100644 --- a/PortabilityLayer/PLImageWidget.cpp +++ b/PortabilityLayer/PLImageWidget.cpp @@ -13,7 +13,7 @@ namespace PortabilityLayer { } - bool ImageWidget::Init(const WidgetBasicState &state) + bool ImageWidget::Init(const WidgetBasicState &state, const void *additionalData) { m_pict = PortabilityLayer::ResourceManager::GetInstance()->GetAppResource('PICT', state.m_resID).StaticCast(); diff --git a/PortabilityLayer/PLImageWidget.h b/PortabilityLayer/PLImageWidget.h index 79e2b71..5c9cd37 100644 --- a/PortabilityLayer/PLImageWidget.h +++ b/PortabilityLayer/PLImageWidget.h @@ -13,7 +13,7 @@ namespace PortabilityLayer ImageWidget(const WidgetBasicState &state); ~ImageWidget(); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void DrawControl(DrawSurface *surface) override; private: diff --git a/PortabilityLayer/PLInvisibleWidget.cpp b/PortabilityLayer/PLInvisibleWidget.cpp index 6cb471e..c97636b 100644 --- a/PortabilityLayer/PLInvisibleWidget.cpp +++ b/PortabilityLayer/PLInvisibleWidget.cpp @@ -14,7 +14,7 @@ namespace PortabilityLayer { } - bool InvisibleWidget::Init(const WidgetBasicState &state) + bool InvisibleWidget::Init(const WidgetBasicState &state, const void *additionalData) { (void)state; diff --git a/PortabilityLayer/PLInvisibleWidget.h b/PortabilityLayer/PLInvisibleWidget.h index 482677b..c331f8a 100644 --- a/PortabilityLayer/PLInvisibleWidget.h +++ b/PortabilityLayer/PLInvisibleWidget.h @@ -10,7 +10,7 @@ namespace PortabilityLayer explicit InvisibleWidget(const WidgetBasicState &state); ~InvisibleWidget(); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override; diff --git a/PortabilityLayer/PLLabelWidget.cpp b/PortabilityLayer/PLLabelWidget.cpp index e1cda5c..e5a8451 100644 --- a/PortabilityLayer/PLLabelWidget.cpp +++ b/PortabilityLayer/PLLabelWidget.cpp @@ -13,7 +13,7 @@ namespace PortabilityLayer { } - bool LabelWidget::Init(const WidgetBasicState &state) + bool LabelWidget::Init(const WidgetBasicState &state, const void *additionalData) { (void)state; return true; diff --git a/PortabilityLayer/PLLabelWidget.h b/PortabilityLayer/PLLabelWidget.h index 1d0f5dc..cfcce13 100644 --- a/PortabilityLayer/PLLabelWidget.h +++ b/PortabilityLayer/PLLabelWidget.h @@ -10,7 +10,7 @@ namespace PortabilityLayer public: LabelWidget(const WidgetBasicState &state); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void SetString(const PLPasStr &str) override; PLPasStr GetString() const override; diff --git a/PortabilityLayer/PLPopupMenuWidget.cpp b/PortabilityLayer/PLPopupMenuWidget.cpp index 78032b9..1b41c2a 100644 --- a/PortabilityLayer/PLPopupMenuWidget.cpp +++ b/PortabilityLayer/PLPopupMenuWidget.cpp @@ -8,6 +8,11 @@ #include "FontFamily.h" #include "Vec2i.h" +static const int kLightGray = 238; +static const int kMidGray = 221; +static const int kMidDarkGray = 170; +static const int kDarkGray = 102; + namespace PortabilityLayer { PopupMenuWidget::PopupMenuWidget(const WidgetBasicState &state) @@ -21,7 +26,7 @@ namespace PortabilityLayer m_menu.Dispose(); } - bool PopupMenuWidget::Init(const WidgetBasicState &state) + bool PopupMenuWidget::Init(const WidgetBasicState &state, const void *additionalData) { m_menu = ::GetMenu(state.m_resID); if (!m_menu) @@ -73,18 +78,29 @@ namespace PortabilityLayer const Rect rect = m_rect; const Rect innerRect = rect.Inset(2, 2); - surface->SetForeColor(StdColors::White()); - surface->FillRect(m_rect.Inset(1, 1)); - surface->SetForeColor(StdColors::Black()); - surface->FrameRect(m_rect); + surface->FillRect(rect); + + surface->SetForeColor(StdColors::White()); + surface->FillRect(rect.Inset(1, 1)); + + surface->SetForeColor(RGBAColor::Create(kMidGray, kMidGray, kMidGray, 255)); + surface->FillRect(rect.Inset(2, 2)); + + const Rect inset2Rect = rect.Inset(2, 2); + + surface->SetForeColor(RGBAColor::Create(kDarkGray, kDarkGray, kDarkGray, 255)); + surface->FillRect(Rect::Create(inset2Rect.bottom, inset2Rect.left, inset2Rect.bottom + 1, inset2Rect.right + 1)); + surface->FillRect(Rect::Create(inset2Rect.top, inset2Rect.right, inset2Rect.bottom + 1, inset2Rect.right + 1)); + Rect textRect = innerRect; textRect.right -= 9; surface->SetSystemFont(12, PortabilityLayer::FontFamilyFlag_Bold); - Point basePoint = Point::Create(textRect.left + 2, (textRect.top + textRect.bottom + surface->MeasureFontAscender() + 1) / 2); + Point basePoint = Point::Create(textRect.left + 2, (textRect.top + textRect.bottom + surface->MeasureFontAscender() + 1) / 2 - 1); + surface->SetForeColor(StdColors::Black()); surface->DrawStringConstrained(basePoint, GetString(), true, textRect); Point arrowMidPoint = Point::Create(textRect.right + 5, (textRect.top + textRect.bottom + 1) / 2); diff --git a/PortabilityLayer/PLPopupMenuWidget.h b/PortabilityLayer/PLPopupMenuWidget.h index 3ad2bcc..de5a542 100644 --- a/PortabilityLayer/PLPopupMenuWidget.h +++ b/PortabilityLayer/PLPopupMenuWidget.h @@ -12,7 +12,7 @@ namespace PortabilityLayer public: explicit PopupMenuWidget(const WidgetBasicState &state); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt); int16_t Capture(const Point &pos, WidgetUpdateCallback_t callback); diff --git a/PortabilityLayer/PLRadioButtonWidget.cpp b/PortabilityLayer/PLRadioButtonWidget.cpp deleted file mode 100644 index 7989144..0000000 --- a/PortabilityLayer/PLRadioButtonWidget.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "PLRadioButtonWidget.h" -#include "PLStandardColors.h" -#include "FontFamily.h" -#include "PLTimeTaggedVOSEvent.h" - -#include - -namespace PortabilityLayer -{ - RadioButtonWidget::RadioButtonWidget(const WidgetBasicState &state) - : WidgetSpec(state) - , m_text(state.m_text) - , m_haveMouseDown(false) - { - } - - RadioButtonWidget::~RadioButtonWidget() - { - } - - bool RadioButtonWidget::Init(const WidgetBasicState &state) - { - (void)state; - - return true; - } - - void RadioButtonWidget::DrawControl(DrawSurface *surface) - { - if (!m_rect.IsValid()) - return; - - surface->SetForeColor(StdColors::White()); - surface->FillRect(m_rect); - - uint16_t radioFrameSize = std::min(12, std::min(m_rect.Width(), m_rect.Height())); - int16_t top = (m_rect.top + m_rect.bottom - static_cast(radioFrameSize)) / 2; - - surface->SetForeColor(StdColors::Black()); - const Rect radioRect = Rect::Create(top, m_rect.left, top + static_cast(radioFrameSize), m_rect.left + static_cast(radioFrameSize)); - surface->FillEllipse(radioRect); - - surface->SetForeColor(StdColors::White()); - surface->FillEllipse(radioRect.Inset(1, 1)); - - if (m_state) - { - surface->SetForeColor(StdColors::Black()); - surface->FillEllipse(radioRect.Inset(3, 3)); - } - - surface->SetForeColor(StdColors::Black()); - surface->SetSystemFont(12, FontFamilyFlag_Bold); - int32_t textV = (m_rect.top + m_rect.bottom + surface->MeasureFontAscender()) / 2; - surface->DrawString(Point::Create(m_rect.left + radioFrameSize + 2, textV), m_text.ToShortStr(), true); - } - - void RadioButtonWidget::SetString(const PLPasStr &str) - { - m_text = PascalStr<255>(str); - } - - PLPasStr RadioButtonWidget::GetString() const - { - return m_text.ToShortStr(); - } - - void RadioButtonWidget::OnStateChanged() - { - if (m_window) - DrawControl(&m_window->m_surface); - } - - WidgetHandleState_t RadioButtonWidget::ProcessEvent(const TimeTaggedVOSEvent &evt) - { - if (!m_visible || !m_enabled) - return WidgetHandleStates::kIgnored; - - if (m_haveMouseDown) - { - if (evt.IsLMouseUpEvent()) - { - m_haveMouseDown = false; - - const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); - if (m_rect.Contains(pt)) - return WidgetHandleStates::kActivated; - else - return WidgetHandleStates::kIgnored; - } - - return WidgetHandleStates::kCaptured; - } - else - { - if (evt.IsLMouseDownEvent()) - { - const Point pt = m_window->MouseToLocal(evt.m_vosEvent.m_event.m_mouseInputEvent); - - if (m_rect.Contains(pt)) - { - m_haveMouseDown = true; - return WidgetHandleStates::kCaptured; - } - else - return WidgetHandleStates::kIgnored; - } - } - - return WidgetHandleStates::kIgnored; - } -} diff --git a/PortabilityLayer/PLRadioButtonWidget.h b/PortabilityLayer/PLRadioButtonWidget.h index dc26f5b..3859cf6 100644 --- a/PortabilityLayer/PLRadioButtonWidget.h +++ b/PortabilityLayer/PLRadioButtonWidget.h @@ -11,7 +11,7 @@ namespace PortabilityLayer RadioButtonWidget(const WidgetBasicState &state); ~RadioButtonWidget(); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void DrawControl(DrawSurface *surface) override; void SetString(const PLPasStr &str) override; diff --git a/PortabilityLayer/PLRegions.h b/PortabilityLayer/PLRegions.h new file mode 100644 index 0000000..e55a393 --- /dev/null +++ b/PortabilityLayer/PLRegions.h @@ -0,0 +1,18 @@ +#pragma once + + +namespace RegionIDs +{ + enum RegionID + { + kNone, + + kMenuBar = 1, + kContent, + kTitleBar, + kClose, + kResize, + }; +} + +typedef RegionIDs::RegionID RegionID_t; diff --git a/PortabilityLayer/PLScrollBarWidget.cpp b/PortabilityLayer/PLScrollBarWidget.cpp index b0600a6..a7e6efb 100644 --- a/PortabilityLayer/PLScrollBarWidget.cpp +++ b/PortabilityLayer/PLScrollBarWidget.cpp @@ -28,7 +28,7 @@ namespace PortabilityLayer DrawControl(m_window->GetDrawSurface()); } - bool ScrollBarWidget::Init(const WidgetBasicState &state) + bool ScrollBarWidget::Init(const WidgetBasicState &state, const void *additionalData) { m_min = state.m_min; m_max = state.m_max; diff --git a/PortabilityLayer/PLScrollBarWidget.h b/PortabilityLayer/PLScrollBarWidget.h index f22a38f..fdd9ab2 100644 --- a/PortabilityLayer/PLScrollBarWidget.h +++ b/PortabilityLayer/PLScrollBarWidget.h @@ -12,7 +12,7 @@ namespace PortabilityLayer public: explicit ScrollBarWidget(const WidgetBasicState &state); - bool Init(const WidgetBasicState &state) override; + bool Init(const WidgetBasicState &state, const void *additionalData) override; void OnEnabledChanged() override; WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt) override; diff --git a/PortabilityLayer/PLWidgets.h b/PortabilityLayer/PLWidgets.h index d86bc9c..c707c3d 100644 --- a/PortabilityLayer/PLWidgets.h +++ b/PortabilityLayer/PLWidgets.h @@ -45,7 +45,7 @@ namespace PortabilityLayer class Widget { public: - virtual bool Init(const WidgetBasicState &state) = 0; + virtual bool Init(const WidgetBasicState &state, const void *additionalData) = 0; virtual void Destroy() = 0; virtual WidgetHandleState_t ProcessEvent(const TimeTaggedVOSEvent &evt); virtual int16_t Capture(const Point &pos, WidgetUpdateCallback_t callback); @@ -125,7 +125,7 @@ namespace PortabilityLayer Widget::BaseRelease(static_cast(this)); } - static T *Create(const WidgetBasicState &state) + static T *Create(const WidgetBasicState &state, const void *additionalData) { void *storage = Widget::BaseAlloc(sizeof(T)); if (!storage) @@ -138,7 +138,7 @@ namespace PortabilityLayer (void)downcastWidget; Widget *widget = widgetT; - if (!widget->Init(state)) + if (!widget->Init(state, additionalData)) { widget->Destroy(); return nullptr; diff --git a/PortabilityLayer/PortabilityLayer.vcxproj b/PortabilityLayer/PortabilityLayer.vcxproj index d03b0b1..d9efe55 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj +++ b/PortabilityLayer/PortabilityLayer.vcxproj @@ -227,6 +227,7 @@ + @@ -340,7 +341,6 @@ - @@ -360,7 +360,6 @@ - diff --git a/PortabilityLayer/PortabilityLayer.vcxproj.filters b/PortabilityLayer/PortabilityLayer.vcxproj.filters index cf33e98..ffc3bed 100644 --- a/PortabilityLayer/PortabilityLayer.vcxproj.filters +++ b/PortabilityLayer/PortabilityLayer.vcxproj.filters @@ -411,9 +411,6 @@ Header Files - - Header Files - Header Files @@ -489,6 +486,12 @@ Header Files + + Header Files + + + Header Files + @@ -707,9 +710,6 @@ Source Files - - Source Files - Source Files @@ -731,12 +731,6 @@ Source Files - - Source Files - - - Source Files - Source Files @@ -770,5 +764,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/PortabilityLayer/WindowManager.cpp b/PortabilityLayer/WindowManager.cpp index 1d0b29f..2065f84 100644 --- a/PortabilityLayer/WindowManager.cpp +++ b/PortabilityLayer/WindowManager.cpp @@ -86,6 +86,26 @@ namespace PortabilityLayer static const int kLightGray = 221; }; + class AlertWindowChromeTheme final : public WindowChromeThemeSingleton + { + public: + void GetChromePadding(const WindowImpl *window, uint16_t padding[WindowChromeSides::kCount]) const override; + void RenderChrome(WindowImpl *window, DrawSurface *surface, WindowChromeSide_t chromeSide) const override; + bool GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const override; + bool GetChromeRegionRect(const WindowImpl *window, RegionID_t region, Rect2i &outRect) const override; + void UpdateRegionChromeState(const WindowImpl *window, RegionID_t region, const void *data) const override; + + private: + void RenderChromeTop(WindowImpl *window, DrawSurface *surface) const; + void RenderChromeLeft(WindowImpl *window, DrawSurface *surface) const; + void RenderChromeBottom(WindowImpl *window, DrawSurface *surface) const; + void RenderChromeRight(WindowImpl *window, DrawSurface *surface) const; + + static const RGBAColor kDarkColor; + static const RGBAColor kMidColor; + static const RGBAColor kLightColor; + }; + class WindowImpl final : public Window { public: @@ -145,6 +165,8 @@ namespace PortabilityLayer bool HandleCloseBoxClick(Window *window, const Point &startPoint) override; void SetWindowTitle(Window *window, const PLPasStr &title) override; Rect2i GetWindowFullRect(Window *window) const override; + bool GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const override; + void SwapExclusiveWindow(Window *& windowRef) override; void SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) override; void ClearResizeInProgress() override; @@ -166,6 +188,8 @@ namespace PortabilityLayer WindowImpl *m_windowStackTop; WindowImpl *m_windowStackBottom; + WindowImpl *m_exclusiveWindow; + Rect2i m_resizeInProgressRect; DrawSurface m_resizeInProgressHorizontalBar; DrawSurface m_resizeInProgressVerticalBar; @@ -585,6 +609,144 @@ namespace PortabilityLayer } } + //--------------------------------------------------------------------------- + // Alert chrome theme + const RGBAColor AlertWindowChromeTheme::kDarkColor = RGBAColor::Create(255, 51, 51, 255); + const RGBAColor AlertWindowChromeTheme::kMidColor = RGBAColor::Create(255, 153, 51, 255); + const RGBAColor AlertWindowChromeTheme::kLightColor = RGBAColor::Create(255, 204, 51, 255); + + + void AlertWindowChromeTheme::GetChromePadding(const WindowImpl *window, uint16_t padding[WindowChromeSides::kCount]) const + { + padding[WindowChromeSides::kTop] = 6; + padding[WindowChromeSides::kBottom] = 6; + padding[WindowChromeSides::kLeft] = 6; + padding[WindowChromeSides::kRight] = 6; + } + + bool AlertWindowChromeTheme::GetChromeInteractionZone(const WindowImpl *window, const Vec2i &point, RegionID_t &outRegion) const + { + return false; + } + + bool AlertWindowChromeTheme::GetChromeRegionRect(const WindowImpl *window, RegionID_t region, Rect2i &outRect) const + { + return false; + } + + void AlertWindowChromeTheme::UpdateRegionChromeState(const WindowImpl *window, RegionID_t region, const void *data) const + { + } + + void AlertWindowChromeTheme::RenderChrome(WindowImpl *window, DrawSurface *surface, WindowChromeSide_t chromeSide) const + { + switch (chromeSide) + { + case WindowChromeSides::kTop: + RenderChromeTop(window, surface); + break; + case WindowChromeSides::kLeft: + RenderChromeLeft(window, surface); + break; + case WindowChromeSides::kBottom: + RenderChromeBottom(window, surface); + break; + case WindowChromeSides::kRight: + RenderChromeRight(window, surface); + break; + default: + break; + } + } + + void AlertWindowChromeTheme::RenderChromeTop(WindowImpl *window, DrawSurface *surface) const + { + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; + + surface->SetForeColor(kMidColor); + surface->FillRect(rect); + + surface->SetForeColor(StdColors::Black()); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.top + 1, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, 1)); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left + 5, rect.bottom, rect.right - 5)); + + surface->SetForeColor(kDarkColor); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom - 1, rect.right - 5)); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 4, rect.bottom, rect.left + 5)); + surface->FillRect(Rect::Create(rect.top + 2, rect.right - 2, rect.bottom, rect.right - 1)); + + surface->SetForeColor(kLightColor); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.bottom, rect.left + 2)); + surface->FillRect(Rect::Create(rect.top + 1, rect.left + 1, rect.top + 2, rect.right - 2)); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.right - 5, rect.bottom, rect.right - 4)); + } + + void AlertWindowChromeTheme::RenderChromeLeft(WindowImpl *window, DrawSurface *surface) const + { + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; + + surface->SetForeColor(StdColors::Black()); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5)); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + + surface->SetForeColor(kLightColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4)); + + surface->SetForeColor(kDarkColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1)); + + surface->SetForeColor(kMidColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2)); + } + + void AlertWindowChromeTheme::RenderChromeBottom(WindowImpl *window, DrawSurface *surface) const + { + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; + + surface->SetForeColor(kMidColor); + surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 1, rect.left + 5)); + surface->FillRect(Rect::Create(rect.bottom - 4, rect.left + 5, rect.bottom - 2, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom - 2, rect.right - 2)); + + surface->SetForeColor(StdColors::Black()); + surface->FillRect(Rect::Create(rect.top, rect.left, rect.bottom, rect.left + 1)); + surface->FillRect(Rect::Create(rect.bottom - 1, rect.left, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + surface->FillRect(Rect::Create(rect.top, rect.left + 5, rect.bottom - 5, rect.left + 6)); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom - 5, rect.right - 5)); + surface->FillRect(Rect::Create(rect.bottom - 6, rect.left + 6, rect.bottom - 5, rect.right - 6)); + + surface->SetForeColor(kLightColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom - 5, rect.right - 4)); + surface->FillRect(Rect::Create(rect.top, rect.left + 1, rect.bottom - 2, rect.left + 2)); + surface->FillRect(Rect::Create(rect.bottom - 5, rect.left + 5, rect.bottom - 4, rect.right - 4)); + + surface->SetForeColor(kDarkColor); + surface->FillRect(Rect::Create(rect.bottom - 2, rect.left + 2, rect.bottom - 1, rect.right - 2)); + surface->FillRect(Rect::Create(rect.top, rect.left + 4, rect.bottom - 5, rect.left + 5)); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom - 1, rect.right - 1)); + } + + void AlertWindowChromeTheme::RenderChromeRight(WindowImpl *window, DrawSurface *surface) const + { + const Rect rect = (*surface->m_port.GetPixMap())->m_rect; + + surface->SetForeColor(StdColors::Black()); + surface->FillRect(Rect::Create(rect.top, rect.right - 6, rect.bottom, rect.right - 5)); + surface->FillRect(Rect::Create(rect.top, rect.right - 1, rect.bottom, rect.right)); + + surface->SetForeColor(kLightColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 5, rect.bottom, rect.right - 4)); + + surface->SetForeColor(kDarkColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 2, rect.bottom, rect.right - 1)); + + surface->SetForeColor(kMidColor); + surface->FillRect(Rect::Create(rect.top, rect.right - 4, rect.bottom, rect.right - 2)); + } + //--------------------------------------------------------------------------- WindowImpl::WindowImpl() : m_windowAbove(nullptr) @@ -627,6 +789,8 @@ namespace PortabilityLayer if (m_styleFlags & WindowStyleFlags::kTitleBar) m_chromeTheme = GenericWindowChromeTheme::GetInstance(); + else if (m_styleFlags & WindowStyleFlags::kAlert) + m_chromeTheme = AlertWindowChromeTheme::GetInstance(); Rect chromeBounds[WindowChromeSides::kCount]; GetChromeDimensions(bounds.Width(), bounds.Height(), chromeBounds); @@ -776,6 +940,7 @@ namespace PortabilityLayer , m_windowStackBottom(nullptr) , m_resizeInProgressRect(Rect2i(0, 0, 0, 0)) , m_isResizeInProgress(false) + , m_exclusiveWindow(nullptr) { } @@ -913,6 +1078,8 @@ namespace PortabilityLayer { WindowImpl *windowImpl = static_cast(window); + assert(windowImpl != m_exclusiveWindow); + DetachWindow(window); if (PortabilityLayer::QDManager::GetInstance()->GetPort() == &windowImpl->m_surface.m_port) @@ -1035,6 +1202,18 @@ namespace PortabilityLayer return Rect2i(window->m_wmY - padding[WindowChromeSides::kTop], window->m_wmX - padding[WindowChromeSides::kLeft], window->m_wmY + portRect.Height() + padding[WindowChromeSides::kBottom], window->m_wmX + portRect.Width() + padding[WindowChromeSides::kRight]); } + bool WindowManagerImpl::GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const + { + return static_cast(window)->GetChromeInteractionZone(point, outRegion); + } + + void WindowManagerImpl::SwapExclusiveWindow(Window *& windowRef) + { + Window *temp = m_exclusiveWindow; + m_exclusiveWindow = static_cast(windowRef); + windowRef = temp; + } + void WindowManagerImpl::SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) { ResetResizeInProgressSurfaces(); @@ -1095,10 +1274,10 @@ namespace PortabilityLayer m_resizeInProgressHorizontalBar.PushToDDSurface(displayDriver); m_resizeInProgressVerticalBar.PushToDDSurface(displayDriver); - displayDriver->DrawSurface(m_resizeInProgressHorizontalBar.m_ddSurface, m_resizeInProgressRect.m_topLeft.m_x - 2, m_resizeInProgressRect.m_topLeft.m_y - 2, m_resizeInProgressRect.Right() - m_resizeInProgressRect.Left() + 4, 3); - displayDriver->DrawSurface(m_resizeInProgressHorizontalBar.m_ddSurface, m_resizeInProgressRect.m_topLeft.m_x - 2, m_resizeInProgressRect.m_bottomRight.m_y - 1, m_resizeInProgressRect.Right() - m_resizeInProgressRect.Left() + 4, 3); - displayDriver->DrawSurface(m_resizeInProgressVerticalBar.m_ddSurface, m_resizeInProgressRect.m_topLeft.m_x - 2, m_resizeInProgressRect.m_topLeft.m_y, 3, m_resizeInProgressRect.Bottom() - m_resizeInProgressRect.Top()); - displayDriver->DrawSurface(m_resizeInProgressVerticalBar.m_ddSurface, m_resizeInProgressRect.m_bottomRight.m_x - 1, m_resizeInProgressRect.m_topLeft.m_y, 3, m_resizeInProgressRect.Bottom() - m_resizeInProgressRect.Top()); + displayDriver->DrawSurface(m_resizeInProgressHorizontalBar.m_ddSurface, m_resizeInProgressRect.m_topLeft.m_x - 2, m_resizeInProgressRect.m_topLeft.m_y - 2, m_resizeInProgressRect.Right() - m_resizeInProgressRect.Left() + 4, 3, nullptr); + displayDriver->DrawSurface(m_resizeInProgressHorizontalBar.m_ddSurface, m_resizeInProgressRect.m_topLeft.m_x - 2, m_resizeInProgressRect.m_bottomRight.m_y - 1, m_resizeInProgressRect.Right() - m_resizeInProgressRect.Left() + 4, 3, nullptr); + displayDriver->DrawSurface(m_resizeInProgressVerticalBar.m_ddSurface, m_resizeInProgressRect.m_topLeft.m_x - 2, m_resizeInProgressRect.m_topLeft.m_y, 3, m_resizeInProgressRect.Bottom() - m_resizeInProgressRect.Top(), nullptr); + displayDriver->DrawSurface(m_resizeInProgressVerticalBar.m_ddSurface, m_resizeInProgressRect.m_bottomRight.m_x - 1, m_resizeInProgressRect.m_topLeft.m_y, 3, m_resizeInProgressRect.Bottom() - m_resizeInProgressRect.Top(), nullptr); } } @@ -1198,6 +1377,11 @@ namespace PortabilityLayer if (!window->IsVisible()) return; + GpDisplayDriverSurfaceEffects effects; + + if (m_exclusiveWindow != nullptr && m_exclusiveWindow != window) + effects.m_darken = true; + DrawSurface &graf = window->m_surface; graf.PushToDDSurface(displayDriver); @@ -1205,8 +1389,7 @@ namespace PortabilityLayer const PixMap *pixMap = *graf.m_port.GetPixMap(); const uint16_t width = pixMap->m_rect.Width(); const uint16_t height = pixMap->m_rect.Height(); - displayDriver->DrawSurface(graf.m_ddSurface, window->m_wmX, window->m_wmY, width, height); - + displayDriver->DrawSurface(graf.m_ddSurface, window->m_wmX, window->m_wmY, width, height, &effects); if (!window->IsBorderless()) { @@ -1231,7 +1414,7 @@ namespace PortabilityLayer chromeSurface->PushToDDSurface(displayDriver); - displayDriver->DrawSurface(chromeSurface->m_ddSurface, chromeOrigins[i].m_x, chromeOrigins[i].m_y, chromeDimensions[i].m_x, chromeDimensions[i].m_y); + displayDriver->DrawSurface(chromeSurface->m_ddSurface, chromeOrigins[i].m_x, chromeOrigins[i].m_y, chromeDimensions[i].m_x, chromeDimensions[i].m_y, &effects); } } } diff --git a/PortabilityLayer/WindowManager.h b/PortabilityLayer/WindowManager.h index da4ca8c..b33e4fa 100644 --- a/PortabilityLayer/WindowManager.h +++ b/PortabilityLayer/WindowManager.h @@ -2,6 +2,8 @@ #include +#include "PLRegions.h" + struct Window; struct DrawSurface; struct GDevice; @@ -33,6 +35,8 @@ namespace PortabilityLayer virtual bool HandleCloseBoxClick(Window *window, const Point &startPoint) = 0; virtual void SetWindowTitle(Window *window, const PLPasStr &title) = 0; virtual Rect2i GetWindowFullRect(Window *window) const = 0; + virtual bool GetWindowChromeInteractionZone(Window *window, const Vec2i &point, RegionID_t &outRegion) const = 0; + virtual void SwapExclusiveWindow(Window *& windowRef) = 0; virtual void SetResizeInProgress(Window *window, const PortabilityLayer::Vec2i &size) = 0; virtual void ClearResizeInProgress() = 0; diff --git a/ShaderSrc/DrawQuadPaletteP.hlsl b/ShaderSrc/DrawQuadPaletteP.hlsl index f1e78ca..7994218 100644 --- a/ShaderSrc/DrawQuadPaletteP.hlsl +++ b/ShaderSrc/DrawQuadPaletteP.hlsl @@ -1,4 +1,5 @@ #include "DrawQuad.h" +#include "DrawQuadPixelConstants.h" SamplerState nearestNeighborSampler : register(s0); Texture2D surfaceTexture : register(t0); @@ -18,7 +19,7 @@ float3 SamplePixel(int2 texCoord) SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input) { SDrawQuadPixelOutput result; - result.color = float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0); + result.color = float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0) * constants_Modulation; return result; } diff --git a/ShaderSrc/DrawQuadPixelConstants.h b/ShaderSrc/DrawQuadPixelConstants.h new file mode 100644 index 0000000..dcb8a5e --- /dev/null +++ b/ShaderSrc/DrawQuadPixelConstants.h @@ -0,0 +1,4 @@ +cbuffer SDrawQuadPixelConstants : register(b0) +{ + float4 constants_Modulation; +};