use crate::*;
pub mod prelude
{
pub use super::MainLoop;
}
pub trait MainLoop
{
fn handle_event(&mut self, event : Event) -> bool;
fn update(&mut self);
fn draw(&mut self);
}
pub struct Context
{
pub(crate) thread_id : std::thread::ThreadId,
pub(crate) multi_media : Box<dyn ContextMultiMedia>,
pub(crate) pen : ContextPen,
_marker: PhantomData<std::rc::Rc<()>>,
}
pub(crate) static mut CONTEXT : Option<Context> = None;
#[doc(hidden)]
#[allow(dead_code)]
#[allow(static_mut_refs)]
pub(crate) fn ctx_ref() -> &'static Context
{
let ctx = unsafe { CONTEXT.as_ref().unwrap() };
assert_eq!(ctx.thread_id, std::thread::current().id(), "Can only use the context in the same thread");
ctx
}
#[doc(hidden)]
#[allow(dead_code)]
#[allow(static_mut_refs)]
pub(crate) fn ctx() -> &'static mut Context
{
let ctx = unsafe { CONTEXT.as_mut().unwrap() };
assert_eq!(ctx.thread_id, std::thread::current().id(), "Can only use the context in the same thread");
ctx
}
#[doc(hidden)]
#[allow(static_mut_refs)]
pub unsafe fn set_context(ctx : Option<Context>) -> Option<Context>
{
unsafe
{
match ctx
{
Some(ctx) =>
{
CONTEXT = Some(ctx);
return None;
},
None => {
CONTEXT.take()
}
}
}
}