diff --git a/render.cpp b/render.cpp index 582f1ee..207b3f0 100644 --- a/render.cpp +++ b/render.cpp @@ -50,6 +50,12 @@ sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) { return $sprites[tile]; } +void SFMLRender::clear_cache() { + $sprites.clear(); + $font.loadFromFile("./assets/text.otf"); + $font.setSmooth(false); + $ui_text.setFont($font); +} void SFMLRender::resize_grid(int new_size, Panel &panel_out) { auto glyph = $font.getGlyph($config.bg_tile, new_size, false); diff --git a/render.hpp b/render.hpp index 572d9ca..4cfc843 100644 --- a/render.hpp +++ b/render.hpp @@ -68,5 +68,6 @@ struct SFMLRender { void clear() { $window.clear(); } void display() { $window.display(); } bool mouse_position(Panel &panel, Point &out); + void clear_cache(); static void init_terminal(); }; diff --git a/tools/designer.cpp b/tools/designer.cpp index e17708e..45fce18 100644 --- a/tools/designer.cpp +++ b/tools/designer.cpp @@ -52,12 +52,20 @@ struct FontGrid { } string from_unicode(wstring input) { - return $converter.to_bytes(input); + try { + return $converter.to_bytes(input); + } catch(...) { + return "?"; + } } wchar_t to_unicode_char(size_t x, size_t y) { - string input = $chars[y][x]; - return $converter.from_bytes(input)[0]; + try { + string input = $chars[y][x]; // BUG: bounds check this instead + return $converter.from_bytes(input)[0]; + } catch(...) { + return L'?'; + } } string at(size_t x, size_t y) { @@ -87,7 +95,7 @@ class GUI { Canvas $canvas; SFMLRender $renderer; FontGrid $font_grid; - wchar_t $start_char = L'\ua66b'; + wchar_t $start_char = L'\u28cc'; wchar_t $fill_char = WCHAR_MIN; WhatTheColor $fg_color; WhatTheColor $bg_color; @@ -143,7 +151,7 @@ class GUI { return hbox({ hflow( vbox( - text(format("\\u{:x}", int($fill_char))) | border, + text(format("\\u{:x} {} MIN: {}, MAX: {}", int($fill_char), int($fill_char), WCHAR_MIN, WCHAR_MAX)) | border, separator(), text(format("FG H: {}, S: {}, V: {}", $fg_color.h, $fg_color.s, $fg_color.v)) | border, @@ -191,7 +199,6 @@ class GUI { bool handle_ui_events() { bool event_happened; using KB = sf::Keyboard; - using MOUSE = sf::Mouse; sf::Event event; int font_size = $renderer.font_size(); @@ -200,21 +207,22 @@ class GUI { shutdown(); return true; } else if(event.type == sf::Event::KeyPressed) { - println("KEY PRESSED"); if(KB::isKeyPressed(KB::Up)) { - $start_char = std::min(WCHAR_MAX, $start_char + $font_grid.page_size()); + $start_char = std::max(WCHAR_MIN+1, $start_char - $font_grid.page_size()); $font_grid.render($start_char, false); event_happened = true; + $renderer.clear_cache(); } else if(KB::isKeyPressed(KB::Down)) { - $start_char = std::max(WCHAR_MIN+1, $start_char - $font_grid.page_size()); + $start_char = std::min(WCHAR_MAX, $start_char + $font_grid.page_size()); $font_grid.render($start_char, false); + $renderer.clear_cache(); } else if(KB::isKeyPressed(KB::Equal)) { resize_fonts(font_size + 10); } else if(KB::isKeyPressed(KB::Hyphen)) { resize_fonts(font_size - 10); event_happened = true; } - } else if(MOUSE::isButtonPressed(MOUSE::Left)) { + } else if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { Point pos; if($renderer.mouse_position($font_view, pos)) { select_cell(pos); @@ -222,6 +230,8 @@ class GUI { } else if($renderer.mouse_position($status_ui, pos)) { $status_ui.mouse_click(Mouse::Button::Left, pos); } + } else if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) { + deselect_cell(); } }