Changeset e2ca44f in mainline


Ignore:
Timestamp:
2021-09-23T22:25:46Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db52892a
Parents:
be869b0
Message:

Set cursor and update pane after handling key press

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/edit/edit.c

    rbe869b0 re2ca44f  
    4040#include <errno.h>
    4141#include <gfx/color.h>
     42#include <gfx/cursor.h>
    4243#include <gfx/font.h>
    4344#include <gfx/render.h>
     
    148149static bool done;
    149150static pane_t pane;
    150 static bool cursor_visible;
    151151
    152152static sysarg_t scr_rows;
     
    160160#define INFNAME_MAX_LEN 128
    161161
    162 static void cursor_show(void);
    163 static void cursor_hide(void);
    164162static void cursor_setvis(bool visible);
    165163
     
    185183static void pane_fini(pane_t *);
    186184static ui_control_t *pane_ctl(pane_t *);
     185static errno_t pane_update(pane_t *);
    187186static errno_t pane_text_display(pane_t *);
    188187static void pane_row_display(void);
    189188static errno_t pane_row_range_display(pane_t *, int r0, int r1);
    190189static void pane_status_display(void);
    191 static void pane_caret_display(void);
     190static void pane_caret_display(pane_t *);
    192191
    193192static void insert_char(char32_t c);
     
    313312
    314313        /* Initial display */
    315         cursor_visible = true;
    316314        rc = ui_window_paint(edit.window);
    317315        if (rc != EOK) {
     
    320318        }
    321319
    322         cursor_hide();
    323 //      console_clear(con);
    324         pane_text_display(&pane);
    325320        pane_status_display();
    326321        if (new_file && doc.file_name != NULL)
    327322                status_display("File not found. Starting empty file.");
    328         pane_caret_display();
    329         cursor_show();
    330 /*
    331         done = false;
    332 
    333         while (!done) {
    334                 rc = console_get_event(con, &ev);
    335                 if (rc != EOK)
    336                         break;
    337 
    338                 pane.rflags = 0;
    339 
    340                 switch (ev.type) {
    341                 case CEV_KEY:
    342                         pane.keymod = ev.ev.key.mods;
    343                         if (ev.ev.key.type == KEY_PRESS)
    344                                 key_handle_press(&ev.ev.key);
    345                         break;
    346                 case CEV_POS:
    347                         pos_handle(&ev.ev.pos);
    348                         break;
    349                 }
    350 
    351                 / Redraw as necessary. /
    352 
    353                 cursor_hide();
    354 
    355                 if (pane.rflags & REDRAW_TEXT)
    356                         pane_text_display(&pane);
    357                 if (pane.rflags & REDRAW_ROW)
    358                         pane_row_display();
    359                 if (pane.rflags & REDRAW_STATUS)
    360                         pane_status_display();
    361                 if (pane.rflags & REDRAW_CARET)
    362                         pane_caret_display();
    363 
    364                 cursor_show();
    365         }
    366 
    367         console_clear(con);
    368 */
     323        pane_caret_display(&pane);
     324        cursor_setvis(true);
    369325
    370326        ui_run(edit.ui);
     
    529485}
    530486
    531 static void cursor_show(void)
    532 {
    533         cursor_setvis(true);
    534 }
    535 
    536 static void cursor_hide(void)
    537 {
    538         cursor_setvis(false);
    539 }
    540 
    541487static void cursor_setvis(bool visible)
    542488{
    543         if (cursor_visible != visible) {
    544 //              console_cursor_visibility(con, visible);
    545                 cursor_visible = visible;
    546         }
     489        gfx_context_t *gc = ui_window_get_gc(edit.window);
     490
     491        (void) gfx_cursor_set_visible(gc, visible);
    547492}
    548493
     
    1028973        return pane->control;
    1029974}
     975
     976/** Repaint parts of pane that need updating.
     977 *
     978 * @param pane Pane
     979 * @return EOK on succes or an error code
     980 */
     981static errno_t pane_update(pane_t *pane)
     982{
     983        errno_t rc;
     984
     985        if (pane->rflags & REDRAW_TEXT) {
     986                rc = pane_text_display(pane);
     987                if (rc != EOK)
     988                        return rc;
     989        }
     990
     991        if (pane->rflags & REDRAW_ROW)
     992                pane_row_display();
     993
     994        if (pane->rflags & REDRAW_STATUS)
     995                pane_status_display();
     996
     997        if (pane->rflags & REDRAW_CARET)
     998                pane_caret_display(pane);
     999
     1000        return EOK;
     1001}
     1002
    10301003
    10311004/** Display pane text.
     
    13321305}
    13331306
    1334 /** Set cursor to reflect position of the caret. */
    1335 static void pane_caret_display(void)
     1307/** Set cursor to reflect position of the caret.
     1308 *
     1309 * @param pane Pane
     1310 */
     1311static void pane_caret_display(pane_t *pane)
    13361312{
    13371313        spt_t caret_pt;
    13381314        coord_t coord;
    1339 
    1340         tag_get_pt(&pane.caret_pos, &caret_pt);
     1315        gfx_coord2_t pos;
     1316        gfx_context_t *gc;
     1317
     1318        tag_get_pt(&pane->caret_pos, &caret_pt);
    13411319
    13421320        spt_get_coord(&caret_pt, &coord);
    1343 //      console_set_pos(con, coord.column - pane.sh_column,
    1344 //          coord.row - pane.sh_row);
     1321
     1322        gc = ui_window_get_gc(edit.window);
     1323        pos.x = pane->rect.p0.x + coord.column - pane->sh_column;
     1324        pos.y = pane->rect.p0.y + coord.row - pane->sh_row;
     1325
     1326        (void) gfx_cursor_set_pos(gc, &pos);
    13451327}
    13461328
     
    20812063    kbd_event_t *event)
    20822064{
    2083         if (event->type == KEY_PRESS)
     2065        if (event->type == KEY_PRESS) {
    20842066                key_handle_press(event);
     2067                (void) pane_update(&pane);
     2068                (void) gfx_update(ui_window_get_gc(window));
     2069        }
    20852070}
    20862071
Note: See TracChangeset for help on using the changeset viewer.