~kameliya/kyuubey

d1492d5fd247a93712f6147fcf4cf6e2093fc22f — Yuki Izumi 6 years ago 2c4029e
React to alt-hold.
3 files changed, 37 insertions(+), 11 deletions(-)

M main.c
M qb.c
M qb.h
M main.c => main.c +2 -0
@@ 67,6 67,7 @@ void loop(void) {
                    break;
                }

                qb_keydown(event.key.keysym.sym, event.key.keysym.mod);
                qb_keypress(event.key.keysym.sym, event.key.keysym.mod);
                keydown_tick = SDL_GetTicks();
                keydown_sym = event.key.keysym.sym;


@@ 75,6 76,7 @@ void loop(void) {
                break;

            case SDL_KEYUP:
                qb_keyup(event.key.keysym.sym);
                keydown_tick = 0;
                break;


M qb.c => qb.c +33 -11
@@ 16,7 16,7 @@ typedef struct doc_line {

typedef struct {
    char *title;
    char is_immediate_window;
    int is_immediate_window;

    doc_line_t *doc;
    int total_lines;


@@ 30,6 30,9 @@ typedef struct {
static editor_t *main_editor;
static editor_t *immediate_editor;

static int alt_held = 0;
static int menubar_focus = 0;

static SDL_Keycode shift_table[][2] = {
    {SDLK_QUOTE, SDLK_QUOTEDBL},
    {SDLK_COMMA, SDLK_LESS},


@@ 211,6 214,15 @@ static int is_printable_key(SDL_Keycode sym) {
    return sym >= SDLK_SPACE && sym <= SDLK_z;
}

void render_menu_option(char const *title, int start) {
    int len = strlen(title);

    screen[0 * 80 + start + 1] = (alt_held ? 0x7f00 : 0x7000) | (title[0]);
    for (int j = 1; j < len; ++j) {
        screen[0 * 80 + start + 1 + j] = 0x7000 | (title[j]);
    }
}

void render_editor(editor_t *editor, int has_focus) {
    /* Render the titlebar. */



@@ 318,18 330,11 @@ void render(void) {
            break;
        }

        int len = strlen(menu_options[i]);
        for (int j = 0; j < len; ++j) {
            screen[0 * 80 + offset + 1 + j] = 0x7000 | (menu_options[i][j]);
        }

        offset += len + 2;
        render_menu_option(menu_options[i], offset);
        offset += strlen(menu_options[i]) + 2;
    }

    screen[0 * 80 + 74] = 0x7000 + 'H';
    screen[0 * 80 + 75] = 0x7000 + 'e';
    screen[0 * 80 + 76] = 0x7000 + 'l';
    screen[0 * 80 + 77] = 0x7000 + 'p';
    render_menu_option("Help", 73);

    /* Draw the editors. */



@@ 411,6 416,23 @@ void qb_init(void) {
    render();
}

void qb_keydown(SDL_Keycode sym, Uint16 mod) {
    if ((sym == SDLK_LALT || sym == SDLK_RALT) && !alt_held) {
        alt_held = 1;
        render();
        text_refresh();
    }
}

void qb_keyup(SDL_Keycode sym) {
    if ((sym == SDLK_LALT || sym == SDLK_RALT) && alt_held) {
        alt_held = 0;
        menubar_focus = 1;
        render();
        text_refresh();
    }
}

void qb_keypress(SDL_Keycode sym, Uint16 mod) {
    if (sym == SDLK_ESCAPE) {
        qb_running = 0;

M qb.h => qb.h +2 -0
@@ 6,6 6,8 @@
extern int qb_running;

void qb_init(void);
void qb_keydown(SDL_Keycode sym, Uint16 mod);
void qb_keyup(SDL_Keycode sym);
void qb_keypress(SDL_Keycode sym, Uint16 mod);
void qb_mouseclick(int button);