diff --git a/demo/android/rust/src/lib.rs b/demo/android/rust/src/lib.rs index 9a1dae22..78f27037 100644 --- a/demo/android/rust/src/lib.rs +++ b/demo/android/rust/src/lib.rs @@ -14,6 +14,7 @@ extern crate lazy_static; use jni::{JNIEnv, JavaVM}; use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JString, JValue}; use pathfinder_demo::DemoApp; +use pathfinder_demo::Options; use pathfinder_demo::window::{Event, SVGPath, Window, WindowSize}; use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_gl::GLVersion; @@ -56,7 +57,8 @@ pub unsafe extern "system" fn }); DEMO_APP.with(|demo_app| { 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)); }); } diff --git a/demo/common/src/lib.rs b/demo/common/src/lib.rs index db844cd8..86d53d07 100644 --- a/demo/common/src/lib.rs +++ b/demo/common/src/lib.rs @@ -105,12 +105,13 @@ pub struct DemoApp where W: Window { } impl DemoApp where W: Window { - pub fn new(window: W, window_size: WindowSize) -> DemoApp { + pub fn new(window: W, window_size: WindowSize, mut options: Options) -> DemoApp { let expire_message_event_id = window.create_user_event_id(); let device = GLDevice::new(window.gl_version(), window.gl_default_framebuffer()); let resources = window.resource_loader(); - let options = Options::get(); + + options.command_line_overrides(); let view_box_size = view_box_size(options.mode, &window_size); @@ -717,13 +718,25 @@ pub struct RenderScene { #[derive(Clone)] pub struct Options { - jobs: Option, - mode: Mode, - input_path: SVGPath, + pub jobs: Option, + pub mode: Mode, + 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 { - fn get() -> Options { + fn command_line_overrides(&mut self) { let matches = App::new("tile-svg") .arg( 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)) .get_matches(); - let jobs: Option = matches - .value_of("jobs") - .map(|string| string.parse().unwrap()); + if let Some(jobs) = matches.value_of("jobs") { + self.jobs = jobs.parse().ok(); + } - let mode = if matches.is_present("3d") { - Mode::ThreeD + if matches.is_present("3d") { + self.mode = Mode::ThreeD; } else if matches.is_present("vr") { - Mode::VR - } else { - Mode::TwoD - }; + self.mode = Mode::VR; + } - let input_path = match matches.value_of("INPUT") { - None => SVGPath::Default, - Some(path) => SVGPath::Path(PathBuf::from(path)), + if let Some(path) = matches.value_of("INPUT") { + self.input_path = SVGPath::Path(PathBuf::from(path)); }; - - Options { jobs, mode, input_path } } fn adjust_thread_pool_settings(&self, mut thread_pool_builder: ThreadPoolBuilder) -> ThreadPoolBuilder { diff --git a/demo/native/src/main.rs b/demo/native/src/main.rs index 0a2014d5..00c082c6 100644 --- a/demo/native/src/main.rs +++ b/demo/native/src/main.rs @@ -13,6 +13,7 @@ use jemallocator; use nfd::Response; use pathfinder_demo::DemoApp; +use pathfinder_demo::Options; use pathfinder_demo::window::{Event, Keycode, SVGPath, Window, WindowSize}; use pathfinder_geometry::basic::point::Point2DI32; use pathfinder_gl::GLVersion; @@ -34,7 +35,8 @@ const DEFAULT_WINDOW_HEIGHT: u32 = 800; fn main() { let window = WindowImpl::new(); 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 { let mut events = vec![app.window.get_event()];