do it, ugly
This commit is contained in:
parent
74df2d95a4
commit
7d72cca2cf
|
|
@ -1,12 +1,12 @@
|
||||||
include(impl.cmake)
|
include(impl.cmake)
|
||||||
|
|
||||||
qt_add_executable(PROJECT-NAME
|
qt_add_library(PROJECT_NAME_ui STATIC
|
||||||
src/main.cxx
|
src/main.cxx
|
||||||
src/main_window.cxx
|
src/main_window.cxx
|
||||||
src/main_window.ui
|
src/main_window.ui
|
||||||
src/viewport.cxx
|
src/viewport.cxx
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(PROJECT-NAME PRIVATE Qt6::Gui Qt6::Widgets)
|
target_link_libraries(PROJECT_NAME_ui PRIVATE Qt6::Gui Qt6::Widgets)
|
||||||
target_link_libraries(PROJECT-NAME PRIVATE PROJECT_NAME_impl)
|
target_link_libraries(PROJECT_NAME_ui PRIVATE PROJECT_NAME_impl)
|
||||||
target_include_directories(PROJECT-NAME PRIVATE src)
|
target_include_directories(PROJECT_NAME_ui PRIVATE src)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ name = "PROJECT-NAME-impl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[lib]
|
|
||||||
crate-type = ["staticlib"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
PROJECT-NAME = {path = "../"}
|
PROJECT-NAME = {path = "../"}
|
||||||
|
|
||||||
|
|
|
||||||
7
ui/build.rs
Normal file
7
ui/build.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() {
|
||||||
|
println!("cargo::rustc-link-search=native=build/ui");
|
||||||
|
println!("cargo::rustc-link-lib=dylib=Qt6Core");
|
||||||
|
println!("cargo::rustc-link-lib=dylib=Qt6Gui");
|
||||||
|
println!("cargo::rustc-link-lib=dylib=Qt6Widgets");
|
||||||
|
println!("cargo::rustc-link-lib=dylib=stdc++");
|
||||||
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ public:
|
||||||
virtual void redraw(const RedrawArgs& args) = 0;
|
virtual void redraw(const RedrawArgs& args) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ICoreFactory : public IBoxed {
|
class ICoreFactory {
|
||||||
private:
|
private:
|
||||||
virtual ICore* new_xcb(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height) const = 0;
|
virtual ICore* new_xcb(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height) const = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use std::{ffi::c_void, num::NonZero, ptr::NonNull};
|
use PROJECT_NAME::{Core, init_gpu_inner};
|
||||||
|
use glam::UVec2;
|
||||||
|
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
|
||||||
|
|
||||||
use PROJECT_NAME::{Core, RedrawArgs, init_gpu_inner};
|
use crate::core::ICoreImpl;
|
||||||
use glam::{UVec2, uvec2};
|
|
||||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle};
|
|
||||||
|
|
||||||
use crate::vtable::ICoreImpl;
|
pub use factory::ICoreFactoryImpl;
|
||||||
|
|
||||||
mod vtable {
|
mod core {
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
use PROJECT_NAME::{Core, RedrawArgs};
|
use PROJECT_NAME::{Core, RedrawArgs};
|
||||||
|
|
@ -32,9 +32,9 @@ mod vtable {
|
||||||
}
|
}
|
||||||
|
|
||||||
static VTABLE: ICoreVTable = ICoreVTable {
|
static VTABLE: ICoreVTable = ICoreVTable {
|
||||||
destroy: destroy,
|
destroy,
|
||||||
configure: configure,
|
configure,
|
||||||
redraw: redraw,
|
redraw,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
@ -67,6 +67,51 @@ mod vtable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod factory {
|
||||||
|
use std::{ffi::c_void, num::NonZero, ptr::NonNull};
|
||||||
|
|
||||||
|
use glam::uvec2;
|
||||||
|
use raw_window_handle::{XcbDisplayHandle, XcbWindowHandle};
|
||||||
|
|
||||||
|
use crate::core::ICoreImpl;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct ICoreFactoryVTable {
|
||||||
|
new_xcb: unsafe extern "C" fn(
|
||||||
|
this: &mut ICoreFactoryImpl,
|
||||||
|
connection: NonNull<c_void>,
|
||||||
|
window: NonZero<u32>,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
) -> Box<ICoreImpl>,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn new_xcb(
|
||||||
|
_this: &mut ICoreFactoryImpl,
|
||||||
|
connection: NonNull<c_void>,
|
||||||
|
window: NonZero<u32>,
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
) -> Box<ICoreImpl> {
|
||||||
|
let display = XcbDisplayHandle::new(Some(connection), 0);
|
||||||
|
let window = XcbWindowHandle::new(window);
|
||||||
|
unsafe { crate::create_viewport(display, window, uvec2(width, height)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
static VTABLE: ICoreFactoryVTable = ICoreFactoryVTable { new_xcb };
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct ICoreFactoryImpl {
|
||||||
|
vtable: &'static ICoreFactoryVTable,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ICoreFactoryImpl {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
ICoreFactoryImpl { vtable: &VTABLE }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsafe fn create_viewport(
|
unsafe fn create_viewport(
|
||||||
display: impl Into<RawDisplayHandle>,
|
display: impl Into<RawDisplayHandle>,
|
||||||
window: impl Into<RawWindowHandle>,
|
window: impl Into<RawWindowHandle>,
|
||||||
|
|
@ -82,15 +127,3 @@ unsafe fn create_viewport(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ICoreImpl::new(Core::new(gpu, size))
|
ICoreImpl::new(Core::new(gpu, size))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
|
||||||
unsafe extern "C" fn rt4_viewport_create(
|
|
||||||
connection: NonNull<c_void>,
|
|
||||||
window: NonZero<u32>,
|
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
) -> Box<ICoreImpl> {
|
|
||||||
let display = XcbDisplayHandle::new(Some(connection), 0);
|
|
||||||
let window = XcbWindowHandle::new(window);
|
|
||||||
unsafe { create_viewport(display, window, uvec2(width, height)) }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,3 @@ extern "C" int run(int argc, char* argv[], ICoreFactory* factory) {
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" ICore* rt4_viewport_create(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height);
|
|
||||||
|
|
||||||
class CoreFactory : public ICoreFactory {
|
|
||||||
public:
|
|
||||||
void destroy() override {}
|
|
||||||
ICore* new_xcb(xcb_connection_t* connection, std::uint32_t window, std::uint32_t width, std::uint32_t height) const override {
|
|
||||||
return rt4_viewport_create(connection, window, width, height);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
|
||||||
CoreFactory factory;
|
|
||||||
return run(argc, argv, &factory);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
26
ui/src/main.rs
Normal file
26
ui/src/main.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
use std::ffi::{c_char, c_int};
|
||||||
|
|
||||||
|
use PROJECT_NAME_impl::ICoreFactoryImpl;
|
||||||
|
|
||||||
|
#[link(kind = "static", name = "PROJECT_NAME_ui")]
|
||||||
|
unsafe extern "C" {
|
||||||
|
fn run(argc: c_int, argv: *mut *mut c_char, factory: &ICoreFactoryImpl) -> c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let factory = ICoreFactoryImpl::new();
|
||||||
|
let mut args: Vec<_> = std::env::args().collect();
|
||||||
|
let mut argv: Vec<*mut c_char> = args
|
||||||
|
.iter_mut()
|
||||||
|
.map(|s| s.as_mut_ptr() as *mut c_char)
|
||||||
|
.collect();
|
||||||
|
argv.push(std::ptr::null_mut());
|
||||||
|
let exit_code = unsafe {
|
||||||
|
run(
|
||||||
|
args.len().try_into().expect("WAY too many arguments"),
|
||||||
|
argv.as_mut_ptr(),
|
||||||
|
&factory,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
std::process::exit(exit_code);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user