summaryrefslogtreecommitdiff
path: root/src/screen
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-05-25 20:22:59 -0400
committerAndrew Opalach <andrew@akon.city> 2024-05-25 20:22:59 -0400
commit2f9a0945bfeee3296cec3d38d094e4c49f9cb65f (patch)
treece80b220accbb44920932b1a2a6ca49ed31752a4 /src/screen
parent90e0930d820972802d1bb2fb27d7dded304483d6 (diff)
downloadcamu-2f9a0945bfeee3296cec3d38d094e4c49f9cb65f.tar.gz
camu-2f9a0945bfeee3296cec3d38d094e4c49f9cb65f.tar.bz2
camu-2f9a0945bfeee3296cec3d38d094e4c49f9cb65f.zip
wip
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/screen')
-rw-r--r--src/screen/screen.c52
-rw-r--r--src/screen/view.c34
-rw-r--r--src/screen/view.h13
3 files changed, 80 insertions, 19 deletions
diff --git a/src/screen/screen.c b/src/screen/screen.c
index b3ce0de..f92cd98 100644
--- a/src/screen/screen.c
+++ b/src/screen/screen.c
@@ -117,7 +117,7 @@ static bool mouse_button_callback(void *userdata, u8 state, u8 button)
}
#if defined SEKIHI_WINDOW_WAYLAND
-#define SCROLL_MULTIPLIER 87.5
+#define SCROLL_MULTIPLIER 150.0
#else
#define SCROLL_MULTIPLIER 25.0
#endif
@@ -149,6 +149,9 @@ static bool key_callback(void *userdata, u8 state, u8 button)
case SEKIHI_BUTTON_PRESSED:
//al_printf("%x\n", button);
switch (button) {
+ case 0x1d:
+ scr->flags |= CAMU_SCREEN_MODIFIER;
+ break;
case 0x10:
case 0x18:
case 'q':
@@ -170,24 +173,55 @@ static bool key_callback(void *userdata, u8 state, u8 button)
case 0x39:
scr->callback(scr->userdata, CAMU_SCREEN_TOGGLE_PAUSE, 0.0);
break;
+ case 0x1f:
+ case 's':
+ scr->callback(scr->userdata, CAMU_SCREEN_RESEEK, 0.0);
+ break;
case 0x13:
case 0x1b:
case 'r': {
struct camu_view *view = get_view_from_mouse_pos(scr);
if (view) {
- view->mode = CAMU_DEFAULT_VIEW;
+ if (!(scr->flags & CAMU_SCREEN_MODIFIER)) {
+ view->mode = CAMU_DEFAULT_VIEW;
+ } else {
+ switch (view->rotation) {
+ case CAMU_VIEW_ROTATION_0:
+ case CAMU_VIEW_ROTATION_360:
+ view->rotation = CAMU_VIEW_ROTATION_270;
+ break;
+ case CAMU_VIEW_ROTATION_270:
+ view->rotation = CAMU_VIEW_ROTATION_180;
+ break;
+ case CAMU_VIEW_ROTATION_180:
+ view->rotation = CAMU_VIEW_ROTATION_90;
+ break;
+ case CAMU_VIEW_ROTATION_90:
+ view->rotation = CAMU_VIEW_ROTATION_0;
+ break;
+ }
+ }
camu_view_calculate(view, scr->width, scr->height);
return true;
}
break;
}
- case 0x1f:
- case 's':
- scr->callback(scr->userdata, CAMU_SCREEN_RESEEK, 0.0);
+ case 0xd: {
+ struct camu_view *view = get_view_from_mouse_pos(scr);
+ if (view) {
+ camu_view_zoom_simple(view, scr->width, scr->height, scr->width / 2.0, scr->height / 2.0, 0.05);
+ return true;
+ }
break;
- case 0x1d:
- scr->flags |= CAMU_SCREEN_MODIFIER;
+ }
+ case 0xc: {
+ struct camu_view *view = get_view_from_mouse_pos(scr);
+ if (view) {
+ camu_view_zoom_simple(view, scr->width, scr->height, scr->width / 2.0, scr->height / 2.0, -0.05);
+ return true;
+ }
break;
+ }
default:
break;
}
@@ -287,12 +321,15 @@ static void add_buffer_internal(struct camu_screen *scr, struct camu_video_buffe
.mode = CAMU_DEFAULT_VIEW,
.width = stream->video.width,
.height = stream->video.height,
+ .stretch = 1.0,
+ .rotation = CAMU_VIEW_ROTATION_0,
.zindex = 0
}
};
#ifdef CAMU_SCREEN_THREADED
al_atomic_bool_store(&buf->ref, true, AL_ATOMIC_RELAXED);
#endif
+ if (buf->view.mode != CAMU_VIEW_NONE) video.view = buf->view;
camu_view_calculate(&video.view, scr->width, scr->height);
al_array_push(scr->videos, video);
}
@@ -305,6 +342,7 @@ static void remove_buffer_internal(struct camu_screen *scr, struct camu_video_bu
#ifdef CAMU_SCREEN_THREADED
al_atomic_bool_store(&buf->ref, false, AL_ATOMIC_RELAXED);
#endif
+ buf->view = video->view;
al_array_remove_at_iter(scr->videos, i);
break;
}
diff --git a/src/screen/view.c b/src/screen/view.c
index ab84277..0ca5f4c 100644
--- a/src/screen/view.c
+++ b/src/screen/view.c
@@ -1,3 +1,5 @@
+#include <al/lib.h>
+
#include "view.h"
#define ZOOM_MAX 100.0
@@ -6,36 +8,48 @@
#define PAN_BOUNDS 35.0
#define X_IN_BOUNDS(view, w, x) \
- ((x + PAN_BOUNDS <= w) && (PAN_BOUNDS - x <= view->width * view->zoom))
+ ((x + PAN_BOUNDS <= w) && (PAN_BOUNDS - x <= view->width * view->zoom / view->stretch))
#define Y_IN_BOUNDS(view, h, y) \
- ((y + PAN_BOUNDS <= h) && (PAN_BOUNDS - y <= view->height * view->zoom))
+ ((y + PAN_BOUNDS <= h) && (PAN_BOUNDS - y <= view->height * view->zoom * view->stretch))
+
+#define VIEW_ON_ITS_SIDE(view) \
+ (view->rotation % CAMU_VIEW_ROTATION_180 == CAMU_VIEW_ROTATION_90)
void camu_view_calculate(struct camu_view *view, s32 window_width, s32 window_height)
{
- if (view->mode == CAMU_VIEW_DETACHED) return;
+ f64 width, height;
+ if (VIEW_ON_ITS_SIDE(view)) {
+ width = (f64)view->height;
+ height = (f64)view->width;
+ view->stretch = height / width;
+ } else {
+ width = (f64)view->width;
+ height = (f64)view->height;
+ view->stretch = 1.0;
+ }
+ f64 frame_ratio = width / height;
f64 ratio = window_width / (f64)window_height;
- f64 frame_ratio = view->width / (f64)view->height;
view->ratio = ratio / frame_ratio;
switch (view->mode) {
case CAMU_VIEW_AUTOFIT:
if (frame_ratio > ratio) {
- view->zoom = (window_width / (f64)view->width);
+ view->zoom = window_width / width;
} else {
- view->zoom = (window_height / (f64)view->height);
+ view->zoom = window_height / height;
}
break;
case CAMU_VIEW_ZOOM:
if (frame_ratio < ratio) {
- view->zoom = (window_width / (f64)view->width);
+ view->zoom = window_width / width;
} else {
- view->zoom = (window_height / (f64)view->height);
+ view->zoom = window_height / height;
}
break;
default:
return;
}
- view->x_offset = (window_width - (view->width * view->zoom)) / 2.0;
- view->y_offset = (window_height - (view->height * view->zoom)) / 2.0;
+ view->x_offset = (window_width - (width * view->zoom)) / 2.0;
+ view->y_offset = (window_height - (height * view->zoom)) / 2.0;
}
bool camu_view_pan_simple(struct camu_view *view, s32 window_width, s32 window_height, f64 dx, f64 dy)
diff --git a/src/screen/view.h b/src/screen/view.h
index 5f33742..8cd3d28 100644
--- a/src/screen/view.h
+++ b/src/screen/view.h
@@ -3,12 +3,20 @@
#include <al/types.h>
enum {
- CAMU_VIEW_HIDDEN = 0,
+ CAMU_VIEW_NONE = 0,
CAMU_VIEW_AUTOFIT,
CAMU_VIEW_ZOOM,
CAMU_VIEW_DETACHED
};
+enum {
+ CAMU_VIEW_ROTATION_0 = 0,
+ CAMU_VIEW_ROTATION_90,
+ CAMU_VIEW_ROTATION_180,
+ CAMU_VIEW_ROTATION_270,
+ CAMU_VIEW_ROTATION_360
+};
+
#define CAMU_DEFAULT_VIEW CAMU_VIEW_AUTOFIT
struct camu_view {
@@ -19,7 +27,8 @@ struct camu_view {
f64 zoom;
f64 x_offset;
f64 y_offset;
- f64 rotation;
+ f64 stretch;
+ s32 rotation;
s32 zindex;
};