text: #include <utils/gd/node.hpp>
  
  USE_LILAC_NAMESPACE();
  
  void lilac::node::limitNodeSize(
      cocos2d::CCNode* spr,
      cocos2d::CCSize const& size,
      float def,
      float min
  ) {
      spr->setScale(1.f);
      auto [cwidth, cheight] = spr->getContentSize();
  
      float scale = def;
      if (size.height && size.height < cheight) {
          scale = size.height / cheight;
      }
      if (size.width && size.width < cwidth) {
          if (size.width / cwidth < scale)
              scale = size.width / cwidth;
      }
      if (def && def < scale) {
          scale = def;
      }
      if (min && scale < min) {
          scale = min;
      }
      spr->setScale(scale);
  }
  
  bool lilac::node::nodeIsVisible(CCNode* t) {
      if (!t->isVisible())
          return false;
  
      if (t->getParent())
          return nodeIsVisible(t->getParent());
      
      return true;
  }
  
  bool lilac::node::nodeIsHovered(CCNode* node, CCPoint const& gpos) {
      auto pos = node->getParent()->convertToWorldSpace(node->getPosition());
      auto size = node->getScaledContentSize();
  
      auto rect = CCRect {
          pos.x - size.width / 2,
          pos.y - size.height / 2,
          size.width,
          size.height
      };
  
      return rect.containsPoint(gpos);
  }
  
  CCPoint lilac::node::getMousePos() {
      auto winSize = CCDirector::sharedDirector()->getWinSize();
      auto winSizePx = CCDirector::sharedDirector()->getOpenGLView()->getViewPortRect();
      auto ratio_w = winSize.width / winSizePx.size.width;
      auto ratio_h = winSize.height / winSizePx.size.height;
      auto mpos = ccGetMousePosition();
      mpos.y = winSizePx.size.height - mpos.y;
      mpos.x *= ratio_w;
      mpos.y *= ratio_h;
      return mpos;
  }
  