| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: heads-up text and input code |
| 30 |
* |
| 31 |
*----------------------------------------------------------------------------- |
| 32 |
*/ |
| 33 |
|
| 34 |
#include "doomdef.h" |
| 35 |
#include "doomstat.h" |
| 36 |
#include "v_video.h" |
| 37 |
#include "hu_lib.h" |
| 38 |
#include "hu_stuff.h" |
| 39 |
#include "r_main.h" |
| 40 |
#include "r_draw.h" |
| 41 |
|
| 42 |
#include "dsda/stretch.h" |
| 43 |
|
| 44 |
#define HU_COLOR 0x30 |
| 45 |
|
| 46 |
char HUlib_Color(int cm) |
| 47 |
{ |
| 48 |
return HU_COLOR + cm; |
| 49 |
} |
| 50 |
|
| 51 |
//////////////////////////////////////////////////////// |
| 52 |
// |
| 53 |
// Basic text line widget |
| 54 |
// |
| 55 |
//////////////////////////////////////////////////////// |
| 56 |
|
| 57 |
// |
| 58 |
// HUlib_clearTextLine() |
| 59 |
// |
| 60 |
// Blank the internal text line in a hu_textline_t widget |
| 61 |
// |
| 62 |
// Passed a hu_textline_t, returns nothing |
| 63 |
// |
| 64 |
void HUlib_clearTextLine(hu_textline_t* t) |
| 65 |
{ |
| 66 |
t->linelen = // killough 1/23 98: support multiple lines |
| 67 |
t->len = 0; |
| 68 |
t->l[0] = 0; |
| 69 |
} |
| 70 |
|
| 71 |
// |
| 72 |
// HUlib_initTextLine() |
| 73 |
// |
| 74 |
// Initialize a hu_textline_t widget. Set the position, font, start char |
| 75 |
// of the font, and color range to be used. |
| 76 |
// |
| 77 |
// Passed a hu_textline_t, and the values used to initialize |
| 78 |
// Returns nothing |
| 79 |
// |
| 80 |
void HUlib_initTextLine(hu_textline_t* t, int x, int y, |
| 81 |
const dsda_font_t* f, int cm, enum patch_translation_e flags ) |
| 82 |
//jff 2/16/98 add color range parameter |
| 83 |
{ |
| 84 |
t->x = x; |
| 85 |
t->y = y; |
| 86 |
t->f = f->font; |
| 87 |
t->sc = f->start; |
| 88 |
t->cm = cm; |
| 89 |
t->flags = flags; |
| 90 |
t->line_height = f->line_height; |
| 91 |
t->space_width = f->space_width; |
| 92 |
HUlib_clearTextLine(t); |
| 93 |
} |
| 94 |
|
| 95 |
// |
| 96 |
// HUlib_addCharToTextLine() |
| 97 |
// |
| 98 |
// Adds a character at the end of the text line in a hu_textline_t widget |
| 99 |
// |
| 100 |
// Passed the hu_textline_t and the char to add |
| 101 |
// Returns false if already at length limit, true if the character added |
| 102 |
// |
| 103 |
dboolean HUlib_addCharToTextLine |
| 104 |
( hu_textline_t* t, |
| 105 |
char ch ) |
| 106 |
{ |
| 107 |
// killough 1/23/98 -- support multiple lines |
| 108 |
if (t->linelen == HU_MAXLINELENGTH) |
| 109 |
return false; |
| 110 |
else |
| 111 |
{ |
| 112 |
t->linelen++; |
| 113 |
if (ch == '\n') |
| 114 |
t->linelen=0; |
| 115 |
|
| 116 |
t->l[t->len++] = ch; |
| 117 |
t->l[t->len] = 0; |
| 118 |
return true; |
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
// |
| 124 |
// HUlib_drawTextLine() |
| 125 |
// |
| 126 |
// Draws a hu_textline_t widget |
| 127 |
// |
| 128 |
// Passed the hu_textline_t and flag whether to draw a cursor |
| 129 |
// Returns nothing |
| 130 |
// |
| 131 |
void HUlib_drawTextLine |
| 132 |
( hu_textline_t* l, |
| 133 |
dboolean drawcursor ) |
| 134 |
{ |
| 135 |
|
| 136 |
int i; |
| 137 |
int w; |
| 138 |
int x; |
| 139 |
unsigned char c; |
| 140 |
int oc = l->cm; //jff 2/17/98 remember default color |
| 141 |
int y; // killough 1/18/98 -- support multiple lines |
| 142 |
|
| 143 |
// draw the new stuff |
| 144 |
|
| 145 |
x = l->x; |
| 146 |
y = l->y; |
| 147 |
for (i=0;i<l->len;i++) |
| 148 |
{ |
| 149 |
c = toupper(l->l[i]); //jff insure were not getting a cheap toupper conv. |
| 150 |
|
| 151 |
if (c=='\n') // killough 1/18/98 -- support multiple lines |
| 152 |
{ |
| 153 |
x = l->x; |
| 154 |
y += l->line_height; |
| 155 |
} |
| 156 |
else if (c=='\t') // killough 1/23/98 -- support tab stops |
| 157 |
x=x-x%80+80; |
| 158 |
else if (c=='\x1b') //jff 2/17/98 escape code for color change |
| 159 |
{ //jff 3/26/98 changed to actual escape char |
| 160 |
if (++i < l->len) |
| 161 |
{ |
| 162 |
if (l->l[i] >= HU_COLOR && l->l[i] < HU_COLOR + CR_HUD_LIMIT) |
| 163 |
l->cm = l->l[i] - HU_COLOR; |
| 164 |
else if (l->l[i] < HU_COLOR) |
| 165 |
x += l->l[i]; |
| 166 |
} |
| 167 |
} |
| 168 |
else if (c != ' ' && c >= l->sc && c <= 127) |
| 169 |
{ |
| 170 |
w = l->f[c - l->sc].width; |
| 171 |
if (x+w-l->f[c - l->sc].leftoffset > BASE_WIDTH) |
| 172 |
break; |
| 173 |
// killough 1/18/98 -- support multiple lines: |
| 174 |
// CPhipps - patch drawing updated |
| 175 |
V_DrawNumPatch(x, y, FG, l->f[c - l->sc].lumpnum, l->cm, VPT_TRANS | l->flags); |
| 176 |
x += w; |
| 177 |
} |
| 178 |
else |
| 179 |
{ |
| 180 |
x += l->space_width; |
| 181 |
if (x >= BASE_WIDTH) |
| 182 |
break; |
| 183 |
} |
| 184 |
} |
| 185 |
l->cm = oc; //jff 2/17/98 restore original color |
| 186 |
|
| 187 |
// draw the cursor if requested |
| 188 |
if (drawcursor && x + l->f['_' - l->sc].width <= BASE_WIDTH) |
| 189 |
{ |
| 190 |
// killough 1/18/98 -- support multiple lines |
| 191 |
// CPhipps - patch drawing updated |
| 192 |
V_DrawNumPatch(x, y, FG, l->f['_' - l->sc].lumpnum, CR_DEFAULT, VPT_NONE | l->flags); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
void HUlib_drawOffsetTextLine(hu_textline_t* l, int offset) |
| 197 |
{ |
| 198 |
int old_y; |
| 199 |
|
| 200 |
old_y = l->y; |
| 201 |
l->y += offset; |
| 202 |
HUlib_drawTextLine(l, false); |
| 203 |
l->y = old_y; |
| 204 |
} |
| 205 |
|
| 206 |
// |
| 207 |
// HUlib_setTextXCenter() |
| 208 |
// |
| 209 |
// Centering a hu_textline_t |
| 210 |
// |
| 211 |
// Passed the hu_textline_t |
| 212 |
// Returns nothing |
| 213 |
// |
| 214 |
void HUlib_setTextXCenter(hu_textline_t* t) |
| 215 |
{ |
| 216 |
char *s = t->l; |
| 217 |
t->x = 320; |
| 218 |
while (*s) |
| 219 |
{ |
| 220 |
int c = toupper(*(s++)) - HU_FONTSTART; |
| 221 |
t->x -= (c < 0 || c > HU_FONTSIZE ? t->space_width : t->f[c].width); |
| 222 |
} |
| 223 |
if (t->x < 0) |
| 224 |
t->x = 0; |
| 225 |
|
| 226 |
t->x >>= 1; |
| 227 |
} |