Skip to content

Commit 9686ae6

Browse files
committed
swars: Switched to new way of drawing mission status
The drawing function is now similar to what we use for drawing other text, only with added colour wave effect. The results are better scaling, and dynamic selection of a shift for shadow behind the text.
1 parent bd29477 commit 9686ae6

File tree

4 files changed

+138
-38
lines changed

4 files changed

+138
-38
lines changed

src/app_text.c

Lines changed: 124 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
#include "display.h"
3636
#include "scandraw.h"
3737
#include "game_speed.h"
38+
#include "game_sprts.h"
3839
#include "hud_panel.h"
3940
#include "mydraw.h"
41+
#include "swlog.h"
4042

4143
#if defined(LB_ENABLE_SHADOW_COLOUR)
4244
# define SHADOW_COLOUR lbDisplay.ShadowColour
@@ -54,54 +56,67 @@ TbBool is_wide_charcode(ulong chr);
5456
* @param ebuf
5557
* @param x
5658
* @param y
57-
* @param len
59+
* @param space_len
5860
*/
59-
void put_down_colwavetext_sprites(const char *sbuf, const char *ebuf, long x, long y, long len)
61+
void put_down_colwavetext_sprites(const char *sbuf, const char *ebuf,
62+
long x, long y, long space_len,
63+
ubyte cw_base, ubyte cw_vari, ubyte cw_shift)
6064
{
6165
const char *c;
6266
const struct TbSprite *spr;
6367
ubyte chr;
6468
long w,h;
6569
for (c=sbuf; c < ebuf; c++)
6670
{
71+
ushort fade_lv;
72+
TbPixel colour;
73+
74+
fade_lv = cw_base + cw_vari/2 - (cw_vari/2 * lbSinTable[LbFPMath_PI/8 * (cw_shift & 0xF)] >> 16);
75+
colour = lbDisplay.DrawColour;
76+
colour = pixmap.fade_table[fade_lv * PALETTE_8b_COLORS + colour];
6777
chr = (ubyte)(*c);
6878
if (chr > 32)
6979
{
7080
spr = LbFontCharSprite(lbFontPtr,chr);
7181
if (spr != NULL)
7282
{
83+
// Draw shadow
84+
LbSpriteDrawOneColour(x + 1, y + 1, spr, SHADOW_COLOUR);
7385
if ((lbDisplay.DrawFlags & Lb_TEXT_ONE_COLOR) != 0)
74-
LbSpriteDrawOneColour(x, y, spr, lbDisplay.DrawColour);
86+
LbSpriteDrawOneColour(x, y, spr, colour);
7587
else
7688
LbSpriteDraw(x, y, spr);
7789
w = spr->SWidth;
7890
if ((lbDisplay.DrawFlags & Lb_TEXT_UNDERLINE) != 0)
7991
{
8092
h = LbTextLineHeight();
81-
LbDrawCharUnderline(x, y, w, h, lbDisplay.DrawColour, SHADOW_COLOUR);
93+
LbDrawCharUnderline(x, y, w, h, colour, SHADOW_COLOUR);
8294
}
8395
x += w;
96+
cw_shift += 1;
8497
}
8598
} else
8699
if (chr == ' ')
87100
{
88-
w = len;
101+
w = space_len;
89102
if ((lbDisplay.DrawFlags & Lb_TEXT_UNDERLINE) != 0)
90103
{
91104
h = LbTextLineHeight();
92-
LbDrawCharUnderline(x, y, w, h, lbDisplay.DrawColour, SHADOW_COLOUR);
105+
LbDrawCharUnderline(x, y, w, h, colour, SHADOW_COLOUR);
93106
}
94107
x += w;
108+
cw_shift += 1;
95109
} else
96110
if (chr == '\t')
97111
{
98-
w = len*(long)lbSpacesPerTab;
112+
w = space_len*(long)lbSpacesPerTab;
99113
if ((lbDisplay.DrawFlags & Lb_TEXT_UNDERLINE) != 0)
100114
{
101115
h = LbTextLineHeight();
102-
LbDrawCharUnderline(x, y, w, h, lbDisplay.DrawColour, SHADOW_COLOUR);
116+
LbDrawCharUnderline(x, y, w, h, colour, SHADOW_COLOUR);
103117
}
104118
x += w;
119+
cw_shift += lbSpacesPerTab;
105120
} else
106121
{
107122
LbIApplyControlCharToDrawSettings(&c);
@@ -115,35 +130,46 @@ void put_down_colwavetext_sprites(const char *sbuf, const char *ebuf, long x, lo
115130
* @param ebuf
116131
* @param x
117132
* @param y
118-
* @param len
133+
* @param space_len
134+
* @param units_per_px
119135
*/
120136
void put_down_colwavetext_sprites_resized(const char *sbuf, const char *ebuf,
121-
long x, long y, long space_len, int units_per_px)
137+
long x, long y, long space_len, int units_per_px,
138+
ubyte cw_base, ubyte cw_vari, ubyte cw_shift)
122139
{
123140
const char *c;
124141
const struct TbSprite *spr;
125142
ubyte chr;
126143
long w,h;
127144
for (c=sbuf; c < ebuf; c++)
128145
{
146+
ushort fade_lv;
147+
TbPixel colour;
148+
149+
fade_lv = cw_base + cw_vari/2 - (cw_vari/2 * lbSinTable[LbFPMath_PI/8 * (cw_shift & 0xF)] >> 16);
150+
colour = lbDisplay.DrawColour;
151+
colour = pixmap.fade_table[fade_lv * PALETTE_8b_COLORS + colour];
129152
chr = (ubyte)(*c);
130153
if (chr > 32)
131154
{
132155
spr = LbFontCharSprite(lbFontPtr,chr);
133156
if (spr != NULL)
134157
{
158+
// Draw shadow
159+
LbSpriteDrawResizedOneColour(x + units_per_px/12, y + units_per_px/12, units_per_px, spr, SHADOW_COLOUR);
135160
if ((lbDisplay.DrawFlags & Lb_TEXT_ONE_COLOR) != 0) {
136-
LbSpriteDrawResizedOneColour(x, y, units_per_px, spr, lbDisplay.DrawColour);
161+
LbSpriteDrawResizedOneColour(x, y, units_per_px, spr, colour);
137162
} else {
138163
LbSpriteDrawResized(x, y, units_per_px, spr);
139164
}
140165
w = spr->SWidth * units_per_px / 16;
141166
if ((lbDisplay.DrawFlags & Lb_TEXT_UNDERLINE) != 0)
142167
{
143168
h = LbTextLineHeight() * units_per_px / 16;
144-
LbDrawCharUnderline(x, y, w, h, lbDisplay.DrawColour, SHADOW_COLOUR);
169+
LbDrawCharUnderline(x, y, w, h, colour, SHADOW_COLOUR);
145170
}
146171
x += w;
172+
cw_shift += 1;
147173
}
148174
} else
149175
if (chr == ' ')
@@ -152,19 +178,21 @@ void put_down_colwavetext_sprites_resized(const char *sbuf, const char *ebuf,
152178
if ((lbDisplay.DrawFlags & Lb_TEXT_UNDERLINE) != 0)
153179
{
154180
h = LbTextLineHeight() * units_per_px / 16;
155-
LbDrawCharUnderline(x, y, w, h, lbDisplay.DrawColour, SHADOW_COLOUR);
181+
LbDrawCharUnderline(x, y, w, h, colour, SHADOW_COLOUR);
156182
}
157183
x += w;
184+
cw_shift += 1;
158185
} else
159186
if (chr == '\t')
160187
{
161188
w = space_len*(long)lbSpacesPerTab;
162189
if ((lbDisplay.DrawFlags & Lb_TEXT_UNDERLINE) != 0)
163190
{
164191
h = LbTextLineHeight() * units_per_px / 16;
165-
LbDrawCharUnderline(x, y, w, h, lbDisplay.DrawColour, SHADOW_COLOUR);
192+
LbDrawCharUnderline(x, y, w, h, colour, SHADOW_COLOUR);
166193
}
167194
x += w;
195+
cw_shift += lbSpacesPerTab;
168196
} else
169197
{
170198
LbIApplyControlCharToDrawSettings(&c);
@@ -173,14 +201,14 @@ void put_down_colwavetext_sprites_resized(const char *sbuf, const char *ebuf,
173201
}
174202

175203
void put_down_cw_sprites(const char *sbuf, const char *ebuf,
176-
long x, long y, long len, int units_per_px)
204+
long x, long y, long space_len, int units_per_px)
177205
{
178206
if (units_per_px == 16)
179207
{
180-
put_down_colwavetext_sprites(sbuf, ebuf, x, y, len);
208+
put_down_colwavetext_sprites(sbuf, ebuf, x, y, space_len, 32, 16, gameturn);
181209
} else
182210
{
183-
put_down_colwavetext_sprites_resized(sbuf, ebuf, x, y, len, units_per_px);
211+
put_down_colwavetext_sprites_resized(sbuf, ebuf, x, y, space_len, units_per_px, 32, 16, gameturn);
184212
}
185213
}
186214

@@ -455,8 +483,11 @@ void draw_text_linewrap2b(int base_x, int *p_pos_y, const char *text)
455483
int pos_x, pos_y;
456484
int base_shift;
457485
TbPixel col2;
486+
int cw_base, cw_vari;
458487

459-
col2 = SCANNER_colour[0];
488+
cw_base = 32;
489+
cw_vari = 16;
490+
col2 = lbDisplay.DrawColour;
460491
pos_x = base_x;
461492
str = text;
462493
pos_y = *p_pos_y;
@@ -492,10 +523,10 @@ void draw_text_linewrap2b(int base_x, int *p_pos_y, const char *text)
492523
struct TbSprite *p_spr;
493524
ushort fade_lv;
494525

495-
fade_lv = 40 - (lbSinTable[128 * ((gameturn + base_shift) & 0xF)] >> 13);
526+
fade_lv = cw_base + cw_vari/2 - (cw_vari/2 * lbSinTable[LbFPMath_PI/8 * ((gameturn + base_shift) & 0xF)] >> 16);
496527
p_spr = &lbFontPtr[my_char_to_upper(*str) - 31];
497528
LbSpriteDrawOneColour(pos_x + 1, pos_y + 1, p_spr, colour_lookup[0]);
498-
LbSpriteDrawOneColour(pos_x, pos_y, p_spr, pixmap.fade_table[256 * fade_lv + col2]);
529+
LbSpriteDrawOneColour(pos_x, pos_y, p_spr, pixmap.fade_table[fade_lv * PALETTE_8b_COLORS + col2]);
499530
pos_x += p_spr->SWidth;
500531
}
501532
str++;
@@ -507,14 +538,6 @@ void draw_text_linewrap2b(int base_x, int *p_pos_y, const char *text)
507538

508539
TbBool AppTextDrawColourWaveResized(int posx, int posy, int units_per_px, const char *text)
509540
{
510-
#if 1
511-
// TODO prepare the function to scale this font to any size, rather than only 1x or 2x selection
512-
if (units_per_px < 24)
513-
draw_text_linewrap2b(posx, &posy, text);
514-
else
515-
draw_text_linewrap1b(posx, &posy, text);
516-
return true;
517-
#endif
518541
struct TbAnyWindow grwnd;
519542
// Counter for amount of blank characters in a line
520543
long count;
@@ -706,4 +729,77 @@ TbBool AppTextDrawColourBorderResized(int posx, int *posy, int units_per_px, int
706729
#endif
707730
}
708731

732+
/** Altered version of LbFontCharSprite() which returns non-const reference.
733+
*/
734+
struct TbSprite *AppFontCharSpriteRW(struct TbSprite *font,
735+
const ulong chr)
736+
{
737+
if (font == NULL)
738+
return NULL;
739+
if ((chr >= 31) && (chr < 256))
740+
return &font[(chr-31)];
741+
return NULL;
742+
}
743+
744+
/** Modifies spacing of given font, by altering width of space character.
745+
*/
746+
ushort FontSpacingAlter(struct TbSprite *font, int units_per_px)
747+
{
748+
struct TbSprite *p_spr;
749+
ushort space_bkp;
750+
751+
p_spr = AppFontCharSpriteRW(font, ' ');
752+
if (p_spr == NULL)
753+
return 0;
754+
space_bkp = p_spr->SWidth;
755+
p_spr->SWidth = (space_bkp * units_per_px) / 16;
756+
return space_bkp;
757+
}
758+
759+
void FontSpacingRestore(struct TbSprite *font, ushort space_bkp)
760+
{
761+
struct TbSprite *p_spr;
762+
763+
p_spr = AppFontCharSpriteRW(font, ' ');
764+
if (p_spr == NULL)
765+
return;
766+
p_spr->SWidth = space_bkp;
767+
}
768+
769+
TbBool AppTextDrawMissionStatus(int posx, int posy, const char *text)
770+
{
771+
ushort space_bkp;
772+
int tx_height;
773+
int units_per_px;
774+
TbBool ret;
775+
776+
lbFontPtr = small_font;
777+
tx_height = font_height('A');
778+
// For window width=320, expect text height=5; so that should
779+
// produce unscaled sprite, which is 16 units per px.
780+
units_per_px = (lbDisplay.GraphicsWindowWidth * 5 / tx_height) / (320 / 16);
781+
// Do not allow any scale, only n * 50%
782+
units_per_px = (units_per_px + 4) & ~0x07;
783+
784+
lbDisplay.DrawFlags = Lb_TEXT_ONE_COLOR | Lb_TEXT_HALIGN_LEFT;
785+
lbDisplay.DrawColour = SCANNER_colour[0];
786+
#if defined(LB_ENABLE_SHADOW_COLOUR)
787+
lbDisplay.ShadowColour = colour_lookup[ColLU_BLACK];
788+
#endif
789+
#if 0 // old way of drawing mission status - remove pending
790+
if (gameturn & 0x40) {
791+
// TODO prepare the function to scale this font to any size, rather than only 1x or 2x selection
792+
if (units_per_px < 24)
793+
draw_text_linewrap2b(posx, &posy, text);
794+
else
795+
draw_text_linewrap1b(posx, &posy, text);
796+
return true;
797+
}
798+
#endif
799+
space_bkp = FontSpacingAlter(small_font, 12);
800+
ret = AppTextDrawColourWaveResized(posx, posy, units_per_px, text);
801+
FontSpacingRestore(small_font, space_bkp);
802+
return ret;
803+
}
804+
709805
/******************************************************************************/

src/app_text.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ TbBool AppTextDrawColourWaveResized(int posx, int posy, int units_per_px, const
5050

5151
TbBool AppTextDrawColourBorderResized(int posx, int *posy, int units_per_px, int plyr, const char *text);
5252

53+
TbBool AppTextDrawMissionStatus(int posx, int posy, const char *text);
54+
5355
#ifdef __cplusplus
5456
};
5557
#endif

src/game.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "bfplanar.h"
3535
#include "bfscrsurf.h"
3636
#include "bfscrcopy.h"
37+
#include "bfstrut.h"
3738
#include "bfsmack.h"
3839
#include "bftringl.h"
3940
#include "bfscd.h"
@@ -120,6 +121,7 @@
120121
#include "plyr_packet.h"
121122
#include "research.h"
122123
#include "rules.h"
124+
#include "scandraw.h"
123125
#include "thing.h"
124126
#include "tngcolisn.h"
125127
#include "tngobjdrw.h"
@@ -6804,21 +6806,16 @@ void draw_mission_concluded(void)
68046806
gui_strings[GSTR_CHK_MISSION_STA_SUF_KEYS], text_time, tm_h, tm_m % 60, tm_s);
68056807
data_15319c = unknmsg_str;
68066808
scroll_text = unknmsg_str;
6809+
LbStringToUpper(unknmsg_str);
68076810
}
68086811
{
68096812
int scr_x, scr_y;
6810-
int tx_height;
6811-
int units_per_px;
68126813

68136814
// TODO the text position should be computed based on position of panels loaded from file
68146815
scr_x = 11 * pop1_sprites_scale;
68156816
scr_y = 26 * pop1_sprites_scale;
6816-
lbFontPtr = small_font;
6817-
tx_height = font_height('A');
6818-
// For window width=320, expect text height=6; so that should
6819-
// produce unscaled sprite, which is 16 units per px.
6820-
units_per_px = (lbDisplay.GraphicsWindowWidth * 6 / tx_height) / (320 / 16);
6821-
AppTextDrawColourWaveResized(scr_x, scr_y, units_per_px, data_15319c);
6817+
6818+
AppTextDrawMissionStatus(scr_x, scr_y, data_15319c);
68226819
}
68236820
}
68246821

src/hud_panel.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ void draw_players_chat_talk(int x, int y)
291291

292292
lbFontPtr = small_font;
293293
tx_height = font_height('A');
294-
// For window width=320, expect text height=6; so that should
294+
// For window width=320, expect text height=5; so that should
295295
// produce unscaled sprite, which is 16 units per px.
296-
units_per_px = (lbDisplay.GraphicsWindowWidth * 6 / tx_height) / (320 / 16);
296+
units_per_px = (lbDisplay.GraphicsWindowWidth * 5 / tx_height) / (320 / 16);
297297
}
298298

299299
for (plyr = 0; plyr < PLAYERS_LIMIT; plyr++)
@@ -316,6 +316,11 @@ void draw_players_chat_talk(int x, int y)
316316
sprintf(locstr, "%s said nothing.", plname);
317317
}
318318

319+
lbDisplay.DrawFlags = Lb_TEXT_ONE_COLOR;
320+
lbDisplay.DrawColour = SCANNER_colour[0];
321+
#if defined(LB_ENABLE_SHADOW_COLOUR)
322+
lbDisplay.ShadowColour = colour_lookup[ColLU_BLACK];
323+
#endif
319324
AppTextDrawColourBorderResized(base_x, &pos_y, units_per_px, plyr, locstr);
320325

321326
if ( !--player_unkn0C9[plyr] ) {

0 commit comments

Comments
 (0)