Skip to content

Commit dc95048

Browse files
committed
boing-ggez: Make fullscreen
1 parent e203444 commit dc95048

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

boing-ggez/src/main.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod state;
1414
use std::env;
1515
use std::path::PathBuf;
1616

17-
use ggez::{event, GameResult};
17+
use ggez::{event, graphics::Rect, Context, GameError, GameResult};
1818

1919
use global_state::GlobalState;
2020

@@ -46,18 +46,55 @@ fn get_resource_dirs() -> Vec<PathBuf> {
4646
.collect()
4747
}
4848

49+
fn configure_window_and_viewport(context: &mut Context) -> Result<(), GameError> {
50+
let (drawable_width, drawable_height) = ggez::graphics::drawable_size(context);
51+
52+
let (new_drawable_width, new_drawable_height) =
53+
if drawable_width / drawable_height > WINDOW_WIDTH / WINDOW_HEIGHT {
54+
(
55+
WINDOW_HEIGHT * (drawable_width / drawable_height),
56+
WINDOW_HEIGHT,
57+
)
58+
} else {
59+
(
60+
WINDOW_WIDTH,
61+
WINDOW_WIDTH * (drawable_height / drawable_width),
62+
)
63+
};
64+
65+
ggez::graphics::set_drawable_size(context, new_drawable_width, new_drawable_height)?;
66+
67+
let tot_border_width = new_drawable_width - WINDOW_WIDTH;
68+
let tot_border_height = new_drawable_height - WINDOW_HEIGHT;
69+
70+
ggez::graphics::set_screen_coordinates(
71+
context,
72+
Rect::new(
73+
-tot_border_width / 2.,
74+
-tot_border_height / 2.,
75+
new_drawable_width,
76+
new_drawable_height,
77+
),
78+
)
79+
}
80+
4981
fn main() -> GameResult {
5082
let resource_dirs = get_resource_dirs();
5183

5284
let mut context_builder = ggez::ContextBuilder::new(GAME_ID, AUTHOR)
5385
.window_setup(ggez::conf::WindowSetup::default().title(WINDOW_TITLE))
54-
.window_mode(ggez::conf::WindowMode::default().dimensions(WINDOW_WIDTH, WINDOW_HEIGHT));
86+
.window_mode(
87+
ggez::conf::WindowMode::default().fullscreen_type(ggez::conf::FullscreenType::Desktop),
88+
);
5589

5690
for dir in resource_dirs {
5791
context_builder = context_builder.add_resource_path(dir);
5892
}
5993

6094
let (mut context, event_loop) = context_builder.build()?;
95+
96+
configure_window_and_viewport(&mut context)?;
97+
6198
let mut state = GlobalState::new(&mut context);
6299

63100
state.play_music(&mut context)?;

0 commit comments

Comments
 (0)