81 lines
2.4 KiB
Rust
81 lines
2.4 KiB
Rust
use gtk::gdk::Display;
|
|
use gtk::{
|
|
gio, glib, style_context_add_provider_for_display, Application, ApplicationWindow, CssProvider,
|
|
GestureDrag,
|
|
};
|
|
use gtk::{prelude::*, DrawingArea};
|
|
// use plotters::prelude::DrawingArea;
|
|
// mod backend;
|
|
mod data;
|
|
mod painter;
|
|
mod render;
|
|
mod tree;
|
|
mod window;
|
|
use data::{CoordType, Npz, Radar2d};
|
|
use painter::wgs84::{LatLonCoord, Mercator, Range};
|
|
use painter::Painter;
|
|
|
|
const APP_ID: &str = "org.gtk_rs.HelloWorld2";
|
|
|
|
fn main() -> glib::ExitCode {
|
|
// gio::resources_register_include!("window.gresource").expect("Failed to register resources");
|
|
// Create a new application
|
|
let app = Application::builder().application_id(APP_ID).build();
|
|
|
|
app.connect_startup(|_| load_css());
|
|
|
|
// 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 = Window::new(app);
|
|
|
|
let window = ApplicationWindow::builder()
|
|
.application(app)
|
|
.title("My GTK App")
|
|
.build();
|
|
|
|
let drawing_area = DrawingArea::new();
|
|
let path = "/Users/ruomu/test2.npz";
|
|
let data = Radar2d::<i8>::load(path, Npz).unwrap();
|
|
let gesture = GestureDrag::new();
|
|
|
|
// gesture.connect_drag_end(|s, x, y| {
|
|
// (&drawing_area).queue_draw();
|
|
// });
|
|
// drawing_area.add_controller(gesture);
|
|
drawing_area.set_draw_func(move |a, b, c, d| {
|
|
let projection = Mercator::new();
|
|
let aa = Range::from((*data.0.dim1.first().unwrap(), *data.0.dim1.last().unwrap()));
|
|
let ab = Range::from((*data.0.dim2.first().unwrap(), *data.0.dim2.last().unwrap()));
|
|
|
|
let coord = LatLonCoord::new(Some(aa), Some(ab), ((0, c), (0, d)), projection);
|
|
let painter: Painter<'_, f64, LatLonCoord<Mercator>> =
|
|
Painter::new(b, coord, c as u32, c as u32);
|
|
painter.draw_radar_2d(&data.0);
|
|
});
|
|
window.set_child(Some(&drawing_area));
|
|
window.set_default_width(1000);
|
|
window.set_default_height(800);
|
|
|
|
window.present();
|
|
}
|
|
|
|
fn load_css() {
|
|
// Load the CSS file and add it to the provider
|
|
let provider = CssProvider::new();
|
|
provider.load_from_data(include_str!("css/style.css"));
|
|
// Add the provider to the default screen
|
|
style_context_add_provider_for_display(
|
|
&Display::default().expect("Could not connect to a display."),
|
|
&provider,
|
|
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
);
|
|
}
|