mGUI: Add 9-slice drawing

This commit is contained in:
Vicki Pfau 2021-09-06 16:54:40 -07:00
parent 337ca2cfaf
commit f603fcdb72
5 changed files with 110 additions and 0 deletions

View File

@ -59,6 +59,31 @@ enum GUIIcon {
GUI_ICON_UP,
GUI_ICON_RIGHT,
GUI_ICON_DOWN,
GUI_ICON_9SLICE_EMPTY_NW,
GUI_ICON_9SLICE_EMPTY_N,
GUI_ICON_9SLICE_EMPTY_NE,
GUI_ICON_9SLICE_EMPTY_W,
GUI_ICON_9SLICE_EMPTY_E,
GUI_ICON_9SLICE_EMPTY_SW,
GUI_ICON_9SLICE_EMPTY_S,
GUI_ICON_9SLICE_EMPTY_SE,
GUI_ICON_9SLICE_FILLED_NW,
GUI_ICON_9SLICE_FILLED_N,
GUI_ICON_9SLICE_FILLED_NE,
GUI_ICON_9SLICE_FILLED_W,
GUI_ICON_9SLICE_FILLED_C,
GUI_ICON_9SLICE_FILLED_E,
GUI_ICON_9SLICE_FILLED_SW,
GUI_ICON_9SLICE_FILLED_S,
GUI_ICON_9SLICE_FILLED_SE,
GUI_ICON_9SLICE_CAP_NNW,
GUI_ICON_9SLICE_CAP_NWW,
GUI_ICON_9SLICE_CAP_NNE,
GUI_ICON_9SLICE_CAP_NEE,
GUI_ICON_9SLICE_CAP_SSW,
GUI_ICON_9SLICE_CAP_SWW,
GUI_ICON_9SLICE_CAP_SSE,
GUI_ICON_9SLICE_CAP_SEE,
GUI_ICON_MAX,
};
@ -80,6 +105,12 @@ struct GUIIconMetric {
int height;
};
enum GUI9SliceStyle {
GUI_9SLICE_FILLED,
GUI_9SLICE_EMPTY,
GUI_9SLICE_EMPTY_CAPPED,
};
unsigned GUIFontHeight(const struct GUIFont*);
unsigned GUIFontGlyphWidth(const struct GUIFont*, uint32_t glyph);
unsigned GUIFontSpanWidth(const struct GUIFont*, const char* text);
@ -96,6 +127,8 @@ void GUIFontDrawIconSize(struct GUIFont* font, int x, int y, int w, int h, uint3
void GUIFontDrawSubmit(struct GUIFont* font);
#endif
void GUIFontDraw9Slice(struct GUIFont*, int x, int y, int width, int height, uint32_t color, enum GUI9SliceStyle style);
CXX_GUARD_END
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 619 B

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -158,4 +158,29 @@ const struct GUIIconMetric defaultIconMetrics[] = {
[GUI_ICON_DOWN] = { 130, 34, 12, 12 },
[GUI_ICON_STATUS_FAST_FORWARD] = { 2, 50, 12, 12 },
[GUI_ICON_STATUS_MUTE] = { 17, 50, 14, 12 },
[GUI_ICON_9SLICE_EMPTY_NW] = { 162, 1, 8, 8 },
[GUI_ICON_9SLICE_EMPTY_N] = { 170, 1, 12, 8 },
[GUI_ICON_9SLICE_EMPTY_NE] = { 182, 1, 8, 8 },
[GUI_ICON_9SLICE_EMPTY_W] = { 162, 9, 8, 12 },
[GUI_ICON_9SLICE_EMPTY_E] = { 182, 9, 8, 12 },
[GUI_ICON_9SLICE_EMPTY_SW] = { 162, 23, 8, 8 },
[GUI_ICON_9SLICE_EMPTY_S] = { 170, 23, 12, 8 },
[GUI_ICON_9SLICE_EMPTY_SE] = { 182, 23, 8, 8 },
[GUI_ICON_9SLICE_FILLED_NW] = { 194, 1, 8, 8 },
[GUI_ICON_9SLICE_FILLED_N] = { 202, 1, 12, 8 },
[GUI_ICON_9SLICE_FILLED_NE] = { 214, 1, 8, 8 },
[GUI_ICON_9SLICE_FILLED_W] = { 194, 9, 8, 12 },
[GUI_ICON_9SLICE_FILLED_C] = { 202, 9, 12, 12 },
[GUI_ICON_9SLICE_FILLED_E] = { 214, 9, 8, 12 },
[GUI_ICON_9SLICE_FILLED_SW] = { 194, 23, 8, 8 },
[GUI_ICON_9SLICE_FILLED_S] = { 202, 23, 12, 8 },
[GUI_ICON_9SLICE_FILLED_SE] = { 214, 23, 8, 8 },
[GUI_ICON_9SLICE_CAP_NNW] = { 240, 1, 8, 7 },
[GUI_ICON_9SLICE_CAP_NWW] = { 226, 16, 6, 8 },
[GUI_ICON_9SLICE_CAP_NNE] = { 232, 1, 8, 7 },
[GUI_ICON_9SLICE_CAP_NEE] = { 248, 16, 6, 8 },
[GUI_ICON_9SLICE_CAP_SSW] = { 240, 24, 8, 7 },
[GUI_ICON_9SLICE_CAP_SWW] = { 226, 8, 6, 8 },
[GUI_ICON_9SLICE_CAP_SSE] = { 232, 24, 8, 7 },
[GUI_ICON_9SLICE_CAP_SEE] = { 248, 8, 6, 8 },
};

View File

@ -86,3 +86,55 @@ void GUIFontPrintf(struct GUIFont* font, int x, int y, enum GUIAlignment align,
va_end(args);
GUIFontPrint(font, x, y, align, color, buffer);
}
void GUIFontDraw9Slice(struct GUIFont* font, int x, int y, int width, int height, uint32_t color, enum GUI9SliceStyle style) {
switch (style) {
case GUI_9SLICE_EMPTY:
case GUI_9SLICE_EMPTY_CAPPED:
GUIFontDrawIcon(font, x , y , GUI_ALIGN_LEFT | GUI_ALIGN_TOP , GUI_ORIENT_0, color, GUI_ICON_9SLICE_EMPTY_NW);
GUIFontDrawIcon(font, x + width, y , GUI_ALIGN_RIGHT | GUI_ALIGN_TOP , GUI_ORIENT_0, color, GUI_ICON_9SLICE_EMPTY_NE);
GUIFontDrawIcon(font, x , y + height, GUI_ALIGN_LEFT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_EMPTY_SW);
GUIFontDrawIcon(font, x + width, y + height, GUI_ALIGN_RIGHT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_EMPTY_SE);
break;
case GUI_9SLICE_FILLED:
GUIFontDrawIcon(font, x , y , GUI_ALIGN_LEFT | GUI_ALIGN_TOP , GUI_ORIENT_0, color, GUI_ICON_9SLICE_FILLED_NW);
GUIFontDrawIcon(font, x + width, y , GUI_ALIGN_RIGHT | GUI_ALIGN_TOP , GUI_ORIENT_0, color, GUI_ICON_9SLICE_FILLED_NE);
GUIFontDrawIcon(font, x , y + height, GUI_ALIGN_LEFT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_FILLED_SW);
GUIFontDrawIcon(font, x + width, y + height, GUI_ALIGN_RIGHT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_FILLED_SE);
break;
}
unsigned offX, offY;
unsigned endX, endY;
GUIFontIconMetrics(font, GUI_ICON_9SLICE_EMPTY_NW, &offX, &offY);
GUIFontIconMetrics(font, GUI_ICON_9SLICE_EMPTY_SE, &endX, &endY);
switch (style) {
case GUI_9SLICE_EMPTY:
GUIFontDrawIconSize(font, x + offX, y, width - offX - endX, offY, color, GUI_ICON_9SLICE_EMPTY_N);
GUIFontDrawIconSize(font, x, y + offY, offX, height - offY - endY, color, GUI_ICON_9SLICE_EMPTY_W);
GUIFontDrawIconSize(font, x + offX, y + height - endY, width - offX - endX, offY, color, GUI_ICON_9SLICE_EMPTY_S);
GUIFontDrawIconSize(font, x + width - endX, y + offY, offX, height - offY - endY, color, GUI_ICON_9SLICE_EMPTY_E);
break;
case GUI_9SLICE_FILLED:
GUIFontDrawIconSize(font, x + offX, y, width - offX - endX, offY, color, GUI_ICON_9SLICE_FILLED_N);
GUIFontDrawIconSize(font, x, y + offY, offX, height - offY - endY, color, GUI_ICON_9SLICE_FILLED_W);
GUIFontDrawIconSize(font, x + offX, y + height - endY, width - offX - endX, offY, color, GUI_ICON_9SLICE_FILLED_S);
GUIFontDrawIconSize(font, x + width - endX, y + offY, offX, height - offY - endY, color, GUI_ICON_9SLICE_FILLED_E);
GUIFontDrawIconSize(font, x + offX, y + offY, width - offX - endX, height - offY - endY, color, GUI_ICON_9SLICE_FILLED_C);
break;
case GUI_9SLICE_EMPTY_CAPPED:
GUIFontDrawIcon(font, x + offX, y, GUI_ALIGN_LEFT | GUI_ALIGN_TOP, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_NNW);
GUIFontDrawIcon(font, x, y + offY, GUI_ALIGN_LEFT | GUI_ALIGN_TOP, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_NWW);
GUIFontDrawIcon(font, x + width - endX, y, GUI_ALIGN_RIGHT | GUI_ALIGN_TOP, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_NNE);
GUIFontDrawIcon(font, x + width, y + offY, GUI_ALIGN_RIGHT | GUI_ALIGN_TOP, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_NEE);
GUIFontDrawIcon(font, x + offX, y + height, GUI_ALIGN_LEFT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_SSW);
GUIFontDrawIcon(font, x, y + height - endY, GUI_ALIGN_LEFT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_SWW);
GUIFontDrawIcon(font, x + width - endX, y + height, GUI_ALIGN_RIGHT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_SSE);
GUIFontDrawIcon(font, x + width, y + height - endY, GUI_ALIGN_RIGHT | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, GUI_ICON_9SLICE_CAP_SEE);
break;
}
}