Changeset be869b0 in mainline
- Timestamp:
- 2021-09-23T08:24:23Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e2ca44f
- Parents:
- f2d6d44e
- git-author:
- Jiri Svoboda <jiri@…> (2021-09-22 17:24:15)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-09-23 08:24:23)
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
rf2d6d44e rbe869b0 40 40 #include <errno.h> 41 41 #include <gfx/color.h> 42 #include <gfx/font.h> 42 43 #include <gfx/render.h> 44 #include <gfx/text.h> 43 45 #include <io/kbd_event.h> 44 46 #include <io/keycode.h> … … 56 58 #include <ui/menubar.h> 57 59 #include <ui/menuentry.h> 60 #include <ui/resource.h> 58 61 #include <ui/ui.h> 59 62 #include <ui/window.h> … … 73 76 * 74 77 * A rectangular area of the screen used to edit a document. Different 75 * panes can be possibly used to edit the same document. 78 * panes can be possibly used to edit the same document. This is a custom 79 * UI control. 76 80 */ 77 81 typedef struct { … … 87 91 /** Pane rectangle */ 88 92 gfx_rect_t rect; 93 94 /** Pane color */ 95 gfx_color_t *color; 89 96 90 97 /* Pane dimensions */ … … 178 185 static void pane_fini(pane_t *); 179 186 static ui_control_t *pane_ctl(pane_t *); 180 static void pane_text_display(void);187 static errno_t pane_text_display(pane_t *); 181 188 static void pane_row_display(void); 182 static void pane_row_range_display(int r0, int r1);189 static errno_t pane_row_range_display(pane_t *, int r0, int r1); 183 190 static void pane_status_display(void); 184 191 static void pane_caret_display(void); … … 315 322 cursor_hide(); 316 323 // console_clear(con); 317 pane_text_display( );324 pane_text_display(&pane); 318 325 pane_status_display(); 319 326 if (new_file && doc.file_name != NULL) … … 347 354 348 355 if (pane.rflags & REDRAW_TEXT) 349 pane_text_display( );356 pane_text_display(&pane); 350 357 if (pane.rflags & REDRAW_ROW) 351 358 pane_row_display(); … … 498 505 static void edit_ui_destroy(edit_t *edit) 499 506 { 500 pane_fini(&pane);501 507 ui_window_destroy(edit->window); 502 508 ui_destroy(edit->ui); … … 978 984 return rc; 979 985 986 rc = gfx_color_new_ega(0x07, &pane->color); 987 if (rc != EOK) { 988 ui_control_delete(pane->control); 989 return rc; 990 } 991 980 992 pane->res = ui_window_get_res(window); 981 993 pane->window = window; … … 987 999 pane->rect.p1.y = arect.p1.y - 1; 988 1000 1001 pane->columns = pane->rect.p1.x - pane->rect.p0.x; 1002 pane->rows = pane->rect.p1.y - pane->rect.p0.y; 1003 989 1004 return EOK; 990 1005 } … … 998 1013 static void pane_fini(pane_t *pane) 999 1014 { 1015 gfx_color_delete(pane->color); 1016 pane->color = NULL; 1000 1017 ui_control_delete(pane->control); 1001 1018 pane->control = NULL; … … 1012 1029 } 1013 1030 1014 static void pane_text_display(void) 1015 { 1031 /** Display pane text. 1032 * 1033 * @param pane Pane 1034 * @return EOK on success or an error code 1035 */ 1036 static errno_t pane_text_display(pane_t *pane) 1037 { 1038 gfx_rect_t rect; 1039 gfx_context_t *gc; 1040 errno_t rc; 1016 1041 int sh_rows, rows; 1017 1042 1018 1043 sheet_get_num_rows(doc.sh, &sh_rows); 1019 rows = min(sh_rows - pane .sh_row + 1, pane.rows);1044 rows = min(sh_rows - pane->sh_row + 1, pane->rows); 1020 1045 1021 1046 /* Draw rows from the sheet. */ 1022 1047 1023 // console_set_pos(con, 0, 0); 1024 pane_row_range_display(0, rows); 1048 rc = pane_row_range_display(pane, 0, rows); 1049 if (rc != EOK) 1050 return rc; 1025 1051 1026 1052 /* Clear the remaining rows if file is short. */ 1027 1053 1028 int i; 1029 sysarg_t j; 1030 for (i = rows; i < pane.rows; ++i) { 1031 // console_set_pos(con, 0, i); 1032 for (j = 0; j < scr_columns; ++j) 1033 putchar(' '); 1034 // console_flush(con); 1035 } 1036 1037 pane.rflags |= (REDRAW_STATUS | REDRAW_CARET); 1038 pane.rflags &= ~REDRAW_ROW; 1054 gc = ui_window_get_gc(pane->window); 1055 1056 rc = gfx_set_color(gc, pane->color); 1057 if (rc != EOK) 1058 goto error; 1059 1060 rect.p0.x = pane->rect.p0.x; 1061 rect.p0.y = pane->rect.p0.y + rows; 1062 rect.p1.x = pane->rect.p1.x; 1063 rect.p1.y = pane->rect.p1.y; 1064 1065 rc = gfx_fill_rect(gc, &rect); 1066 if (rc != EOK) 1067 goto error; 1068 1069 pane->rflags &= ~REDRAW_ROW; 1070 return EOK; 1071 error: 1072 return rc; 1039 1073 } 1040 1074 … … 1050 1084 1051 1085 ridx = coord.row - pane.sh_row; 1052 pane_row_range_display(ridx, ridx + 1);1086 (void) pane_row_range_display(&pane, ridx, ridx + 1); 1053 1087 pane.rflags |= (REDRAW_STATUS | REDRAW_CARET); 1054 1088 } 1055 1089 1056 static void pane_row_range_display(int r0, int r1) 1057 { 1058 int i, j, fill; 1090 /** Display a range of rows of text. 1091 * 1092 * @param r0 Start row (inclusive) 1093 * @param r1 End row (exclusive) 1094 * @return EOk on success or an error code 1095 */ 1096 static errno_t pane_row_range_display(pane_t *pane, int r0, int r1) 1097 { 1098 int i, fill; 1059 1099 spt_t rb, re, dep, pt; 1060 1100 coord_t rbc, rec; 1061 1101 char row_buf[ROW_BUF_SIZE]; 1102 char cbuf[STR_BOUNDS(1) + 1]; 1062 1103 char32_t c; 1063 1104 size_t pos, size; 1105 size_t cpos; 1064 1106 int s_column; 1065 1107 coord_t csel_start, csel_end, ctmp; 1108 gfx_font_t *font; 1109 gfx_context_t *gc; 1110 gfx_text_fmt_t fmt; 1111 gfx_coord2_t tpos; 1112 gfx_rect_t rect; 1113 errno_t rc; 1114 1115 font = ui_resource_get_font(edit.ui_res); 1116 gc = ui_window_get_gc(edit.window); 1117 1118 gfx_text_fmt_init(&fmt); 1119 fmt.color = pane->color; 1066 1120 1067 1121 /* Determine selection start and end. */ 1068 1122 1069 tag_get_pt(&pane .sel_start, &pt);1123 tag_get_pt(&pane->sel_start, &pt); 1070 1124 spt_get_coord(&pt, &csel_start); 1071 1125 1072 tag_get_pt(&pane .caret_pos, &pt);1126 tag_get_pt(&pane->caret_pos, &pt); 1073 1127 spt_get_coord(&pt, &csel_end); 1074 1128 … … 1083 1137 // console_set_pos(con, 0, 0); 1084 1138 for (i = r0; i < r1; ++i) { 1139 tpos.x = pane->rect.p0.x; 1140 tpos.y = pane->rect.p0.y + i; 1141 1085 1142 /* Starting point for row display */ 1086 rbc.row = pane .sh_row + i;1087 rbc.column = pane .sh_column;1143 rbc.row = pane->sh_row + i; 1144 rbc.column = pane->sh_column; 1088 1145 sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb); 1089 1146 1090 1147 /* Ending point for row display */ 1091 rec.row = pane .sh_row + i;1092 rec.column = pane .sh_column + pane.columns;1148 rec.row = pane->sh_row + i; 1149 rec.column = pane->sh_column + pane->columns; 1093 1150 sheet_get_cell_pt(doc.sh, &rec, dir_before, &re); 1094 1151 … … 1108 1165 size = str_size(row_buf); 1109 1166 pos = 0; 1110 s_column = pane .sh_column;1167 s_column = pane->sh_column; 1111 1168 while (pos < size) { 1112 1169 if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) { … … 1124 1181 c = str_decode(row_buf, &pos, size); 1125 1182 if (c != '\t') { 1126 printf("%lc", (wint_t) c); 1183 cpos = 0; 1184 rc = chr_encode(c, cbuf, &cpos, sizeof(cbuf)); 1185 if (rc != EOK) 1186 return rc; 1187 1188 rc = gfx_puttext(font, &tpos, &fmt, cbuf); 1189 if (rc != EOK) 1190 return rc; 1191 1127 1192 s_column += 1; 1193 tpos.x++; 1128 1194 } else { 1129 1195 fill = 1 + ALIGN_UP(s_column, TAB_WIDTH) - 1130 1196 s_column; 1131 1197 1132 for (j = 0; j < fill; ++j) 1133 putchar(' '); 1198 rc = gfx_set_color(gc, fmt.color); 1199 if (rc != EOK) 1200 return rc; 1201 1202 rect.p0.x = tpos.x; 1203 rect.p0.y = tpos.y; 1204 rect.p1.x = tpos.x + fill; 1205 rect.p1.y = tpos.y + 1; 1206 1207 rc = gfx_fill_rect(gc, &rect); 1208 if (rc != EOK) 1209 return rc; 1210 1134 1211 s_column += fill; 1212 tpos.x += fill; 1135 1213 } 1136 1214 } … … 1144 1222 /* Fill until the end of display area. */ 1145 1223 1146 if ((unsigned)s_column - 1 < scr_columns) 1147 fill = scr_columns - (s_column - 1); 1148 else 1149 fill = 0; 1150 1151 for (j = 0; j < fill; ++j) 1152 putchar(' '); 1153 // console_flush(con); 1154 // console_set_style(con, STYLE_NORMAL); 1155 } 1156 1157 pane.rflags |= REDRAW_CARET; 1224 rc = gfx_set_color(gc, fmt.color); 1225 if (rc != EOK) 1226 return rc; 1227 1228 rect.p0.x = tpos.x; 1229 rect.p0.y = tpos.y; 1230 rect.p1.x = pane->rect.p1.x; 1231 rect.p1.y = tpos.y + 1; 1232 1233 rc = gfx_fill_rect(gc, &rect); 1234 if (rc != EOK) 1235 return rc; 1236 } 1237 1238 return EOK; 1158 1239 } 1159 1240 … … 1282 1363 { 1283 1364 pane_t *pane = (pane_t *)arg; 1284 gfx_color_t *color = NULL;1285 1365 gfx_context_t *gc; 1286 1366 errno_t rc; … … 1288 1368 gc = ui_window_get_gc(pane->window); 1289 1369 1290 rc = gfx_color_new_ega(0x01, &color); 1291 if (rc != EOK) 1292 goto error; 1293 1294 rc = gfx_set_color(gc, color); 1295 if (rc != EOK) 1296 goto error; 1297 1298 rc = gfx_fill_rect(gc, &pane->rect); 1370 rc = pane_text_display(pane); 1299 1371 if (rc != EOK) 1300 1372 goto error; … … 1304 1376 goto error; 1305 1377 1306 gfx_color_delete(color);1307 return EOK;1308 1378 error: 1309 if (color != NULL)1310 gfx_color_delete(color);1311 1379 return rc; 1312 1380 } -
uspace/lib/ui/include/ui/resource.h
rf2d6d44e rbe869b0 39 39 #include <errno.h> 40 40 #include <gfx/context.h> 41 #include <gfx/font.h> 41 42 #include <stdbool.h> 42 43 #include <types/ui/resource.h> … … 47 48 void *); 48 49 extern void ui_resource_expose(ui_resource_t *); 50 extern gfx_font_t *ui_resource_get_font(ui_resource_t *); 49 51 50 52 #endif -
uspace/lib/ui/src/resource.c
rf2d6d44e rbe869b0 594 594 } 595 595 596 /** Get the UI font. 597 * 598 * @param resource UI resource 599 * @return UI font 600 */ 601 gfx_font_t *ui_resource_get_font(ui_resource_t *resource) 602 { 603 return resource->font; 604 } 605 596 606 /** @} 597 607 */
Note:
See TracChangeset
for help on using the changeset viewer.