Debian Codegraph @

src/vga256d.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 #include "vga256d.h"cxx . . $ `<file>/src/vga256d.h`/
20
21 #include "config.h"cxx . . $ `<file>/src/config.h`/ // For fullscreen stuff
22 #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/
23 #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/
24 #include "palette.h"cxx . . $ `<file>/src/palette.h`/
25 #include "video.h"cxx . . $ `<file>/src/video.h`/
26
27 #include "SDL.h"
28
29 #include <assert.h>
30 #include <ctype.h>
31 #include <math.h>
32 #include <stdio.h>
33 #include <string.h>
34
35 void JE_pixcxx . . $ JE_pix(a8f544383a9967e9).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int x, int y, JE_bytecxx . . $ JE_byte# c)
36 {
37 /* Bad things happen if we don't clip */
38 if (x < surface->pitchcxx . . $ SDL_Surface#pitch. && y < surface->hcxx . . $ SDL_Surface#h.)
39 {
40 Uint8cxx . . $ Uint8# *vga = surface->pixelscxx . . $ SDL_Surface#pixels.;
41 vga[y * surface->pitchcxx . . $ SDL_Surface#pitch. + x] = c;
42 }
43 }
44
45 void JE_pix3cxx . . $ JE_pix3(a8f544383a9967e9).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int x, int y, JE_bytecxx . . $ JE_byte# c)
46 {
47 /* Originally implemented as several direct accesses */
48 JE_pixcxx . . $ JE_pix(a8f544383a9967e9).(surface, x, y, c);
49 JE_pixcxx . . $ JE_pix(a8f544383a9967e9).(surface, x - 1, y, c);
50 JE_pixcxx . . $ JE_pix(a8f544383a9967e9).(surface, x + 1, y, c);
51 JE_pixcxx . . $ JE_pix(a8f544383a9967e9).(surface, x, y - 1, c);
52 JE_pixcxx . . $ JE_pix(a8f544383a9967e9).(surface, x, y + 1, c);
53 }
54
55 void JE_rectanglecxx . . $ JE_rectangle(fa5faf37b232239e).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int a, int b, int c, int d, int e) /* x1, y1, x2, y2, color */
56 {
57 if (a < surface->pitchcxx . . $ SDL_Surface#pitch. && b < surface->hcxx . . $ SDL_Surface#h. &&
58 c < surface->pitchcxx . . $ SDL_Surface#pitch. && d < surface->hcxx . . $ SDL_Surface#h.)
59 {
60 Uint8cxx . . $ Uint8# *vga = surface->pixelscxx . . $ SDL_Surface#pixels.;
61 int i;
62
63 /* Top line */
64 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&vga[b * surface->pitchcxx . . $ SDL_Surface#pitch. + a], e, c - a + 1);
65
66 /* Bottom line */
67 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&vga[d * surface->pitchcxx . . $ SDL_Surface#pitch. + a], e, c - a + 1);
68
69 /* Left line */
70 for (i = (b + 1) * surface->pitchcxx . . $ SDL_Surface#pitch. + a; i < (d * surface->pitchcxx . . $ SDL_Surface#pitch. + a); i += surface->pitchcxx . . $ SDL_Surface#pitch.)
71 {
72 vga[i] = e;
73 }
74
75 /* Right line */
76 for (i = (b + 1) * surface->pitchcxx . . $ SDL_Surface#pitch. + c; i < (d * surface->pitchcxx . . $ SDL_Surface#pitch. + c); i += surface->pitchcxx . . $ SDL_Surface#pitch.)
77 {
78 vga[i] = e;
79 }
80 }
81 else
82 {
83 printfcxx . . $ printf(581fddd72a8db8fc).("!!! WARNING: Rectangle clipped: %d %d %d %d %d\n", a, b, c, d, e);
84 }
85 }
86
87 void fill_rectangle_xycxx . . $ fill_rectangle_xy(da1d960d0d6e485d).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int x, int y, int x2, int y2, Uint8cxx . . $ Uint8# color)
88 {
89 SDL_Rectcxx . . $ SDL_Rect# rect = { x, y, x2 - x + 1, y2 - y + 1 };
90 SDL_FillRectcxx . . $ SDL_FillRect(3ec95406e4bae91).(surface, &rect, color);
91 }
92
93 void JE_barShadecxx . . $ JE_barShade(ad548318d53dbf5e).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int a, int b, int c, int d) /* x1, y1, x2, y2 */
94 {
95 if (a < surface->pitchcxx . . $ SDL_Surface#pitch. && b < surface->hcxx . . $ SDL_Surface#h. &&
96 c < surface->pitchcxx . . $ SDL_Surface#pitch. && d < surface->hcxx . . $ SDL_Surface#h.)
97 {
98 Uint8cxx . . $ Uint8# *vga = surface->pixelscxx . . $ SDL_Surface#pixels.;
99 int i, j, width;
100
101 width = c - a + 1;
102
103 for (i = b * surface->pitchcxx . . $ SDL_Surface#pitch. + a; i <= d * surface->pitchcxx . . $ SDL_Surface#pitch. + a; i += surface->pitchcxx . . $ SDL_Surface#pitch.)
104 {
105 for (j = 0; j < width; j++)
106 {
107 vga[i + j] = ((vga[i + j] & 0x0F) >> 1) | (vga[i + j] & 0xF0);
108 }
109 }
110 }
111 else
112 {
113 printfcxx . . $ printf(581fddd72a8db8fc).("!!! WARNING: Darker Rectangle clipped: %d %d %d %d\n", a,b,c,d);
114 }
115 }
116
117 void JE_barBrightcxx . . $ JE_barBright(ad548318d53dbf5e).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int a, int b, int c, int d) /* x1, y1, x2, y2 */
118 {
119 if (a < surface->pitchcxx . . $ SDL_Surface#pitch. && b < surface->hcxx . . $ SDL_Surface#h. &&
120 c < surface->pitchcxx . . $ SDL_Surface#pitch. && d < surface->hcxx . . $ SDL_Surface#h.)
121 {
122 Uint8cxx . . $ Uint8# *vga = surface->pixelscxx . . $ SDL_Surface#pixels.;
123 int i, j, width;
124
125 width = c-a+1;
126
127 for (i = b * surface->pitchcxx . . $ SDL_Surface#pitch. + a; i <= d * surface->pitchcxx . . $ SDL_Surface#pitch. + a; i += surface->pitchcxx . . $ SDL_Surface#pitch.)
128 {
129 for (j = 0; j < width; j++)
130 {
131 JE_bytecxx . . $ JE_byte# al, ah;
132 al = ah = vga[i + j];
133
134 ah &= 0xF0;
135 al = (al & 0x0F) + 2;
136
137 if (al > 0x0F)
138 {
139 al = 0x0F;
140 }
141
142 vga[i + j] = al + ah;
143 }
144 }
145 }
146 else
147 {
148 printfcxx . . $ printf(581fddd72a8db8fc).("!!! WARNING: Brighter Rectangle clipped: %d %d %d %d\n", a,b,c,d);
149 }
150 }
151
152 void draw_segmented_gaugecxx . . $ draw_segmented_gauge(915c4eaa04ad7c00).(SDL_Surfacecxx . . $ SDL_Surface# *surface, int x, int y, Uint8cxx . . $ Uint8# color, uintcxx . . $ uint# segment_width, uintcxx . . $ uint# segment_height, uintcxx . . $ uint# segment_value, uintcxx . . $ uint# value)
153 {
154 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(segment_width > 0 && segment_height > 0);
155
156 const uintcxx . . $ uint# segments = value / segment_value,
157 partial_segment = value % segment_value;
158
159 for (uintcxx . . $ uint# i = 0; i < segments; ++i)
160 {
161 fill_rectangle_whcxx . . $ fill_rectangle_wh(2ff783435439505a).(surface, x, y, segment_width, segment_height, color + 12);
162 x += segment_width + 1;
163 }
164 if (partial_segment > 0)
165 fill_rectangle_whcxx . . $ fill_rectangle_wh(2ff783435439505a).(surface, x, y, segment_width, segment_height, color + (12 * partial_segment / segment_value));
166 }