Skip to content

Commit 7c7acfd

Browse files
committed
update gain example to render black background
1 parent bb6e072 commit 7c7acfd

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

examples/gain/src/lib.rs

+41-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use std::io::{self, Read, Write};
22

33
use serde::{Deserialize, Serialize};
44

5-
use reflector_platform::{App, AppMode, AppOptions, Response, Window, WindowOptions};
5+
use reflector_platform::{
6+
App, AppMode, AppOptions, Bitmap, Response, Window, WindowContext, WindowOptions,
7+
};
68

79
use coupler::format::clap::*;
810
use coupler::format::vst3::*;
@@ -86,8 +88,8 @@ impl Plugin for Gain {
8688
}
8789
}
8890

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()
9193
}
9294
}
9395

@@ -132,13 +134,46 @@ impl Processor for GainProcessor {
132134
}
133135
}
134136

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+
135170
pub struct GainEditor {
136171
_app: App,
137172
window: Window,
138173
}
139174

140175
impl GainEditor {
141-
fn open(parent: &ParentWindow) -> reflector_platform::Result<GainEditor> {
176+
fn open(host: EditorHost, parent: &ParentWindow) -> reflector_platform::Result<GainEditor> {
142177
let app = AppOptions::new().mode(AppMode::Guest).build()?;
143178

144179
let mut options = WindowOptions::new();
@@ -151,7 +186,8 @@ impl GainEditor {
151186
};
152187
unsafe { options.raw_parent(raw_parent) };
153188

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))?;
155191

156192
window.show();
157193

0 commit comments

Comments
 (0)