diff options
| -rw-r--r-- | src/gate.rs | 46 | ||||
| -rw-r--r-- | src/input_layout.rs | 25 | ||||
| -rw-r--r-- | src/main.rs | 38 | ||||
| -rw-r--r-- | src/output_layout.rs | 1 | ||||
| -rw-r--r-- | src/wire.rs | 0 |
5 files changed, 82 insertions, 28 deletions
diff --git a/src/gate.rs b/src/gate.rs index bb27a6d..2b2952c 100644 --- a/src/gate.rs +++ b/src/gate.rs @@ -17,9 +17,12 @@ enum State { DragStop, } +#[derive(Debug, Clone)] pub struct Connection { - radius: f32, - color: Color, + dst: Option<Box<Connection>>, + pub radius: f32, + pub color: Color, + pub on: bool, } impl Rec { @@ -33,24 +36,31 @@ impl Rec { } impl Connection { - pub fn new(radius: f32, color: Color) -> Connection { - Connection { radius, color } + pub fn new(radius: f32, color: Color, on: bool) -> Connection { + Connection { + dst: None, + radius, + color, + on, + } } } -pub struct Gate { +pub struct Gate<'a> { rect: Rec, input: Vec<Connection>, output: Connection, + label: &'a str, state: State, } -impl Gate { - pub fn new(rect: Rec, input: Vec<Connection>, output: Connection) -> Gate { +impl<'a> Gate<'a> { + pub fn new(rect: Rec, input: Vec<Connection>, label: &'a str, output: Connection) -> Gate { Gate { rect, input, output, + label, state: State::default(), } } @@ -69,12 +79,10 @@ impl Gate { self.state = State::DragStop; } - println!("{:?}", self.state); - match self.state { State::Dragging => { - self.rect.x = mouse_position().0; - self.rect.y = mouse_position().1; + self.rect.x = mouse_position().0 - self.rect.w / 2.0; + self.rect.y = mouse_position().1 - self.rect.h / 2.0; self.draw_helper(); } _ => { @@ -97,15 +105,27 @@ impl Gate { self.rect.x, self.rect.y + 25. + (30. * cnt as f32), node.radius, - node.color, + if node.on { node.color } else { GRAY }, ); } + draw_text( + self.label, + self.rect.x + self.rect.w / 2.0, + self.rect.y + self.rect.h / 2.0, + 20.0, + WHITE, + ); + draw_circle( self.rect.x + self.rect.w, self.rect.y + self.rect.h / 2., self.output.radius, - self.output.color, + if self.output.on { + self.output.color + } else { + GRAY + }, ); } } diff --git a/src/input_layout.rs b/src/input_layout.rs new file mode 100644 index 0000000..2b086a3 --- /dev/null +++ b/src/input_layout.rs @@ -0,0 +1,25 @@ +use crate::gate::*; +use macroquad::prelude::*; + +pub struct InputLayout { + inputs: Vec<Connection>, +} + +impl InputLayout { + pub fn new(inputs: Vec<Connection>) -> Self { + InputLayout { inputs } + } + pub fn draw(&self) { + let playground_offset_x: f32 = screen_width() / 20.; + let playground_offset_y: f32 = screen_height() / 14.; + let playground_height: f32 = screen_height() - playground_offset_y * 2.0; + for (cnt, node) in self.inputs.iter().enumerate() { + draw_circle( + playground_offset_x, + playground_height / 3.0 + 25. + (30. * cnt as f32), + node.radius, + if node.on { node.color } else { GRAY }, + ); + } + } +} diff --git a/src/main.rs b/src/main.rs index 1759a20..3e1b2e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,35 +1,43 @@ use macroquad::prelude::*; mod gate; +mod input_layout; use gate::*; +use input_layout::*; -#[macroquad::main("egui with macroquad")] +#[macroquad::main("lgsim")] async fn main() { let mut gate = Gate::new( Rec::new(500., 500., 120., 80., RED), - vec![Connection::new(10., GOLD), Connection::new(10., GOLD)], - Connection::new(10., GOLD), + vec![Connection::new(10., GREEN, false); 2], + "GATE", + Connection::new(10., GREEN, false), ); + let input_layout = InputLayout::new(vec![Connection::new(10., GREEN, false); 16]); + loop { + let playground_offset_x: f32 = screen_width() / 20.; + let playground_offset_y: f32 = screen_height() / 14.; + let playground_width: f32 = screen_width() - playground_offset_x * 2.0; + let playground_height: f32 = screen_height() - playground_offset_y * 2.0; clear_background(color_u8!(27, 27, 27, 255)); // Process keys, mouse etc. - egui_macroquad::ui(|egui_ctx| { - egui::Window::new("egui ❤ macroquad").show(egui_ctx, |ui| { - ui.label("Test"); - }); - }); + draw_rectangle_lines( + playground_offset_x, + playground_offset_y, + playground_width, + playground_height, + 6., + WHITE, + ); // Draw things before egui - - // let gate2 = Gate::new( - // Rec::new(700., 700., 120., 80., RED), - // vec![Connection::new(10., GOLD), Connection::new(10., GOLD)], - // ); + input_layout.draw(); gate.draw(); - // gate2.draw(); - egui_macroquad::draw(); + + // egui_macroquad::draw(); // Draw things after egui diff --git a/src/output_layout.rs b/src/output_layout.rs new file mode 100644 index 0000000..0c7101b --- /dev/null +++ b/src/output_layout.rs @@ -0,0 +1 @@ +struct OutputLayout {} diff --git a/src/wire.rs b/src/wire.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/wire.rs |
