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 callbacks;
callbacks.registerCallback("bindCanvas", [mainInterface](String const& canvasName) -> Maybe<CanvasWidgetPtr> {
if (auto canvas = mainInterface->fetchCanvas(canvasName))
callbacks.registerCallback("bindCanvas", [mainInterface](String const& canvasName, Maybe<bool> ignoreInterfaceScale) -> Maybe<CanvasWidgetPtr> {
if (auto canvas = mainInterface->fetchCanvas(canvasName, ignoreInterfaceScale.value(false)))
return canvas;
return {};
});

View File

@ -796,7 +796,10 @@ void MainInterface::update() {
for (auto& pair : m_canvases) {
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();
}
}
@ -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))
return *canvasPtr;
else {
CanvasWidgetPtr canvas = m_canvases.emplace(canvasName, make_shared<CanvasWidget>()).first->second;
canvas->setPosition(Vec2I());
canvas->setSize(Vec2I(m_guiContext->windowSize()));
canvas->setIgnoreInterfaceScale(true);
if (ignoreInterfaceScale)
canvas->setSize(Vec2I(m_guiContext->windowSize()));
else
canvas->setSize(Vec2I(m_guiContext->windowInterfaceSize()));
canvas->setIgnoreInterfaceScale(ignoreInterfaceScale);
return canvas;
}
}

View File

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

View File

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

View File

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