Exemple #1
0
bool UIText::display(int offsetX, int offsetY) {
	if (!_visible) {
		return STATUS_OK;
	}


	BaseFont *font = _font;
	if (!font) {
		font = _gameRef->getSystemFont();
	}

	if (_back) {
		_back->display(offsetX + _posX, offsetY + _posY, _width, _height);
	}
	if (_image) {
		_image->draw(offsetX + _posX, offsetY + _posY, nullptr);
	}

	if (font && _text) {
		int textOffset;
		switch (_verticalAlign) {
		case VAL_TOP:
			textOffset = 0;
			break;
		case VAL_BOTTOM:
			textOffset = _height - font->getTextHeight((byte *)_text, _width);
			break;
		default:
			textOffset = (_height - font->getTextHeight((byte *)_text, _width)) / 2;
		}
		font->drawText((byte *)_text, offsetX + _posX, offsetY + _posY + textOffset, _width, _textAlign, _height);
	}

	//_gameRef->_renderer->_rectList.add(new BaseActiveRect(_gameRef,  this, NULL, OffsetX + _posX, OffsetY + _posY, _width, _height, 100, 100, false));

	return STATUS_OK;
}
Exemple #2
0
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;
}