19 #include <winpr/assert.h>
21 #include <rdtk/config.h>
23 #include "rdtk_font.h"
25 #include "rdtk_text_field.h"
27 int rdtk_text_field_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
28 uint16_t nHeight, rdtkTextField* textField,
const char* text)
32 uint16_t textWidth = 0;
33 uint16_t textHeight = 0;
34 uint16_t fillWidth = 0;
35 uint16_t fillHeight = 0;
36 rdtkFont* font = NULL;
37 rdtkEngine* engine = NULL;
38 rdtkNinePatch* ninePatch = NULL;
40 WINPR_ASSERT(surface);
41 WINPR_ASSERT(textField);
44 engine = surface->engine;
46 textField = surface->engine->textField;
47 ninePatch = textField->ninePatch;
49 rdtk_font_text_draw_size(font, &textWidth, &textHeight, text);
51 rdtk_nine_patch_draw(surface, nXDst, nYDst, nWidth, nHeight, ninePatch);
53 if ((textWidth > 0) && (textHeight > 0))
55 fillWidth = nWidth - (ninePatch->width - ninePatch->fillWidth);
56 fillHeight = nHeight - (ninePatch->height - ninePatch->fillHeight);
58 offsetX = ninePatch->fillLeft;
59 offsetY = ninePatch->fillTop;
61 if (textWidth < fillWidth)
62 offsetX = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
63 else if (textWidth < ninePatch->width)
64 offsetX = ((ninePatch->width - textWidth) / 2);
66 if (textHeight < fillHeight)
67 offsetY = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
68 else if (textHeight < ninePatch->height)
69 offsetY = ((ninePatch->height - textHeight) / 2);
71 rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
77 rdtkTextField* rdtk_text_field_new(rdtkEngine* engine, rdtkNinePatch* ninePatch)
80 WINPR_ASSERT(ninePatch);
82 rdtkTextField* textField = (rdtkTextField*)calloc(1,
sizeof(rdtkTextField));
87 textField->engine = engine;
88 textField->ninePatch = ninePatch;
93 void rdtk_text_field_free(rdtkTextField* textField)
98 int rdtk_text_field_engine_init(rdtkEngine* engine)
100 WINPR_ASSERT(engine);
102 if (!engine->textField)
104 engine->textField = rdtk_text_field_new(engine, engine->textField9patch);
105 if (!engine->textField)
112 int rdtk_text_field_engine_uninit(rdtkEngine* engine)
114 WINPR_ASSERT(engine);
115 if (engine->textField)
117 rdtk_text_field_free(engine->textField);
118 engine->textField = NULL;