FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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.

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_OpenFontRW(ops, 1, 64);
57 if (!_font)
58 widget_log_error(-1, "TTF_OpenFontRW");
59 }
60}
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 74 of file SDL2/dialogs/sdl_widget.cpp.

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

◆ ~SdlWidget()

SdlWidget::~SdlWidget ( )
virtual

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

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

◆ 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(false, "SDLResourceManager::get");
54 else
55 {
56 _font = TTF_OpenFontIO(ops, true, 64);
57 if (!_font)
58 widget_log_error(false, "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 180 of file SDL2/dialogs/sdl_widget.cpp.

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

◆ fill() [1/2]

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

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

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

◆ fill() [2/2]

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

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

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

◆ rect()

const SDL_FRect & SdlWidget::rect ( ) const

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

243{
244 return _rect;
245}

◆ set_wrap()

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

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

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

◆ update_text() [1/2]

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

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

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

◆ update_text() [2/2]

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

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

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

◆ wrap()

bool SdlWidget::wrap ( ) const

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

231{
232 return _wrap;
233}

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