Stupidity fix.

This commit is contained in:
KikooDX 2021-01-29 18:06:41 +01:00
parent 6cd12f6333
commit dca275fb03
2 changed files with 43 additions and 32 deletions

View File

@ -77,44 +77,53 @@ pub fn main() !void {
input_cursor -= 1;
const action = input_buffer[input_cursor];
var selection_update: movement.SelectionUpdate = undefined;
const movement_command = switch (action) {
'A'...'Z' => action - 'A' + 'a',
else => action,
};
const was_lowercase: bool = movement_command == action;
// TODO: move to functions.
switch (action) {
// Check for movement.
const selection_update: movement.SelectionUpdate = switch (movement_command) {
// Movement.
'h' => selection_update = movement.move_left(&cursor, 1, true),
'j' => selection_update = movement.move_down(&cursor, 1, true),
'k' => selection_update = movement.move_up(&cursor, 1, true),
'l' => selection_update = movement.move_right(&cursor, 1, true),
'H' => selection_update = movement.move_left(&cursor, 1, false),
'J' => selection_update = movement.move_down(&cursor, 1, false),
'K' => selection_update = movement.move_up(&cursor, 1, false),
'L' => selection_update = movement.move_right(&cursor, 1, false),
'h' => movement.move_left(&cursor, 1, was_lowercase),
'j' => movement.move_down(&cursor, 1, was_lowercase),
'k' => movement.move_up(&cursor, 1, was_lowercase),
'l' => movement.move_right(&cursor, 1, was_lowercase),
// Diagonals and rectangle selection.
'y' => selection_update = movement.move_up_left(&cursor, 1, true),
'u' => selection_update = movement.move_up_right(&cursor, 1, true),
'b' => selection_update = movement.move_down_left(&cursor, 1, true),
'n' => selection_update = movement.move_down_right(&cursor, 1, true),
'Y' => selection_update = movement.move_up_left(&cursor, 1, false),
'U' => selection_update = movement.move_up_right(&cursor, 1, false),
'B' => selection_update = movement.move_down_left(&cursor, 1, false),
'N' => selection_update = movement.move_down_right(&cursor, 1, false),
// Actions.
'd' => level.action_delete(),
// Zoom (pog feature).
'-' => if (scale > 3) {
scale -= 1;
'y' => movement.move_up_left(&cursor, 1, was_lowercase),
'u' => movement.move_up_right(&cursor, 1, was_lowercase),
'b' => movement.move_down_left(&cursor, 1, was_lowercase),
'n' => movement.move_down_right(&cursor, 1, was_lowercase),
else => blk: {
break :blk movement.SelectionUpdate{
.active = false,
.area = undefined,
.exclusive = undefined,
.state = undefined,
};
},
'+' => if (scale < comptime maxInt(scale_type)) {
scale += 1;
},
// Reset zoom.
'0' => scale = scale_default,
else => log("No action mapped to key {}.", .{action}),
}
};
if (selection_update.exclusive != undefined)
if (selection_update.active) {
level.apply_selection_update(selection_update);
} else {
// If didn't input movement, check for action.
switch (action) {
// Actions.
'd' => level.action_delete(),
// Zoom (pog feature).
'-' => if (scale > 3) {
scale -= 1;
},
'+' => if (scale < comptime maxInt(scale_type)) {
scale += 1;
},
// Reset zoom.
'0' => scale = scale_default,
else => log("No action for {} key.", .{action}),
}
}
}
ray.BeginDrawing();

View File

@ -15,6 +15,7 @@ const maxIntVec2 = comptime maxInt(Vec2.int_type);
/// Describe changes to make on selection.
pub const SelectionUpdate = struct {
active: bool,
exclusive: bool,
area: Rect,
state: bool,
@ -48,6 +49,7 @@ fn move(cursor: *Vec2, n: u32, exclusive_selection: bool, dx: i2, dy: i2) Select
}
return SelectionUpdate{
.active = true,
.exclusive = exclusive_selection,
.area = if (exclusive_selection)
Rect.init_from_vec2(cursor.*, cursor.*)