1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
extern crate gl;
use self::gl::types::*;
use crate::actor::Actor;
use crate::actor::EventHandler;
pub struct Stage<'a> {
width: u32,
height: u32,
viewport_width: u32,
viewport_height: u32,
visible: bool,
pub stage_actor: Actor<'a>,
}
impl<'a> Stage<'a> {
pub fn new(vw: u32, vh: u32, event_handler: Option<Box<dyn EventHandler + 'a>>) -> Self {
Stage {
width: 0,
height: 0,
viewport_width: vw,
viewport_height: vh,
visible: false,
stage_actor: Actor::new("stage_actor".to_string(), vw, vh, event_handler)
}
}
pub fn initialize(&mut self) {
self.stage_actor.init_gl(self.viewport_width, self.viewport_height);
}
pub fn set_visible(&mut self, visible: bool) {
self.visible = visible;
}
pub fn handle_input(&mut self, key: usize) {
println!("stage key: {}", key);
self.stage_actor.handle_input(key);
}
pub fn render(&mut self, shader_program: GLuint) {
if !self.visible {
return
}
self.stage_actor.animate();
self.stage_actor.render(shader_program, None);
}
pub fn add_actor(&mut self, mut actor: Actor<'a>) -> usize {
actor.init_gl(self.viewport_width, self.viewport_height);
self.stage_actor.sub_actor_list.push(actor);
self.stage_actor.sub_actor_list.len() - 1
}
}