From 40a531f8b57da39f60fbe6bbe4ef803a1d13630b Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 5 Jul 2024 18:02:40 +0200 Subject: [PATCH] - [NEW] Ara draw::draw() pot fer stretch (zoom) --- source/jdraw.cpp | 20 +++++++++++++------- source/jdraw.h | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/jdraw.cpp b/source/jdraw.cpp index 4b66887..8c4091a 100644 --- a/source/jdraw.cpp +++ b/source/jdraw.cpp @@ -323,7 +323,7 @@ namespace draw } // Pinta un troç de la superficie "source" en la superficie "destination". - void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip) + void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip, int dw, int dh) { // Si no hi ha superficie d'oritge especificada, no fem res, o petarà el mame if (source == nullptr) @@ -331,20 +331,26 @@ namespace draw return; } + if (dw==0) dw = w; + if (dh==0) dh = h; + // En principi, el quadrat de l'oritge començarà en (sx,sy) i avançarem 1 pixel en positiu tant en x com en y - int sdx = 1, sdy = 1, ssx = sx, ssy = sy; + float sdx = float(w)/float(dw); + float sdy = float(h)/float(dh); + float ssx = sx; + float ssy = sy; // Però si s'ha especificat que fem flip en horitzontal... if (flip & DRAW_FLIP_HORIZONTAL) { - sdx = -1; // Avançarem 1 pixel en negatiu + sdx = -sdx; // Avançarem 1 pixel en negatiu ssx = sx + w - 1; // I començarem al final, o siga, sumarem a sx el ample } // De igual forma per al flip en vertical, per a la y if (flip & DRAW_FLIP_VERTICAL) { - sdy = -1; + sdy = -sdy; ssy = sy + h - 1; } @@ -352,12 +358,12 @@ namespace draw int csx = ssx; // Anem linea per linea. Les variables dels dos bucles for controlen les coordenades en la destinació, que sempre van avant. - for (int y = dy; y < dy + h; ++y) + for (int y = dy; y < dy + dh; ++y) { ssx = csx; // fiquem la coordenada de l'oritge al principi // en cada linea, anem pixel a pixel - for (int x = dx; x < dx + w; ++x) + for (int x = dx; x < dx + dw; ++x) { pset(destination, x, y, pget(source, ssx, ssy)); // Agafem pixel de l'oritge i el fiquem en la destinació ssx += sdx; // avancem (o retrocedim) la coordenada x de l'oritge @@ -445,7 +451,7 @@ namespace draw for (int i=0;i>4)*8); + draw((x+i)*8, y*8, 8, 8, (chr&15)*8, (chr>>4)*8, DRAW_FLIP_NONE,zoom&FONT_ZOOM_HORIZONTAL?16:8, zoom&FONT_ZOOM_VERTICAL?16:8); } source = tmp; } diff --git a/source/jdraw.h b/source/jdraw.h index 266be2a..3bb9e0a 100644 --- a/source/jdraw.h +++ b/source/jdraw.h @@ -95,7 +95,7 @@ namespace draw /// @param sx coordenada x de l'oritge /// @param sy coordenada y de l'oritge /// @param flip si s'ha de fer flip en hortizontal o vertical (o ambdos) - void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip = DRAW_FLIP_NONE); + void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int flip = DRAW_FLIP_NONE, int dw=0, int dh=0); void swapcol(const uint8_t c1, const uint8_t c2); void restorecol(const uint8_t c);