mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 16:07:52 -05:00
Compare commits
10 commits
811a5d0b8a
...
2a2f3ffa40
Author | SHA1 | Date | |
---|---|---|---|
|
2a2f3ffa40 | ||
|
d95a43be0b | ||
|
793f554cda | ||
|
834199ad9c | ||
|
bcaa0ab6be | ||
|
61df8b7d98 | ||
|
9c9c75d46b | ||
|
d117d50fb0 | ||
|
b80efe0517 | ||
|
7d40c8188f |
4 changed files with 53 additions and 4 deletions
|
@ -713,6 +713,24 @@ namespace geode::cocos {
|
|||
*/
|
||||
GEODE_DLL void limitNodeSize(cocos2d::CCNode* node, cocos2d::CCSize const& size, float def, float min);
|
||||
|
||||
/**
|
||||
* Rescale node to fit inside given width
|
||||
* @param node Node to rescale
|
||||
* @param width Width to fit inside
|
||||
* @param def Default scale
|
||||
* @param min Minimum scale
|
||||
*/
|
||||
GEODE_DLL void limitNodeWidth(cocos2d::CCNode* node, float width, float def, float min);
|
||||
|
||||
/**
|
||||
* Rescale node to fit inside given height
|
||||
* @param node Node to rescale
|
||||
* @param height Height to fit inside
|
||||
* @param def Default scale
|
||||
* @param min Minimum scale
|
||||
*/
|
||||
GEODE_DLL void limitNodeHeight(cocos2d::CCNode* node, float height, float def, float min);
|
||||
|
||||
/**
|
||||
* Checks if a node is visible (recursively
|
||||
* checks parent visibility)
|
||||
|
|
|
@ -334,6 +334,8 @@ struct MDParser {
|
|||
}
|
||||
|
||||
float spriteScale = 1.0f;
|
||||
float spriteWidth = 0.0f;
|
||||
float spriteHeight = 0.0f;
|
||||
|
||||
for (auto [key, value] : imgArguments) {
|
||||
if (key == "scale") {
|
||||
|
@ -342,6 +344,18 @@ struct MDParser {
|
|||
spriteScale = *scaleRes;
|
||||
}
|
||||
}
|
||||
else if (key == "width") {
|
||||
auto widthRes = utils::numFromString<float>(value);
|
||||
if (widthRes) {
|
||||
spriteWidth = *widthRes;
|
||||
}
|
||||
}
|
||||
else if (key == "height") {
|
||||
auto heightRes = utils::numFromString<float>(value);
|
||||
if (heightRes) {
|
||||
spriteHeight = *heightRes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (utils::string::startsWith(s_lastImage, "frame:")) {
|
||||
|
@ -357,6 +371,15 @@ struct MDParser {
|
|||
}
|
||||
if (spr && spr->getUserObject("geode.texture-loader/fallback") == nullptr) {
|
||||
spr->setScale(spriteScale);
|
||||
if (spriteWidth > 0.0f && spriteHeight <= 0.0f) {
|
||||
limitNodeWidth(spr, spriteWidth, 999.f, .1f);
|
||||
}
|
||||
else if (spriteHeight > 0.0f && spriteWidth <= 0.0f) {
|
||||
limitNodeHeight(spr, spriteHeight, 999.f, .1f);
|
||||
}
|
||||
else if (spriteWidth > 0.0f && spriteHeight > 0.0f) {
|
||||
limitNodeSize(spr, { spriteWidth, spriteHeight }, 999.f, .1f);
|
||||
}
|
||||
renderer->renderNode(spr);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -29,11 +29,11 @@ void ScrollLayer::visit() {
|
|||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
if (this->getParent()) {
|
||||
CCPoint const offset = this->isIgnoreAnchorPointForPosition()
|
||||
? ccp(0, 0) : CCPoint(this->getContentSize() * -this->getAnchorPoint());
|
||||
// CCPoint const offset = this->isIgnoreAnchorPointForPosition()
|
||||
// ? ccp(0, 0) : CCPoint(this->getContentSize() * -this->getAnchorPoint());
|
||||
|
||||
auto const bottomLeft = this->convertToWorldSpace(ccp(0, 0) - offset);
|
||||
auto const topRight = this->convertToWorldSpace(this->getContentSize() - offset);
|
||||
auto const bottomLeft = this->convertToWorldSpace(ccp(0, 0));
|
||||
auto const topRight = this->convertToWorldSpace(this->getContentSize());
|
||||
CCSize const size = topRight - bottomLeft;
|
||||
|
||||
CCEGLView::get()->setScissorInPoints(bottomLeft.x, bottomLeft.y, size.width, size.height);
|
||||
|
|
|
@ -455,6 +455,14 @@ void geode::cocos::limitNodeSize(CCNode* spr, CCSize const& size, float def, flo
|
|||
spr->setScale(clamp(std::min(size.height / spr->getContentHeight(), size.width / spr->getContentWidth()), min, def));
|
||||
}
|
||||
|
||||
void geode::cocos::limitNodeWidth(CCNode* spr, float width, float def, float min) {
|
||||
spr->setScale(clamp(width / spr->getContentSize().width, min, def));
|
||||
}
|
||||
|
||||
void geode::cocos::limitNodeHeight(CCNode* spr, float height, float def, float min) {
|
||||
spr->setScale(clamp(height / spr->getContentSize().height, min, def));
|
||||
}
|
||||
|
||||
bool geode::cocos::nodeIsVisible(CCNode* node) {
|
||||
if (!node->isVisible()) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue