mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
cache rendering of UILabel
This commit is contained in:
@@ -42,6 +42,9 @@ FrameBuffer::~FrameBuffer()
|
||||
|
||||
void FrameBuffer::resize(const Size& size)
|
||||
{
|
||||
if(m_texture && m_texture->getSize() == size)
|
||||
return;
|
||||
|
||||
internalBind();
|
||||
m_texture = TexturePtr(new Texture(size.width(), size.height(), 4));
|
||||
m_texture->setSmooth(true);
|
||||
|
@@ -131,8 +131,8 @@ void Painter::setCompositionMode(Painter::CompositionMode compositionMode)
|
||||
case CompositionMode_Multiply:
|
||||
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case CompositionMode_Addition:
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
case CompositionMode_Add:
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ public:
|
||||
enum CompositionMode {
|
||||
CompositionMode_Normal,
|
||||
CompositionMode_Multiply,
|
||||
CompositionMode_Addition
|
||||
CompositionMode_Add
|
||||
};
|
||||
|
||||
void init();
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
void setCustomProgram(PainterShaderProgramPtr program);
|
||||
void releaseCustomProgram() { m_customProgram = nullptr; }
|
||||
void setCompositionMode(CompositionMode compositionMode);
|
||||
void resetCompositionMode() { setCompositionMode(CompositionMode_Normal); }
|
||||
|
||||
void setProjectionMatrix(const Matrix3& projectionMatrix) { m_projectionMatrix = projectionMatrix; }
|
||||
Matrix3 getProjectionMatrix() { return m_projectionMatrix; }
|
||||
|
@@ -163,7 +163,7 @@ bool ParticleEmitter::load(const OTMLNodePtr& node)
|
||||
else if(childNode->value() == "multiply")
|
||||
m_pCompositionMode = Painter::CompositionMode_Multiply;
|
||||
else if(childNode->value() == "addition")
|
||||
m_pCompositionMode = Painter::CompositionMode_Addition;
|
||||
m_pCompositionMode = Painter::CompositionMode_Add;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -704,6 +704,7 @@ void X11Window::poll()
|
||||
break;
|
||||
case UnmapNotify:
|
||||
m_visible = false;
|
||||
releaseAllKeys();
|
||||
break;
|
||||
case FocusIn:
|
||||
m_focused = true;
|
||||
|
@@ -407,6 +407,10 @@ private:
|
||||
void initText();
|
||||
void parseTextStyle(const OTMLNodePtr& styleNode);
|
||||
|
||||
Boolean<true> m_textMustRecache;
|
||||
FrameBufferPtr m_textFramebuffer;
|
||||
Size m_textCachedBoxSize;
|
||||
|
||||
protected:
|
||||
void drawText(const Rect& screenCoords);
|
||||
|
||||
@@ -423,8 +427,8 @@ public:
|
||||
void clearText() { setText(""); }
|
||||
|
||||
void setText(const std::string& text);
|
||||
void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; }
|
||||
void setTextOffset(const Point& offset) { m_textOffset = offset; }
|
||||
void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; m_textMustRecache = true; }
|
||||
void setTextOffset(const Point& offset) { m_textOffset = offset; m_textMustRecache = true; }
|
||||
void setFont(const std::string& fontName);
|
||||
|
||||
std::string getText() { return m_text; }
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "uitranslator.h"
|
||||
#include <framework/graphics/fontmanager.h>
|
||||
#include <framework/graphics/painter.h>
|
||||
#include <framework/graphics/framebuffer.h>
|
||||
|
||||
void UIWidget::initText()
|
||||
{
|
||||
@@ -47,12 +48,30 @@ void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode)
|
||||
|
||||
void UIWidget::drawText(const Rect& screenCoords)
|
||||
{
|
||||
g_painter.setColor(m_color);
|
||||
if(m_text.length() > 0 && m_color.a() > 0) {
|
||||
Rect textRect = screenCoords;
|
||||
textRect.translate(m_textOffset);
|
||||
m_font->renderText(m_text, textRect, m_textAlign, m_color);
|
||||
if(m_text.length() == 0 || m_color.a() == 0)
|
||||
return;
|
||||
|
||||
Size boxSize = screenCoords.size();
|
||||
if(boxSize != m_textCachedBoxSize || m_textMustRecache) {
|
||||
if(!m_textFramebuffer)
|
||||
m_textFramebuffer = FrameBufferPtr(new FrameBuffer(boxSize));
|
||||
else
|
||||
m_textFramebuffer->resize(boxSize);
|
||||
|
||||
m_textFramebuffer->bind();
|
||||
Rect virtualTextRect(0, 0, boxSize);
|
||||
virtualTextRect.translate(m_textOffset);
|
||||
g_painter.setCompositionMode(Painter::CompositionMode_Add);
|
||||
m_font->renderText(m_text, virtualTextRect, m_textAlign, Fw::white);
|
||||
g_painter.resetCompositionMode();
|
||||
m_textFramebuffer->release();
|
||||
|
||||
m_textMustRecache = false;
|
||||
m_textCachedBoxSize = boxSize;
|
||||
}
|
||||
|
||||
g_painter.setColor(m_color);
|
||||
m_textFramebuffer->draw(screenCoords);
|
||||
}
|
||||
|
||||
void UIWidget::onTextChange(const std::string& text)
|
||||
@@ -67,26 +86,29 @@ void UIWidget::onFontChange(const std::string& font)
|
||||
|
||||
void UIWidget::setText(const std::string& text)
|
||||
{
|
||||
if(m_text != text) {
|
||||
m_text = text;
|
||||
if(m_text == text)
|
||||
return;
|
||||
|
||||
// update rect size
|
||||
if(!m_rect.isValid()) {
|
||||
Size textSize = m_font->calculateTextRectSize(m_text);
|
||||
Size newSize = getSize();
|
||||
if(newSize.width() <= 0)
|
||||
newSize.setWidth(textSize.width());
|
||||
if(newSize.height() <= 0)
|
||||
newSize.setHeight(textSize.height());
|
||||
setSize(newSize);
|
||||
}
|
||||
m_text = text;
|
||||
|
||||
onTextChange(text);
|
||||
// update rect size
|
||||
if(!m_rect.isValid()) {
|
||||
Size textSize = m_font->calculateTextRectSize(m_text);
|
||||
Size newSize = getSize();
|
||||
if(newSize.width() <= 0)
|
||||
newSize.setWidth(textSize.width());
|
||||
if(newSize.height() <= 0)
|
||||
newSize.setHeight(textSize.height());
|
||||
setSize(newSize);
|
||||
}
|
||||
|
||||
onTextChange(text);
|
||||
m_textMustRecache = true;
|
||||
}
|
||||
|
||||
void UIWidget::setFont(const std::string& fontName)
|
||||
{
|
||||
m_font = g_fonts.getFont(fontName);
|
||||
onFontChange(fontName);
|
||||
m_textMustRecache = true;
|
||||
}
|
||||
|
@@ -162,7 +162,7 @@ void Game::processWalkCancel(Otc::Direction direction)
|
||||
|
||||
void Game::walk(Otc::Direction direction)
|
||||
{
|
||||
if(!isOnline() || isDead() || !checkBotProtection())
|
||||
if(!isOnline() || !m_localPlayer->isKnown() || isDead() || !checkBotProtection())
|
||||
return;
|
||||
|
||||
if(m_localPlayer->isFollowing())
|
||||
|
@@ -39,6 +39,9 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
|
||||
|
||||
// check for blockable tiles in the walk direction
|
||||
TilePtr tile = g_map.getTile(m_pos + Position::getPosFromDirection(direction));
|
||||
if(!tile)
|
||||
return false;
|
||||
|
||||
if(!tile->isWalkable()) {
|
||||
g_game.processTextMessage("statusSmall", "Sorry, not possible.");
|
||||
return false;
|
||||
|
@@ -34,6 +34,7 @@ public:
|
||||
void setAttackingCreature(const CreaturePtr& creature);
|
||||
void setFollowingCreature(const CreaturePtr& creature);
|
||||
void setIcons(Otc::PlayerIcons icons) { m_icons = icons; }
|
||||
void setKnown(bool known) { m_known = known; }
|
||||
|
||||
bool getCanReportBugs() { return m_canReportBugs; }
|
||||
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
CreaturePtr getFollowingCreature() { return m_followingCreature; }
|
||||
Otc::PlayerIcons getIcons() { return m_icons; }
|
||||
|
||||
bool isKnown() { return m_known; }
|
||||
bool isAttacking() { return m_attackingCreature != nullptr; }
|
||||
bool isFollowing() { return m_followingCreature != nullptr; }
|
||||
|
||||
@@ -65,6 +67,7 @@ public:
|
||||
|
||||
private:
|
||||
bool m_canReportBugs;
|
||||
bool m_known;
|
||||
CreaturePtr m_attackingCreature, m_followingCreature;
|
||||
Otc::PlayerIcons m_icons;
|
||||
int m_skills[Otc::LastSkill][Otc::LastSkillType];
|
||||
|
@@ -1142,6 +1142,10 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
||||
creature->setEmblem(emblem);
|
||||
creature->setPassable(passable);
|
||||
creature->cancelWalk(direction);
|
||||
|
||||
if(creature == m_localPlayer) {
|
||||
m_localPlayer->setKnown(true);
|
||||
}
|
||||
}
|
||||
|
||||
thing = creature;
|
||||
|
Reference in New Issue
Block a user