@@ -2,7 +2,9 @@ use std::io::{self, Read, Write};
2
2
3
3
use serde:: { Deserialize , Serialize } ;
4
4
5
- use reflector_platform:: { App , AppMode , AppOptions , Response , Window , WindowOptions } ;
5
+ use reflector_platform:: {
6
+ App , AppMode , AppOptions , Bitmap , Response , Window , WindowContext , WindowOptions ,
7
+ } ;
6
8
7
9
use coupler:: format:: clap:: * ;
8
10
use coupler:: format:: vst3:: * ;
@@ -86,8 +88,8 @@ impl Plugin for Gain {
86
88
}
87
89
}
88
90
89
- fn editor ( & mut self , _host : EditorHost , parent : & ParentWindow ) -> Self :: Editor {
90
- GainEditor :: open ( parent) . unwrap ( )
91
+ fn editor ( & mut self , host : EditorHost , parent : & ParentWindow ) -> Self :: Editor {
92
+ GainEditor :: open ( host , parent) . unwrap ( )
91
93
}
92
94
}
93
95
@@ -132,13 +134,46 @@ impl Processor for GainProcessor {
132
134
}
133
135
}
134
136
137
+ struct EditorState {
138
+ framebuffer : Vec < u32 > ,
139
+ _host : EditorHost ,
140
+ }
141
+
142
+ impl EditorState {
143
+ fn new ( host : EditorHost ) -> EditorState {
144
+ EditorState {
145
+ framebuffer : Vec :: new ( ) ,
146
+ _host : host,
147
+ }
148
+ }
149
+
150
+ fn handle_event ( & mut self , cx : & WindowContext , event : reflector_platform:: Event ) -> Response {
151
+ use reflector_platform:: Event ;
152
+
153
+ match event {
154
+ Event :: Frame => {
155
+ let scale = cx. window ( ) . scale ( ) ;
156
+ let size = cx. window ( ) . size ( ) ;
157
+ let width = ( size. width * scale) as usize ;
158
+ let height = ( size. height * scale) as usize ;
159
+ self . framebuffer . resize ( width * height, 0xFF000000 ) ;
160
+
161
+ cx. window ( ) . present ( Bitmap :: new ( & self . framebuffer , width, height) ) ;
162
+ }
163
+ _ => { }
164
+ }
165
+
166
+ Response :: Ignore
167
+ }
168
+ }
169
+
135
170
pub struct GainEditor {
136
171
_app : App ,
137
172
window : Window ,
138
173
}
139
174
140
175
impl GainEditor {
141
- fn open ( parent : & ParentWindow ) -> reflector_platform:: Result < GainEditor > {
176
+ fn open ( host : EditorHost , parent : & ParentWindow ) -> reflector_platform:: Result < GainEditor > {
142
177
let app = AppOptions :: new ( ) . mode ( AppMode :: Guest ) . build ( ) ?;
143
178
144
179
let mut options = WindowOptions :: new ( ) ;
@@ -151,7 +186,8 @@ impl GainEditor {
151
186
} ;
152
187
unsafe { options. raw_parent ( raw_parent) } ;
153
188
154
- let window = options. open ( app. handle ( ) , move |_cx, _event| Response :: Ignore ) ?;
189
+ let mut state = EditorState :: new ( host) ;
190
+ let window = options. open ( app. handle ( ) , move |cx, event| state. handle_event ( cx, event) ) ?;
155
191
156
192
window. show ( ) ;
157
193
0 commit comments