- [NEW] Ja es pot especificar zoom i fullscreen seguint el standard Jailer

This commit is contained in:
2024-12-02 18:38:04 +01:00
parent cbbf39c6cc
commit 810cdf4ecb
3 changed files with 92 additions and 13 deletions

View File

@@ -13,6 +13,10 @@ namespace zxscreen
SDL_Window *win = nullptr;
SDL_Renderer *ren = nullptr;
SDL_Texture *tex = nullptr;
uint8_t zoom = 1;
bool fullscreen = false;
int fullscreen_scale = 1;
SDL_Rect dest_rect;
uint32_t time=0;
@@ -78,19 +82,46 @@ namespace zxscreen
//border
for (int j=0;j<176;++j) { *(ptr_pixel++) = 0; *(ptr_color++) = 1; count+=2; }
}
printf("COUNT: %i\n", count);
//printf("COUNT: %i\n", count);
}
void show()
void reinit()
{
if (win) return;
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352, 296, SDL_WINDOW_SHOWN);
if (tex) SDL_DestroyTexture(tex);
if (ren) SDL_DestroyRenderer(ren);
if (win) SDL_DestroyWindow(win);
const int z = fullscreen ? 1 : zoom;
win = SDL_CreateWindow("ZX Spectrum Screen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 352*z, 296*z, fullscreen?SDL_WINDOW_FULLSCREEN_DESKTOP:SDL_WINDOW_SHOWN);
ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 352, 296);
create_tables();
if (fullscreen)
{
int w, h;
SDL_GetWindowSize(win, &w, &h);
fullscreen_scale = h/296;
dest_rect.w = 352 * fullscreen_scale;
dest_rect.h = 296 * fullscreen_scale;
dest_rect.x = (w - dest_rect.w)/2;
dest_rect.y = (h - dest_rect.h)/2;
}
else
{
dest_rect.x = dest_rect.y = 0;
dest_rect.w = 352 * zoom;
dest_rect.h = 296 * zoom;
}
redraw();
}
void init()
{
create_tables();
reinit();
}
void refresh(const uint8_t dt)
{
const uint8_t* memory = z80::getMem();
@@ -151,7 +182,46 @@ namespace zxscreen
SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch);
for (int i=0; i<352*296;++i) *(pixels++) = palette[zx_pixels[i]];
SDL_UnlockTexture(tex);
SDL_RenderCopy(ren, tex, NULL, NULL);
if (fullscreen)
{
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
SDL_RenderClear(ren);
}
// Pintem la textura a pantalla
SDL_RenderCopy(ren, tex, NULL, &dest_rect);
SDL_RenderPresent(ren);
}
void setZoom(const int value)
{
if (value < 1) return;
SDL_DisplayMode dm;
SDL_GetCurrentDisplayMode(0, &dm);
if (352*value > dm.w) return;
if (296*value > dm.h) return;
zoom = value;
reinit();
}
void incZoom()
{
setZoom(zoom+1);
}
void decZoom()
{
setZoom(zoom-1);
}
void toggleFullscreen()
{
fullscreen = !fullscreen;
reinit();
}
}