|
|
|
|
@ -26,39 +26,64 @@ enum class UiType {
|
|
|
|
|
|
|
|
|
|
class UiItemBase { |
|
|
|
|
public: |
|
|
|
|
UiItemBase(UiType type, SDL_Rect rect, UiFlags flags) |
|
|
|
|
: m_type(type) |
|
|
|
|
, m_rect(rect) |
|
|
|
|
, m_iFlags(flags) |
|
|
|
|
virtual ~UiItemBase() = default; |
|
|
|
|
|
|
|
|
|
[[nodiscard]] UiType GetType() const |
|
|
|
|
{ |
|
|
|
|
return type_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsType(UiType testType) const |
|
|
|
|
{ |
|
|
|
|
return type_ == testType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] UiFlags GetFlags() const |
|
|
|
|
{ |
|
|
|
|
return uiFlags_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsHidden() const |
|
|
|
|
{ |
|
|
|
|
return HasAnyOf(uiFlags_, UiFlags::ElementHidden); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
virtual ~UiItemBase() {}; |
|
|
|
|
[[nodiscard]] bool IsNotInteractive() const |
|
|
|
|
{ |
|
|
|
|
return HasAnyOf(uiFlags_, UiFlags::ElementHidden | UiFlags::ElementDisabled); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool has_flag(UiFlags flag) const |
|
|
|
|
void Hide() |
|
|
|
|
{ |
|
|
|
|
return (m_iFlags & flag) == flag; |
|
|
|
|
uiFlags_ |= UiFlags::ElementHidden; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool has_any_flag(UiFlags flags) const |
|
|
|
|
void Show() |
|
|
|
|
{ |
|
|
|
|
return HasAnyOf(m_iFlags, flags); |
|
|
|
|
uiFlags_ &= ~UiFlags::ElementHidden; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void add_flag(UiFlags flag) |
|
|
|
|
protected: |
|
|
|
|
UiItemBase(UiType type, SDL_Rect rect, UiFlags flags) |
|
|
|
|
: type_(type) |
|
|
|
|
, m_rect(rect) |
|
|
|
|
, uiFlags_(flags) |
|
|
|
|
{ |
|
|
|
|
m_iFlags |= flag; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void remove_flag(UiFlags flag) |
|
|
|
|
void SetFlags(UiFlags flags) |
|
|
|
|
{ |
|
|
|
|
m_iFlags &= ~flag; |
|
|
|
|
uiFlags_ = flags; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// protected:
|
|
|
|
|
UiType m_type; |
|
|
|
|
private: |
|
|
|
|
UiType type_; |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
SDL_Rect m_rect; |
|
|
|
|
UiFlags m_iFlags; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
UiFlags uiFlags_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
@ -67,18 +92,41 @@ class UiImage : public UiItemBase {
|
|
|
|
|
public: |
|
|
|
|
UiImage(Art *art, SDL_Rect rect, UiFlags flags = UiFlags::None, bool animated = false, int frame = 0) |
|
|
|
|
: UiItemBase(UiType::Image, rect, flags) |
|
|
|
|
, m_art(art) |
|
|
|
|
, m_animated(animated) |
|
|
|
|
, m_frame(frame) |
|
|
|
|
, art_(art) |
|
|
|
|
, animated_(animated) |
|
|
|
|
, frame_(frame) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsCentered() const |
|
|
|
|
{ |
|
|
|
|
return HasAnyOf(GetFlags(), UiFlags::AlignCenter); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~UiImage() {}; |
|
|
|
|
[[nodiscard]] Art *GetArt() const |
|
|
|
|
{ |
|
|
|
|
return art_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private:
|
|
|
|
|
Art *m_art; |
|
|
|
|
bool m_animated; |
|
|
|
|
int m_frame; |
|
|
|
|
[[nodiscard]] bool IsAnimated() const |
|
|
|
|
{ |
|
|
|
|
return animated_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] int GetFrame() const |
|
|
|
|
{ |
|
|
|
|
return frame_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SetFrame(int frame) |
|
|
|
|
{ |
|
|
|
|
frame_ = frame; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
Art *art_; |
|
|
|
|
bool animated_; |
|
|
|
|
int frame_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
@ -93,9 +141,9 @@ public:
|
|
|
|
|
*/ |
|
|
|
|
UiArtText(const char *text, SDL_Rect rect, UiFlags flags = UiFlags::None, int spacing = 1, int lineHeight = -1) |
|
|
|
|
: UiItemBase(UiType::ArtText, rect, flags) |
|
|
|
|
, m_text(text) |
|
|
|
|
, m_spacing(spacing) |
|
|
|
|
, m_lineHeight(lineHeight) |
|
|
|
|
, text_(text) |
|
|
|
|
, spacing_(spacing) |
|
|
|
|
, lineHeight_(lineHeight) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -107,36 +155,34 @@ public:
|
|
|
|
|
*/ |
|
|
|
|
UiArtText(const char **ptext, SDL_Rect rect, UiFlags flags = UiFlags::None, int spacing = 1, int lineHeight = -1) |
|
|
|
|
: UiItemBase(UiType::ArtText, rect, flags) |
|
|
|
|
, m_ptext(ptext) |
|
|
|
|
, m_spacing(spacing) |
|
|
|
|
, m_lineHeight(lineHeight) |
|
|
|
|
, textPointer_(ptext) |
|
|
|
|
, spacing_(spacing) |
|
|
|
|
, lineHeight_(lineHeight) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char *text() const |
|
|
|
|
[[nodiscard]] string_view GetText() const |
|
|
|
|
{ |
|
|
|
|
if (m_text != nullptr) |
|
|
|
|
return m_text; |
|
|
|
|
return *m_ptext; |
|
|
|
|
if (text_ != nullptr) |
|
|
|
|
return text_; |
|
|
|
|
return *textPointer_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int spacing() const |
|
|
|
|
[[nodiscard]] int GetSpacing() const |
|
|
|
|
{ |
|
|
|
|
return m_spacing; |
|
|
|
|
return spacing_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int lineHeight() const |
|
|
|
|
[[nodiscard]] int GetLineHeight() const |
|
|
|
|
{ |
|
|
|
|
return m_lineHeight; |
|
|
|
|
return lineHeight_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~UiArtText() {}; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
const char *m_text = nullptr; |
|
|
|
|
const char **m_ptext = nullptr; |
|
|
|
|
int m_spacing = 1; |
|
|
|
|
int m_lineHeight = -1; |
|
|
|
|
const char *text_ = nullptr; |
|
|
|
|
const char **textPointer_ = nullptr; |
|
|
|
|
int spacing_; |
|
|
|
|
int lineHeight_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
@ -161,27 +207,44 @@ public:
|
|
|
|
|
|
|
|
|
|
class UiArtTextButton : public UiItemBase { |
|
|
|
|
public: |
|
|
|
|
UiArtTextButton(const char *text, void (*action)(), SDL_Rect rect, UiFlags flags = UiFlags::None) |
|
|
|
|
using Callback = void (*)(); |
|
|
|
|
|
|
|
|
|
UiArtTextButton(const char *text, Callback action, SDL_Rect rect, UiFlags flags = UiFlags::None) |
|
|
|
|
: UiItemBase(UiType::ArtTextButton, rect, flags) |
|
|
|
|
, m_text(text) |
|
|
|
|
, m_action(action) |
|
|
|
|
, text_(text) |
|
|
|
|
, action_(action) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private:
|
|
|
|
|
const char *m_text; |
|
|
|
|
void (*m_action)(); |
|
|
|
|
void SetFlags(UiFlags flags) |
|
|
|
|
{ |
|
|
|
|
UiItemBase::SetFlags(flags); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] string_view GetText() const |
|
|
|
|
{ |
|
|
|
|
return text_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Activate() const |
|
|
|
|
{ |
|
|
|
|
action_(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
const char *text_; |
|
|
|
|
Callback action_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
class UiEdit : public UiItemBase { |
|
|
|
|
public: |
|
|
|
|
UiEdit(const char *hint, char *value, std::size_t max_length, bool allowEmpty, SDL_Rect rect, UiFlags flags = UiFlags::None) |
|
|
|
|
UiEdit(const char *hint, char *value, std::size_t maxLength, bool allowEmpty, SDL_Rect rect, UiFlags flags = UiFlags::None) |
|
|
|
|
: UiItemBase(UiType::Edit, rect, flags) |
|
|
|
|
, m_hint(hint) |
|
|
|
|
, m_value(value) |
|
|
|
|
, m_max_length(max_length) |
|
|
|
|
, m_max_length(maxLength) |
|
|
|
|
, m_allowEmpty(allowEmpty) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
@ -201,12 +264,17 @@ class UiText : public UiItemBase {
|
|
|
|
|
public: |
|
|
|
|
UiText(const char *text, SDL_Rect rect, UiFlags flags = UiFlags::ColorDialogWhite) |
|
|
|
|
: UiItemBase(UiType::Text, rect, flags) |
|
|
|
|
, m_text(text) |
|
|
|
|
, text_(text) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private:
|
|
|
|
|
const char *m_text; |
|
|
|
|
[[nodiscard]] string_view GetText() const |
|
|
|
|
{ |
|
|
|
|
return text_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
const char *text_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
@ -215,28 +283,61 @@ public:
|
|
|
|
|
|
|
|
|
|
class UiButton : public UiItemBase { |
|
|
|
|
public: |
|
|
|
|
UiButton(Art *art, const char *text, void (*action)(), SDL_Rect rect, UiFlags flags = UiFlags::None) |
|
|
|
|
using Callback = void (*)(); |
|
|
|
|
|
|
|
|
|
UiButton(Art *art, const char *text, Callback action, SDL_Rect rect, UiFlags flags = UiFlags::None) |
|
|
|
|
: UiItemBase(UiType::Button, rect, flags) |
|
|
|
|
, m_art(art) |
|
|
|
|
, m_text(text) |
|
|
|
|
, m_action(action) |
|
|
|
|
, m_pressed(false) |
|
|
|
|
, art_(art) |
|
|
|
|
, text_(text) |
|
|
|
|
, action_(action) |
|
|
|
|
, pressed_(false) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum FrameKey : uint8_t { |
|
|
|
|
DEFAULT, |
|
|
|
|
PRESSED, |
|
|
|
|
}; |
|
|
|
|
[[nodiscard]] int GetFrame() const |
|
|
|
|
{ |
|
|
|
|
// Frame 1 is a held button sprite, frame 0 is the default
|
|
|
|
|
return IsPressed() ? 1 : 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private:
|
|
|
|
|
Art *m_art; |
|
|
|
|
[[nodiscard]] Art *GetArt() const |
|
|
|
|
{ |
|
|
|
|
return art_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char *m_text; |
|
|
|
|
void (*m_action)(); |
|
|
|
|
[[nodiscard]] string_view GetText() const |
|
|
|
|
{ |
|
|
|
|
return text_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Activate() const |
|
|
|
|
{ |
|
|
|
|
action_(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsPressed() const |
|
|
|
|
{ |
|
|
|
|
return pressed_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Press() |
|
|
|
|
{ |
|
|
|
|
pressed_ = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Release() |
|
|
|
|
{ |
|
|
|
|
pressed_ = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
Art *art_; |
|
|
|
|
|
|
|
|
|
const char *text_; |
|
|
|
|
Callback action_; |
|
|
|
|
|
|
|
|
|
// State
|
|
|
|
|
bool m_pressed; |
|
|
|
|
bool pressed_; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
@ -258,8 +359,6 @@ public:
|
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~UiListItem() {}; |
|
|
|
|
|
|
|
|
|
// private:
|
|
|
|
|
const char *m_text; |
|
|
|
|
std::vector<DrawStringFormatArg> args; |
|
|
|
|
@ -267,10 +366,10 @@ public:
|
|
|
|
|
UiFlags uiFlags; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
typedef std::vector<std::unique_ptr<UiListItem>> vUiListItem; |
|
|
|
|
|
|
|
|
|
class UiList : public UiItemBase { |
|
|
|
|
public: |
|
|
|
|
using vUiListItem = std::vector<std::unique_ptr<UiListItem>>; |
|
|
|
|
|
|
|
|
|
UiList(const vUiListItem &vItems, size_t viewportSize, Sint16 x, Sint16 y, Uint16 item_width, Uint16 item_height, UiFlags flags = UiFlags::None, int spacing = 1) |
|
|
|
|
: UiItemBase(UiType::List, { x, y, item_width, static_cast<Uint16>(item_height * viewportSize) }, flags) |
|
|
|
|
, viewportSize(viewportSize) |
|
|
|
|
@ -278,15 +377,13 @@ public:
|
|
|
|
|
, m_y(y) |
|
|
|
|
, m_width(item_width) |
|
|
|
|
, m_height(item_height) |
|
|
|
|
, m_spacing(spacing) |
|
|
|
|
, spacing_(spacing) |
|
|
|
|
{ |
|
|
|
|
for (auto &item : vItems) |
|
|
|
|
for (const auto &item : vItems) |
|
|
|
|
m_vecItems.push_back(item.get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
~UiList() {}; |
|
|
|
|
|
|
|
|
|
SDL_Rect itemRect(int i) const |
|
|
|
|
[[nodiscard]] SDL_Rect itemRect(int i) const |
|
|
|
|
{ |
|
|
|
|
SDL_Rect tmp; |
|
|
|
|
tmp.x = m_x; |
|
|
|
|
@ -305,14 +402,14 @@ public:
|
|
|
|
|
return index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UiListItem *GetItem(int i) const |
|
|
|
|
[[nodiscard]] UiListItem *GetItem(std::size_t i) const |
|
|
|
|
{ |
|
|
|
|
return m_vecItems[i]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int spacing() const |
|
|
|
|
[[nodiscard]] int GetSpacing() const |
|
|
|
|
{ |
|
|
|
|
return m_spacing; |
|
|
|
|
return spacing_; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private:
|
|
|
|
|
@ -320,6 +417,8 @@ public:
|
|
|
|
|
Sint16 m_x, m_y; |
|
|
|
|
Uint16 m_width, m_height; |
|
|
|
|
std::vector<UiListItem *> m_vecItems; |
|
|
|
|
int m_spacing; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
int spacing_; |
|
|
|
|
}; |
|
|
|
|
} // namespace devilution
|
|
|
|
|
|