Procházet zdrojové kódy

Fix bugs in text display caused by indices not being normalized.
Fix FPS '.' position
Fix FPS display width.
Fix text spacing in texture frame.

Sam Jaffe před 6 roky
rodič
revize
f973fdc0f9
2 změnil soubory, kde provedl 8 přidání a 3 odebrání
  1. 2 2
      engine/src/fps_counter.cxx
  2. 6 1
      engine/src/text_engine.cxx

+ 2 - 2
engine/src/fps_counter.cxx

@@ -28,7 +28,7 @@ fps_counter::~fps_counter() {}
 std::string fps_counter::fps(env::clock::duration const & since) const {
   auto fps = magnitude_ * env::clock::duration::period::den / since.count();
   std::string fps_str = std::to_string(fps);
-  fps_str.insert(fps_str.size() - digits_ + 1, ".");
+  fps_str.insert(fps_str.size() - digits_, ".");
   return fps_str;
 }
 
@@ -36,5 +36,5 @@ void fps_counter::set_frame_step(env::clock::duration const & since) {
   if (++counter_ != change_after_) { return; }
   counter_ = 0;
   text_engine_->create_text_cells(
-      glyphs_, {make_vector(5.f, 680.f), make_vector(20.f, 20.f), fps(since)});
+      glyphs_, {make_vector(5.f, 680.f), make_vector(10.f, 20.f), fps(since)});
 }

+ 6 - 1
engine/src/text_engine.cxx

@@ -37,7 +37,12 @@ text_engine::text_engine(std::string const & font,
     : font_(font), prototype_(to_object(font_material(font_), *manager)),
       glyphs_(glyph_locations(font_)) {
   // TODO (sjaffe): Also needs to be programmatic
-  prototype_.frame.size = make_vector(0.125f, 0.125f);
+  auto glyph_size = make_vector(0.125f, 0.125f);
+  // The font I chose is a monospace font where height = 2 * width
+  prototype_.frame.size = glyph_size / make_vector(2, 1);
+  for (auto & pair : glyphs_) {
+    pair.second *= glyph_size;
+  }
 }
 
 void text_engine::create_text_cells(std::vector<graphics::object> & out,