Skip to content

Commit 7810801

Browse files
committed
fix issues changing UI scaling in game
1 parent 02cab3e commit 7810801

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

sulis_core/src/io/glium_adapter.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ pub struct GliumDisplay {
122122
scale_factor: f64,
123123
}
124124

125+
impl GliumDisplay {
126+
fn set_matrix(&mut self) {
127+
let (ui_x, ui_y) = Config::ui_size();
128+
self.matrix = [
129+
[2.0 / ui_x as f32, 0.0, 0.0, 0.0],
130+
[0.0, 2.0 / ui_y as f32, 0.0, 0.0],
131+
[0.0, 0.0, 1.0, 0.0],
132+
[-1.0, -1.0, 0.0, 1.0f32],
133+
];
134+
}
135+
}
136+
125137
struct GliumTexture {
126138
texture: Texture2d,
127139
sampler_fn: Box<dyn Fn(Sampler<Texture2d>) -> Sampler<Texture2d>>,
@@ -403,6 +415,8 @@ fn try_get_display(
403415
let (res_x, res_y) = Config::display_resolution();
404416
let vsync = Config::vsync_enabled();
405417

418+
log::info!("Creating display {res_x} by {res_y}");
419+
406420
let dims = LogicalSize::new(res_x as f64, res_y as f64);
407421

408422
let attrs = Window::default_attributes()
@@ -542,23 +556,19 @@ impl GliumDisplay {
542556

543557
window.set_cursor_visible(false);
544558

545-
let (ui_x, ui_y) = Config::ui_size();
546-
547-
Ok((GliumDisplay {
559+
let mut glium_display = GliumDisplay {
548560
display,
549561
window,
550562
monitor,
551563
base_program,
552564
swap_program,
553-
matrix: [
554-
[2.0 / ui_x as f32, 0.0, 0.0, 0.0],
555-
[0.0, 2.0 / ui_y as f32, 0.0, 0.0],
556-
[0.0, 0.0, 1.0, 0.0],
557-
[-1.0, -1.0, 0.0, 1.0f32],
558-
],
565+
matrix: [[0.0; 4]; 4],
559566
textures: HashMap::new(),
560567
scale_factor,
561-
}, event_loop))
568+
};
569+
glium_display.set_matrix();
570+
571+
Ok((glium_display, event_loop))
562572
}
563573

564574
pub(crate) fn get_display_configurations(&self) -> Vec<DisplayConfiguration> {
@@ -722,6 +732,11 @@ impl ApplicationHandler for GliumApp {
722732
if self.updater.is_exit() {
723733
event_loop.exit();
724734
} else if self.updater.recreate_window() {
735+
self.ui_x = Config::ui_width();
736+
self.ui_y = Config::ui_height();
737+
self.io.set_matrix();
738+
Cursor::update_max();
739+
725740
let window = &self.io.window;
726741
let (res_x, res_y) = Config::display_resolution();
727742
let (fullscreen, decorations) = configured_fullscreen(res_x, res_y, self.io.monitor.clone());

sulis_core/src/ui/widget.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl Widget {
584584
}
585585
}
586586

587-
pub(in crate::ui) fn setup_root(root: &Rc<RefCell<Widget>>) {
587+
pub(crate) fn setup_root(root: &Rc<RefCell<Widget>>) {
588588
let (ui_x, ui_y) = Config::ui_size();
589589
let mut root = root.borrow_mut();
590590
root.state.set_size(Size::new(ui_x, ui_y));

0 commit comments

Comments
 (0)