Changeset de9992c in mainline
- Timestamp:
- 2020-10-16T23:34:55Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1769693
- Parents:
- 8ef48ece
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-16 23:31:37)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-16 23:34:55)
- Location:
- uspace/lib/ui
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/meson.build
r8ef48ece rde9992c 29 29 deps = [ 'gfx', 'gfxfont' ] 30 30 src = files( 31 'src/paint.c', 31 32 'src/pbutton.c', 32 33 'src/resource.c', … … 35 36 test_src = files( 36 37 'test/main.c', 38 'test/paint.c', 37 39 'test/pbutton.c', 38 40 'test/resource.c', -
uspace/lib/ui/private/resource.h
r8ef48ece rde9992c 38 38 #define _UI_PRIVATE_RESOURCE_H 39 39 40 #include <gfx/color.h> 40 41 #include <gfx/context.h> 41 42 #include <gfx/font.h> … … 53 54 /** Font */ 54 55 gfx_font_t *font; 56 57 /** Button frame color */ 58 gfx_color_t *btn_frame_color; 59 /** Button face color */ 60 gfx_color_t *btn_face_color; 61 /** Button text color */ 62 gfx_color_t *btn_text_color; 63 /** Button highlight color */ 64 gfx_color_t *btn_highlight_color; 65 /** Button shadow color */ 66 gfx_color_t *btn_shadow_color; 55 67 }; 56 68 -
uspace/lib/ui/src/pbutton.c
r8ef48ece rde9992c 42 42 #include <stdlib.h> 43 43 #include <str.h> 44 #include <ui/paint.h> 44 45 #include <ui/pbutton.h> 45 46 #include "../private/pbutton.h" … … 133 134 static errno_t ui_pbutton_paint_frame(ui_pbutton_t *pbutton) 134 135 { 135 gfx_color_t *color = NULL;136 136 gfx_rect_t rect; 137 137 gfx_coord_t thickness; … … 140 140 thickness = pbutton->isdefault ? 2 : 1; 141 141 142 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 143 if (rc != EOK) 144 goto error; 145 146 rc = gfx_set_color(pbutton->res->gc, color); 142 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_frame_color); 147 143 if (rc != EOK) 148 144 goto error; … … 180 176 goto error; 181 177 182 gfx_color_delete(color);183 178 return EOK; 184 179 error: 185 if (color != NULL)186 gfx_color_delete(color);187 180 return rc; 188 181 } … … 196 189 gfx_rect_t *rect) 197 190 { 198 gfx_color_t *color = NULL; 199 gfx_rect_t frect; 200 gfx_coord_t i; 201 errno_t rc; 202 203 /* Highlight */ 204 205 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 206 if (rc != EOK) 207 goto error; 208 209 rc = gfx_set_color(pbutton->res->gc, color); 210 if (rc != EOK) 211 goto error; 212 213 for (i = 0; i < 2; i++) { 214 frect.p0.x = rect->p0.x + i; 215 frect.p0.y = rect->p0.y + i; 216 frect.p1.x = rect->p1.x - i - 1; 217 frect.p1.y = rect->p0.y + i + 1; 218 rc = gfx_fill_rect(pbutton->res->gc, &frect); 219 if (rc != EOK) 220 goto error; 221 222 frect.p0.x = rect->p0.x + i; 223 frect.p0.y = rect->p0.y + i + 1; 224 frect.p1.x = rect->p0.x + i + 1; 225 frect.p1.y = rect->p1.y - i - 1; 226 rc = gfx_fill_rect(pbutton->res->gc, &frect); 227 if (rc != EOK) 228 goto error; 229 } 230 231 gfx_color_delete(color); 232 color = NULL; 233 234 /* Shadow */ 235 236 rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &color); 237 if (rc != EOK) 238 goto error; 239 240 rc = gfx_set_color(pbutton->res->gc, color); 241 if (rc != EOK) 242 goto error; 243 244 for (i = 0; i < 2; i++) { 245 frect.p0.x = rect->p0.x + i; 246 frect.p0.y = rect->p1.y - i - 1; 247 frect.p1.x = rect->p1.x - i - 1; 248 frect.p1.y = rect->p1.y - i; 249 rc = gfx_fill_rect(pbutton->res->gc, &frect); 250 if (rc != EOK) 251 goto error; 252 253 frect.p0.x = rect->p1.x - i - 1; 254 frect.p0.y = rect->p0.y + i; 255 frect.p1.x = rect->p1.x - i; 256 frect.p1.y = rect->p1.y - i; 257 rc = gfx_fill_rect(pbutton->res->gc, &frect); 258 if (rc != EOK) 259 goto error; 260 } 261 262 gfx_color_delete(color); 263 264 return EOK; 265 error: 266 if (color != NULL) 267 gfx_color_delete(color); 268 return rc; 191 return ui_paint_bevel(pbutton->res->gc, rect, 192 pbutton->res->btn_highlight_color, 193 pbutton->res->btn_shadow_color, 2, NULL); 269 194 } 270 195 … … 277 202 gfx_rect_t *rect) 278 203 { 279 gfx_color_t *color = NULL; 280 gfx_rect_t frect; 281 errno_t rc; 282 283 rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &color); 284 if (rc != EOK) 285 goto error; 286 287 rc = gfx_set_color(pbutton->res->gc, color); 288 if (rc != EOK) 289 goto error; 290 291 frect.p0.x = rect->p0.x; 292 frect.p0.y = rect->p0.y; 293 frect.p1.x = rect->p1.x; 294 frect.p1.y = rect->p0.y + 2; 295 rc = gfx_fill_rect(pbutton->res->gc, &frect); 296 if (rc != EOK) 297 goto error; 298 299 frect.p0.x = rect->p0.x; 300 frect.p0.y = rect->p0.y + 2; 301 frect.p1.x = rect->p0.x + 2; 302 frect.p1.y = rect->p1.y; 303 rc = gfx_fill_rect(pbutton->res->gc, &frect); 304 if (rc != EOK) 305 goto error; 306 307 gfx_color_delete(color); 308 309 return EOK; 310 error: 311 if (color != NULL) 312 gfx_color_delete(color); 313 return rc; 204 return ui_paint_bevel(pbutton->res->gc, rect, 205 pbutton->res->btn_shadow_color, 206 pbutton->res->btn_face_color, 2, NULL); 314 207 } 315 208 … … 321 214 errno_t ui_pbutton_paint(ui_pbutton_t *pbutton) 322 215 { 323 gfx_color_t *color = NULL;324 216 gfx_coord2_t pos; 325 217 gfx_text_fmt_t fmt; … … 337 229 rect.p1.y = pbutton->rect.p1.y - thickness; 338 230 339 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color); 340 if (rc != EOK) 341 goto error; 342 343 rc = gfx_set_color(pbutton->res->gc, color); 344 if (rc != EOK) 345 goto error; 346 347 rc = gfx_fill_rect(pbutton->res->gc, &rect); 348 if (rc != EOK) 349 goto error; 350 351 gfx_color_delete(color); 352 color = NULL; 353 354 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 355 if (rc != EOK) 356 goto error; 357 358 rc = gfx_set_color(pbutton->res->gc, color); 231 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_face_color); 232 if (rc != EOK) 233 goto error; 234 235 rc = gfx_fill_rect(pbutton->res->gc, &rect); 236 if (rc != EOK) 237 goto error; 238 239 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_text_color); 359 240 if (rc != EOK) 360 241 goto error; … … 376 257 if (rc != EOK) 377 258 goto error; 378 379 gfx_color_delete(color);380 color = NULL;381 259 382 260 rc = ui_pbutton_paint_frame(pbutton); … … 396 274 return EOK; 397 275 error: 398 if (color != NULL)399 gfx_color_delete(color);400 276 return rc; 401 277 } -
uspace/lib/ui/src/resource.c
r8ef48ece rde9992c 59 59 gfx_font_t *font = NULL; 60 60 gfx_font_info_t *finfo; 61 gfx_color_t *btn_frame_color = NULL; 62 gfx_color_t *btn_face_color = NULL; 63 gfx_color_t *btn_text_color = NULL; 64 gfx_color_t *btn_highlight_color = NULL; 65 gfx_color_t *btn_shadow_color = NULL; 61 66 errno_t rc; 62 67 … … 79 84 goto error; 80 85 86 rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color); 87 if (rc != EOK) 88 goto error; 89 90 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &btn_face_color); 91 if (rc != EOK) 92 goto error; 93 94 rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_text_color); 95 if (rc != EOK) 96 goto error; 97 98 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, 99 &btn_highlight_color); 100 if (rc != EOK) 101 goto error; 102 103 rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &btn_shadow_color); 104 if (rc != EOK) 105 goto error; 106 81 107 resource->gc = gc; 82 108 resource->tface = tface; 83 109 resource->font = font; 110 resource->btn_frame_color = btn_frame_color; 111 resource->btn_face_color = btn_face_color; 112 resource->btn_text_color = btn_text_color; 113 resource->btn_highlight_color = btn_highlight_color; 114 resource->btn_shadow_color = btn_shadow_color; 84 115 *rresource = resource; 85 116 return EOK; 86 117 error: 118 if (btn_frame_color != NULL) 119 gfx_color_delete(btn_frame_color); 120 if (btn_face_color != NULL) 121 gfx_color_delete(btn_face_color); 122 if (btn_text_color != NULL) 123 gfx_color_delete(btn_text_color); 124 if (btn_highlight_color != NULL) 125 gfx_color_delete(btn_highlight_color); 126 if (btn_shadow_color != NULL) 127 gfx_color_delete(btn_shadow_color); 87 128 if (tface != NULL) 88 129 gfx_typeface_destroy(tface); … … 100 141 return; 101 142 143 gfx_color_delete(resource->btn_frame_color); 144 gfx_color_delete(resource->btn_face_color); 145 gfx_color_delete(resource->btn_text_color); 146 gfx_color_delete(resource->btn_highlight_color); 147 gfx_color_delete(resource->btn_shadow_color); 148 102 149 gfx_font_close(resource->font); 103 150 gfx_typeface_destroy(resource->tface); -
uspace/lib/ui/test/main.c
r8ef48ece rde9992c 31 31 PCUT_INIT; 32 32 33 PCUT_IMPORT(paint); 33 34 PCUT_IMPORT(pbutton); 34 35 PCUT_IMPORT(resource);
Note:
See TracChangeset
for help on using the changeset viewer.