rodecomp/Source/UI/Buttons/UICheckBox.cpp
ragnarok-clanker 1fcafbcdd3 Decompile fn_10803 (UICheckBox::Paint)
Batch #12919 by cremane: 0 byte-identical, 1 confirmed by peer review.

- fn_10803 UICheckBox::Paint: logic confirmed by peer review

Peer-reviewed-by: gordaoprogramas, Toshiro, codeplay
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-11-06 12:36:37 +00:00

205 lines
5.5 KiB
C++

#include "Client/Mode/CMode.h"
#include "Client/Mode/ModeMgr.h"
#include "UI/Window/UINewSelectCharWnd.h"
#include "Client/Replay.h"
#include "Render/DeviceContext/DeviceContext.h"
#include "Resource/Bitmap/BitmapResource.h"
#include "Resource/ResourceMgr.h"
#include "Resource/TextureNames.h"
#include "UI/Buttons/UICheckBox.h"
// OFFSET: 0x0084F010
// FUNCTION: fn_10656
UICheckBox::UICheckBox()
: UIWindow(0), m_disabled(0), m_hidden(0), m_color(0), m_fontHeight(12), m_message(-1), m_notify(0) {
this->geometry.unknown_0030 = 0;
this->geometry.id = 213;
}
// OFFSET: 0x008514C0
// FUNCTION: fn_10691
UICheckBox::~UICheckBox() = default;
// OFFSET: 0x0085C8C0
// FUNCTION: fn_10803
void UICheckBox::Paint() {
int width = 0;
if (this->m_checked.empty() || this->m_unchecked.empty()) {
return;
}
if (this->m_disabled != 0) {
this->ClearSurface(0xFFFF00FFu);
return;
}
if (this->m_hidden != 0) {
return;
}
switch (this->geometry.unknown_0030) {
case 0: {
CBitmapRes* bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_unchecked.c_str())));
this->DrawBitmap(0, (this->geometry.height - bitmap->image.height) / 2, &bitmap->image, false);
width = bitmap->image.width;
break;
}
case 1: {
CBitmapRes* bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_checked.c_str())));
this->DrawBitmap(0, (this->geometry.height - bitmap->image.height) / 2, &bitmap->image, false);
width = bitmap->image.width;
break;
}
}
if (!this->m_text.empty()) {
this->DrawTextAt((width + 3), 0, this->m_text.c_str(), 0, 0, this->m_fontHeight, this->m_color, 0, 0);
}
}
// INLINED
__forceinline void UICheckBox::Notify() {
this->Invalidate();
if (this->Root()) {
this->Root()->Invalidate();
}
if (this->parent) {
this->parent->SendMsg(this, 6, this->geometry.id, this->geometry.unknown_0030, 0, 0);
}
}
// OFFSET: 0x008658D0
// FUNCTION: fn_10932
void UICheckBox::SetChecked(int value) {
if (this->m_disabled != 0) {
return;
}
this->geometry.unknown_0030 = value;
this->Notify();
}
// OFFSET: 0x0086AF70
// FUNCTION: fn_10999
void UICheckBox::SetHidden(bool hidden) {
this->m_hidden = hidden;
this->Show(!hidden);
this->Invalidate();
}
// OFFSET: 0x0085EB90
// FUNCTION: fn_10841
void UICheckBox::Slot25(int, int) {
if (this->m_disabled != 0 || g_replayAnimationScaling) {
return;
}
this->geometry.unknown_0030 = 1u - this->geometry.unknown_0030;
this->Notify();
if (this->m_notify != 0) {
this->parent->SendMsg(this, 2, this->m_message, 0, 0, 0);
}
}
// OFFSET: 0x0085F310
// FUNCTION: fn_10859
void UICheckBox::Slot28(int x, int y) {
if (this->m_disabled != 0) {
return;
}
this->Slot27(x, y);
if (this->m_tooltip.empty()) {
return;
}
int screenX = 0;
int screenY = -20;
this->ToScreen(screenX, screenY);
if (this->geometry.unknown_0030 != 0 || this->m_uncheckedTooltip.empty()) {
g_modeMgr.gameMode->ShowTooltip(this->m_tooltip.c_str(), screenX, screenY, -1, false, true);
} else {
g_modeMgr.gameMode->ShowTooltip(this->m_uncheckedTooltip.c_str(), screenX, screenY, -1, false, true);
}
}
// OFFSET: 0x0085F9C0
// FUNCTION: fn_10877
void UICheckBox::ResetCursor(int, int) {
if (this->m_disabled == 0) {
g_modeMgr.gameMode->SetCursorAction(2);
}
}
// OFFSET: 0x00865450
// FUNCTION: fn_10926
void UICheckBox::SetImages(const char* checked, const char* unchecked, const char* text) {
this->m_checked = checked;
this->m_unchecked = unchecked;
ResourceMgr::Instance().Load(Resolve(this->m_unchecked.c_str()));
this->m_text = text ? text : "";
if (!this->m_text.empty()) {
const int width = this->TextWidth(this->m_text.c_str(), 0, 0, 12, 0, 0);
CBitmapRes* bitmap = nullptr;
switch (this->geometry.unknown_0030) {
case 0:
bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_unchecked.c_str())));
break;
case 1:
bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_checked.c_str())));
break;
}
const int desired = ((bitmap->image.width + width) + 3);
if (desired != this->geometry.width) {
this->Resize(desired, this->geometry.height);
}
}
}
// OFFSET: 0x00865600
// FUNCTION: fn_10928
void UICheckBox::SetBitmaps(const char* checked, const char* unchecked) {
this->m_checked = checked;
this->m_unchecked = unchecked;
CBitmapRes* bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_checked.c_str())));
this->geometry.width = bitmap->image.width;
this->geometry.height = bitmap->image.height;
ResourceMgr::Instance().Load(Resolve(this->m_unchecked.c_str()));
}
// OFFSET: 0x00869760
// FUNCTION: fn_10968
void UICheckBox::SetTooltip(const char* text) {
if (text) {
this->m_tooltip = text;
}
}
// OFFSET: 0x008653B0
// FUNCTION: fn_10925
void UICheckBox::FitToText() {
if (this->m_text.empty()) {
return;
}
const int width = this->TextWidth(this->m_text.c_str(), 0, 0, 12, 0, 0);
CBitmapRes* bitmap = nullptr;
switch (this->geometry.unknown_0030) {
case 0:
bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_unchecked.c_str())));
break;
case 1:
bitmap = static_cast<CBitmapRes*>(ResourceMgr::Instance().Load(Resolve(this->m_checked.c_str())));
break;
}
const int desired = ((bitmap->image.width + width) + 3);
if (desired != this->geometry.width) {
this->Resize(desired, this->geometry.height);
}
}