-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from subalterngames/panel_background_optimization
Panel background optimization
- Loading branch information
Showing
18 changed files
with
249 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::{Rectangle, RectanglePixel}; | ||
use crate::Renderer; | ||
|
||
/// A background rectangle and a border rectangle, both in pixel units. | ||
#[derive(Clone)] | ||
pub(crate) struct PanelBackground { | ||
/// The background. | ||
pub background: RectanglePixel, | ||
/// The border. | ||
pub border: RectanglePixel, | ||
/// The rectangle in grid units. | ||
pub grid_rect: Rectangle, | ||
} | ||
|
||
impl PanelBackground { | ||
pub fn new(position: [u32; 2], size: [u32; 2], renderer: &Renderer) -> Self { | ||
let background = RectanglePixel::new( | ||
renderer.grid_to_pixel(position), | ||
renderer.grid_to_pixel(size), | ||
); | ||
let border = renderer.get_border_rect(position, size); | ||
let grid_rect = Rectangle::new(position, size); | ||
Self { | ||
background, | ||
border, | ||
grid_rect, | ||
} | ||
} | ||
|
||
/// Adjust the size by a delta in grid units. | ||
pub fn resize_by(&mut self, delta: [u32; 2], renderer: &Renderer) { | ||
self.grid_rect.size[0] += delta[0]; | ||
self.grid_rect.size[1] += delta[1]; | ||
let delta = renderer.grid_to_pixel(delta); | ||
self.background.size[0] += delta[0]; | ||
self.background.size[1] += delta[1]; | ||
self.border.size[0] += delta[0]; | ||
self.border.size[1] += delta[1]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// A rectangle has a position and a size. | ||
#[derive(Clone)] | ||
pub(crate) struct RectanglePixel { | ||
/// The position in pixel units. | ||
pub position: [f32; 2], | ||
/// The size in pixel units. | ||
pub size: [f32; 2], | ||
} | ||
|
||
impl RectanglePixel { | ||
pub fn new(position: [f32; 2], size: [f32; 2]) -> Self { | ||
Self { position, size } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.