2015-09-26 14:49:21 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Parallel Realities
|
|
|
|
Copyright (C) 2011, 2012, 2013 Guus Sliepen
|
2016-11-17 01:43:03 +01:00
|
|
|
Copyright (C) 2015, 2016 Julie Marchant <onpon4@riseup.net>
|
2015-09-26 14:49:21 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 3
|
|
|
|
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
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-11-02 23:53:05 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2016-08-04 21:58:38 +02:00
|
|
|
#include "SDL.h"
|
|
|
|
|
2016-11-26 00:21:31 +01:00
|
|
|
#include "defs.h"
|
|
|
|
#include "structs.h"
|
|
|
|
|
2016-01-02 22:59:48 +01:00
|
|
|
#include "engine.h"
|
2015-09-26 14:49:21 +02:00
|
|
|
#include "gfx.h"
|
|
|
|
|
|
|
|
SDL_Surface *screen;
|
2016-11-26 00:41:55 +01:00
|
|
|
LinkedRect *screen_bufferHead;
|
|
|
|
LinkedRect *screen_bufferTail;
|
2015-09-26 14:49:21 +02:00
|
|
|
|
|
|
|
void screen_blit(SDL_Surface *image, int x, int y)
|
|
|
|
{
|
|
|
|
gfx_blit(image, x, y, screen);
|
|
|
|
}
|
2015-10-11 18:04:52 +02:00
|
|
|
|
|
|
|
void screen_blitText(int i)
|
|
|
|
{
|
2016-01-04 04:39:16 +01:00
|
|
|
screen_blit(gfx_textSprites[i].image, (int)gfx_textSprites[i].x, (int)gfx_textSprites[i].y);
|
2015-10-11 18:04:52 +02:00
|
|
|
}
|
2015-11-02 23:53:05 +01:00
|
|
|
|
2015-11-07 01:36:20 +01:00
|
|
|
int screen_renderString(const char *in, int x, int y, int fontColor)
|
|
|
|
{
|
|
|
|
return gfx_renderString(in, x, y, fontColor, 0, screen);
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:43:34 +01:00
|
|
|
/*
|
|
|
|
Draws the background surface that has been loaded
|
|
|
|
*/
|
|
|
|
void screen_drawBackground()
|
|
|
|
{
|
|
|
|
screen_blit(gfx_background, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-11-02 23:53:05 +01:00
|
|
|
void screen_addBuffer(int x, int y, int w, int h)
|
|
|
|
{
|
2016-11-26 00:41:55 +01:00
|
|
|
LinkedRect *rect = new LinkedRect;
|
2015-11-02 23:53:05 +01:00
|
|
|
|
|
|
|
rect->next = NULL;
|
|
|
|
rect->x = x;
|
|
|
|
rect->y = y;
|
|
|
|
rect->w = w;
|
|
|
|
rect->h = h;
|
|
|
|
|
|
|
|
screen_bufferTail->next = rect;
|
|
|
|
screen_bufferTail = rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void screen_flushBuffer()
|
|
|
|
{
|
2016-11-26 00:41:55 +01:00
|
|
|
LinkedRect *prevRect = screen_bufferHead;
|
|
|
|
LinkedRect *rect = screen_bufferHead;
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_bufferTail = screen_bufferHead;
|
|
|
|
|
|
|
|
while (rect->next != NULL)
|
|
|
|
{
|
|
|
|
rect = rect->next;
|
|
|
|
|
|
|
|
prevRect->next = rect->next;
|
|
|
|
delete rect;
|
|
|
|
rect = prevRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_bufferHead->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void screen_unBuffer()
|
|
|
|
{
|
2016-11-26 00:41:55 +01:00
|
|
|
LinkedRect *prevRect = screen_bufferHead;
|
|
|
|
LinkedRect *rect = screen_bufferHead;
|
2015-11-02 23:53:05 +01:00
|
|
|
screen_bufferTail = screen_bufferHead;
|
|
|
|
|
|
|
|
while (rect->next != NULL)
|
|
|
|
{
|
|
|
|
rect = rect->next;
|
|
|
|
|
|
|
|
SDL_Rect blitRect;
|
|
|
|
|
|
|
|
blitRect.x = rect->x;
|
|
|
|
blitRect.y = rect->y;
|
|
|
|
blitRect.w = rect->w;
|
|
|
|
blitRect.h = rect->h;
|
|
|
|
|
2015-11-07 01:43:34 +01:00
|
|
|
if (SDL_BlitSurface(gfx_background, &blitRect, screen, &blitRect) < 0)
|
2015-11-02 23:53:05 +01:00
|
|
|
{
|
|
|
|
printf("BlitSurface error: %s\n", SDL_GetError());
|
2016-01-02 22:59:48 +01:00
|
|
|
engine_showError(2, "");
|
2015-11-02 23:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
prevRect->next = rect->next;
|
|
|
|
delete rect;
|
|
|
|
rect = prevRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen_bufferHead->next = NULL;
|
|
|
|
}
|
2015-11-07 03:35:07 +01:00
|
|
|
|
|
|
|
void screen_clear(Uint32 color)
|
|
|
|
{
|
|
|
|
SDL_FillRect(screen, NULL, color);
|
|
|
|
}
|
2015-12-31 16:47:27 +01:00
|
|
|
|
|
|
|
void screen_drawRect(int x, int y, int w, int h, Uint8 red, Uint8 green, Uint8 blue)
|
|
|
|
{
|
|
|
|
gfx_drawRect(screen, x, y, w, h, red, green, blue);
|
|
|
|
}
|