diff --git a/README.md b/README.md index 4d786d2..1cbbd5b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,11 @@ Actions: * `-`: decrease scale (dezoom) * `=`: reset scale +# Mouse control +* Right click: reset selection. +* Hold left click: add to selection. +* Hold left click + shift: select rectangle. + # License Copyright (c) 2021 KikooDX diff --git a/src/level.zig b/src/level.zig index 4b22064..d52953c 100644 --- a/src/level.zig +++ b/src/level.zig @@ -104,8 +104,11 @@ pub fn draw_selection(self: *Self, scale: u16, offset: Vec2) void { /// Set the `state` of a cell at `cursor` if possible pub fn select_cell(self: *Self, cursor: Vec2, state: bool) void { const target: u32 = @intCast(u32, cursor.y) * self.width + @intCast(u32, cursor.x); - if (target < self.width * self.height and target >= 0) + if (cursor.x < self.width and cursor.y < self.height and + target < self.width * self.height and target >= 0) + { self.selection[target] = state; + } } /// Reset state of selection: `state` everywhere.