Changeset 47728678 in mainline for uspace/lib/ui/src/pbutton.c
- Timestamp:
- 2020-10-13T09:24:56Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f6df5a3
- Parents:
- f80690a
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-12 21:24:39)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-13 09:24:56)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/pbutton.c
rf80690a r47728678 35 35 36 36 #include <errno.h> 37 #include <gfx/color.h> 38 #include <gfx/context.h> 39 #include <gfx/render.h> 40 #include <gfx/text.h> 37 41 #include <stdlib.h> 42 #include <str.h> 38 43 #include <ui/pbutton.h> 39 44 #include "../private/pbutton.h" 45 #include "../private/resource.h" 40 46 41 47 /** Create new push button. 42 48 * 49 * @param resource UI resource 43 50 * @param caption Caption 44 51 * @param rpbutton Place to store pointer to new push button 45 52 * @return EOK on success, ENOMEM if out of memory 46 53 */ 47 errno_t ui_pbutton_create(const char *caption, ui_pbutton_t **rpbutton) 54 errno_t ui_pbutton_create(ui_resource_t *resource, const char *caption, 55 ui_pbutton_t **rpbutton) 48 56 { 49 57 ui_pbutton_t *pbutton; … … 53 61 return ENOMEM; 54 62 55 (void) caption; 63 pbutton->caption = str_dup(caption); 64 if (pbutton->caption == NULL) { 65 free(pbutton); 66 return ENOMEM; 67 } 68 69 pbutton->res = resource; 56 70 *rpbutton = pbutton; 57 71 return EOK; … … 70 84 } 71 85 86 /** Set button rectangle. 87 * 88 * @param pbutton Button 89 * @param rect New button rectanle 90 */ 91 void ui_pbutton_set_rect(ui_pbutton_t *pbutton, gfx_rect_t *rect) 92 { 93 pbutton->rect = *rect; 94 } 95 96 /** Paint push button. 97 * 98 * @param pbutton Push button 99 * @return EOK on success or an error code 100 */ 101 errno_t ui_pbutton_paint(ui_pbutton_t *pbutton) 102 { 103 gfx_color_t *color = NULL; 104 gfx_coord2_t pos; 105 gfx_text_fmt_t fmt; 106 errno_t rc; 107 108 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color); 109 if (rc != EOK) 110 goto error; 111 112 rc = gfx_set_color(pbutton->res->gc, color); 113 if (rc != EOK) 114 goto error; 115 116 rc = gfx_fill_rect(pbutton->res->gc, &pbutton->rect); 117 if (rc != EOK) 118 goto error; 119 120 gfx_color_delete(color); 121 122 rc = gfx_color_new_rgb_i16(0, 0, 0, &color); 123 if (rc != EOK) 124 goto error; 125 126 rc = gfx_set_color(pbutton->res->gc, color); 127 if (rc != EOK) 128 goto error; 129 130 /* Center of button rectangle */ 131 pos.x = (pbutton->rect.p0.x + pbutton->rect.p1.x) / 2; 132 pos.y = (pbutton->rect.p0.y + pbutton->rect.p1.y) / 2; 133 134 gfx_text_fmt_init(&fmt); 135 fmt.halign = gfx_halign_center; 136 fmt.valign = gfx_valign_center; 137 138 rc = gfx_puttext(pbutton->res->font, &pos, &fmt, pbutton->caption); 139 if (rc != EOK) 140 goto error; 141 142 gfx_color_delete(color); 143 144 return EOK; 145 error: 146 if (color != NULL) 147 gfx_color_delete(color); 148 return rc; 149 } 150 72 151 /** @} 73 152 */
Note:
See TracChangeset
for help on using the changeset viewer.