use coords::proj::Mercator; use coords::Mapper; use data::{Npz, Radar2d}; use gtk::prelude::*; use gtk::{gio, glib, Application, ApplicationWindow}; use std::ptr; mod coords; mod data; mod errors; mod monitor; mod pipeline; mod render; mod tree; mod window; use monitor::Monitor; use render::{BackgroundConfig, BackgroundWidget, ForegroundConfig, ForegroundWidget, Render}; const APP_ID: &str = "org.gtk_rs.HelloWorld2"; fn main() -> glib::ExitCode { // Load GL pointers from epoxy (GL context management library used by GTK). { #[cfg(target_os = "macos")] let library = unsafe { libloading::os::unix::Library::new("libepoxy.0.dylib") }.unwrap(); #[cfg(all(unix, not(target_os = "macos")))] let library = unsafe { libloading::os::unix::Library::new("libepoxy.so.0") }.unwrap(); #[cfg(windows)] let library = libloading::os::windows::Library::open_already_loaded("libepoxy-0.dll") .or_else(|_| libloading::os::windows::Library::open_already_loaded("epoxy-0.dll")) .unwrap(); epoxy::load_with(|name| { unsafe { library.get::<_>(name.as_bytes()) } .map(|symbol| *symbol) .unwrap_or(ptr::null()) }); } // gio::resources_register_include!("monitor.gresource").expect("Failed to register resources"); // Create a new application let app = Application::builder().application_id(APP_ID).build(); // Connect to "activate" signal of `app` app.connect_activate(build_ui); // Run the application app.run() } fn build_ui(app: &Application) { // Create a window and set the title let window = ApplicationWindow::builder() .application(app) .title("My GTK App") .build(); let mut background_config = BackgroundConfig::new(); let mut foreground_config = ForegroundConfig::new(); let background_widget = BackgroundWidget::new(background_config); let foreground_widget = ForegroundWidget::new(foreground_config); let render = Render::new(background_widget, foreground_widget); let path = "/Users/ruomu/projects/cinrad_g/test2.npz"; let data = Radar2d::::load(path, Npz).unwrap(); let projection = Mercator::new(); let mut mapper: Mapper = projection.into(); mapper.set_lat_range(29.960..30.764); mapper.set_lon_range(120.038..120.965); render.set_mapper(mapper); let monitor = Monitor::new(render); monitor.load_data_2d(data).unwrap(); window.set_child(Some(&monitor)); window.set_default_width(1000); window.set_default_height(800); window.present(); }