Maintenance: [forced, user-approved] Family C5: remove fabricated EditPainting/LinkLayout paint aggregate. UIEditCtrl::PaintText (0x8
Batch #10191 by ragnarok-clanker: forced by an admin (7 lower score(s), 10 changed function(s)); checked with 66 compiled unit(s), including every includer of Source/UI/Edit/UIEditCtrl.h, Source/UI/Edit/UIEditPaint.inl.
This commit is contained in:
parent
b30b72eee9
commit
d004f563dc
4 changed files with 99 additions and 224 deletions
|
|
@ -113,6 +113,7 @@
|
|||
#include "UI/Dialogs/UINpcEditDialogWnd.h"
|
||||
#include "UI/Rodex/UIRodexComposeWnd.h"
|
||||
#include "UI/UIBartermarketWnd.h"
|
||||
#include "UI/Edit/UIEditPaint.inl"
|
||||
// GLOBAL: gl_24862
|
||||
bool g_vendingSaleAlarm;
|
||||
|
||||
|
|
@ -194,161 +195,6 @@ protected:
|
|||
~EditLinkLayout() = default;
|
||||
};
|
||||
|
||||
struct EditPainting {
|
||||
std::string& text;
|
||||
const int& anchor;
|
||||
const int& cursor;
|
||||
const int& mask;
|
||||
const int& firstVisible;
|
||||
const int& y;
|
||||
const int& invalidatesParent;
|
||||
const std::uint32_t& color;
|
||||
const std::uint32_t& secondColor;
|
||||
const bool& focused;
|
||||
const bool& chatInputFocused;
|
||||
const bool& caretEnabled;
|
||||
const std::uint32_t& tick;
|
||||
const int& candidateCursor;
|
||||
const int& width;
|
||||
const int& height;
|
||||
const int& screenWidth;
|
||||
const int& screenHeight;
|
||||
const InputCharset& charset;
|
||||
EditViewport& viewport;
|
||||
CDC& surface;
|
||||
FontCache& fonts;
|
||||
const TextLocale& locale;
|
||||
const BitmapImage& colorChip;
|
||||
UIWindow* const& parent;
|
||||
UIWindow* const& candidateWindow;
|
||||
UIWindow* const& readingWindow;
|
||||
const int& absoluteX;
|
||||
const int& absoluteY;
|
||||
const std::list<UIWindow*>& linkWindows;
|
||||
EditLinkLayout& links;
|
||||
|
||||
bool alternate = false;
|
||||
const std::string* placeholder = nullptr;
|
||||
std::uint32_t placeholderColor = 0;
|
||||
bool placeholderEnabled = false;
|
||||
|
||||
void Draw();
|
||||
};
|
||||
// INLINED
|
||||
void EditPainting::Draw() {
|
||||
TextContext context(this->surface);
|
||||
context.SetFont(0, 12, 0, 0);
|
||||
const auto measure = [&](const char* text, int bytes) { return context.Measure(text, bytes ? bytes : static_cast<int>(std::strlen(text))).cx; };
|
||||
int x = 3;
|
||||
|
||||
if (this->invalidatesParent == 0 && this->firstVisible != 0) {
|
||||
x = (3 - measure(this->text.c_str(), this->firstVisible));
|
||||
}
|
||||
|
||||
const auto draw = [&](const std::string& value) {
|
||||
const bool placeholder = this->alternate && !this->focused && this->placeholderEnabled && this->secondColor == 0xFFFFFFFFu;
|
||||
context.SetColor(placeholder ? this->placeholderColor : this->color);
|
||||
const std::string& displayed = placeholder && value.empty() ? *this->placeholder : value;
|
||||
context.Draw(x, this->y, displayed.c_str(), static_cast<int>(displayed.size()));
|
||||
|
||||
if (this->secondColor != 0xFFFFFFFFu) {
|
||||
context.SetColor(this->secondColor);
|
||||
context.Draw((x - 1), this->y, value.c_str(), static_cast<int>(value.size()));
|
||||
}
|
||||
};
|
||||
const auto highlight = [&](int left, int extent) {
|
||||
const int start = std::max(left, 3);
|
||||
const int adjusted = left < 3 ? (extent + (left - 3)) : extent;
|
||||
|
||||
if (start < this->width && adjusted > 0) {
|
||||
std::uint32_t pixel = 0x00FF0000u;
|
||||
|
||||
if (this->colorChip.width > 6 && this->colorChip.height > 2) {
|
||||
pixel = this->colorChip.pixels[2 * this->colorChip.width + 6];
|
||||
}
|
||||
|
||||
const std::uint32_t color = ((pixel >> 16) & 255) | (pixel & 0xFF00) | ((pixel & 255) << 16);
|
||||
RECT rectangle{start, 0, std::min((start + adjusted), this->width), this->height};
|
||||
this->surface.Fill(&rectangle, color);
|
||||
}
|
||||
};
|
||||
const auto moveCandidate = [&](UIWindow* window, int offset) {
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
int left = (offset + this->absoluteX);
|
||||
int top = ((this->height + 6) + this->absoluteY);
|
||||
|
||||
if ((window->geometry.width + left) > this->screenWidth) {
|
||||
left = (this->screenWidth - window->geometry.width);
|
||||
}
|
||||
|
||||
if ((window->geometry.height + top) > this->screenHeight) {
|
||||
top = (((top - 12) - this->height) - window->geometry.height);
|
||||
}
|
||||
|
||||
window->Move(left, top);
|
||||
};
|
||||
std::string display;
|
||||
|
||||
if (this->focused) {
|
||||
this->viewport.Synchronize();
|
||||
unsigned begin = static_cast<unsigned>(std::min(this->anchor, this->cursor));
|
||||
unsigned end = static_cast<unsigned>(std::max(this->anchor, this->cursor));
|
||||
|
||||
if (this->mask != 0) {
|
||||
display.assign(this->text.size(), static_cast<char>(this->mask));
|
||||
} else {
|
||||
const char* prefix = this->alternate ? g_serverLanguage->candidate.c_str() : g_serverLanguage->Prefix(false);
|
||||
display = prefix;
|
||||
display += this->text;
|
||||
const auto prefixBytes = static_cast<unsigned>(std::strlen(prefix));
|
||||
begin += prefixBytes;
|
||||
end += prefixBytes + static_cast<unsigned>(this->candidateCursor);
|
||||
}
|
||||
|
||||
const int left = begin == 0 ? 0 : measure(display.c_str(), static_cast<int>(begin));
|
||||
const int right = end == 0 ? 0 : measure(display.c_str(), static_cast<int>(end));
|
||||
|
||||
if (g_serverLanguage->cursor != g_serverLanguage->anchor) {
|
||||
highlight((x + left), (right - left));
|
||||
draw(display);
|
||||
} else if (this->candidateCursor != 0) {
|
||||
moveCandidate(this->candidateWindow, left);
|
||||
moveCandidate(this->readingWindow, right);
|
||||
|
||||
if (((this->tick / 500u) & 1u) == 0) {
|
||||
highlight((x + left), std::max((right - left), 2));
|
||||
}
|
||||
|
||||
draw(display);
|
||||
} else {
|
||||
draw(display);
|
||||
|
||||
if (((this->tick / 500u) & 1u) == 0 && (this->alternate ? this->caretEnabled : (!this->chatInputFocused || this->caretEnabled))) {
|
||||
context.SetColor(this->color);
|
||||
context.Draw(((x + left) - 2), this->y, "|", 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this->mask != 0) {
|
||||
display.assign(this->text.size(), static_cast<char>(this->mask));
|
||||
} else {
|
||||
display = this->text;
|
||||
}
|
||||
|
||||
draw(display);
|
||||
|
||||
if (this->invalidatesParent != 0 && this->parent) {
|
||||
this->parent->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
if (std::any_of(this->linkWindows.begin(), this->linkWindows.end(), [](const UIWindow* window) { return window->geometry.id == 438; })) {
|
||||
this->links.Update();
|
||||
}
|
||||
}
|
||||
class LinkLayout : public EditLinkLayout {
|
||||
public:
|
||||
// INLINED
|
||||
|
|
@ -558,76 +404,10 @@ void UIEditCtrl::SelectAll() {
|
|||
// OFFSET: 0x00856980
|
||||
// FUNCTION: fn_10755
|
||||
void UIEditCtrl::PaintText() {
|
||||
this->PaintTextWithPolicy(false, nullptr, 0, false);
|
||||
this->PaintTextWithPolicy(nullptr, 0, false);
|
||||
}
|
||||
|
||||
// INLINED
|
||||
void UIEditCtrl::PaintTextWithPolicy(bool alternate, const std::string* placeholder, std::uint32_t placeholderColor, bool placeholderEnabled) {
|
||||
const bool focused = g_windowMgr.hoverWindow == this;
|
||||
EditTextState state{this->text, this->anchor, this->cursor, this->maximum, focused, g_textCodePage};
|
||||
EditViewport viewport{
|
||||
this->text,
|
||||
this->anchor,
|
||||
this->cursor,
|
||||
this->firstVisible,
|
||||
this->geometry.width,
|
||||
g_textCodePage,
|
||||
state,
|
||||
*this->geometry.surface,
|
||||
g_fontCache,
|
||||
this->m_context->locale
|
||||
};
|
||||
UIWindow* parent = this->parent;
|
||||
int left = 0, top = 0;
|
||||
|
||||
for (const UIWindow* window = this; window; window = window->parent) {
|
||||
left += window->geometry.x;
|
||||
top += window->geometry.y;
|
||||
}
|
||||
|
||||
const bool chat = (g_chatSuggestions && g_chatSuggestions->unknown_00BC == this) || this->m_edit->otherChatInput == this;
|
||||
const DWORD tick = timeGetTime();
|
||||
LinkLayout layout(*this);
|
||||
EditPainting painting{
|
||||
this->text,
|
||||
this->anchor,
|
||||
this->cursor,
|
||||
this->mask,
|
||||
this->firstVisible,
|
||||
this->textY,
|
||||
this->invalidatesParent,
|
||||
this->textColor,
|
||||
this->secondColor,
|
||||
focused,
|
||||
chat,
|
||||
reinterpret_cast<const bool&>(g_windowMgr.unknown_0024),
|
||||
tick,
|
||||
g_serverLanguage->compositionCursor,
|
||||
this->geometry.width,
|
||||
this->geometry.height,
|
||||
g_renderer->viewport.width,
|
||||
g_renderer->viewport.height,
|
||||
this->m_edit->charset,
|
||||
viewport,
|
||||
*this->geometry.surface,
|
||||
g_fontCache,
|
||||
this->m_context->locale,
|
||||
this->m_edit->colorChip,
|
||||
parent,
|
||||
g_windowMgr.window_03A4,
|
||||
g_windowMgr.window_03AC,
|
||||
left,
|
||||
top,
|
||||
this->links,
|
||||
layout
|
||||
};
|
||||
|
||||
painting.alternate = alternate;
|
||||
painting.placeholder = placeholder;
|
||||
painting.placeholderColor = placeholderColor;
|
||||
painting.placeholderEnabled = placeholderEnabled;
|
||||
painting.Draw();
|
||||
}
|
||||
|
||||
// OFFSET: 0x00862FB0
|
||||
void UIEditCtrl::Synchronize() {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public:
|
|||
|
||||
protected:
|
||||
UIEditContext* m_edit;
|
||||
void PaintTextWithPolicy(bool alternate, const std::string* placeholder, std::uint32_t placeholderColor, bool placeholderEnabled);
|
||||
void PaintTextWithPolicy(const std::string* placeholder, std::uint32_t placeholderColor, bool placeholderEnabled);
|
||||
bool RemoveInvalidLink(std::list<UIWindow*>::iterator& entry);
|
||||
void SnapLinkSelection(std::size_t prefix, std::size_t bytes);
|
||||
std::string BracketFittedText(const std::string& name);
|
||||
|
|
|
|||
94
Source/UI/Edit/UIEditPaint.inl
Normal file
94
Source/UI/Edit/UIEditPaint.inl
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#ifndef RAGNAROK_SOURCE_UI_EDIT_UIEDITPAINT_INL
|
||||
#define RAGNAROK_SOURCE_UI_EDIT_UIEDITPAINT_INL
|
||||
|
||||
#include "Client/Input/Language.h"
|
||||
#include "UI/Edit/UIEditCtrl.h"
|
||||
#include "UI/Window/UIWindowMgr.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
// INLINED
|
||||
__forceinline void UIEditCtrl::PaintTextWithPolicy(const std::string* placeholder, std::uint32_t placeholderColor, bool placeholderEnabled) {
|
||||
int x = 3;
|
||||
if (this->invalidatesParent == 0 && this->firstVisible != 0) {
|
||||
x -= this->TextWidth(this->text.c_str(), this->firstVisible, 0, 12, 0, 0);
|
||||
}
|
||||
|
||||
std::string display;
|
||||
if (g_windowMgr.GetHoverWindow() == this) {
|
||||
this->Synchronize();
|
||||
unsigned begin;
|
||||
unsigned end;
|
||||
if (this->mask != 0) {
|
||||
display.assign(this->text.size(), static_cast<char>(this->mask));
|
||||
begin = std::min(this->anchor, this->cursor);
|
||||
end = std::max(this->anchor, this->cursor);
|
||||
} else {
|
||||
const char* prefix = g_serverLanguage->Prefix(false);
|
||||
display = prefix + this->text;
|
||||
const unsigned prefixBytes = static_cast<unsigned>(std::strlen(prefix));
|
||||
begin = std::min(this->anchor, this->cursor) + prefixBytes;
|
||||
end = std::max(this->anchor, this->cursor) + g_serverLanguage->compositionCursor + prefixBytes;
|
||||
}
|
||||
|
||||
const int left = begin ? this->TextWidth(display.c_str(), begin, 0, 12, 0, 0) : 0;
|
||||
const int right = end ? this->TextWidth(display.c_str(), end, 0, 12, 0, 0) : 0;
|
||||
|
||||
if (std::abs(g_serverLanguage->cursor - g_serverLanguage->anchor) != 0) {
|
||||
this->DrawSelection(left + x, right - left);
|
||||
} else if (g_serverLanguage->compositionCursor != 0) {
|
||||
this->MoveCandidateWindow(left);
|
||||
this->MoveReadingWindow(right);
|
||||
if (((timeGetTime() / 500) & 1) == 0) {
|
||||
this->DrawSelection(left + x, std::max(right - left, 2));
|
||||
}
|
||||
} else {
|
||||
if (this->secondColor == 0xFFFFFFFF) {
|
||||
this->DrawTextAt(x, this->textY, display.c_str(), 0, 0, 12, this->textColor, 0, 0);
|
||||
} else {
|
||||
this->DrawEmboldenedText(x, this->textY, display.c_str(), this->textColor, this->secondColor, 0, 0, 12);
|
||||
}
|
||||
if (((timeGetTime() / 500) & 1) == 0 && IsInputSuggestionAllowed()) {
|
||||
this->DrawTextAt(left + x - 2, this->textY, "|", 0, 0, 12, this->textColor, 0, 0);
|
||||
}
|
||||
if (this->invalidatesParent != 0 && this->parent) {
|
||||
this->parent->Invalidate();
|
||||
}
|
||||
this->UpdateLinks();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->secondColor == 0xFFFFFFFF) {
|
||||
this->DrawTextAt(x, this->textY, display.c_str(), 0, 0, 12, this->textColor, 0, 0);
|
||||
} else {
|
||||
this->DrawEmboldenedText(x, this->textY, display.c_str(), this->textColor, this->secondColor, 0, 0, 12);
|
||||
}
|
||||
this->UpdateLinks();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->mask != 0) {
|
||||
display.assign(this->text.size(), static_cast<char>(this->mask));
|
||||
} else {
|
||||
display = this->text;
|
||||
}
|
||||
if (this->secondColor == 0xFFFFFFFF) {
|
||||
if (placeholderEnabled) {
|
||||
this->DrawTextAt(x, this->textY, display == "" ? placeholder->c_str() : display.c_str(), 0, 0, 12, placeholderColor, 0, 0);
|
||||
} else {
|
||||
this->DrawTextAt(x, this->textY, display.c_str(), 0, 0, 12, this->textColor, 0, 0);
|
||||
}
|
||||
} else {
|
||||
this->DrawEmboldenedText(x, this->textY, display.c_str(), this->textColor, this->secondColor, 0, 0, 12);
|
||||
}
|
||||
if (this->invalidatesParent != 0 && this->parent) {
|
||||
this->parent->Invalidate();
|
||||
}
|
||||
this->UpdateLinks();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -773,7 +773,7 @@ void UIEditCtrl4::Slot23() {
|
|||
// OFFSET: 0x008563D0
|
||||
// FUNCTION: fn_10754
|
||||
void UIEditCtrl4::PaintText() {
|
||||
this->PaintTextWithPolicy(true, &this->placeholder, this->placeholderColor, this->placeholderEnabled == 1);
|
||||
this->PaintTextWithPolicy(&this->placeholder, this->placeholderColor, this->placeholderEnabled == 1);
|
||||
}
|
||||
|
||||
// OFFSET: 0x00869800
|
||||
|
|
@ -1121,6 +1121,7 @@ UIShowAndEditTimeCtrl::UIShowAndEditTimeCtrl(UIWindowContext& windows) : UIWindo
|
|||
}
|
||||
|
||||
#include "UI/Edit/UIItemTagCtrl.h"
|
||||
#include "UI/Edit/UIEditPaint.inl"
|
||||
|
||||
// OFFSET: 0x0085C4F0
|
||||
// FUNCTION: fn_10801
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue