Split view into submodules
Getty Ritter
7 years ago
| 1 | use gdk; | |
| 2 | 1 | use gtk::{ |
| 3 | 2 | self, |
| 4 | 3 | BoxExt, |
| 12 | 11 | FileChooserExt, |
| 13 | 12 | ButtonExt, |
| 14 | 13 | }; |
| 15 | use std::cell::RefCell; | |
| 16 | 14 | use std::process; |
| 17 | use std::rc::Rc; | |
| 18 | 15 | |
| 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; | |
| 73 | 18 | |
| 74 | 19 | pub struct App { |
| 75 | 20 | pub window: gtk::Window, |
| 79 | 24 | pub header: Header, |
| 80 | 25 | } |
| 81 | 26 | |
| 27 | /// The `App` is the main window that contains everything | |
| 82 | 28 | impl App { |
| 83 | 29 | fn new() -> App { |
| 84 | 30 | let window = gtk::Window::new(gtk::WindowType::Toplevel); |
| 120 | 66 | |
| 121 | 67 | // HEADER |
| 122 | 68 | |
| 69 | /// The `Header` is the top toolbar; it contains buttons for opening | |
| 70 | /// and saving documents as well as document status | |
| 123 | 71 | pub struct Header { |
| 124 | 72 | pub container: gtk::HeaderBar, |
| 125 | 73 | pub open_btn: gtk::Button, |
| 183 | 131 | } |
| 184 | 132 | } |
| 185 | 133 | |
| 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 | |
| 187 | 137 | pub struct Toolbar { |
| 188 | 138 | toolbar: gtk::Box, |
| 189 | 139 | tile_width: gtk::Entry, |