rodecomp/Source/UI/Buttons/UIBmpTextButton.cpp
ragnarok-clanker 2ea0a2361f Decompile fn_10799 (UIBmpTextButton::Paint)
Batch #11140 by cremane: 0 byte-identical, 1 confirmed by peer review.

- fn_10799 UIBmpTextButton::Paint: logic confirmed by peer review

Peer-reviewed-by: Yommy, Tanke, dori
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-05 00:32:04 +00:00

129 lines
5.1 KiB
C++

#include "Render/Text/FontCache.h"
#include "Resource/Bitmap/BitmapResource.h"
#include "Resource/ResourceMgr.h"
#include "Resource/TextureNames.h"
#include "UI/Buttons/UIBmpTextButton.h"
#include <cstring>
// OFFSET: 0x0084ED30
// FUNCTION: fn_10652
UIBmpTextButton::UIBmpTextButton() : UIBitmapButton() {
}
UIBmpTextButton::~UIBmpTextButton() = default;
// OFFSET: 0x007C2340
// FUNCTION: fn_09323
void UIBmpTextButton::SetText(std::string value) {
this->text = value;
this->Invalidate();
}
// OFFSET: 0x0085BDE0
// FUNCTION: fn_10799
void UIBmpTextButton::Paint() {
this->ClearSurface(0xFFFF00FF);
bool found = false;
std::vector<BitmapButtonTextStyle>::iterator style = this->styles.begin();
for (; style != this->styles.end(); ++style) {
if (this->m_disabled == 0) {
if (this->geometry.unknown_0030 == style->state) {
found = true;
break;
}
} else if (this->m_disabled == 1 && style->state == 3) {
found = true;
break;
}
}
if (this->m_disabled == 1) {
CBitmapRes* bitmap = dynamic_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_names[3].c_str())));
this->DrawBitmap(0, 0, bitmap ? &bitmap->image : nullptr, false);
if (this->text.size() > 0) {
if (found) {
if (style->shadow == 1) {
this->DrawTextAt(style->x, style->y, this->text.c_str(), 0, 0, style->height, 0xE2E2E2, 0, 0);
}
this->DrawTextAt(style->x + 1, style->y + 1, this->text.c_str(), 0, 0, style->height, style->color, style->bold, 0);
} else {
const int x = static_cast<int>((this->geometry.width - this->TextWidth(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
const int y = static_cast<int>((this->geometry.height - this->TextHeight(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
this->DrawTextAt(x, y, this->text.c_str(), 0, 0, 12, 0xE2E2E2, 0, 0);
this->DrawTextAt(x + 1, y + 1, this->text.c_str(), 0, 0, 12, 0x6F6F6F, 0, 0);
}
}
} else {
switch (this->geometry.unknown_0030) {
case 0: {
CBitmapRes* bitmap = dynamic_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_names[0].c_str())));
this->DrawBitmap(0, 0, bitmap ? &bitmap->image : nullptr, false);
if (this->text.size() > 0) {
if (found) {
if (style->shadow == 1) {
this->DrawTextAt(style->x + 1, style->y + 1, this->text.c_str(), 0, 0, style->height, 0xD7D7D7, style->bold, 0);
}
this->DrawTextAt(style->x, style->y, this->text.c_str(), 0, 0, style->height, style->color, style->bold, 0);
} else {
const int x = static_cast<int>((this->geometry.width - this->TextWidth(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
const int y = static_cast<int>((this->geometry.height - this->TextHeight(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
this->DrawTextAt(x + 1, y + 1, this->text.c_str(), 0, 0, 12, 0xD7D7D7, 0, 0);
this->DrawTextAt(x, y, this->text.c_str(), 0, 0, 12, 0, 0, 0);
}
}
break;
}
case 1: {
CBitmapRes* bitmap = dynamic_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_names[1].c_str())));
this->DrawBitmap(0, 0, bitmap ? &bitmap->image : nullptr, false);
if (this->text.size() > 0) {
if (found) {
if (style->shadow == 1) {
this->DrawTextAt(style->x + 1, style->y + 1, this->text.c_str(), 0, 0, style->height, 0xC7A796, style->bold, 0);
}
this->DrawTextAt(style->x, style->y, this->text.c_str(), 0, 0, style->height, style->color, style->bold, 0);
} else {
const int x = static_cast<int>((this->geometry.width - this->TextWidth(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
const int y = static_cast<int>((this->geometry.height - this->TextHeight(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
this->DrawTextAt(x + 1, y + 1, this->text.c_str(), 0, 0, 12, 0xC7A796, 0, 0);
this->DrawTextAt(x, y, this->text.c_str(), 0, 0, 12, 0, 0, 0);
}
}
break;
}
case 2: {
CBitmapRes* bitmap = dynamic_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_names[2].c_str())));
this->DrawBitmap(0, 0, bitmap ? &bitmap->image : nullptr, false);
if (this->text.size() > 0) {
if (found) {
if (style->shadow == 1) {
this->DrawTextAt(style->x, style->y, this->text.c_str(), 0, 0, style->height, 0xFFFFFF, style->bold, 0);
}
this->DrawTextAt(style->x + 1, style->y + 1, this->text.c_str(), 0, 0, style->height, style->color, style->bold, 0);
} else {
const int x = static_cast<int>((this->geometry.width - this->TextWidth(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
const int y = static_cast<int>((this->geometry.height - this->TextHeight(this->text.c_str(), 0, 0, 12, 0, 0)) * 0.5);
this->DrawTextAt(x, y, this->text.c_str(), 0, 0, 12, 0xFFFFFF, 0, 0);
this->DrawTextAt(x + 1, y + 1, this->text.c_str(), 0, 0, 12, 0, 0, 0);
}
}
break;
}
}
}
if (this->m_invalidateParent == 1 && this->parent) {
this->parent->Invalidate();
}
}