Пример #1
0
bool ScanSequence::is_valid() const {
    bool res = true;
    int num_lines = static_cast<int>(get_num_lines());
    for (int line_no = 0; line_no < num_lines; line_no++) {
        if (!get_scanline(line_no).is_valid()) res = false;
    }
    return res;
}
Пример #2
0
static int message_handle_key_editmode(struct key_event * k)
{
        int line_len, num_lines = -1;
        int new_cursor_line = cursor_line;
        int new_cursor_char = cursor_char;
        char *ptr;
        int doing_drag = 0;
        int clipl, clipr, cp;

        if (k->mouse == MOUSE_SCROLL_UP) {
                if (k->state == KEY_RELEASE)
                        return 0;
                new_cursor_line -= MOUSE_SCROLL_LINES;
        } else if (k->mouse == MOUSE_SCROLL_DOWN) {
                if (k->state == KEY_RELEASE)
                        return 0;
                new_cursor_line += MOUSE_SCROLL_LINES;
        } else if (k->mouse == MOUSE_CLICK && k->mouse_button == 2) {
                if (k->state == KEY_RELEASE)
                        status.flags |= CLIPPY_PASTE_SELECTION;
                return 1;
        } else if (k->mouse == MOUSE_CLICK) {
                if (k->x >= 2 && k->x <= 77 && k->y >= 13 && k->y <= 47) {
                        new_cursor_line = (k->y - 13) + top_line;
                        new_cursor_char = (k->x - 2);
                        if (k->sx != k->x || k->sy != k->y) {
                                /* yay drag operation */
                                cp = get_absolute_position(current_song->message, (k->sy-13)+top_line,
                                                        (k->sx-2));
                                widgets_message[0].clip_start = cp;
                                doing_drag = 1;
                        }
                }
        }

        line_len = get_nth_line(current_song->message, cursor_line, &ptr);


        switch (k->sym) {
        case SDLK_UP:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                new_cursor_line--;
                break;
        case SDLK_DOWN:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                new_cursor_line++;
                break;
        case SDLK_LEFT:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                new_cursor_char--;
                break;
        case SDLK_RIGHT:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                new_cursor_char++;
                break;
        case SDLK_PAGEUP:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                new_cursor_line -= 35;
                break;
        case SDLK_PAGEDOWN:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                new_cursor_line += 35;
                break;
        case SDLK_HOME:
                if (k->state == KEY_RELEASE)
                        return 1;
                if (k->mod & KMOD_CTRL)
                        new_cursor_line = 0;
                else
                        new_cursor_char = 0;
                break;
        case SDLK_END:
                if (k->state == KEY_RELEASE)
                        return 1;
                if (k->mod & KMOD_CTRL) {
                        num_lines = get_num_lines(current_song->message);
                        new_cursor_line = num_lines;
                } else {
                        new_cursor_char = line_len;
                }
                break;
        case SDLK_ESCAPE:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                message_set_viewmode();
                memused_songchanged();
                return 1;
        case SDLK_BACKSPACE:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                if (k->sym && clippy_owner(CLIPPY_SELECT) == widgets_message) {
                        _delete_selection();
                } else {
                        message_delete_char();
                }
                return 1;
        case SDLK_DELETE:
                if (!NO_MODIFIER(k->mod))
                        return 0;
                if (k->state == KEY_RELEASE)
                        return 1;
                if (k->sym && clippy_owner(CLIPPY_SELECT) == widgets_message) {
                        _delete_selection();
                } else {
                        message_delete_next_char();
                }
                return 1;
        default:
                if (k->mod & KMOD_CTRL) {
                        if (k->state == KEY_RELEASE)
                                return 1;
                        if (k->sym == SDLK_t) {
                                message_extfont = !message_extfont;
                                break;
                        } else if (k->sym == SDLK_y) {
                                clippy_select(NULL, NULL, 0);
                                message_delete_line();
                                break;
                        }
                } else if (k->mod & KMOD_ALT) {
                        if (k->state == KEY_RELEASE)
                                return 1;
                        if (k->sym == SDLK_c) {
                                prompt_message_clear();
                                return 1;
                        }
                } else if (k->mouse == MOUSE_NONE) {
                        if (k->unicode == '\r' || k->unicode == '\t'
                        || k->unicode >= 32) {
                                if (k->state == KEY_RELEASE)
                                        return 1;
                                if (k->sym && clippy_owner(CLIPPY_SELECT) == widgets_message) {
                                        _delete_selection();
                                }
                                if (k->mod & (KMOD_SHIFT|KMOD_CAPS)) {
                                        message_insert_char(toupper((unsigned int)k->unicode));
                                } else {
                                        message_insert_char(k->unicode);
                                }
                                return 1;
                        }
                        return 0;
                }

                if (k->mouse != MOUSE_CLICK)
                        return 0;

                if (k->state == KEY_RELEASE)
                        return 1;
                if (!doing_drag) {
                        clippy_select(NULL, NULL, 0);
                }
        }

        if (new_cursor_line != cursor_line) {
                if (num_lines == -1)
                        num_lines = get_num_lines(current_song->message);

                if (new_cursor_line < 0)
                        new_cursor_line = 0;
                else if (new_cursor_line > num_lines)
                        new_cursor_line = num_lines;

                /* make sure the cursor doesn't go past the new eol */
                line_len = get_nth_line(current_song->message, new_cursor_line, &ptr);
                if (new_cursor_char > line_len)
                        new_cursor_char = line_len;

                cursor_char = new_cursor_char;
                cursor_line = new_cursor_line;
        } else if (new_cursor_char != cursor_char) {
        /* we say "else" here ESPECIALLY because the mouse can only come
        in the top section - not because it's some clever optimization */
                if (new_cursor_char < 0) {
                        if (cursor_line == 0) {
                                new_cursor_char = cursor_char;
                        } else {
                                cursor_line--;
                                new_cursor_char =
                                        get_nth_line(current_song->message, cursor_line, &ptr);
                        }

                } else if (new_cursor_char >
                           get_nth_line(current_song->message, cursor_line, &ptr)) {
                        if (cursor_line == get_num_lines(current_song->message)) {
                                new_cursor_char = cursor_char;
                        } else {
                                cursor_line++;
                                new_cursor_char = 0;
                        }
                }
                cursor_char = new_cursor_char;
        }

        message_reposition();
        cursor_pos = get_absolute_position(current_song->message, cursor_line, cursor_char);

        if (doing_drag) {
                widgets_message[0].clip_end = cursor_pos;

                clipl = widgets_message[0].clip_start;
                clipr = widgets_message[0].clip_end;
                if (clipl > clipr) {
                        cp = clipl;
                        clipl = clipr;
                        clipr = cp;
                }
                clippy_select(widgets_message, (current_song->message+clipl), clipr-clipl);
        }

        status.flags |= NEED_UPDATE;

        return 1;
}
Пример #3
0
static int message_handle_key_viewmode(struct key_event * k)
{
        if (k->state == KEY_PRESS) {
                if (k->mouse == MOUSE_SCROLL_UP) {
                        top_line -= MOUSE_SCROLL_LINES;
                } else if (k->mouse == MOUSE_SCROLL_DOWN) {
                        top_line += MOUSE_SCROLL_LINES;
                } else if (k->mouse == MOUSE_CLICK) {
                        message_set_editmode();
                        return message_handle_key_editmode(k);
                }
        }

        switch (k->sym) {
        case SDLK_UP:
                if (k->state == KEY_RELEASE)
                        return 0;
                top_line--;
                break;
        case SDLK_DOWN:
                if (k->state == KEY_RELEASE)
                        return 0;
                top_line++;
                break;
        case SDLK_PAGEUP:
                if (k->state == KEY_RELEASE)
                        return 0;
                top_line -= 35;
                break;
        case SDLK_PAGEDOWN:
                if (k->state == KEY_RELEASE)
                        return 0;
                top_line += 35;
                break;
        case SDLK_HOME:
                if (k->state == KEY_RELEASE)
                        return 0;
                top_line = 0;
                break;
        case SDLK_END:
                if (k->state == KEY_RELEASE)
                        return 0;
                top_line = get_num_lines(current_song->message) - 34;
                break;
        case SDLK_t:
                if (k->state == KEY_RELEASE)
                        return 0;
                if (k->mod & KMOD_CTRL) {
                        message_extfont = !message_extfont;
                        break;
                }
                return 1;
        case SDLK_RETURN:
                if (k->state == KEY_PRESS)
                        return 0;
                message_set_editmode();
                return 1;
        default:
                return 0;
        }

        if (top_line < 0)
                top_line = 0;

        status.flags |= NEED_UPDATE;

        return 1;
}
Пример #4
0
const Scanline& ScanSequence::get_scanline(int index) const {
    if (index < 0 || index >= get_num_lines()) {
        throw std::runtime_error("ScanSequence::Invalid index.");
    }
    return scanlines[index];
}