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 const int rc1 = rdtk_font_text_draw_size(font, &textWidth, &textHeight, text);
42 if (rc1 < 0)
43 return rc1;
44
45 if ((textWidth > 0) && (textHeight > 0))
46 {
47 offsetX = 0;
48 offsetY = 0;
49
50 if (textWidth < nWidth)
51 offsetX = ((nWidth - textWidth) / 2);
52
53 if (textHeight < nHeight)
54 offsetY = ((nHeight - textHeight) / 2);
55
56 const int rc2 = rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
57 if (rc2 < 0)
58 return rc2;
59 }
60
61 return 1;
62}
63
64rdtkLabel* rdtk_label_new(rdtkEngine* engine)
65{
66 WINPR_ASSERT(engine);
67 rdtkLabel* label = (rdtkLabel*)calloc(1, sizeof(rdtkLabel));
68
69 if (!label)
70 return NULL;
71
72 label->engine = engine;
73
74 return label;
75}
76
77void rdtk_label_free(rdtkLabel* label)
78{
79 free(label);
80}
81
82int rdtk_label_engine_init(rdtkEngine* engine)
83{
84 WINPR_ASSERT(engine);
85 if (!engine->label)
86 {
87 engine->label = rdtk_label_new(engine);
88 }
89
90 return 1;
91}
92
93int rdtk_label_engine_uninit(rdtkEngine* engine)
94{
95 WINPR_ASSERT(engine);
96 if (engine->label)
97 {
98 rdtk_label_free(engine->label);
99 engine->label = NULL;
100 }
101
102 return 1;
103}