Skip to content

Commit

Permalink
final touches on objects
Browse files Browse the repository at this point in the history
  • Loading branch information
H4kor committed Jan 6, 2024
1 parent d63b845 commit 329409e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/chamber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl Chamber {
to: v.pos.into(),
color: color,
width: WALL_WIDTH,
dashed: false,
})];
} else if self.first_vert == None {
// special case: placement of first vertex
Expand Down
3 changes: 3 additions & 0 deletions src/door.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ impl Door {
from: world_pos - (self.width / 2.0) * tangent,
to: world_pos + (self.width / 2.0) * tangent,
width: 10.0,
dashed: false,
}),
Box::new(Line {
color: color,
from: world_pos - (self.width / 4.0) * tangent,
to: world_pos + (self.width / 4.0) * tangent,
width: 20.0,
dashed: false,
}),
]
} else {
Expand All @@ -82,6 +84,7 @@ impl Door {
from: world_pos - (self.width / 2.0) * tangent,
to: world_pos + (self.width / 2.0) * tangent,
width: 20.0,
dashed: false,
})]
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl Object {
// draw x in box
Box::new(Line {
color: color,
dashed: self.hidden,
from: Vec2 {
x: self.pos.x as f64,
y: self.pos.y as f64,
Expand All @@ -97,6 +98,7 @@ impl Object {
}),
Box::new(Line {
color: color,
dashed: self.hidden,
from: Vec2 {
x: (self.pos.x + GRID_SIZE) as f64,
y: self.pos.y as f64,
Expand Down
3 changes: 3 additions & 0 deletions src/view/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl Canvas {
b: 0.0,
},
width: 3.0,
dashed: false,
}
.draw(ctx),
}
Expand Down Expand Up @@ -324,13 +325,15 @@ impl Canvas {
b: 0.0,
};
Line {
dashed: false,
from: w1.p1.into(),
to: w1.p2.into(),
color: color,
width: 3.0,
}
.draw(ctx);
Line {
dashed: false,
from: w2.p1.into(),
to: w2.p2.into(),
color: color,
Expand Down
6 changes: 6 additions & 0 deletions src/view/entity_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ impl StateEventSubscriber for EntityTabs {
StateEvent::ActiveDoorChanged(Some(_)) => {
self.widget.set_current_page(Some(2));
}
StateEvent::ActiveObjectChanged(Some(_)) => {
self.widget.set_current_page(Some(3));
}
StateEvent::DoorAdded(_) => {
self.widget.set_current_page(Some(2));
}
StateEvent::ObjectAdded(_) => {
self.widget.set_current_page(Some(3));
}
_ => {}
};
vec![]
Expand Down
2 changes: 2 additions & 0 deletions src/view/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl Grid {
},
color: self.color,
width: self.width,
dashed: false,
});
lines.push(line);
}
Expand All @@ -70,6 +71,7 @@ impl Grid {
},
color: self.color,
width: self.width,
dashed: false,
});
lines.push(line);
}
Expand Down
6 changes: 1 addition & 5 deletions src/view/object_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ use std::cell::RefCell;
use std::rc::Rc;

use gtk::glib::clone;
use gtk::{
gio, glib, CheckButton, DropDown, Expression, ListItem, PolicyType, ScrolledWindow,
SignalListItemFactory,
};
use gtk::{gio, CheckButton, ListItem, PolicyType, ScrolledWindow, SignalListItemFactory};
use gtk::{prelude::*, Label, TextView};
use gtk::{Box, Entry};

use crate::chamber::ChamberId;
use crate::state::events::StateEvent;
use crate::state::{StateCommand, StateController, StateEventSubscriber};

Expand Down
6 changes: 6 additions & 0 deletions src/view/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Line {
pub to: Vec2<f64>,
pub color: Rgb,
pub width: f64,
pub dashed: bool,
}

pub struct Polygon {
Expand Down Expand Up @@ -58,6 +59,11 @@ impl Primitive for Point {

impl Primitive for Line {
fn draw(&self, ctx: &gtk::cairo::Context) {
if self.dashed {
ctx.set_dash(&vec![20.0, 10.0], 0.0);
} else {
ctx.set_dash(&vec![], 0.0);
}
ctx.set_line_width(self.width);
ctx.set_source_rgb(self.color.r, self.color.g, self.color.b);
ctx.move_to(self.from.x, self.from.y);
Expand Down

0 comments on commit 329409e

Please sign in to comment.