4 extern crate gfx_device_gl;
10 use piston_window::{Glyphs, OpenGL, PistonWindow, WindowSettings, UpdateEvent,
11 EventLoop, Window, Texture, Flip};
13 use conrod::{Theme, Color, Button, Colorable, Labelable, Frameable,
14 Positionable, Sizeable, Graphics, Canvas, Widget, Tabs,
17 use image::{ImageFormat, load_from_memory_with_format};
19 use std::io::{Write, Read};
20 use std::process::{Command, Output, Stdio, ChildStdin, ChildStdout};
23 use graphics::{Line, Rectangle, Polygon, Ellipse, DrawState, Transformed, Image};
24 use gfx_device_gl::Resources;
27 <piston_window::G2d<'static> as Graphics>::Texture,
30 type Ui = conrod::Ui<Backend>;
31 type UiCell<'a> = conrod::UiCell<'a, Backend>;
33 const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
34 const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
36 fn rand_color() -> [f32; 4] {
52 pub fn view_space<G: graphics::Graphics>(s: &Space,
54 c: graphics::Context, gl: &mut G) {
55 let (xctr, zctr) = ((wsize.w - wsize.side_w) / 2.0, (wsize.h - wsize.header_h) / 2.0);
56 let (xcur, ycur, zcur) = (s.row_size_before_current(Axis::X) as f64,
57 (s.row_size_before_current(Axis::Y) / 2) as f64,
58 s.row_size_before_current(Axis::Z) as f64);
59 let (wshift, hshift) = (xctr - (xcur + ycur) + wsize.side_w,
60 zctr - (zcur + ycur) + wsize.header_h);
61 let mut wy = (s.row_size(Axis::Y) / 3) as f64;
62 for iy in (0..s.faces[0].len()).rev() {
63 let ysize = (s.size[Space::axis_idx(Axis::Y)][iy] / 3) as f64;
65 for ix in 0..s.faces.len() {
66 let xsize = s.size[Space::axis_idx(Axis::X)][ix] as f64;
68 for iz in 0..s.faces[0][0].len() {
69 let zsize = s.size[Space::axis_idx(Axis::Z)][iz] as f64;
70 match s.faces[ix][iy][iz] {
74 if let Some((r, g, b)) = ss[Space::ori_idx(Ori::Back)] {
75 Rectangle::new([r, g, b, 0.6])
76 .draw([0.0, 0.0, xsize, zsize],
77 &DrawState::default(),
78 c.transform.trans(x, z),
80 Rectangle::new_border(BLACK, 1.0)
81 .draw([0.0, 0.0, xsize, zsize],
82 &DrawState::default(),
83 c.transform.trans(x, z),
86 if let Some((r, g, b)) = ss[Space::ori_idx(Ori::Top)] {
87 Polygon::new([r, g, b, 0.6])
90 [x + xsize - ysize, z - ysize],
91 [x - ysize, z - ysize]],
92 &DrawState::default(),
98 &DrawState::default(),
101 Line::new(BLACK, 1.0)
103 x + xsize - ysize, z - ysize],
104 &DrawState::default(),
107 Line::new(BLACK, 1.0)
108 .draw([x + xsize - ysize, z - ysize,
109 x - ysize, z - ysize],
110 &DrawState::default(),
113 Line::new(BLACK, 1.0)
114 .draw([x - ysize, z - ysize,
116 &DrawState::default(),
120 if let Some((r, g, b)) = ss[Space::ori_idx(Ori::Side)] {
121 Polygon::new([r, g, b, 0.6])
122 .draw(&[[x, z + zsize],
124 [x - ysize, z - ysize],
125 [x - ysize, z + zsize - ysize]],
126 &DrawState::default(),
129 Line::new(BLACK, 1.0)
132 &DrawState::default(),
135 Line::new(BLACK, 1.0)
137 x - ysize, z - ysize],
138 &DrawState::default(),
141 Line::new(BLACK, 1.0)
142 .draw([x - ysize, z - ysize,
143 x - ysize, z + zsize - ysize],
144 &DrawState::default(),
147 Line::new(BLACK, 1.0)
148 .draw([x - ysize, z + zsize - ysize,
150 &DrawState::default(),
154 if (ix, iy, iz) == s.current_node_coord() {
156 .draw([-3.0, -3.0, 7.0, 7.0],
157 &DrawState::default(),
158 c.transform.trans(x, z),
161 Pos::E((_, a)) => match a {
162 Axis::X => Line::new(RED, 1.0)
163 .draw([x, z, x + xsize, z],
164 &DrawState::default(),
167 Axis::Y => Line::new(RED, 1.0)
168 .draw([x, z, x - ysize, z - ysize],
169 &DrawState::default(),
172 Axis::Z => Line::new(RED, 1.0)
173 .draw([x, z, x, z + zsize],
174 &DrawState::default(),
178 Pos::F((_, o)) => match o {
179 Ori::Back => Rectangle::new_border(RED, 1.0)
180 .draw([0.0, 0.0, xsize, zsize],
181 &DrawState::default(),
182 c.transform.trans(x, z),
188 &DrawState::default(),
193 x + xsize - ysize, z - ysize],
194 &DrawState::default(),
198 .draw([x + xsize - ysize, z - ysize,
199 x - ysize, z - ysize],
200 &DrawState::default(),
204 .draw([x - ysize, z - ysize,
206 &DrawState::default(),
214 &DrawState::default(),
219 x - ysize, z - ysize],
220 &DrawState::default(),
224 .draw([x - ysize, z - ysize,
225 x - ysize, z + zsize - ysize],
226 &DrawState::default(),
230 .draw([x - ysize, z + zsize - ysize,
232 &DrawState::default(),