Browse Source

🎨 readability-identifier-naming on DiabloUI

pull/1639/head
Anders Jenbo 5 years ago
parent
commit
191d98207b
  1. 10
      Source/DiabloUI/art.cpp
  2. 58
      Source/DiabloUI/art_draw.cpp
  3. 6
      Source/DiabloUI/button.cpp
  4. 64
      Source/DiabloUI/credits.cpp
  5. 168
      Source/DiabloUI/diabloui.cpp
  6. 4
      Source/DiabloUI/dialogs.cpp
  7. 8
      Source/DiabloUI/fonts.cpp
  8. 12
      Source/DiabloUI/mainmenu.cpp
  9. 22
      Source/DiabloUI/progress.cpp
  10. 26
      Source/DiabloUI/selconn.cpp
  11. 174
      Source/DiabloUI/selhero.cpp
  12. 10
      Source/DiabloUI/selyesno.cpp
  13. 38
      Source/DiabloUI/text_draw.cpp
  14. 8
      Source/DiabloUI/title.cpp
  15. 20
      Source/DiabloUI/ttf_render_wrapped.cpp

10
Source/DiabloUI/art.cpp

@ -33,18 +33,18 @@ void LoadArt(const char *pszFile, Art *art, int frames, SDL_Color *pPalette)
format = 0;
break;
}
SDLSurfaceUniquePtr art_surface { SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, width, height, bpp, format) };
SDLSurfaceUniquePtr artSurface { SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, width, height, bpp, format) };
if (!SBmpLoadImage(pszFile, pPalette, static_cast<BYTE *>(art_surface->pixels),
art_surface->pitch * art_surface->format->BytesPerPixel * height, nullptr, nullptr, nullptr)) {
if (!SBmpLoadImage(pszFile, pPalette, static_cast<BYTE *>(artSurface->pixels),
artSurface->pitch * artSurface->format->BytesPerPixel * height, nullptr, nullptr, nullptr)) {
SDL_Log("Failed to load image");
return;
}
art->logical_width = art_surface->w;
art->logical_width = artSurface->w;
art->frame_height = height / frames;
art->surface = ScaleSurfaceToOutput(std::move(art_surface));
art->surface = ScaleSurfaceToOutput(std::move(artSurface));
}
void LoadMaskedArt(const char *pszFile, Art *art, int frames, int mask)

58
Source/DiabloUI/art_draw.cpp

@ -12,20 +12,20 @@ void DrawArt(Sint16 screenX, Sint16 screenY, Art *art, int nFrame, Uint16 srcW,
if (screenY >= gnScreenHeight || screenX >= gnScreenWidth || art->surface == nullptr)
return;
SDL_Rect src_rect;
src_rect.x = 0;
src_rect.y = nFrame * art->h();
src_rect.w = art->w();
src_rect.h = art->h();
SDL_Rect srcRect;
srcRect.x = 0;
srcRect.y = nFrame * art->h();
srcRect.w = art->w();
srcRect.h = art->h();
ScaleOutputRect(&src_rect);
ScaleOutputRect(&srcRect);
if (srcW && srcW < src_rect.w)
src_rect.w = srcW;
if (srcH && srcH < src_rect.h)
src_rect.h = srcH;
SDL_Rect dst_rect = { screenX, screenY, src_rect.w, src_rect.h };
ScaleOutputRect(&dst_rect);
if (srcW && srcW < srcRect.w)
srcRect.w = srcW;
if (srcH && srcH < srcRect.h)
srcRect.h = srcH;
SDL_Rect dstRect = { screenX, screenY, srcRect.w, srcRect.h };
ScaleOutputRect(&dstRect);
if (art->surface->format->BitsPerPixel == 8 && art->palette_version != pal_surface_palette_version) {
if (SDLC_SetSurfaceColors(art->surface.get(), pal_surface->format->palette) <= -1)
@ -33,7 +33,7 @@ void DrawArt(Sint16 screenX, Sint16 screenY, Art *art, int nFrame, Uint16 srcW,
art->palette_version = pal_surface_palette_version;
}
if (SDL_BlitSurface(art->surface.get(), &src_rect, DiabloUiSurface(), &dst_rect) < 0)
if (SDL_BlitSurface(art->surface.get(), &srcRect, DiabloUiSurface(), &dstRect) < 0)
ErrSdl();
}
@ -42,21 +42,21 @@ void DrawArt(const CelOutputBuffer &out, Sint16 screenX, Sint16 screenY, Art *ar
if (screenY >= gnScreenHeight || screenX >= gnScreenWidth || art->surface == nullptr)
return;
SDL_Rect src_rect;
src_rect.x = 0;
src_rect.y = nFrame * art->h();
src_rect.w = art->w();
src_rect.h = art->h();
if (srcW && srcW < src_rect.w)
src_rect.w = srcW;
if (srcH && srcH < src_rect.h)
src_rect.h = srcH;
SDL_Rect dst_rect;
dst_rect.x = BUFFER_BORDER_LEFT + screenX;
dst_rect.y = BUFFER_BORDER_TOP + screenY;
dst_rect.w = src_rect.w;
dst_rect.h = src_rect.h;
SDL_Rect srcRect;
srcRect.x = 0;
srcRect.y = nFrame * art->h();
srcRect.w = art->w();
srcRect.h = art->h();
if (srcW && srcW < srcRect.w)
srcRect.w = srcW;
if (srcH && srcH < srcRect.h)
srcRect.h = srcH;
SDL_Rect dstRect;
dstRect.x = BUFFER_BORDER_LEFT + screenX;
dstRect.y = BUFFER_BORDER_TOP + screenY;
dstRect.w = srcRect.w;
dstRect.h = srcRect.h;
if (art->surface->format->BitsPerPixel == 8 && art->palette_version != pal_surface_palette_version) {
if (SDLC_SetSurfaceColors(art->surface.get(), out.surface->format->palette) <= -1)
@ -64,7 +64,7 @@ void DrawArt(const CelOutputBuffer &out, Sint16 screenX, Sint16 screenY, Art *ar
art->palette_version = pal_surface_palette_version;
}
if (SDL_BlitSurface(art->surface.get(), &src_rect, out.surface, &dst_rect) < 0)
if (SDL_BlitSurface(art->surface.get(), &srcRect, out.surface, &dstRect) < 0)
ErrSdl();
}

6
Source/DiabloUI/button.cpp

@ -23,13 +23,13 @@ void RenderButton(UiButton *button)
}
DrawArt(button->m_rect.x, button->m_rect.y, button->m_art, frame, button->m_rect.w, button->m_rect.h);
SDL_Rect text_rect = button->m_rect;
SDL_Rect textRect = button->m_rect;
if (!button->m_pressed)
--text_rect.y;
--textRect.y;
SDL_Color color1 = { 243, 243, 243, 0 };
SDL_Color color2 = { 0, 0, 0, 0 };
DrawTTF(button->m_text, text_rect, UIS_CENTER,
DrawTTF(button->m_text, textRect, UIS_CENTER,
color1, color2, button->m_render_cache);
}

64
Source/DiabloUI/credits.cpp

@ -19,8 +19,8 @@ namespace devilution {
namespace {
const SDL_Rect VIEWPORT = { 0, 114, 640, 251 };
const int SHADOW_OFFSET_X = 2;
const int SHADOW_OFFSET_Y = 2;
const int ShadowOffsetX = 2;
const int ShadowOffsetY = 2;
const int LINE_H = 22;
char const *const *text;
@ -67,29 +67,29 @@ CachedLine PrepareLine(std::size_t index)
while (contents[0] == '\t')
++contents;
const SDL_Color shadow_color = { 0, 0, 0, 0 };
SDLSurfaceUniquePtr text { RenderText(contents, shadow_color) };
const SDL_Color shadowColor = { 0, 0, 0, 0 };
SDLSurfaceUniquePtr text { RenderText(contents, shadowColor) };
// Precompose shadow and text:
SDLSurfaceUniquePtr surface;
if (text != nullptr) {
// Set up the target surface to have 3 colors: mask, text, and shadow.
surface = SDLSurfaceUniquePtr { SDL_CreateRGBSurfaceWithFormat(0, text->w + SHADOW_OFFSET_X, text->h + SHADOW_OFFSET_Y, 8, SDL_PIXELFORMAT_INDEX8) };
const SDL_Color mask_color = { 0, 255, 0, 0 }; // Any color different from both shadow and text
const SDL_Color &text_color = palette->colors[224];
SDL_Color colors[3] = { mask_color, text_color, shadow_color };
surface = SDLSurfaceUniquePtr { SDL_CreateRGBSurfaceWithFormat(0, text->w + ShadowOffsetX, text->h + ShadowOffsetY, 8, SDL_PIXELFORMAT_INDEX8) };
const SDL_Color maskColor = { 0, 255, 0, 0 }; // Any color different from both shadow and text
const SDL_Color &textColor = palette->colors[224];
SDL_Color colors[3] = { maskColor, textColor, shadowColor };
if (SDLC_SetSurfaceColors(surface.get(), colors, 0, 3) <= -1)
SDL_Log("%s", SDL_GetError());
SDLC_SetColorKey(surface.get(), 0);
// Blit the shadow first:
SDL_Rect shadow_rect = { SHADOW_OFFSET_X, SHADOW_OFFSET_Y, 0, 0 };
if (SDL_BlitSurface(text.get(), nullptr, surface.get(), &shadow_rect) <= -1)
SDL_Rect shadowRect = { ShadowOffsetX, ShadowOffsetY, 0, 0 };
if (SDL_BlitSurface(text.get(), nullptr, surface.get(), &shadowRect) <= -1)
ErrSdl();
// Change the text surface color and blit again:
SDL_Color text_colors[2] = { mask_color, text_color };
if (SDLC_SetSurfaceColors(text.get(), text_colors, 0, 2) <= -1)
SDL_Color textColors[2] = { maskColor, textColor };
if (SDLC_SetSurfaceColors(text.get(), textColors, 0, 2) <= -1)
ErrSdl();
SDLC_SetColorKey(text.get(), 0);
@ -136,10 +136,10 @@ private:
void CreditsRenderer::Render()
{
const int offset_y = -VIEWPORT.h + (SDL_GetTicks() - ticks_begin_) / 40;
if (offset_y == prev_offset_y_)
const int offsetY = -VIEWPORT.h + (SDL_GetTicks() - ticks_begin_) / 40;
if (offsetY == prev_offset_y_)
return;
prev_offset_y_ = offset_y;
prev_offset_y_ = offsetY;
SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000);
DrawArt(PANEL_LEFT - 320, UI_OFFSET_Y, &ArtBackgroundWidescreen);
@ -147,16 +147,16 @@ void CreditsRenderer::Render()
if (font == nullptr)
return;
const std::size_t lines_begin = std::max(offset_y / LINE_H, 0);
const std::size_t lines_end = std::min(lines_begin + MAX_VISIBLE_LINES, textLines);
const std::size_t linesBegin = std::max(offsetY / LINE_H, 0);
const std::size_t linesEnd = std::min(linesBegin + MAX_VISIBLE_LINES, textLines);
if (lines_begin >= lines_end) {
if (lines_end == textLines)
if (linesBegin >= linesEnd) {
if (linesEnd == textLines)
finished_ = true;
return;
}
while (lines_end > lines_.size())
while (linesEnd > lines_.size())
lines_.push_back(PrepareLine(lines_.size()));
SDL_Rect viewport = VIEWPORT;
@ -166,8 +166,8 @@ void CreditsRenderer::Render()
SDL_SetClipRect(DiabloUiSurface(), &viewport);
// We use unscaled coordinates for calculation throughout.
Sint16 dest_y = UI_OFFSET_Y + VIEWPORT.y - (offset_y - lines_begin * LINE_H);
for (std::size_t i = lines_begin; i < lines_end; ++i, dest_y += LINE_H) {
Sint16 destY = UI_OFFSET_Y + VIEWPORT.y - (offsetY - linesBegin * LINE_H);
for (std::size_t i = linesBegin; i < linesEnd; ++i, destY += LINE_H) {
CachedLine &line = lines_[i];
if (line.m_surface == nullptr)
continue;
@ -177,16 +177,16 @@ void CreditsRenderer::Render()
line = PrepareLine(line.m_index);
}
Sint16 dest_x = PANEL_LEFT + VIEWPORT.x + 31;
Sint16 destX = PANEL_LEFT + VIEWPORT.x + 31;
int j = 0;
while (text[line.m_index][j++] == '\t')
dest_x += 40;
destX += 40;
SDL_Rect dst_rect = { dest_x, dest_y, 0, 0 };
ScaleOutputRect(&dst_rect);
dst_rect.w = line.m_surface->w;
dst_rect.h = line.m_surface->h;
if (SDL_BlitSurface(line.m_surface.get(), nullptr, DiabloUiSurface(), &dst_rect) < 0)
SDL_Rect dstRect = { destX, destY, 0, 0 };
ScaleOutputRect(&dstRect);
dstRect.w = line.m_surface->w;
dstRect.h = line.m_surface->h;
if (SDL_BlitSurface(line.m_surface.get(), nullptr, DiabloUiSurface(), &dstRect) < 0)
ErrSdl();
}
SDL_SetClipRect(DiabloUiSurface(), nullptr);
@ -194,12 +194,12 @@ void CreditsRenderer::Render()
bool TextDialog()
{
CreditsRenderer credits_renderer;
CreditsRenderer creditsRenderer;
bool endMenu = false;
SDL_Event event;
do {
credits_renderer.Render();
creditsRenderer.Render();
UiFadeIn();
while (SDL_PollEvent(&event)) {
switch (event.type) {
@ -219,7 +219,7 @@ bool TextDialog()
}
UiHandleEvents(&event);
}
} while (!endMenu && !credits_renderer.Finished());
} while (!endMenu && !creditsRenderer.Finished());
return true;
}

168
Source/DiabloUI/diabloui.cpp

@ -61,11 +61,11 @@ namespace {
DWORD fadeTc;
int fadeValue = 0;
struct scrollBarState {
struct ScrollBarState {
bool upArrowPressed;
bool downArrowPressed;
scrollBarState()
ScrollBarState()
{
upArrowPressed = false;
downArrowPressed = false;
@ -111,14 +111,14 @@ void UiInitList(int count, void (*fnFocus)(int value), void (*fnSelect)(int valu
}
}
void UiInitScrollBar(UiScrollBar *ui_sb, std::size_t viewport_size, const std::size_t *current_offset)
void UiInitScrollBar(UiScrollBar *uiSb, std::size_t viewportSize, const std::size_t *currentOffset)
{
ListViewportSize = viewport_size;
ListOffset = current_offset;
ListViewportSize = viewportSize;
ListOffset = currentOffset;
if (ListViewportSize >= static_cast<std::size_t>(SelectedItemMax + 1)) {
ui_sb->add_flag(UIS_HIDDEN);
uiSb->add_flag(UIS_HIDDEN);
} else {
ui_sb->remove_flag(UIS_HIDDEN);
uiSb->remove_flag(UIS_HIDDEN);
}
}
@ -186,12 +186,12 @@ void UiFocusPageUp()
UiFocus(0);
} else {
const std::size_t relpos = SelectedItem - *ListOffset;
std::size_t prev_page_start = SelectedItem - relpos;
if (prev_page_start >= ListViewportSize)
prev_page_start -= ListViewportSize;
std::size_t prevPageStart = SelectedItem - relpos;
if (prevPageStart >= ListViewportSize)
prevPageStart -= ListViewportSize;
else
prev_page_start = 0;
UiFocus(prev_page_start);
prevPageStart = 0;
UiFocus(prevPageStart);
UiFocus(*ListOffset + relpos);
}
}
@ -202,20 +202,20 @@ void UiFocusPageDown()
UiFocus(SelectedItemMax);
} else {
const std::size_t relpos = SelectedItem - *ListOffset;
std::size_t next_page_end = SelectedItem + (ListViewportSize - relpos - 1);
if (next_page_end + ListViewportSize <= static_cast<std::size_t>(SelectedItemMax))
next_page_end += ListViewportSize;
std::size_t nextPageEnd = SelectedItem + (ListViewportSize - relpos - 1);
if (nextPageEnd + ListViewportSize <= static_cast<std::size_t>(SelectedItemMax))
nextPageEnd += ListViewportSize;
else
next_page_end = SelectedItemMax;
UiFocus(next_page_end);
nextPageEnd = SelectedItemMax;
UiFocus(nextPageEnd);
UiFocus(*ListOffset + relpos);
}
}
void selhero_CatToName(char *in_buf, char *out_buf, int cnt)
void SelheroCatToName(char *inBuf, char *outBuf, int cnt)
{
std::string output = utf8_to_latin1(in_buf);
strncat(out_buf, output.c_str(), cnt - strlen(out_buf));
std::string output = utf8_to_latin1(inBuf);
strncat(outBuf, output.c_str(), cnt - strlen(outBuf));
}
#ifdef __vita__
@ -226,9 +226,9 @@ void selhero_SetName(char *in_buf, char *out_buf, int cnt)
}
#endif
bool HandleMenuAction(MenuAction menu_action)
bool HandleMenuAction(MenuAction menuAction)
{
switch (menu_action) {
switch (menuAction) {
case MenuAction_SELECT:
UiFocusNavigationSelect();
return true;
@ -309,7 +309,7 @@ void UiFocusNavigation(SDL_Event *event)
if (clipboard == nullptr) {
SDL_Log("%s", SDL_GetError());
} else {
selhero_CatToName(clipboard, UiTextInput, UiTextInputLen);
SelheroCatToName(clipboard, UiTextInput, UiTextInputLen);
}
}
return;
@ -344,7 +344,7 @@ void UiFocusNavigation(SDL_Event *event)
#ifdef __vita__
selhero_SetName(event->text.text, UiTextInput, UiTextInputLen);
#else
selhero_CatToName(event->text.text, UiTextInput, UiTextInputLen);
SelheroCatToName(event->text.text, UiTextInput, UiTextInputLen);
#endif
}
return;
@ -443,7 +443,7 @@ bool IsInsideRect(const SDL_Event &event, const SDL_Rect &rect)
}
// Equivalent to SDL_Rect { ... } but avoids -Wnarrowing.
inline SDL_Rect makeRect(int x, int y, int w, int h)
inline SDL_Rect MakeRect(int x, int y, int w, int h)
{
using Pos = decltype(SDL_Rect {}.x);
using Len = decltype(SDL_Rect {}.w);
@ -473,9 +473,9 @@ void LoadHeros()
if (offset + portraitHeight > ArtHero.h()) {
offset = 0;
}
SDL_Rect src_rect = makeRect(0, offset, ArtHero.w(), portraitHeight);
SDL_Rect dst_rect = makeRect(0, i * portraitHeight, ArtHero.w(), portraitHeight);
SDL_BlitSurface(ArtHero.surface.get(), &src_rect, heros, &dst_rect);
SDL_Rect srcRect = MakeRect(0, offset, ArtHero.w(), portraitHeight);
SDL_Rect dstRect = MakeRect(0, i * portraitHeight, ArtHero.w(), portraitHeight);
SDL_BlitSurface(ArtHero.surface.get(), &srcRect, heros, &dstRect);
}
for (int i = 0; i <= static_cast<int>(enum_size<HeroClass>::value); i++) {
@ -486,8 +486,8 @@ void LoadHeros()
if (portrait.surface == nullptr)
continue;
SDL_Rect dst_rect = makeRect(0, i * portraitHeight, portrait.w(), portraitHeight);
SDL_BlitSurface(portrait.surface.get(), nullptr, heros, &dst_rect);
SDL_Rect dstRect = MakeRect(0, i * portraitHeight, portrait.w(), portraitHeight);
SDL_BlitSurface(portrait.surface.get(), nullptr, heros, &dstRect);
}
ArtHero.surface = SDLSurfaceUniquePtr { heros };
@ -699,91 +699,91 @@ void UiPollAndRender()
namespace {
void Render(UiText *ui_text)
void Render(UiText *uiText)
{
DrawTTF(ui_text->m_text,
ui_text->m_rect,
ui_text->m_iFlags,
ui_text->m_color,
ui_text->m_shadow_color,
ui_text->m_render_cache);
DrawTTF(uiText->m_text,
uiText->m_rect,
uiText->m_iFlags,
uiText->m_color,
uiText->m_shadow_color,
uiText->m_render_cache);
}
void Render(const UiArtText *ui_art_text)
void Render(const UiArtText *uiArtText)
{
DrawArtStr(ui_art_text->m_text, ui_art_text->m_rect, ui_art_text->m_iFlags);
DrawArtStr(uiArtText->m_text, uiArtText->m_rect, uiArtText->m_iFlags);
}
void Render(const UiImage *ui_image)
void Render(const UiImage *uiImage)
{
int x = ui_image->m_rect.x;
if ((ui_image->m_iFlags & UIS_CENTER) && ui_image->m_art != nullptr) {
const int x_offset = GetCenterOffset(ui_image->m_art->w(), ui_image->m_rect.w);
x += x_offset;
int x = uiImage->m_rect.x;
if ((uiImage->m_iFlags & UIS_CENTER) && uiImage->m_art != nullptr) {
const int xOffset = GetCenterOffset(uiImage->m_art->w(), uiImage->m_rect.w);
x += xOffset;
}
if (ui_image->m_animated) {
DrawAnimatedArt(ui_image->m_art, x, ui_image->m_rect.y);
if (uiImage->m_animated) {
DrawAnimatedArt(uiImage->m_art, x, uiImage->m_rect.y);
} else {
DrawArt(x, ui_image->m_rect.y, ui_image->m_art, ui_image->m_frame, ui_image->m_rect.w);
DrawArt(x, uiImage->m_rect.y, uiImage->m_art, uiImage->m_frame, uiImage->m_rect.w);
}
}
void Render(const UiArtTextButton *ui_button)
void Render(const UiArtTextButton *uiButton)
{
DrawArtStr(ui_button->m_text, ui_button->m_rect, ui_button->m_iFlags);
DrawArtStr(uiButton->m_text, uiButton->m_rect, uiButton->m_iFlags);
}
void Render(const UiList *ui_list)
void Render(const UiList *uiList)
{
for (std::size_t i = 0; i < ui_list->m_vecItems.size(); ++i) {
SDL_Rect rect = ui_list->itemRect(i);
const UiListItem *item = ui_list->GetItem(i);
for (std::size_t i = 0; i < uiList->m_vecItems.size(); ++i) {
SDL_Rect rect = uiList->itemRect(i);
const UiListItem *item = uiList->GetItem(i);
if (i + (ListOffset == nullptr ? 0 : *ListOffset) == SelectedItem)
DrawSelector(rect);
DrawArtStr(item->m_text, rect, ui_list->m_iFlags);
DrawArtStr(item->m_text, rect, uiList->m_iFlags);
}
}
void Render(const UiScrollBar *ui_sb)
void Render(const UiScrollBar *uiSb)
{
// Bar background (tiled):
{
const std::size_t bg_y_end = DownArrowRect(ui_sb).y;
std::size_t bg_y = ui_sb->m_rect.y + ui_sb->m_arrow->h();
while (bg_y < bg_y_end) {
std::size_t drawH = std::min(bg_y + ui_sb->m_bg->h(), bg_y_end) - bg_y;
DrawArt(ui_sb->m_rect.x, bg_y, ui_sb->m_bg, 0, SCROLLBAR_BG_WIDTH, drawH);
bg_y += drawH;
const std::size_t bgYEnd = DownArrowRect(uiSb).y;
std::size_t bgY = uiSb->m_rect.y + uiSb->m_arrow->h();
while (bgY < bgYEnd) {
std::size_t drawH = std::min(bgY + uiSb->m_bg->h(), bgYEnd) - bgY;
DrawArt(uiSb->m_rect.x, bgY, uiSb->m_bg, 0, SCROLLBAR_BG_WIDTH, drawH);
bgY += drawH;
}
}
// Arrows:
{
const SDL_Rect rect = UpArrowRect(ui_sb);
const SDL_Rect rect = UpArrowRect(uiSb);
const int frame = static_cast<int>(scrollBarState.upArrowPressed ? ScrollBarArrowFrame_UP_ACTIVE : ScrollBarArrowFrame_UP);
DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
DrawArt(rect.x, rect.y, uiSb->m_arrow, frame, rect.w);
}
{
const SDL_Rect rect = DownArrowRect(ui_sb);
const SDL_Rect rect = DownArrowRect(uiSb);
const int frame = static_cast<int>(scrollBarState.downArrowPressed ? ScrollBarArrowFrame_DOWN_ACTIVE : ScrollBarArrowFrame_DOWN);
DrawArt(rect.x, rect.y, ui_sb->m_arrow, frame, rect.w);
DrawArt(rect.x, rect.y, uiSb->m_arrow, frame, rect.w);
}
// Thumb:
if (SelectedItemMax > 0) {
const SDL_Rect rect = ThumbRect(ui_sb, SelectedItem, SelectedItemMax + 1);
DrawArt(rect.x, rect.y, ui_sb->m_thumb);
const SDL_Rect rect = ThumbRect(uiSb, SelectedItem, SelectedItemMax + 1);
DrawArt(rect.x, rect.y, uiSb->m_thumb);
}
}
void Render(const UiEdit *ui_edit)
void Render(const UiEdit *uiEdit)
{
DrawSelector(ui_edit->m_rect);
SDL_Rect rect = ui_edit->m_rect;
DrawSelector(uiEdit->m_rect);
SDL_Rect rect = uiEdit->m_rect;
rect.x += 43;
rect.y += 1;
rect.w -= 86;
DrawArtStr(ui_edit->m_value, rect, ui_edit->m_iFlags, /*drawTextCursor=*/true);
DrawArtStr(uiEdit->m_value, rect, uiEdit->m_iFlags, /*drawTextCursor=*/true);
}
void RenderItem(UiItemBase *item)
@ -818,11 +818,11 @@ void RenderItem(UiItemBase *item)
}
}
bool HandleMouseEventArtTextButton(const SDL_Event &event, const UiArtTextButton *ui_button)
bool HandleMouseEventArtTextButton(const SDL_Event &event, const UiArtTextButton *uiButton)
{
if (event.type != SDL_MOUSEBUTTONDOWN || event.button.button != SDL_BUTTON_LEFT)
return false;
ui_button->m_action();
uiButton->m_action();
return true;
}
@ -830,12 +830,12 @@ bool HandleMouseEventArtTextButton(const SDL_Event &event, const UiArtTextButton
Uint32 dbClickTimer;
#endif
bool HandleMouseEventList(const SDL_Event &event, UiList *ui_list)
bool HandleMouseEventList(const SDL_Event &event, UiList *uiList)
{
if (event.type != SDL_MOUSEBUTTONDOWN || event.button.button != SDL_BUTTON_LEFT)
return false;
const std::size_t index = ui_list->indexAt(event.button.y);
const std::size_t index = uiList->indexAt(event.button.y);
if (gfnListFocus != nullptr && SelectedItem != index) {
UiFocus(index);
@ -856,34 +856,34 @@ bool HandleMouseEventList(const SDL_Event &event, UiList *ui_list)
return true;
}
bool HandleMouseEventScrollBar(const SDL_Event &event, const UiScrollBar *ui_sb)
bool HandleMouseEventScrollBar(const SDL_Event &event, const UiScrollBar *uiSb)
{
if (event.button.button != SDL_BUTTON_LEFT)
return false;
if (event.type == SDL_MOUSEBUTTONUP) {
if (scrollBarState.upArrowPressed && IsInsideRect(event, UpArrowRect(ui_sb))) {
if (scrollBarState.upArrowPressed && IsInsideRect(event, UpArrowRect(uiSb))) {
UiFocusUp();
return true;
}
if (scrollBarState.downArrowPressed && IsInsideRect(event, DownArrowRect(ui_sb))) {
if (scrollBarState.downArrowPressed && IsInsideRect(event, DownArrowRect(uiSb))) {
UiFocusDown();
return true;
}
} else if (event.type == SDL_MOUSEBUTTONDOWN) {
if (IsInsideRect(event, BarRect(ui_sb))) {
if (IsInsideRect(event, BarRect(uiSb))) {
// Scroll up or down based on thumb position.
const SDL_Rect thumb_rect = ThumbRect(ui_sb, SelectedItem, SelectedItemMax + 1);
if (event.button.y < thumb_rect.y) {
const SDL_Rect thumbRect = ThumbRect(uiSb, SelectedItem, SelectedItemMax + 1);
if (event.button.y < thumbRect.y) {
UiFocusPageUp();
} else if (event.button.y > thumb_rect.y + thumb_rect.h) {
} else if (event.button.y > thumbRect.y + thumbRect.h) {
UiFocusPageDown();
}
return true;
}
if (IsInsideRect(event, UpArrowRect(ui_sb))) {
if (IsInsideRect(event, UpArrowRect(uiSb))) {
scrollBarState.upArrowPressed = true;
return true;
} else if (IsInsideRect(event, DownArrowRect(ui_sb))) {
} else if (IsInsideRect(event, DownArrowRect(uiSb))) {
scrollBarState.downArrowPressed = true;
return true;
}

4
Source/DiabloUI/dialogs.cpp

@ -36,7 +36,7 @@ std::vector<UiItemBase *> vecOkDialog;
void LoadFallbackPalette()
{
// clang-format off
static const SDL_Color fallback_palette[256] = {
static const SDL_Color FallbackPalette[256] = {
{ 0x00, 0x00, 0x00, 0 },
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
BLANKCOLOR, BLANKCOLOR, BLANKCOLOR,
@ -153,7 +153,7 @@ void LoadFallbackPalette()
BLANKCOLOR,
};
// clang-format on
ApplyGamma(logical_palette, fallback_palette, 256);
ApplyGamma(logical_palette, FallbackPalette, 256);
}
void Init(const char *text, const char *caption, bool error, bool renderBehind)

8
Source/DiabloUI/fonts.cpp

@ -65,13 +65,13 @@ void LoadTtfFont()
was_fonts_init = true;
}
std::string ttf_font_path = GetTtfPath() + GetTtfName();
std::string ttfFontPath = GetTtfPath() + GetTtfName();
#ifdef __linux__
if (!FileExists(ttf_font_path.c_str())) {
ttf_font_path = "/usr/share/fonts/truetype/" + GetTtfName();
if (!FileExists(ttfFontPath.c_str())) {
ttfFontPath = "/usr/share/fonts/truetype/" + GetTtfName();
}
#endif
font = TTF_OpenFont(ttf_font_path.c_str(), 17);
font = TTF_OpenFont(ttfFontPath.c_str(), 17);
if (font == nullptr) {
SDL_Log("TTF_OpenFont: %s", TTF_GetError());
return;

12
Source/DiabloUI/mainmenu.cpp

@ -18,7 +18,7 @@ void UiMainMenuSelect(int value)
MainMenuResult = (_mainmenu_selections)vecMenuItems[value]->m_value;
}
void mainmenu_Esc()
void MainmenuEsc()
{
std::size_t last = vecMenuItems.size() - 1;
if (SelectedItem == last) {
@ -28,7 +28,7 @@ void mainmenu_Esc()
}
}
void mainmenu_Load(const char *name, void (*fnSound)(const char *file))
void MainmenuLoad(const char *name, void (*fnSound)(const char *file))
{
gfnSoundFunction = fnSound;
@ -60,10 +60,10 @@ void mainmenu_Load(const char *name, void (*fnSound)(const char *file))
SDL_Rect rect = { 17, (Sint16)(gnScreenHeight - 36), 605, 21 };
vecMainMenuDialog.push_back(new UiArtText(name, rect, UIS_SMALL));
UiInitList(vecMenuItems.size(), nullptr, UiMainMenuSelect, mainmenu_Esc, vecMainMenuDialog, true);
UiInitList(vecMenuItems.size(), nullptr, UiMainMenuSelect, MainmenuEsc, vecMainMenuDialog, true);
}
void mainmenu_Free()
void MainmenuFree()
{
ArtBackgroundWidescreen.Unload();
ArtBackground.Unload();
@ -91,7 +91,7 @@ bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, void (*
MainMenuResult = MAINMENU_NONE;
while (MainMenuResult == MAINMENU_NONE) {
mainmenu_attract_time_out = attractTimeOut;
mainmenu_Load(name, fnSound);
MainmenuLoad(name, fnSound);
mainmenu_restart_repintro(); // for automatic starts
@ -103,7 +103,7 @@ bool UiMainMenuDialog(const char *name, _mainmenu_selections *pdwResult, void (*
}
}
mainmenu_Free();
MainmenuFree();
if (gbSpawned && !gbIsHellfire && MainMenuResult == MAINMENU_REPLAY_INTRO) {
UiSelOkDialog(nullptr, "The Diablo introduction cinematic is only available in the full retail version of Diablo. Visit https://www.gog.com/game/diablo to purchase.", true);

22
Source/DiabloUI/progress.cpp

@ -25,7 +25,7 @@ void DialogActionCancel()
endMenu = true;
}
void progress_Load(const char *msg)
void ProgressLoad(const char *msg)
{
LoadBackgroundArt("ui_art\\black.pcx");
LoadArt("ui_art\\spopup.pcx", &ArtPopupSm);
@ -45,7 +45,7 @@ void progress_Load(const char *msg)
vecProgress.push_back(new UiButton(&SmlButton, "Cancel", &DialogActionCancel, rect3, 0));
}
void progress_Free()
void ProgressFree()
{
ArtBackground.Unload();
ArtPopupSm.Unload();
@ -59,7 +59,7 @@ void progress_Free()
UnloadTtfFont();
}
void progress_Render(BYTE progress)
void ProgressRender(BYTE progress)
{
SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000);
DrawArt(0, 0, &ArtBackground);
@ -75,16 +75,16 @@ void progress_Render(BYTE progress)
DrawArt(GetCenterOffset(110), y + 99, &SmlButton, 2, 110);
if (msgSurface) {
SDL_Rect dsc_rect = {
SDL_Rect dscRect = {
static_cast<Sint16>(x + 50 + 1),
static_cast<Sint16>(y + 8 + 1),
static_cast<Uint16>(msgSurface->w),
static_cast<Uint16>(msgSurface->h)
};
Blit(msgShadow, nullptr, &dsc_rect);
dsc_rect.x -= 1;
dsc_rect.y -= 1;
Blit(msgSurface, nullptr, &dsc_rect);
Blit(msgShadow, nullptr, &dscRect);
dscRect.x -= 1;
dscRect.y -= 1;
Blit(msgSurface, nullptr, &dscRect);
}
}
@ -92,7 +92,7 @@ void progress_Render(BYTE progress)
bool UiProgressDialog(const char *msg, int (*fnfunc)())
{
progress_Load(msg);
ProgressLoad(msg);
SetFadeLevel(256);
endMenu = false;
@ -101,7 +101,7 @@ bool UiProgressDialog(const char *msg, int (*fnfunc)())
SDL_Event event;
while (!endMenu && progress < 100) {
progress = fnfunc();
progress_Render(progress);
ProgressRender(progress);
UiRenderItems(vecProgress);
DrawMouse();
RenderPresent();
@ -134,7 +134,7 @@ bool UiProgressDialog(const char *msg, int (*fnfunc)())
UiHandleEvents(&event);
}
}
progress_Free();
ProgressFree();
return progress == 100;
}

26
Source/DiabloUI/selconn.cpp

@ -20,11 +20,11 @@ std::vector<UiItemBase *> vecSelConnDlg;
#define DESCRIPTION_WIDTH 205
void selconn_Esc();
void selconn_Focus(int value);
void selconn_Select(int value);
void SelconnEsc();
void SelconnFocus(int value);
void SelconnSelect(int value);
void selconn_Load()
void SelconnLoad()
{
LoadBackgroundArt("ui_art\\selconn.pcx");
@ -69,10 +69,10 @@ void selconn_Load()
SDL_Rect rect10 = { (Sint16)(PANEL_LEFT + 454), (Sint16)(UI_OFFSET_Y + 427), 140, 35 };
vecSelConnDlg.push_back(new UiArtTextButton("Cancel", &UiFocusNavigationEsc, rect10, UIS_CENTER | UIS_VCENTER | UIS_BIG | UIS_GOLD));
UiInitList(vecConnItems.size(), selconn_Focus, selconn_Select, selconn_Esc, vecSelConnDlg);
UiInitList(vecConnItems.size(), SelconnFocus, SelconnSelect, SelconnEsc, vecSelConnDlg);
}
void selconn_Free()
void SelconnFree()
{
ArtBackground.Unload();
@ -87,13 +87,13 @@ void selconn_Free()
vecSelConnDlg.clear();
}
void selconn_Esc()
void SelconnEsc()
{
selconn_ReturnValue = false;
selconn_EndMenu = true;
}
void selconn_Focus(int value)
void SelconnFocus(int value)
{
int players = MAX_PLRS;
switch (vecConnItems[value]->m_value) {
@ -115,13 +115,13 @@ void selconn_Focus(int value)
WordWrapArtStr(selconn_Description, DESCRIPTION_WIDTH);
}
void selconn_Select(int value)
void SelconnSelect(int value)
{
provider = vecConnItems[value]->m_value;
selconn_Free();
SelconnFree();
selconn_EndMenu = SNetInitializeProvider(provider, selconn_GameData);
selconn_Load();
SelconnLoad();
}
} // namespace
@ -129,7 +129,7 @@ void selconn_Select(int value)
int UiSelectProvider(GameData *gameData)
{
selconn_GameData = gameData;
selconn_Load();
SelconnLoad();
selconn_ReturnValue = true;
selconn_EndMenu = false;
@ -137,7 +137,7 @@ int UiSelectProvider(GameData *gameData)
UiClearScreen();
UiPollAndRender();
}
selconn_Free();
SelconnFree();
return selconn_ReturnValue;
}

174
Source/DiabloUI/selhero.cpp

@ -32,7 +32,7 @@ namespace {
std::size_t selhero_SaveCount = 0;
_uiheroinfo selhero_heros[MAX_CHARACTERS];
_uiheroinfo selhero_heroInfo;
const size_t kMaxViewportItems = 6;
const size_t KMaxViewportItems = 6;
char textStats[5][4];
char title[32];
_selhero_selections selhero_result;
@ -47,25 +47,25 @@ UiImage *SELHERO_DIALOG_HERO_IMG;
bool bUIElementsLoaded = false;
void selhero_List_Focus(int value);
void selhero_List_Select(int value);
void selhero_List_Esc();
void selhero_Load_Focus(int value);
void selhero_Load_Select(int value);
void selhero_Name_Select(int value);
void selhero_Name_Esc();
void selhero_ClassSelector_Focus(int value);
void selhero_ClassSelector_Select(int value);
void selhero_ClassSelector_Esc();
const char *selhero_GenerateName(HeroClass hero_class);
void selhero_UiFocusNavigationYesNo()
void SelheroListFocus(int value);
void SelheroListSelect(int value);
void SelheroListEsc();
void SelheroLoadFocus(int value);
void SelheroLoadSelect(int value);
void SelheroNameSelect(int value);
void SelheroNameEsc();
void SelheroClassSelectorFocus(int value);
void SelheroClassSelectorSelect(int value);
void SelheroClassSelectorEsc();
const char *SelheroGenerateName(HeroClass heroClass);
void SelheroUiFocusNavigationYesNo()
{
if (selhero_deleteEnabled)
UiFocusNavigationYesNo();
}
void selhero_FreeListItems()
void SelheroFreeListItems()
{
for (auto pUIItem : vecSelHeroDlgItems) {
delete pUIItem;
@ -73,7 +73,7 @@ void selhero_FreeListItems()
vecSelHeroDlgItems.clear();
}
void selhero_FreeDlgItems()
void SelheroFreeDlgItems()
{
for (auto pUIItem : vecSelDlgItems) {
delete pUIItem;
@ -81,7 +81,7 @@ void selhero_FreeDlgItems()
vecSelDlgItems.clear();
}
void selhero_Free()
void SelheroFree()
{
ArtBackground.Unload();
@ -90,14 +90,14 @@ void selhero_Free()
}
vecSelHeroDialog.clear();
selhero_FreeDlgItems();
selhero_FreeListItems();
SelheroFreeDlgItems();
SelheroFreeListItems();
UnloadScrollBar();
bUIElementsLoaded = false;
}
void selhero_SetStats()
void SelheroSetStats()
{
SELHERO_DIALOG_HERO_IMG->m_frame = static_cast<int>(selhero_heroInfo.heroclass);
snprintf(textStats[0], sizeof(textStats[0]), "%d", selhero_heroInfo.level);
@ -110,34 +110,34 @@ void selhero_SetStats()
std::size_t listOffset = 0;
UiArtTextButton *SELLIST_DIALOG_DELETE_BUTTON;
void selhero_UpdateViewportItems()
void SelheroUpdateViewportItems()
{
const std::size_t num_viewport_heroes = std::min(selhero_SaveCount - listOffset, kMaxViewportItems);
for (std::size_t i = 0; i < num_viewport_heroes; i++) {
const std::size_t numViewportHeroes = std::min(selhero_SaveCount - listOffset, KMaxViewportItems);
for (std::size_t i = 0; i < numViewportHeroes; i++) {
const std::size_t index = i + listOffset;
vecSelHeroDlgItems[i]->m_text = selhero_heros[index].name;
vecSelHeroDlgItems[i]->m_value = static_cast<int>(index);
}
if (num_viewport_heroes < kMaxViewportItems) {
vecSelHeroDlgItems[num_viewport_heroes]->m_text = "New Hero";
vecSelHeroDlgItems[num_viewport_heroes]->m_value = static_cast<int>(selhero_SaveCount);
if (numViewportHeroes < KMaxViewportItems) {
vecSelHeroDlgItems[numViewportHeroes]->m_text = "New Hero";
vecSelHeroDlgItems[numViewportHeroes]->m_value = static_cast<int>(selhero_SaveCount);
}
}
void selhero_ScrollIntoView(std::size_t index)
void SelheroScrollIntoView(std::size_t index)
{
std::size_t new_offset = listOffset;
if (index >= listOffset + kMaxViewportItems)
new_offset = index - (kMaxViewportItems - 1);
std::size_t newOffset = listOffset;
if (index >= listOffset + KMaxViewportItems)
newOffset = index - (KMaxViewportItems - 1);
if (index < listOffset)
new_offset = index;
if (new_offset != listOffset) {
listOffset = new_offset;
selhero_UpdateViewportItems();
newOffset = index;
if (newOffset != listOffset) {
listOffset = newOffset;
SelheroUpdateViewportItems();
}
}
bool SelHero_GetHeroInfo(_uiheroinfo *pInfo)
bool SelHeroGetHeroInfo(_uiheroinfo *pInfo)
{
selhero_heros[selhero_SaveCount] = *pInfo;
selhero_SaveCount++;
@ -145,14 +145,14 @@ bool SelHero_GetHeroInfo(_uiheroinfo *pInfo)
return true;
}
void selhero_List_Focus(int value)
void SelheroListFocus(int value)
{
const auto index = static_cast<std::size_t>(value);
selhero_ScrollIntoView(index);
SelheroScrollIntoView(index);
int baseFlags = UIS_CENTER | UIS_BIG;
if (selhero_SaveCount && index < selhero_SaveCount) {
memcpy(&selhero_heroInfo, &selhero_heros[index], sizeof(selhero_heroInfo));
selhero_SetStats();
SelheroSetStats();
SELLIST_DIALOG_DELETE_BUTTON->m_iFlags = baseFlags | UIS_GOLD;
selhero_deleteEnabled = true;
return;
@ -168,22 +168,22 @@ void selhero_List_Focus(int value)
selhero_deleteEnabled = false;
}
bool selhero_List_DeleteYesNo()
bool SelheroListDeleteYesNo()
{
selhero_navigateYesNo = selhero_deleteEnabled;
return selhero_navigateYesNo;
}
void selhero_List_Select(int value)
void SelheroListSelect(int value)
{
if (static_cast<std::size_t>(value) == selhero_SaveCount) {
selhero_FreeDlgItems();
SelheroFreeDlgItems();
SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 264), (Sint16)(UI_OFFSET_Y + 211), 320, 33 };
vecSelDlgItems.push_back(new UiArtText("Choose Class", rect1, UIS_CENTER | UIS_BIG));
selhero_FreeListItems();
SelheroFreeListItems();
int itemH = 33;
vecSelHeroDlgItems.push_back(new UiListItem("Warrior", static_cast<int>(HeroClass::Warrior)));
vecSelHeroDlgItems.push_back(new UiListItem("Rogue", static_cast<int>(HeroClass::Rogue)));
@ -208,7 +208,7 @@ void selhero_List_Select(int value)
SDL_Rect rect3 = { (Sint16)(PANEL_LEFT + 429), (Sint16)(UI_OFFSET_Y + 429), 140, 35 };
vecSelDlgItems.push_back(new UiArtTextButton("Cancel", &UiFocusNavigationEsc, rect3, UIS_CENTER | UIS_BIG | UIS_GOLD));
UiInitList(vecSelHeroDlgItems.size(), selhero_ClassSelector_Focus, selhero_ClassSelector_Select, selhero_ClassSelector_Esc, vecSelDlgItems);
UiInitList(vecSelHeroDlgItems.size(), SelheroClassSelectorFocus, SelheroClassSelectorSelect, SelheroClassSelectorEsc, vecSelDlgItems);
memset(&selhero_heroInfo.name, 0, sizeof(selhero_heroInfo.name));
strncpy(title, "New Single Player Hero", sizeof(title) - 1);
if (selhero_isMultiPlayer) {
@ -218,12 +218,12 @@ void selhero_List_Select(int value)
}
if (selhero_heroInfo.hassaved) {
selhero_FreeDlgItems();
SelheroFreeDlgItems();
SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 264), (Sint16)(UI_OFFSET_Y + 211), 320, 33 };
vecSelDlgItems.push_back(new UiArtText("Save File Exists", rect1, UIS_CENTER | UIS_BIG));
selhero_FreeListItems();
SelheroFreeListItems();
vecSelHeroDlgItems.push_back(new UiListItem("Load Game", 0));
vecSelHeroDlgItems.push_back(new UiListItem("New Game", 1));
vecSelDlgItems.push_back(new UiList(vecSelHeroDlgItems, PANEL_LEFT + 265, (UI_OFFSET_Y + 285), 320, 33, UIS_CENTER | UIS_MED | UIS_GOLD));
@ -234,15 +234,15 @@ void selhero_List_Select(int value)
SDL_Rect rect3 = { (Sint16)(PANEL_LEFT + 429), (Sint16)(UI_OFFSET_Y + 427), 140, 35 };
vecSelDlgItems.push_back(new UiArtTextButton("Cancel", &UiFocusNavigationEsc, rect3, UIS_CENTER | UIS_VCENTER | UIS_BIG | UIS_GOLD));
UiInitList(vecSelHeroDlgItems.size(), selhero_Load_Focus, selhero_Load_Select, selhero_List_Init, vecSelDlgItems, true);
UiInitList(vecSelHeroDlgItems.size(), SelheroLoadFocus, SelheroLoadSelect, selhero_List_Init, vecSelDlgItems, true);
strncpy(title, "Single Player Characters", sizeof(title) - 1);
return;
}
selhero_Load_Select(1);
SelheroLoadSelect(1);
}
void selhero_List_Esc()
void SelheroListEsc()
{
UiInitList_clear();
@ -250,24 +250,24 @@ void selhero_List_Esc()
selhero_result = SELHERO_PREVIOUS;
}
void selhero_ClassSelector_Focus(int value)
void SelheroClassSelectorFocus(int value)
{
const auto hero_class = static_cast<HeroClass>(vecSelHeroDlgItems[value]->m_value);
const auto heroClass = static_cast<HeroClass>(vecSelHeroDlgItems[value]->m_value);
_uidefaultstats defaults;
gfnHeroStats(static_cast<unsigned int>(hero_class), &defaults);
gfnHeroStats(static_cast<unsigned int>(heroClass), &defaults);
selhero_heroInfo.level = 1;
selhero_heroInfo.heroclass = hero_class;
selhero_heroInfo.heroclass = heroClass;
selhero_heroInfo.strength = defaults.strength;
selhero_heroInfo.magic = defaults.magic;
selhero_heroInfo.dexterity = defaults.dexterity;
selhero_heroInfo.vitality = defaults.vitality;
selhero_SetStats();
SelheroSetStats();
}
bool shouldPrefillHeroName()
bool ShouldPrefillHeroName()
{
#if defined __3DS__
return false;
@ -278,14 +278,14 @@ bool shouldPrefillHeroName()
#endif
}
void selhero_ClassSelector_Select(int value)
void SelheroClassSelectorSelect(int value)
{
auto hClass = static_cast<HeroClass>(vecSelHeroDlgItems[value]->m_value);
if (gbSpawned && (hClass == HeroClass::Rogue || hClass == HeroClass::Sorcerer || (hClass == HeroClass::Bard && !hfbard_mpq))) {
ArtBackground.Unload();
UiSelOkDialog(nullptr, "The Rogue and Sorcerer are only available in the full retail version of Diablo. Visit https://www.gog.com/game/diablo to purchase.", false);
LoadBackgroundArt("ui_art\\selhero.pcx");
selhero_List_Select(selhero_SaveCount);
SelheroListSelect(selhero_SaveCount);
return;
}
@ -297,9 +297,9 @@ void selhero_ClassSelector_Select(int value)
#if defined __3DS__
ctr_vkbdInput("Enter Hero name..", selhero_GenerateName(selhero_heroInfo.heroclass), selhero_heroInfo.name);
#endif
if (shouldPrefillHeroName())
strncpy(selhero_heroInfo.name, selhero_GenerateName(selhero_heroInfo.heroclass), sizeof(selhero_heroInfo.name) - 1);
selhero_FreeDlgItems();
if (ShouldPrefillHeroName())
strncpy(selhero_heroInfo.name, SelheroGenerateName(selhero_heroInfo.heroclass), sizeof(selhero_heroInfo.name) - 1);
SelheroFreeDlgItems();
SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 264), (Sint16)(UI_OFFSET_Y + 211), 320, 33 };
vecSelDlgItems.push_back(new UiArtText("Enter Name", rect1, UIS_CENTER | UIS_BIG));
@ -312,23 +312,23 @@ void selhero_ClassSelector_Select(int value)
SDL_Rect rect4 = { (Sint16)(PANEL_LEFT + 429), (Sint16)(UI_OFFSET_Y + 429), 140, 35 };
vecSelDlgItems.push_back(new UiArtTextButton("Cancel", &UiFocusNavigationEsc, rect4, UIS_CENTER | UIS_BIG | UIS_GOLD));
UiInitList(0, nullptr, selhero_Name_Select, selhero_Name_Esc, vecSelDlgItems);
UiInitList(0, nullptr, SelheroNameSelect, SelheroNameEsc, vecSelDlgItems);
}
void selhero_ClassSelector_Esc()
void SelheroClassSelectorEsc()
{
selhero_FreeDlgItems();
selhero_FreeListItems();
SelheroFreeDlgItems();
SelheroFreeListItems();
if (selhero_SaveCount) {
selhero_List_Init();
return;
}
selhero_List_Esc();
SelheroListEsc();
}
void selhero_Name_Select(int value)
void SelheroNameSelect(int value)
{
if (!UiValidPlayerName(selhero_heroInfo.name)) {
@ -350,7 +350,7 @@ void selhero_Name_Select(int value)
if (overwrite) {
if (gfnHeroCreate(&selhero_heroInfo)) {
selhero_Load_Select(1);
SelheroLoadSelect(1);
return;
}
UiErrorOkDialog("Unable to create character.", vecSelDlgItems);
@ -358,19 +358,19 @@ void selhero_Name_Select(int value)
}
memset(selhero_heroInfo.name, '\0', sizeof(selhero_heroInfo.name));
selhero_ClassSelector_Select(0);
SelheroClassSelectorSelect(0);
}
void selhero_Name_Esc()
void SelheroNameEsc()
{
selhero_List_Select(selhero_SaveCount);
SelheroListSelect(selhero_SaveCount);
}
void selhero_Load_Focus(int value)
void SelheroLoadFocus(int value)
{
}
void selhero_Load_Select(int value)
void SelheroLoadSelect(int value)
{
UiInitList_clear();
selhero_endMenu = true;
@ -389,7 +389,7 @@ void selhero_Load_Select(int value)
// This means selhero's render loop will render selgame's items,
// which happens to work because the render loops are similar.
selhero_endMenu = false;
selhero_Free();
SelheroFree();
LoadBackgroundArt("ui_art\\selgame.pcx");
selgame_GameSelection_Select(0);
}
@ -397,9 +397,9 @@ void selhero_Load_Select(int value)
selhero_result = SELHERO_NEW_DUNGEON;
}
const char *selhero_GenerateName(HeroClass hero_class)
const char *SelheroGenerateName(HeroClass heroClass)
{
static const char *const kNames[6][10] = {
static const char *const KNames[6][10] = {
{
// Warrior
"Aidan",
@ -482,7 +482,7 @@ const char *selhero_GenerateName(HeroClass hero_class)
int iRand = rand() % 10;
return kNames[static_cast<std::size_t>(hero_class) % 6][iRand];
return KNames[static_cast<std::size_t>(heroClass) % 6][iRand];
}
} // namespace
@ -495,10 +495,10 @@ void selhero_Init()
LoadScrollBar();
selhero_SaveCount = 0;
gfnHeroInfo(SelHero_GetHeroInfo);
gfnHeroInfo(SelHeroGetHeroInfo);
std::reverse(selhero_heros, selhero_heros + selhero_SaveCount);
selhero_FreeDlgItems();
SelheroFreeDlgItems();
SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 24), (Sint16)(UI_OFFSET_Y + 161), 590, 35 };
vecSelHeroDialog.push_back(new UiArtText(title, rect1, UIS_CENTER | UIS_BIG));
@ -538,17 +538,17 @@ void selhero_Init()
void selhero_List_Init()
{
listOffset = 0;
selhero_FreeDlgItems();
SelheroFreeDlgItems();
SDL_Rect rect1 = { (Sint16)(PANEL_LEFT + 264), (Sint16)(UI_OFFSET_Y + 211), 320, 33 };
vecSelDlgItems.push_back(new UiArtText("Select Hero", rect1, UIS_CENTER | UIS_BIG));
selhero_FreeListItems();
const size_t num_viewport_heroes = std::min(selhero_SaveCount + 1, kMaxViewportItems);
for (std::size_t i = 0; i < num_viewport_heroes; i++) {
SelheroFreeListItems();
const size_t numViewportHeroes = std::min(selhero_SaveCount + 1, KMaxViewportItems);
for (std::size_t i = 0; i < numViewportHeroes; i++) {
vecSelHeroDlgItems.push_back(new UiListItem("", -1));
}
selhero_UpdateViewportItems();
SelheroUpdateViewportItems();
vecSelDlgItems.push_back(new UiList(vecSelHeroDlgItems, PANEL_LEFT + 265, (UI_OFFSET_Y + 256), 320, 26, UIS_CENTER | UIS_MED | UIS_GOLD));
@ -560,14 +560,14 @@ void selhero_List_Init()
vecSelDlgItems.push_back(new UiArtTextButton("OK", &UiFocusNavigationSelect, rect3, UIS_CENTER | UIS_BIG | UIS_GOLD));
SDL_Rect rect4 = { (Sint16)(PANEL_LEFT + 364), (Sint16)(UI_OFFSET_Y + 429), 120, 35 };
SELLIST_DIALOG_DELETE_BUTTON = new UiArtTextButton("Delete", &selhero_UiFocusNavigationYesNo, rect4, UIS_CENTER | UIS_BIG | UIS_DISABLED);
SELLIST_DIALOG_DELETE_BUTTON = new UiArtTextButton("Delete", &SelheroUiFocusNavigationYesNo, rect4, UIS_CENTER | UIS_BIG | UIS_DISABLED);
vecSelDlgItems.push_back(SELLIST_DIALOG_DELETE_BUTTON);
SDL_Rect rect5 = { (Sint16)(PANEL_LEFT + 489), (Sint16)(UI_OFFSET_Y + 429), 120, 35 };
vecSelDlgItems.push_back(new UiArtTextButton("Cancel", &UiFocusNavigationEsc, rect5, UIS_CENTER | UIS_BIG | UIS_GOLD));
UiInitList(selhero_SaveCount + 1, selhero_List_Focus, selhero_List_Select, selhero_List_Esc, vecSelDlgItems, false, selhero_List_DeleteYesNo);
UiInitScrollBar(scrollBar, kMaxViewportItems, &listOffset);
UiInitList(selhero_SaveCount + 1, SelheroListFocus, SelheroListSelect, SelheroListEsc, vecSelDlgItems, false, SelheroListDeleteYesNo);
UiInitScrollBar(scrollBar, KMaxViewportItems, &listOffset);
if (selhero_isMultiPlayer) {
strcpy(title, "Multi Player Characters");
} else {
@ -598,7 +598,7 @@ static void UiSelHeroDialog(
if (selhero_SaveCount) {
selhero_List_Init();
} else {
selhero_List_Select(selhero_SaveCount);
SelheroListSelect(selhero_SaveCount);
}
selhero_endMenu = false;
@ -607,7 +607,7 @@ static void UiSelHeroDialog(
UiRenderItems(vecSelHeroDialog);
UiPollAndRender();
}
selhero_Free();
SelheroFree();
if (selhero_navigateYesNo) {
char dialogTitle[32];

10
Source/DiabloUI/selyesno.cpp

@ -16,7 +16,7 @@ std::vector<UiItemBase *> vecSelYesNoDialog;
#define MESSAGE_WIDTH 280
void selyesno_Free()
void SelyesnoFree()
{
ArtBackground.Unload();
@ -31,13 +31,13 @@ void selyesno_Free()
vecSelYesNoDialog.clear();
}
void selyesno_Select(int value)
void SelyesnoSelect(int value)
{
selyesno_value = vecSelYesNoDialogItems[value]->m_value == 0;
selyesno_endMenu = true;
}
void selyesno_Esc()
void SelyesnoEsc()
{
selyesno_value = false;
selyesno_endMenu = true;
@ -64,7 +64,7 @@ bool UiSelHeroYesNoDialog(const char *title, const char *body)
strncpy(selyesno_confirmationMessage, body, sizeof(selyesno_confirmationMessage) - 1);
WordWrapArtStr(selyesno_confirmationMessage, MESSAGE_WIDTH);
UiInitList(vecSelYesNoDialogItems.size(), nullptr, selyesno_Select, selyesno_Esc, vecSelYesNoDialog, true, nullptr);
UiInitList(vecSelYesNoDialogItems.size(), nullptr, SelyesnoSelect, SelyesnoEsc, vecSelYesNoDialog, true, nullptr);
selyesno_value = true;
selyesno_endMenu = false;
@ -74,7 +74,7 @@ bool UiSelHeroYesNoDialog(const char *title, const char *body)
UiPollAndRender();
}
selyesno_Free();
SelyesnoFree();
return selyesno_value;
}

38
Source/DiabloUI/text_draw.cpp

@ -35,35 +35,35 @@ int AlignXOffset(int flags, const SDL_Rect &dest, int w)
} // namespace
void DrawTTF(const char *text, const SDL_Rect &rectIn, int flags,
const SDL_Color &text_color, const SDL_Color &shadow_color,
TtfSurfaceCache &render_cache)
const SDL_Color &textColor, const SDL_Color &shadowColor,
TtfSurfaceCache &renderCache)
{
SDL_Rect rect(rectIn);
if (font == nullptr || text == nullptr || *text == '\0')
return;
const auto x_align = XAlignmentFromFlags(flags);
if (render_cache.text == nullptr)
render_cache.text = ScaleSurfaceToOutput(SDLSurfaceUniquePtr { RenderUTF8_Solid_Wrapped(font, text, text_color, rect.w, x_align) });
if (render_cache.shadow == nullptr)
render_cache.shadow = ScaleSurfaceToOutput(SDLSurfaceUniquePtr { RenderUTF8_Solid_Wrapped(font, text, shadow_color, rect.w, x_align) });
const auto xAlign = XAlignmentFromFlags(flags);
if (renderCache.text == nullptr)
renderCache.text = ScaleSurfaceToOutput(SDLSurfaceUniquePtr { RenderUTF8_Solid_Wrapped(font, text, textColor, rect.w, xAlign) });
if (renderCache.shadow == nullptr)
renderCache.shadow = ScaleSurfaceToOutput(SDLSurfaceUniquePtr { RenderUTF8_Solid_Wrapped(font, text, shadowColor, rect.w, xAlign) });
SDL_Surface *text_surface = render_cache.text.get();
SDL_Surface *shadow_surface = render_cache.shadow.get();
if (text_surface == nullptr)
SDL_Surface *textSurface = renderCache.text.get();
SDL_Surface *shadowSurface = renderCache.shadow.get();
if (textSurface == nullptr)
return;
SDL_Rect dest_rect = rect;
ScaleOutputRect(&dest_rect);
dest_rect.x += AlignXOffset(flags, dest_rect, text_surface->w);
dest_rect.y += (flags & UIS_VCENTER) ? (dest_rect.h - text_surface->h) / 2 : 0;
SDL_Rect destRect = rect;
ScaleOutputRect(&destRect);
destRect.x += AlignXOffset(flags, destRect, textSurface->w);
destRect.y += (flags & UIS_VCENTER) ? (destRect.h - textSurface->h) / 2 : 0;
SDL_Rect shadow_rect = dest_rect;
++shadow_rect.x;
++shadow_rect.y;
if (SDL_BlitSurface(shadow_surface, nullptr, DiabloUiSurface(), &shadow_rect) < 0)
SDL_Rect shadowRect = destRect;
++shadowRect.x;
++shadowRect.y;
if (SDL_BlitSurface(shadowSurface, nullptr, DiabloUiSurface(), &shadowRect) < 0)
ErrSdl();
if (SDL_BlitSurface(text_surface, nullptr, DiabloUiSurface(), &dest_rect) < 0)
if (SDL_BlitSurface(textSurface, nullptr, DiabloUiSurface(), &destRect) < 0)
ErrSdl();
}

8
Source/DiabloUI/title.cpp

@ -7,7 +7,7 @@ namespace {
std::vector<UiItemBase *> vecTitleScreen;
void title_Load()
void TitleLoad()
{
if (gbIsHellfire) {
LoadBackgroundArt("ui_art\\hf_logo1.pcx", 16);
@ -18,7 +18,7 @@ void title_Load()
}
}
void title_Free()
void TitleFree()
{
ArtBackground.Unload();
ArtBackgroundWidescreen.Unload();
@ -45,7 +45,7 @@ void UiTitleDialog()
SDL_Rect rect = { (Sint16)(PANEL_LEFT + 49), (Sint16)(UI_OFFSET_Y + 410), 550, 26 };
vecTitleScreen.push_back(new UiArtText("Copyright \xA9 1996-2001 Blizzard Entertainment", rect, UIS_MED | UIS_CENTER));
}
title_Load();
TitleLoad();
bool endMenu = false;
Uint32 timeOut = SDL_GetTicks() + 7000;
@ -70,7 +70,7 @@ void UiTitleDialog()
}
}
title_Free();
TitleFree();
}
void UiSetSpawned(bool bSpawned)

20
Source/DiabloUI/ttf_render_wrapped.cpp

@ -29,7 +29,7 @@ SDL_bool CharacterIsDelimiter(char c, const char *delimiters)
} // namespace
// Based on SDL 2.0.12 TTF_RenderUTF8_Blended_Wrapped
SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength, const int x_align)
SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Color fg, Uint32 wrapLength, const int xAlign)
{
int width, height;
SDL_Surface *textbuf;
@ -48,21 +48,21 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
if (wrapLength > 0 && *text) {
const char *wrapDelims = " \t\r\n";
int w, h;
char *spot, *tok, *next_tok, *end;
char *spot, *tok, *nextTok, *end;
char delim;
const std::size_t str_len = std::strlen(text);
const std::size_t strLen = std::strlen(text);
numLines = 0;
str = SDL_stack_alloc(char, str_len + 1);
str = SDL_stack_alloc(char, strLen + 1);
if (str == nullptr) {
TTF_SetError("Out of memory");
return nullptr;
}
std::memcpy(str, text, str_len + 1);
std::memcpy(str, text, strLen + 1);
tok = str;
end = str + str_len;
end = str + strLen;
do {
strLines = (char **)SDL_realloc(strLines, (numLines + 1) * sizeof(*strLines));
if (!strLines) {
@ -82,7 +82,7 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
} else {
spot = end;
}
next_tok = spot;
nextTok = spot;
/* Get the longest string that will fit in the desired space */
for (;;) {
@ -110,10 +110,10 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
--spot;
}
if (spot > tok) {
next_tok = spot;
nextTok = spot;
}
}
tok = next_tok;
tok = nextTok;
} while (tok < end);
}
@ -162,7 +162,7 @@ SDL_Surface *RenderUTF8_Solid_Wrapped(TTF_Font *font, const char *text, SDL_Colo
dest.w = static_cast<Uint16>(tmp->w);
dest.h = static_cast<Uint16>(tmp->h);
switch (x_align) {
switch (xAlign) {
case TextAlignment_END:
dest.x = textbuf->w - tmp->w;
break;

Loading…
Cancel
Save