Closed Cthutu closed 3 years ago
I've discovered the with_automatic_console_resize
method in BTermBuilder, but there are 2 problems with it.
1) The fonts still shrink and grow slightly when resizing the window. 2) When the window is enlarged to a certain point, it causes a crash.
This was building on Windows 10 with the latest version of Rltk. Below is the code I used to test it:
use rltk::{GameState, Rltk};
struct State {}
impl GameState for State {
fn tick(&mut self, ctx: &mut Rltk) {
ctx.cls();
ctx.print(1, 1, "Hello Rust World");
}
}
fn main() -> rltk::BError {
use rltk::RltkBuilder;
let context = RltkBuilder::simple80x50()
.with_automatic_console_resize(true)
.with_title("Roguelike Tutorial")
.build()?;
let gs = State {};
rltk::main_loop(context, gs)
}
Interestingly enough, it doesn't crash when maximising the window, only when dragging it.
Does the bracket-lib
example bench-scalable
work for you? It uses the resizable console. I couldn't get it to crash on my Win10 machine. When I have some time (probably after the book release; it's literally eating every spare minute right now) I'll see if I can reproduce the crash with your code.
The font's do scale a little (this is probably because you're stretching the OpenGL texture which is a multiple of the font's dimensions to a window, which is not. The solution to stop the warping of characters is to either put a slight margin within the window, or restrict the inner size of the window to a multiple of the font's dimensions.
As for the crash, I could not reproduce it in that demo.
This issue might be related to #178. In that issue, a few pixels of the tiles are getting shaved off the bottom of tiles. Could also be due to the window size not being a multiple of the font size. Maybe you're on to something with using the letterboxing. Kyzrati describes the letterboxing and calculations used in making Cogmind pixel-perfect. https://www.gridsagegames.com/blog/2014/09/fonts-in-roguelikes/
I just colour the right and lower margins black in my C++ ASCII engine: https://github.com/cthutu/agf. I get it for free due to the clamping settings on the colour and ASCII character code textures I use.
This does appear to be #178 , so I'll pursue it in there.
The scaling system is a lot smarter now. Check the "bench_scalable" example - it supports adding/removing characters on resize rather than just scaling the window. #239 has made this quite a bit more stable.
The latest scaling code should help with this. It only resizes the backing buffer to "natural" sizes, and adds gutters to avoid squishing - so the console grows/shrinks by a consistent amount.
I'm no longer able to reproduce this bug, so I'm closing the issue. Please reopen if you run into the problem again.
When I resize a BTerm after creation, the characters in the window grow and shrink with it. Is it possible to increase and decrease the number of characters in a BTerm, so as to keep the size of the characters constant?