- [NEW] Ara draw::draw() pot fer stretch (zoom)

This commit is contained in:
2024-07-05 18:02:40 +02:00
parent 0cee2e3c36
commit 40a531f8b5
2 changed files with 14 additions and 8 deletions

View File

@@ -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<len;++i)
{
char chr = text[i]-32;
draw((x+i)*8, y*8, zoom&FONT_ZOOM_HORIZONTAL?16:8, zoom&FONT_ZOOM_VERTICAL?16:8, (chr&15)*8, (chr>>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;
}

View File

@@ -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);