- [FIX] Arreglat el ampastre de zooms i modes
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#define BASE_WINDOW_WIDTH 360
|
#define BASE_WINDOW_WIDTH 720
|
||||||
#define BASE_WINDOW_HEIGHT 280
|
#define BASE_WINDOW_HEIGHT 560
|
||||||
|
|
||||||
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
#define swap(a, b) {auto tmp=a;a=b;b=tmp;}
|
||||||
|
|
||||||
@@ -37,6 +37,8 @@ uint8_t *char_screen = NULL;
|
|||||||
uint8_t *color_screen = NULL;
|
uint8_t *color_screen = NULL;
|
||||||
uint8_t screen_width = 40;
|
uint8_t screen_width = 40;
|
||||||
uint8_t screen_height = 30;
|
uint8_t screen_height = 30;
|
||||||
|
uint16_t pixels_width = 640;
|
||||||
|
uint16_t pixels_height = 480;
|
||||||
uint8_t current_color = 0x1e;
|
uint8_t current_color = 0x1e;
|
||||||
uint8_t current_border = 0;
|
uint8_t current_border = 0;
|
||||||
uint8_t current_mode = 1;
|
uint8_t current_mode = 1;
|
||||||
@@ -52,12 +54,12 @@ uint8_t cursor_y = 0;
|
|||||||
SDL_Window *mini_win;
|
SDL_Window *mini_win;
|
||||||
SDL_Renderer *mini_ren;
|
SDL_Renderer *mini_ren;
|
||||||
SDL_Texture *mini_bak = NULL;
|
SDL_Texture *mini_bak = NULL;
|
||||||
uint8_t window_zoom = 2;
|
uint8_t window_zoom = 1;
|
||||||
bool window_fullscreen = false;
|
bool window_fullscreen = false;
|
||||||
uint16_t window_width = BASE_WINDOW_WIDTH * window_zoom;
|
uint16_t window_width = BASE_WINDOW_WIDTH * window_zoom;
|
||||||
uint16_t window_height = BASE_WINDOW_HEIGHT * window_zoom;
|
uint16_t window_height = BASE_WINDOW_HEIGHT * window_zoom;
|
||||||
uint16_t window_hborder = (window_width - screen_width*8*window_zoom) / 2;
|
uint16_t window_hborder = (window_width - pixels_width*window_zoom) / 2;
|
||||||
uint16_t window_vborder = (window_height - screen_height*8*window_zoom) / 2;
|
uint16_t window_vborder = (window_height - pixels_height*window_zoom) / 2;
|
||||||
|
|
||||||
Uint32 *pixels;
|
Uint32 *pixels;
|
||||||
int pitch;
|
int pitch;
|
||||||
@@ -88,6 +90,8 @@ void reinit() {
|
|||||||
case 0:
|
case 0:
|
||||||
screen_width = 80;
|
screen_width = 80;
|
||||||
screen_height = 30;
|
screen_height = 30;
|
||||||
|
pixels_width = 640;
|
||||||
|
pixels_height = 480;
|
||||||
current_color = 0x07;
|
current_color = 0x07;
|
||||||
current_border = 0;
|
current_border = 0;
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
@@ -98,6 +102,8 @@ void reinit() {
|
|||||||
case 1:
|
case 1:
|
||||||
screen_width = 40;
|
screen_width = 40;
|
||||||
screen_height = 30;
|
screen_height = 30;
|
||||||
|
pixels_width = 640;
|
||||||
|
pixels_height = 480;
|
||||||
current_color = 0x07;
|
current_color = 0x07;
|
||||||
current_border = 0;
|
current_border = 0;
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
@@ -108,6 +114,8 @@ void reinit() {
|
|||||||
case 2:
|
case 2:
|
||||||
screen_width = 20;
|
screen_width = 20;
|
||||||
screen_height = 15;
|
screen_height = 15;
|
||||||
|
pixels_width = 640;
|
||||||
|
pixels_height = 480;
|
||||||
current_color = 0x07;
|
current_color = 0x07;
|
||||||
current_border = 0;
|
current_border = 0;
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
@@ -118,6 +126,8 @@ void reinit() {
|
|||||||
case 3:
|
case 3:
|
||||||
screen_width = 32;
|
screen_width = 32;
|
||||||
screen_height = 24;
|
screen_height = 24;
|
||||||
|
pixels_width = 512;
|
||||||
|
pixels_height = 384;
|
||||||
current_color = 0x07;
|
current_color = 0x07;
|
||||||
current_border = 0;
|
current_border = 0;
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
@@ -128,18 +138,30 @@ void reinit() {
|
|||||||
case 4:
|
case 4:
|
||||||
screen_width = 80;
|
screen_width = 80;
|
||||||
screen_height = 30;
|
screen_height = 30;
|
||||||
|
pixels_width = 640;
|
||||||
|
pixels_height = 480;
|
||||||
current_color = 0x07;
|
current_color = 0x07;
|
||||||
current_border = 0;
|
current_border = 0;
|
||||||
cursor_x = 0;
|
cursor_x = 0;
|
||||||
cursor_y = 0;
|
cursor_y = 0;
|
||||||
char_screen = &mem[0];
|
char_screen = &mem[0];
|
||||||
color_screen = &mem[0x1200];
|
color_screen = &mem[2400];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
window_width = BASE_WINDOW_WIDTH * window_zoom;
|
uint8_t zoom = window_zoom;
|
||||||
window_height = BASE_WINDOW_HEIGHT * window_zoom;
|
if (window_fullscreen) {
|
||||||
window_hborder = (window_width - screen_width*8*window_zoom) / 2;
|
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
||||||
window_vborder = (window_height - screen_height*8*window_zoom) / 2;
|
int max_w_zoom = dm->w / (pixels_width);
|
||||||
|
int max_h_zoom = dm->h / (pixels_height);
|
||||||
|
zoom = SDL_min(max_w_zoom, max_h_zoom);
|
||||||
|
window_width = dm->w;
|
||||||
|
window_height = dm->h;
|
||||||
|
} else {
|
||||||
|
window_width = BASE_WINDOW_WIDTH * zoom;
|
||||||
|
window_height = BASE_WINDOW_HEIGHT * zoom;
|
||||||
|
}
|
||||||
|
window_hborder = (window_width - pixels_width*zoom) / 2;
|
||||||
|
window_vborder = (window_height - pixels_height*zoom) / 2;
|
||||||
|
|
||||||
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width*8, screen_height*8);
|
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width*8, screen_height*8);
|
||||||
SDL_SetTextureScaleMode(mini_bak, SDL_SCALEMODE_NEAREST);
|
SDL_SetTextureScaleMode(mini_bak, SDL_SCALEMODE_NEAREST);
|
||||||
@@ -233,8 +255,8 @@ void applyZoom(int zoom)
|
|||||||
// 3. Nuevo tamaño
|
// 3. Nuevo tamaño
|
||||||
window_width = BASE_WINDOW_WIDTH * window_zoom;
|
window_width = BASE_WINDOW_WIDTH * window_zoom;
|
||||||
window_height = BASE_WINDOW_HEIGHT * window_zoom;
|
window_height = BASE_WINDOW_HEIGHT * window_zoom;
|
||||||
window_hborder = (window_width - screen_width*8*window_zoom) / 2;
|
window_hborder = (window_width - pixels_width*window_zoom) / 2;
|
||||||
window_vborder = (window_height - screen_height*8*window_zoom) / 2;
|
window_vborder = (window_height - pixels_height*window_zoom) / 2;
|
||||||
|
|
||||||
// 4. Calcular nueva posición para mantener el centro
|
// 4. Calcular nueva posición para mantener el centro
|
||||||
int newX = SDL_max(0, oldX - (window_width - oldW) / 2);
|
int newX = SDL_max(0, oldX - (window_width - oldW) / 2);
|
||||||
@@ -253,13 +275,13 @@ void applyFullScreen() {
|
|||||||
} else {
|
} else {
|
||||||
window_fullscreen = true;
|
window_fullscreen = true;
|
||||||
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
||||||
int max_w_zoom = dm->w / (screen_width*8);
|
int max_w_zoom = dm->w / (pixels_width);
|
||||||
int max_h_zoom = dm->h / (screen_height*8);
|
int max_h_zoom = dm->h / (pixels_height);
|
||||||
int max_window_zoom = SDL_min(max_w_zoom, max_h_zoom);
|
int max_window_zoom = SDL_min(max_w_zoom, max_h_zoom);
|
||||||
window_width = dm->w;
|
window_width = dm->w;
|
||||||
window_height = dm->h;
|
window_height = dm->h;
|
||||||
window_hborder = (window_width - screen_width*8*max_window_zoom) / 2;
|
window_hborder = (window_width - pixels_width*max_window_zoom) / 2;
|
||||||
window_vborder = (window_height - screen_height*8*max_window_zoom) / 2;
|
window_vborder = (window_height - pixels_height*max_window_zoom) / 2;
|
||||||
SDL_SetWindowFullscreen(mini_win, window_fullscreen);
|
SDL_SetWindowFullscreen(mini_win, window_fullscreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user