Out of bounds cursor safety + update README.md with mouse controls

This commit is contained in:
KikooDX 2021-02-01 00:40:43 +01:00
parent 8fc2e3fefb
commit 170409c014
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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.