Moved to SFML 3.0 now.

main
Zed A. Shaw 7 days ago
parent 7c56f350ab
commit e05b2c304c
  1. 55
      gui.cpp
  2. 12
      gui.hpp
  3. 61
      meson.build
  4. 58
      render.cpp
  5. 24
      render.hpp
  6. 14
      scratchpad/img2ansi.cpp
  7. 25
      sound.cpp
  8. 6
      sound.hpp
  9. 32
      tools/designer.cpp
  10. 15
      tools/fontextract.cpp
  11. 13
      wraps/openal-soft.wrap
  12. 23
      wraps/sfml.wrap

@ -312,42 +312,42 @@ void GUI::shutdown() {
bool GUI::game_ui_events() {
auto& world = *$level.world;
using KB = sf::Keyboard;
using KB = sf::Keyboard::Key;
auto player = world.get_the<Player>();
int map_font_size = $renderer.font_size();
auto& player_motion = world.get<Motion>(player.entity);
bool event_happened = false;
if(KB::isKeyPressed(KB::Left)) {
if(sf::Keyboard::isKeyPressed(KB::Left)) {
player_motion.dx = -1;
event_happened = true;
} else if(KB::isKeyPressed(KB::Right)) {
} else if(sf::Keyboard::isKeyPressed(KB::Right)) {
player_motion.dx = 1;
event_happened = true;
} else if(KB::isKeyPressed(KB::Up)) {
} else if(sf::Keyboard::isKeyPressed(KB::Up)) {
player_motion.dy = -1;
event_happened = true;
} else if(KB::isKeyPressed(KB::Down)) {
} else if(sf::Keyboard::isKeyPressed(KB::Down)) {
player_motion.dy = 1;
event_happened = true;
} else if(KB::isKeyPressed(KB::Equal)) {
} else if(sf::Keyboard::isKeyPressed(KB::Equal)) {
resize_map(map_font_size + 10);
} else if(KB::isKeyPressed(KB::Hyphen)) {
} else if(sf::Keyboard::isKeyPressed(KB::Hyphen)) {
resize_map(map_font_size - 10);
} else if(KB::isKeyPressed(KB::L)) {
} else if(sf::Keyboard::isKeyPressed(KB::L)) {
auto &debug = world.get_the<Debug>();
debug.LIGHT = !debug.LIGHT;
} else if(KB::isKeyPressed(KB::I)) {
} else if(sf::Keyboard::isKeyPressed(KB::I)) {
toggle_modal(&$inventory_ui, $inventory_open);
} else if(KB::isKeyPressed(KB::P)) {
} else if(sf::Keyboard::isKeyPressed(KB::P)) {
auto &debug = world.get_the<Debug>();
debug.PATHS = !debug.PATHS;
} else if(KB::isKeyPressed(KB::S)) {
} else if(sf::Keyboard::isKeyPressed(KB::S)) {
save_world();
} else if(KB::isKeyPressed(KB::Tab)) {
} else if(sf::Keyboard::isKeyPressed(KB::Tab)) {
$status_ui.key_press(Event::Tab);
} else if(KB::isKeyPressed(KB::Enter)) {
} else if(sf::Keyboard::isKeyPressed(KB::Enter)) {
$status_ui.key_press(Event::Return);
}
@ -356,17 +356,17 @@ bool GUI::game_ui_events() {
bool GUI::modal_ui_events() {
using KB = sf::Keyboard;
using KB = sf::Keyboard::Key;
bool event_happened = false;
for(Panel *panel : $active_panels) {
if(KB::isKeyPressed(KB::Tab)) {
if(sf::Keyboard::isKeyPressed(KB::Tab)) {
event_happened = true;
panel->key_press(Event::Tab);
} else if(KB::isKeyPressed(KB::Enter)) {
} else if(sf::Keyboard::isKeyPressed(KB::Enter)) {
event_happened = true;
panel->key_press(Event::Return);
} else if(KB::isKeyPressed(KB::Escape)) {
} else if(sf::Keyboard::isKeyPressed(KB::Escape)) {
// BUG: this is dogshit, rewerite it
if($inventory_open) {
toggle_modal(panel, $inventory_open);
@ -378,15 +378,13 @@ bool GUI::modal_ui_events() {
}
bool GUI::handle_ui_events() {
using MOUSE = sf::Mouse;
bool event_happened = false;
sf::Event event;
Point pos;
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();
} else if(event.type == sf::Event::KeyPressed) {
} else if(event->is<sf::Event::KeyPressed>()) {
if($modal_shown) {
event_happened = modal_ui_events();
} else {
@ -395,7 +393,7 @@ bool GUI::handle_ui_events() {
} else {
for(Panel *panel : $active_panels) {
if($renderer.mouse_position(*panel, pos)) {
if(MOUSE::isButtonPressed(MOUSE::Left)) {
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
panel->mouse_click(Mouse::Button::Left, pos);
event_happened = true;
} else {
@ -410,23 +408,12 @@ bool GUI::handle_ui_events() {
}
void GUI::init_shaders() {
auto& shader = $paused.load_shader("./shaders/modal.frag");
shader.setUniform("offsetFactor", sf::Glsl::Vec2{0.001f, 0.001f});
shader.setUniform("darkness", 0.05f);
}
void GUI::pause_screen() {
auto &window = $renderer.$window;
auto size = window.getSize();
$paused.texture.create(size.x, size.y);
$paused.texture.update(window);
$paused.sprite.setTexture($paused.texture);
$paused.sprite.setPosition(0,0);
}
void GUI::draw_paused() {
$renderer.draw_sprite($paused.sprite, &$paused.shader);
}
void GUI::run_systems() {

@ -36,17 +36,6 @@ struct ActionLog {
}
};
struct UnDumbTSS {
sf::Texture texture;
sf::Sprite sprite;
sf::Shader shader;
sf::Shader& load_shader(string filename) {
bool good = shader.loadFromFile(filename, sf::Shader::Fragment);
dbc::check(good, "shader could not be loaded");
return shader;
}
};
class DeathUI : public Panel {
public:
@ -143,7 +132,6 @@ class GUI {
Component $test_button;
SoundManager $sounds;
SFMLRender $renderer;
UnDumbTSS $paused;
std::vector<Panel*> $active_panels;
public:

@ -1,20 +1,47 @@
project('roguish', 'cpp',
default_options: [ 'cpp_std=c++20' ])
default_options: [
'cpp_std=c++20',
'cpp_args=-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1',
])
# use this for common options only for our executables
cpp_args=[]
# these are passed as override_defaults
exe_defaults = ['warning_level=2', 'werror=true']
cc = meson.get_compiler('cpp')
catch2 = dependency('catch2-with-main')
fmt = dependency('fmt')
fmt = dependency('fmt', allow_fallback: true)
json = dependency('nlohmann_json')
ftxui_screen = dependency('ftxui-screen')
ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component')
sfml = dependency('sfml')
freetype2 = dependency('freetype2')
thread_dep = dependency('threads')
freetype2 = dependency('freetype2')
opengl32 = cc.find_library('opengl32', required: true)
winmm = cc.find_library('winmm', required: true)
gdi32 = cc.find_library('gdi32', required: true)
flac = dependency('flac')
ogg = dependency('ogg')
vorbis = dependency('vorbis')
vorbisfile = dependency('vorbisfile')
vorbisenc = dependency('vorbisenc')
sfml_audio = dependency('sfml_audio')
sfml_graphics = dependency('sfml_graphics')
sfml_main = dependency('sfml_main')
sfml_network = dependency('sfml_network')
sfml_system = dependency('sfml_system')
sfml_window = dependency('sfml_window')
dependencies = [
fmt, ftxui_screen, ftxui_dom,
ftxui_component, json,
sfml, freetype2, thread_dep
ftxui_screen, ftxui_dom, ftxui_component,
thread_dep, fmt, json, opengl32, freetype2,
flac, ogg, vorbis, vorbisfile, vorbisenc,
winmm, gdi32, sfml_audio, sfml_graphics,
sfml_main, sfml_network, sfml_system,
sfml_window
]
source=[
@ -65,12 +92,15 @@ runtests = executable('runtests',
'tests/worldbuilder.cpp',
'tests/inventory.cpp',
'tests/matrix2.cpp',
], cpp_args:['-Wextra','-Werror'],
dependencies: dependencies + catch2)
],
cpp_args: cpp_args,
override_options: exe_defaults,
dependencies: dependencies + [catch2])
roguish = executable('roguish',
source + ['main.cpp'],
cpp_args:['-Wextra','-Werror'],
cpp_args: cpp_args,
override_options: exe_defaults,
dependencies: dependencies)
designer = executable('designer', [
@ -83,16 +113,19 @@ designer = executable('designer', [
'panel.cpp',
'pathing.cpp',
'lights.cpp',
'tools/designer.cpp'
], cpp_args:['-Wextra','-Werror'],
'tools/designer.cpp'],
cpp_args: cpp_args,
override_options: exe_defaults,
dependencies: dependencies)
fontextract = executable('fontextract', [
'dbc.cpp',
'rand.cpp',
'config.cpp',
'tools/fontextract.cpp'
'tools/fontextract.cpp',
],
cpp_args: cpp_args,
override_options: exe_defaults,
dependencies: dependencies)
img2ansi = executable('img2ansi', [
@ -102,6 +135,8 @@ img2ansi = executable('img2ansi', [
'render.cpp',
'scratchpad/img2ansi.cpp'
],
cpp_args: cpp_args,
override_options: exe_defaults,
dependencies: dependencies)
test('tests', runtests)

@ -16,24 +16,25 @@
using namespace fmt;
SFMLRender::SFMLRender() :
$window(sf::VideoMode($config.video_x,$config.video_y), "Roguish"),
$window(sf::VideoMode({$config.video_x, $config.video_y}), "Roguish"),
$map_font_size(0),
$line_spacing(0),
$default_fg(ColorValue::LIGHT_MID),
$default_bg(ColorValue::BLACK),
$bg_sprite($font_texture),
$font(FONT_FILE_NAME),
$ui_text($font),
$ansi($default_fg, $default_bg)
{
// force true color, but maybe I want to support different color sets
$font.loadFromFile(FONT_FILE_NAME);
$font.setSmooth(false);
$ui_text.setFont($font);
$ui_text.setPosition(0,0);
$ui_text.setPosition({0,0});
$ui_text.setCharacterSize($config.ui_font_size);
$ui_text.setFillColor(ColorValue::LIGHT_MID);
sf::Glyph glyph = $font.getGlyph($config.ui_base_char, $config.ui_font_size, false);
$text_bounds = glyph.bounds;
$cells_w = std::ceil($config.video_x / $text_bounds.width);
$cells_h = std::ceil($config.video_y / $text_bounds.height);
$cells_w = std::ceil($config.video_x / $text_bounds.size.x);
$cells_h = std::ceil($config.video_y / $text_bounds.size.y);
}
sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) {
@ -43,17 +44,16 @@ sf::Sprite &SFMLRender::get_text_sprite(wchar_t tile) {
// the glyphs on the font texture, so this gets loaded each time
// we get a new glyph from the font.
$font_texture = $font.getTexture($map_font_size);
sf::Sprite sprite($font_texture);
sprite.setTextureRect(glyph.textureRect);
$sprites[tile] = sprite;
$sprites.try_emplace(tile, $font_texture, glyph.textureRect);
}
return $sprites[tile];
return $sprites.at(tile);
}
void SFMLRender::clear_cache() {
$sprites.clear();
$font.loadFromFile("./assets/text.otf");
bool good = $font.openFromFile(FONT_FILE_NAME);
dbc::check(good, "Failed to load the font.");
$font.setSmooth(false);
$ui_text.setFont($font);
}
@ -62,14 +62,14 @@ void SFMLRender::center_panel(Panel &panel) {
int cell_center_x = ($cells_w - panel.width) / 2;
int cell_center_y = ($cells_h - panel.height) / 2;
panel.x = cell_center_x * $text_bounds.width;
panel.y = cell_center_y * $text_bounds.height;
panel.x = cell_center_x * $text_bounds.size.x;
panel.y = cell_center_y * $text_bounds.size.y;
}
void SFMLRender::resize_grid(int new_size, Panel &panel_out) {
auto glyph = $font.getGlyph($config.bg_tile, new_size, false);
int view_x = std::ceil(($config.video_x - panel_out.x) / glyph.bounds.width);
int view_y = std::ceil(($config.video_y - panel_out.y) / glyph.bounds.height);
int view_x = std::ceil(($config.video_x - panel_out.x) / glyph.bounds.size.x);
int view_y = std::ceil(($config.video_y - panel_out.y) / glyph.bounds.size.y);
// looks good, set 'em all
$base_glyph = glyph;
@ -87,8 +87,8 @@ inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, s
sp_bounds = sprite.getLocalBounds();
// calculate where to center the sprite, but only if it's smaller
width_delta = grid_bounds.width > sp_bounds.width ? (grid_bounds.width - sp_bounds.width) / 2 : 0;
height_delta = grid_bounds.height > sp_bounds.width ? (grid_bounds.height - sp_bounds.height) / 2 : 0;
width_delta = grid_bounds.size.x > sp_bounds.size.x ? (grid_bounds.size.x - sp_bounds.size.x) / 2 : 0;
height_delta = grid_bounds.size.y > sp_bounds.size.x ? (grid_bounds.size.y - sp_bounds.size.y) / 2 : 0;
}
void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf::Color default_bg, float x, float y) {
@ -148,12 +148,12 @@ inline sf::FloatRect draw_chunk(sf::RenderWindow& window,
text.setString(out);
text.setPosition({x, y});
// get a base character for the cell size
sf::FloatRect bounds(x, y, text_bounds.width * out.size(), text_bounds.height);
sf::FloatRect bounds({x, y}, {text_bounds.size.x * out.size(), text_bounds.size.y});
if(default_bg != bgcolor) {
sf::RectangleShape backing({bounds.width, bounds.height});
sf::RectangleShape backing({bounds.size.x, bounds.size.y});
backing.setFillColor(bgcolor);
backing.setPosition({bounds.left, bounds.top + bg_box_offset});
backing.setPosition({bounds.position.x, bounds.position.y + bg_box_offset});
window.draw(backing);
}
@ -177,7 +177,7 @@ void SFMLRender::render_text(const std::wstring &text, sf::Color default_fg, sf:
auto bounds = draw_chunk($window,
$text_bounds, $ui_text,
default_bg, cur_bg, $config.bg_box_offset, x, y, out);
x += bounds.width;
x += bounds.size.x;
}
cur_bg = bg;
$ui_text.setFillColor(fg);
@ -195,7 +195,7 @@ void SFMLRender::render_text(const std::wstring &text, sf::Color default_fg, sf:
bounds = $ui_text.getLocalBounds();
}
y += bounds.height;
y += bounds.size.y;
x = start_x; // reset to the original position
}
break;
@ -225,8 +225,8 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
auto bounds = panel.grid ? $grid_bounds : $text_bounds;
sf::RectangleShape backing(
sf::Vector2f(bounds.width * panel.width + panel.border_px,
bounds.height * panel.height + panel.border_px));
sf::Vector2f(bounds.size.x * panel.width + panel.border_px,
bounds.size.y * panel.height + panel.border_px));
backing.setFillColor(panel.default_bg);
@ -235,7 +235,7 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
backing.setOutlineThickness(panel.border_px);
}
backing.setPosition(panel.x + x_offset, panel.y + y_offset);
backing.setPosition({panel.x + x_offset, panel.y + y_offset});
$window.draw(backing);
if(panel.grid) {
@ -252,12 +252,12 @@ bool SFMLRender::mouse_position(Panel &panel, Point &out) {
auto bounds = panel.grid ? $grid_bounds : $text_bounds;
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))
&& pos.x <= (panel.x + panel.width * bounds.size.x)
&& pos.y <= (panel.y + panel.height * bounds.size.y))
{
out = {
size_t((pos.x - panel.x) / bounds.width),
size_t((pos.y - panel.y) / bounds.height)
size_t((pos.x - panel.x) / bounds.size.x),
size_t((pos.y - panel.y) / bounds.size.y)
};
return true;

@ -11,6 +11,7 @@
#include "ansi_parser.hpp"
#include "panel.hpp"
#include "constants.hpp"
#include <optional>
using ftxui::Canvas, ftxui::Screen;
@ -18,8 +19,8 @@ using ftxui::Canvas, ftxui::Screen;
* BUG: This could be so much better.
*/
struct RenderConfig {
int video_x = VIDEO_WINDOW_X;
int video_y = VIDEO_WINDOW_Y;
unsigned int video_x = VIDEO_WINDOW_X;
unsigned int video_y = VIDEO_WINDOW_Y;
int ui_font_size=UI_FONT_SIZE;
int base_map_font_size=BASE_MAP_FONT_SIZE;
wchar_t bg_tile = BG_TILE;
@ -34,17 +35,18 @@ struct SFMLRender {
sf::RenderWindow $window;
int $map_font_size;
float $line_spacing;
std::unordered_map<wchar_t, sf::Sprite> $sprites;
sf::Font $font;
sf::Color $default_fg;
sf::Color $default_bg;
sf::Texture $font_texture;
sf::Glyph $base_glyph;
sf::Sprite $bg_sprite;
sf::FloatRect $grid_bounds;
sf::Font $font;
sf::Text $ui_text;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
sf::Color $default_fg;
sf::Color $default_bg;
ANSIParser $ansi;
std::unordered_map<wchar_t, sf::Sprite> $sprites;
sf::Glyph $base_glyph;
sf::FloatRect $grid_bounds;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
sf::FloatRect $text_bounds;
SFMLRender();
@ -61,8 +63,8 @@ struct SFMLRender {
void draw_sprite(sf::Sprite &sprite, sf::Shader *shader);
void center_panel(Panel &panel);
bool poll_event(sf::Event &event) {
return $window.pollEvent(event);
std::optional<sf::Event> poll_event() {
return $window.pollEvent();
}
void close() { return $window.close(); }

@ -80,8 +80,7 @@ int main(int argc, char *argv[]) {
println("LOADING IMAGE: {}", image_file);
// load the image from argv
sf::Image image;
image.loadFromFile(image_file);
sf::Image image(image_file);
// divide the image into cells
auto size = image.getSize();
@ -101,7 +100,7 @@ int main(int argc, char *argv[]) {
// sum the cell
for(unsigned int x = 0; x < cell.x ; x++) {
for(unsigned int y = 0; y < cell.y ; y++) {
auto pixel = image.getPixel((i*cell.x) + x, (j * cell.y) + y);
auto pixel = image.getPixel({(i*(unsigned int)cell.x) + x, (j * (unsigned int)cell.y) + y});
avg.r += pixel.r;
avg.g += pixel.g;
@ -144,8 +143,6 @@ int main(int argc, char *argv[]) {
return ftxui::canvas(drawing);
}));
sf::Event event;
int start_x = 0;
int start_y = 0;
int end_x = 600;
@ -153,8 +150,7 @@ int main(int argc, char *argv[]) {
int cur_x = start_x;
int cur_y = start_y;
sf::Texture texture;
texture.loadFromFile(image_file);
sf::Texture texture(image_file);
sf::Sprite sprite(texture);
panel.render();
@ -170,8 +166,8 @@ int main(int argc, char *argv[]) {
renderer.draw(panel, cur_x, cur_y);
renderer.display();
while(renderer.poll_event(event)) {
if(event.type == sf::Event::Closed) {
while(const auto event = renderer.poll_event()) {
if(event->is<sf::Event::Closed>()) {
renderer.close();
}
}

@ -3,6 +3,7 @@
#include <fmt/core.h>
using namespace fmt;
using std::make_shared;
namespace fs = std::filesystem;
SoundManager::SoundManager(std::string base_path) : $base_path(base_path) {
@ -13,31 +14,29 @@ void SoundManager::load(const std::string name, const std::string sound_path) {
// get the sound file with base_path
fs::path full_path = $base_path / sound_path;
// confirm it's there
dbc::check(fs::exists(full_path), format("sound file {} does not exist", sound_path));
dbc::check(fs::exists(full_path), fmt::format("sound file {} does not exist", sound_path));
// create the buffer and keep in the buffer map
SoundPair* pair = new SoundPair();
$sounds[name] = pair;
bool good = pair->buffer.loadFromFile(full_path.string());
dbc::check(good, format("failed to load sound {}", sound_path));
auto buffer = make_shared<sf::SoundBuffer>(full_path);
// set it on the sound and keep in the sound map
pair->sound.setBuffer(pair->buffer);
pair->sound.setRelativeToListener(false);
pair->sound.setPosition(0.0f, 0.0f, 1.0f);
auto sound = make_shared<sf::Sound>(*buffer);
sound->setRelativeToListener(false);
sound->setPosition({0.0f, 0.0f, 1.0f});
$sounds.try_emplace(name, buffer, sound);
}
void SoundManager::play(const std::string name) {
dbc::check($sounds.contains(name), format("sound {} is not loaded in map", name));
dbc::check($sounds.contains(name), fmt::format("sound {} is not loaded in map", name));
// get the sound from the sound map
auto pair = $sounds.at(name);
// play it
pair->sound.play();
pair.sound->play();
}
void SoundManager::playAt(const std::string name, float x, float y, float z) {
auto pair = $sounds.at(name);
pair->sound.setPosition(x, y, z);
pair->sound.play();
pair.sound->setPosition({x, y, z});
pair.sound->play();
}

@ -6,13 +6,13 @@
#include <SFML/Audio.hpp>
struct SoundPair {
sf::SoundBuffer buffer;
sf::Sound sound;
std::shared_ptr<sf::SoundBuffer> buffer;
std::shared_ptr<sf::Sound> sound;
};
struct SoundManager {
std::filesystem::path $base_path;
std::unordered_map<std::string, SoundPair* > $sounds;
std::unordered_map<std::string, SoundPair> $sounds;
SoundManager(std::string base_path);

@ -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);
}
}

@ -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);

@ -1,13 +0,0 @@
[wrap-file]
directory = openal-soft-1.23.1
source_url = https://github.com/kcat/openal-soft/archive/refs/tags/1.23.1.tar.gz
source_filename = openal-soft-1.23.1.tar.gz
source_hash = dfddf3a1f61059853c625b7bb03de8433b455f2f79f89548cbcbd5edca3d4a4a
patch_filename = openal-soft_1.23.1-2_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/openal-soft_1.23.1-2/get_patch
patch_hash = e03c3afe0bb40a931d25d41d92a08b90e3c33b217d1b47210b26ca6627eb3aa3
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/openal-soft_1.23.1-2/openal-soft-1.23.1.tar.gz
wrapdb_version = 1.23.1-2
[provide]
openal = openal_dep

@ -1,13 +1,14 @@
[wrap-file]
directory = SFML-2.6.2
source_url = https://github.com/SFML/SFML/archive/refs/tags/2.6.2.tar.gz
source_filename = 2.6.2.tar.gz
source_hash = 15ff4d608a018f287c6a885db0a2da86ea389e516d2323629e4d4407a7ce047f
patch_filename = sfml_2.6.2-1_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/sfml_2.6.2-1/get_patch
patch_hash = 36737f7fc6d616be791c6901b15414315b3a77df82dabc80b151d628e5d48386
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/sfml_2.6.2-1/2.6.2.tar.gz
wrapdb_version = 2.6.2-1
[wrap-git]
directory=SFML-3.0.0
url=https://github.com/SFML/SFML.git
revision=3.0.0
depth=1
method=cmake
[provide]
sfml = sfml_dep
sfml_audio = sfml_audio_dep
sfml_graphics = sfml_graphics_dep
sfml_main = sfml_main_dep
sfml_network = sfml_network_dep
sfml_system = sfml_system_dep
sfml_window = sfml_window_dep

Loading…
Cancel
Save