2
* OpenTyrian: A modern cross-platform port of Tyrian
3
* Copyright (C) 2007-2009 The OpenTyrian Development Team
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "config.h" // For fullscreen stuff
33
void JE_pix( SDL_Surface *surface, int x, int y, JE_byte c )
35
/* Bad things happen if we don't clip */
36
if (x < surface->pitch && y < surface->h)
38
Uint8 *vga = surface->pixels;
39
vga[y * surface->pitch + x] = c;
43
void JE_pix3( SDL_Surface *surface, int x, int y, JE_byte c )
45
/* Originally impemented as several direct accesses */
46
JE_pix(surface, x, y, c);
47
JE_pix(surface, x - 1, y, c);
48
JE_pix(surface, x + 1, y, c);
49
JE_pix(surface, x, y - 1, c);
50
JE_pix(surface, x, y + 1, c);
53
void JE_rectangle( SDL_Surface *surface, int a, int b, int c, int d, int e ) /* x1, y1, x2, y2, color */
55
if (a < surface->pitch && b < surface->h &&
56
c < surface->pitch && d < surface->h)
58
Uint8 *vga = surface->pixels;
62
memset(&vga[b * surface->pitch + a], e, c - a + 1);
65
memset(&vga[d * surface->pitch + a], e, c - a + 1);
68
for (i = (b + 1) * surface->pitch + a; i < (d * surface->pitch + a); i += surface->pitch)
74
for (i = (b + 1) * surface->pitch + c; i < (d * surface->pitch + c); i += surface->pitch)
79
printf("!!! WARNING: Rectangle clipped: %d %d %d %d %d\n", a, b, c, d, e);
83
void fill_rectangle_xy( SDL_Surface *surface, int x, int y, int x2, int y2, Uint8 color )
85
SDL_Rect rect = { x, y, x2 - x + 1, y2 - y + 1 };
86
SDL_FillRect(surface, &rect, color);
89
void JE_barShade( SDL_Surface *surface, int a, int b, int c, int d ) /* x1, y1, x2, y2 */
91
if (a < surface->pitch && b < surface->h &&
92
c < surface->pitch && d < surface->h)
94
Uint8 *vga = surface->pixels;
99
for (i = b * surface->pitch + a; i <= d * surface->pitch + a; i += surface->pitch)
101
for (j = 0; j < width; j++)
103
vga[i + j] = ((vga[i + j] & 0x0F) >> 1) | (vga[i + j] & 0xF0);
107
printf("!!! WARNING: Darker Rectangle clipped: %d %d %d %d\n", a,b,c,d);
111
void JE_barBright( SDL_Surface *surface, int a, int b, int c, int d ) /* x1, y1, x2, y2 */
113
if (a < surface->pitch && b < surface->h &&
114
c < surface->pitch && d < surface->h)
116
Uint8 *vga = surface->pixels;
121
for (i = b * surface->pitch + a; i <= d * surface->pitch + a; i += surface->pitch)
123
for (j = 0; j < width; j++)
126
al = ah = vga[i + j];
129
al = (al & 0x0F) + 2;
136
vga[i + j] = al + ah;
140
printf("!!! WARNING: Brighter Rectangle clipped: %d %d %d %d\n", a,b,c,d);
144
void draw_segmented_gauge( SDL_Surface *surface, int x, int y, Uint8 color, uint segment_width, uint segment_height, uint segment_value, uint value )
146
assert(segment_width > 0 && segment_height > 0);
148
const uint segments = value / segment_value,
149
partial_segment = value % segment_value;
151
for (uint i = 0; i < segments; ++i)
153
fill_rectangle_hw(surface, x, y, segment_width, segment_height, color + 12);
154
x += segment_width + 1;
156
if (partial_segment > 0)
157
fill_rectangle_hw(surface, x, y, segment_width, segment_height, color + (12 * partial_segment / segment_value));