void UINode::renderDebug (int x, int y, int textY) const { const int panelX = getRenderX(); const int panelY = getRenderY(); const int w = getRenderWidth(false); const int h = getRenderHeight(false); const Color* color[5]; color[0] = &colorGreen; color[1] = &colorBlue; color[2] = &colorRed; color[3] = &colorYellow; color[4] = &colorCyan; const int index = (panelX * 22 * h + panelY * 23 * w) % 5; renderRect(x + getRenderX(false), y + getRenderY(false), w, h, *color[index]); if (!fequals(_padding, 0.0f)) { renderRect(x + panelX, y + panelY, getRenderWidth(), getRenderHeight(), *color[index]); } renderFilledRect(x + getRenderCenterX(), y + getRenderCenterY(), 4, 4, colorRed); renderFilledRect(x + panelX, y + panelY, 4, 4, colorBlue); const BitmapFontPtr& font = getFont(MEDIUM_FONT); int panelTextY = textY; for (UINodeListConstIter i = _nodes.begin(); i != _nodes.end(); ++i) { const UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; nodePtr->renderDebug(x + panelX, y + panelY, panelTextY); const std::string debugInfo = "[id=" + nodePtr->getId() + "]"; _frontend->renderFilledRect(x - 1, panelTextY + 1, font->getTextWidth(debugInfo) + 2, font->getTextHeight(debugInfo) + 2, colorGrayAlpha); font->print(debugInfo, colorCyan, x, panelTextY); panelTextY += font->getTextHeight(debugInfo); } }
void UINodeBackground::renderMiddle(int x, int y) const { const int renderHeight = getRenderHeight(false); renderImage(getCave(), x + getRenderX(false), y + getRenderY(false) + renderHeight - _imageHeight); if (_amountVertical > 1) renderImage(getCaveArt(), x + getRenderX(false), y + getRenderY(false) + renderHeight - 2 * _imageHeight); const int tileCnt = (int)_tiles.size(); if (tileCnt > 0) { for (int row = 3; row <= _amountVertical; ++row) { renderImage(_tiles[(row * _amountHorizontal) % tileCnt], x + getRenderX(false), y + getRenderY(false) + renderHeight - row * _imageHeight); } for (int row = 1; row <= _amountVertical; ++row) { for (int col = 1; col < _amountHorizontal; ++col) { renderImage(_tiles[((row * _amountHorizontal) + col) % tileCnt], x + getRenderX(false) + _imageWidth * col, y + getRenderY(false) + renderHeight - row * _imageHeight); } } } if (_showVehicle && _amountHorizontal > 1 && _vehicle) renderImage(_vehicle, x + getRenderX(false) + _imageWidth, y + getRenderY(false) + renderHeight - _vehicle->getHeight()); if (!_title.empty()) { x += getRenderCenterX() - _textWidth / 2; y += getRenderY() + 10; _font->print(_title, _fontColor, x, y); } }
bool UINode::onFingerPress (int64_t finger, uint16_t x, uint16_t y) { initDrag(x, y); for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->isVisible()) continue; if (!nodePtr->checkBounds(x - getRenderX(), y - getRenderY())) continue; if (nodePtr->onFingerPress(finger, x - getRenderX(), y - getRenderY())) return true; } return false; }
bool UINode::onMouseButtonPress (int32_t x, int32_t y, unsigned char button) { if (!_enabled) return false; for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; if ((*i)->onMouseButtonPress(x - getRenderX(), y - getRenderY(), button)) { return true; } } switch (button) { case SDL_BUTTON_LEFT: initDrag(x, y); onMouseLeftPress(x, y); return true; case SDL_BUTTON_RIGHT: return onMouseRightPress(x, y); case SDL_BUTTON_MIDDLE: return onMouseMiddlePress(x, y); } return false; }
void UINode::renderMiddle (int x, int y) const { if (!_texture) return; const int childX = x + getRenderX(); const int childY = y + getRenderY(); renderImage(_texture, childX, childY, getRenderWidth(), getRenderHeight(), _alpha); }
void UINode::renderBack (int x, int y) const { const int w = getRenderWidth(false); const int h = getRenderHeight(false); if (_backgroundColor[3] > 0.001f) { renderFilledRect(x + getRenderX(false), y + getRenderY(false), w, h, _backgroundColor); } }
void UINode::onMouseMotion (int32_t x, int32_t y, int32_t relX, int32_t relY) { for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; nodePtr->onMouseMotion(x - getRenderX(), y - getRenderY(), relX, relY); } }
void UINodeServerSelector::render (int x, int y) const { Super::render(x, y); x += getRenderX(); y += getRenderY(); _frontend->renderFilledRect(x, y, _colWidth * _frontend->getWidth(), _headlineHeight, colorGray); _headlineFont->print(NAME_HEADLINE, _fontColor, x + getNameX(), y, false); _headlineFont->print(MAP_HEADLINE, _fontColor, x + getMapX(), y, false); _headlineFont->print(PLAYERS_HEADLINE, _fontColor, x + getPlayersX(), y, false); }
void UINodeCheckbox::render (int x, int y) const { UINodeButton::render(x, y); if (_label.empty()) return; x += getRenderX() + getRenderWidth() + getPadding() * _frontend->getWidth(); y += getRenderCenterY() - _font->getTextHeight(_label) / 2; _font->print(_label, _fontColor, x, y); }
bool UINode::onJoystickButtonPress (int x, int y, uint8_t button) { for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; if ((*i)->onJoystickButtonPress(x - getRenderX(), y - getRenderY(), button)) { return true; } } return false; }
bool UINode::onControllerButtonPress (int x, int y, const std::string& button) { for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; if ((*i)->onControllerButtonPress(x - getRenderX(), y - getRenderY(), button)) { return true; } } return false; }
void UINode::initDrag (int32_t x, int32_t y) { for (UINodeListConstIter i = _nodes.begin(); i != _nodes.end(); ++i) { UINode* node = *i; if (!node->hasFocus()) continue; node->initDrag(x - getRenderX(), y - getRenderY()); break; } _dragStartX = x; _dragStartY = y; }
void UINode::renderTop (int x, int y) const { const int childX = x + getRenderX(); const int childY = y + getRenderY(); if (_renderBorder) { const int w = getRenderWidth(false); const int h = getRenderHeight(false); renderRect(x + getRenderX(false), y + getRenderY(false), w, h, _borderColor); } int textYOffset = 0; for (DelayedTextsConstIter i = _texts.begin(); i != _texts.end(); ++i) { const UINodeDelayedText& t = *i; const int fontX = t.pos.x > 0.00001f ? (t.pos.x * _frontend->getWidth()) : (getRenderCenterX() - t.font->getTextWidth(t.text) / 2.0f); int fontY; if (t.pos.y > 0.00001f) { fontY = t.pos.y * _frontend->getHeight(); } else { const int textHeight = t.font->getTextHeight(t.text); fontY = textYOffset + getRenderCenterY() - textHeight / 2.0f; textYOffset += textHeight; } t.font->print(t.text, colorWhite, fontX, fontY); } const bool debug = Config.isDebugUI(); const bool focus = hasFocus(); if (debug && focus) renderDebug(x, y, y + 20); for (UINodeListConstIter i = _nodes.begin(); i != _nodes.end(); ++i) { const UINode* nodePtr = *i; if (!nodePtr->isVisible()) continue; nodePtr->render(childX, childY); } }
bool UINode::onFingerMotion (int64_t finger, uint16_t x, uint16_t y, int16_t dx, int16_t dy) { const bool focus = checkFocus(x, y); if (!focus) return false; for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; nodePtr->onFingerMotion(finger, x - getRenderX(), y - getRenderY(), dx, dy); } return focus; }
void UINodeSlider::render (int x, int y) const { UINode::render(x, y); x += getRenderX(); y += getRenderY(); const int w = getRenderWidth(); const int h = getRenderHeight(); const int deltaHeight = h / 2; const float steps = _max - _min + 1.0f; const float stepDelta = w / steps * (_stepWidth < 1.0f ? 1.0f : _stepWidth); const int sliderX = x + (_value - _min) / steps * w; renderLine(x, y + deltaHeight, x + w, y + deltaHeight, _lineColor); renderFilledRect(sliderX, y, stepDelta, h, _sliderColor); }
bool UINode::onFingerRelease (int64_t finger, uint16_t x, uint16_t y) { handleDrop(x, y); execute(); for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; if (!nodePtr->hasFocus()) continue; if (nodePtr->onFingerRelease(finger, x - getRenderX(), y - getRenderY())) { return true; } } return false; }
void IUINodeMap::render (int x, int y) const { renderFilledRect(getRenderX(), getRenderY(), getRenderWidth(), getRenderHeight(), colorBlack); if (_map.isActive()) _map.render(); UINode::render(0, 0); if (_map.isStarted()) return; const BitmapFontPtr& font = getFont(HUGE_FONT); y += getRenderHeight() / 10; x += getRenderWidth() / 10; y += font->print(tr("Players:"), colorWhite, x, y) + font->getCharHeight(); for (std::vector<std::string>::const_iterator i = _players.begin(); i != _players.end(); ++i) { y += font->print(*i, colorWhite, x + 10, y) + font->getCharHeight(); } }
bool UINode::checkFocus (int32_t x, int32_t y) { if (x <= -1 || y <= -1 || !isVisible() || !isActive()) { if (hasFocus()) removeFocus(); return false; } if (checkBounds(x, y)) { if (_nodes.empty()) { addFocus(x, y); return true; } const int childX = x - getRenderX(); const int childY = y - getRenderY(); bool focusOnChildren = false; for (UINodeListRevIter i = _nodes.rbegin(); i != _nodes.rend(); ++i) { UINode* nodePtr = *i; int focusX = childX; int focusY = childY; if (focusOnChildren) { focusX = focusY = -1; } const bool focus = nodePtr->checkFocus(focusX, focusY); focusOnChildren |= focus; } if (focusOnChildren) { addFocus(x, y); return true; } } if (hasFocus()) { removeFocus(); } return false; }
void UINodeBackgroundScene::render (int x, int y) const { UINode::render(x, y); x += getRenderX(false); y += getRenderY(false); renderBackground(x, y); if (MapFailedReasons::FAILED_WATER_HEIGHT == *_reason) renderFailedWaterHeight(x, y); else if (MapFailedReasons::FAILED_NPC_FLYING == *_reason) renderFailedNpcFlying(x, y); else if (MapFailedReasons::FAILED_NPC_WALKING == *_reason) renderFailedNpcWalking(x, y); else if (MapFailedReasons::FAILED_NPC_MAMMUT == *_reason) renderFailedNpcMammut(x, y); else if (MapFailedReasons::FAILED_NPC_FISH == *_reason) renderFailedNpcFish(x, y); else if (MapFailedReasons::FAILED_HITPOINTS == *_reason || MapFailedReasons::FAILED_SIDESCROLL == *_reason) renderFailedHitpoints(x, y); }
void UINode::renderOnTop (int x, int y) const { const int relX = x + getRenderX(); const int relY = y + getRenderY(); for (UINodeListConstIter i = _nodes.begin(); i != _nodes.end(); ++i) { const UINode* nodePtr = *i; nodePtr->renderOnTop(relX, relY); } const BitmapFontPtr& font = getFont(MEDIUM_FONT); if (_tooltip.empty()) return; if (!hasFocus()) return; const int padding = 2; const int width = font->getTextWidth(_tooltip) + 2 * padding; const int height = font->getTextHeight(_tooltip) + 2 * padding; const int xTooltip = std::min(_frontend->getWidth(), x + _focusMouseX + width) - width; const int yTooltip = std::max(0, y + _focusMouseY - height); renderFilledRect(xTooltip - padding, yTooltip - padding, width, height, colorBlack); font->print(_tooltip, colorWhite, xTooltip, yTooltip); }
inline float UINodeSlider::calculateValue (int32_t x) const { const int steps = _max - _min + 1; const float value = _min + (x - getRenderX(false)) * steps / static_cast<float>(getRenderWidth(false)); return clamp(value - static_cast<float>(fmod(value, _stepWidth)), _min, _max); }