bool UIWindow::display(int offsetX, int offsetY) { // go exclusive if (_mode == WINDOW_EXCLUSIVE || _mode == WINDOW_SYSTEM_EXCLUSIVE) { if (!_shieldWindow) { _shieldWindow = new UIWindow(_gameRef); } if (_shieldWindow) { _shieldWindow->_posX = _shieldWindow->_posY = 0; _shieldWindow->_width = _gameRef->_renderer->getWidth(); _shieldWindow->_height = _gameRef->_renderer->getHeight(); _shieldWindow->display(); } } else if (_isMenu) { if (!_shieldButton) { _shieldButton = new UIButton(_gameRef); _shieldButton->setName("close"); _shieldButton->setListener(this, _shieldButton, 0); _shieldButton->_parent = this; } if (_shieldButton) { _shieldButton->_posX = _shieldButton->_posY = 0; _shieldButton->setWidth(_gameRef->_renderer->getWidth()); _shieldButton->setHeight(_gameRef->_renderer->getHeight()); _shieldButton->display(); } } if (!_visible) { return STATUS_OK; } if (_fadeBackground) { Graphics::PixelFormat format = _gameRef->_renderer->getPixelFormat(); byte fadeR, fadeG, fadeB, fadeA; // First convert from the internal format to the screen-format uint32 fadeColor = format.ARGBToColor(RGBCOLGetA(_fadeColor), RGBCOLGetR(_fadeColor), RGBCOLGetG(_fadeColor), RGBCOLGetB(_fadeColor)); // Then get components format.colorToARGB(fadeColor, fadeA, fadeR, fadeG, fadeB); _gameRef->_renderer->fadeToColor(fadeR, fadeG, fadeB, fadeA); } if (_dragging) { _posX += (_gameRef->_mousePos.x - _dragFrom.x); _posY += (_gameRef->_mousePos.y - _dragFrom.y); _dragFrom.x = _gameRef->_mousePos.x; _dragFrom.y = _gameRef->_mousePos.y; } if (!_focusedWidget || (!_focusedWidget->canFocus() || _focusedWidget->isDisabled() || !_focusedWidget->isVisible())) { moveFocus(); } bool popViewport = false; if (_clipContents) { if (!_viewport) { _viewport = new BaseViewport(_gameRef); } if (_viewport) { _viewport->setRect(_posX + offsetX, _posY + offsetY, _posX + _width + offsetX, _posY + _height + offsetY); _gameRef->pushViewport(_viewport); popViewport = true; } } UITiledImage *back = _back; BaseSprite *image = _image; BaseFont *font = _font; if (!isFocused()) { if (_backInactive) { back = _backInactive; } if (_imageInactive) { image = _imageInactive; } if (_fontInactive) { font = _fontInactive; } } if (_alphaColor != 0) { _gameRef->_renderer->_forceAlphaColor = _alphaColor; } if (back) { back->display(_posX + offsetX, _posY + offsetY, _width, _height); } if (image) { image->draw(_posX + offsetX, _posY + offsetY, _transparent ? nullptr : this); } if (!BasePlatform::isRectEmpty(&_titleRect) && font && _text) { font->drawText((byte *)_text, _posX + offsetX + _titleRect.left, _posY + offsetY + _titleRect.top, _titleRect.right - _titleRect.left, _titleAlign, _titleRect.bottom - _titleRect.top); } if (!_transparent && !image) { _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, this, nullptr, _posX + offsetX, _posY + offsetY, _width, _height, 100, 100, false)); } for (uint32 i = 0; i < _widgets.size(); i++) { _widgets[i]->display(_posX + offsetX, _posY + offsetY); } if (_alphaColor != 0) { _gameRef->_renderer->_forceAlphaColor = 0; } if (popViewport) { _gameRef->popViewport(); } return STATUS_OK; }
bool UIButton::display(int offsetX, int offsetY) { if (!_visible) { return STATUS_OK; } UITiledImage *back = nullptr; BaseSprite *image = nullptr; BaseFont *font = 0; //RECT rect; //BasePlatform::setRect(&rect, OffsetX + _posX, OffsetY + _posY, OffsetX+_posX+_width, OffsetY+_posY+_height); //_hover = (!_disable && BasePlatform::ptInRect(&rect, _gameRef->_mousePos)!=FALSE); _hover = (!_disable && _gameRef->_activeObject == this && (_gameRef->_interactive || _gameRef->_state == GAME_SEMI_FROZEN)); if ((_press && _hover && !_gameRef->_mouseLeftDown) || (_oneTimePress && g_system->getMillis() - _oneTimePressTime >= 100)) { press(); } if (_disable) { if (_backDisable) { back = _backDisable; } if (_imageDisable) { image = _imageDisable; } if (_text && _fontDisable) { font = _fontDisable; } } else if (_press || _oneTimePress || _stayPressed) { if (_backPress) { back = _backPress; } if (_imagePress) { image = _imagePress; } if (_text && _fontPress) { font = _fontPress; } } else if (_hover) { if (_backHover) { back = _backHover; } if (_imageHover) { image = _imageHover; } if (_text && _fontHover) { font = _fontHover; } } else if (_canFocus && isFocused()) { if (_backFocus) { back = _backFocus; } if (_imageFocus) { image = _imageFocus; } if (_text && _fontFocus) { font = _fontFocus; } } if (!back && _back) { back = _back; } if (!image && _image) { image = _image; } if (_text && !font) { if (_font) { font = _font; } else { font = _gameRef->getSystemFont(); } } int imageX = offsetX + _posX; int imageY = offsetY + _posY; if (image && _centerImage) { Rect32 rc; image->getBoundingRect(&rc, 0, 0); imageX += (_width - (rc.right - rc.left)) / 2; imageY += (_height - (rc.bottom - rc.top)) / 2; } if (back) { back->display(offsetX + _posX, offsetY + _posY, _width, _height); } //if (image) image->Draw(ImageX +((_press||_oneTimePress)&&back?1:0), ImageY +((_press||_oneTimePress)&&back?1:0), nullptr); if (image) { image->draw(imageX + ((_press || _oneTimePress) && back ? 1 : 0), imageY + ((_press || _oneTimePress) && back ? 1 : 0), _pixelPerfect ? this : nullptr); } if (font && _text) { int text_offset = (_height - font->getTextHeight((byte *)_text, _width)) / 2; font->drawText((byte *)_text, offsetX + _posX + ((_press || _oneTimePress) ? 1 : 0), offsetY + _posY + text_offset + ((_press || _oneTimePress) ? 1 : 0), _width, _align); } if (!_pixelPerfect || !_image) { _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, this, nullptr, offsetX + _posX, offsetY + _posY, _width, _height, 100, 100, false)); } // reset unused sprites if (_image && _image != image) { _image->reset(); } if (_imageDisable && _imageDisable != image) { _imageDisable->reset(); } if (_imageFocus && _imageFocus != image) { _imageFocus->reset(); } if (_imagePress && _imagePress != image) { _imagePress->reset(); } if (_imageHover && _imageHover != image) { _imageHover->reset(); } _press = _hover && _gameRef->_mouseLeftDown && _gameRef->_capturedObject == this; return STATUS_OK; }