Allow demo apps to provide default options
This commit is contained in:
parent
ace5392701
commit
4db3fb6279
|
@ -14,6 +14,7 @@ extern crate lazy_static;
|
||||||
use jni::{JNIEnv, JavaVM};
|
use jni::{JNIEnv, JavaVM};
|
||||||
use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JString, JValue};
|
use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JString, JValue};
|
||||||
use pathfinder_demo::DemoApp;
|
use pathfinder_demo::DemoApp;
|
||||||
|
use pathfinder_demo::Options;
|
||||||
use pathfinder_demo::window::{Event, SVGPath, Window, WindowSize};
|
use pathfinder_demo::window::{Event, SVGPath, Window, WindowSize};
|
||||||
use pathfinder_geometry::basic::point::Point2DI32;
|
use pathfinder_geometry::basic::point::Point2DI32;
|
||||||
use pathfinder_gl::GLVersion;
|
use pathfinder_gl::GLVersion;
|
||||||
|
@ -56,7 +57,8 @@ pub unsafe extern "system" fn
|
||||||
});
|
});
|
||||||
DEMO_APP.with(|demo_app| {
|
DEMO_APP.with(|demo_app| {
|
||||||
gl::load_with(|name| egl::get_proc_address(name) as *const c_void);
|
gl::load_with(|name| egl::get_proc_address(name) as *const c_void);
|
||||||
*demo_app.borrow_mut() = Some(DemoApp::new(WindowImpl, window_size));
|
let options = Options::default();
|
||||||
|
*demo_app.borrow_mut() = Some(DemoApp::new(WindowImpl, window_size, options));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,12 +105,13 @@ pub struct DemoApp<W> where W: Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W> DemoApp<W> where W: Window {
|
impl<W> DemoApp<W> where W: Window {
|
||||||
pub fn new(window: W, window_size: WindowSize) -> DemoApp<W> {
|
pub fn new(window: W, window_size: WindowSize, mut options: Options) -> DemoApp<W> {
|
||||||
let expire_message_event_id = window.create_user_event_id();
|
let expire_message_event_id = window.create_user_event_id();
|
||||||
|
|
||||||
let device = GLDevice::new(window.gl_version(), window.gl_default_framebuffer());
|
let device = GLDevice::new(window.gl_version(), window.gl_default_framebuffer());
|
||||||
let resources = window.resource_loader();
|
let resources = window.resource_loader();
|
||||||
let options = Options::get();
|
|
||||||
|
options.command_line_overrides();
|
||||||
|
|
||||||
let view_box_size = view_box_size(options.mode, &window_size);
|
let view_box_size = view_box_size(options.mode, &window_size);
|
||||||
|
|
||||||
|
@ -717,13 +718,25 @@ pub struct RenderScene {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
jobs: Option<usize>,
|
pub jobs: Option<usize>,
|
||||||
mode: Mode,
|
pub mode: Mode,
|
||||||
input_path: SVGPath,
|
pub input_path: SVGPath,
|
||||||
|
hidden_field_for_future_proofing: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Options {
|
||||||
|
fn default() -> Self {
|
||||||
|
Options {
|
||||||
|
jobs: None,
|
||||||
|
mode: Mode::TwoD,
|
||||||
|
input_path: SVGPath::Default,
|
||||||
|
hidden_field_for_future_proofing: (),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
fn get() -> Options {
|
fn command_line_overrides(&mut self) {
|
||||||
let matches = App::new("tile-svg")
|
let matches = App::new("tile-svg")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("jobs")
|
Arg::with_name("jobs")
|
||||||
|
@ -738,24 +751,19 @@ impl Options {
|
||||||
.arg(Arg::with_name("INPUT").help("Path to the SVG file to render").index(1))
|
.arg(Arg::with_name("INPUT").help("Path to the SVG file to render").index(1))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let jobs: Option<usize> = matches
|
if let Some(jobs) = matches.value_of("jobs") {
|
||||||
.value_of("jobs")
|
self.jobs = jobs.parse().ok();
|
||||||
.map(|string| string.parse().unwrap());
|
}
|
||||||
|
|
||||||
let mode = if matches.is_present("3d") {
|
if matches.is_present("3d") {
|
||||||
Mode::ThreeD
|
self.mode = Mode::ThreeD;
|
||||||
} else if matches.is_present("vr") {
|
} else if matches.is_present("vr") {
|
||||||
Mode::VR
|
self.mode = Mode::VR;
|
||||||
} else {
|
}
|
||||||
Mode::TwoD
|
|
||||||
};
|
|
||||||
|
|
||||||
let input_path = match matches.value_of("INPUT") {
|
if let Some(path) = matches.value_of("INPUT") {
|
||||||
None => SVGPath::Default,
|
self.input_path = SVGPath::Path(PathBuf::from(path));
|
||||||
Some(path) => SVGPath::Path(PathBuf::from(path)),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Options { jobs, mode, input_path }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn adjust_thread_pool_settings(&self, mut thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
|
fn adjust_thread_pool_settings(&self, mut thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
use jemallocator;
|
use jemallocator;
|
||||||
use nfd::Response;
|
use nfd::Response;
|
||||||
use pathfinder_demo::DemoApp;
|
use pathfinder_demo::DemoApp;
|
||||||
|
use pathfinder_demo::Options;
|
||||||
use pathfinder_demo::window::{Event, Keycode, SVGPath, Window, WindowSize};
|
use pathfinder_demo::window::{Event, Keycode, SVGPath, Window, WindowSize};
|
||||||
use pathfinder_geometry::basic::point::Point2DI32;
|
use pathfinder_geometry::basic::point::Point2DI32;
|
||||||
use pathfinder_gl::GLVersion;
|
use pathfinder_gl::GLVersion;
|
||||||
|
@ -34,7 +35,8 @@ const DEFAULT_WINDOW_HEIGHT: u32 = 800;
|
||||||
fn main() {
|
fn main() {
|
||||||
let window = WindowImpl::new();
|
let window = WindowImpl::new();
|
||||||
let window_size = window.size();
|
let window_size = window.size();
|
||||||
let mut app = DemoApp::new(window, window_size);
|
let options = Options::default();
|
||||||
|
let mut app = DemoApp::new(window, window_size, options);
|
||||||
|
|
||||||
while !app.should_exit {
|
while !app.should_exit {
|
||||||
let mut events = vec![app.window.get_event()];
|
let mut events = vec![app.window.get_event()];
|
||||||
|
|
Loading…
Reference in New Issue