Convert glade components to Rust and add the palette #26
|
@ -28,13 +28,13 @@ const DRAWING_ORIGIN: (f64, f64) = (1024. / 2., 768. / 2.);
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
enum Terrain {
|
||||
Empty,
|
||||
Mountain,
|
||||
Grasslands,
|
||||
ShallowWater,
|
||||
DeepWater,
|
||||
Badlands,
|
||||
DeepWater,
|
||||
Desert,
|
||||
Empty,
|
||||
Grasslands,
|
||||
Mountain,
|
||||
ShallowWater,
|
||||
Swamp,
|
||||
}
|
||||
|
||||
|
@ -113,6 +113,7 @@ fn main() {
|
|||
#[derive(Default)]
|
||||
pub struct HexGridWindowPrivate {
|
||||
layout: gtk::Box,
|
||||
palette: gtk::Box,
|
||||
|
||||
drawing_area: DrawingArea,
|
||||
hex_address: Label,
|
||||
|
@ -128,6 +129,7 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
|||
type ParentType = gtk::ApplicationWindow;
|
||||
|
||||
fn new() -> Self {
|
||||
println!("hexGridWindowPrivate::new()");
|
||||
let current_coordinate = Rc::new(RefCell::new(None));
|
||||
|
||||
let drawing_area = DrawingArea::builder()
|
||||
|
@ -195,8 +197,15 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
|||
|
||||
hex_address_row.append(&hex_address);
|
||||
|
||||
let palette = gtk::Box::builder()
|
||||
.spacing(8)
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.hexpand(true)
|
||||
.build();
|
||||
|
||||
sidebar.append(&canvas_address_row);
|
||||
sidebar.append(&hex_address_row);
|
||||
sidebar.append(&palette);
|
||||
|
||||
layout.append(&drawing_area);
|
||||
layout.append(&sidebar);
|
||||
|
@ -209,12 +218,14 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
|||
canvas_address,
|
||||
current_coordinate,
|
||||
layout,
|
||||
palette,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for HexGridWindowPrivate {
|
||||
fn constructed(&self) {
|
||||
println!("HexGridWindowPrivate::constructed()");
|
||||
self.parent_constructed();
|
||||
|
||||
let map_text_resource = resources_lookup_data(
|
||||
|
@ -236,14 +247,29 @@ impl ObjectImpl for HexGridWindowPrivate {
|
|||
.unwrap();
|
||||
|
||||
let image = reader.decode().unwrap();
|
||||
let deep_water = Tile::new(&image, Terrain::DeepWater);
|
||||
let shallow_water = Tile::new(&image, Terrain::ShallowWater);
|
||||
let grasslands = Tile::new(&image, Terrain::Grasslands);
|
||||
let desert = Tile::new(&image, Terrain::Desert);
|
||||
let mountain = Tile::new(&image, Terrain::Mountain);
|
||||
let badlands = Tile::new(&image, Terrain::Badlands);
|
||||
let deep_water = Tile::new(&image, Terrain::DeepWater);
|
||||
let desert = Tile::new(&image, Terrain::Desert);
|
||||
let grasslands = Tile::new(&image, Terrain::Grasslands);
|
||||
let mountain = Tile::new(&image, Terrain::Mountain);
|
||||
let shallow_water = Tile::new(&image, Terrain::ShallowWater);
|
||||
let swamp = Tile::new(&image, Terrain::Swamp);
|
||||
|
||||
let badlands_image = gtk::Image::from_pixbuf(Some(&badlands.image));
|
||||
self.palette.append(&badlands_image);
|
||||
self.palette
|
||||
.append(>k::Image::from_pixbuf(Some(&deep_water.image)));
|
||||
self.palette
|
||||
.append(>k::Image::from_pixbuf(Some(&desert.image)));
|
||||
self.palette
|
||||
.append(>k::Image::from_pixbuf(Some(&grasslands.image)));
|
||||
self.palette
|
||||
.append(>k::Image::from_pixbuf(Some(&mountain.image)));
|
||||
self.palette
|
||||
.append(>k::Image::from_pixbuf(Some(&shallow_water.image)));
|
||||
self.palette
|
||||
.append(>k::Image::from_pixbuf(Some(&swamp.image)));
|
||||
|
||||
let motion_controller = gtk::EventControllerMotion::new();
|
||||
{
|
||||
let canvas_address = self.canvas_address.clone();
|
||||
|
|
Loading…
Reference in New Issue