Skip to content

Commit

Permalink
Make Rect methods public; refactor resize
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Oct 10, 2024
1 parent 953d596 commit e5caca0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct Camera {
pos: Vec2,
vel: Vec2,
snap: bool,
force: bool,
pub(crate) force: bool,
}

impl Camera {
Expand Down Expand Up @@ -130,6 +130,10 @@ impl Camera {
}
}

pub fn pos(&self) -> Vec2 {
self.pos
}

pub fn move_pos(&mut self, pos: Vec2) {
self.pos = pos;
self.snap = true;
Expand Down
5 changes: 5 additions & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ impl Engine {
self.set_default_font(handle);
}

pub(crate) fn resize(&mut self, size: UVec2) {
self.render.borrow_mut().resize(size);
self.camera.force = true;
}

/// Scene base draw, draw maps and entities
pub fn scene_base_draw(&mut self, w: &mut World) {
let viewport = self.viewport();
Expand Down
5 changes: 1 addition & 4 deletions src/platform/sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ impl Platform for SDLPlatform {
// Obtained samplerate might be different from requested
// platform_output_samplerate = obtained_spec.freq;
engine.init(setup);
engine
.render
.borrow_mut()
.resize(event_handler.window.drawable_size().into());
engine.resize(event_handler.window.drawable_size().into());

while !event_handler.wants_to_exit {
if let Err(err) = engine.handle_assets().await {
Expand Down
7 changes: 6 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ pub struct Rect {
}

impl Rect {
pub(crate) fn is_touching(&self, other: &Self) -> bool {
pub fn is_touching(&self, other: &Self) -> bool {
!(self.min.x > other.max.x
|| self.max.x < other.min.x
|| self.min.y > other.max.y
|| self.max.y < other.min.y)
}

pub fn contains_pos(&self, pos: Vec2) -> bool {
let Rect { min, max } = self;
pos.x >= min.x && pos.y >= min.y && pos.x <= max.x && pos.y <= max.y
}
}

/// SweepAxis
Expand Down

0 comments on commit e5caca0

Please sign in to comment.