Skip to content

Commit

Permalink
chore: resizable window
Browse files Browse the repository at this point in the history
  • Loading branch information
raklaptudirm committed Apr 27, 2024
1 parent 1455049 commit 4713c25
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions gui/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl GuiBuilder {
let (mut raylib, thread) = raylib::init()
.size(self.width, self.height)
.title(&self.title)
.resizable()
.build();
let textures = Textures::load(&mut raylib, &thread);
let board = Board::from_str(&self.fen).unwrap();
Expand All @@ -36,8 +37,6 @@ impl GuiBuilder {
raylib,
thread,
options: GuiOptions {
width: self.width,
height: self.height,
scale: self.scale,
board,
textures,
Expand All @@ -50,7 +49,7 @@ pub struct Gui {
raylib: RaylibHandle,
thread: RaylibThread,

options: GuiOptions,
pub options: GuiOptions,
}

impl Gui {
Expand All @@ -66,13 +65,9 @@ impl Gui {
}
}

struct GuiOptions {
width: i32,
height: i32,

scale: f32,

board: ataxx::Board,
pub struct GuiOptions {
pub scale: f32,
pub board: ataxx::Board,

textures: Textures,
}
Expand All @@ -91,13 +86,12 @@ impl<'a> Drawer<'a> {

fn draw_board(&mut self) {
self.drawer.clear_background(Color::BLACK);

self.drawer.draw_texture_ex(
&self.gui.textures.board,
Vector2::new(
self.gui.width as f32 / 2.0
self.drawer.get_screen_width() as f32 / 2.0
- self.gui.textures.board.width() as f32 * self.gui.scale / 2.0,
self.gui.height as f32 / 2.0
self.drawer.get_screen_height() as f32 / 2.0
- self.gui.textures.board.height() as f32 * self.gui.scale / 2.0,
),
0.0,
Expand All @@ -118,9 +112,9 @@ impl<'a> Drawer<'a> {
self.gui.textures.border.height() as f32,
);
let dst_rec = Rectangle::new(
self.gui.width as f32 / 2.0
self.drawer.get_screen_width() as f32 / 2.0
- self.gui.textures.border.width() as f32 * self.gui.scale / 2.0,
self.gui.height as f32 / 2.0
self.drawer.get_screen_height() as f32 / 2.0
- self.gui.textures.border.height() as f32 * self.gui.scale / 2.0,
self.gui.textures.border.width() as f32 * self.gui.scale,
self.gui.textures.border.height() as f32 * self.gui.scale,
Expand All @@ -145,9 +139,9 @@ impl<'a> Drawer<'a> {
};

let top_left = Vector2::new(
self.gui.width as f32 / 2.0 - 183.0 * self.gui.scale / 2.0
self.drawer.get_screen_width() as f32 / 2.0 - 183.0 * self.gui.scale / 2.0
+ sq.file() as u32 as f32 * (SQUARE_SIZE - 1.0) * self.gui.scale,
self.gui.height as f32 / 2.0 - 183.0 * self.gui.scale / 2.0
self.drawer.get_screen_height() as f32 / 2.0 - 183.0 * self.gui.scale / 2.0
+ sq.rank() as u32 as f32 * (SQUARE_SIZE - 1.0) * self.gui.scale,
);

Expand Down

0 comments on commit 4713c25

Please sign in to comment.