Skip to content

Commit 7dfe29b

Browse files
committed
rename button to screenshot
1 parent 18c9c71 commit 7dfe29b

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

src/DevTools.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ void DevTools::toggle() {
275275
this->show(!m_visible);
276276
}
277277

278+
bool DevTools::isVisible() {
279+
return m_visible;
280+
}
281+
278282
void DevTools::sceneChanged() {
279283
m_selectedNode = nullptr;
280284
}

src/DevTools.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@ class DevTools {
116116

117117
void show(bool visible);
118118
void toggle();
119+
120+
bool isVisible();
119121
};

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class $modify(MenuLayer) {
4444

4545
class $modify(GameToolbox) {
4646
static void preVisitWithClippingRect(CCNode* node, CCRect clipRect) {
47-
if (!node->isVisible())
48-
return;
47+
if (!node->isVisible() || !DevTools::get()->isVisible())
48+
return GameToolbox::preVisitWithClippingRect(node, clipRect);
4949

5050
glEnable(GL_SCISSOR_TEST);
5151

@@ -54,7 +54,7 @@ class $modify(GameToolbox) {
5454
kmMat4 mat;
5555
kmGLGetMatrix(KM_GL_PROJECTION, &mat);
5656
if (mat.mat[5] < 0) {
57-
auto ws = CCDirector::sharedDirector()->getWinSize();
57+
auto ws = CCDirector::get()->getWinSize();
5858
clipRect.origin.y = ws.height - (clipRect.origin.y + node->getContentSize().height);
5959
}
6060

src/pages/Attributes.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,19 @@ void DevTools::drawBasicAttributes(CCNode* node) {
7777
clipboard::write(std::string(geode::cocos::getObjectName(node)));
7878
}
7979
ImGui::SameLine();
80-
if (ImGui::Button("Render")) {
81-
80+
if (ImGui::Button(U8STR(FEATHER_SAVE " Screenshot"))) {
8281
file::pick(file::PickMode::SaveFile, file::FilePickOptions {
8382
.filters = {{ .description = "PNG Image", .files = {"*.png"} }}
8483
}).listen([node](auto choice) {
8584
if (auto file = choice->ok()) {
8685
int width, height;
8786
auto bytes = renderToBytes(node, width, height);
8887

89-
saveRenderToFile(bytes, width, height, string::pathToString(*file).c_str());
88+
auto path = string::pathToString(*file);
89+
if (!path.ends_with(".png")) {
90+
path += ".png";
91+
}
92+
saveRenderToFile(bytes, width, height, path.c_str());
9093
}
9194
});
9295
}

src/platform/utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ std::string formatAddressIntoOffset(uintptr_t addr, bool module) {
2626
}
2727
}
2828

29-
std::vector<uint8_t> renderToBytes(cocos2d::CCNode* node, int& width, int& height) {
29+
std::vector<uint8_t> renderToBytes(CCNode* node, int& width, int& height) {
3030
// Get scale from cocos2d units to opengl units
3131
GLint viewport[4];
3232
glGetIntegerv(GL_VIEWPORT, viewport);
33-
auto winSize = cocos2d::CCDirector::sharedDirector()->getWinSize();
33+
auto winSize = CCDirector::get()->getWinSize();
3434

3535
width = node->getContentSize().width * (viewport[2] / winSize.width);
3636
height = node->getContentSize().height * (viewport[3] / winSize.height);
@@ -111,5 +111,5 @@ std::vector<uint8_t> renderToBytes(cocos2d::CCNode* node, int& width, int& heigh
111111
void saveRenderToFile(std::vector<uint8_t> const& data, int width, int height, char const* filename) {
112112
auto img = new CCImage();
113113
img->initWithImageData((void*)data.data(), data.size(), CCImage::kFmtRawData, width, height, 8);
114-
img->saveToFile(filename);
114+
img->saveToFile(filename, false);
115115
}

0 commit comments

Comments
 (0)