1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** GUIX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** Button Management (Button) */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
|
21 |
|
|
#define GX_SOURCE_CODE |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#include "gx_api.h" |
27 |
|
|
#include "gx_system.h" |
28 |
|
|
#include "gx_canvas.h" |
29 |
|
|
#include "gx_context.h" |
30 |
|
|
#include "gx_widget.h" |
31 |
|
|
#include "gx_button.h" |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
/**************************************************************************/ |
35 |
|
|
/* */ |
36 |
|
|
/* FUNCTION RELEASE */ |
37 |
|
|
/* */ |
38 |
|
|
/* _gx_pixelmap_button_draw PORTABLE C */ |
39 |
|
|
/* 6.1 */ |
40 |
|
|
/* AUTHOR */ |
41 |
|
|
/* */ |
42 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
43 |
|
|
/* */ |
44 |
|
|
/* DESCRIPTION */ |
45 |
|
|
/* */ |
46 |
|
|
/* This function draws the specified button, which is a special type */ |
47 |
|
|
/* of widget. */ |
48 |
|
|
/* */ |
49 |
|
|
/* INPUT */ |
50 |
|
|
/* */ |
51 |
|
|
/* button Button control block */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* None */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _gx_context_pixelmap_get Retrieve pixelmap image */ |
60 |
|
|
/* _gx_canvas_pixelmap_draw Draw the pixelmap */ |
61 |
|
|
/* _gx_button_draw Draw the button */ |
62 |
|
|
/* _gx_widget_children_draw Draw children widgets */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* Application Code */ |
67 |
|
|
/* GUIX Internal Code */ |
68 |
|
|
/* */ |
69 |
|
|
/* RELEASE HISTORY */ |
70 |
|
|
/* */ |
71 |
|
|
/* DATE NAME DESCRIPTION */ |
72 |
|
|
/* */ |
73 |
|
|
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */ |
74 |
|
|
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */ |
75 |
|
|
/* resulting in version 6.1 */ |
76 |
|
|
/* */ |
77 |
|
|
/**************************************************************************/ |
78 |
|
8543 |
VOID _gx_pixelmap_button_draw(GX_PIXELMAP_BUTTON *button) |
79 |
|
|
{ |
80 |
|
|
GX_RESOURCE_ID pixelmap; |
81 |
|
|
GX_PIXELMAP *map; |
82 |
|
8543 |
GX_WIDGET *widget = (GX_WIDGET *)button; |
83 |
|
|
INT xpos; |
84 |
|
|
INT ypos; |
85 |
|
|
|
86 |
|
|
|
87 |
|
|
/* default to using the normal pixlemap */ |
88 |
|
8543 |
pixelmap = button -> gx_pixelmap_button_normal_id; |
89 |
|
|
|
90 |
|
|
/* If the button is not enabled and the user provided |
91 |
|
|
a disabled pixelmap, use that */ |
92 |
✓✓ |
8543 |
if (button -> gx_pixelmap_button_disabled_id && |
93 |
✓✓ |
1187 |
!(button -> gx_widget_style & GX_STYLE_ENABLED)) |
94 |
|
|
{ |
95 |
|
65 |
pixelmap = button -> gx_pixelmap_button_disabled_id; |
96 |
|
|
} |
97 |
|
|
else |
98 |
|
|
{ |
99 |
|
|
/* otherwise, if the button is pushed used the selected pixelmap */ |
100 |
✓✓ |
8478 |
if (button -> gx_widget_style & GX_STYLE_BUTTON_PUSHED) |
101 |
|
|
{ |
102 |
✓✓ |
132 |
if (button -> gx_pixelmap_button_selected_id) |
103 |
|
|
{ |
104 |
|
115 |
pixelmap = button -> gx_pixelmap_button_selected_id; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
|
109 |
✓✓ |
8543 |
if (!(button -> gx_widget_style & GX_STYLE_ENABLED)) |
110 |
|
|
{ |
111 |
✓✓ |
68 |
if (button -> gx_pixelmap_button_disabled_id) |
112 |
|
|
{ |
113 |
|
65 |
pixelmap = button -> gx_pixelmap_button_disabled_id; |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
|
117 |
|
8543 |
_gx_context_pixelmap_get(pixelmap, &map); |
118 |
|
|
|
119 |
✓✓ |
8543 |
if (map) |
120 |
|
|
{ |
121 |
✓✓✓ |
8515 |
switch (button -> gx_widget_style & GX_PIXELMAP_HALIGN_MASK) |
122 |
|
|
{ |
123 |
|
1817 |
case GX_STYLE_HALIGN_CENTER: |
124 |
|
1817 |
xpos = button -> gx_widget_size.gx_rectangle_right - |
125 |
|
1817 |
button -> gx_widget_size.gx_rectangle_left - |
126 |
|
1817 |
map -> gx_pixelmap_width + 1; |
127 |
|
|
|
128 |
|
1817 |
xpos /= 2; |
129 |
|
1817 |
xpos += button -> gx_widget_size.gx_rectangle_left; |
130 |
|
1817 |
break; |
131 |
|
|
|
132 |
|
2 |
case GX_STYLE_HALIGN_RIGHT: |
133 |
|
2 |
xpos = button -> gx_widget_size.gx_rectangle_right - map -> gx_pixelmap_width + 1; |
134 |
|
2 |
break; |
135 |
|
|
|
136 |
|
6696 |
default: |
137 |
|
6696 |
xpos = button -> gx_widget_size.gx_rectangle_left; |
138 |
|
6696 |
break; |
139 |
|
|
} |
140 |
|
|
|
141 |
✓✓✓ |
8515 |
switch (button -> gx_widget_style & GX_PIXELMAP_VALIGN_MASK) |
142 |
|
|
{ |
143 |
|
1826 |
case GX_STYLE_VALIGN_CENTER: |
144 |
|
1826 |
ypos = button -> gx_widget_size.gx_rectangle_bottom - |
145 |
|
1826 |
button -> gx_widget_size.gx_rectangle_top - |
146 |
|
1826 |
map -> gx_pixelmap_height + 1; |
147 |
|
|
|
148 |
|
1826 |
ypos /= 2; |
149 |
|
1826 |
ypos += button -> gx_widget_size.gx_rectangle_top; |
150 |
|
1826 |
break; |
151 |
|
|
|
152 |
|
2 |
case GX_STYLE_VALIGN_BOTTOM: |
153 |
|
2 |
ypos = button -> gx_widget_size.gx_rectangle_bottom - map -> gx_pixelmap_height + 1; |
154 |
|
2 |
break; |
155 |
|
|
|
156 |
|
6687 |
default: |
157 |
|
6687 |
ypos = button -> gx_widget_size.gx_rectangle_top; |
158 |
|
6687 |
break; |
159 |
|
|
} |
160 |
|
8515 |
_gx_widget_context_fill_set(widget); |
161 |
|
8515 |
_gx_canvas_pixelmap_draw((GX_VALUE)xpos, (GX_VALUE)ypos, map); |
162 |
|
|
} |
163 |
|
|
else |
164 |
|
|
{ |
165 |
|
|
/* If I don't have a pixelmap and not transparent, |
166 |
|
|
draw something |
167 |
|
|
*/ |
168 |
✓✓ |
28 |
if (!(widget -> gx_widget_style & GX_STYLE_TRANSPARENT)) |
169 |
|
|
{ |
170 |
|
23 |
_gx_button_draw((GX_BUTTON *)button); |
171 |
|
|
} |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
/* Draw button's children. */ |
175 |
|
8543 |
_gx_widget_children_draw(widget); |
176 |
|
8543 |
} |
177 |
|
|
|