1
- use baseview:: gl:: GlConfig ;
1
+ use baseview:: gl:: { GlConfig , GlContext } ;
2
2
use baseview:: {
3
3
Event , EventStatus , MouseEvent , PhyPoint , Size , Window , WindowEvent , WindowHandler , WindowInfo ,
4
4
WindowOpenOptions , WindowScalePolicy ,
@@ -7,42 +7,45 @@ use femtovg::renderer::OpenGl;
7
7
use femtovg:: { Canvas , Color } ;
8
8
9
9
struct FemtovgExample {
10
+ _window : Window ,
11
+ gl_context : GlContext ,
10
12
canvas : Canvas < OpenGl > ,
11
13
current_size : WindowInfo ,
12
14
current_mouse_position : PhyPoint ,
13
15
damaged : bool ,
14
16
}
15
17
16
18
impl FemtovgExample {
17
- fn new ( window : & mut Window ) -> Self {
18
- let context = window. gl_context ( ) . unwrap ( ) ;
19
- unsafe { context . make_current ( ) } ;
19
+ fn new ( window : Window ) -> Self {
20
+ let gl_context = window. gl_context ( ) . unwrap ( ) ;
21
+ unsafe { gl_context . make_current ( ) } ;
20
22
21
23
let renderer =
22
- unsafe { OpenGl :: new_from_function ( |s| context . get_proc_address ( s) ) } . unwrap ( ) ;
24
+ unsafe { OpenGl :: new_from_function ( |s| gl_context . get_proc_address ( s) ) } . unwrap ( ) ;
23
25
24
26
let mut canvas = Canvas :: new ( renderer) . unwrap ( ) ;
25
27
// TODO: get actual window width
26
28
canvas. set_size ( 512 , 512 , 1.0 ) ;
27
29
28
- unsafe { context . make_not_current ( ) } ;
30
+ unsafe { gl_context . make_not_current ( ) } ;
29
31
Self {
30
32
canvas,
31
33
current_size : WindowInfo :: from_logical_size ( Size { width : 512.0 , height : 512.0 } , 1.0 ) ,
32
34
current_mouse_position : PhyPoint { x : 256 , y : 256 } ,
33
35
damaged : true ,
36
+ _window : window,
37
+ gl_context,
34
38
}
35
39
}
36
40
}
37
41
38
42
impl WindowHandler for FemtovgExample {
39
- fn on_frame ( & mut self , window : & mut Window ) {
43
+ fn on_frame ( & mut self ) {
40
44
if !self . damaged {
41
45
return ;
42
46
}
43
47
44
- let context = window. gl_context ( ) . unwrap ( ) ;
45
- unsafe { context. make_current ( ) } ;
48
+ unsafe { self . gl_context . make_current ( ) } ;
46
49
47
50
let screen_height = self . canvas . height ( ) ;
48
51
let screen_width = self . canvas . width ( ) ;
@@ -70,12 +73,12 @@ impl WindowHandler for FemtovgExample {
70
73
71
74
// Tell renderer to execute all drawing commands
72
75
self . canvas . flush ( ) ;
73
- context . swap_buffers ( ) ;
74
- unsafe { context . make_not_current ( ) } ;
76
+ self . gl_context . swap_buffers ( ) ;
77
+ unsafe { self . gl_context . make_not_current ( ) } ;
75
78
self . damaged = false ;
76
79
}
77
80
78
- fn on_event ( & mut self , _window : & mut Window , event : Event ) -> EventStatus {
81
+ fn on_event ( & mut self , event : Event ) -> EventStatus {
79
82
match event {
80
83
Event :: Window ( WindowEvent :: Resized ( size) ) => {
81
84
let phy_size = size. physical_size ( ) ;
0 commit comments