Ejemplo n.º 1
0
bool AdInventoryBox::display() {
	AdGame *adGame = (AdGame *)_gameRef;

	if (!_visible) {
		return STATUS_OK;
	}

	int itemsX, itemsY;
	itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing)));
	itemsY = (int)floor((float)((_itemsArea.bottom - _itemsArea.top + _spacing) / (_itemHeight + _spacing)));

	if (_window) {
		_window->enableWidget("prev", _scrollOffset > 0);
		_window->enableWidget("next", _scrollOffset + itemsX * itemsY < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size());
	}


	if (_closeButton) {
		_closeButton->_posX = _closeButton->_posY = 0;
		_closeButton->setWidth(_gameRef->_renderer->getWidth());
		_closeButton->setHeight(_gameRef->_renderer->getHeight());

		_closeButton->display();
	}


	// display window
	Rect32 rect = _itemsArea;
	if (_window) {
		rect.offsetRect(_window->_posX, _window->_posY);
		_window->display();
	}

	// display items
	if (_window && _window->_alphaColor != 0) {
		_gameRef->_renderer->_forceAlphaColor = _window->_alphaColor;
	}
	int yyy = rect.top;
	for (int j = 0; j < itemsY; j++) {
		int xxx = rect.left;
		for (int i = 0; i < itemsX; i++) {
			int itemIndex = _scrollOffset + j * itemsX + i;
			if (itemIndex >= 0 && itemIndex < (int32)adGame->_inventoryOwner->getInventory()->_takenItems.size()) {
				AdItem *item = adGame->_inventoryOwner->getInventory()->_takenItems[itemIndex];
				if (item != ((AdGame *)_gameRef)->_selectedItem || !_hideSelected) {
					item->update();
					item->display(xxx, yyy);
				}
			}

			xxx += (_itemWidth + _spacing);
		}
		yyy += (_itemHeight + _spacing);
	}
	if (_window && _window->_alphaColor != 0) {
		_gameRef->_renderer->_forceAlphaColor = 0;
	}

	return STATUS_OK;
}
bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, TransformStruct transform) {
	BaseRenderOSystem *renderer = static_cast<BaseRenderOSystem *>(_gameRef->_renderer);

	if (!_loaded) {
		finishLoad();
	}

	if (renderer->_forceAlphaColor != 0) {
		transform._rgbaMod = renderer->_forceAlphaColor;
	}

	// TODO: This _might_ miss the intended behaviour by 1 in each direction
	// But I think it fits the model used in Wintermute.
	Common::Rect srcRect;
	srcRect.left = rect->left;
	srcRect.top = rect->top;
	srcRect.setWidth(rect->right - rect->left);
	srcRect.setHeight(rect->bottom - rect->top);

	Common::Rect position;

	if (newRect) {
		position.top = y;
		position.left = x;
		position.setWidth(newRect->width());
		position.setHeight(newRect->height());
	} else {

		Rect32 r;
		r.top = 0;
		r.left = 0;
		r.setWidth(rect->width());
		r.setHeight(rect->height());

		r = TransformTools::newRect(r, transform, 0);

		position.top = r.top + y + transform._offset.y;
		position.left = r.left + x + transform._offset.x;
		position.setWidth(r.width() * transform._numTimesX);
		position.setHeight(r.height() * transform._numTimesY);
	}
	renderer->modTargetRect(&position);

	// TODO: This actually requires us to have the SAME source-offsets every time,
	// But no checking is in place for that yet.

	// Optimize by not doing alpha-blits if we lack alpha
	if (_alphaType == TransparentSurface::ALPHA_OPAQUE && !transform._alphaDisable) {
		transform._alphaDisable = true;
	}

	renderer->drawSurface(this, _surface, &srcRect, &position, transform); 
	return STATUS_OK;
}
Ejemplo n.º 3
0
bool VideoTheoraPlayer::display(uint32 alpha) {
    Rect32 rc;
    bool res;

    if (_texture && _videoFrameReady) {
        rc.setRect(0, 0, _texture->getWidth(), _texture->getHeight());
        if (_playZoom == 100.0f) {
            res = _texture->displayTrans(_posX, _posY, rc, alpha);
        } else {
            res = _texture->displayTransZoom(_posX, _posY, rc, _playZoom, _playZoom, alpha);
        }
    } else {
        res = STATUS_FAILED;
    }

    if (_subtitler && _foundSubtitles && _gameRef->_subtitles) {
        _subtitler->display();
    }
    return res;
}
Ejemplo n.º 4
0
bool VideoTheoraPlayer::display(uint32 alpha) {
    Rect32 rc;
    bool res;

    if (_texture && _videoFrameReady) {
        rc.setRect(0, 0, _texture->getWidth(), _texture->getHeight());
        if (_playZoom == 100.0f) {
            res = _texture->displayTrans(_posX, _posY, rc, alpha);
        } else {
            res = _texture->displayTransZoom(_posX, _posY, rc, _playZoom, _playZoom, alpha);
        }
    } else {
        res = STATUS_FAILED;
    }
    // TODO: Add subtitles-support
    /*	if (m_Subtitler && _gameRef->m_VideoSubtitles) {
    		m_Subtitler->display();
    	}*/

    return res;
}
Ejemplo n.º 5
0
void BaseFontTT::drawText(const byte *text, int x, int y, int width, TTextAlign align, int maxHeight, int maxLength) {
	if (text == nullptr || strcmp((const char *)text, "") == 0) {
		return;
	}

	WideString textStr;

	// TODO: Why do we still insist on Widestrings everywhere?
	// HACK: J.U.L.I.A. uses CP1252, we need to fix that,
	// And we still don't have any UTF8-support.
	if (_gameRef->_textEncoding == TEXT_UTF8) {
		textStr = StringUtil::utf8ToWide((const char *)text);
	} else {
		textStr = StringUtil::ansiToWide((const char *)text);
	}

	if (maxLength >= 0 && textStr.size() > (uint32)maxLength) {
		textStr = WideString(textStr.c_str(), (uint32)maxLength);
	}
	//text = text.substr(0, MaxLength); // TODO: Remove

	BaseRenderer *renderer = _gameRef->_renderer;

	// find cached surface, if exists
	uint32 minUseTime = UINT_MAX;
	int minIndex = -1;
	BaseSurface *surface = nullptr;
	int textOffset = 0;

	for (int i = 0; i < NUM_CACHED_TEXTS; i++) {
		if (_cachedTexts[i] == nullptr) {
			minUseTime = 0;
			minIndex = i;
		} else {
			if (_cachedTexts[i]->_text == textStr && _cachedTexts[i]->_align == align && _cachedTexts[i]->_width == width && _cachedTexts[i]->_maxHeight == maxHeight && _cachedTexts[i]->_maxLength == maxLength) {
				surface = _cachedTexts[i]->_surface;
				textOffset = _cachedTexts[i]->_textOffset;
				_cachedTexts[i]->_marked = true;
				_cachedTexts[i]->_lastUsed = g_system->getMillis();
				break;
			} else {
				if (_cachedTexts[i]->_lastUsed < minUseTime) {
					minUseTime = _cachedTexts[i]->_lastUsed;
					minIndex = i;
				}
			}
		}
	}

	// not found, create one
	if (!surface) {
		debugC(kWintermuteDebugFont, "Draw text: %s", text);
		surface = renderTextToTexture(textStr, width, align, maxHeight, textOffset);
		if (surface) {
			// write surface to cache
			if (_cachedTexts[minIndex] != nullptr) {
				delete _cachedTexts[minIndex];
			}
			_cachedTexts[minIndex] = new BaseCachedTTFontText;

			_cachedTexts[minIndex]->_surface = surface;
			_cachedTexts[minIndex]->_align = align;
			_cachedTexts[minIndex]->_width = width;
			_cachedTexts[minIndex]->_maxHeight = maxHeight;
			_cachedTexts[minIndex]->_maxLength = maxLength;
			_cachedTexts[minIndex]->_text = textStr;
			_cachedTexts[minIndex]->_textOffset = textOffset;
			_cachedTexts[minIndex]->_marked = true;
			_cachedTexts[minIndex]->_lastUsed = g_system->getMillis();
		}
	}


	// and paint it
	if (surface) {
		Rect32 rc;
		rc.setRect(0, 0, surface->getWidth(), surface->getHeight());
		for (uint32 i = 0; i < _layers.size(); i++) {
			uint32 color = _layers[i]->_color;
			uint32 origForceAlpha = renderer->_forceAlphaColor;
			if (renderer->_forceAlphaColor != 0) {
				color = BYTETORGBA(RGBCOLGetR(color), RGBCOLGetG(color), RGBCOLGetB(color), RGBCOLGetA(renderer->_forceAlphaColor));
				renderer->_forceAlphaColor = 0;
			}
			surface->displayTransOffset(x, y - textOffset, rc, color, Graphics::BLEND_NORMAL, false, false, _layers[i]->_offsetX, _layers[i]->_offsetY);

			renderer->_forceAlphaColor = origForceAlpha;
		}
	}


}
Ejemplo n.º 6
0
bool AdResponseBox::display() {
    Rect32 rect = _responseArea;
    if (_window) {
        rect.offsetRect(_window->_posX, _window->_posY);
        //_window->display();
    }

    int xxx, yyy;
    uint32 i;

    xxx = rect.left;
    yyy = rect.top;

    // shift down if needed
    if (!_horizontal) {
        int totalHeight = 0;
        for (i = 0; i < _respButtons.size(); i++) {
            totalHeight += (_respButtons[i]->_height + _spacing);
        }
        totalHeight -= _spacing;

        switch (_verticalAlign) {
        case VAL_BOTTOM:
            if (yyy + totalHeight < rect.bottom) {
                yyy = rect.bottom - totalHeight;
            }
            break;

        case VAL_CENTER:
            if (yyy + totalHeight < rect.bottom) {
                yyy += ((rect.bottom - rect.top) - totalHeight) / 2;
            }
            break;

        case VAL_TOP:
            // do nothing
            break;
        }
    }

    // prepare response buttons
    bool scrollNeeded = false;
    for (i = _scrollOffset; i < _respButtons.size(); i++) {
        if ((_horizontal && xxx + _respButtons[i]->_width > rect.right)
                || (!_horizontal && yyy + _respButtons[i]->_height > rect.bottom)) {

            scrollNeeded = true;
            _respButtons[i]->_visible = false;
            break;
        }

        _respButtons[i]->_visible = true;
        _respButtons[i]->_posX = xxx;
        _respButtons[i]->_posY = yyy;

        if (_horizontal) {
            xxx += (_respButtons[i]->_width + _spacing);
        } else {
            yyy += (_respButtons[i]->_height + _spacing);
        }
    }

    // show appropriate scroll buttons
    if (_window) {
        _window->showWidget("prev", _scrollOffset > 0);
        _window->showWidget("next", scrollNeeded);
    }

    // go exclusive
    if (_shieldWindow) {
        _shieldWindow->_posX = _shieldWindow->_posY = 0;
        _shieldWindow->_width = _gameRef->_renderer->getWidth();
        _shieldWindow->_height = _gameRef->_renderer->getHeight();

        _shieldWindow->display();
    }

    // display window
    if (_window) {
        _window->display();
    }


    // display response buttons
    for (i = _scrollOffset; i < _respButtons.size(); i++) {
        _respButtons[i]->display();
    }

    return STATUS_OK;
}