Compare commits
No commits in common. "f328f4023d8be8be9504d96b26ab9595d0a659a7" and "1b61689de61cacef43358a19c45425e8d1b6368d" have entirely different histories.
f328f4023d
...
1b61689de6
|
@ -0,0 +1,8 @@
|
|||
use gtk::prelude::*;
|
||||
|
||||
fn main() {
|
||||
gtk::init();
|
||||
for name in gtk::IconTheme::new().icon_names() {
|
||||
println!("{}", name);
|
||||
}
|
||||
}
|
|
@ -44,15 +44,13 @@ fn main() {
|
|||
|
||||
pub struct HexGridWindowPrivate {
|
||||
layout: gtk::Box,
|
||||
paintbrush_icon: gtk::Box,
|
||||
palette: gtk::ListBox,
|
||||
palette: gtk::Box,
|
||||
|
||||
drawing_area: DrawingArea,
|
||||
hex_address: labeled_field::LabeledField,
|
||||
canvas_address: labeled_field::LabeledField,
|
||||
|
||||
current_coordinate: Rc<RefCell<Option<AxialAddr>>>,
|
||||
paintbrush: Rc<RefCell<Option<tile::Tile>>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -97,12 +95,14 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
|||
let canvas_address = labeled_field::LabeledField::new("Canvas 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::Box::builder()
|
||||
.spacing(8)
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.hexpand(true)
|
||||
.build();
|
||||
|
||||
sidebar.append(&canvas_address);
|
||||
sidebar.append(&hex_address);
|
||||
sidebar.append(&paintbrush_icon);
|
||||
sidebar.append(&palette);
|
||||
|
||||
layout.append(&drawing_area);
|
||||
|
@ -117,8 +117,6 @@ impl ObjectSubclass for HexGridWindowPrivate {
|
|||
current_coordinate,
|
||||
layout,
|
||||
palette,
|
||||
paintbrush_icon,
|
||||
paintbrush: Rc::new(RefCell::new(None)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,12 +154,6 @@ impl ObjectImpl for HexGridWindowPrivate {
|
|||
let shallow_water = tile::Tile::new(&image, tile::Terrain::ShallowWater);
|
||||
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
|
||||
.append(&palette_entry::PaletteEntry::new(&badlands));
|
||||
self.palette
|
||||
|
@ -177,27 +169,6 @@ impl ObjectImpl for HexGridWindowPrivate {
|
|||
self.palette
|
||||
.append(&palette_entry::PaletteEntry::new(&swamp));
|
||||
|
||||
{
|
||||
let paintbrush = self.paintbrush.clone();
|
||||
let image = image.clone();
|
||||
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 canvas_address = self.canvas_address.clone();
|
||||
|
@ -257,13 +228,7 @@ impl ObjectImpl for HexGridWindowPrivate {
|
|||
}
|
||||
});
|
||||
}
|
||||
let click_controller = gtk::GestureClick::new();
|
||||
click_controller.connect_released(|_, press, x, y| {
|
||||
println!("key pressed: {} {} {}", press, x, y);
|
||||
});
|
||||
|
||||
self.drawing_area.add_controller(&motion_controller);
|
||||
self.drawing_area.add_controller(&click_controller);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,4 @@ impl PaletteEntry {
|
|||
|
||||
row
|
||||
}
|
||||
|
||||
pub fn terrain(&self) -> tile::Terrain {
|
||||
self.imp().terrain.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ impl From<&Terrain> for String {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Tile {
|
||||
pub terrain: Terrain,
|
||||
pub image: Pixbuf,
|
||||
|
|
Loading…
Reference in New Issue