Changeset 0e5ed803 in mainline for uspace/app/nav/panel.c
- Timestamp:
- 2021-10-04T20:39:24Z (3 years ago)
- Children:
- 3b67e95
- Parents:
- 68b9e540
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/panel.c
r68b9e540 r0e5ed803 36 36 37 37 #include <errno.h> 38 #include <gfx/render.h> 38 39 #include <stdlib.h> 40 #include <ui/control.h> 41 #include <ui/paint.h> 39 42 #include "panel.h" 40 43 #include "nav.h" 41 44 45 static void panel_ctl_destroy(void *); 46 static errno_t panel_ctl_paint(void *); 47 static ui_evclaim_t panel_ctl_pos_event(void *, pos_event_t *); 48 49 /** Panel control ops */ 50 ui_control_ops_t panel_ctl_ops = { 51 .destroy = panel_ctl_destroy, 52 .paint = panel_ctl_paint, 53 .pos_event = panel_ctl_pos_event 54 }; 55 42 56 /** Create panel. 43 57 * 58 * @param window Containing window 44 59 * @param rpanel Place to store pointer to new panel 45 60 * @return EOK on success or an error code 46 61 */ 47 errno_t panel_create( panel_t **rpanel)62 errno_t panel_create(ui_window_t *window, panel_t **rpanel) 48 63 { 49 64 panel_t *panel; 65 errno_t rc; 50 66 51 67 panel = calloc(1, sizeof(panel_t)); … … 53 69 return ENOMEM; 54 70 71 rc = ui_control_new(&panel_ctl_ops, (void *)panel, 72 &panel->control); 73 if (rc != EOK) { 74 free(panel); 75 return rc; 76 } 77 78 rc = gfx_color_new_ega(0x07, &panel->color); 79 if (rc != EOK) 80 goto error; 81 82 panel->window = window; 55 83 *rpanel = panel; 56 84 return EOK; 85 error: 86 ui_control_delete(panel->control); 87 free(panel); 88 return rc; 57 89 } 58 90 … … 63 95 void panel_destroy(panel_t *panel) 64 96 { 97 ui_control_delete(panel->control); 65 98 free(panel); 66 99 } 67 100 101 /** Paint panel. 102 * 103 * @param panel Panel 104 */ 105 errno_t panel_paint(panel_t *panel) 106 { 107 gfx_context_t *gc = ui_window_get_gc(panel->window); 108 ui_resource_t *res = ui_window_get_res(panel->window); 109 errno_t rc; 110 111 rc = gfx_set_color(gc, panel->color); 112 if (rc != EOK) 113 return rc; 114 115 rc = gfx_fill_rect(gc, &panel->rect); 116 if (rc != EOK) 117 return rc; 118 119 rc = ui_paint_text_box(res, &panel->rect, ui_box_single, 120 panel->color); 121 if (rc != EOK) 122 return rc; 123 124 rc = gfx_update(gc); 125 if (rc != EOK) 126 return rc; 127 128 return EOK; 129 } 130 131 /** Handle panel position event. 132 * 133 * @param panel Panel 134 * @param event Position event 135 * @return ui_claimed iff event was claimed 136 */ 137 ui_evclaim_t panel_pos_event(panel_t *panel, pos_event_t *event) 138 { 139 return ui_unclaimed; 140 } 141 142 /** Get base control for panel. 143 * 144 * @param panel Panel 145 * @return Base UI control 146 */ 147 ui_control_t *panel_ctl(panel_t *panel) 148 { 149 return panel->control; 150 } 151 152 /** Set panel rectangle. 153 * 154 * @param panel Panel 155 * @param rect Rectangle 156 */ 157 void panel_set_rect(panel_t *panel, gfx_rect_t *rect) 158 { 159 panel->rect = *rect; 160 } 161 162 /** Destroy panel control. 163 * 164 * @param arg Argument (panel_t *) 165 */ 166 void panel_ctl_destroy(void *arg) 167 { 168 panel_t *panel = (panel_t *) arg; 169 170 panel_destroy(panel); 171 } 172 173 /** Paint panel control. 174 * 175 * @param arg Argument (panel_t *) 176 * @return EOK on success or an error code 177 */ 178 errno_t panel_ctl_paint(void *arg) 179 { 180 panel_t *panel = (panel_t *) arg; 181 182 return panel_paint(panel); 183 } 184 185 /** Handle panel control position event. 186 * 187 * @param arg Argument (panel_t *) 188 * @param pos_event Position event 189 * @return @c ui_claimed iff the event is claimed 190 */ 191 ui_evclaim_t panel_ctl_pos_event(void *arg, pos_event_t *event) 192 { 193 panel_t *panel = (panel_t *) arg; 194 195 return panel_pos_event(panel, event); 196 } 197 198 68 199 /** @} 69 200 */
Note:
See TracChangeset
for help on using the changeset viewer.