aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c48
1 files changed, 45 insertions, 3 deletions
diff --git a/map.c b/map.c
index 70f4cc0..d0e48a6 100644
--- a/map.c
+++ b/map.c
@@ -524,10 +524,40 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
while (1) {
int ch = getch();
- /* FIXME: move this to the switch statement */
- if (ch == 'q') { clear_message(); visited_free(visited, *height); path_free(path, *height); break; }
- /* Handle keyboard keys */
+ /*
+ * Keybindings:
+ * [k] \
+ * [h] [l] } Move the view
+ * [j] /
+ *
+ * [K] \
+ * [H] [L] } Move the view faster
+ * [J] /
+ *
+ * [z] - Move the view to the top left corner
+ * [x] - Move the view to the bottom right corner
+ *
+ * [g] followed by:
+ * [s] - Move the view to the start
+ * [e] - Move the view to the end
+ *
+ * [a] - Toggle pathfinding
+ *
+ * [d] - Switch algorithms (A* or Dijsktra's)
+ *
+ * [s] - Save the map to a plaintext file
+ *
+ * [q] - Exit the map editor
+ *
+ * Mousebindings:
+ * LMB on wall/empty space to toggle them
+ * Drag start/goal with LMB to move them
+ * Drag right/bottom borders with LMB to resize the map
+ * Drag with MMB to move the view (buggy)
+ */
switch (ch) {
+ case 'q': clear_message(); visited_free(visited, *height); path_free(path, *height); mousemask(oldmask, NULL); printf("\033[?1003l\n"); return;
+
case 'h': map_offset_x += 2; break;
case 'l': map_offset_x -= 2; break;
case 'j': map_offset_y -= 1; break;
@@ -598,6 +628,18 @@ void map_editor(Map *map, size_t *width, size_t *height, Position *start, Positi
/* Handle mouse */
if (ch == KEY_MOUSE) {
if (getmouse(&event) == OK) {
+ if (event.bstate & BUTTON2_PRESSED) {
+ int init_x = event.x,
+ init_y = event.y,
+ init_map_offset_x = map_offset_x,
+ init_map_offset_y = map_offset_y;
+ while ((ch = getch()) == KEY_MOUSE \
+ && getmouse(&event) == OK && !(event.bstate & BUTTON2_RELEASED)) {
+ map_offset_y = init_map_offset_y + (event.y - init_y);
+ map_offset_x = init_map_offset_x + ((event.x - init_x) / 2 * 2);
+ draw_map(*map, NULL, *width, *height, *start, *goal, NULL, path, visited, NULL);
+ }
+ }
if (event.bstate & BUTTON1_PRESSED) {
/* Translate event coordinates into map coordinates */
size_t row = event.y - map_offset_y,