Skip to content

Commit

Permalink
fix: volume println, canvas resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Xevion committed Apr 24, 2024
1 parent 02c526f commit 31d7322
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ fn main() {

let ctx = sdl2::init().unwrap();
let video_ctx = ctx.video().unwrap();
let mut window_size = Point::new(640, 480);

let window = match video_ctx
.window("rust-sdl2-emscripten", 640, 480)
.window("rust-sdl2-emscripten", window_size.x as u32, window_size.y as u32)
.position_centered()
.resizable()
.allow_highdpi()
Expand All @@ -90,8 +91,6 @@ fn main() {
Err(err) => panic!("failed to create canvas: {}", err),
};

// canvas.set_logical_size(1000, 1000);

let texture_creator = canvas.texture_creator();
let mut point = Point::new(0, 0);

Expand All @@ -114,7 +113,7 @@ fn main() {
},
|v| v,
);
print!("Volume: {}", volume);
println!("Volume: {}", volume);
mixer::Music::set_volume(volume as i32);

let music_data = RWops::from_bytes(MUSIC_DATA).unwrap();
Expand Down Expand Up @@ -157,6 +156,8 @@ fn main() {
Event::Window { win_event, .. } => match win_event {
sdl2::event::WindowEvent::Resized(w, h) => {
println!("Resized to {}x{}", w, h);
window_size.x = w;
window_size.y = h;
canvas.window_mut().set_size(w as u32, h as u32).unwrap();
}
_ => {}
Expand Down Expand Up @@ -229,7 +230,7 @@ fn main() {
let canvas_size = canvas.window().size();
if point.x < 0 {
point.x = canvas_size.0 as i32 - 32;
} else if point.x >= 640 {
} else if point.x >= canvas_size.0 as i32 {
point.x = 0;
}
if point.y < 0 {
Expand All @@ -244,7 +245,11 @@ fn main() {

let focused = ctx.mouse().focused_window_id().is_some();
if focused != previous_focus {
println!("Focus: {:?}", focused);
if focused {
println!("Focus gained");
} else {
println!("Focus lost");
}
previous_focus = focused;
}

Expand Down Expand Up @@ -286,7 +291,7 @@ fn main() {
&texture,
None,
Rect::new(
640i32 - (25i32 * text.len() as i32),
window_size.x - (25i32 * text.len() as i32),
0,
25 * text.len() as u32,
40,
Expand Down

0 comments on commit 31d7322

Please sign in to comment.