FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
SDL3/dialogs/sdl_select.cpp
1
20#include <cassert>
21
22#include <string>
23#include <utility>
24
25#include <SDL3/SDL.h>
26#include <SDL3_ttf/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
34static const SDL_Color labelmouseovercolor = { 0, 0x80, 0, 0x60 };
35static const SDL_Color labelbackgroundcolor = { 0x69, 0x66, 0x63, 0xff };
36static const SDL_Color labelhighlightcolor = { 0xcd, 0xca, 0x35, 0x60 };
37static const SDL_Color labelfontcolor = { 0xd1, 0xcf, 0xcd, 0xff };
38
39SdlSelectWidget::SdlSelectWidget(SDL_Renderer* renderer, std::string label, const SDL_FRect& rect)
40 : SdlWidget(renderer, rect, true), _text(std::move(label)), _mouseover(false), _highlight(false)
41{
42}
43
44SdlSelectWidget::SdlSelectWidget(SdlSelectWidget&& other) noexcept = default;
45
46bool SdlSelectWidget::set_mouseover(SDL_Renderer* renderer, bool mouseOver)
47{
48 _mouseover = mouseOver;
49 return update_text(renderer);
50}
51
52bool SdlSelectWidget::set_highlight(SDL_Renderer* renderer, bool highlight)
53{
54 _highlight = highlight;
55 return update_text(renderer);
56}
57
58bool SdlSelectWidget::update_text(SDL_Renderer* renderer)
59{
60 assert(renderer);
61 std::vector<SDL_Color> colors = { labelbackgroundcolor };
62 if (_highlight)
63 colors.push_back(labelhighlightcolor);
64 if (_mouseover)
65 colors.push_back(labelmouseovercolor);
66 if (!fill(renderer, colors))
67 return false;
68 return SdlWidget::update_text(renderer, _text, labelfontcolor);
69}