Skip to content

Commit 53d367d

Browse files
committed
Add "Scale" property to meta.json to apply DPI scale factor
1 parent bcd6385 commit 53d367d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Source/PluginMode.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ class PluginMode final : public Component
4848
editor->getTopLevelComponent()->sendLookAndFeelChange();
4949
}
5050

51+
auto metaFile = patchPtr.get()->getPatchFile().getSiblingFile("meta.json");
52+
if (metaFile.existsAsFile()) {
53+
auto json = juce::JSON::parse(metaFile.loadFileAsString());
54+
if (json.isObject()) {
55+
auto jsonObject = json.getDynamicObject();
56+
if (jsonObject != nullptr && jsonObject->hasProperty("Scale")) {
57+
scaleDPIMult = jsonObject->getProperty("Scale");
58+
}
59+
}
60+
}
61+
5162
desktopWindow = editor->getPeer();
5263

5364
editor->nvgSurface.invalidateAll();
@@ -135,8 +146,9 @@ class PluginMode final : public Component
135146
setWidthAndHeight(previousScale * 0.01f);
136147
}
137148

138-
void setWidthAndHeight(float const scale)
149+
void setWidthAndHeight(float scale)
139150
{
151+
scale *= scaleDPIMult;
140152
auto newWidth = static_cast<int>(width * scale);
141153
auto newHeight = static_cast<int>(height * scale) + titlebarHeight + nativeTitleBarHeight;
142154

@@ -322,7 +334,7 @@ class PluginMode final : public Component
322334
cnv->setTransform(cnv->getTransform().scale(scale));
323335
cnv->setBounds(-b.getX() + x / scale, -b.getY() + y / scale, b.getWidth() + b.getX(), b.getHeight() + b.getY());
324336
} else {
325-
float scale = getWidth() / width;
337+
float scale = (getWidth() / width);
326338
pluginModeScale = scale;
327339
scaleComboBox.setVisible(true);
328340
editorButton->setVisible(true);
@@ -474,6 +486,7 @@ class PluginMode final : public Component
474486
float const height = static_cast<float>(cnv->patchHeight.getValue()) + 1.0f;
475487

476488
float pluginModeScale = 1.0f;
489+
float scaleDPIMult = 1.0f;
477490

478491
String lastTheme;
479492

0 commit comments

Comments
 (0)