@@ -6,7 +6,8 @@ extern crate gleam;
6
6
extern crate webrender;
7
7
extern crate winit;
8
8
9
- use direct_composition:: { DirectComposition , AngleVisual } ;
9
+ use direct_composition:: DirectComposition ;
10
+ use webrender:: api:: { ColorF , DeviceUintSize } ;
10
11
use winit:: os:: windows:: WindowExt ;
11
12
12
13
fn main ( ) {
@@ -25,23 +26,22 @@ fn main() {
25
26
webrender:: RendererOptions :: default ( ) ,
26
27
) . unwrap ( ) ;
27
28
28
- let visual1 = composition. create_angle_visual ( 300 , 200 ) ;
29
- visual1. set_offset_x ( 100. ) ;
30
- visual1. set_offset_y ( 50. ) ;
31
-
32
- let visual2 = composition. create_angle_visual ( 400 , 300 ) ;
29
+ let mut clicks: usize = 0 ;
33
30
let mut offset_y = 100. ;
34
- visual2. set_offset_x ( 200. ) ;
35
- visual2. set_offset_y ( offset_y) ;
31
+ let mut rects = [
32
+ Rectangle :: new ( & composition, DeviceUintSize :: new ( 300 , 200 ) , 0. , 0.2 , 0.4 , 1. ) ,
33
+ Rectangle :: new ( & composition, DeviceUintSize :: new ( 400 , 300 ) , 0. , 0.5 , 0. , 0.5 ) ,
34
+ ] ;
35
+ rects[ 0 ] . render ( ) ;
36
+ rects[ 1 ] . render ( ) ;
36
37
37
- composition. commit ( ) ;
38
+ rects[ 0 ] . visual . set_offset_x ( 100. ) ;
39
+ rects[ 0 ] . visual . set_offset_y ( 50. ) ;
38
40
39
- let mut rgba1 = ( 0. , 0.2 , 0.4 , 1. ) ;
40
- let mut rgba2 = ( 0. , 0.5 , 0. , 0.5 ) ;
41
- render_plain_rgba_frame ( & visual1, & rgba1) ;
42
- render_plain_rgba_frame ( & visual2, & rgba2) ;
41
+ rects[ 1 ] . visual . set_offset_x ( 200. ) ;
42
+ rects[ 1 ] . visual . set_offset_y ( offset_y) ;
43
43
44
- let mut clicks : u32 = 0 ;
44
+ composition . commit ( ) ;
45
45
46
46
events_loop. run_forever ( |event| {
47
47
if let winit:: Event :: WindowEvent { event, .. } = event {
@@ -56,7 +56,7 @@ fn main() {
56
56
} ;
57
57
offset_y = ( offset_y - 10. * dy) . max ( 0. ) . min ( 468. ) ;
58
58
59
- visual2 . set_offset_y ( offset_y) ;
59
+ rects [ 1 ] . visual . set_offset_y ( offset_y) ;
60
60
composition. commit ( ) ;
61
61
}
62
62
winit:: WindowEvent :: MouseInput {
@@ -65,14 +65,10 @@ fn main() {
65
65
..
66
66
} => {
67
67
clicks += 1 ;
68
- let ( rgba, visual) = if clicks % 2 == 0 {
69
- ( & mut rgba1, & visual1)
70
- } else {
71
- ( & mut rgba2, & visual2)
72
- } ;
73
- rgba. 1 += 0.1 ;
74
- rgba. 1 %= 1. ;
75
- render_plain_rgba_frame ( visual, rgba)
68
+ let rect = & mut rects[ clicks % 2 ] ;
69
+ rect. color . g += 0.1 ;
70
+ rect. color . g %= 1. ;
71
+ rect. render ( )
76
72
}
77
73
_ => { }
78
74
}
@@ -89,14 +85,31 @@ fn direct_composition_from_window(window: &winit::Window) -> DirectComposition {
89
85
}
90
86
}
91
87
92
- fn render_plain_rgba_frame ( visual : & AngleVisual , & ( r, g, b, a) : & ( f32 , f32 , f32 , f32 ) ) {
93
- visual. make_current ( ) ;
94
- visual. gleam . clear_color ( r, g, b, a) ;
95
- visual. gleam . clear ( gleam:: gl:: COLOR_BUFFER_BIT ) ;
96
- assert_eq ! ( visual. gleam. get_error( ) , 0 ) ;
97
- visual. present ( ) ;
88
+ struct Rectangle {
89
+ visual : direct_composition:: AngleVisual ,
90
+ color : ColorF ,
98
91
}
99
92
93
+ impl Rectangle {
94
+ fn new ( composition : & DirectComposition , size : DeviceUintSize ,
95
+ r : f32 , g : f32 , b : f32 , a : f32 )
96
+ -> Self {
97
+ Rectangle {
98
+ visual : composition. create_angle_visual ( size. width , size. height ) ,
99
+ color : ColorF { r, g, b, a } ,
100
+ }
101
+ }
102
+
103
+ fn render ( & self ) {
104
+ self . visual . make_current ( ) ;
105
+ self . visual . gleam . clear_color ( self . color . r , self . color . g , self . color . b , self . color . a ) ;
106
+ self . visual . gleam . clear ( gleam:: gl:: COLOR_BUFFER_BIT ) ;
107
+ assert_eq ! ( self . visual. gleam. get_error( ) , 0 ) ;
108
+ self . visual . present ( ) ;
109
+ }
110
+ }
111
+
112
+
100
113
#[ derive( Clone ) ]
101
114
struct Notifier {
102
115
events_proxy : winit:: EventsLoopProxy ,
0 commit comments