Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the circle, rectangle and fill brushes #41

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rmxp-types/src/option_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ impl<T> FromIterator<(usize, T)> for OptionVec<T> {
vec.reserve(additional);
vec.extend(std::iter::repeat_with(|| None).take(additional));
}
if vec[i].is_none() {
num_values += 1;
}
vec[i] = Some(v);
num_values += 1;
}
Self { vec, num_values }
}
Expand Down
26 changes: 22 additions & 4 deletions src/components/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl MapView {
ui: &mut egui::Ui,
map: &rpg::Map,
dragging_event: bool,
drawing_shape_pos: Option<egui::Pos2>,
) -> egui::Response {
// Allocate the largest size we can for the tilemap
let canvas_rect = ui.max_rect();
Expand Down Expand Up @@ -126,16 +127,20 @@ impl MapView {

let ctrl_drag = ui.input(|i| {
// Handle pan
if i.key_pressed(egui::Key::ArrowUp) {
if i.key_pressed(egui::Key::ArrowUp) && self.cursor_pos.y > 0. {
self.cursor_pos.y -= 1.0;
}
if i.key_pressed(egui::Key::ArrowDown) {
if i.key_pressed(egui::Key::ArrowDown)
&& self.cursor_pos.y < map.data.ysize() as f32 - 1.
{
self.cursor_pos.y += 1.0;
}
if i.key_pressed(egui::Key::ArrowLeft) {
if i.key_pressed(egui::Key::ArrowLeft) && self.cursor_pos.x > 0. {
self.cursor_pos.x -= 1.0;
}
if i.key_pressed(egui::Key::ArrowRight) {
if i.key_pressed(egui::Key::ArrowRight)
&& self.cursor_pos.x < map.data.xsize() as f32 - 1.
{
self.cursor_pos.x += 1.0;
}

Expand Down Expand Up @@ -428,6 +433,19 @@ impl MapView {
);
}

// Draw the origin tile for the rectangle and circle brushes
if let Some(drawing_shape_pos) = drawing_shape_pos {
let drawing_shape_rect = egui::Rect::from_min_size(
map_rect.min + (drawing_shape_pos.to_vec2() * tile_size),
egui::Vec2::splat(tile_size),
);
ui.painter().rect_stroke(
drawing_shape_rect,
5.,
egui::Stroke::new(1., egui::Color32::WHITE),
);
}

// Display cursor.
ui.painter().rect_stroke(
cursor_rect,
Expand Down
18 changes: 18 additions & 0 deletions src/components/tilepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ pub enum SelectedTile {
Autotile(i16),
Tile(i16),
}

impl SelectedTile {
pub fn from_id(id: i16) -> Self {
if id < 384 {
SelectedTile::Autotile(id / 48)
} else {
SelectedTile::Tile(id)
}
}

pub fn to_id(&self) -> i16 {
match *self {
Self::Autotile(tile) => tile * 48,
Self::Tile(tile) => tile,
}
}
}

impl Default for SelectedTile {
fn default() -> Self {
SelectedTile::Autotile(0)
Expand Down
Loading