Avoid non-alpha characters in _qdgdfv_alnum in win32.
[qdgdf.git] / qdgdf_video_ext.c
bloba479c46426172c980148754d3cf47a8aeef1ad8d
1 /*
3 Extension to the Quick and Dirty Game Development Framework (QDGDF)
5 Copyright (C) 2001 Daniel Compton <C_Anon01@yahoo.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "config.h"
25 #include "qdgdf_video_ext.h"
27 void qdgdfv_display_pcx(unsigned char *pcx, unsigned int w, unsigned int h, unsigned int x,
28 unsigned int y)
30 unsigned int sw = _qdgdfv_screen_x_size; /* max screen width is sw */
31 unsigned char *vscreen = _qdgdfv_virtual_screen + y * sw;
32 unsigned int i;
34 for (i = 0; i < h; i++) {
35 memcpy(vscreen + x, pcx, w);
36 vscreen += sw;
37 pcx += w;
41 int qdgdfv_display_pcx_safe(unsigned char *pcx, unsigned int w, unsigned int h, unsigned int x,
42 unsigned int y)
44 unsigned int sw = _qdgdfv_screen_x_size; /* max screen width is sw */
45 unsigned int sh = _qdgdfv_screen_y_size; /* max screen heigh is sh */
46 unsigned char *vscreen = _qdgdfv_virtual_screen;
47 unsigned int i;
49 if (x >= sw || y >= sh)
50 return 0;
52 if ((x + w) > sw)
53 w = sw - x;
54 if ((y + h) > sh)
55 h = sh - y;
57 vscreen += y * sw;
58 for (i = 0; i < h; i++) {
59 memcpy(vscreen + x, pcx, w);
60 vscreen += sw;
61 pcx += w;
64 return 1;
67 int qdgdfv_display_pcx_full(unsigned char *pcx, unsigned int w, unsigned int h, unsigned int x,
68 unsigned int y)
70 unsigned int sw = _qdgdfv_screen_x_size; /* max screen width is sw */
71 unsigned int sh = _qdgdfv_screen_y_size; /* max screen heigh is sh */
72 unsigned char *vscreen = _qdgdfv_virtual_screen;
73 unsigned int i;
75 if (w > sw || h > sh)
76 return 0;
78 if ((x + w) > sw) {
79 x = sw - w;
81 if ((y + h) > sh) {
82 y = sh - h;
85 vscreen += y * sw;
86 for (i = 0; i < h; i++) {
87 memcpy(vscreen + x, pcx, w);
88 vscreen += sw;
89 pcx += w;
92 return 1;
95 unsigned char qdgdfv_find_color(unsigned int r, unsigned int g, unsigned int b)
97 unsigned int *table = _qdgdfv_palette;
98 unsigned long lastcolor = abs(r - table[0]) + abs(g - table[1]) + abs(b - table[2]);
99 unsigned int i = 3;
100 unsigned int pos = 0;
102 for (; i < 256 * 3; i += 3) {
103 unsigned long curcolor =
104 abs(r - table[i]) + abs(g - table[i + 1]) + abs(b - table[i + 2]);
105 if (curcolor < lastcolor) {
106 lastcolor = curcolor;
107 pos = i;
110 return pos / 3;
113 int qdgdfv_plot_pixel_color(unsigned int x, unsigned int y, unsigned char color)
115 if (x < _qdgdfv_screen_x_size && y < _qdgdfv_screen_y_size) {
116 _qdgdfv_virtual_screen[y * _qdgdfv_screen_x_size + x] = color;
117 return 1;
119 return 0;
122 int qdgdfv_plot_pixel_rgb(unsigned int x, unsigned int y, unsigned long RGB)
124 if (x < _qdgdfv_screen_x_size && y < _qdgdfv_screen_y_size) {
125 _qdgdfv_virtual_screen[y * _qdgdfv_screen_x_size + x] =
126 qdgdfv_find_color(GetRValue(RGB), GetGValue(RGB), GetBValue(RGB));
127 return 1;
129 return 0;
132 int qdgdfv_draw_rect_fill(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
133 unsigned char color)
135 unsigned int sw = _qdgdfv_screen_x_size; /* max screen width is sw */
136 unsigned int sh = _qdgdfv_screen_y_size; /* max screen heigh is sh */
137 unsigned long totsw = x + w;
138 unsigned long totsh = y + h;
139 if ((totsw <= sw) && (totsh <= sh)) { /* if memset cant be sent a 0 length, then add (w != 0) */
140 unsigned char *vscreen = _qdgdfv_virtual_screen + y * sw;
141 unsigned int i = 0;
142 for (; i < h; i++) {
143 memset(vscreen + x, color, w);
144 vscreen += sw;
146 return 1;
148 return 0;
151 /* wallw is number of pixels for size of the wall */
152 int qdgdfv_draw_rect(unsigned int x, unsigned int y, unsigned int w, unsigned int h,
153 unsigned int wallw, unsigned char color)
155 int result;
156 result = qdgdfv_draw_hline(x, y, w, wallw, color);
157 if (!result)
158 return result;
159 result = qdgdfv_draw_vline(x, y, h, wallw, color);
160 if (!result)
161 return result;
162 result = qdgdfv_draw_hline(x, y + h - wallw, w, wallw, color);
163 if (!result)
164 return result;
165 result = qdgdfv_draw_vline(x + w - wallw, y, h, wallw, color);
166 return result;