FreeRDP
SDL3/dialogs/sdl_button.cpp
1 
21 #include <cassert>
22 #include <utility>
23 
24 #include "sdl_button.hpp"
25 
26 static const SDL_Color buttonbackgroundcolor = { 0x69, 0x66, 0x63, 0xff };
27 static const SDL_Color buttonhighlightcolor = { 0xcd, 0xca, 0x35, 0x60 };
28 static const SDL_Color buttonmouseovercolor = { 0x66, 0xff, 0x66, 0x60 };
29 static const SDL_Color buttonfontcolor = { 0xd1, 0xcf, 0xcd, 0xff };
30 
31 SdlButton::SdlButton(SDL_Renderer* renderer, std::string label, int id, const SDL_FRect& rect)
32  : SdlWidget(renderer, rect, false), _name(std::move(label)), _id(id)
33 {
34  assert(renderer);
35 
36  update_text(renderer, _name, buttonfontcolor, buttonbackgroundcolor);
37 }
38 
39 SdlButton::SdlButton(SdlButton&& other) noexcept = default;
40 
41 SdlButton::~SdlButton() = default;
42 
43 bool SdlButton::highlight(SDL_Renderer* renderer)
44 {
45  assert(renderer);
46 
47  std::vector<SDL_Color> colors = { buttonbackgroundcolor, buttonhighlightcolor };
48  if (!fill(renderer, colors))
49  return false;
50  return update_text(renderer, _name, buttonfontcolor);
51 }
52 
53 bool SdlButton::mouseover(SDL_Renderer* renderer)
54 {
55  std::vector<SDL_Color> colors = { buttonbackgroundcolor, buttonmouseovercolor };
56  if (!fill(renderer, colors))
57  return false;
58  return update_text(renderer, _name, buttonfontcolor);
59 }
60 
61 bool SdlButton::update(SDL_Renderer* renderer)
62 {
63  assert(renderer);
64 
65  return update_text(renderer, _name, buttonfontcolor, buttonbackgroundcolor);
66 }
67 
68 int SdlButton::id() const
69 {
70  return _id;
71 }