mirror of
https://github.com/joel16/VitaShell.git
synced 2025-03-01 16:45:33 +00:00
Improve image viewer
This commit is contained in:
parent
aa56ee7b67
commit
39a5564e5b
87
photo.c
87
photo.c
@ -46,11 +46,11 @@ int photoViewer(char *file, int type) {
|
||||
case FILE_TYPE_BMP:
|
||||
tex = vita2d_load_BMP_buffer(buffer);
|
||||
break;
|
||||
|
||||
|
||||
case FILE_TYPE_PNG:
|
||||
tex = vita2d_load_PNG_buffer(buffer);
|
||||
break;
|
||||
|
||||
|
||||
case FILE_TYPE_JPEG:
|
||||
tex = vita2d_load_JPEG_buffer(buffer, size);
|
||||
break;
|
||||
@ -64,16 +64,26 @@ int photoViewer(char *file, int type) {
|
||||
// Set bilinear filter
|
||||
vita2d_texture_set_filters(tex, SCE_GXM_TEXTURE_FILTER_LINEAR, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
||||
|
||||
float scale = 1.0f;
|
||||
float scale_x = 1.0f;
|
||||
float scale_y = 1.0f;
|
||||
float rad = 0.0f;
|
||||
|
||||
// Screen center
|
||||
float x = SCREEN_WIDTH / 2.0f;
|
||||
float y = SCREEN_HEIGHT / 2.0f;
|
||||
|
||||
// Adjust to screen
|
||||
float width = vita2d_texture_get_width(tex);
|
||||
float height = vita2d_texture_get_height(tex);
|
||||
float width2 = width / 2.0f;
|
||||
float height2 = height / 2.0f;
|
||||
|
||||
if (height > SCREEN_HEIGHT) { // height is first priority
|
||||
scale = SCREEN_HEIGHT / height;
|
||||
scale_y = SCREEN_HEIGHT / height;
|
||||
scale_x = scale_y * width;
|
||||
} else if (width > SCREEN_WIDTH) { // width is second priority
|
||||
scale = SCREEN_WIDTH / width;
|
||||
scale_x = SCREEN_WIDTH / width;
|
||||
scale_y = scale_x * height;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
@ -83,28 +93,77 @@ int photoViewer(char *file, int type) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (current_buttons & SCE_CTRL_UP || current_buttons & SCE_CTRL_LEFT_ANALOG_UP) {
|
||||
y -= MOVE_SPEED;
|
||||
} else if (current_buttons & SCE_CTRL_DOWN || current_buttons & SCE_CTRL_LEFT_ANALOG_DOWN) {
|
||||
y += MOVE_SPEED;
|
||||
}
|
||||
|
||||
if (current_buttons & SCE_CTRL_LEFT || current_buttons & SCE_CTRL_LEFT_ANALOG_LEFT) {
|
||||
x -= MOVE_SPEED;
|
||||
} else if (current_buttons & SCE_CTRL_RIGHT || current_buttons & SCE_CTRL_LEFT_ANALOG_RIGHT) {
|
||||
x += MOVE_SPEED;
|
||||
}
|
||||
|
||||
if ((x - scale_x * width2) > SCREEN_WIDTH) {
|
||||
x = SCREEN_WIDTH + scale_x * width2;
|
||||
} else if ((x + scale_x * width2) < 0) {
|
||||
x = -scale_x * width2;
|
||||
}
|
||||
|
||||
if ((y - scale_y * height2) > SCREEN_HEIGHT) {
|
||||
y = SCREEN_HEIGHT + scale_y * height2;
|
||||
} else if ((y + scale_y * height2) < 0) {
|
||||
y = -scale_y * height2;
|
||||
}
|
||||
|
||||
if (hold2_buttons & SCE_CTRL_LTRIGGER) {
|
||||
scale /= ZOOM_FACTOR;
|
||||
rad -= ROTATION_SPEED;
|
||||
}
|
||||
|
||||
if (hold2_buttons & SCE_CTRL_RTRIGGER) {
|
||||
scale *= ZOOM_FACTOR;
|
||||
rad += ROTATION_SPEED;
|
||||
}
|
||||
|
||||
if (scale < ZOOM_MIN) {
|
||||
scale = ZOOM_MIN;
|
||||
if (current_buttons & (SCE_CTRL_RIGHT_ANALOG_UP | SCE_CTRL_RIGHT_ANALOG_DOWN)) {
|
||||
scale_y -= ZOOM_SPEED * ((pad.ry - ANALOG_CENTER) / 128.0f);
|
||||
}
|
||||
|
||||
if (scale > ZOOM_MAX) {
|
||||
scale = ZOOM_MAX;
|
||||
if (current_buttons & (SCE_CTRL_RIGHT_ANALOG_RIGHT | SCE_CTRL_RIGHT_ANALOG_LEFT)) {
|
||||
scale_x += ZOOM_SPEED * ((pad.rx - ANALOG_CENTER) / 128.0f);
|
||||
}
|
||||
|
||||
// TODO: move with analog
|
||||
if (scale_x < ZOOM_MIN) {
|
||||
scale_x = ZOOM_MIN;
|
||||
} else if (scale_x > ZOOM_MAX) {
|
||||
scale_x = ZOOM_MAX;
|
||||
}
|
||||
|
||||
if (scale_y < ZOOM_MIN) {
|
||||
scale_y = ZOOM_MIN;
|
||||
} else if (scale_y > ZOOM_MAX) {
|
||||
scale_y = ZOOM_MAX;
|
||||
}
|
||||
|
||||
if (current_buttons & SCE_CTRL_TRIANGLE) {
|
||||
if (height > SCREEN_HEIGHT) { // height is first priority
|
||||
scale_y = SCREEN_HEIGHT / height;
|
||||
scale_x = scale_y * width;
|
||||
} else if (width > SCREEN_WIDTH) { // width is second priority
|
||||
scale_x = SCREEN_WIDTH / width;
|
||||
scale_y = scale_x * height;
|
||||
}
|
||||
scale_x = 1.0f;
|
||||
scale_y = 1.0f;
|
||||
rad = 0.0f;
|
||||
x = SCREEN_WIDTH / 2.0f;
|
||||
y = SCREEN_HEIGHT / 2.0f;
|
||||
}
|
||||
|
||||
// Start drawing
|
||||
START_DRAWING();
|
||||
|
||||
vita2d_draw_texture_scale_rotate_hotspot(tex, SCREEN_WIDTH / 2.0f, SCREEN_HEIGHT / 2.0f, scale, scale, 0.0f, vita2d_texture_get_width(tex) / 2.0f, vita2d_texture_get_height(tex) / 2.0f);
|
||||
vita2d_draw_texture_scale_rotate_hotspot(tex, x, y, scale_x, scale_y, rad, vita2d_texture_get_width(tex) / 2.0f, vita2d_texture_get_height(tex) / 2.0f);
|
||||
|
||||
// End drawing
|
||||
END_DRAWING();
|
||||
@ -118,4 +177,4 @@ int photoViewer(char *file, int type) {
|
||||
free(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
6
photo.h
6
photo.h
@ -21,8 +21,10 @@
|
||||
|
||||
#define ZOOM_MIN 0.1f
|
||||
#define ZOOM_MAX 10.0f
|
||||
#define ZOOM_FACTOR 1.02f
|
||||
#define ZOOM_SPEED 0.05f
|
||||
#define MOVE_SPEED 5.0f
|
||||
#define ROTATION_SPEED 0.05f
|
||||
|
||||
int photoViewer(char *file, int type);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
12
utils.c
12
utils.c
@ -22,6 +22,7 @@
|
||||
#include "language.h"
|
||||
#include "utils.h"
|
||||
|
||||
SceCtrlData pad;
|
||||
uint32_t old_buttons, current_buttons, pressed_buttons, hold_buttons, hold2_buttons, released_buttons;
|
||||
|
||||
void errorDialog(int error) {
|
||||
@ -57,13 +58,12 @@ int debugPrintf(char *text, ...) {
|
||||
|
||||
void disableAutoSuspend() {
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_AUTO_SUSPEND);
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_OLED_OFF);
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_OLED_OFF);
|
||||
}
|
||||
|
||||
void readPad() {
|
||||
static int hold_n = 0, hold2_n = 0;
|
||||
|
||||
SceCtrlData pad;
|
||||
memset(&pad, 0, sizeof(SceCtrlData));
|
||||
sceCtrlPeekBufferPositive(0, &pad, 1);
|
||||
|
||||
@ -172,11 +172,11 @@ void getDateString(char *string, int date_format, SceRtcTime *time) {
|
||||
case SCE_SYSTEM_PARAM_DATE_FORMAT_YYYYMMDD:
|
||||
sprintf(string, "%02d/%02d/%02d", time->year, time->month, time->day);
|
||||
break;
|
||||
|
||||
|
||||
case SCE_SYSTEM_PARAM_DATE_FORMAT_DDMMYYYY:
|
||||
sprintf(string, "%02d/%02d/%02d", time->day, time->month, time->year);
|
||||
break;
|
||||
|
||||
|
||||
case SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY:
|
||||
sprintf(string, "%02d/%02d/%02d", time->month, time->day, time->year);
|
||||
break;
|
||||
@ -188,9 +188,9 @@ void getTimeString(char *string, int time_format, SceRtcTime *time) {
|
||||
case SCE_SYSTEM_PARAM_TIME_FORMAT_12HR:
|
||||
sprintf(string, "%02d:%02d %s", time->hour >= 12 ? time->hour - 12 : time->hour, time->minutes, time->hour >= 12 ? "PM" : "AM");
|
||||
break;
|
||||
|
||||
|
||||
case SCE_SYSTEM_PARAM_TIME_FORMAT_24HR:
|
||||
sprintf(string, "%02d:%02d", time->hour, time->minutes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
utils.h
3
utils.h
@ -43,6 +43,7 @@ enum {
|
||||
*/
|
||||
};
|
||||
|
||||
extern SceCtrlData pad;
|
||||
extern uint32_t old_buttons, current_buttons, pressed_buttons, hold_buttons, hold2_buttons, released_buttons;
|
||||
|
||||
void errorDialog(int error);
|
||||
@ -62,4 +63,4 @@ void getSizeString(char *string, uint64_t size);
|
||||
void getDateString(char *string, int date_format, SceRtcTime *time);
|
||||
void getTimeString(char *string, int time_format, SceRtcTime *time);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user