use hexga_math::prelude::*;
use crate::*;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq, Default)]
pub enum CursorIcon
{
#[default]
Default,
Help,
Pointer,
Wait,
Crosshair,
Text,
Move,
NotAllowed,
EWResize,
NSResize,
NESWResize,
NWSEResize,
}
pub trait ContextWindow
{
fn get_clipboard(&mut self) -> Option<String>;
fn set_clipboard(&mut self, text : &str);
fn dpi_scale(&mut self) -> float;
fn is_dpi_hight(&mut self) -> bool;
fn quit(&mut self);
fn request_quit(&mut self);
fn get_position(&mut self) -> Point2;
fn set_position(&mut self, pos : Point2);
fn get_screen_size_tuple(&mut self) -> Point2;
fn set_size(&mut self, size : Point2);
fn set_fullscreen(&mut self, fullscreen: bool);
fn show_keyboard(&mut self, show: bool);
fn show_mouse(&mut self, show: bool);
fn grab_mouse(&mut self, grab: bool);
fn set_mouse_cursor(&mut self, cursor_icon: CursorIcon);
}
impl ContextWindow for ()
{
fn get_clipboard(&mut self) -> Option<String> { None }
fn set_clipboard(&mut self, _text : &str) {}
fn dpi_scale(&mut self) -> f32 { 1.0 }
fn is_dpi_hight(&mut self) -> bool { false }
fn quit(&mut self) {}
fn request_quit(&mut self) {}
fn get_position(&mut self) -> Point2 { Point2::ZERO }
fn set_position(&mut self, _pos : Point2) {}
fn get_screen_size_tuple(&mut self) -> Point2 { Point2::ONE }
fn set_size(&mut self, _size : Point2) {}
fn set_fullscreen(&mut self, _fullscreen: bool) {}
fn show_keyboard(&mut self, _show: bool) {}
fn show_mouse(&mut self, _show: bool) {}
fn grab_mouse(&mut self, _grab: bool) {}
fn set_mouse_cursor(&mut self, _cursor_icon: CursorIcon) {}
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct WindowParam
{
pub title: String,
pub size : Point2,
pub high_dpi: bool,
pub fullscreen: bool,
pub sample_count: u32,
pub resizable: bool,
pub icon: Option<Icon>,
pub platform: Platform,
}
impl Default for WindowParam
{
fn default() -> Self
{
Self { title: "hexga window".to_owned(), size : point2(960, 540), high_dpi: false, fullscreen: false, sample_count: 1, resizable: true, icon: None, platform: Platform::default() }
}
}
#[derive(PartialEq, Eq, Hash, Clone)]
pub struct Icon {
pub rgba_16x16: [u8; 16 * 16 * 4],
pub rgba_32x32: [u8; 32 * 32 * 4],
pub rgba_64x64: [u8; 64 * 64 * 4],
}
impl std::fmt::Debug for Icon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Icon").finish()
}
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "hexga_io", derive(Save, Load))]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct Platform
{
pub swap_interval: Option<i32>,
pub blocking_event_loop: bool,
pub framebuffer_alpha : bool,
}
impl Default for Platform
{
fn default() -> Self
{
Self
{
swap_interval: None,
blocking_event_loop: false,
framebuffer_alpha: false
}
}
}
impl WindowParam
{
pub fn new() -> Self { Self::default() }
pub fn title(mut self, title : impl Into<String>) -> Self { self.title = title.into(); self }
pub fn high_dpi(mut self, high_dpi : bool) -> Self { self.high_dpi = high_dpi; self }
pub fn fullscreen(mut self, fullscreen : bool) -> Self { self.fullscreen = fullscreen; self }
pub fn sample_count(mut self, sample_count : u32) -> Self { self.sample_count = sample_count; self }
pub fn resizeable(mut self, window_resizable : bool) -> Self { self.resizable = window_resizable; self }
pub fn icon(mut self, icon : Option<Icon>) -> Self { self.icon = icon; self }
pub fn platform(mut self, platform : Platform) -> Self { self.platform = platform; self }
}