Add an icon to represent the currently selected paintbrush
This commit is contained in:
parent
75c3c5c42d
commit
fa8cdf4492
|
@ -44,6 +44,7 @@ fn main() {
|
||||||
|
|
||||||
pub struct HexGridWindowPrivate {
|
pub struct HexGridWindowPrivate {
|
||||||
layout: gtk::Box,
|
layout: gtk::Box,
|
||||||
|
paintbrush_icon: gtk::Box,
|
||||||
palette: gtk::ListBox,
|
palette: gtk::ListBox,
|
||||||
|
|
||||||
drawing_area: DrawingArea,
|
drawing_area: DrawingArea,
|
||||||
|
@ -51,6 +52,7 @@ pub struct HexGridWindowPrivate {
|
||||||
canvas_address: labeled_field::LabeledField,
|
canvas_address: labeled_field::LabeledField,
|
||||||
|
|
||||||
current_coordinate: Rc<RefCell<Option<AxialAddr>>>,
|
current_coordinate: Rc<RefCell<Option<AxialAddr>>>,
|
||||||
|
paintbrush: Rc<RefCell<Option<tile::Tile>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -95,10 +97,12 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
||||||
let canvas_address = labeled_field::LabeledField::new("Canvas Address", "-----");
|
let canvas_address = labeled_field::LabeledField::new("Canvas Address", "-----");
|
||||||
let hex_address = labeled_field::LabeledField::new("Hex Address", "-----");
|
let hex_address = labeled_field::LabeledField::new("Hex Address", "-----");
|
||||||
|
|
||||||
|
let paintbrush_icon = gtk::Box::new(gtk::Orientation::Horizontal, 0);
|
||||||
let palette = gtk::ListBox::builder().hexpand(true).build();
|
let palette = gtk::ListBox::builder().hexpand(true).build();
|
||||||
|
|
||||||
sidebar.append(&canvas_address);
|
sidebar.append(&canvas_address);
|
||||||
sidebar.append(&hex_address);
|
sidebar.append(&hex_address);
|
||||||
|
sidebar.append(&paintbrush_icon);
|
||||||
sidebar.append(&palette);
|
sidebar.append(&palette);
|
||||||
|
|
||||||
layout.append(&drawing_area);
|
layout.append(&drawing_area);
|
||||||
|
@ -113,6 +117,8 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
||||||
current_coordinate,
|
current_coordinate,
|
||||||
layout,
|
layout,
|
||||||
palette,
|
palette,
|
||||||
|
paintbrush_icon,
|
||||||
|
paintbrush: Rc::new(RefCell::new(None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,6 +156,12 @@ impl ObjectImpl for HexGridWindowPrivate {
|
||||||
let shallow_water = tile::Tile::new(&image, tile::Terrain::ShallowWater);
|
let shallow_water = tile::Tile::new(&image, tile::Terrain::ShallowWater);
|
||||||
let swamp = tile::Tile::new(&image, tile::Terrain::Swamp);
|
let swamp = tile::Tile::new(&image, tile::Terrain::Swamp);
|
||||||
|
|
||||||
|
let paintbrush_image = gtk::Image::from_pixbuf(Some(&grasslands.image));
|
||||||
|
paintbrush_image.set_width_request(100);
|
||||||
|
paintbrush_image.set_height_request(88);
|
||||||
|
self.paintbrush_icon.append(&paintbrush_image);
|
||||||
|
*self.paintbrush.borrow_mut() = Some(grasslands.clone());
|
||||||
|
|
||||||
self.palette
|
self.palette
|
||||||
.append(&palette_entry::PaletteEntry::new(&badlands));
|
.append(&palette_entry::PaletteEntry::new(&badlands));
|
||||||
self.palette
|
self.palette
|
||||||
|
@ -165,11 +177,26 @@ impl ObjectImpl for HexGridWindowPrivate {
|
||||||
self.palette
|
self.palette
|
||||||
.append(&palette_entry::PaletteEntry::new(&swamp));
|
.append(&palette_entry::PaletteEntry::new(&swamp));
|
||||||
|
|
||||||
self.palette.connect_selected_rows_changed(|palette| {
|
{
|
||||||
let row: Option<palette_entry::PaletteEntry> =
|
let paintbrush = self.paintbrush.clone();
|
||||||
palette.selected_row().and_then(|r| r.downcast().ok());
|
let image = image.clone();
|
||||||
println!("selected rows changed to: {:?}", row.map(|r| r.terrain()));
|
let paintbrush_icon = self.paintbrush_icon.clone();
|
||||||
});
|
self.palette.connect_selected_rows_changed(move |palette| {
|
||||||
|
let row: Option<palette_entry::PaletteEntry> =
|
||||||
|
palette.selected_row().and_then(|r| r.downcast().ok());
|
||||||
|
if let Some(row) = row {
|
||||||
|
let new_tile = tile::Tile::new(&image, row.terrain());
|
||||||
|
*paintbrush.borrow_mut() = Some(new_tile.clone());
|
||||||
|
while let Some(icon) = paintbrush_icon.first_child() {
|
||||||
|
paintbrush_icon.remove(&icon);
|
||||||
|
}
|
||||||
|
let image = gtk::Image::from_pixbuf(Some(&new_tile.image));
|
||||||
|
image.set_width_request(100);
|
||||||
|
image.set_height_request(88);
|
||||||
|
paintbrush_icon.append(&image);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let motion_controller = gtk::EventControllerMotion::new();
|
let motion_controller = gtk::EventControllerMotion::new();
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,6 +58,7 @@ impl From<&Terrain> for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Tile {
|
pub struct Tile {
|
||||||
pub terrain: Terrain,
|
pub terrain: Terrain,
|
||||||
pub image: Pixbuf,
|
pub image: Pixbuf,
|
||||||
|
|
Loading…
Reference in New Issue