From 170409c014dc23fd4990bdecdd06c93e7bd07104 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Mon, 1 Feb 2021 00:40:43 +0100 Subject: [PATCH] Out of bounds cursor safety + update README.md with mouse controls --- README.md | 5 +++++ src/level.zig | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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.