FreeRDP
Loading...
Searching...
No Matches
rdtk_label.c
1
19#include <winpr/assert.h>
20
21#include <rdtk/config.h>
22
23#include "rdtk_font.h"
24
25#include "rdtk_label.h"
26
27int rdtk_label_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
28 uint16_t nHeight, WINPR_ATTR_UNUSED rdtkLabel* label, const char* text,
29 WINPR_ATTR_UNUSED uint16_t hAlign, WINPR_ATTR_UNUSED uint16_t vAlign)
30{
31 uint16_t offsetX = 0;
32 uint16_t offsetY = 0;
33 uint16_t textWidth = 0;
34 uint16_t textHeight = 0;
35
36 WINPR_ASSERT(surface);
37
38 rdtkEngine* engine = surface->engine;
39 rdtkFont* font = engine->font;
40
41 rdtk_font_text_draw_size(font, &textWidth, &textHeight, text);
42
43 if ((textWidth > 0) && (textHeight > 0))
44 {
45 offsetX = 0;
46 offsetY = 0;
47
48 if (textWidth < nWidth)
49 offsetX = ((nWidth - textWidth) / 2);
50
51 if (textHeight < nHeight)
52 offsetY = ((nHeight - textHeight) / 2);
53
54 rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
55 }
56
57 return 1;
58}
59
60rdtkLabel* rdtk_label_new(rdtkEngine* engine)
61{
62 WINPR_ASSERT(engine);
63 rdtkLabel* label = (rdtkLabel*)calloc(1, sizeof(rdtkLabel));
64
65 if (!label)
66 return NULL;
67
68 label->engine = engine;
69
70 return label;
71}
72
73void rdtk_label_free(rdtkLabel* label)
74{
75 free(label);
76}
77
78int rdtk_label_engine_init(rdtkEngine* engine)
79{
80 WINPR_ASSERT(engine);
81 if (!engine->label)
82 {
83 engine->label = rdtk_label_new(engine);
84 }
85
86 return 1;
87}
88
89int rdtk_label_engine_uninit(rdtkEngine* engine)
90{
91 WINPR_ASSERT(engine);
92 if (engine->label)
93 {
94 rdtk_label_free(engine->label);
95 engine->label = NULL;
96 }
97
98 return 1;
99}