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 */
120136void 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
175203void 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
508539TbBool 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/******************************************************************************/
0 commit comments