Fixed issue that fonts weren't rescaled going fullscreen.
This commit is contained in:
parent
529a55859c
commit
959d385342
@ -1,7 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const allegro = @import("allegro");
|
const allegro = @import("allegro");
|
||||||
const engine = @import("engine.zig");
|
const engine = @import("engine.zig");
|
||||||
const paths = @import("paths.zig");
|
|
||||||
const Palette = @import("palette.zig").Palette;
|
const Palette = @import("palette.zig").Palette;
|
||||||
const Scene = @import("scene.zig").Scene;
|
const Scene = @import("scene.zig").Scene;
|
||||||
const Renderer = @import("renderer.zig").Renderer;
|
const Renderer = @import("renderer.zig").Renderer;
|
||||||
@ -80,16 +79,6 @@ pub const Context = struct {
|
|||||||
self.events.destroy();
|
self.events.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registerFonts(self: *Context) !void {
|
|
||||||
const viewport = self.renderer.viewport;
|
|
||||||
const fonts = &self.renderer.fonts;
|
|
||||||
try fonts.addFromFileTTF("default", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(32));
|
|
||||||
try fonts.addFromFileTTF("small", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(16));
|
|
||||||
try fonts.addFromFileTTF("extra-small", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(12));
|
|
||||||
try fonts.addFromFileTTF("large", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(64));
|
|
||||||
try fonts.addFromFileTTF("debug", paths.AssetsDir ++ "/fonts/Cabin-Regular.ttf", viewport.scaledInteger(16));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn quit(self: *Context) void {
|
pub fn quit(self: *Context) void {
|
||||||
self.shouldQuit = true;
|
self.shouldQuit = true;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
allegro.convertMemoryBitmaps();
|
allegro.convertMemoryBitmaps();
|
||||||
|
|
||||||
try context.registerFonts();
|
try renderer.registerFonts();
|
||||||
|
|
||||||
try context.switchToScene(TitleScene, null);
|
try context.switchToScene(TitleScene, null);
|
||||||
|
|
||||||
@ -85,9 +85,8 @@ pub fn main() !void {
|
|||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
allegro.c.ALLEGRO_EVENT_DISPLAY_CLOSE => context.quit(),
|
allegro.c.ALLEGRO_EVENT_DISPLAY_CLOSE => context.quit(),
|
||||||
allegro.c.ALLEGRO_EVENT_DISPLAY_RESIZE => {
|
allegro.c.ALLEGRO_EVENT_DISPLAY_RESIZE => {
|
||||||
context.renderer.resized(event.display.width, event.display.height);
|
|
||||||
try context.registerFonts();
|
|
||||||
_ = allegro.acknowledgeResize(allegro.Display{ .native = event.display.source.? });
|
_ = allegro.acknowledgeResize(allegro.Display{ .native = event.display.source.? });
|
||||||
|
context.renderer.resized();
|
||||||
},
|
},
|
||||||
allegro.c.ALLEGRO_EVENT_KEY_CHAR => {
|
allegro.c.ALLEGRO_EVENT_KEY_CHAR => {
|
||||||
switch (event.keyboard.keycode) {
|
switch (event.keyboard.keycode) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const allegro = @import("allegro");
|
const allegro = @import("allegro");
|
||||||
const engine = @import("engine.zig");
|
const engine = @import("engine.zig");
|
||||||
|
const paths = @import("paths.zig");
|
||||||
const Context = @import("context.zig").Context;
|
const Context = @import("context.zig").Context;
|
||||||
|
|
||||||
pub const Renderer = struct {
|
pub const Renderer = struct {
|
||||||
@ -109,8 +110,19 @@ pub const Renderer = struct {
|
|||||||
self.printText(font, color, screen.x, screen.y, alignment, fmt, args);
|
self.printText(font, color, screen.x, screen.y, alignment, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resized(self: *Renderer, width: i32, height: i32) void {
|
pub fn registerFonts(self: *Renderer) !void {
|
||||||
self.viewport.update(width, height);
|
const viewport = self.viewport;
|
||||||
|
const fonts = &self.fonts;
|
||||||
|
try fonts.addFromFileTTF("default", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(32));
|
||||||
|
try fonts.addFromFileTTF("small", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(16));
|
||||||
|
try fonts.addFromFileTTF("extra-small", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(12));
|
||||||
|
try fonts.addFromFileTTF("large", paths.AssetsDir ++ "/fonts/Pixellari.ttf", viewport.scaledInteger(64));
|
||||||
|
try fonts.addFromFileTTF("debug", paths.AssetsDir ++ "/fonts/Cabin-Regular.ttf", viewport.scaledInteger(16));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resized(self: *Renderer) void {
|
||||||
|
self.viewport.update(self.display.width(), self.display.height());
|
||||||
|
self.registerFonts() catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn takeScreenshot(self: Renderer) !void {
|
pub fn takeScreenshot(self: Renderer) !void {
|
||||||
@ -121,6 +133,6 @@ pub const Renderer = struct {
|
|||||||
pub fn toggleFullScreen(self: *Renderer) void {
|
pub fn toggleFullScreen(self: *Renderer) void {
|
||||||
var displayFlags = allegro.getDisplayFlags(self.display);
|
var displayFlags = allegro.getDisplayFlags(self.display);
|
||||||
_ = allegro.setDisplayFlag(self.display, allegro.NewDisplayFlags{ .FULLSCREEN_WINDOW = true }, !displayFlags.FULLSCREEN_WINDOW);
|
_ = allegro.setDisplayFlag(self.display, allegro.NewDisplayFlags{ .FULLSCREEN_WINDOW = true }, !displayFlags.FULLSCREEN_WINDOW);
|
||||||
self.viewport.update(self.display.width(), self.display.height());
|
self.resized();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user