/* Copyright 2023, Savanni D'Gerinel This file is part of the Luminescent Dreams Tools. Luminescent Dreams Tools is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Luminescent Dreams Tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Lumeto. If not, see . */ use cairo::{Context, Path}; use coordinates::{hex_map::parse_data, AxialAddr}; use gio::resources_lookup_data; use glib::{subclass::InitializingObject, Object}; use gtk::{ gdk_pixbuf::Pixbuf, gio, prelude::*, subclass::prelude::*, Application, CompositeTemplate, DrawingArea, Label, }; use image::io::Reader as ImageReader; use std::{cell::RefCell, io::Cursor, rc::Rc}; const APP_ID: &'static str = "com.luminescent-dreams.hex-grid"; const HEX_RADIUS: f64 = 50.; const MAP_RADIUS: usize = 3; const DRAWING_ORIGIN: (f64, f64) = (1024. / 2., 768. / 2.); #[derive(Clone, Debug)] enum Tile { Empty, Mountain, Grasslands, ShallowWater, DeepWater, Badlands, Desert, Swamp, } impl Tile { fn color(&self) -> (f64, f64, f64) { match self { Self::Empty => (0., 0., 0.), Self::Mountain => (0.5, 0.5, 0.5), Self::Grasslands => (0., 1., 0.), Self::ShallowWater => (0.5, 0.5, 1.), Self::DeepWater => (0., 0., 1.), Self::Badlands => (0.5, 0.25, 0.), Self::Desert => (1., 1., 0.), Self::Swamp => (0., 0.25, 0.), } } } impl Default for Tile { fn default() -> Self { Self::Empty } } impl From<&str> for Tile { fn from(s: &str) -> Self { match s { "m" => Self::Mountain, "g" => Self::Grasslands, "sw" => Self::ShallowWater, "dw" => Self::DeepWater, "b" => Self::Badlands, "d" => Self::Desert, "s" => Self::Swamp, _ => Self::Empty, } } } impl From for Tile { fn from(s: String) -> Self { Self::from(s.as_ref()) } } fn main() { gio::resources_register_include!("com.luminescent-dreams.hex-grid.gresource") .expect("Failed to register resources"); let app = Application::builder().application_id(APP_ID).build(); app.connect_activate(|app| { let window = HexGridWindow::new(app); window.present(); }); app.run(); } #[derive(CompositeTemplate, Default)] #[template(resource = "/com/luminescent-dreams/hex-grid/main.glade")] pub struct HexGridWindowPrivate { #[template_child] pub drawing_area: TemplateChild, #[template_child] pub hex_address: TemplateChild