19 #include <winpr/assert.h>
21 #include <rdtk/config.h>
23 #include "rdtk_font.h"
25 #include "rdtk_button.h"
27 int rdtk_button_draw(rdtkSurface* surface, uint16_t nXDst, uint16_t nYDst, uint16_t nWidth,
28 uint16_t nHeight, rdtkButton* button,
const char* text)
32 uint16_t textWidth = 0;
33 uint16_t textHeight = 0;
34 uint16_t fillWidth = 0;
35 uint16_t fillHeight = 0;
37 WINPR_ASSERT(surface);
41 rdtkEngine* engine = surface->engine;
42 rdtkFont* font = engine->font;
43 rdtkNinePatch* ninePatch = button->ninePatch;
45 rdtk_font_text_draw_size(font, &textWidth, &textHeight, text);
47 rdtk_nine_patch_draw(surface, nXDst, nYDst, nWidth, nHeight, ninePatch);
49 if ((textWidth > 0) && (textHeight > 0))
51 fillWidth = nWidth - (ninePatch->width - ninePatch->fillWidth);
52 fillHeight = nHeight - (ninePatch->height - ninePatch->fillHeight);
54 offsetX = ninePatch->fillLeft;
55 offsetY = ninePatch->fillTop;
57 if (textWidth < fillWidth)
58 offsetX = ((fillWidth - textWidth) / 2) + ninePatch->fillLeft;
59 else if (textWidth < ninePatch->width)
60 offsetX = ((ninePatch->width - textWidth) / 2);
62 if (textHeight < fillHeight)
63 offsetY = ((fillHeight - textHeight) / 2) + ninePatch->fillTop;
64 else if (textHeight < ninePatch->height)
65 offsetY = ((ninePatch->height - textHeight) / 2);
67 rdtk_font_draw_text(surface, nXDst + offsetX, nYDst + offsetY, font, text);
73 rdtkButton* rdtk_button_new(rdtkEngine* engine, rdtkNinePatch* ninePatch)
76 WINPR_ASSERT(ninePatch);
78 rdtkButton* button = (rdtkButton*)calloc(1,
sizeof(rdtkButton));
83 button->engine = engine;
84 button->ninePatch = ninePatch;
89 void rdtk_button_free(rdtkButton* button)
94 int rdtk_button_engine_init(rdtkEngine* engine)
100 engine->button = rdtk_button_new(engine, engine->button9patch);
108 int rdtk_button_engine_uninit(rdtkEngine* engine)
110 WINPR_ASSERT(engine);
114 rdtk_button_free(engine->button);
115 engine->button = NULL;