diff --git a/render.cpp b/render.cpp index 5aff842..60b5c9a 100644 --- a/render.cpp +++ b/render.cpp @@ -92,7 +92,6 @@ void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf: sf::Color cur_fg = default_fg; sf::Color cur_bg = default_bg; - // make a copy so we don't modify the cached one $ansi.parse(text, [&](auto fg, auto bg) { cur_fg = fg; cur_bg = bg; @@ -235,9 +234,14 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) { } bool SFMLRender::mouse_position(Panel &panel, Point &out) { - sf::Vector2i pos = sf::Mouse::getPosition($window); + // yes, you have to do this in sfml + sf::Vector2f pos = $window.mapPixelToCoords(sf::Mouse::getPosition($window)); + auto bounds = panel.grid ? $grid_bounds : $text_bounds; + println("mouse position pos={},{} panel.pos={},{} panel.size={},{}", + pos.x, pos.y, panel.x, panel.y, panel.width, panel.height); + if(pos.x >= panel.x && pos.y >= panel.y && pos.x <= (panel.x + panel.width * bounds.width) && pos.y <= (panel.y + panel.height * bounds.height)) diff --git a/status.txt b/status.txt index f8b36a5..039fa51 100644 --- a/status.txt +++ b/status.txt @@ -1,9 +1,6 @@ TODAY'S GOAL: -==== -Font Extractor -=== - +0. \ua3fd causes the character immediately after to vanish. 1. Why do Sliders only have to be kept around forever and can't go in containers like everything else? 2. Why are sliders not selected when I click on them? Is it a hover? 3. Why do fonts render blank? Also when I scroll they slowly disappear until there's a column. diff --git a/tools/designer.cpp b/tools/designer.cpp index 2d12f83..e519577 100644 --- a/tools/designer.cpp +++ b/tools/designer.cpp @@ -65,6 +65,7 @@ struct FontGrid { } void render(size_t start_char, bool fill) { + dbc::check(start_char > 0 && start_char < $charmap.size(), format("attempt render from bad start {}", start_char)); size_t next_char = start_char; for(size_t y = 0; y < height; ++y) { @@ -73,6 +74,9 @@ struct FontGrid { next_char++; } + // just get out of here, nothing more to render + if(next_char >= $charmap.size()) return; + $grid[y][x] = { .cm_index = next_char, .as_string = $charmap[next_char], @@ -122,8 +126,8 @@ class GUI { Canvas $canvas; SFMLRender $renderer; FontGrid $font_grid; - size_t $start_char = 0; - size_t $fill_char = 0; + size_t $start_char = 1; + size_t $fill_char = 1; WhatTheColor $fg_color; WhatTheColor $bg_color; Component $fg_settings; @@ -157,8 +161,8 @@ class GUI { for(size_t y = 0; y < $font_grid.height; y++) { for(size_t x = 0; x < $font_grid.width; x++, flip_it++) { $canvas.DrawText(x * 2, y * 4, $font_grid.as_string(x, y), [&](auto &pixel) { - pixel.foreground_color = Color::HSV($fg_color.h, $fg_color.s, $fg_color.v); - pixel.background_color = Color::HSV($bg_color.h, $bg_color.s, $bg_color.v / (flip_it % 2 * 2 + 1)); + pixel.foreground_color = Color::HSV($fg_color.h, $fg_color.s, $fg_color.v / (flip_it % 2 + 1)); + pixel.background_color = Color::HSV($bg_color.h, $bg_color.s, $bg_color.v / (flip_it % 2 + 1)); }); } } @@ -235,6 +239,7 @@ class GUI { using KB = sf::Keyboard; sf::Event event; int font_size = $renderer.font_size(); + int page_size = $font_grid.page_size(); while($renderer.poll_event(event)) { if(event.type == sf::Event::Closed) { @@ -242,12 +247,12 @@ class GUI { return true; } else if(event.type == sf::Event::KeyPressed) { if(KB::isKeyPressed(KB::Up)) { - $start_char = std::max(size_t(1), $start_char - $font_grid.page_size()); + $start_char = std::max(1, int($start_char) - page_size); render_grid($start_char, false); event_happened = true; $renderer.clear_cache(); } else if(KB::isKeyPressed(KB::Down)) { - $start_char = std::min($font_grid.max_chars(), $start_char + $font_grid.page_size()); + $start_char = std::min($font_grid.max_chars() - page_size, $start_char + page_size); render_grid($start_char, false); $renderer.clear_cache(); } else if(KB::isKeyPressed(KB::Equal)) {