FreeRDP
SDL2/dialogs/sdl_select.cpp
1 
20 #include <cassert>
21 
22 #include <string>
23 #include <utility>
24 
25 #include <SDL.h>
26 #include <SDL_ttf.h>
27 
28 #include "sdl_select.hpp"
29 #include "sdl_widget.hpp"
30 #include "sdl_button.hpp"
31 #include "sdl_buttons.hpp"
32 #include "sdl_input_widgets.hpp"
33 
34 static const SDL_Color labelmouseovercolor = { 0, 0x80, 0, 0x60 };
35 static const SDL_Color labelbackgroundcolor = { 0x69, 0x66, 0x63, 0xff };
36 static const SDL_Color labelhighlightcolor = { 0xcd, 0xca, 0x35, 0x60 };
37 static const SDL_Color labelfontcolor = { 0xd1, 0xcf, 0xcd, 0xff };
38 
39 SdlSelectWidget::SdlSelectWidget(SDL_Renderer* renderer, std::string label, SDL_Rect rect)
40  : SdlWidget(renderer, rect, true), _text(std::move(label)), _mouseover(false), _highlight(false)
41 {
42  update_text(renderer);
43 }
44 
45 SdlSelectWidget::SdlSelectWidget(SdlSelectWidget&& other) noexcept = default;
46 
47 SdlSelectWidget::~SdlSelectWidget() = default;
48 
49 bool SdlSelectWidget::set_mouseover(SDL_Renderer* renderer, bool mouseOver)
50 {
51  _mouseover = mouseOver;
52  return update_text(renderer);
53 }
54 
55 bool SdlSelectWidget::set_highlight(SDL_Renderer* renderer, bool highlight)
56 {
57  _highlight = highlight;
58  return update_text(renderer);
59 }
60 
61 bool SdlSelectWidget::update_text(SDL_Renderer* renderer)
62 {
63  assert(renderer);
64  std::vector<SDL_Color> colors = { labelbackgroundcolor };
65  if (_highlight)
66  colors.push_back(labelhighlightcolor);
67  if (_mouseover)
68  colors.push_back(labelmouseovercolor);
69  if (!fill(renderer, colors))
70  return false;
71  return SdlWidget::update_text(renderer, _text, labelfontcolor);
72 }