Skip to content

Commit

Permalink
i add zoom level text
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Feb 9, 2024
1 parent 99df5d5 commit b11f9f9
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project(BetterEdit VERSION 1.0.0)
file(GLOB SOURCES
src/features/*.cpp
src/features/scaling/*.cpp
src/features/ZoomLevelText/*.cpp
src/utils/*.cpp
src/*.cpp
)
Expand Down
6 changes: 6 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
"default": true,
"name": "New Color Menu",
"description": "Changes the object color selection menu to show more channels aswell as previews for colors and special colors"
},
"show-zoom-text": {
"type": "bool",
"default": true,
"name": "Show Zoom Text",
"description": "When enabled, flashes the current zoom level as text when you zoom in / out in the editor"
}
}
}
47 changes: 47 additions & 0 deletions src/features/ZoomLevelText/ZoomLevelText.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <Geode/modify/EditorUI.hpp>
#include "ZoomLevelText.hpp"

void showZoomText(EditorUI* ui) {
if (Mod::get()->template getSettingValue<bool>("show-zoom-text")) {
auto label = static_cast<CCLabelBMFont*>(ui->getChildByID("zoom-text"_spr));

if (label) {
label->setString(
("Zoom: " + numToString(
ui->m_editorLayer->m_objectLayer->getScale(), 2
) + "x").c_str()
);
label->setOpacity(255);
label->stopAllActions();
label->runAction(CCSequence::create(
CCDelayTime::create(.5f),
CCFadeOut::create(.5f),
nullptr
));
}
}
}

class $modify(EditorUI) {
bool init(LevelEditorLayer* layer) {
if (!EditorUI::init(layer))
return false;

auto winSize = CCDirector::sharedDirector()->getWinSize();

auto zoomLabel = CCLabelBMFont::create("", "bigFont.fnt");
zoomLabel->setScale(.5f);
zoomLabel->setPosition(winSize.width / 2, winSize.height - 60.f);
zoomLabel->setID("zoom-text"_spr);
zoomLabel->setOpacity(0);
zoomLabel->setZOrder(99999);
this->addChild(zoomLabel);

return true;
}

void updateZoom(float zoom) {
EditorUI::updateZoom(zoom);
showZoomText(this);
}
};
7 changes: 7 additions & 0 deletions src/features/ZoomLevelText/ZoomLevelText.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <Geode/binding/EditorUI.hpp>

using namespace geode::prelude;

void showZoomText(EditorUI* ui);

0 comments on commit b11f9f9

Please sign in to comment.