Merge pull request #88 from glowcoil/on_frame_window
add window argument to WindowHandler::on_frame()
This commit is contained in:
commit
663f9d5d4c
5 changed files with 14 additions and 15 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,14 +218,13 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
|
|
|
@ -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…
Add table
Reference in a new issue