use blinc_platform::{Cursor, Window};
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(target_os = "android")]
use ndk::native_window::NativeWindow;
#[cfg(target_os = "android")]
pub struct AndroidWindow {
native_window: NativeWindow,
focused: AtomicBool,
running: AtomicBool,
scale_factor: f64,
}
#[cfg(target_os = "android")]
impl AndroidWindow {
pub fn new(native_window: NativeWindow) -> Self {
Self {
native_window,
focused: AtomicBool::new(true),
running: AtomicBool::new(true),
scale_factor: 1.0,
}
}
pub fn with_scale_factor(native_window: NativeWindow, scale_factor: f64) -> Self {
Self {
native_window,
focused: AtomicBool::new(true),
running: AtomicBool::new(true),
scale_factor,
}
}
pub fn set_scale_factor(&mut self, scale_factor: f64) {
self.scale_factor = scale_factor;
}
pub fn native_window(&self) -> &NativeWindow {
&self.native_window
}
pub(crate) fn set_focused(&self, focused: bool) {
self.focused.store(focused, Ordering::Relaxed);
}
pub(crate) fn set_running(&self, running: bool) {
self.running.store(running, Ordering::Relaxed);
}
pub fn is_running(&self) -> bool {
self.running.load(Ordering::Relaxed)
}
}
#[cfg(target_os = "android")]
impl Window for AndroidWindow {
fn id(&self) -> blinc_platform::WindowId {
blinc_platform::WindowId::PRIMARY
}
fn size(&self) -> (u32, u32) {
(
self.native_window.width() as u32,
self.native_window.height() as u32,
)
}
fn logical_size(&self) -> (f32, f32) {
let (w, h) = self.size();
let scale = self.scale_factor as f32;
(w as f32 / scale, h as f32 / scale)
}
fn scale_factor(&self) -> f64 {
self.scale_factor
}
fn set_title(&self, _title: &str) {
}
fn set_cursor(&self, _cursor: Cursor) {
}
fn request_redraw(&self) {
}
fn is_focused(&self) -> bool {
self.focused.load(Ordering::Relaxed)
}
fn is_visible(&self) -> bool {
self.running.load(Ordering::Relaxed)
}
}
#[cfg(target_os = "android")]
unsafe impl Send for AndroidWindow {}
#[cfg(target_os = "android")]
unsafe impl Sync for AndroidWindow {}
#[cfg(not(target_os = "android"))]
#[derive(Default)]
pub struct AndroidWindow {
_private: (),
}
#[cfg(not(target_os = "android"))]
impl AndroidWindow {
pub fn new() -> Self {
Self::default()
}
}
#[cfg(not(target_os = "android"))]
impl Window for AndroidWindow {
fn id(&self) -> blinc_platform::WindowId {
blinc_platform::WindowId::PRIMARY
}
fn size(&self) -> (u32, u32) {
(0, 0)
}
fn logical_size(&self) -> (f32, f32) {
(0.0, 0.0)
}
fn scale_factor(&self) -> f64 {
1.0
}
fn set_title(&self, _title: &str) {}
fn set_cursor(&self, _cursor: Cursor) {}
fn request_redraw(&self) {}
fn is_focused(&self) -> bool {
false
}
fn is_visible(&self) -> bool {
false
}
}