1
0
Fork 0

Add a HasRawWindowHandle wrapper struct

This commit is contained in:
Robbert van der Helm 2022-02-06 00:06:01 +01:00
parent 4021b28155
commit 7a6bfa4573
3 changed files with 17 additions and 6 deletions

View file

@ -34,7 +34,8 @@ pub use param::range::Range;
pub use param::smoothing::{Smoother, SmoothingStyle}; pub use param::smoothing::{Smoother, SmoothingStyle};
pub use param::{BoolParam, FloatParam, IntParam, Param}; pub use param::{BoolParam, FloatParam, IntParam, Param};
pub use plugin::{ pub use plugin::{
BufferConfig, BusConfig, Editor, NoteEvent, Plugin, ProcessStatus, RawWindowHandle, Vst3Plugin, BufferConfig, BusConfig, Editor, EditorWindowHandle, NoteEvent, Plugin, ProcessStatus,
Vst3Plugin,
}; };
// The rest is either internal or already re-exported // The rest is either internal or already re-exported

View file

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
@ -21,9 +22,6 @@ use crate::buffer::Buffer;
use crate::context::{GuiContext, ProcessContext}; use crate::context::{GuiContext, ProcessContext};
use crate::param::internals::Params; use crate::param::internals::Params;
/// A raw window handle for platform and GUI framework agnostic editors.
pub use raw_window_handle::RawWindowHandle;
/// Basic functionality that needs to be implemented by a plugin. The wrappers will use this to /// Basic functionality that needs to be implemented by a plugin. The wrappers will use this to
/// expose the plugin in a particular plugin format. /// expose the plugin in a particular plugin format.
/// ///
@ -85,7 +83,7 @@ pub trait Plugin: Default + Send + Sync + 'static {
// instance. // instance.
fn create_editor<'a, 'context: 'a>( fn create_editor<'a, 'context: 'a>(
&'a self, &'a self,
parent: RawWindowHandle, parent: EditorWindowHandle,
context: Arc<dyn GuiContext + 'context>, context: Arc<dyn GuiContext + 'context>,
) -> Option<Box<dyn Editor + 'context>> { ) -> Option<Box<dyn Editor + 'context>> {
None None
@ -162,6 +160,17 @@ pub trait Editor {
// TODO: Resizing // TODO: Resizing
} }
/// A raw window handle for platform and GUI framework agnostic editors.
pub struct EditorWindowHandle {
pub handle: RawWindowHandle,
}
unsafe impl HasRawWindowHandle for EditorWindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle {
self.handle
}
}
/// We only support a single main input and output bus at the moment. /// We only support a single main input and output bus at the moment.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BusConfig { pub struct BusConfig {

View file

@ -51,6 +51,7 @@ use crate::plugin::{
}; };
use crate::wrapper::state::{ParamValue, State}; use crate::wrapper::state::{ParamValue, State};
use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy, u16strlcpy}; use crate::wrapper::util::{hash_param_id, process_wrapper, strlcpy, u16strlcpy};
use crate::EditorWindowHandle;
// Alias needed for the VST3 attribute macro // Alias needed for the VST3 attribute macro
use vst3_sys as vst3_com; use vst3_sys as vst3_com;
@ -1363,7 +1364,7 @@ impl<P: Plugin> IPlugView for WrapperView<P> {
.inner .inner
.plugin .plugin
.write() .write()
.create_editor(handle, self.inner.clone()); .create_editor(EditorWindowHandle { handle }, self.inner.clone());
kResultOk kResultOk
} else { } else {
kResultFalse kResultFalse