Add basic pointer selection

Part of #4.
This commit is contained in:
Leroy Hopson 2021-07-08 20:10:58 +07:00 committed by Leroy Hopson
parent fae28006cf
commit 57c1c3524d
3 changed files with 92 additions and 6 deletions

View file

@ -286,9 +286,15 @@ void Terminal::_register_methods() {
register_method("sb_up", &Terminal::sb_up);
register_method("sb_down", &Terminal::sb_down);
register_method("start_selection", &Terminal::start_selection);
register_method("select_to_pointer", &Terminal::select_to_pointer);
register_method("reset_selection", &Terminal::reset_selection);
register_method("_update_theme", &Terminal::update_theme);
register_method("_update_size", &Terminal::update_theme);
register_property<Terminal, Vector2>("cell_size", &Terminal::cell_size,
Vector2(0, 0));
register_property<Terminal, int>("rows", &Terminal::rows, 24);
register_property<Terminal, int>("cols", &Terminal::cols, 80);
register_property<Terminal, int>("update_mode", &Terminal::update_mode,
@ -547,11 +553,10 @@ void Terminal::update_size() {
// Recalculates the cell_size and number of cols/rows based on font size and
// the Control's rect_size.
Ref<Font> fontref = fontmap.count("Regular")
? fontmap["Regular"]
: has_font("Regular", "Terminal")
? get_font("Regular", "Terminal")
: get_font("");
Ref<Font> fontref = fontmap.count("Regular") ? fontmap["Regular"]
: has_font("Regular", "Terminal")
? get_font("Regular", "Terminal")
: get_font("");
cell_size = fontref->get_string_size("W");
rows = std::max(2, (int)floor(get_rect().size.y / cell_size.y));
@ -577,4 +582,19 @@ void Terminal::sb_up(int num) {
void Terminal::sb_down(int num) {
tsm_screen_sb_down(screen, num);
update();
}
void Terminal::start_selection(Vector2 position) {
tsm_screen_selection_start(screen, position.x, position.y);
update();
}
void Terminal::select_to_pointer(Vector2 position) {
tsm_screen_selection_target(screen, position.x, position.y);
update();
}
void Terminal::reset_selection() {
tsm_screen_selection_reset(screen);
update();
}

View file

@ -29,7 +29,6 @@ private:
static void _populate_key_list();
static uint32_t mapkey(std::pair<int64_t, int64_t> key);
Vector2 cell_size;
std::map<int, Color> palette = {};
std::map<String, Ref<Font>> fontmap = {};
@ -59,6 +58,10 @@ public:
void sb_up(int num);
void sb_down(int num);
void start_selection(Vector2 position);
void select_to_pointer(Vector2 position);
void reset_selection();
enum UpdateMode {
DISABLED,
AUTO,
@ -66,6 +69,7 @@ public:
ALL_NEXT_FRAME,
};
Vector2 cell_size;
int rows;
int cols;
int update_mode;