2011-08-24 14:14:44 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
2015-03-01 21:37:32 +01:00
|
|
|
Copyright (C) 2011, 2012, 2013 Guus Sliepen
|
2016-01-02 22:59:48 +01:00
|
|
|
Copyright (C) 2015, 2016 onpon4 <onpon4@riseup.net>
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
as published by the Free Software Foundation; either version 3
|
2011-08-24 14:14:44 +02:00
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-02-26 17:20:36 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-08-24 14:14:44 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-02-26 17:20:36 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 14:14:44 +02:00
|
|
|
*/
|
|
|
|
|
2015-06-16 05:56:20 +02:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2011-08-26 21:29:04 +02:00
|
|
|
#include "Starfighter.h"
|
|
|
|
|
2015-11-07 01:43:34 +01:00
|
|
|
SDL_Surface *gfx_background;
|
2011-08-26 23:53:46 +02:00
|
|
|
SDL_Surface *shape[MAX_SHAPES];
|
|
|
|
SDL_Surface *shipShape[MAX_SHIPSHAPES];
|
|
|
|
SDL_Surface *fontShape[MAX_FONTSHAPES];
|
|
|
|
SDL_Surface *shopSurface[MAX_SHOPSHAPES];
|
2015-11-02 23:53:05 +01:00
|
|
|
bRect *screen_bufferHead;
|
|
|
|
bRect *screen_bufferTail;
|
2015-10-11 18:04:52 +02:00
|
|
|
textObject gfx_text[MAX_TEXTSHAPES];
|
2011-08-26 23:53:46 +02:00
|
|
|
SDL_Surface *messageBox;
|
|
|
|
|
2015-09-26 14:49:21 +02:00
|
|
|
void gfx_init()
|
2011-08-24 14:14:44 +02:00
|
|
|
{
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_bufferHead = new bRect;
|
|
|
|
screen_bufferHead->next = NULL;
|
|
|
|
screen_bufferTail = screen_bufferHead;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
for (int i = 0 ; i < MAX_SHAPES ; i++)
|
|
|
|
shape[i] = NULL;
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
for (int i = 0 ; i < MAX_SHIPSHAPES ; i++)
|
|
|
|
shipShape[i] = NULL;
|
|
|
|
|
|
|
|
for (int i = 0 ; i < MAX_TEXTSHAPES ; i++)
|
2015-10-11 18:04:52 +02:00
|
|
|
gfx_text[i].image = NULL;
|
2011-08-26 23:53:46 +02:00
|
|
|
|
|
|
|
for (int i = 0 ; i < MAX_SHOPSHAPES ; i++)
|
|
|
|
shopSurface[i] = NULL;
|
|
|
|
|
|
|
|
for (int i = 0 ; i < MAX_FONTSHAPES ; i++)
|
|
|
|
fontShape[i] = NULL;
|
|
|
|
|
2015-11-07 01:43:34 +01:00
|
|
|
gfx_background = NULL;
|
2011-08-26 23:53:46 +02:00
|
|
|
messageBox = NULL;
|
|
|
|
|
|
|
|
screen = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-26 14:49:21 +02:00
|
|
|
SDL_Surface *gfx_setTransparent(SDL_Surface *sprite)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2013-10-01 14:33:33 +02:00
|
|
|
SDL_SetColorKey(sprite, SDL_TRUE, SDL_MapRGB(sprite->format, 0, 0, 0));
|
2011-08-26 23:53:46 +02:00
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2015-09-26 14:49:21 +02:00
|
|
|
void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2016-01-02 22:59:48 +01:00
|
|
|
SDL_Rect blitRect;
|
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
// Exit early if image is not on dest at all
|
2015-03-01 03:49:56 +01:00
|
|
|
if (x + image->w < 0 || x >= dest->w || y + image->h < 0 || y >= dest->h)
|
2011-08-26 23:53:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Set up a rectangle to draw to
|
|
|
|
blitRect.x = x;
|
|
|
|
blitRect.y = y;
|
|
|
|
blitRect.w = image->w;
|
|
|
|
blitRect.h = image->h;
|
|
|
|
|
|
|
|
/* Blit onto the destination surface */
|
2015-03-01 03:49:56 +01:00
|
|
|
if (SDL_BlitSurface(image, NULL, dest, &blitRect) < 0)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
printf("BlitSurface error: %s\n", SDL_GetError());
|
2016-01-02 22:59:48 +01:00
|
|
|
engine_showError(2, "");
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2015-03-31 19:02:09 +02:00
|
|
|
// Only if it is to the screen, mark the region as damaged
|
2015-03-01 03:49:56 +01:00
|
|
|
if (dest == screen)
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
In 16 bit mode this is slow. VERY slow. Don't write directly to a surface
|
|
|
|
that constantly needs updating (eg - the main game screen)
|
|
|
|
*/
|
2015-11-04 02:26:56 +01:00
|
|
|
static int gfx_renderStringBase(const char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-06-16 05:56:20 +02:00
|
|
|
int i;
|
|
|
|
int splitword;
|
2011-08-26 23:53:46 +02:00
|
|
|
SDL_Rect area;
|
2015-06-16 05:56:20 +02:00
|
|
|
SDL_Rect letter;
|
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
area.x = x;
|
|
|
|
area.y = y;
|
|
|
|
area.w = 8;
|
|
|
|
area.h = 14;
|
|
|
|
|
|
|
|
letter.y = 0;
|
|
|
|
letter.w = 8;
|
|
|
|
letter.h = 14;
|
|
|
|
|
|
|
|
while (*in != '\0')
|
|
|
|
{
|
2015-06-16 05:56:20 +02:00
|
|
|
if (*in != ' ')
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
letter.x = (*in - 33);
|
|
|
|
letter.x *= 8;
|
|
|
|
|
|
|
|
/* Blit onto the screen surface */
|
2015-06-16 05:56:20 +02:00
|
|
|
if (SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0)
|
|
|
|
{
|
2011-08-26 23:53:46 +02:00
|
|
|
printf("BlitSurface error: %s\n", SDL_GetError());
|
2016-01-02 22:59:48 +01:00
|
|
|
engine_showError(2, "");
|
2015-06-16 05:56:20 +02:00
|
|
|
}
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
area.x += 9;
|
|
|
|
|
|
|
|
if (wrap)
|
|
|
|
{
|
2015-06-16 05:56:20 +02:00
|
|
|
if ((area.x > (dest->w - 70)) && (*in == ' '))
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
area.y += 16;
|
|
|
|
area.x = x;
|
|
|
|
}
|
2015-06-16 05:56:20 +02:00
|
|
|
else if (area.x > (dest->w - 31))
|
|
|
|
{
|
|
|
|
splitword = 1;
|
|
|
|
for (i = 0 ; i < 4 ; i++)
|
|
|
|
{
|
|
|
|
if (!isalpha(*(in + i)))
|
|
|
|
{
|
|
|
|
splitword = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (splitword)
|
|
|
|
{
|
|
|
|
letter.x = (int)('-') - 33;
|
|
|
|
letter.x *= 8;
|
|
|
|
if (SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0)
|
|
|
|
{
|
|
|
|
printf("BlitSurface error: %s\n", SDL_GetError());
|
2016-01-02 22:59:48 +01:00
|
|
|
engine_showError(2, "");
|
2015-06-16 05:56:20 +02:00
|
|
|
}
|
|
|
|
area.y += 16;
|
|
|
|
area.x = x;
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return area.y;
|
|
|
|
}
|
|
|
|
|
2015-11-04 02:26:56 +01:00
|
|
|
int gfx_renderString(const char *in, int x, int y, int fontColor, int wrap, SDL_Surface *dest)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-11-06 16:12:57 +01:00
|
|
|
if (x == -1)
|
|
|
|
x = (dest->w - (strlen(in) * 9)) / 2;
|
|
|
|
|
2015-11-04 02:26:56 +01:00
|
|
|
gfx_renderStringBase(in, x, y - 1, FONT_OUTLINE, wrap, dest);
|
|
|
|
gfx_renderStringBase(in, x, y + 1, FONT_OUTLINE, wrap, dest);
|
|
|
|
gfx_renderStringBase(in, x, y + 2, FONT_OUTLINE, wrap, dest);
|
|
|
|
gfx_renderStringBase(in, x - 1, y, FONT_OUTLINE, wrap, dest);
|
|
|
|
gfx_renderStringBase(in, x - 2, y, FONT_OUTLINE, wrap, dest);
|
|
|
|
gfx_renderStringBase(in, x + 1, y, FONT_OUTLINE, wrap, dest);
|
|
|
|
return gfx_renderStringBase(in, x, y, fontColor, wrap, dest);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the pixel at (x, y) to the given value
|
|
|
|
* NOTE: The surface must be locked before calling this!
|
|
|
|
*/
|
2015-11-07 03:35:07 +01:00
|
|
|
void gfx_putPixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-03-01 03:49:06 +01:00
|
|
|
int bpp = surface->format->BytesPerPixel;
|
|
|
|
/* Here p is the address to the pixel we want to set */
|
|
|
|
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
switch(bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
*p = pixel;
|
|
|
|
break;
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
case 2:
|
|
|
|
*(Uint16 *)p = pixel;
|
|
|
|
break;
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
case 3:
|
|
|
|
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
|
|
|
{
|
2011-08-26 23:53:46 +02:00
|
|
|
p[0] = (pixel >> 16) & 0xff;
|
|
|
|
p[1] = (pixel >> 8) & 0xff;
|
|
|
|
p[2] = pixel & 0xff;
|
2015-03-01 03:49:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-26 23:53:46 +02:00
|
|
|
p[0] = pixel & 0xff;
|
|
|
|
p[1] = (pixel >> 8) & 0xff;
|
|
|
|
p[2] = (pixel >> 16) & 0xff;
|
2015-03-01 03:49:06 +01:00
|
|
|
}
|
|
|
|
break;
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
case 4:
|
|
|
|
*(Uint32 *)p = pixel;
|
|
|
|
break;
|
|
|
|
}
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2015-11-20 20:11:12 +01:00
|
|
|
void gfx_drawLine(SDL_Surface *dest, int x1, int y1, int x2, int y2, int col)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
int counter = 0;
|
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
if ( SDL_MUSTLOCK(dest) )
|
|
|
|
{
|
|
|
|
if ( SDL_LockSurface(dest) < 0 )
|
|
|
|
{
|
2011-08-26 23:53:46 +02:00
|
|
|
printf("Can't lock screen: %s\n", SDL_GetError());
|
2016-01-02 22:59:48 +01:00
|
|
|
engine_showError(2, "");
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2015-11-07 03:35:07 +01:00
|
|
|
gfx_putPixel(dest, x1, y1, col);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
|
|
|
if (x1 > x2) x1--;
|
|
|
|
if (x1 < x2) x1++;
|
|
|
|
if (y1 > y2) y1--;
|
|
|
|
if (y1 < y2) y1++;
|
|
|
|
|
|
|
|
if ((x1 == x2) && (y1 == y2))
|
|
|
|
{break;}
|
|
|
|
if (counter == 1000)
|
|
|
|
{printf("Loop Error!\n"); break;}
|
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
if (SDL_MUSTLOCK(dest))
|
|
|
|
{
|
2011-08-26 23:53:46 +02:00
|
|
|
SDL_UnlockSurface(dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
A quick(?) circle draw function. This code was posted to the SDL
|
|
|
|
mailing list... I didn't write it myself.
|
|
|
|
*/
|
2015-11-20 20:11:12 +01:00
|
|
|
void gfx_drawCircle(int xc, int yc, int R, SDL_Surface *PIX, int col)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2016-01-02 22:59:48 +01:00
|
|
|
int x = 0;
|
|
|
|
int xx = 0;
|
|
|
|
int y = R;
|
|
|
|
int yy = 2 * R;
|
2015-03-01 03:49:06 +01:00
|
|
|
int p = 1 - R;
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-11-07 03:35:07 +01:00
|
|
|
gfx_putPixel(PIX, xc, yc - y, col);
|
|
|
|
gfx_putPixel(PIX, xc, yc + y, col);
|
|
|
|
gfx_putPixel(PIX, xc - y, yc, col);
|
|
|
|
gfx_putPixel(PIX, xc + y, yc, col);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-03-01 03:49:06 +01:00
|
|
|
while (x < y)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
xx += 2;
|
2015-03-01 03:49:06 +01:00
|
|
|
x++;
|
2011-08-26 23:53:46 +02:00
|
|
|
if (p >= 0)
|
|
|
|
{
|
|
|
|
yy -= 2;
|
2015-03-01 03:49:06 +01:00
|
|
|
y--;
|
2011-08-26 23:53:46 +02:00
|
|
|
p -= yy;
|
|
|
|
}
|
|
|
|
p += xx + 1;
|
|
|
|
|
2015-11-07 03:35:07 +01:00
|
|
|
gfx_putPixel(PIX, xc - x, yc - y, col);
|
|
|
|
gfx_putPixel(PIX, xc + x, yc - y, col);
|
|
|
|
gfx_putPixel(PIX, xc - x, yc + y, col);
|
|
|
|
gfx_putPixel(PIX, xc + x, yc + y, col);
|
|
|
|
gfx_putPixel(PIX, xc - y, yc - x, col);
|
|
|
|
gfx_putPixel(PIX, xc + y, yc - x, col);
|
|
|
|
gfx_putPixel(PIX, xc - y, yc + x, col);
|
|
|
|
gfx_putPixel(PIX, xc + y, yc + x, col);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((x = y))
|
|
|
|
{
|
2015-11-07 03:35:07 +01:00
|
|
|
gfx_putPixel(PIX, xc - x, yc - y, col);
|
|
|
|
gfx_putPixel(PIX, xc + x, yc - y, col);
|
|
|
|
gfx_putPixel(PIX, xc - x, yc + y, col);
|
|
|
|
gfx_putPixel(PIX, xc + x, yc + y, col);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-31 16:47:27 +01:00
|
|
|
void gfx_drawRect(SDL_Surface *dest, int x, int y, int w, int h, Uint8 red, Uint8 green, Uint8 blue)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2012-12-09 16:53:21 +01:00
|
|
|
SDL_Rect r = {(int16_t)x, (int16_t)y, (uint16_t)w, (uint16_t)h};
|
2011-08-26 23:53:46 +02:00
|
|
|
SDL_FillRect(dest, &r, SDL_MapRGB(screen->format, red, green, blue));
|
|
|
|
|
2015-11-20 20:11:12 +01:00
|
|
|
gfx_drawLine(dest, x, y, x + w, y, SDL_MapRGB(screen->format, 255, 255, 255));
|
|
|
|
gfx_drawLine(dest, x, y, x, y + h, SDL_MapRGB(screen->format, 255, 255, 255));
|
|
|
|
gfx_drawLine(dest, x, y + h, x + w, y + h, SDL_MapRGB(screen->format, 128, 128, 128));
|
|
|
|
gfx_drawLine(dest, x + w, y + 1, x + w, y + h, SDL_MapRGB(screen->format, 128, 128, 128));
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2015-12-31 16:47:27 +01:00
|
|
|
SDL_Surface *gfx_createSurface(int width, int height)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_Surface *surface;
|
2011-08-26 23:53:46 +02:00
|
|
|
Uint32 rmask, gmask, bmask, amask;
|
|
|
|
|
|
|
|
/* SDL interprets each pixel as a 32-bit number, so our masks must depend
|
|
|
|
on the endianness (byte order) of the machine */
|
|
|
|
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
|
|
|
|
rmask = 0xff000000;
|
|
|
|
gmask = 0x00ff0000;
|
|
|
|
bmask = 0x0000ff00;
|
|
|
|
amask = 0x000000ff;
|
|
|
|
#else
|
|
|
|
rmask = 0x000000ff;
|
|
|
|
gmask = 0x0000ff00;
|
|
|
|
bmask = 0x00ff0000;
|
|
|
|
amask = 0xff000000;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, rmask, gmask, bmask, amask);
|
|
|
|
|
|
|
|
if (surface == NULL) {
|
|
|
|
printf("CreateRGBSurface failed: %s\n", SDL_GetError());
|
2016-01-02 22:59:48 +01:00
|
|
|
engine_showError(2, "");
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
return surface;
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2015-12-31 16:47:27 +01:00
|
|
|
SDL_Surface *gfx_createTextSurface(const char *inString, int color)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-12-31 16:47:27 +01:00
|
|
|
// XXX: Magic numbers
|
|
|
|
SDL_Surface *surface = gfx_createSurface(strlen(inString) * 9, 16);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-11-06 16:12:57 +01:00
|
|
|
gfx_renderString(inString, 1, 1, color, 0, surface);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
2015-09-26 14:49:21 +02:00
|
|
|
return gfx_setTransparent(surface);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
2011-08-24 14:14:44 +02:00
|
|
|
|
2015-12-31 16:47:27 +01:00
|
|
|
void gfx_createTextObject(int index, const char *inString, int x, int y, int fontColor)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
/* Shortcut: if we already rendered the same string in the same color, don't render it again. */
|
2015-10-11 18:04:52 +02:00
|
|
|
if(gfx_text[index].text && gfx_text[index].image && gfx_text[index].fontColor == fontColor && !strcmp(gfx_text[index].text, inString)) {
|
|
|
|
gfx_text[index].x = x;
|
|
|
|
gfx_text[index].y = y;
|
2011-08-26 23:53:46 +02:00
|
|
|
if (x == -1)
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_text[index].x = (screen->w - gfx_text[index].image->w) / 2;
|
2011-08-26 23:53:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-11 18:04:52 +02:00
|
|
|
strcpy(gfx_text[index].text, inString);
|
|
|
|
gfx_text[index].x = x;
|
|
|
|
gfx_text[index].y = y;
|
|
|
|
gfx_text[index].fontColor = fontColor;
|
|
|
|
if (gfx_text[index].image != NULL)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-10-11 18:04:52 +02:00
|
|
|
SDL_FreeSurface(gfx_text[index].image);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_text[index].image = gfx_createTextSurface(inString, fontColor);
|
2011-08-26 23:53:46 +02:00
|
|
|
if (x == -1)
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_text[index].x = (screen->w - gfx_text[index].image->w) / 2;
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2016-01-02 22:59:48 +01:00
|
|
|
SDL_Surface *gfx_createAlphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-12-31 16:47:27 +01:00
|
|
|
SDL_Surface *surface = gfx_createSurface(width, height);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
|
|
|
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green, blue));
|
|
|
|
|
2013-09-30 16:52:43 +02:00
|
|
|
SDL_SetSurfaceAlphaMod(surface, 128);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2016-01-02 22:59:48 +01:00
|
|
|
void gfx_createMessageBox(SDL_Surface *face, const char *message, signed char transparent)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2016-01-02 22:59:48 +01:00
|
|
|
int x = 60;
|
|
|
|
|
2011-08-26 23:53:46 +02:00
|
|
|
if (messageBox != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(messageBox);
|
|
|
|
messageBox = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transparent)
|
2016-01-02 22:59:48 +01:00
|
|
|
messageBox = gfx_createAlphaRect(550, 60, 0x00, 0x00, 0x00);
|
2011-08-26 23:53:46 +02:00
|
|
|
else
|
2015-12-31 16:47:27 +01:00
|
|
|
messageBox = gfx_createSurface(550, 60);
|
2011-08-26 23:53:46 +02:00
|
|
|
|
|
|
|
if (face != NULL)
|
|
|
|
{
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_drawRect(messageBox, 0, 0, messageBox->w - 1, messageBox->h - 1, 0x00, 0x00, 0xaa);
|
2015-09-26 14:49:21 +02:00
|
|
|
gfx_blit(face, 5, 5, messageBox);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-12-31 16:47:27 +01:00
|
|
|
gfx_drawRect(messageBox, 0, 0, messageBox->w - 1, messageBox->h - 1, 0x00, 0x00, 0x00);
|
2011-08-26 23:53:46 +02:00
|
|
|
x = 10;
|
|
|
|
}
|
|
|
|
|
2015-11-04 02:26:56 +01:00
|
|
|
gfx_renderString(message, x, 5, FONT_WHITE, 1, messageBox);
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
|
2016-01-02 22:59:48 +01:00
|
|
|
SDL_Surface *gfx_loadImage(const char *filename)
|
|
|
|
{
|
|
|
|
SDL_Surface *image, *newImage;
|
|
|
|
|
|
|
|
image = IMG_Load(filename);
|
|
|
|
|
|
|
|
if (image == NULL) {
|
|
|
|
printf("Couldn't load %s: %s\n", filename, SDL_GetError());
|
|
|
|
engine_showError(0, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
newImage = SDL_ConvertSurface(image, screen->format, 0);
|
|
|
|
if ( newImage ) {
|
|
|
|
SDL_FreeSurface(image);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This happens when we are loading the window icon image
|
|
|
|
newImage = image;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gfx_setTransparent(newImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfx_free()
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
|
|
|
for (int i = 0 ; i < MAX_SHAPES ; i++)
|
|
|
|
{
|
|
|
|
if (shape[i] != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(shape[i]);
|
|
|
|
shape[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0 ; i < MAX_SHIPSHAPES ; i++)
|
|
|
|
{
|
|
|
|
if (shipShape[i] != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(shipShape[i]);
|
|
|
|
shipShape[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0 ; i < MAX_TEXTSHAPES ; i++)
|
|
|
|
{
|
2015-10-11 18:04:52 +02:00
|
|
|
if (gfx_text[i].image != NULL)
|
2011-08-26 23:53:46 +02:00
|
|
|
{
|
2015-10-11 18:04:52 +02:00
|
|
|
SDL_FreeSurface(gfx_text[i].image);
|
|
|
|
gfx_text[i].image = NULL;
|
2011-08-26 23:53:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0 ; i < MAX_SHOPSHAPES ; i++)
|
|
|
|
{
|
|
|
|
if (shopSurface[i] != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(shopSurface[i]);
|
|
|
|
shopSurface[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageBox != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(messageBox);
|
|
|
|
messageBox = NULL;
|
|
|
|
}
|
|
|
|
}
|