gdritter repos palladio / bd0dcd2
Split view into submodules Getty Ritter 6 years ago
1 changed file(s) with 8 addition(s) and 58 deletion(s). Collapse all Expand all
1 use gdk;
21 use gtk::{
32 self,
43 BoxExt,
1211 FileChooserExt,
1312 ButtonExt,
1413 };
15 use std::cell::RefCell;
1614 use std::process;
17 use std::rc::Rc;
1815
19 pub struct GridCanvas {
20 pub canvas: gtk::DrawingArea,
21 pub mouse_loc: Rc<RefCell<Option<(i32, i32)>>>,
22 }
23
24 impl GridCanvas {
25 fn new() -> GridCanvas {
26 let canvas = gtk::DrawingArea::new();
27 let mouse_loc = Rc::new(RefCell::new(Some((2, 2))));
28 let reader_mouse = mouse_loc.clone();
29 let writer_mouse = mouse_loc.clone();
30
31 canvas.connect_draw(move |cv, ctx| {
32 let w = cv.get_allocated_width();
33 let h = cv.get_allocated_height();
34 ctx.set_source_rgb(1.0, 1.0, 1.0);
35 ctx.rectangle(0.0, 0.0, w as f64, h as f64);
36 ctx.fill();
37
38 ctx.set_source_rgb(0.9, 0.9, 0.9);
39 reader_mouse.borrow().map(|(x, y)| {
40 ctx.rectangle(x as f64 * 32.0, y as f64 * 32.0, 32.0, 32.0);
41 ctx.fill();
42 });
43
44 ctx.set_source_rgb(0.8, 0.8, 0.8);
45 for x in 0..((w / 32) + 1) {
46 ctx.move_to(x as f64 * 32.0, 0.0);
47 ctx.line_to(x as f64 * 32.0, h as f64);
48 ctx.stroke();
49 }
50 for y in 0..((h / 32) + 1) {
51 ctx.move_to(0.0, y as f64 * 32.0);
52 ctx.line_to(w as f64, y as f64 * 32.0);
53 ctx.stroke();
54 }
55 gtk::Inhibit(false)
56 });
57
58 canvas.connect_motion_notify_event(move |cv, motion| {
59 let (x, y) = motion.get_position();
60 *writer_mouse.borrow_mut() = Some((x as i32 / 32, y as i32 / 32));
61 cv.queue_draw();
62 gtk::Inhibit(false)
63 });
64
65 canvas.add_events(gdk::POINTER_MOTION_MASK.bits() as i32);
66
67 GridCanvas {
68 canvas,
69 mouse_loc,
70 }
71 }
72 }
16 mod canvas;
17 use self::canvas::GridCanvas;
7318
7419 pub struct App {
7520 pub window: gtk::Window,
7924 pub header: Header,
8025 }
8126
27 /// The `App` is the main window that contains everything
8228 impl App {
8329 fn new() -> App {
8430 let window = gtk::Window::new(gtk::WindowType::Toplevel);
12066
12167 // HEADER
12268
69 /// The `Header` is the top toolbar; it contains buttons for opening
70 /// and saving documents as well as document status
12371 pub struct Header {
12472 pub container: gtk::HeaderBar,
12573 pub open_btn: gtk::Button,
183131 }
184132 }
185133
186
134 /// The `Toolbar` is the pane on the right that contains tileset
135 /// information: this includes tileset info like width, height, and
136 /// source image, as well as the tile picker for elsewhere
187137 pub struct Toolbar {
188138 toolbar: gtk::Box,
189139 tile_width: gtk::Entry,