FreeRDP
Loading...
Searching...
No Matches
SdlWidget Class Reference
Inheritance diagram for SdlWidget:

Public Member Functions

 SdlWidget (SDL_Renderer *renderer, SDL_Rect rect, bool input)
 
 SdlWidget (SdlWidget &&other) noexcept
 
bool fill (SDL_Renderer *renderer, SDL_Color color)
 
bool fill (SDL_Renderer *renderer, const std::vector< SDL_Color > &colors)
 
bool update_text (SDL_Renderer *renderer, const std::string &text, SDL_Color fgcolor)
 
bool update_text (SDL_Renderer *renderer, const std::string &text, SDL_Color fgcolor, SDL_Color bgcolor)
 
bool wrap () const
 
bool set_wrap (bool wrap=true, size_t width=0)
 
const SDL_Rect & rect () const
 
 SdlWidget (const SdlWidget &other)=delete
 
SdlWidgetoperator= (const SdlWidget &other)=delete
 
SdlWidgetoperator= (SdlWidget &&other)=delete
 
 SdlWidget (SDL_Renderer *renderer, const SDL_FRect &rect, bool input)
 
 SdlWidget (SDL_Renderer *renderer, const SDL_FRect &rect, SDL_IOStream *ops)
 
 SdlWidget (const SdlWidget &other)=delete
 
 SdlWidget (SdlWidget &&other) noexcept
 
SdlWidgetoperator= (const SdlWidget &other)=delete
 
SdlWidgetoperator= (SdlWidget &&other)=delete
 
bool fill (SDL_Renderer *renderer, SDL_Color color)
 
bool fill (SDL_Renderer *renderer, const std::vector< SDL_Color > &colors)
 
bool update_text (SDL_Renderer *renderer, const std::string &text, SDL_Color fgcolor)
 
bool update_text (SDL_Renderer *renderer, const std::string &text, SDL_Color fgcolor, SDL_Color bgcolor)
 
bool wrap () const
 
bool set_wrap (bool wrap=true, size_t width=0)
 
const SDL_FRect & rect () const
 

Static Public Member Functions

static bool error_ex (Sint32 res, const char *what, const char *file, size_t line, const char *fkt)
 
static bool error_ex (bool success, const char *what, const char *file, size_t line, const char *fkt)
 

Detailed Description

Definition at line 48 of file SDL2/dialogs/sdl_widget.hpp.

Constructor & Destructor Documentation

◆ SdlWidget() [1/3]

SdlWidget::SdlWidget ( SDL_Renderer *  renderer,
SDL_Rect  rect,
bool  input 
)

Definition at line 45 of file SDL2/dialogs/sdl_widget.cpp.

45 : _rect(rect), _input(input)
46{
47 assert(renderer);
48
50 "OpenSans-VariableFont_wdth,wght.ttf");
51 if (!ops)
52 widget_log_error(-1, "SDLResourceManager::get");
53 else
54 {
55 _font = TTF_OpenFontRW(ops, 1, 64);
56 if (!_font)
57 widget_log_error(-1, "TTF_OpenFontRW");
58 }
59}
static SDL_RWops * get(const std::string &type, const std::string &id)
static std::string typeFonts()

◆ SdlWidget() [2/3]

SdlWidget::SdlWidget ( SdlWidget &&  other)
noexcept

Definition at line 73 of file SDL2/dialogs/sdl_widget.cpp.

74 : _font(other._font), _image(other._image), _rect(other._rect), _input(other._input),
75 _wrap(other._wrap), _text_width(other._text_width)
76{
77 other._font = nullptr;
78 other._image = nullptr;
79}

◆ ~SdlWidget()

SdlWidget::~SdlWidget ( )
virtual

Definition at line 172 of file SDL2/dialogs/sdl_widget.cpp.

173{
174 TTF_CloseFont(_font);
175 if (_image)
176 SDL_DestroyTexture(_image);
177}

◆ SdlWidget() [3/3]

SdlWidget::SdlWidget ( SDL_Renderer *  renderer,
const SDL_FRect &  rect,
bool  input 
)

Definition at line 45 of file SDL3/dialogs/sdl_widget.cpp.

46 : _rect(rect), _input(input)
47{
48 assert(renderer);
49
51 "OpenSans-VariableFont_wdth,wght.ttf");
52 if (!ops)
53 widget_log_error(-1, "SDLResourceManager::get");
54 else
55 {
56 _font = TTF_OpenFontIO(ops, true, 64);
57 if (!_font)
58 widget_log_error(-1, "TTF_OpenFontRW");
59 }
60}
static SDL_IOStream * get(const std::string &type, const std::string &id)

Member Function Documentation

◆ error_ex() [1/2]

bool SdlWidget::error_ex ( bool  success,
const char *  what,
const char *  file,
size_t  line,
const char *  fkt 
)
static

Definition at line 198 of file SDL3/dialogs/sdl_widget.cpp.

200{
201 if (success)
202 {
203 // Flip SDL3 convention to existing code convention to minimize code changes
204 return false;
205 }
206 static wLog* log = nullptr;
207 if (!log)
208 log = WLog_Get(TAG);
209 // Use -1 as it indicates error similar to SDL2 conventions
210 // sdl_log_error_ex treats any value other than 0 as SDL error
211 return sdl_log_error_ex(-1, log, what, file, line, fkt);
212}

◆ error_ex() [2/2]

bool SdlWidget::error_ex ( Sint32  res,
const char *  what,
const char *  file,
size_t  line,
const char *  fkt 
)
static

Definition at line 179 of file SDL2/dialogs/sdl_widget.cpp.

181{
182 static wLog* log = nullptr;
183 if (!log)
184 log = WLog_Get(TAG);
185 return sdl_log_error_ex(res, log, what, file, line, fkt);
186}

◆ fill() [1/2]

bool SdlWidget::fill ( SDL_Renderer *  renderer,
const std::vector< SDL_Color > &  colors 
)

Definition at line 204 of file SDL2/dialogs/sdl_widget.cpp.

205{
206 assert(renderer);
207 SDL_BlendMode mode = SDL_BLENDMODE_INVALID;
208 SDL_GetRenderDrawBlendMode(renderer, &mode);
209 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
210 for (auto color : colors)
211 {
212 draw_rect(renderer, &_rect, color);
213 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD);
214 }
215 SDL_SetRenderDrawBlendMode(renderer, mode);
216 return true;
217}

◆ fill() [2/2]

bool SdlWidget::fill ( SDL_Renderer *  renderer,
SDL_Color  color 
)

Definition at line 198 of file SDL2/dialogs/sdl_widget.cpp.

199{
200 std::vector<SDL_Color> colors = { color };
201 return fill(renderer, colors);
202}

◆ rect()

const SDL_FRect & SdlWidget::rect ( ) const

Definition at line 241 of file SDL2/dialogs/sdl_widget.cpp.

242{
243 return _rect;
244}

◆ set_wrap()

bool SdlWidget::set_wrap ( bool  wrap = true,
size_t  width = 0 
)

Definition at line 234 of file SDL2/dialogs/sdl_widget.cpp.

235{
236 _wrap = wrap;
237 _text_width = width;
238 return _wrap;
239}

◆ update_text() [1/2]

bool SdlWidget::update_text ( SDL_Renderer *  renderer,
const std::string &  text,
SDL_Color  fgcolor 
)

Definition at line 246 of file SDL2/dialogs/sdl_widget.cpp.

247{
248
249 if (text.empty())
250 return true;
251
252 SDL_Rect src{};
253 SDL_Rect dst{};
254
255 SDL_Texture* texture = nullptr;
256 if (_image)
257 {
258 texture = _image;
259 dst = _rect;
260 auto rc = SDL_QueryTexture(_image, nullptr, nullptr, &src.w, &src.h);
261 if (rc < 0)
262 widget_log_error(rc, "SDL_QueryTexture");
263 }
264 else if (_wrap)
265 texture = render_text_wrapped(renderer, text, fgcolor, src, dst);
266 else
267 texture = render_text(renderer, text, fgcolor, src, dst);
268 if (!texture)
269 return false;
270
271 const int rc = SDL_RenderCopy(renderer, texture, &src, &dst);
272 if (!_image)
273 SDL_DestroyTexture(texture);
274 if (rc < 0)
275 return !widget_log_error(rc, "SDL_RenderCopy");
276 return true;
277}

◆ update_text() [2/2]

bool SdlWidget::update_text ( SDL_Renderer *  renderer,
const std::string &  text,
SDL_Color  fgcolor,
SDL_Color  bgcolor 
)

Definition at line 219 of file SDL2/dialogs/sdl_widget.cpp.

221{
222 assert(renderer);
223
224 if (!fill(renderer, bgcolor))
225 return false;
226 return update_text(renderer, text, fgcolor);
227}

◆ wrap()

bool SdlWidget::wrap ( ) const

Definition at line 229 of file SDL2/dialogs/sdl_widget.cpp.

230{
231 return _wrap;
232}

The documentation for this class was generated from the following files: