Add hardware cursor game setting

This commit is contained in:
Kae 2024-04-19 08:52:35 +10:00
parent 9533c8d0a5
commit d5f5fb5ddf
6 changed files with 29 additions and 4 deletions

View File

@ -6,4 +6,6 @@ function patch(image)
image:copyInto({119, 26}, checkbox)
-- Object Lighting
image:copyInto({19, 15}, checkbox)
-- Hardware Cursor
image:copyInto({119, 15}, checkbox)
end

View File

@ -31,5 +31,8 @@ function patch(config)
-- Create object lighting toggle
shift(clone(layout, "multiTextureLabel", "objectLightingLabel"), 0, -11).value = "NEW OBJECT LIGHTS"
shift(clone(layout, "multiTextureCheckbox", "objectLightingCheckbox"), 0, -11)
-- Create hardware cursor toggle
shift(clone(layout, "multiTextureLabel", "hardwareCursorLabel"), 98, -11).value = "HARDWARE CURSOR"
shift(clone(layout, "multiTextureCheckbox", "hardwareCursorCheckbox"), 99, -11)
return config
end

View File

@ -41,6 +41,7 @@ public:
virtual void setVSyncEnabled(bool vSync) = 0;
virtual void setCursorVisible(bool cursorVisible) = 0;
virtual void setCursorPosition(Vec2I cursorPosition) = 0;
virtual void setCursorHardware(bool cursorHardware) = 0;
virtual bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) = 0;
virtual void setAcceptingTextInput(bool acceptingTextInput) = 0;

View File

@ -630,6 +630,10 @@ private:
SDL_WarpMouseInWindow(parent->m_sdlWindow, cursorPosition[0], cursorPosition[1]);
}
void setCursorHardware(bool hardware) override {
parent->m_cursorHardware = hardware;
}
bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) override {
return parent->setCursorImage(id, image, scale, offset);
}
@ -828,12 +832,16 @@ private:
}
}
static const size_t MaximumCursorDimensions = 128;
static const size_t MaximumCursorPixelCount = MaximumCursorDimensions * MaximumCursorDimensions;
static const size_t MaxCursorSize = 128;
bool setCursorImage(const String& id, const ImageConstPtr& image, unsigned scale, const Vec2I& offset) {
auto imageSize = image->size().piecewiseMultiply(Vec2U::filled(scale));
if (!scale || imageSize.max() > MaximumCursorDimensions || (size_t)(imageSize[0] * imageSize[1]) > MaximumCursorPixelCount)
if (!m_cursorHardware || !scale || imageSize.max() > MaxCursorSize || imageSize.product() > square(MaxCursorSize)) {
if (auto defaultCursor = SDL_GetDefaultCursor()) {
if (SDL_GetCursor() != defaultCursor)
SDL_SetCursor(defaultCursor);
}
return m_cursorVisible = false;
}
auto& entry = m_cursorCache.get(m_currentCursor = { scale, offset, id }, [&](auto const&) {
auto entry = std::make_shared<CursorEntry>();
@ -926,6 +934,7 @@ private:
bool m_windowVSync = true;
unsigned m_maxFrameSkip = 5;
bool m_cursorVisible = true;
bool m_cursorHardware = true;
bool m_acceptingTextInput = false;
bool m_audioEnabled = false;
bool m_quitRequested = false;

View File

@ -53,6 +53,7 @@ Json const AdditionalDefaultConfiguration = Json::parseJson(R"JSON(
"sfxVol" : 100,
"instrumentVol" : 100,
"musicVol" : 70,
"hardwareCursor" : true,
"windowedResolution" : [1000, 600],
"fullscreenResolution" : [1920, 1080],
"fullscreen" : false,
@ -207,6 +208,7 @@ void ClientApplication::applicationInit(ApplicationControllerPtr appController)
appController->setTargetUpdateRate(updateRate);
appController->setApplicationTitle(assets->json("/client.config:windowTitle").toString());
appController->setVSyncEnabled(vsync);
appController->setCursorHardware(configuration->get("hardwareCursor").optBool().value(true));
if (fullscreen)
appController->setFullscreenWindow(fullscreenSize);

View File

@ -80,6 +80,12 @@ GraphicsMenu::GraphicsMenu() {
Root::singleton().configuration()->set("antiAliasing", checked);
syncGui();
});
reader.registerCallback("hardwareCursorCheckbox", [=](Widget*) {
bool checked = fetchChild<ButtonWidget>("hardwareCursorCheckbox")->isChecked();
m_localChanges.set("hardwareCursor", checked);
Root::singleton().configuration()->set("hardwareCursor", checked);
GuiContext::singleton().applicationController()->setCursorHardware(checked);
});
reader.registerCallback("monochromeCheckbox", [=](Widget*) {
bool checked = fetchChild<ButtonWidget>("monochromeCheckbox")->isChecked();
m_localChanges.set("monochromeLighting", checked);
@ -146,6 +152,7 @@ StringList const GraphicsMenu::ConfigKeys = {
"limitTextureAtlasSize",
"useMultiTexturing",
"antiAliasing",
"hardwareCursor",
"monochromeLighting",
"newObjectLighting"
};
@ -204,6 +211,7 @@ void GraphicsMenu::syncGui() {
fetchChild<ButtonWidget>("antiAliasingCheckbox")->setChecked(m_localChanges.get("antiAliasing").toBool());
fetchChild<ButtonWidget>("monochromeCheckbox")->setChecked(m_localChanges.get("monochromeLighting").toBool());
fetchChild<ButtonWidget>("objectLightingCheckbox")->setChecked(m_localChanges.get("newObjectLighting").optBool().value(true));
fetchChild<ButtonWidget>("hardwareCursorCheckbox")->setChecked(m_localChanges.get("hardwareCursor").toBool());
}
void GraphicsMenu::apply() {