Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Add fullscreen support
Browse files Browse the repository at this point in the history
  • Loading branch information
darthdeus committed Apr 22, 2024
1 parent dca9278 commit 8c0e92f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# EXAMPLE=animated_text
# EXAMPLE=animated_sprites
# EXAMPLE=alpha_sprite
EXAMPLE=blood_canvas
# EXAMPLE=blood_canvas
# EXAMPLE=bloom
# EXAMPLE=custom_config
# EXAMPLE=cooldowns
Expand All @@ -15,6 +15,7 @@ EXAMPLE=blood_canvas
# EXAMPLE=egui
# EXAMPLE=exr-hdr-image
# EXAMPLE=full_game_loop
EXAMPLE=fullscreen
# EXAMPLE=framerate_vsync
# EXAMPLE=fragment-shader
# EXAMPLE=music
Expand Down
4 changes: 4 additions & 0 deletions comfy-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub struct GameConfig {
pub resolution: ResolutionConfig,
pub min_resolution: ResolutionConfig,

/// Initial config for fullscreen, only works on game launch.
pub fullscreen: bool,

pub target_framerate: u32,
pub vsync_enabled: bool,
pub desired_maximum_frame_latency: u32,
Expand Down Expand Up @@ -123,6 +126,7 @@ impl Default for GameConfig {

resolution,
min_resolution,
fullscreen: false,

target_framerate: 60,
vsync_enabled: true,
Expand Down
21 changes: 21 additions & 0 deletions comfy/examples/fullscreen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use comfy::*;

simple_game!("Fullscreen", GameState, config, setup, update);

fn config(config: GameConfig) -> GameConfig {
GameConfig { fullscreen: true, ..config }
}

pub struct GameState {}

impl GameState {
pub fn new(_c: &EngineState) -> Self {
Self {}
}
}

fn setup(_state: &mut GameState, _c: &mut EngineContext) {}

fn update(_state: &mut GameState, _c: &mut EngineContext) {
draw_text("Comfy likes fullscreen", Vec2::ZERO, PINK, TextAlign::Center);
}
7 changes: 6 additions & 1 deletion comfy/src/game_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn run_comfy_main_async(

let window = winit::window::WindowBuilder::new().with_title(title);

let window = match resolution {
let mut window = match resolution {
ResolutionConfig::Physical(w, h) => {
window.with_inner_size(winit::dpi::PhysicalSize::new(w, h))
}
Expand All @@ -64,6 +64,11 @@ pub async fn run_comfy_main_async(
}
};

if game_config().fullscreen {
window = window
.with_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
}

let window = window.build(&event_loop).unwrap();
let window = Box::leak(Box::new(window));

Expand Down

0 comments on commit 8c0e92f

Please sign in to comment.