19 changed files with 571 additions and 156 deletions
@ -0,0 +1,53 @@
|
||||
#include "DiabloUI/button.h" |
||||
#include "DiabloUI/art_draw.h" |
||||
#include "DiabloUI/text_draw.h" |
||||
|
||||
namespace dvl { |
||||
|
||||
Art SmlButton; |
||||
|
||||
void LoadSmlButtonArt() |
||||
{ |
||||
LoadArt("ui_art\\but_sml.pcx", &SmlButton, 15); |
||||
} |
||||
|
||||
void RenderButton(UiButton *button) |
||||
{ |
||||
int frame; |
||||
if (button->has_flag(UIS_DISABLED)) { |
||||
frame = button->frame_map[UiButton::DISABLED]; |
||||
} else if (button->pressed) { |
||||
frame = button->frame_map[UiButton::PRESSED]; |
||||
} else { |
||||
frame = button->frame_map[UiButton::DEFAULT]; |
||||
} |
||||
DrawArt(button->rect.x, button->rect.y, button->art, frame, button->rect.w, button->rect.h); |
||||
|
||||
SDL_Rect text_rect = button->rect; |
||||
if (!button->pressed) --text_rect.y; |
||||
DrawTTF(button->text, text_rect, UIS_CENTER, |
||||
SDL_Color{ 243, 243, 243, 0 }, SDL_Color{ 0, 0, 0, 0 }, &button->render_cache); |
||||
} |
||||
|
||||
bool HandleMouseEventButton(const SDL_Event &event, UiButton *button) |
||||
{ |
||||
if (event.button.button != SDL_BUTTON_LEFT) |
||||
return false; |
||||
switch (event.type) { |
||||
case SDL_MOUSEBUTTONUP: |
||||
button->action(); |
||||
return true; |
||||
case SDL_MOUSEBUTTONDOWN: |
||||
button->pressed = true; |
||||
return true; |
||||
default: |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
void HandleGlobalMouseUpButton(UiButton *button) |
||||
{ |
||||
button->pressed = false; |
||||
} |
||||
|
||||
} // namespace dvl
|
||||
@ -0,0 +1,52 @@
|
||||
#pragma once |
||||
|
||||
#include "DiabloUI/art.h" |
||||
#include "DiabloUI/ui_item.h" |
||||
|
||||
namespace dvl { |
||||
|
||||
extern Art SmlButton; |
||||
void LoadSmlButtonArt(); |
||||
inline void UnloadSmlButtonArt() |
||||
{ |
||||
SmlButton.Unload(); |
||||
} |
||||
constexpr decltype(SDL_Rect().w) SML_BUTTON_WIDTH = 110; |
||||
constexpr decltype(SDL_Rect().h) SML_BUTTON_HEIGHT = 27; |
||||
|
||||
enum class ButtonFrame { |
||||
BG_GOLD = 0, |
||||
BG_GOLD_PRESSED, |
||||
BG_YELLOW, |
||||
BG_YELLOW_PRESSED, |
||||
DISABLED, |
||||
}; |
||||
|
||||
constexpr UiButton::FrameMap ButtonBgYellowFrameMap = { |
||||
static_cast<int>(ButtonFrame::BG_YELLOW), |
||||
static_cast<int>(ButtonFrame::BG_YELLOW_PRESSED), |
||||
static_cast<int>(ButtonFrame::DISABLED), |
||||
}; |
||||
constexpr UiButton::FrameMap ButtonBgGoldFrameMap = { |
||||
static_cast<int>(ButtonFrame::BG_GOLD), |
||||
static_cast<int>(ButtonFrame::BG_GOLD_PRESSED), |
||||
static_cast<int>(ButtonFrame::DISABLED), |
||||
}; |
||||
|
||||
constexpr UiButton MakeSmlButton( |
||||
const char *text, void (*action)(), decltype(SDL_Rect().x) x, decltype(SDL_Rect().y) y, int flags = 0) |
||||
{ |
||||
return UiButton( |
||||
&SmlButton, |
||||
(flags & UIS_GOLD) ? ButtonBgGoldFrameMap : ButtonBgYellowFrameMap, |
||||
text, |
||||
action, |
||||
SDL_Rect{ x, y, SML_BUTTON_WIDTH, SML_BUTTON_HEIGHT }, |
||||
flags); |
||||
} |
||||
|
||||
void RenderButton(UiButton *button); |
||||
bool HandleMouseEventButton(const SDL_Event &event, UiButton *button); |
||||
void HandleGlobalMouseUpButton(UiButton *button); |
||||
|
||||
} // namespace dvl
|
||||
@ -0,0 +1,12 @@
|
||||
#pragma once |
||||
|
||||
#include <cstddef> |
||||
|
||||
#include "DiabloUI/ui_item.h" |
||||
|
||||
namespace dvl { |
||||
|
||||
void UiErrorOkDialog(const char *text, UiItem *renderBehind, std::size_t renderBehindSize); |
||||
void UiErrorOkDialog(const char *text, const char *caption, UiItem *render_behind, std::size_t render_behind_size); |
||||
|
||||
} // namespace dvl
|
||||
Loading…
Reference in new issue