interface.bindCanvas uses interface scale by default

This commit is contained in:
Kae 2023-07-05 18:25:16 +10:00
parent c923f4f13b
commit 54dfd900ca
5 changed files with 18 additions and 7 deletions

View File

@ -10,8 +10,8 @@ namespace Star {
LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) { LuaCallbacks LuaBindings::makeInterfaceCallbacks(MainInterface* mainInterface) {
LuaCallbacks callbacks; LuaCallbacks callbacks;
callbacks.registerCallback("bindCanvas", [mainInterface](String const& canvasName) -> Maybe<CanvasWidgetPtr> { callbacks.registerCallback("bindCanvas", [mainInterface](String const& canvasName, Maybe<bool> ignoreInterfaceScale) -> Maybe<CanvasWidgetPtr> {
if (auto canvas = mainInterface->fetchCanvas(canvasName)) if (auto canvas = mainInterface->fetchCanvas(canvasName, ignoreInterfaceScale.value(false)))
return canvas; return canvas;
return {}; return {};
}); });

View File

@ -796,7 +796,10 @@ void MainInterface::update() {
for (auto& pair : m_canvases) { for (auto& pair : m_canvases) {
pair.second->setPosition(Vec2I()); pair.second->setPosition(Vec2I());
pair.second->setSize(Vec2I(m_guiContext->windowSize())); if (pair.second->ignoreInterfaceScale())
pair.second->setSize(Vec2I(m_guiContext->windowSize()));
else
pair.second->setSize(Vec2I(m_guiContext->windowInterfaceSize()));
pair.second->update(); pair.second->update();
} }
} }
@ -923,14 +926,17 @@ void MainInterface::warpTo(WarpAction const& warpAction) {
} }
} }
CanvasWidgetPtr MainInterface::fetchCanvas(String const& canvasName) { CanvasWidgetPtr MainInterface::fetchCanvas(String const& canvasName, bool ignoreInterfaceScale) {
if (auto canvasPtr = m_canvases.ptr(canvasName)) if (auto canvasPtr = m_canvases.ptr(canvasName))
return *canvasPtr; return *canvasPtr;
else { else {
CanvasWidgetPtr canvas = m_canvases.emplace(canvasName, make_shared<CanvasWidget>()).first->second; CanvasWidgetPtr canvas = m_canvases.emplace(canvasName, make_shared<CanvasWidget>()).first->second;
canvas->setPosition(Vec2I()); canvas->setPosition(Vec2I());
canvas->setSize(Vec2I(m_guiContext->windowSize())); if (ignoreInterfaceScale)
canvas->setIgnoreInterfaceScale(true); canvas->setSize(Vec2I(m_guiContext->windowSize()));
else
canvas->setSize(Vec2I(m_guiContext->windowInterfaceSize()));
canvas->setIgnoreInterfaceScale(ignoreInterfaceScale);
return canvas; return canvas;
} }
} }

View File

@ -115,7 +115,7 @@ public:
void warpToOwnShip(); void warpToOwnShip();
void warpTo(WarpAction const& warpAction); void warpTo(WarpAction const& warpAction);
CanvasWidgetPtr fetchCanvas(String const& canvasName); CanvasWidgetPtr fetchCanvas(String const& canvasName, bool ignoreInterfaceScale = false);
private: private:
PanePtr createEscapeDialog(); PanePtr createEscapeDialog();

View File

@ -18,6 +18,10 @@ void CanvasWidget::setIgnoreInterfaceScale(bool ignoreInterfaceScale) {
m_ignoreInterfaceScale = ignoreInterfaceScale; m_ignoreInterfaceScale = ignoreInterfaceScale;
} }
bool CanvasWidget::ignoreInterfaceScale() const {
return m_ignoreInterfaceScale;
}
void CanvasWidget::clear() { void CanvasWidget::clear() {
m_renderOps.clear(); m_renderOps.clear();
} }

View File

@ -32,6 +32,7 @@ public:
void setCaptureMouseEvents(bool captureMouse); void setCaptureMouseEvents(bool captureMouse);
void setCaptureKeyboardEvents(bool captureKeyboard); void setCaptureKeyboardEvents(bool captureKeyboard);
void setIgnoreInterfaceScale(bool ignoreInterfaceScale); void setIgnoreInterfaceScale(bool ignoreInterfaceScale);
bool ignoreInterfaceScale() const;
// Returns mouse position relative to the lower left of the drawing region. // Returns mouse position relative to the lower left of the drawing region.
Vec2I mousePosition() const; Vec2I mousePosition() const;