MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / GUI_Widget_SpriteButton_Draw

Function GUI_Widget_SpriteButton_Draw

src/gui/widget_draw.c:76–129  ·  view source on GitHub ↗

* Draw a sprite button widget to the display, relative to 0,0. * * @param w The widget (which is a button) to draw. */

Source from the content-addressed store, hash-verified

74 * @param w The widget (which is a button) to draw.
75 */
76void GUI_Widget_SpriteButton_Draw(Widget *w)
77{
78 Screen oldScreenID;
79 uint16 positionX, positionY;
80 uint16 width, height;
81 uint16 spriteID;
82 bool buttonDown;
83
84 if (w == NULL) return;
85
86 spriteID = 0;
87 if (g_unitSelected != NULL) {
88 const UnitInfo *ui;
89
90 ui = &g_table_unitInfo[g_unitSelected->o.type];
91
92 spriteID = ui->o.spriteID;
93 } else {
94 const StructureInfo *si;
95 Structure *s;
96
97 s = Structure_Get_ByPackedTile(g_selectionPosition);
98 if (s == NULL) return;
99 si = &g_table_structureInfo[s->o.type];
100
101 spriteID = si->o.spriteID;
102 }
103
104 oldScreenID = SCREEN_ACTIVE;
105 if (GFX_Screen_IsActive(SCREEN_0)) {
106 oldScreenID = GFX_Screen_SetActive(SCREEN_1);
107 }
108
109 buttonDown = w->state.hover2;
110
111 positionX = w->offsetX;
112 positionY = w->offsetY;
113 width = w->width;
114 height = w->height;
115
116 GUI_DrawWiredRectangle(positionX - 1, positionY - 1, positionX + width, positionY + height, 12);
117
118 GUI_DrawSprite(SCREEN_ACTIVE, g_sprites[spriteID], positionX, positionY, 0, DRAWSPRITE_FLAG_REMAP, g_paletteMapping1, buttonDown ? 1 : 0);
119
120 GUI_DrawBorder(positionX, positionY, width, height, buttonDown ? 0 : 1, false);
121
122 if (oldScreenID != SCREEN_0) return;
123
124 GUI_Mouse_Hide_InRegion(positionX - 1, positionY - 1, positionX + width + 1, positionY + height + 1);
125 GFX_Screen_Copy2(positionX - 1, positionY - 1, positionX - 1, positionY - 1, width + 2, height + 2, SCREEN_1, SCREEN_0, false);
126 GUI_Mouse_Show_InRegion();
127
128 GFX_Screen_SetActive(SCREEN_0);
129}
130
131/**
132 * Draw a sprite/text button widget to the display, relative to 0,0.

Callers

nothing calls this directly

Calls 9

GFX_Screen_IsActiveFunction · 0.85
GFX_Screen_SetActiveFunction · 0.85
GUI_DrawWiredRectangleFunction · 0.85
GUI_DrawSpriteFunction · 0.85
GUI_DrawBorderFunction · 0.85
GUI_Mouse_Hide_InRegionFunction · 0.85
GFX_Screen_Copy2Function · 0.85
GUI_Mouse_Show_InRegionFunction · 0.85

Tested by

no test coverage detected