mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
cieniowanie i drobne poprawki
zawiera drobny błąd wyświetlania cienia (walnięta funkcja do flipowania)
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "SDL_TTF.h"
|
||||
#include <iostream>
|
||||
extern SDL_Surface * ekran;
|
||||
extern SDL_Color tytulowy, tlo, zwykly ;
|
||||
bool isItIn(const SDL_Rect * rect, int x, int y)
|
||||
@ -42,7 +43,7 @@ void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=ty
|
||||
SDL_UpdateRect(dst,x,y,temp->w,temp->h);
|
||||
SDL_FreeSurface(temp);
|
||||
}
|
||||
void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC)
|
||||
void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC, Uint8 A)
|
||||
{
|
||||
Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;
|
||||
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
@ -63,10 +64,11 @@ void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G,
|
||||
///**************/
|
||||
///Reverses the toRot surface by the vertical axis
|
||||
///**************/
|
||||
SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
|
||||
SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot, int myC)
|
||||
{
|
||||
SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->w, toRot->h, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
|
||||
SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
|
||||
//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
|
||||
for(int i=0; i<ret->w; ++i)
|
||||
{
|
||||
for(int j=0; j<ret->h; ++j)
|
||||
@ -75,11 +77,11 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
|
||||
Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel;
|
||||
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
||||
{
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], 2);
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[0], p[1], p[2], myC);
|
||||
}
|
||||
else
|
||||
{
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], 2);
|
||||
CSDL_Ext::SDL_PutPixel(ret, i, j, p[2], p[1], p[0], myC);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,6 +93,7 @@ SDL_Surface * CSDL_Ext::hFlip(SDL_Surface * toRot)
|
||||
{
|
||||
SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->w, toRot->h, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
|
||||
SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
|
||||
//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
|
||||
for(int i=0; i<ret->w; ++i)
|
||||
{
|
||||
for(int j=0; j<ret->h; ++j)
|
||||
@ -120,6 +123,7 @@ SDL_Surface * CSDL_Ext::rotate02(SDL_Surface * toRot)
|
||||
{
|
||||
SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->h, toRot->w, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
|
||||
SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
|
||||
//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
|
||||
for(int i=0; i<ret->w; ++i)
|
||||
{
|
||||
for(int j=0; j<ret->h; ++j)
|
||||
@ -148,6 +152,7 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot)
|
||||
{
|
||||
SDL_Surface * first = SDL_CreateRGBSurface(toRot->flags, toRot->w, toRot->h, toRot->format->BitsPerPixel, toRot->format->Rmask, toRot->format->Gmask, toRot->format->Bmask, toRot->format->Amask);
|
||||
SDL_Surface * ret = SDL_ConvertSurface(first, toRot->format, toRot->flags);
|
||||
//SDL_SetColorKey(ret, SDL_SRCCOLORKEY, toRot->format->colorkey);
|
||||
for(int i=0; i<ret->w; ++i)
|
||||
{
|
||||
for(int j=0; j<ret->h; ++j)
|
||||
@ -207,7 +212,7 @@ SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy)
|
||||
return cursor;
|
||||
}
|
||||
|
||||
Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
|
||||
Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y, bool colorByte)
|
||||
{
|
||||
int bpp = surface->format->BytesPerPixel;
|
||||
/* Here p is the address to the pixel we want to retrieve */
|
||||
@ -215,7 +220,12 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
|
||||
|
||||
switch(bpp) {
|
||||
case 1:
|
||||
return *p;
|
||||
if(colorByte)
|
||||
{
|
||||
return colorToUint32(surface->format->palette->colors+(*p));
|
||||
}
|
||||
else
|
||||
return *p;
|
||||
|
||||
case 2:
|
||||
return *(Uint16 *)p;
|
||||
@ -232,4 +242,70 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, int x, int y)
|
||||
default:
|
||||
return 0; /* shouldn't happen, but avoids warnings */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
|
||||
{
|
||||
Uint32 trans = SDL_MapRGBA(src->format, 0, 255, 255, 255);
|
||||
//SDL_SetColorKey(src, SDL_SRCCOLORKEY, trans);
|
||||
/*SDL_SetColorKey(src, 0, trans);
|
||||
src = SDL_ConvertSurface(src, ekran->format, ekran->flags);
|
||||
for(int i=0; i<src->w; ++i)
|
||||
{
|
||||
for(int j=0; j<src->h; ++j)
|
||||
{
|
||||
Uint8 cr, cg, cb, ca;
|
||||
SDL_GetRGBA(SDL_GetPixel(src, i, j), src->format, &cr, &cg, &cb, &ca);
|
||||
if(cr == 255 && cb == 255)
|
||||
{
|
||||
Uint32 aaaa=src->format->Amask;
|
||||
Uint32 aaab=src->format->Bmask;
|
||||
Uint32 aaag=src->format->Gmask;
|
||||
Uint32 aaar=src->format->Rmask;
|
||||
Uint32 put = cg << 24 | cr << 16 | ca << 8 | cb;
|
||||
SDL_Rect rrr = genRect(1, 1, i, j);
|
||||
SDL_FillRect(src, &rrr, put);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//SDL_UpdateRect(src, 0, 0, src->w, src->h);
|
||||
SDL_SetColorKey(src, 0, trans);
|
||||
src->flags|=SDL_SRCALPHA;
|
||||
|
||||
if(src->format->BitsPerPixel == 8)
|
||||
{
|
||||
for(int yy=0; yy<src->format->palette->ncolors; ++yy)
|
||||
{
|
||||
SDL_Color cur = *(src->format->palette->colors+yy);
|
||||
if(cur.r == 255 && cur.b == 255)
|
||||
{
|
||||
SDL_Color shadow;
|
||||
shadow.b = shadow.g = shadow.r = 0;
|
||||
shadow.unused = cur.g + 25; //25 is a scalable constans to make it nicer
|
||||
SDL_SetColors(src, &shadow, yy, 1);
|
||||
}
|
||||
if(cur.g == 255 && cur.b == 255)
|
||||
{
|
||||
SDL_Color transp;
|
||||
transp.b = transp.g = transp.r = 0;
|
||||
transp.unused = 255;
|
||||
SDL_SetColors(src, &transp, yy, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_UpdateRect(src, 0, 0, src->w, src->h);
|
||||
return src;
|
||||
}
|
||||
|
||||
Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
|
||||
{
|
||||
Uint32 ret = 0;
|
||||
ret+=color->unused;
|
||||
ret*=256;
|
||||
ret+=color->b;
|
||||
ret*=256;
|
||||
ret+=color->g;
|
||||
ret*=256;
|
||||
ret+=color->r;
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user