Merge pull request #88 from glowcoil/on_frame_window
add window argument to WindowHandler::on_frame()
This commit is contained in:
commit
663f9d5d4c
|
@ -14,7 +14,7 @@ struct OpenWindowExample {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowHandler for OpenWindowExample {
|
impl WindowHandler for OpenWindowExample {
|
||||||
fn on_frame(&mut self) {
|
fn on_frame(&mut self, _window: &mut Window) {
|
||||||
while let Ok(message) = self.rx.pop() {
|
while let Ok(message) = self.rx.pop() {
|
||||||
println!("Message: {:?}", message);
|
println!("Message: {:?}", message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,15 +217,14 @@ impl WindowState {
|
||||||
&mut *(state_ptr as *mut Self)
|
&mut *(state_ptr as *mut Self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn trigger_event(&mut self, event: Event){
|
pub(super) fn trigger_event(&mut self, event: Event) {
|
||||||
self.window_handler.on_event(
|
self.window_handler
|
||||||
&mut crate::Window::new(&mut self.window),
|
.on_event(&mut crate::Window::new(&mut self.window), event);
|
||||||
event
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn trigger_frame(&mut self){
|
pub(super) fn trigger_frame(&mut self) {
|
||||||
self.window_handler.on_frame()
|
self.window_handler
|
||||||
|
.on_frame(&mut crate::Window::new(&mut self.window));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn process_native_key_event(
|
pub(super) fn process_native_key_event(
|
||||||
|
@ -236,11 +235,11 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Don't call until WindowState pointer is stored in view
|
/// Don't call until WindowState pointer is stored in view
|
||||||
unsafe fn setup_timer(window_state_ptr: *mut WindowState){
|
unsafe fn setup_timer(window_state_ptr: *mut WindowState) {
|
||||||
extern "C" fn timer_callback(
|
extern "C" fn timer_callback(
|
||||||
_: *mut __CFRunLoopTimer,
|
_: *mut __CFRunLoopTimer,
|
||||||
window_state_ptr: *mut c_void,
|
window_state_ptr: *mut c_void,
|
||||||
){
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let window_state = &mut *(
|
let window_state = &mut *(
|
||||||
window_state_ptr as *mut WindowState
|
window_state_ptr as *mut WindowState
|
||||||
|
@ -276,8 +275,8 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call when freeing view
|
/// Call when freeing view
|
||||||
pub(super) unsafe fn remove_timer(&mut self){
|
pub(super) unsafe fn remove_timer(&mut self) {
|
||||||
if let Some(frame_timer) = self.frame_timer.take(){
|
if let Some(frame_timer) = self.frame_timer.take() {
|
||||||
CFRunLoop::get_current()
|
CFRunLoop::get_current()
|
||||||
.remove_timer(&frame_timer, kCFRunLoopDefaultMode);
|
.remove_timer(&frame_timer, kCFRunLoopDefaultMode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ unsafe extern "system" fn wnd_proc(
|
||||||
WM_TIMER => {
|
WM_TIMER => {
|
||||||
match wparam {
|
match wparam {
|
||||||
WIN_FRAME_TIMER => {
|
WIN_FRAME_TIMER => {
|
||||||
(&*window_state_ptr).borrow_mut().handler.on_frame();
|
(&*window_state_ptr).borrow_mut().handler.on_frame(&mut window);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::win as platform;
|
||||||
use crate::x11 as platform;
|
use crate::x11 as platform;
|
||||||
|
|
||||||
pub trait WindowHandler {
|
pub trait WindowHandler {
|
||||||
fn on_frame(&mut self);
|
fn on_frame(&mut self, window: &mut Window);
|
||||||
fn on_event(&mut self, window: &mut Window, event: Event);
|
fn on_event(&mut self, window: &mut Window, event: Event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,7 @@ impl Window {
|
||||||
while self.event_loop_running {
|
while self.event_loop_running {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let until_next_frame = if now > next_frame {
|
let until_next_frame = if now > next_frame {
|
||||||
handler.on_frame();
|
handler.on_frame(&mut crate::Window::new(self));
|
||||||
|
|
||||||
next_frame = Instant::now() + self.frame_interval;
|
next_frame = Instant::now() + self.frame_interval;
|
||||||
self.frame_interval
|
self.frame_interval
|
||||||
|
|
Loading…
Reference in a new issue