1 /**
2  * @file controller_font_menu.cc
3  * @brief Controller of the menu scroll text
4  * @date 2007-10-21
5  * @copyright 1991-2014 TLK Games
6  * @author Bruno Ethvignot
7  * @version $Revision: 24 $
8  */
9 /*
10  * copyright (c) 1991-2014 TLK Games all rights reserved
11  * $Id: controller_font_menu.cc 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $
12  *
13  * TecnoballZ is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * TecnoballZ is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  * MA  02110-1301, USA.
27  */
28 #include "../include/controller_font_menu.h"
29 #include "../include/handler_resources.h"
30 
31 /**
32  * Create the scroll text controller
33  */
controller_font_menu()34 controller_font_menu::controller_font_menu ()
35 {
36   littleInit ();
37   max_of_sprites = MAX_OF_FONTS + 2;
38   sprites_have_shades = true;
39   sprite_type_id = sprite_object::FONT_MENU;
40   offset_xx1 = 0;
41   offset_yy1 = 0;
42 }
43 
44 /**
45  * Release the scroll text controller
46  */
~controller_font_menu()47 controller_font_menu::~controller_font_menu ()
48 {
49   if (NULL != scrolltexts)
50     {
51       delete[](char *)scrolltexts;
52       scrolltexts = NULL;
53     }
54   release_sprites_list ();
55 }
56 
57 /**
58  * Perform some initializations
59  */
60 void
create_fontes_list()61 controller_font_menu::create_fontes_list ()
62 {
63   create_sprites_list ();
64   Uint32 i;
65   /* fisrt element of the list is NULL */
66   characters_list[0] = NULL;
67   Uint32 j = 0;
68   for (i = 0; i < MAX_OF_FONTS; i++, j = (j + 18) & SINUS_MASK)
69     {
70       sprite_font_menu *sprite = sprites_list[i];
71       characters_list[i + 1] = sprite;
72       sprite->zeCosValue = j;
73       sprite->set_x_coord (100);
74       sprite->set_y_coord (300);
75       sprite->set_image (26);
76     }
77   characters_list[i + 1] = NULL;
78   objectLeft = sprites_list[i++];
79   objectRigh = sprites_list[i];
80   objectLeft->set_image (42);
81   objectRigh->set_image (42);
82   enable_sprites ();
83   object_ptr = &characters_list[MAX_OF_FONTS];
84   scrolltexts = resources->load_texts (handler_resources::TEXTS_SCROLL_MENU, 1, 0, 0);
85   scrollText = scrolltexts[0];
86   scroll_ptr = scrollText;
87 }
88 
89 /**
90  * Moving of the fonts
91  */
92 void
move_chars()93 controller_font_menu::move_chars ()
94 {
95   Sint32 a, b, width;
96   Sint16 *table, *sinPT, *cosPT;
97   sprite_font_menu *sprite;
98   sprite_font_menu *zzBOB;
99   /* convert unsigned to signed */
100   Sint32 res = (Sint32) resolution;
101 
102   sinPT = table_sinL;
103   cosPT = table_cosL;
104 
105   /*
106    * vertical moving of the characters
107    */
108   /* determine the width of scrolling text */
109   a = (offset_xx1 + 3) & SINUS_MASK;
110   offset_xx1 = a;
111   table = sinPT + a;
112   width = ((*table * 10 * res) >> SINUS_DECA) + 132 * res;
113   Sint32 depla = 1;
114   if (birth_flag)
115     {
116       depla *= 2;
117     }
118   sprite_font_menu **sprite_fonts = object_ptr;
119   for (Uint32 i = 0; i < MAX_OF_FONTS; i++)
120     {
121       if (NULL == *sprite_fonts)
122         {
123           sprite_fonts = &characters_list[MAX_OF_FONTS];
124         }
125       sprite = *(sprite_fonts--);
126       a = sprite->zeCosValue + depla;
127 
128       /* read a new character */
129       if (a >= 256)
130         {
131           char *sText = scroll_ptr;
132           Uint32 c = (Uint32) * sText;
133           /* end of text, restart it! */
134           if (0 == c)
135             {
136               sText = scrollText;
137               scroll_ptr = sText;
138               c = *sText;
139             }
140           scroll_ptr++;
141           c -= 32;
142           b = 127;
143           c = c & b;
144           b = asciiToBob[c];
145           sprite->set_image (b);
146           /* fisrt element of the list? */
147           if (NULL == *(object_ptr - 1))
148             {
149               object_ptr = &characters_list[MAX_OF_FONTS + 1];
150             }
151           object_ptr--;
152         }
153       /* radius only varies on 180 degree */
154       a = a & 255;
155       sprite->zeCosValue = a;
156       table = cosPT + a;
157       a = ((*table * width) >> SINUS_DECA) + 152 * res;
158       sprite->set_x_coord (a);
159     }
160 
161   /*
162    * vertical moving of the characters
163    */
164   /* and 0x1ff => value 0 to 511 */
165   a = (offset_yy1 + 2) & SINUS_MASK;
166   offset_yy1 = a;
167   depla = 4;
168   if (birth_flag)
169     {
170       depla *= 2;
171     }
172   sprite_fonts = object_ptr;
173   Sint32 zerad = 25 * res;
174   Sint32 zeoff = 200 * res;
175   for (Uint32 i = 0; i < MAX_OF_FONTS; i++)
176     {
177       if (*sprite_fonts == NULL)
178         {
179           sprite_fonts = &characters_list[MAX_OF_FONTS];
180         }
181       sprite = *(sprite_fonts--);
182       a = (a + depla) & SINUS_MASK;
183       table = sinPT + a;
184       b = ((*table * zerad) >> SINUS_DECA) + zeoff;
185       sprite->set_y_coord (b);
186     }
187 
188   /* move the left mask */
189   sprite = objectRigh;
190   table = cosPT;
191   a = ((*table * width) >> SINUS_DECA) + 152 * res;
192   sprite->set_x_coord (a);
193   zzBOB = *(++sprite_fonts);
194   a = zzBOB->get_y_coord ();
195   sprite->set_y_coord (a);
196 
197   /* move the right mask */
198   sprite = objectLeft;
199   table = cosPT + 255;
200   a = ((*table * width) >> SINUS_DECA) + 152 * res;
201   sprite->set_x_coord (a);
202   zzBOB = *object_ptr;
203   a = zzBOB->get_y_coord ();
204   sprite->set_y_coord (a);
205 }
206 
207 char controller_font_menu::asciiToBob[128] =
208 {
209   26,       // 32 ' ' space
210   37,                           // 33 '!'
211   39,                           // 34 '''
212   26,                           // 35 '#' (space)
213   26,                           // 36 '$' (space)
214   26,                           // 37 '%' (space)
215   26,                           // 38 '&' (space)
216   39,                           // 39 "'"
217   26,                           // 40 '(' (space)
218   26,                           // 41 ')' (space)
219   26,                           // 42 '*' (space)
220   26,                           // 43 '+' (space)
221   40,                           // 44 ','
222   41,                           // 45 '-'
223   38,                           // 46 '.'
224   26,                           // 47 '/' (space)
225   27,                           // 48 '0'
226   28,                           // 49 '1'
227   29,                           // 50 '2'
228   30,                           // 51 '3'
229   31,                           // 52 '4'
230   32,                           // 53 '5'
231   33,                           // 54 '6'
232   34,                           // 55 '7'
233   35,                           // 56 '8'
234   36,                           // 57 '9'
235   26,                           // 58 ':' (space)
236   26,                           // 59 ';' (space)
237   26,                           // 60 '<' (space)
238   26,                           // 61 '=' (space)
239   26,                           // 62 '>' (space)
240   26,                           // 63 '?' (space)
241   26,                           // 64 '@' (space)
242   00,                           // 65 'A'
243   01,                           // 66 'B'
244   02,                           // 67 'C'
245   03,                           // 68 'D'
246   04,                           // 69 'E'
247   05,                           // 70 'F'
248   06,                           // 71 'G'
249   7,                            // 72 'H'
250   8,                            // 73 'I'
251   9,                            // 74 'J'
252   10,                           // 75 'K'
253   11,                           // 76 'L'
254   12,                           // 77 'M'
255   13,                           // 78 'N'
256   14,                           // 79 'O'
257   15,                           // 80 'P'
258   16,                           // 81 'Q'
259   17,                           // 82 'R'
260   18,                           // 83 'S'
261   19,                           // 84 'T'
262   20,                           // 85 'U'
263   21,                           // 86 'V'
264   22,                           // 87 'W'
265   23,                           // 88 'X'
266   24,                           // 89 'Y'
267   25,                           // 90 'Z'
268   26,                           // 91 '[' (space)
269   26,                           // 92 '\' (space)
270   26,                           // 93 ']' (space)
271   26,                           // 94 '^' (space)
272   26,                           // 95 '_' (space)
273   26,                           // 96 '`' (space)
274   26,                           // 97 'a' (space)
275   26,                           // 98 'b' (space)
276   26,                           // 99 'c' (space)
277   26,                           // 100 'd' (space)
278   26,                           // 101 'e' (space)
279   26,                           // 102 'f' (space)
280   26,                           // 103 'g' (space)
281   26,                           // 104 'h' (space)
282   26,                           // 105 'i' (space)
283   26,                           // 106 'j' (space)
284   26,                           // 107 'k' (space)
285   26,                           // 108 'l' (space)
286   26,                           // 109 'm' (space)
287   26,                           // 110 'n' (space)
288   26,                           // 111 'o' (space)
289   26,                           // 112 'p' (space)
290   26,                           // 113 'q' (space)
291   26,                           // 114 'r' (space)
292   26,                           // 115 's' (space)
293   26,                           // 116 't' (space)
294   26,                           // 117 'u' (space)
295   26,                           // 118 'v' (space)
296   26,                           // 119 'w' (space)
297   26,                           // 120 'x' (space)
298   26,                           // 121 'y' (space)
299   26,                           // 122 'z' (space)
300   26,                           // 123 '{' (space)
301   26,                           // 124 '|' (space)
302   26,                           // 125 '}' (space)
303   26,                           // 126 '~' (space)
304   26                            // 127 ' ' (space)
305 };
306