Debian Codegraph @

Descent3/TelcomEffectsRender.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/TelcomEffectsRender.cpp $
21 * $Revision: 15 $
22 * $Date: 3/20/00 12:21p $
23 * $Author: Matt $
24 *
25 * <insert description of file here>
26 *
27 * $Log: /DescentIII/main/TelcomEffectsRender.cpp $
28 *
29 * 15 3/20/00 12:21p Matt
30 * Merge of Duane's post-1.3 changes.
31 * Minor optimization.
32 *
33 * 14 7/28/99 3:41p Kevin
34 * Macintosh!
35 *
36 * 13 5/17/99 1:46p Ardussi
37 * changed to compile on Mac
38 *
39 * 12 5/03/99 1:16p Jeff
40 * play sounds at full volume
41 *
42 * 11 4/20/99 12:46p Jeff
43 * telcom main menu, mouse over button sets focus. if you go into telcom
44 * main menu, when you leave a system it will return you to main menu.
45 *
46 * 10 4/14/99 3:57a Jeff
47 * fixed case mismatch in #includes
48 *
49 * $NoKeywords: $
50 */
51 #include "TelComEffects.h"
52 #include "textaux.h"
53 #include "mem.h"
54 #include "hlsoundlib.h"
55 #include <string.h>
56
57 #include <stdlib.h>
58
59 int glitch_dx = 0, glitch_dy = 0;
60 #define DISABLED_TEXT_COLOR GR_RGB(180, 180, 180);
61 int GetTextEffectWithTabStopsOnScreen(int screen) {
62 int count = 0;
63 ASSERT(screen >= 0 && screen < MAX_TELCOM_SCREENS);
64 int node = Screen_roots[screen];
65 while (node != -1) {
66 if (TCEffects[node].type == EFX_TEXT_STATIC || TCEffects[node].type == EFX_TEXT_FADE ||
67 TCEffects[node].type == EFX_TEXT_TYPE) {
68 if (TCEffects[node].tab_stop)
69 count++;
70 }
71 node = TCEffects[node].next;
72 }
73 return count;
74 }
75 void RenderTextStatic(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
76 if (!ok_to_render)
77 return;
78 ASSERT(tce->type == EFX_TEXT_STATIC);
79 ASSERT(tce->text_buffer);
80 // See if we have any events waiting
81 tTCEvent evt;
82 while (PopEvent(tce, &evt)) {
83 switch (evt.id) {
84 case TEVT_SCROLLDOWN:
85 if (tce->textinfo.scroll_d) {
86 // mprintf(0,"Down Baby Down!\n");
87 tce->textinfo.line_index++;
88 }
89 break;
90 case TEVT_SCROLLUP:
91 if (tce->textinfo.line_index > 0) {
92 // mprintf(0,"Up Baby Up!\n");
93 tce->textinfo.line_index--;
94 }
95 break;
96 case TEVT_GAINFOCUS: {
97 // mprintf(0,"Text %d Gain Focus\n",tce-TCEffects);
98 } break;
99 case TEVT_LOSTFOCUS: {
100 // mprintf(0,"Text %d Lost Focus\n",tce-TCEffects);
101 } break;
102 }
103 }
104 ddgr_color color_to_use = tce->color;
105 int tab_count = GetTextEffectWithTabStopsOnScreen(tce->screen);
106 if (tab_count > 1) {
107 // we need to see what color to use for the text, cause there is more than
108 // one text item with a tab stop.
109 if (!tce->has_focus) {
110 // use the disable text color
111 color_to_use = DISABLED_TEXT_COLOR;
112 }
113 }
114 uint8_t old_alpha = grtext_GetAlpha();
115 grtext_SetFont(Game_fonts[tce->textinfo.font_index]);
116 grtext_SetColor(color_to_use);
117 grtext_SetAlpha(tce->alpha);
118 int curry = tce->pos_y + yoff;
119 int height = grfont_GetHeight(Game_fonts[tce->textinfo.font_index]) + 1;
120 char buff[256];
121 const char *nextline;
122 int count = 0; // get to the first line of text (scrolling)
123 nextline = textaux_CopyTextLine(tce->text_buffer, buff);
124 if ((tce->textinfo.line_index) && (nextline)) {
125 count++;
126 while (count <= tce->textinfo.line_index) {
127 nextline = textaux_CopyTextLine(nextline, buff);
128 count++;
129 }
130 }
131 int lcount = 0;
132 while ((nextline) && ((curry + height) < tce->pos_y + tce->h)) {
133 grtext_Printf(tce->pos_x + glitch_dx + xoff, curry + glitch_dy, buff);
134 lcount++;
135 curry += height;
136 nextline = textaux_CopyTextLine(nextline, buff);
137 }
138 grtext_Printf(tce->pos_x + glitch_dx + xoff, curry + glitch_dy, buff);
139 lcount++;
140 grtext_SetAlpha(old_alpha);
141
142 if ((lcount * height) > tce->h) {
143 // we can scroll down
144 tce->textinfo.scroll_d = true;
145 } else {
146 // we can't scroll down
147 tce->textinfo.scroll_d = false;
148 }
149 tce->age += frametime;
150 }
151 void RenderTextType(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
152 if (!ok_to_render)
153 return;
154 ASSERT(tce->type == EFX_TEXT_TYPE);
155 ASSERT(tce->text_buffer);
156 // See if we have any events waiting
157 tTCEvent evt;
158 while (PopEvent(tce, &evt)) {
159 switch (evt.id) {
160 case TEVT_SCROLLDOWN:
161 if (tce->textinfo.scroll_d) {
162 // mprintf(0,"Down Baby Down!\n");
163 tce->textinfo.line_index++;
164 }
165 break;
166 case TEVT_SCROLLUP:
167 if (tce->textinfo.line_index > 0) {
168 // mprintf(0,"Up Baby Up!\n");
169 tce->textinfo.line_index--;
170 }
171 break;
172 case TEVT_GAINFOCUS: {
173 // mprintf(0,"Text %d Gain Focus\n",tce-TCEffects);
174 } break;
175 case TEVT_LOSTFOCUS: {
176 // mprintf(0,"Text %d Lost Focus\n",tce-TCEffects);
177 } break;
178 }
179 }
180 if ((!tce->text_buffer) || (tce->text_buffer[0] == '\0'))
181 return;
182 float flash_step;
183 ddgr_color hi_color = tce->color; //@JEFF: GR_RGB(255,255,255);
184 int strlength = strlen(tce->text_buffer);
185 if (tce->textinfo.last_letter >= strlength - 1) {
186 TelcomStopSound(TCSND_TYPING);
187 }
188 flash_step = frametime * (((float)strlength) / tce->speed);
189 char *temp;
190 if (tce->textinfo.last_letter < strlength - 1) {
191 TelcomStartSound(TCSND_TYPING);
192 }
193 tce->textinfo.last_letter += flash_step;
194 if (tce->textinfo.last_letter > strlength)
195 tce->textinfo.last_letter = strlength;
196 int ll = (int)tce->textinfo.last_letter;
197 temp = (char *)mem_malloc(strlength + 10);
198 if (!temp) {
199 tce->age += frametime;
200 return;
201 }
202 strcpy(temp, tce->text_buffer);
203 temp[ll] = '\0';
204
205 uint8_t old_alpha = grtext_GetAlpha();
206 grtext_SetFont(Game_fonts[tce->textinfo.font_index]);
207 char buff[1024];
208 const char *nextline;
209 int height = grfont_GetHeight(Game_fonts[tce->textinfo.font_index]) + 1;
210 int curry = tce->pos_y;
211 ddgr_color color_to_use = hi_color;
212 int tab_count = GetTextEffectWithTabStopsOnScreen(tce->screen);
213 if (tab_count > 1) {
214 // we need to see what color to use for the text, cause there is more than
215 // one text item with a tab stop.
216 if (!tce->has_focus) {
217 // use the disable text color
218 color_to_use = DISABLED_TEXT_COLOR;
219 }
220 }
221 grtext_SetColor(color_to_use);
222 grtext_SetAlpha(255.0);
223
224 int count = 0; // get to the first line of text (scrolling)
225 nextline = textaux_CopyTextLine(temp, buff);
226 if ((tce->textinfo.line_index) && (nextline)) {
227 count++;
228 while (count <= tce->textinfo.line_index) {
229 nextline = textaux_CopyTextLine(nextline, buff);
230 count++;
231 }
232 }
233 int lcount = 0;
234 while ((nextline) && ((curry + height) <= tce->pos_y + tce->h)) {
235 grtext_Printf(tce->pos_x + xoff + glitch_dx, curry + yoff + glitch_dy, buff);
236 lcount++;
237 curry += height;
238 nextline = textaux_CopyTextLine(nextline, buff);
239 }
240 grtext_Printf(tce->pos_x + xoff + glitch_dx, curry + yoff + glitch_dy, buff);
241 lcount++;
242 if ((lcount * height) > tce->h) {
243 // we can scroll down
244 tce->textinfo.scroll_d = true;
245 } else {
246 // we can't scroll down
247 tce->textinfo.scroll_d = false;
248 }
249 /*
250 if( ll>2 ){
251 grtext_SetColor(tce->color); //!<<_---------USE CORRECT COLOR HERE WHEN IMPLEMENTED
252 if(ll<strlength-1){
253 temp[ll-2]='\0';
254 }else{
255 //strcpy(temp,tce->text_buffer);
256 temp[11]='\0';
257 }
258 curry = tce->pos_y;
259 count = 0; //get to the first line of text (scrolling)
260 nextline = textaux_CopyTextLine(temp,buff);
261 if((tce->textinfo.line_index)&&(nextline)){
262 count++;
263 while(count<=tce->textinfo.line_index){
264 nextline = textaux_CopyTextLine(nextline,buff);
265 count++;
266 }
267 }
268 while((nextline)&&((curry+height)<=tce->pos_y+tce->h) ){
269 grtext_Printf(tce->pos_x+xoff+glitch_dx,curry+yoff+glitch_dy,buff);
270 curry += height;
271 nextline = textaux_CopyTextLine(nextline,buff);
272 }
273 grtext_Printf(tce->pos_x+xoff+glitch_dx,curry+yoff+glitch_dy,buff);
274 }
275 //draw scroll buttons now (if needed)
276 //if m_iIndex!=0 then we can scroll up
277 if(tce->textinfo.line_index){
278 tce->textinfo.scroll_u = true;
279 }else
280 tce->textinfo.scroll_u = false;
281 //if curry+height>m_iBottomY then we can scroll down
282 if( (curry+height)>tce->pos_y+tce->h){
283 tce->textinfo.scroll_d = true;
284 }
285 else
286 tce->textinfo.scroll_d = false;
287 */
288 grtext_SetAlpha(old_alpha);
289 mem_free(temp);
290 tce->age += frametime;
291 }
292 void RenderTextFade(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
293 if (!ok_to_render)
294 return;
295 ASSERT(tce->type == EFX_TEXT_FADE);
296 ASSERT(tce->text_buffer);
297 // See if we have any events waiting
298 tTCEvent evt;
299 while (PopEvent(tce, &evt)) {
300 switch (evt.id) {
301 case TEVT_SCROLLDOWN:
302 if (tce->textinfo.scroll_d) {
303 // mprintf(0,"Down Baby Down!\n");
304 tce->textinfo.line_index++;
305 }
306 break;
307 case TEVT_SCROLLUP:
308 if (tce->textinfo.line_index > 0) {
309 // mprintf(0,"Up Baby Up!\n");
310 tce->textinfo.line_index--;
311 }
312 break;
313 case TEVT_GAINFOCUS: {
314 // mprintf(0,"Text %d Gain Focus\n",tce-TCEffects);
315 } break;
316 case TEVT_LOSTFOCUS: {
317 // mprintf(0,"Text %d Lost Focus\n",tce-TCEffects);
318 } break;
319 }
320 }
321
322 if (tce->speed == 0)
323 tce->speed = 0.0001f;
324 float amount = tce->age * (255.0 / tce->speed);
325 uint8_t alpha;
326 if (tce->flags == TC_TEXTF_IN) {
327 // fade in, but not fade out
328 tce->alpha += amount;
329 if (tce->alpha > 255.0f) {
330 tce->alpha = 255.0f;
331 }
332 alpha = tce->alpha;
333 } else if (tce->flags == TC_TEXTF_OUT) {
334 // fade out, but not fade in
335 tce->alpha -= amount;
336 if (tce->alpha < 0.0f) {
337 tce->alpha = 0.0f;
338 }
339 alpha = tce->alpha;
340 } else {
341 // fade in, then fade out (if alpha is negative, then we are fading out)
342 if (tce->alpha < 0.0f) {
343 tce->alpha += amount;
344 alpha = (-tce->alpha);
345 if (tce->alpha > 0.0f) {
346 // we're done fading out
347 tce->alpha = 1234.0f;
348 alpha = 0;
349 }
350 } else if (tce->alpha != 1234.0f) {
351 tce->alpha += amount;
352 alpha = tce->alpha;
353 if (tce->alpha > 255.0f) {
354 // switch to fading out
355 alpha = 255;
356 tce->alpha = -255.0f;
357 }
358 } else
359 alpha = 0;
360 }
361 ddgr_color color_to_use = tce->color;
362 int tab_count = GetTextEffectWithTabStopsOnScreen(tce->screen);
363 if (tab_count > 1) {
364 // we need to see what color to use for the text, cause there is more than
365 // one text item with a tab stop.
366 if (!tce->has_focus) {
367 // use the disable text color
368 color_to_use = DISABLED_TEXT_COLOR;
369 }
370 }
371 uint8_t old_alpha = grtext_GetAlpha();
372 grtext_SetFont(Game_fonts[tce->textinfo.font_index]);
373 grtext_SetColor(color_to_use);
374 grtext_SetAlpha(alpha);
375 int curry = tce->pos_y;
376 int height = grfont_GetHeight(Game_fonts[tce->textinfo.font_index]) + 1;
377 char buff[256];
378 const char *nextline;
379 int count = 0; // get to the first line of text (scrolling)
380 nextline = textaux_CopyTextLine(tce->text_buffer, buff);
381 if ((tce->textinfo.line_index) && (nextline)) {
382 count++;
383 while (count <= tce->textinfo.line_index) {
384 nextline = textaux_CopyTextLine(nextline, buff);
385 count++;
386 }
387 }
388 int lcount = 0;
389 while ((nextline) && ((curry + height) < tce->pos_y + tce->h)) {
390 grtext_Printf(tce->pos_x + glitch_dx + xoff, curry + glitch_dy + yoff, buff);
391 lcount++;
392 curry += height;
393 nextline = textaux_CopyTextLine(nextline, buff);
394 }
395 grtext_Printf(tce->pos_x + glitch_dx + xoff, curry + glitch_dy + yoff, buff);
396 lcount++;
397 grtext_SetAlpha(old_alpha);
398 if ((lcount * height) > tce->h) {
399 // we can scroll down
400 tce->textinfo.scroll_d = true;
401 } else {
402 // we can't scroll down
403 tce->textinfo.scroll_d = false;
404 }
405 tce->age += frametime;
406 }
407 void RenderBmpStatic(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
408 if (!ok_to_render)
409 return;
410 ASSERT(tce->type == EFX_BMP_STATIC);
411 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
412 tce->age += frametime;
413 }
414 void BlurBitmapArea(uint16_t *srcbm, uint16_t *dstbm, int16_t width, int16_t height, int16_t startx, int16_t starty, int16_t bmw) {
415 int pixel_count, blue_total, red_total, green_total;
416 pixel_count = width * height;
417 blue_total = red_total = green_total = 0;
418 int16_t x, y;
419 int16_t pos;
420 if (!pixel_count)
421 return;
422
423 for (y = starty; y < height + starty; y++)
424 for (x = startx; x < width + startx; x++) {
425 pos = y * bmw + x;
426 if (srcbm[pos] & OPAQUE_FLAG) {
427 blue_total += GR_COLOR_BLUE(GR_16_TO_COLOR(srcbm[pos]));
428 red_total += GR_COLOR_RED(GR_16_TO_COLOR(srcbm[pos]));
429 green_total += GR_COLOR_GREEN(GR_16_TO_COLOR(srcbm[pos]));
430 }
431 }
432 uint16_t col;
433 if (red_total + green_total + blue_total)
434 col = OPAQUE_FLAG | GR_RGB16(red_total / pixel_count, green_total / pixel_count, blue_total / pixel_count);
435 else
436 col = 0;
437 for (x = startx; x < width + startx; x++)
438 for (y = starty; y < height + starty; y++) {
439 dstbm[y * bmw + x] = col;
440 }
441 }
442 void RenderBmpBlur(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
443 ASSERT(tce->type == EFX_BMP_BLUR);
444 if (!ok_to_render) {
445 if (tce->flags == TC_BMPF_OUT && (!(tce->flags & TC_NOEARLYRENDER))) {
446 UploadChunk(&tce->bmpinfo.chunk_bmp);
447 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
448 }
449 return;
450 }
451
452 if ((tce->flags == TC_BMPF_OUT) && (tce->bmpinfo.stage <= 0))
453 return;
454 int sbm_handle = tce->bmpinfo.bm_handle;
455 int dbm_handle = tce->bmpinfo.temp_bmhandle;
456 bm_ClearBitmap(dbm_handle);
457 int x = 0;
458 int y = 0;
459 bool done = false;
460 if ((tce->flags == TC_BMPF_OUT) && (tce->bmpinfo.stage < 0))
461 done = true;
462 if ((tce->flags == TC_BMPF_IN) && (tce->bmpinfo.stage > BLUR_STAGES))
463 done = true;
464
465 uint16_t *src, *dest;
466 int rowsize, w, h;
467
468 if (!done) {
469 src = bm_data(sbm_handle, 0);
470 dest = bm_data(dbm_handle, 0);
471 rowsize = bm_w(sbm_handle, 0);
472 w = bm_w(sbm_handle, 0);
473 h = bm_h(sbm_handle, 0);
474 int current_stage;
475 int block_size;
476 current_stage = tce->bmpinfo.stage;
477 block_size = 1 << (BLUR_STAGES - current_stage);
478 int x = 0, y = 0, bs_w, bs_h;
479
480 for (x = 0; x < w; x += block_size)
481 for (y = 0; y < h; y += block_size) {
482 if (x + block_size > w)
483 bs_w = w - x;
484 else
485 bs_w = block_size;
486 if (y + block_size > h)
487 bs_h = h - y;
488 else
489 bs_h = block_size;
490 BlurBitmapArea(src, dest, bs_w, bs_h, x, y, w);
491 }
492 int dim = bm_w(tce->bmpinfo.chunk_bmp.bm_array[0], 0);
493 int how_many_across = tce->bmpinfo.chunk_bmp.w;
494 int bh = tce->bmpinfo.chunk_bmp.ph;
495 int bw = tce->bmpinfo.chunk_bmp.pw;
496 uint16_t *src_data = bm_data(dbm_handle, 0);
497 for (y = 0; y < bh; y++) {
498 for (x = 0; x < bw; x++) {
499 int piece_y = y / dim;
500 int piece_x = x / dim;
501 int sub_x = x % dim;
502 int sub_y = y % dim;
503 int bm = tce->bmpinfo.chunk_bmp.bm_array[piece_y * how_many_across + piece_x];
504 uint16_t *dest_data = bm_data(bm, 0);
505 uint16_t pix = src_data[y * bw + x];
506 dest_data[sub_y * dim + sub_x] = pix;
507 }
508 }
509 UploadChunk(&tce->bmpinfo.chunk_bmp);
510 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
511
512 float amt = tce->speed * frametime;
513 if (tce->flags == TC_BMPF_IN)
514 tce->bmpinfo.stage += amt;
515 else
516 tce->bmpinfo.stage -= amt;
517 } else {
518 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
519 }
520 tce->age += frametime;
521 }
522 #define N_FADE_STAGES 4
523 void RenderBmpScanline(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
524 ASSERT(tce->type == EFX_BMP_SCANLINE);
525 if (!ok_to_render) {
526 if (tce->flags == TC_BMPF_OUT && (!(tce->flags & TC_NOEARLYRENDER))) {
527 UploadChunk(&tce->bmpinfo.chunk_bmp);
528 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
529 }
530 return;
531 }
532
533 bool changed = true;
534 bool done;
535 int x, y;
536 int sbm_handle = tce->bmpinfo.bm_handle;
537 int dbm_handle = tce->bmpinfo.temp_bmhandle;
538 uint16_t *src, *dest;
539 int rowsize, w, h, xx, yy, stage;
540 float k;
541 if (dbm_handle == BAD_BITMAP_HANDLE)
542 goto done_scanline;
543 bm_ClearBitmap(dbm_handle);
544
545 x = 0;
546 y = 0;
547 done = false;
548
549 k = tce->age / tce->speed;
550
551 if (k > 1.2)
552 goto done_scanline;
553 if (k > 1.0) {
554 k = 1.0;
555 done = 1;
556 }
557 if (tce->flags == TC_BMPF_OUT) {
558 k = 1.0 - k;
559 }
560 src = bm_data(sbm_handle, 0);
561 dest = bm_data(dbm_handle, 0);
562 rowsize = bm_w(sbm_handle, 0);
563 w = bm_w(sbm_handle, 0);
564 h = bm_h(sbm_handle, 0);
565 for (yy = stage = 0; yy < h; yy++) {
566 int span_width;
567 span_width = w * ((k - ((float)stage / N_FADE_STAGES)) * N_FADE_STAGES);
568 if (span_width < 0)
569 span_width = 0;
570 if (span_width > w)
571 span_width = w;
572 for (xx = 0; xx < span_width; xx++)
573 if (dest && src)
574 *dest++ = *src++;
575
576 dest += (rowsize - xx);
577 src += (w - span_width);
578 switch (stage) {
579 case 0:
580 stage = 2;
581 break;
582 case 1:
583 stage = 3;
584 break;
585 case 2:
586 stage = 1;
587 break;
588 case 3:
589 stage = 0;
590 break;
591 }
592 }
593 // we now chunk the bitmap (this is slow, the above should be done right to the chunk)
594 if (changed) {
595 int dim = bm_w(tce->bmpinfo.chunk_bmp.bm_array[0], 0);
596 int how_many_across = tce->bmpinfo.chunk_bmp.w;
597 int bh = tce->bmpinfo.chunk_bmp.ph;
598 int bw = tce->bmpinfo.chunk_bmp.pw;
599 uint16_t *src_data = bm_data(dbm_handle, 0);
600 int x, y;
601 for (y = 0; y < bh; y++) {
602 for (x = 0; x < bw; x++) {
603 int piece_y = y / dim;
604 int piece_x = x / dim;
605 int sub_x = x % dim;
606 int sub_y = y % dim;
607 int bm = tce->bmpinfo.chunk_bmp.bm_array[piece_y * how_many_across + piece_x];
608 uint16_t *dest_data = bm_data(bm, 0);
609 uint16_t pix = src_data[y * bw + x];
610 dest_data[sub_y * dim + sub_x] = pix;
611 }
612 }
613 UploadChunk(&tce->bmpinfo.chunk_bmp);
614 }
615 done_scanline:
616 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
617 tce->age += frametime;
618 }
619 void RenderBmpInvert(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
620 ASSERT(tce->type == EFX_BMP_INVERT);
621 int srcbmph = tce->bmpinfo.bm_handle;
622 bool changed = true;
623 if (!ok_to_render && tce->flags & TC_NOEARLYRENDER)
624 return;
625 float k;
626
627 if (ok_to_render) {
628 k = tce->age / tce->speed;
629 } else {
630 k = 0;
631 }
632 int inv;
633 if (k > 1.0) {
634 k = 1.0;
635 changed = false;
636 } else if (k < 0) {
637 mprintf(0, "k<0 on inverse bitmap...bashing (%.2f/%.2f)\n", tce->age, tce->speed);
638 if (tce->age < 0)
639 Int3();
640 if (tce->speed < 0)
641 tce->speed = 0.1f;
642 k = 0;
643 changed = false;
644 }
645 if (tce->flags == TC_BMPF_OUT)
646 k = 1 - k;
647 inv = 255 - (255.0f * k);
648 uint8_t r, g, b;
649 int bh = bm_h(srcbmph, 0);
650 int bw = bm_w(srcbmph, 0);
651 int how_many = tce->bmpinfo.chunk_bmp.w * tce->bmpinfo.chunk_bmp.h;
652 int how_many_across = tce->bmpinfo.chunk_bmp.w;
653 int dim = bm_h(tce->bmpinfo.chunk_bmp.bm_array[0], 0);
654 int shift; // speed up (since dim is always a power of 2)
655 switch (dim) {
656 case 32:
657 shift = 5;
658 break;
659 case 64:
660 shift = 6;
661 break;
662 case 128:
663 shift = 7;
664 break;
665 }
666 uint16_t *src_data = bm_data(srcbmph, 0);
667 uint16_t *sdata;
668 uint16_t *ddata;
669 uint16_t pix;
670 int maxx, maxy;
671 int windex, hindex;
672 int s_y, s_x, d_y, d_x;
673 // is there any need to do this if !changed!?!?
674 for (hindex = 0; hindex < tce->bmpinfo.chunk_bmp.h; hindex++) {
675 for (windex = 0; windex < tce->bmpinfo.chunk_bmp.w; windex++) {
676 // loop through the chunks
677 // find end x and y
678 if (windex < tce->bmpinfo.chunk_bmp.w - 1)
679 maxx = dim;
680 else
681 maxx = bw - (windex << shift);
682 if (hindex < tce->bmpinfo.chunk_bmp.h - 1)
683 maxy = dim;
684 else
685 maxy = bh - (hindex << shift);
686 // find the starting source x and y
687 s_x = (windex << shift);
688 s_y = (hindex << shift);
689 // get the pointers pointing to the right spot
690 ddata = bm_data(tce->bmpinfo.chunk_bmp.bm_array[hindex * how_many_across + windex], 0);
691 sdata = &src_data[s_y * bw + s_x];
692 // copy the data
693 for (d_y = 0; d_y < maxy; d_y++) {
694 for (d_x = 0; d_x < maxx; d_x++) {
695 pix = sdata[d_x];
696 if (pix) {
697 r = GR_COLOR_RED(GR_16_TO_COLOR(pix));
698 g = GR_COLOR_GREEN(GR_16_TO_COLOR(pix));
699 b = GR_COLOR_BLUE(GR_16_TO_COLOR(pix));
700 ddata[d_x] = OPAQUE_FLAG | GR_RGB16(abs(r - inv), abs(g - inv), abs(b - inv));
701 } else {
702 ddata[d_x] = 0;
703 }
704 } // end for d_x
705 sdata += bw;
706 ddata += dim;
707 } // end for d_y
708 } // end for windex
709 } // end for hindex
710
711 if (changed)
712 UploadChunk(&tce->bmpinfo.chunk_bmp);
713 BltBmpToScreen(tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff, &tce->bmpinfo.chunk_bmp);
714 if (ok_to_render)
715 tce->age += frametime;
716 }
717 void RenderBmpStretch(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
718 ASSERT(tce->type == EFX_BMP_STRETCH);
719 if (!ok_to_render) {
720 return;
721 }
722
723 float k = (tce->age) / tce->speed;
724 if (k > 1.0) {
725 k = 1.0;
726 } else if (k < 0) {
727 k = 0;
728 }
729 if (tce->flags == TC_BMPF_OUT)
730 k = 1 - k;
731 int w, h;
732 // width
733 // h = 64;
734 // w = k*64.0;
735 // height
736 // w = 64;
737 // h = k*64.0;
738 // width & height
739 h = w = (k * 64.0);
740 int src_w = bm_w(tce->bmpinfo.bm_handle, 0);
741 int src_h = bm_h(tce->bmpinfo.bm_handle, 0);
742 int realx, realy;
743 int w_count = (src_w + 63) / 64;
744 int h_count = (src_h + 63) / 64;
745 float tw = ((float)k * src_w) / ((float)w_count);
746 float th = ((float)k * src_h) / ((float)h_count);
747 int startx = tce->pos_x + (src_w / 2) - (((float)w_count) * tw / 2.0f);
748 int starty = tce->pos_y + (src_h / 2) - (((float)h_count) * th / 2.0f);
749 rend_SetAlphaType(AT_CONSTANT_TEXTURE);
750 rend_SetAlphaValue(255.0);
751 rend_SetLighting(LS_NONE);
752 rend_SetColorModel(CM_MONO);
753 rend_SetOverlayType(OT_NONE);
754 rend_SetWrapType(WT_CLAMP);
755 rend_SetFiltering(0);
756 int dx, dy;
757 int index;
758 index = 0;
759 for (dy = 0, realy = starty; dy < h_count; dy++, realy += h)
760 for (dx = 0, realx = startx; dx < w_count; dx++, realx += w) {
761 rend_DrawScaledBitmap(realx + xoff + glitch_dx, realy + yoff + glitch_dy, realx + w + xoff + glitch_dx,
762 realy + h + yoff + glitch_dy, tce->bmpinfo.bitmaps[index], 0, 0, 1, 1);
763 index++;
764 }
765 rend_SetFiltering(1);
766 tce->age += frametime;
767 }
768 void RenderBackground(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
769 if (!ok_to_render)
770 return;
771 ASSERT(tce->type == EFX_BACKGROUND);
772 int lx, rx, ty, by;
773 lx = tce->pos_x + xoff;
774 rx = tce->pos_x + xoff + tce->w;
775 ty = tce->pos_y + yoff;
776 by = tce->pos_y + yoff + tce->h;
777 rend_FillRect(tce->color, lx, ty, rx, by);
778 tce->age += frametime;
779 }
780 void RenderMovie(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
781 if (!ok_to_render)
782 return;
783 ASSERT(tce->type == EFX_MOVIE);
784
785 if (!tce->movieinfo.handle)
786 return;
787 bool done = false;
788 FrameMovie(tce->movieinfo.handle, tce->pos_x + glitch_dx, tce->pos_y + glitch_dy, false);
789 float end_time = tce->age + frametime;
790 while ((end_time > tce->age) && (!done)) {
791 if (!FrameMovie(tce->movieinfo.handle, tce->pos_x + glitch_dx + xoff, tce->pos_y + glitch_dy + yoff)) {
792 /*
793 if(IsLooping()) //looping?
794 {
795 EndMovie(m_MovieHandle);
796 m_MovieHandle = StartMovie(m_szMovieName);
797 }
798 else
799 {
800 EndMovie(m_MovieHandle);
801 m_MovieHandle = NULL;
802 done = true;
803 }*/
804 EndMovie(tce->movieinfo.handle);
805 tce->movieinfo.handle = NULL;
806 done = true;
807 } else
808 tce->age += 1.0f / tce->movieinfo.fps;
809 }
810 }
811 void RenderPolyModel(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
812 /*
813 if(!ok_to_render)
814 return;
815 ASSERT(tce->type==EFX_POLYMODEL);
816 if(tce->polyinfo.handle==-1)
817 return false;
818 float k = tce->age;
819 //setup how much we're gonna rotate
820 float xrot = k*tce->polyinfo.m_Rot.x + tce->polyinfo.m_Ori.x;
821 float yrot = k*tce->polyinfo.m_Rot.y + tce->polyinfo.m_Ori.y;
822 float zrot = k*tce->polyinfo.m_Rot.z + tce->polyinfo.m_Ori.z;
823 //fade in speed 2.0f
824 k*=(1.0f/2.0f);
825 if (k > 1.3) {
826 k = 1.3f;
827 }
828 else
829 if (k < 0){
830 k = 0.0f;
831 }
832 poly_model *pm=GetPolymodelPointer(tce->polyinfo.handle);
833 vector view_vec;
834 matrix view_orient;
835 float light_scalar;
836 //set all animation to default position
837 float norm_angles[MAX_SUBOBJECTS];
838 for (int i=0;i<MAX_SUBOBJECTS;i++){
839 norm_angles[i]=0;
840 }
841 //viewer at origin
842 vm_MakeIdentity(&view_orient);
843 vector pos;
844 pos.x = - (tce->polyinfo.m_Pos.x + (((float)glitch_dx)/tce->polyinfo.m_Pos.z));
845 pos.y = - (tce->polyinfo.m_Pos.y + (((float)glitch_dy)/tce->polyinfo.m_Pos.z));
846 pos.z = - tce->polyinfo.m_Pos.z;
847
848 g3_StartFrame (&pos,&view_orient,D3_DEFAULT_ZOOM);
849 //shed some light on the subject
850 light_scalar = 0.86f;
851 //we need to rotate our model about Y 180 degrees so it faces the camera
852 vm_AnglesToMatrix(&view_orient,xrot,yrot,zrot);
853 tce->polyinfo.m_mOrient += view_orient;
854 vm_Orthogonalize(&tce->polyinfo.m_mOrient);
855
856 //draw the polymodel with our little fade in effect
857 polymodel_effect pe={0};
858 pe.type=PEF_ALPHA;
859 if(k>=0.3)
860 pe.alpha=k-0.3f;
861 else
862 pe.alpha=0.005f;
863 SetPolymodelEffect(&pe);
864 vm_MakeZero (&view_vec);
865 rend_SetZBufferState(1);
866 DrawPolygonModel(&view_vec,&tce->polyinfo.m_mOrient,tce->polyinfo.handle,norm_angles,0,light_scalar,light_scalar,light_scalar,0xFFFFFFFF,1);
867 //DrawPolygonModel(&m_Pos,&m_mOrient,m_iHandle,norm_angles,0,light_scalar,0xFFFFFFFF,1);
868 if(k<1)
869 DrawModelOutline(GR_RGB(255,255,255),1.0-k);
870 g3_EndFrame();
871 rend_SetZBufferState(0);
872 */
873 tce->age += frametime;
874 }
875 void RenderSound(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
876 if (!ok_to_render)
877 return;
878 ASSERT(tce->type == EFX_SOUND);
879 tce->age += frametime;
880 if (tce->soundinfo.started)
881 return;
882 tce->soundinfo.started = true;
883 if (tce->soundinfo.handle != -1)
884 Sound_system.Play2dSound(tce->soundinfo.handle, MAX_GAME_VOLUME);
885 }
886 #define FLASH_SWITCH 1.0f
887 extern tceffect TCEffects[MAX_TCEFFECTS];
888 void RenderButton(tceffect *tce, float frametime, int xoff, int yoff, bool ok_to_render) {
889 if (!ok_to_render)
890 return;
891 ASSERT(tce->type == EFX_BUTTON);
892 tTCEvent evt;
893 bool time_to_flash = false;
894 bool glow = false;
895 while (PopEvent(tce, &evt)) {
896 switch (evt.id) {
897 case TEVT_GAINFOCUS: {
898 int num = tce - TCEffects;
899 // mprintf(0,"Button: Recv'd GAIN FOCUS Event (%d)\n",num);
900 } break;
901 case TEVT_LOSTFOCUS: {
902 int num = tce - TCEffects;
903 // mprintf(0,"Button: Recv'd LOST FOCUS Event (%d)\n",num);
904 } break;
905 case TEVT_MOUSEOVER: {
906 if (tce->flags & OBF_GLOW) {
907 if (tce->flags & OBF_MOUSEOVERFOCUS) {
908 // for effects with this flag set, only glow if we have focus
909 if (tce->tab_stop && tce->has_focus) {
910 time_to_flash = true;
911 glow = true;
912 }
913 } else {
914 time_to_flash = true;
915 glow = true;
916 }
917 }
918 } break;
919 case TEVT_MOUSEENTER: {
920 if (tce->flags & OBF_MOUSEOVERFOCUS) {
921 // check to see if we have focus, if not, and we are a tab, set focus
922 if (tce->tab_stop && !tce->has_focus) {
923 // set the focus on us!
924 TelComSetFocusOnEffect(tce - TCEffects);
925 }
926 }
927 } break;
928 case TEVT_MOUSECLICK:
929 case TEVT_MOUSEDOWN:
930 case TEVT_MOUSEUP: {
931 // send out the event to the appropriate system/effect
932 switch (tce->buttoninfo.button_type) {
933 case BUTT_UPARROW: {
934 // mprintf(0,"Button: Telling Text to Scroll Up\n");
935 int efxnum = GetEfxNumFromID(tce->buttoninfo.parent, tce->screen);
936 if (efxnum != -1) {
937 SendEventToEffect(efxnum, TEVT_SCROLLUP);
938 }
939 } break;
940 case BUTT_DOWNARROW: {
941 // mprintf(0,"Button: Telling Text to Scroll Down\n");
942 int efxnum = GetEfxNumFromID(tce->buttoninfo.parent, tce->screen);
943 if (efxnum != -1) {
944 SendEventToEffect(efxnum, TEVT_SCROLLDOWN);
945 }
946 } break;
947 case BUTT_NEXTPAGE:
948 // mprintf(0,"Button: Telling TelCom to go to Next Page\n");
949 TelComSendEvent(TEVT_TCNEXT);
950 break;
951 case BUTT_PREVPAGE:
952 // mprintf(0,"Button: Telling TelCom to go to Prev Page\n");
953 TelComSendEvent(TEVT_TCPREV);
954 break;
955 case BUTT_QUIT:
956 // mprintf(0,"Button: Telling TelCom to go to Quit\n");
957 TelComSendEvent(TEVT_TCQUIT);
958 break;
959 case BUTT_JUMP:
960 // mprintf(0,"Button: Telling TelCom to jump to %d\n",tce->buttoninfo.jump_page);
961 TelComSendEvent(TEVT_TCJUMP, tce->buttoninfo.jump_page);
962 break;
963 case BUTT_INTERNAL:
964 // mprintf(0,"Button: Calling internal callback\n");
965 if (tce->buttoninfo.internal)
966 tce->buttoninfo.internal((int)(tce - TCEffects));
967 break;
968 default:
969 mprintf(0, "Button: Invalid Button Type\n");
970 Int3(); // invalid button type
971 // missing JUMP!!!!!!!!!!!!!!!!
972 };
973 } break;
974 default: {
975 mprintf(0, "Button: Recv'd Evt %d\n", evt.id);
976 } break;
977 };
978 }
979 tce->age += frametime;
980 if (tce->age > FLASH_SWITCH) {
981 tce->buttoninfo.flash_state = !tce->buttoninfo.flash_state;
982 tce->age = 0;
983 }
984 if (tce->buttoninfo.flash_state && tce->flags & OBF_FLASH) {
985 time_to_flash = true;
986 }
987 if (tce->buttoninfo.flash_time > 0)
988 tce->buttoninfo.flash_time -= frametime;
989 if (tce->buttoninfo.flash_time > 0 && !glow)
990 time_to_flash = false;
991 if (tce->buttoninfo.flash_state &&
992 (tce->buttoninfo.button_type == BUTT_UPARROW || tce->buttoninfo.button_type == BUTT_DOWNARROW)) {
993 // this is an up/down arrow check to see if we can scroll in the appropriate direction
994 if (tce->buttoninfo.parent > -1) {
995 int pid = GetEfxNumFromID(tce->buttoninfo.parent, tce->screen);
996 ASSERT(pid != -1);
997 if (pid != -1) {
998 tceffect *t = &TCEffects[pid];
999 ASSERT(t->type == EFX_TEXT_STATIC || t->type == EFX_TEXT_TYPE || t->type == EFX_TEXT_FADE);
1000 switch (tce->buttoninfo.button_type) {
1001 case BUTT_UPARROW: {
1002 if (t->textinfo.line_index > 0) {
1003 time_to_flash = true;
1004 }
1005 } break;
1006 case BUTT_DOWNARROW: {
1007 if (t->textinfo.scroll_d) {
1008 time_to_flash = true;
1009 }
1010 } break;
1011 }
1012 }
1013 }
1014 }
1015 if (tce->buttoninfo.flash_handle == -1 && time_to_flash)
1016 time_to_flash = false;
1017 if (tce->has_focus) {
1018 BltBmpToScreen(tce->pos_x + glitch_dx, tce->pos_y + glitch_dy,
1019 (time_to_flash) ? &tce->buttoninfo.flashfocus_chunk : &tce->buttoninfo.chunkfocus_bmp);
1020 } else {
1021 BltBmpToScreen(tce->pos_x + glitch_dx, tce->pos_y + glitch_dy,
1022 (time_to_flash) ? &tce->buttoninfo.flash_chunk : &tce->buttoninfo.chunk_bmp);
1023 }
1024 }