Moved to SFML 3.0 now.

This commit is contained in:
Zed A. Shaw 2025-01-29 12:55:33 -05:00
parent 7c56f350ab
commit e05b2c304c
12 changed files with 167 additions and 173 deletions

View file

@ -237,52 +237,52 @@ class GUI {
bool handle_ui_events() {
bool event_happened;
using KB = sf::Keyboard;
sf::Event event;
using KB = sf::Keyboard::Key;
Point pos;
int font_size = $renderer.font_size();
int page_size = $font_grid.page_size();
while($renderer.poll_event(event)) {
if(event.type == sf::Event::Closed) {
while(const auto event = $renderer.poll_event()) {
if(event->is<sf::Event::Closed>()) {
shutdown();
return true;
} else if(event.type == sf::Event::KeyPressed) {
if(KB::isKeyPressed(KB::Up)) {
} else if(event->is<sf::Event::KeyPressed>()) {
if(sf::Keyboard::isKeyPressed(KB::Up)) {
$start_char = std::max(1, int($start_char) - page_size);
render_grid($start_char, false);
event_happened = true;
$renderer.clear_cache();
} else if(event.key.code == KB::C && event.key.control) {
} else if(sf::Keyboard::isKeyPressed(KB::C)
&& sf::Keyboard::isKeyPressed(KB::LControl)) {
wchar_t selected_char = $font_grid.as_wchar($fill_char);
string out = format("\\u{:x}", int(selected_char));
println("COPIED {}", out);
sf::Clipboard::setString(out);
} else if(KB::isKeyPressed(KB::Down)) {
} else if(sf::Keyboard::isKeyPressed(KB::Down)) {
$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::Tab)) {
} else if(sf::Keyboard::isKeyPressed(KB::Tab)) {
$status_ui.key_press(Event::Tab);
} else if(KB::isKeyPressed(KB::Tab)) {
} else if(sf::Keyboard::isKeyPressed(KB::Tab)) {
$status_ui.key_press(Event::Return);
} else if(KB::isKeyPressed(KB::Equal)) {
} else if(sf::Keyboard::isKeyPressed(KB::Equal)) {
resize_fonts(font_size + 10);
} else if(KB::isKeyPressed(KB::Hyphen)) {
} else if(sf::Keyboard::isKeyPressed(KB::Hyphen)) {
resize_fonts(font_size - 10);
event_happened = true;
}
} else if($renderer.mouse_position($font_view, pos)) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
select_cell(pos);
event_happened = true;
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) {
deselect_cell();
}
} else if($renderer.mouse_position($status_ui, pos)) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
$status_ui.mouse_click(Mouse::Button::Left, pos);
} else if(event.type == sf::Event::MouseMoved) {
} else if(event->is<sf::Event::MouseMoved>()) {
$status_ui.mouse_release(Mouse::Button::Left, pos);
}
}

View file

@ -44,20 +44,19 @@ struct FontExtractor {
FontExtractor(fs::path font_path) :
$font_path(font_path)
{
bool good = $font.loadFromFile($font_path.string());
bool good = $font.openFromFile($font_path);
dbc::check(good, format("failed to load font {}", $font_path.string()));
$font.setSmooth(false);
for(int i = 100; i < 200; i++) {
auto glyph = $font.getGlyph(ui_base_char, i, false);
if(glyph.bounds.width > 0 && glyph.bounds.height > 0) {
if(glyph.bounds.size.x > 0 && glyph.bounds.size.y > 0) {
$grid_bounds = glyph.bounds;
$font_size = i;
break;
}
}
dbc::check($grid_bounds.width > 0 && $grid_bounds.height > 0, "couldn't find a valid font size");
dbc::check($grid_bounds.size.x > 0 && $grid_bounds.size.y > 0, "couldn't find a valid font size");
println("!!!!!!!!!!!!!!!!!!!!! FONT SIZE {}", $font_size);
}
@ -133,10 +132,10 @@ struct FontExtractor {
auto bounds = glyph.bounds;
// skip bad chars
if(bounds.width <= 0 || bounds.height <= 0) continue;
if(bounds.size.x <= 0 || bounds.size.y <= 0) continue;
if(bounds.width <= $grid_bounds.width &&
bounds.height <= $grid_bounds.height) {
if(bounds.size.x <= $grid_bounds.size.x &&
bounds.size.y <= $grid_bounds.size.y) {
return i;
}
}
@ -175,7 +174,7 @@ struct FontExtractor {
void clear_font_cache() {
if($clear_count % CLEAR_CACHE_POINT == 0) {
bool good = $font.loadFromFile($font_path.string());
bool good = $font.openFromFile($font_path);
dbc::check(good, format("failed to load font {}", $font_path.string()));
$font.setSmooth(false);