commit f165df94468786319400344fa7fd813e8e1899a7
parent 8fc171098d49a47e586b9038a31cde0f1ffd12fd
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 13 Feb 2023 00:30:37 +0100
Change keybinds, small fixes
Diffstat:
M | ntrop.c | | | 54 | +++++++++++++++++++++++++++--------------------------- |
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/ntrop.c b/ntrop.c
@@ -15,7 +15,7 @@
const char *file_path;
uint8_t *file_data;
-size_t data_len;
+ssize_t data_len;
ssize_t data_width;
ssize_t data_height;
@@ -59,7 +59,7 @@ usage(void)
}
uint8_t *
-read_file(const char *path, size_t *len)
+read_file(const char *path, ssize_t *len)
{
FILE *file;
char *chunk;
@@ -183,11 +183,11 @@ vis(void)
Color *data_colors;
Image window_image;
int window_init_frames;
- size_t pos, len;
+ ssize_t pos, len;
double mouse_move;
ssize_t data_x, data_y;
- size_t data_pos;
- size_t x, y;
+ ssize_t data_pos;
+ ssize_t x, y;
data_colors = value_colors;
show_value = true;
@@ -227,12 +227,12 @@ vis(void)
bar_width = MAX(80, window_width / 7);
if (window_init_frames > 0) {
data_width = MAX(1, MIN(data_len,
- (window_width - bar_width) / 2 / zoom));
- data_height = data_window_len / data_width
- + !!(data_window_len % data_width);
+ (window_width - bar_width) / zoom / 2));
data_window_len = MIN(data_len,
MAX(window_width / 2 / zoom
* window_height / 2 / zoom, 200));
+ data_height = data_window_len / data_width
+ + !!(data_window_len % data_width);
}
if (IsKeyPressed(KEY_G))
zoom = 2;
@@ -262,13 +262,11 @@ vis(void)
} else if (mouse_y < 20) {
bar_start -= bar_zoom * bar_width * 20;
}
- bar_start = MIN((ssize_t) data_len
- - bar_width * window_height * bar_zoom, bar_start);
- bar_start = MAX(0, bar_start);
+ bar_start = MAX(0, MIN(data_len - bar_width
+ * window_height * bar_zoom, bar_start));
data_window_start = bar_start + (mouse_y * bar_width + mouse_x) * bar_zoom;
- data_window_start = MAX(0, MIN(
- (ssize_t) data_len - data_window_len,
+ data_window_start = MAX(0, MIN(data_len - data_window_len,
data_window_start - data_window_len / 2));
} else if (drag) {
zoom_x = drag_zoom_x - (mouse_x - drag_mouse_x) * 1.F / zoom;
@@ -293,33 +291,30 @@ vis(void)
show_pos ^= IsKeyPressed(KEY_T);
show_bar ^= IsKeyPressed(KEY_B);
- if (IsKeyDown(KEY_LEFT_ALT)) {
+ if (IsKeyDown(KEY_LEFT_CONTROL)) {
if (key_press_hold(KEY_LEFT) || key_press_hold(KEY_A)) {
data_width -= IsKeyDown(KEY_LEFT_SHIFT) ? 5 : 1;
} else if (key_press_hold(KEY_RIGHT) || key_press_hold(KEY_D)) {
data_width += IsKeyDown(KEY_LEFT_SHIFT) ? 5 : 1;
}
- data_width = MAX(0, data_width);
+ data_width = MAX(1, data_width);
} else if (IsKeyDown(KEY_LEFT_SHIFT)) {
if (key_press_hold(KEY_LEFT) || key_press_hold(KEY_A)) {
- data_window_start -= 1;
- } else if (key_press_hold(KEY_RIGHT) || key_press_hold(KEY_D)) {
data_window_start += 1;
+ } else if (key_press_hold(KEY_RIGHT) || key_press_hold(KEY_D)) {
+ data_window_start -= 1;
}
- data_window_start = MAX(0, data_window_start);
- } else if (IsKeyDown(KEY_LEFT_CONTROL)) {
+ } else if (IsKeyDown(KEY_LEFT_ALT)) {
if (key_press_hold(KEY_LEFT) || key_press_hold(KEY_A)) {
- data_window_start -= bar_zoom * bar_width * 4;
+ data_window_start -= data_width * 8;
} else if (key_press_hold(KEY_RIGHT) || key_press_hold(KEY_D)) {
- data_window_start += bar_zoom * bar_width * 4;
+ data_window_start += data_width * 8;
}
- data_window_start = MAX(0, data_window_start);
if (key_press_hold(KEY_UP) || key_press_hold(KEY_W)) {
- data_window_len -= bar_zoom * bar_width * 4;
+ data_window_len -= data_width * 8;
} else if (key_press_hold(KEY_DOWN) || key_press_hold(KEY_S)) {
- data_window_len += bar_zoom * bar_width * 4;
+ data_window_len += data_width * 8;
}
- data_window_len = MAX(0, data_window_len);
} else {
if (key_press_hold(KEY_LEFT) || key_press_hold(KEY_A)) {
zoom_x -= 20.F / zoom;
@@ -333,8 +328,13 @@ vis(void)
zoom_y += 20.F / zoom;
}
}
- len = MIN(data_window_len, data_len - data_window_start);
- data_height = len / data_width + !!(len % data_width);
+
+ len = data_len - data_window_len;
+ if (len % data_width)
+ len += data_width - (len % data_width);
+ data_window_start = MAX(0, MIN(len, data_window_start));
+ data_window_len = MAX(0, MIN(len, data_window_len));
+ data_height = data_window_len / data_width;
if (IsKeyPressed(KEY_P)) {
show_value = !show_value;