mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Feat: Adds Screen zoom buttons in DD side menu (#3361)
This commit is contained in:
1 parent
e3ba2bc68d
commit
771f7cb8c3
76 files changed
+650
-13
No files matched your search
@@ -696,6 +696,8 @@ static struct surface *g_key_target;
|
||||
static struct surface *g_ime_click;
|
||||
static int g_input_pipe[2] = {-1, -1};
|
||||
struct input_msg { int type; int p1; int p2; int p3; int p4; };
|
||||
static atomic_int g_zoom_request_percent = 100;
|
||||
static atomic_int g_zoom_request_pending = 0;
|
||||
|
||||
struct surface;
|
||||
static void constraints_surface_gone(struct surface *s);
|
||||
@@ -3544,6 +3546,15 @@ static void pointer_input(double x, double y, int relative, uint32_t button, int
|
||||
if (k) confine_clamp(k, &x, &y);
|
||||
g_ptr_x = x; g_ptr_y = y;
|
||||
g_ptr_known = 1;
|
||||
if (relative && !button && (dx != 0.0 || dy != 0.0)) {
|
||||
int ow, oh;
|
||||
double ox, oy;
|
||||
vkp_output_size(&ow, &oh);
|
||||
if (ow > 0 && oh > 0 &&
|
||||
vkp_scene_to_output(g_ptr_x, g_ptr_y, &ox, &oy) &&
|
||||
vkp_zoom_pan_cursor(ox, oy))
|
||||
schedule_render();
|
||||
}
|
||||
if (atomic_load(&g_cursor_composite)) schedule_render();
|
||||
if (k) {
|
||||
target = k->surface;
|
||||
@@ -3612,15 +3623,38 @@ static void pointer_button(uint32_t button, int pressed) {
|
||||
}
|
||||
|
||||
static void deliver_pointer(const struct input_msg *m) {
|
||||
static int last_x, last_y, last_valid;
|
||||
int w, h, ow, oh;
|
||||
double x, y;
|
||||
int moved = last_valid && (m->p2 != last_x || m->p3 != last_y);
|
||||
last_x = m->p2;
|
||||
last_y = m->p3;
|
||||
last_valid = 1;
|
||||
scene_size(&w, &h);
|
||||
vkp_output_size(&ow, &oh);
|
||||
if (ow <= 0 || oh <= 0 ||
|
||||
!vkp_output_to_scene((double)m->p2 * ow / INPUT_SPACE_W, (double)m->p3 * oh / INPUT_SPACE_H, &x, &y)) {
|
||||
|
||||
if (ow <= 0 || oh <= 0) {
|
||||
x = (double)m->p2 * w / INPUT_SPACE_W;
|
||||
y = (double)m->p3 * h / INPUT_SPACE_H;
|
||||
} else {
|
||||
double ox = (double)m->p2 * ow / INPUT_SPACE_W;
|
||||
double oy = (double)m->p3 * oh / INPUT_SPACE_H;
|
||||
if (m->p1 == 1 && !pointer_locked_for_cursor() &&
|
||||
(moved || ox <= 0.0 || oy <= 0.0 || ox >= ow || oy >= oh) &&
|
||||
vkp_zoom_pan_cursor(ox, oy))
|
||||
schedule_render();
|
||||
if (!vkp_output_to_scene(ox, oy, &x, &y)) {
|
||||
schedule_render();
|
||||
if (g_ptr_known) {
|
||||
x = g_ptr_x;
|
||||
y = g_ptr_y;
|
||||
} else {
|
||||
x = (double)m->p2 * w / INPUT_SPACE_W;
|
||||
y = (double)m->p3 * h / INPUT_SPACE_H;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x < 0) x = 0;
|
||||
if (y < 0) y = 0;
|
||||
if (x > w - 1) x = w - 1;
|
||||
@@ -3632,6 +3666,7 @@ static void input_output_to_scene(double px, double py, double *x, double *y) {
|
||||
int w, h, ow, oh;
|
||||
scene_size(&w, &h);
|
||||
vkp_output_size(&ow, &oh);
|
||||
|
||||
if (ow <= 0 || oh <= 0 ||
|
||||
!vkp_output_to_scene(px * ow / INPUT_SPACE_W, py * oh / INPUT_SPACE_H, x, y)) {
|
||||
*x = px * w / INPUT_SPACE_W;
|
||||
@@ -3855,12 +3890,63 @@ static void touch_up(int id, double x, double y) {
|
||||
}
|
||||
|
||||
static void deliver_touch(const struct input_msg *m) {
|
||||
static int last_x[MAX_TOUCH_POINTS], last_y[MAX_TOUCH_POINTS];
|
||||
static int pan_start_x[MAX_TOUCH_POINTS], pan_start_y[MAX_TOUCH_POINTS];
|
||||
static unsigned char last_valid[MAX_TOUCH_POINTS];
|
||||
static unsigned char pan_started[MAX_TOUCH_POINTS];
|
||||
double x, y;
|
||||
int id = m->p2;
|
||||
int valid_id = id >= 0 && id < MAX_TOUCH_POINTS;
|
||||
|
||||
if (valid_id && m->p1 == 0) {
|
||||
pan_start_x[id] = m->p3;
|
||||
pan_start_y[id] = m->p4;
|
||||
pan_started[id] = 0;
|
||||
}
|
||||
if (valid_id && g_touch_points[id].surface &&
|
||||
m->p1 == 1 && last_valid[id] && !pan_started[id]) {
|
||||
int dx = m->p3 - pan_start_x[id];
|
||||
int dy = m->p4 - pan_start_y[id];
|
||||
if (dx * dx + dy * dy >= 400)
|
||||
pan_started[id] = 1;
|
||||
}
|
||||
if (valid_id && g_touch_points[id].surface &&
|
||||
m->p1 == 1 && pan_started[id] && last_valid[id] &&
|
||||
(m->p3 != last_x[id] || m->p4 != last_y[id])) {
|
||||
int ow, oh;
|
||||
vkp_output_size(&ow, &oh);
|
||||
if (ow > 0 && oh > 0 &&
|
||||
vkp_zoom_pan_cursor((double)m->p3 * ow / INPUT_SPACE_W,
|
||||
(double)m->p4 * oh / INPUT_SPACE_H))
|
||||
schedule_render();
|
||||
}
|
||||
|
||||
input_output_to_scene(m->p3, m->p4, &x, &y);
|
||||
if (m->p1 == 0) touch_down(m->p2, x, y);
|
||||
else if (m->p1 == 1) touch_motion(m->p2, x, y);
|
||||
else if (m->p1 == 2) touch_up(m->p2, x, y);
|
||||
else if (m->p1 == 3) touch_cancel_all();
|
||||
if (m->p1 == 0) {
|
||||
if (valid_id) {
|
||||
last_x[id] = m->p3;
|
||||
last_y[id] = m->p4;
|
||||
last_valid[id] = 1;
|
||||
}
|
||||
touch_down(id, x, y);
|
||||
} else if (m->p1 == 1) {
|
||||
if (valid_id) {
|
||||
last_x[id] = m->p3;
|
||||
last_y[id] = m->p4;
|
||||
last_valid[id] = 1;
|
||||
}
|
||||
touch_motion(id, x, y);
|
||||
} else if (m->p1 == 2) {
|
||||
touch_up(id, x, y);
|
||||
if (valid_id) {
|
||||
last_valid[id] = 0;
|
||||
pan_started[id] = 0;
|
||||
}
|
||||
} else if (m->p1 == 3) {
|
||||
touch_cancel_all();
|
||||
memset(last_valid, 0, sizeof(last_valid));
|
||||
memset(pan_started, 0, sizeof(pan_started));
|
||||
}
|
||||
publish_query_state();
|
||||
}
|
||||
|
||||
@@ -4067,12 +4153,20 @@ static int on_input_readable(int fd, uint32_t mask, void *data) {
|
||||
case 11: axis_event(m.p1, m.p2, 0); break;
|
||||
case 12: axis_event(m.p1, m.p2, 1); break;
|
||||
case 13: deliver_pen(&m); break;
|
||||
case 14:
|
||||
atomic_store(&g_zoom_request_pending, 1);
|
||||
break;
|
||||
case 20: stream_take(); break;
|
||||
case 21: if (!m.p1) stream_forget_all(); schedule_render(); break;
|
||||
case 22: schedule_render(); break;
|
||||
default: deliver_pointer(&m); break;
|
||||
}
|
||||
}
|
||||
if (atomic_exchange(&g_zoom_request_pending, 0)) {
|
||||
int zoom_percent = atomic_load(&g_zoom_request_percent);
|
||||
vk_present_set_zoom((float)zoom_percent / 100.0f);
|
||||
schedule_render();
|
||||
}
|
||||
if (atomic_exchange(&g_output_refresh_pending, 0) &&
|
||||
atomic_load(&g_output_refresh_mhz) != g_output_announced_refresh_mhz) {
|
||||
output_notify_mode();
|
||||
@@ -4096,6 +4190,23 @@ void droiddeck_wayland_set_scale_mode(int mode, int alignment) {
|
||||
(void)n;
|
||||
}
|
||||
|
||||
void droiddeck_wayland_set_zoom(int zoom_percent) {
|
||||
if (zoom_percent < 100) zoom_percent = 100;
|
||||
if (zoom_percent > 300) zoom_percent = 300;
|
||||
if (g_input_pipe[1] < 0) {
|
||||
vk_present_set_zoom((float)zoom_percent / 100.0f);
|
||||
return;
|
||||
}
|
||||
atomic_store(&g_zoom_request_percent, zoom_percent);
|
||||
atomic_store(&g_zoom_request_pending, 1);
|
||||
struct input_msg m = { 14, zoom_percent, 0, 0, 0 };
|
||||
ssize_t n;
|
||||
do {
|
||||
n = write(g_input_pipe[1], &m, sizeof(m));
|
||||
} while (n < 0 && errno == EINTR);
|
||||
(void)n;
|
||||
}
|
||||
|
||||
void droiddeck_wayland_send_pointer(int action, int x, int y) {
|
||||
if (g_input_pipe[1] < 0) return;
|
||||
struct input_msg m = { 0, action, x, y, 0 };
|
||||
|
||||
@@ -268,13 +268,16 @@ static pthread_cond_t g_req_condition = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
|
||||
static volatile int g_mode = VKP_MODE_STRETCH, g_align = VKP_ALIGN_CENTER;
|
||||
static volatile float g_zoom = 1.0f;
|
||||
|
||||
static struct {
|
||||
int scene_w, scene_h, out_w, out_h, mode, align;
|
||||
float kx, ky, off_x, off_y;
|
||||
float base_kx, base_ky, base_off_x, base_off_y, zoom;
|
||||
int rx, ry, rw, rh;
|
||||
int valid;
|
||||
} g_map;
|
||||
static pthread_mutex_t g_map_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t g_game_picture_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static float g_game_picture_rect[4];
|
||||
static int g_game_picture_placed;
|
||||
@@ -429,8 +432,21 @@ int vkp_completion_unknown(void) { return g_dev_state == -3; }
|
||||
void vk_present_set_scale_mode(int mode, int alignment) {
|
||||
if (mode < VKP_MODE_OFF || mode > VKP_MODE_INTEGER) mode = VKP_MODE_FIT;
|
||||
if (alignment < VKP_ALIGN_CENTER || alignment > VKP_ALIGN_PICTURE_RIGHT) alignment = VKP_ALIGN_CENTER;
|
||||
pthread_mutex_lock(&g_map_lock);
|
||||
g_mode = mode;
|
||||
g_align = alignment;
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
}
|
||||
|
||||
void vk_present_set_zoom(float zoom) {
|
||||
if (!(zoom >= 1.0f)) zoom = 1.0f;
|
||||
if (zoom > 3.0f) zoom = 3.0f;
|
||||
zoom = 1.0f + roundf((zoom - 1.0f) * 4.0f) * 0.25f;
|
||||
pthread_mutex_lock(&g_map_lock);
|
||||
if (g_zoom != zoom) {
|
||||
g_zoom = zoom;
|
||||
}
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
}
|
||||
|
||||
static const char *mode_name(int m) {
|
||||
@@ -456,13 +472,18 @@ static const char *align_name(int a) {
|
||||
}
|
||||
|
||||
static void update_map(int scene_w, int scene_h) {
|
||||
pthread_mutex_lock(&g_map_lock);
|
||||
int mode = g_mode, align = g_align;
|
||||
float zoom = g_zoom;
|
||||
int W = (int)g_extent.width, H = (int)g_extent.height;
|
||||
if (g_map.valid && g_map.scene_w == scene_w && g_map.scene_h == scene_h && g_map.out_w == W &&
|
||||
g_map.out_h == H && g_map.mode == mode && g_map.align == align)
|
||||
g_map.out_h == H && g_map.mode == mode && g_map.align == align && g_map.zoom == zoom) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return;
|
||||
}
|
||||
g_map.valid = 0;
|
||||
g_map.scene_w = scene_w; g_map.scene_h = scene_h; g_map.out_w = W; g_map.out_h = H;
|
||||
g_map.mode = mode; g_map.align = align;
|
||||
g_map.mode = mode; g_map.align = align; g_map.zoom = zoom;
|
||||
|
||||
int half = H / 2;
|
||||
switch (align) {
|
||||
@@ -495,6 +516,82 @@ static void update_map(int scene_w, int scene_h) {
|
||||
else if (align == VKP_ALIGN_PICTURE_BOTTOM) g_map.off_y = H - scene_h * g_map.ky;
|
||||
else if (align == VKP_ALIGN_PICTURE_LEFT) g_map.off_x = 0;
|
||||
else if (align == VKP_ALIGN_PICTURE_RIGHT) g_map.off_x = W - scene_w * g_map.kx;
|
||||
|
||||
g_map.base_kx = g_map.kx;
|
||||
g_map.base_ky = g_map.ky;
|
||||
g_map.base_off_x = g_map.off_x;
|
||||
g_map.base_off_y = g_map.off_y;
|
||||
|
||||
if (!(g_map.base_kx > 0.0f) || !(g_map.base_ky > 0.0f) ||
|
||||
!isfinite(g_map.base_kx) || !isfinite(g_map.base_ky) ||
|
||||
!isfinite(g_map.base_off_x) || !isfinite(g_map.base_off_y)) {
|
||||
pthread_mutex_lock(&g_game_picture_lock);
|
||||
g_game_picture_placed = 0;
|
||||
pthread_mutex_unlock(&g_game_picture_lock);
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (zoom > 1.0f) {
|
||||
float cx = (float)g_map.rx + (float)g_map.rw * 0.5f;
|
||||
float cy = (float)g_map.ry + (float)g_map.rh * 0.5f;
|
||||
float image_w, image_h;
|
||||
|
||||
g_map.kx = g_map.base_kx * zoom;
|
||||
g_map.ky = g_map.base_ky * zoom;
|
||||
image_w = scene_w * g_map.kx;
|
||||
image_h = scene_h * g_map.ky;
|
||||
|
||||
g_map.off_x = cx + (g_map.base_off_x - cx) * zoom;
|
||||
g_map.off_y = cy + (g_map.base_off_y - cy) * zoom;
|
||||
|
||||
if (image_w >= g_map.rw) {
|
||||
float min_x = (float)g_map.rx + g_map.rw - image_w;
|
||||
if (g_map.off_x < min_x) g_map.off_x = min_x;
|
||||
if (g_map.off_x > g_map.rx) g_map.off_x = (float)g_map.rx;
|
||||
} else {
|
||||
g_map.off_x = (float)g_map.rx + (g_map.rw - image_w) * 0.5f;
|
||||
}
|
||||
|
||||
if (image_h >= g_map.rh) {
|
||||
float min_y = (float)g_map.ry + g_map.rh - image_h;
|
||||
if (g_map.off_y < min_y) g_map.off_y = min_y;
|
||||
if (g_map.off_y > g_map.ry) g_map.off_y = (float)g_map.ry;
|
||||
} else {
|
||||
g_map.off_y = (float)g_map.ry + (g_map.rh - image_h) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (zoom > 1.0f &&
|
||||
(!(g_map.kx > 0.0f) || !(g_map.ky > 0.0f) ||
|
||||
!isfinite(g_map.kx) || !isfinite(g_map.ky) ||
|
||||
!isfinite(g_map.off_x) || !isfinite(g_map.off_y))) {
|
||||
if (g_map.base_kx > 0.0f && g_map.base_ky > 0.0f &&
|
||||
isfinite(g_map.base_kx) && isfinite(g_map.base_ky) &&
|
||||
isfinite(g_map.base_off_x) && isfinite(g_map.base_off_y)) {
|
||||
g_map.kx = g_map.base_kx;
|
||||
g_map.ky = g_map.base_ky;
|
||||
g_map.off_x = g_map.base_off_x;
|
||||
g_map.off_y = g_map.base_off_y;
|
||||
} else {
|
||||
pthread_mutex_lock(&g_game_picture_lock);
|
||||
g_game_picture_placed = 0;
|
||||
pthread_mutex_unlock(&g_game_picture_lock);
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(g_map.kx > 0.0f) || !(g_map.ky > 0.0f) ||
|
||||
!isfinite(g_map.kx) || !isfinite(g_map.ky) ||
|
||||
!isfinite(g_map.off_x) || !isfinite(g_map.off_y)) {
|
||||
pthread_mutex_lock(&g_game_picture_lock);
|
||||
g_game_picture_placed = 0;
|
||||
pthread_mutex_unlock(&g_game_picture_lock);
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
g_map.valid = 1;
|
||||
pthread_mutex_lock(&g_game_picture_lock);
|
||||
g_game_picture_placed = mode == VKP_MODE_INTEGER || align == VKP_ALIGN_PICTURE_TOP || align == VKP_ALIGN_PICTURE_BOTTOM || align == VKP_ALIGN_PICTURE_LEFT || align == VKP_ALIGN_PICTURE_RIGHT;
|
||||
@@ -507,6 +604,7 @@ static void update_map(int scene_w, int scene_h) {
|
||||
mode_name(mode), align_name(align), scene_w, scene_h,
|
||||
(int)(scene_w * g_map.kx + 0.5f), (int)(scene_h * g_map.ky + 0.5f),
|
||||
(int)g_map.off_x, (int)g_map.off_y, W, H);
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
}
|
||||
|
||||
int vkp_game_picture_rect(float rect[4]) {
|
||||
@@ -518,16 +616,26 @@ int vkp_game_picture_rect(float rect[4]) {
|
||||
}
|
||||
|
||||
int vkp_output_to_scene(double ox, double oy, double *sx, double *sy) {
|
||||
if (!g_map.valid || g_map.kx <= 0 || g_map.ky <= 0) return 0;
|
||||
pthread_mutex_lock(&g_map_lock);
|
||||
if (!g_map.valid || g_map.kx <= 0 || g_map.ky <= 0) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 0;
|
||||
}
|
||||
*sx = (ox - g_map.off_x) / g_map.kx;
|
||||
*sy = (oy - g_map.off_y) / g_map.ky;
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int vkp_scene_to_output(double sx, double sy, double *ox, double *oy) {
|
||||
if (!g_map.valid || g_map.kx <= 0 || g_map.ky <= 0) return 0;
|
||||
pthread_mutex_lock(&g_map_lock);
|
||||
if (!g_map.valid || g_map.kx <= 0 || g_map.ky <= 0) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 0;
|
||||
}
|
||||
*ox = sx * g_map.kx + g_map.off_x;
|
||||
*oy = sy * g_map.ky + g_map.off_y;
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -536,6 +644,99 @@ void vkp_output_size(int *w, int *h) {
|
||||
*h = (int)g_extent.height;
|
||||
}
|
||||
|
||||
int vkp_zoom_pan_cursor(double ox, double oy) {
|
||||
double cursor_x, cursor_y;
|
||||
float next_x, next_y;
|
||||
float image_w, image_h;
|
||||
int changed;
|
||||
|
||||
pthread_mutex_lock(&g_map_lock);
|
||||
if (!g_map.valid || g_map.zoom != g_zoom || g_map.mode != g_mode ||
|
||||
g_map.align != g_align || g_zoom <= 1.0f || g_zoom > 3.0f ||
|
||||
g_map.scene_w <= 0 || g_map.scene_h <= 0 ||
|
||||
g_map.rw <= 0 || g_map.rh <= 0 ||
|
||||
g_map.base_kx <= 0.0f || g_map.base_ky <= 0.0f ||
|
||||
g_map.kx <= 0.0f || g_map.ky <= 0.0f ||
|
||||
!isfinite(g_map.base_kx) || !isfinite(g_map.base_ky) ||
|
||||
!isfinite(g_map.kx) || !isfinite(g_map.ky) ||
|
||||
!isfinite(g_map.off_x) || !isfinite(g_map.off_y)) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!isfinite(ox) || !isfinite(oy)) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cursor_x = (ox - g_map.off_x) / g_map.kx;
|
||||
cursor_y = (oy - g_map.off_y) / g_map.ky;
|
||||
|
||||
if (cursor_x < 0.0) cursor_x = 0.0;
|
||||
if (cursor_y < 0.0) cursor_y = 0.0;
|
||||
if (cursor_x > g_map.scene_w - 1) cursor_x = g_map.scene_w - 1;
|
||||
if (cursor_y > g_map.scene_h - 1) cursor_y = g_map.scene_h - 1;
|
||||
|
||||
next_x = g_map.off_x;
|
||||
next_y = g_map.off_y;
|
||||
image_w = g_map.scene_w * g_map.kx;
|
||||
image_h = g_map.scene_h * g_map.ky;
|
||||
|
||||
if (image_w > g_map.rw) {
|
||||
float left = ((float)g_map.rx - g_map.off_x) / g_map.kx;
|
||||
float right = ((float)(g_map.rx + g_map.rw) - g_map.off_x) / g_map.kx;
|
||||
float margin = (right - left) * 0.2f;
|
||||
|
||||
if (cursor_x < left + margin)
|
||||
next_x += (float)(left + margin - cursor_x) * g_map.kx * 0.5f;
|
||||
else if (cursor_x > right - margin)
|
||||
next_x -= (float)(cursor_x - (right - margin)) * g_map.kx * 0.5f;
|
||||
|
||||
float min_x = (float)g_map.rx + g_map.rw - image_w;
|
||||
if (next_x < min_x) next_x = min_x;
|
||||
if (next_x > g_map.rx) next_x = (float)g_map.rx;
|
||||
}
|
||||
|
||||
if (image_h > g_map.rh) {
|
||||
float top = ((float)g_map.ry - g_map.off_y) / g_map.ky;
|
||||
float bottom = ((float)(g_map.ry + g_map.rh) - g_map.off_y) / g_map.ky;
|
||||
float margin = (bottom - top) * 0.2f;
|
||||
|
||||
if (cursor_y < top + margin)
|
||||
next_y += (float)(top + margin - cursor_y) * g_map.ky * 0.5f;
|
||||
else if (cursor_y > bottom - margin)
|
||||
next_y -= (float)(cursor_y - (bottom - margin)) * g_map.ky * 0.5f;
|
||||
|
||||
float min_y = (float)g_map.ry + g_map.rh - image_h;
|
||||
if (next_y < min_y) next_y = min_y;
|
||||
if (next_y > g_map.ry) next_y = (float)g_map.ry;
|
||||
}
|
||||
|
||||
if (!isfinite(next_x) || !isfinite(next_y)) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
changed = fabsf(next_x - g_map.off_x) >= 0.5f ||
|
||||
fabsf(next_y - g_map.off_y) >= 0.5f;
|
||||
if (!changed) {
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_map.off_x = next_x;
|
||||
g_map.off_y = next_y;
|
||||
|
||||
pthread_mutex_lock(&g_game_picture_lock);
|
||||
g_game_picture_rect[0] = g_map.off_x;
|
||||
g_game_picture_rect[1] = g_map.off_y;
|
||||
g_game_picture_rect[2] = g_map.off_x + g_map.scene_w * g_map.kx;
|
||||
g_game_picture_rect[3] = g_map.off_y + g_map.scene_h * g_map.ky;
|
||||
pthread_mutex_unlock(&g_game_picture_lock);
|
||||
pthread_mutex_unlock(&g_map_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void init_black_image(void);
|
||||
|
||||
static int has_ext(VkExtensionProperties *e, uint32_t n, const char *name) {
|
||||
|
||||
@@ -20,6 +20,8 @@ enum vkp_align { VKP_ALIGN_CENTER = 0, VKP_ALIGN_TOP = 1, VKP_ALIGN_BOTTOM = 2,
|
||||
VKP_ALIGN_PICTURE_TOP = 3, VKP_ALIGN_PICTURE_BOTTOM = 4,
|
||||
VKP_ALIGN_PICTURE_LEFT = 5, VKP_ALIGN_PICTURE_RIGHT = 6 };
|
||||
void vk_present_set_scale_mode(int mode, int alignment);
|
||||
void vk_present_set_zoom(float zoom);
|
||||
int vkp_zoom_pan_cursor(double ox, double oy);
|
||||
int vkp_game_picture_rect(float rect[4]);
|
||||
int vkp_output_to_scene(double ox, double oy, double *sx, double *sy);
|
||||
int vkp_scene_to_output(double sx, double sy, double *ox, double *oy);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
extern int droiddeck_wayland_run(void);
|
||||
extern void droiddeck_wayland_set_scale_mode(int mode, int alignment);
|
||||
extern void droiddeck_wayland_set_zoom(int zoom_percent);
|
||||
extern void droiddeck_wayland_send_pointer(int action, int x, int y);
|
||||
extern void droiddeck_wayland_send_touch(int action, int pointer_id, int x, int y);
|
||||
extern void droiddeck_wayland_send_pen(int flags, int x, int y);
|
||||
@@ -511,6 +512,15 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetScaleMode(JNIEnv
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG, "scale mode %d alignment %d", mode, alignment);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetZoom(JNIEnv *env, jclass clazz, jfloat zoom) {
|
||||
(void)env;
|
||||
(void)clazz;
|
||||
if (!(zoom >= 1.0f)) zoom = 1.0f;
|
||||
if (zoom > 3.0f) zoom = 3.0f;
|
||||
droiddeck_wayland_set_zoom((int)(zoom * 100.0f + 0.5f));
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeGamePictureRect(JNIEnv *env, jclass clazz, jfloatArray out) {
|
||||
|
||||
Reference in new issue
Block a user