Fixed the overflows and make the render handle SFML's weird window coordinates not matching world coordinates.

main
Zed A. Shaw 2 weeks ago
parent cb2e766305
commit f05f652c26
  1. 8
      render.cpp
  2. 5
      status.txt
  3. 17
      tools/designer.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_fg = default_fg;
sf::Color cur_bg = default_bg; sf::Color cur_bg = default_bg;
// make a copy so we don't modify the cached one
$ansi.parse(text, [&](auto fg, auto bg) { $ansi.parse(text, [&](auto fg, auto bg) {
cur_fg = fg; cur_fg = fg;
cur_bg = bg; 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) { 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; 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 if(pos.x >= panel.x && pos.y >= panel.y
&& pos.x <= (panel.x + panel.width * bounds.width) && pos.x <= (panel.x + panel.width * bounds.width)
&& pos.y <= (panel.y + panel.height * bounds.height)) && pos.y <= (panel.y + panel.height * bounds.height))

@ -1,9 +1,6 @@
TODAY'S GOAL: TODAY'S GOAL:
==== 0. \ua3fd causes the character immediately after to vanish.
Font Extractor
===
1. Why do Sliders only have to be kept around forever and can't go in containers like everything else? 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? 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. 3. Why do fonts render blank? Also when I scroll they slowly disappear until there's a column.

@ -65,6 +65,7 @@ struct FontGrid {
} }
void render(size_t start_char, bool fill) { 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; size_t next_char = start_char;
for(size_t y = 0; y < height; ++y) { for(size_t y = 0; y < height; ++y) {
@ -73,6 +74,9 @@ struct FontGrid {
next_char++; next_char++;
} }
// just get out of here, nothing more to render
if(next_char >= $charmap.size()) return;
$grid[y][x] = { $grid[y][x] = {
.cm_index = next_char, .cm_index = next_char,
.as_string = $charmap[next_char], .as_string = $charmap[next_char],
@ -122,8 +126,8 @@ class GUI {
Canvas $canvas; Canvas $canvas;
SFMLRender $renderer; SFMLRender $renderer;
FontGrid $font_grid; FontGrid $font_grid;
size_t $start_char = 0; size_t $start_char = 1;
size_t $fill_char = 0; size_t $fill_char = 1;
WhatTheColor $fg_color; WhatTheColor $fg_color;
WhatTheColor $bg_color; WhatTheColor $bg_color;
Component $fg_settings; Component $fg_settings;
@ -157,8 +161,8 @@ class GUI {
for(size_t y = 0; y < $font_grid.height; y++) { for(size_t y = 0; y < $font_grid.height; y++) {
for(size_t x = 0; x < $font_grid.width; x++, flip_it++) { 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) { $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.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 * 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; using KB = sf::Keyboard;
sf::Event event; sf::Event event;
int font_size = $renderer.font_size(); int font_size = $renderer.font_size();
int page_size = $font_grid.page_size();
while($renderer.poll_event(event)) { while($renderer.poll_event(event)) {
if(event.type == sf::Event::Closed) { if(event.type == sf::Event::Closed) {
@ -242,12 +247,12 @@ class GUI {
return true; return true;
} else if(event.type == sf::Event::KeyPressed) { } else if(event.type == sf::Event::KeyPressed) {
if(KB::isKeyPressed(KB::Up)) { 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); render_grid($start_char, false);
event_happened = true; event_happened = true;
$renderer.clear_cache(); $renderer.clear_cache();
} else if(KB::isKeyPressed(KB::Down)) { } 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); render_grid($start_char, false);
$renderer.clear_cache(); $renderer.clear_cache();
} else if(KB::isKeyPressed(KB::Equal)) { } else if(KB::isKeyPressed(KB::Equal)) {

Loading…
Cancel
Save