Fixed the overflows and make the render handle SFML's weird window coordinates not matching world coordinates.
This commit is contained in:
parent
cb2e766305
commit
f05f652c26
3 changed files with 18 additions and 12 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue