check if we have a working C++ compiler
[rofl0r-df-libgraphics.git] / g_src / interface.cpp
blobde1ebcec6f41226bb455da9e0f158618b656372b
1 #include "platform.h"
2 #include <string.h>
3 #include <math.h>
4 #include <iosfwd>
5 #include <iostream>
6 #include <ios>
7 #include <streambuf>
8 #include <istream>
9 #include <ostream>
10 #include <iomanip>
11 #include <sstream>
12 #include <cstdlib>
13 #include <fstream>
14 #include <zlib.h>
16 #include "svector.h"
17 using std::string;
19 #include "endian.h"
21 #include "files.h"
23 #include "enabler.h"
25 #include "textlines.h"
27 #include "find_files.h"
29 #include "basics.h"
31 #include "g_basics.h"
33 #include "music_and_sound_g.h"
35 #include "graphics.h"
37 #include "init.h"
39 #include "keybindings.h"
40 #include "interface.h"
41 #include "KeybindingScreen.h"
42 #include "ttf_manager.hpp"
44 #include <list>
45 #include <set>
47 void dwarf_end_announcements();
48 void dwarf_remove_screen();
49 void dwarf_option_screen();
50 void drawborder(const char *str,char style,const char *colorstr);
53 inline void CHECK_ERR(int err, const char* msg)
55 if (err != Z_OK)
57 MessageBox(NULL, "One of the compressed files on disk has errors in it. Restore from backup if you are able.", 0, 0);
58 exit(1);
62 using std::fstream;
63 using std::ios;
64 using std::list;
65 using std::set;
67 extern interfacest gview;
68 extern enablerst enabler;
69 extern graphicst gps;
70 extern initst init;
71 #ifndef NO_FMOD
72 extern musicsoundst musicsound;
73 #endif
75 extern GameMode gamemode;
76 extern GameType gametype;
78 extern int32_t movie_version;
83 void viewscreen_movieplayerst::help()
85 if(is_playing)return;
87 viewscreenst::help();
90 void interfacest::finish_movie()
92 supermovie_on=0;
93 currentblocksize=0;
94 nextfilepos=0;
95 supermovie_pos=0;
96 viewscreen_movieplayerst::create(INTERFACE_PUSH_AT_BACK);
99 void interfacest::use_movie_input()
101 if(supermovie_on)handlemovie(1);
102 finish_movie();
105 viewscreen_movieplayerst *viewscreen_movieplayerst::create(char pushtype,viewscreenst *scr)
107 viewscreen_movieplayerst *newv=new viewscreen_movieplayerst();
108 gview.addscreen(newv,pushtype,scr);
110 return newv;
113 void viewscreen_movieplayerst::force_play(const string &file)
115 force_file=file;
116 is_forced_play=1;
119 void viewscreen_movieplayerst::logic()
121 enabler.flag&=~ENABLERFLAG_MAXFPS;
123 enabler.flag|=ENABLERFLAG_RENDER;
125 if(!force_file.empty()&&!is_playing&&!quit_if_no_play&&is_forced_play)
127 is_playing=1;
128 quit_if_no_play=1;
129 gview.movie_file=force_file;
130 gview.supermovie_on=0;
131 gview.currentblocksize=0;
132 gview.nextfilepos=0;
133 gview.supermovie_pos=0;
134 maxmoviepos=0;
137 if(!is_playing&&quit_if_no_play)
139 breakdownlevel=INTERFACE_BREAKDOWN_STOPSCREEN;
140 return;
143 //LOAD A MOVIE BUFFER BY BUFFER
144 if(is_playing)
146 if(gview.supermovie_pos>=MOVIEBUFFSIZE||gview.currentblocksize==0)
148 gview.read_movie_chunk(maxmoviepos,is_playing);
151 if(is_playing)
153 int half_frame_size=init.display.grid_x*init.display.grid_y;
155 #ifndef NO_FMOD
156 //PLAY ANY RELEVANT SOUNDS
157 if(gview.supermovie_delaystep==gview.supermovie_delayrate)
159 int fr=gview.supermovie_pos/(half_frame_size*2);
160 if(fr>=0&&fr<200)
162 int c,sd;
163 for(c=0;c<16;c++)
165 sd=gview.supermovie_sound_time[fr][c];
166 if(sd>=0&&sd<gview.supermovie_sound.str.size())
168 musicsound.playsound(sd,c);
173 #endif
175 //PRINT THE NEXT FRAME AND ADVANCE POSITION
176 short x2,y2;
177 for(x2=0;x2<init.display.grid_x;x2++)
179 for(y2=0;y2<init.display.grid_y;y2++)
181 gview.supermovie_pos++;
184 if(gview.supermovie_delaystep==0)
186 gview.supermovie_pos+=half_frame_size;
187 gview.supermovie_delaystep=gview.supermovie_delayrate;
189 else
191 gview.supermovie_pos-=half_frame_size;//RETURN TO LAST FRAME
192 gview.supermovie_delaystep--;
195 //DONE
196 if(gview.supermovie_pos>=maxmoviepos&&
197 maxmoviepos+half_frame_size*2<MOVIEBUFFSIZE)
199 is_playing=0;
200 //NOTE: THIS CAUSES IT TO LOSE THE LAST FRAME DUE TO CLEARING
206 void viewscreen_movieplayerst::render()
208 if(breakdownlevel!=INTERFACE_BREAKDOWN_NONE)return;
210 if(!is_playing&&is_forced_play)return;
212 if(!quit_if_no_play)
214 if(editing)drawborder(NULL);
215 else drawborder(" Moving Records ");
218 //LOAD A MOVIE BUFFER BY BUFFER
219 if(is_playing)
221 if(gview.currentblocksize>0)
223 int32_t half_frame_size=init.display.grid_x*init.display.grid_y;
225 //PRINT THE NEXT FRAME AND ADVANCE POSITION
226 drawborder(NULL,-1);
228 int32_t curp=gview.supermovie_pos;
229 //HANG ON THE LAST FRAME TO AVOID POSSIBLE OVERRUNS
230 if(gview.supermovie_pos>=MOVIEBUFFSIZE-half_frame_size*2)
232 curp=MOVIEBUFFSIZE-half_frame_size*4;
234 short x2,y2;
235 for(x2=0;x2<init.display.grid_x;x2++)
237 for(y2=0;y2<init.display.grid_y;y2++,++curp)
239 gps.locate(y2,x2);
241 gps.changecolor((gview.supermoviebuffer[curp+half_frame_size] & 7),
242 (gview.supermoviebuffer[curp+half_frame_size] & 56)>>3,
243 (gview.supermoviebuffer[curp+half_frame_size] & 64));
245 gps.addchar(gview.supermoviebuffer[curp]);
250 else if(loading)
252 int scroll=selfile/21*21;
253 int l;
254 for(l=scroll;l<filelist.size() && l<scroll+21;l++)
256 if(l==selfile)gps.changecolor(7,0,1);
257 else gps.changecolor(7,0,0);
258 gps.locate(l-scroll+2,2);
259 gps.addst(filelist[l]);
262 #ifdef DEBUG_MOVIE_EDIT
263 else if(editing)
265 if(editing_menu)
267 int tx,ty;
268 unsigned char c=0;
269 for(ty=0;ty<16;ty++)
271 for(tx=0;tx<16;tx++)
273 gps.locate(ty,tx);
274 gps.changecolor(editing_screenf,editing_screenb,editing_screenbright);
275 gps.addchar(c);
276 c++;
279 gps.locate(18,0);
280 gps.changecolor(editing_screenf,editing_screenb,editing_screenbright);
281 gps.addchar(editing_char);
282 for(ty=0;ty<16;ty++)
284 for(tx=0;tx<8;tx++)
286 gps.locate(ty,tx+16);
287 gps.changecolor(ty%8,tx,ty/8);
288 gps.addchar('A');
292 gps.changecolor(7,0,1);
293 gps.locate(20,0);
294 string str;
295 gps.addst("1/100 sec per frame: ");convert_long_to_string(gview.supermovie_delayrate,str);
296 gps.addst(str);
298 int scroll=(editing_selected_sound/25)*25;
299 int e;
300 for(e=scroll;e<scroll+25&&e<gview.supermovie_sound.str.size();e++)
302 if(e==editing_selected_sound)gps.changecolor(7,0,1);
303 else gps.changecolor(7,0,0);
304 gps.locate(e-scroll,26);
305 gps.addst(gview.supermovie_sound.str[e]->dat);
308 int frame=gview.supermovie_pos/4000,sd;
309 for(e=0;e<SOUND_CHANNELNUM;e++)
311 gps.changecolor(2,0,1);
312 gps.locate(e-scroll,52);
313 sd=gview.supermovie_sound_time[frame][e];
314 if(sd>=0&&sd<gview.supermovie_sound.str.size())gps.addst(gview.supermovie_sound.str[sd]->dat);
315 else
317 gps.addst("-----------------");
319 gps.changecolor(4,0,1);
320 gps.locate(e-scroll,(init.display.grid_x-1));
321 gps.addst("X");
324 else
326 drawborder(NULL,-1);
328 int curp=gview.supermovie_pos;
329 int x2,y2;
330 for(x2=0;x2<80;x2++)
332 for(y2=0;y2<25;y2++)
334 gps.locate(y2,x2);
336 gps.changecolor((gview.supermoviebuffer[curp+2000] & 7),
337 (gview.supermoviebuffer[curp+2000] & 56)>>3,
338 (gview.supermoviebuffer[curp+2000] & 64));
340 gps.addchar(gview.supermoviebuffer[curp]);
342 curp++;
346 if(enabler.mouse_y<150)gps.locate(24,0);
347 else gps.locate(0,0);
348 gps.changecolor(2,0,1);
349 gps.addst("Frame: ");
350 string num;
351 convert_long_to_string(gview.supermovie_pos/4000+1,num);
352 gps.addst(num);
354 if(enabler.mouse_y<150)gps.locate(24,20);
355 else gps.locate(0,20);
356 gps.changecolor(3,0,1);
357 gps.addst("Copy From: ");
358 convert_long_to_string(editing_copy_from/4000+1,num);
359 gps.addst(num);
361 if(enabler.mouse_y<150)gps.locate(24,40);
362 else gps.locate(0,40);
363 gps.changecolor(4,0,1);
364 gps.addst("Ends At: ");
365 convert_long_to_string(end_frame_pos/4000+1,num);
366 gps.addst(num);
368 if(enabler.mouse_y<150)gps.locate(24,60);
369 else gps.locate(0,60);
370 int sx,sy;
371 gps.get_mouse_text_coords(sx,sy);
372 gps.changecolor(7,0,1);
373 gps.addst("(");
374 convert_long_to_string(sx,num);
375 gps.addst(num);
376 gps.addst(",");
377 convert_long_to_string(sy,num);
378 gps.addst(num);
379 gps.addst(")");
382 #endif
383 else
385 gps.changecolor(7,0,1);
386 gps.locate(2,2);
387 gview.print_interface_token(INTERFACEKEY_MOVIE_RECORD);
388 gps.addst(": Start recording (active record is erased, stops when you return here)");
389 gps.locate(3,2);
390 gview.print_interface_token(INTERFACEKEY_MOVIE_PLAY);
391 gps.addst(": Play the active moving record");
392 gps.locate(4,2);
393 gview.print_interface_token(INTERFACEKEY_MOVIE_SAVE);
394 gps.addst(": Save the active moving record (you will be prompted for a name)");
395 gps.locate(5,2);
396 gview.print_interface_token(INTERFACEKEY_MOVIE_LOAD);
397 gps.addst(": Load a moving record");
399 #ifdef DEBUG_MOVIE_EDIT
400 gps.locate(7,2);
401 gps.addst("E: Edit");
402 #endif
404 if(saving)
406 gps.locate(10,2);
407 gps.addst("Name: ");
408 gps.addst(savename);
413 void viewscreen_movieplayerst::feed(std::set<InterfaceKey> &events)
415 if(events.count(INTERFACEKEY_LEAVESCREEN))
417 events.clear();
419 if(is_playing)
421 is_playing=0;
422 enabler.release_grid_size();
423 if (gview.original_fps)
424 enabler.set_fps(gview.original_fps);
425 gview.supermovie_on=0;
426 gview.currentblocksize=0;
427 gview.nextfilepos=0;
428 gview.supermovie_pos=0;
429 maxmoviepos=0;
431 #ifndef NO_FMOD
432 musicsound.stop_sound();
433 #endif
435 else if(saving)saving=0;
436 else if(loading)loading=0;
437 #ifdef DEBUG_MOVIE_EDIT
438 else if(editing)editing=0;
439 #endif
440 else
442 is_playing=0;
443 enabler.release_grid_size();
444 if (gview.original_fps)
445 enabler.set_fps(gview.original_fps);
446 gview.supermovie_on=0;
447 gview.currentblocksize=0;
448 gview.nextfilepos=0;
449 gview.supermovie_pos=0;
450 maxmoviepos=0;
452 breakdownlevel=INTERFACE_BREAKDOWN_STOPSCREEN;
453 return;
456 else if(saving)
458 standardstringentry(savename,39,STRINGENTRY_LETTERS|STRINGENTRY_SPACE|STRINGENTRY_NUMBERS|STRINGENTRY_SYMBOLS,events);
460 if(events.count(INTERFACEKEY_SELECT))
462 string filename;
463 filename="data/movies/";
464 filename+=savename;
465 filename+=".cmv";
467 copy_file(gview.movie_file,filename);
468 saving=0;
471 else if(loading)
473 if(events.count(INTERFACEKEY_SELECT))
475 string filename;
476 filename="data/movies/";
477 filename+=filelist[selfile];
479 if(filename!=gview.movie_file)
481 copy_file(filename,gview.movie_file);
483 loading=0;
486 standardscrolling(events,selfile,0,filelist.size()-1,21);
488 #ifdef DEBUG_MOVIE_EDIT
489 else if(editing)
491 char entering=0;
493 if(editing_menu)
495 if(enabler.mouse_lbut&&enabler.tracking_on)
497 int sx,sy;
498 gps.get_mouse_text_coords(sx,sy);
500 if(sx>=0&&sx<80&&sy>=0&&sy<25)
502 if(sx>=0&&sx<16&&sy>=0&&sy<16)
504 editing_char=sx+sy*16;
506 if(sx>=16&&sx<24&&sy>=0&&sy<16)
508 editing_screenf=sy%8;
509 editing_screenb=sx-16;
510 editing_screenbright=sy/8;
512 if(sx>=26&&sx<=51&&sy>=0&&sy<SOUND_CHANNELNUM)
514 editing_selected_sound=sy;
516 int frame=gview.supermovie_pos/4000;
517 if(sx>=52&&sx<=78&&sy>=0&&sy<SOUND_CHANNELNUM)
519 gview.supermovie_sound_time[frame][sy]=editing_selected_sound;
521 if(sx==(init.display.grid_x-1)&&sy>=0&&sy<SOUND_CHANNELNUM)
523 gview.supermovie_sound_time[frame][sy]=-1;
527 enabler.mouse_lbut=0;
530 if(enabler.mouse_rbut&&enabler.tracking_on)
532 editing_menu=0;
533 enabler.mouse_rbut=0;
536 if(editing_selected_sound>=0&&editing_selected_sound<gview.supermovie_sound.str.size())
538 if(gview.c== '%')
540 delete gview.supermovie_sound.str[editing_selected_sound];
541 gview.supermovie_sound.str.erase(editing_selected_sound);
543 else
545 standardstringentry(events,gview.supermovie_sound.str[editing_selected_sound]->dat,26,STRINGENTRY_LETTERS|STRINGENTRY_SPACE|STRINGENTRY_NUMBERS|STRINGENTRY_SYMBOLS);
546 entering=1;
549 else
551 if(gview.c== '#')gview.supermovie_sound.add_string("new_sound");
552 if(gview.c== '+')gview.supermovie_delayrate++;
553 if(gview.c== '-')gview.supermovie_delayrate--;
554 if(gview.c== 'T')text_mode=1-text_mode;
556 if(gview.supermovie_delayrate<0)gview.supermovie_delayrate=0;
557 if(gview.supermovie_delayrate>10)gview.supermovie_delayrate=10;
559 else
561 if(text_mode)
563 if(gview.c!=0)
565 int sx,sy;
566 gps.get_mouse_text_coords(sx,sy);
568 if(sx>=0&&sx<80&&sy>=0&&sy<25)
570 int curpos=gview.supermovie_pos+sy+sx*25;
571 gview.supermoviebuffer[curpos]=gview.c;
572 gview.supermoviebuffer[curpos+2000]=(editing_screenf&7)+((editing_screenb&7)<<3);
573 if(editing_screenbright)gview.supermoviebuffer[curpos+2000]+=64;
577 else
579 if(gview.c== 'a')
581 int x2,y2;
582 for(x2=0;x2<80;x2++)
584 for(y2=0;y2<25;y2++)
586 if(x2>0)
588 gview.supermoviebuffer[gview.supermovie_pos+y2+(x2-1)*25]=gview.supermoviebuffer[gview.supermovie_pos+y2+x2*25];
589 gview.supermoviebuffer[gview.supermovie_pos+y2+(x2-1)*25+2000]=gview.supermoviebuffer[gview.supermovie_pos+y2+x2*25+2000];
591 if(x2==(init.display.grid_x-1))gview.supermoviebuffer[gview.supermovie_pos+y2+x2*25]=0;
595 if(gview.c== 'd')
597 int x2,y2;
598 for(x2=(init.display.grid_x-1);x2>=0;x2--)
600 for(y2=0;y2<(init.display.grid_y-1);y2++)
602 if(x2<(init.display.grid_x-1))
604 gview.supermoviebuffer[gview.supermovie_pos+y2+(x2+1)*25]=gview.supermoviebuffer[gview.supermovie_pos+y2+x2*25];
605 gview.supermoviebuffer[gview.supermovie_pos+y2+(x2+1)*25+2000]=gview.supermoviebuffer[gview.supermovie_pos+y2+x2*25+2000];
607 if(x2==0)gview.supermoviebuffer[gview.supermovie_pos+y2+x2*25]=0;
611 if(gview.c== 'E')end_frame_pos=gview.supermovie_pos;
612 if(gview.c== 'c')editing_copy_from=gview.supermovie_pos;
613 if(gview.c== 'p')
615 int i;
616 for(i=0;i<4000;i++)
618 gview.supermoviebuffer[gview.supermovie_pos+i]=gview.supermoviebuffer[editing_copy_from+i];
621 if(gview.c== '+')gview.supermovie_pos+=4000;
622 if(gview.c== '-')gview.supermovie_pos-=4000;
623 if(gview.c== '/')gview.supermovie_pos-=40000;
624 if(gview.c== '*')gview.supermovie_pos+=40000;
625 if(gview.supermovie_pos<0)gview.supermovie_pos=0;
626 if(gview.supermovie_pos>=MOVIEBUFFSIZE)gview.supermovie_pos=MOVIEBUFFSIZE-4000;
629 if(enabler.mouse_lbut&&enabler.tracking_on)
631 int sx,sy;
632 gps.get_mouse_text_coords(sx,sy);
634 if(sx>=0&&sx<80&&sy>=0&&sy<25)
636 int curpos=gview.supermovie_pos+sy+sx*25;
637 gview.supermoviebuffer[curpos]=editing_char;
638 gview.supermoviebuffer[curpos+2000]=(editing_screenf&7)+((editing_screenb&7)<<3);
639 if(editing_screenbright)gview.supermoviebuffer[curpos+2000]+=64;
642 if(enabler.mouse_rbut&&enabler.tracking_on)
644 editing_menu=1;
645 enabler.mouse_rbut=0;
649 if(!entering&&gview.c== 'S')
651 int opos=gview.supermovie_pos;
652 gview.first_movie_write=1;
653 gview.supermovie_pos=end_frame_pos+4000;
655 gview.write_movie_chunk();
657 gview.supermovie_pos=opos;
660 #endif
661 else
663 if(is_playing)
666 else
668 #ifdef DEBUG_MOVIE_EDIT
669 if(gview.c== 'E')
671 editing=1;
672 gview.supermovie_pos=0;
674 #endif
676 if(events.count(INTERFACEKEY_MOVIE_RECORD))
678 //TURN ON THE MOVIE RECORDER
679 is_playing=0;
680 enabler.release_grid_size();
681 if (gview.original_fps)
682 enabler.set_fps(gview.original_fps);
683 gview.supermovie_on=1;
684 gview.currentblocksize=0;
685 gview.nextfilepos=0;
686 gview.supermovie_pos=0;
687 gview.supermovie_delayrate=0;
688 gview.first_movie_write=1;
689 maxmoviepos=0;
691 breakdownlevel=INTERFACE_BREAKDOWN_STOPSCREEN;
693 if(events.count(INTERFACEKEY_MOVIE_PLAY))
695 is_playing=1;
696 gview.supermovie_on=0;
697 gview.currentblocksize=0;
698 gview.nextfilepos=0;
699 gview.supermovie_pos=0;
700 maxmoviepos=0;
702 if(events.count(INTERFACEKEY_MOVIE_SAVE))
704 savename.erase();
705 saving=1;
707 if(events.count(INTERFACEKEY_MOVIE_LOAD))
709 selfile=0;
711 clearfilelist();
713 find_files_by_pattern("data/movies/*.cmv",filelist);
715 if(filelist.size()>0)loading=1;
721 void viewscreen_movieplayerst::clearfilelist()
723 int f;
724 for(f=0;f<filelist.size();f++)delete[] filelist[f];
725 filelist.clear();
728 viewscreen_movieplayerst::viewscreen_movieplayerst()
730 force_file.erase();
731 gview.movie_file="data/movies/last_record.cmv";
732 is_playing=0;
733 enabler.release_grid_size();
734 if (gview.original_fps)
735 enabler.set_fps(gview.original_fps);
736 is_forced_play=0;
737 quit_if_no_play=0;
738 gview.supermovie_on=0;
739 gview.currentblocksize=0;
740 gview.nextfilepos=0;
741 gview.supermovie_pos=0;
742 maxmoviepos=0;
743 saving=0;
744 loading=0;
745 editing=0;
746 text_mode=0;
747 editing_copy_from=0;
748 editing_char=219;
749 editing_screenf=7;
750 editing_screenb=0;
751 editing_screenbright=0;
752 editing_menu=0;
753 editing_selected_sound=0;
754 end_frame_pos=0;
755 gview.supermovie_sound.clean();
756 #ifndef NO_FMOD
757 int i,c;
758 for(i=0;i<200;i++)
760 for(c=0;c<SOUND_CHANNELNUM;c++)gview.supermovie_sound_time[i][c]=-1;
762 #endif
765 interfacest::interfacest()
767 original_fps = 0;
768 shutdown_interface_for_ms=0;
769 shutdown_interface_tickcount=0;
770 flag=0;
771 supermovie_on=0;
772 supermovie_pos=0;
773 supermovie_delayrate=0;
776 interfacest::~interfacest()
778 //GO AHEAD
779 while(view.child!=NULL)
781 removescreen(view.child);
785 void interfacest::addscreen(viewscreenst *scr,char pushtype,viewscreenst *relate)
787 gps.force_full_display_count+=2;
789 switch(pushtype)
791 case INTERFACE_PUSH_AS_PARENT:insertscreen_as_parent(scr,relate);break;
792 case INTERFACE_PUSH_AS_CHILD:insertscreen_as_child(scr,relate);break;
793 case INTERFACE_PUSH_AT_FRONT:insertscreen_at_front(scr);break;
794 default:insertscreen_at_back(scr);break;
797 //WHENEVER A SCREEN IS ADDED, END ANNOUNCEMENTS
798 if(gamemode==GAMEMODE_DWARF)dwarf_end_announcements();
801 void interfacest::insertscreen_as_parent(viewscreenst *scr,viewscreenst *child)
803 if(child==NULL)
805 insertscreen_at_back(scr);
806 return;
809 scr->child=child;
810 scr->parent=child->parent;
812 if(scr->parent!=NULL)scr->parent->child=scr;
813 child->parent=scr;
816 void interfacest::insertscreen_as_child(viewscreenst *scr,viewscreenst *parent)
818 if(parent==NULL)
820 insertscreen_at_back(scr);
821 return;
824 scr->child=parent->child;
825 scr->parent=parent;
827 if(scr->child!=NULL)scr->child->parent=scr;
828 parent->child=scr;
831 void interfacest::insertscreen_at_back(viewscreenst *scr)
833 //GRAB CURRENT SCREEN AT THE END OF THE LIST
834 viewscreenst *currentscreen=&view;
835 while(currentscreen->child!=NULL)currentscreen=currentscreen->child;
837 //PUT IT ON TO THE BACK SCREEN
838 insertscreen_as_child(scr,currentscreen);
841 void interfacest::insertscreen_at_front(viewscreenst *scr)
843 //PUT IT ON TO THE BASE
844 insertscreen_as_child(scr,&view);
847 viewscreenst *interfacest::grab_lastscreen() {
848 viewscreenst *currentscreen = &view;
849 while (currentscreen->child) currentscreen = currentscreen->child;
850 return currentscreen;
853 char interfacest::loop() {
854 //NO INTERFACE LEFT, QUIT
855 if(view.child==0)return 1;
857 //GRAB CURRENT SCREEN AT THE END OF THE LIST
858 viewscreenst *currentscreen = grab_lastscreen();
859 //MOVE SCREENS BACK
860 switch(currentscreen->breakdownlevel) {
861 case INTERFACE_BREAKDOWN_NONE: {
863 currentscreen->logic();
865 if(currentscreen->movies_okay())
867 //HANDLE MOVIES
868 handlemovie(0);
871 const Time now = SDL_GetTicks();
872 // Process as much input as possible. Some screens can't handle multiple input events
873 // per logic call (retain_nonzero_input, and any alteration to the window setup
874 // requires us to stop until the next logic call.
875 for (;;) {
876 if (currentscreen->child || currentscreen->breakdownlevel != INTERFACE_BREAKDOWN_NONE)
877 break; // Some previous input or logic had the effect of switching screens
879 if (flag & INTERFACEFLAG_RETAIN_NONZERO_INPUT) {
880 flag&=~INTERFACEFLAG_RETAIN_NONZERO_INPUT;
881 break;
882 } else {
883 set<InterfaceKey> era = enabler.get_input(now);
884 if (era.size() == 0) {
885 if(enabler.mouse_lbut || enabler.mouse_rbut) currentscreen->feed(era);
886 break;
889 if (era.count(INTERFACEKEY_OPTIONS)&&!currentscreen->key_conflict(INTERFACEKEY_OPTIONS)) {
890 //PEEL BACK ALL SCREENS TO THE CURRENT OPTION SCREEN IF THERE IS ONE
891 //UNLESS THERE IS A BLOCKING SCREEN LIKE THE REGION MAKER
892 viewscreenst *opscreen=&view;
893 while(opscreen!=NULL) {
894 if(opscreen->is_option_screen()) {
895 opscreen->option_key_pressed=1;
896 while(opscreen->child!=NULL) {
897 if(opscreen->child->is_option_screen()==2) {
898 opscreen->child->option_key_pressed=1;
899 opscreen->option_key_pressed=0;
900 break;
902 removescreen(opscreen->child);
904 break;
906 opscreen = opscreen->child;
908 //NEED A NEW OPTIONS SCREEN?
909 if(opscreen==NULL) dwarf_option_screen();
911 era.clear();
912 continue;
914 //DO MOVIE COMMANDS
915 if (era.count(INTERFACEKEY_MOVIES)&&!currentscreen->key_conflict(INTERFACEKEY_MOVIES))
916 if(currentscreen->movies_okay()) use_movie_input();
917 if (era.count(INTERFACEKEY_HELP)&&!currentscreen->key_conflict(INTERFACEKEY_HELP))
918 currentscreen->help();
919 // Prefix commands
920 // Most prefix commands we don't want to touch game management commands,
921 // i.e. what's in here. Macro playback is a notable exception.
922 if (era.count(INTERFACEKEY_PREFIX))
923 enabler.prefix_toggle();
924 int repeats = 1; // If this input ends a prefix command, we'll want to repeat it.
925 if (enabler.prefix_building()) {
926 // TODO: OMGWTFBBQ
927 char c = 0;
928 if (era.count(INTERFACEKEY_STRING_A048)) c = '0';
929 else if (era.count(INTERFACEKEY_STRING_A049)) c = '1';
930 else if (era.count(INTERFACEKEY_STRING_A050)) c = '2';
931 else if (era.count(INTERFACEKEY_STRING_A051)) c = '3';
932 else if (era.count(INTERFACEKEY_STRING_A052)) c = '4';
933 else if (era.count(INTERFACEKEY_STRING_A053)) c = '5';
934 else if (era.count(INTERFACEKEY_STRING_A054)) c = '6';
935 else if (era.count(INTERFACEKEY_STRING_A055)) c = '7';
936 else if (era.count(INTERFACEKEY_STRING_A056)) c = '8';
937 else if (era.count(INTERFACEKEY_STRING_A057)) c = '9';
939 if (c) {
940 enabler.prefix_add_digit(c);
941 era.clear();
942 } else {
943 repeats = enabler.prefix_end();
946 // TTF toggle
947 if (era.count(INTERFACEKEY_TOGGLE_TTF)) {
948 if (init.font.use_ttf == ttf_auto) {
949 // Do whatever produces a visible result.
950 if (ttf_manager.ttf_active())
951 init.font.use_ttf = ttf_off;
952 else
953 init.font.use_ttf = ttf_on;
954 } else if (init.font.use_ttf == ttf_on) {
955 init.font.use_ttf = ttf_off;
956 } else {
957 init.font.use_ttf = ttf_on;
959 gps.force_full_display_count++;
961 // Zoom commands
962 if (era.count(INTERFACEKEY_ZOOM_IN))
963 enabler.zoom_display(zoom_in);
964 if (era.count(INTERFACEKEY_ZOOM_OUT))
965 enabler.zoom_display(zoom_out);
966 if (era.count(INTERFACEKEY_ZOOM_RESET))
967 enabler.zoom_display(zoom_reset);
968 // Macro commands
969 if (era.count(INTERFACEKEY_RECORD_MACRO)) {
970 if (enabler.is_recording())
971 enabler.record_stop();
972 else
973 enabler.record_input();
975 if (era.count(INTERFACEKEY_PLAY_MACRO)) {
976 for (int i = 0; i < repeats; i++)
977 enabler.play_macro();
979 if (era.count(INTERFACEKEY_SAVE_MACRO))
980 gview.addscreen(new MacroScreenSave(), INTERFACE_PUSH_AT_BACK, NULL);
981 if (era.count(INTERFACEKEY_LOAD_MACRO))
982 gview.addscreen(new MacroScreenLoad(), INTERFACE_PUSH_AT_BACK, NULL);
983 // Feed input
984 for (int i = 0; i < repeats; i++)
985 currentscreen->feed(era);
986 if (era.count(INTERFACEKEY_TOGGLE_FULLSCREEN)) {
987 enabler.toggle_fullscreen();
989 if (era.count(INTERFACEKEY_FPS_UP)) {
990 int fps = enabler.get_fps();
991 enabler.set_fps(fps + fps/10);
992 enabler.clear_fps();
994 if (era.count(INTERFACEKEY_FPS_DOWN)) {
995 int fps = enabler.get_fps();
996 enabler.set_fps(fps - fps/10);
997 enabler.clear_fps();
1001 break;
1002 } // case INTERFACE_BREAKDOWN_NONE
1004 case INTERFACE_BREAKDOWN_QUIT:
1006 handlemovie(1);
1007 return 1;
1009 case INTERFACE_BREAKDOWN_STOPSCREEN:
1010 if(currentscreen->movies_okay())
1012 //HANDLE MOVIES
1013 handlemovie(0);
1016 removescreen(currentscreen);
1017 break;
1018 case INTERFACE_BREAKDOWN_TOFIRST:
1019 if(currentscreen->movies_okay())
1021 //HANDLE MOVIES
1022 handlemovie(0);
1025 remove_to_first();
1026 break;
1029 return 0;
1032 void interfacest::remove_to_first()
1034 //GRAB LAST SCREEN AT THE END OF THE LIST
1035 viewscreenst *lastscreen=&view;
1036 while(lastscreen->child!=NULL)lastscreen=lastscreen->child;
1038 //NO INTERFACE LEFT
1039 if(lastscreen==&view)return;
1041 //GO AHEAD
1042 while(lastscreen->parent!=&view)
1044 viewscreenst *par=lastscreen->parent;
1045 removescreen(lastscreen);
1046 lastscreen=par;
1050 void interfacest::removescreen(viewscreenst *scr)
1052 //THE MINIMAP IS EXPENSIVE, SO WE REFRESH IT WHENEVER INTERFACE GETS IN THE WAY
1053 if(gamemode==GAMEMODE_DWARF)dwarf_remove_screen();
1055 //FIX LINKS
1056 if(scr->parent!=NULL)scr->parent->child=scr->child;
1057 if(scr->child!=NULL)scr->child->parent=scr->parent;
1059 //WASTE SCREEN
1060 delete scr;
1063 int interfacest::write_movie_chunk()
1065 int inputsize=supermovie_pos;
1066 if(inputsize>MOVIEBUFFSIZE)inputsize=MOVIEBUFFSIZE;
1068 //DUMP CURRENT BUFFER INTO A COMPRESSION STREAM
1069 z_stream c_stream;
1070 int err;
1072 c_stream.zalloc = (alloc_func)0;
1073 c_stream.zfree = (free_func)0;
1074 c_stream.opaque = (voidpf)0;
1076 err = deflateInit(&c_stream, 9);
1077 CHECK_ERR(err, "deflateInit");
1079 c_stream.next_out = (Bytef*)supermoviebuffer_comp;
1080 c_stream.avail_out = COMPMOVIEBUFFSIZE;
1082 c_stream.next_in = (Bytef*)supermoviebuffer;
1083 c_stream.avail_in = inputsize;
1085 while (c_stream.total_in != inputsize && c_stream.total_out < COMPMOVIEBUFFSIZE) {
1086 //c_stream.avail_in = c_stream.avail_out = 1; // force small buffers
1087 err = deflate(&c_stream, Z_NO_FLUSH);
1088 CHECK_ERR(err, "deflate");
1091 // Finish the stream, still forcing small buffers:
1092 for (;;) {
1093 err = deflate(&c_stream, Z_FINISH);
1094 if (err == Z_STREAM_END) break;
1095 CHECK_ERR(err, "deflate");
1098 err = deflateEnd(&c_stream);
1099 CHECK_ERR(err, "deflateEnd");
1101 int length=0;
1103 if(c_stream.total_out>0)
1105 if(first_movie_write)
1107 //GET RID OF ANY EXISTING MOVIES IF THIS IS THE FIRST TIME THROUGH
1108 unlink(movie_file.c_str());
1111 //OPEN UP THE MOVIE FILE AND APPEND
1112 std::fstream f;
1113 f.open(movie_file.c_str(), fstream::out | fstream::binary | fstream::app);
1115 if(f.is_open())
1117 //WRITE A HEADER
1118 if(first_movie_write)
1120 int swp_l=byteswap(movie_version);
1121 f.write((const char *)&swp_l,sizeof(int));
1124 cursesmovie_headerst cmh;
1125 cmh.dimx=init.display.grid_x;
1126 cmh.dimy=init.display.grid_y;
1127 cmh.delayrate=supermovie_delayrate;
1128 cmh.dimx=byteswap(cmh.dimx);
1129 cmh.dimy=byteswap(cmh.dimy);
1130 cmh.delayrate=byteswap(cmh.delayrate);
1131 f.write((const char *)&cmh,sizeof(cursesmovie_headerst));
1133 int s;
1134 s=byteswap(gview.supermovie_sound.str.size());
1135 f.write((const char *)&s,sizeof(int));
1136 char buf[50];
1137 for(s=0;s<gview.supermovie_sound.str.size();s++)
1139 strcpy(buf,gview.supermovie_sound.str[s]->dat.c_str());
1140 f.write(buf,sizeof(char)*50);
1143 int i1,i2;
1144 for(i1=0;i1<200;i1++)
1146 for(i2=0;i2<SOUND_CHANNELNUM;i2++)
1148 #ifndef NO_FMOD
1149 swp_l=byteswap(gview.supermovie_sound_time[i1][i2]);
1150 #else
1151 swp_l=-1;
1152 #endif
1153 f.write((const char *)&swp_l,sizeof(int));
1158 //WRITE IT
1159 int compsize=byteswap(c_stream.total_out);
1160 f.write((const char *)&compsize,sizeof(int));
1161 f.write((const char *)supermoviebuffer_comp,c_stream.total_out);
1163 f.seekg(0,ios::beg);
1164 int beg=f.tellg();
1165 f.seekg(0,ios::end);
1166 int end=f.tellg();
1167 length=end-beg;
1169 f.close();
1171 else supermovie_on=0;
1173 first_movie_write=0;
1176 return length;
1179 void interfacest::read_movie_chunk(int &maxmoviepos,char &is_playing)
1181 //OPEN UP THE MOVIE FILE AND MOVE TO CORRECT POSITION
1182 std::fstream f;
1183 f.open(movie_file.c_str(), fstream::in | fstream::binary);
1185 if(f.is_open())
1187 f.seekg(0,ios::beg);
1188 int beg=f.tellg();
1189 f.seekg(0,ios::end);
1190 int end=f.tellg();
1191 int file_size=end-beg;
1193 if(gview.nextfilepos<file_size)
1195 f.seekg(gview.nextfilepos,ios::beg);
1197 //LOAD THE HEADER
1198 char fail=0;
1199 if(gview.nextfilepos==0)
1201 int loadversion;
1202 f.read((char *)&loadversion,sizeof(int));
1203 loadversion=byteswap(loadversion);
1205 if(loadversion>movie_version)fail=1;
1207 cursesmovie_headerst cmh;
1208 f.read((char *)&cmh,sizeof(cursesmovie_headerst));
1209 cmh.dimx=byteswap(cmh.dimx);
1210 cmh.dimy=byteswap(cmh.dimy);
1211 cmh.delayrate=byteswap(cmh.delayrate);
1213 enabler.override_grid_size(cmh.dimx, cmh.dimy);
1214 if (!gview.original_fps)
1215 gview.original_fps = enabler.get_fps();
1216 enabler.set_fps(100);
1218 gview.supermovie_delayrate=cmh.delayrate;
1219 gview.supermovie_delaystep=cmh.delayrate;
1221 gview.supermovie_sound.clean();
1222 if(loadversion>=10001)
1224 int num;
1225 f.read((char *)&num,sizeof(int));
1226 num=byteswap(num);
1227 gview.nextfilepos+=sizeof(int);
1228 char buf[50];
1229 int s;
1230 for(s=0;s<num;s++)
1232 f.read(buf,sizeof(char)*50);
1233 string str=buf;
1234 gview.supermovie_sound.add_string(str);
1235 gview.nextfilepos+=sizeof(char)*50;
1238 int i1,i2,swp_l;
1239 for(i1=0;i1<200;i1++)
1241 for(i2=0;i2<SOUND_CHANNELNUM;i2++)
1243 f.read((char *)&swp_l,sizeof(int));
1244 #ifndef NO_FMOD
1245 gview.supermovie_sound_time[i1][i2]=byteswap(swp_l);
1246 #endif
1250 gview.nextfilepos+=sizeof(int)*200*SOUND_CHANNELNUM;
1252 else
1254 #ifndef NO_FMOD
1255 int i,c;
1256 for(i=0;i<200;i++)
1258 for(c=0;c<SOUND_CHANNELNUM;c++)gview.supermovie_sound_time[i][c]=-1;
1260 #endif
1263 gview.nextfilepos+=sizeof(int)+sizeof(cursesmovie_headerst);
1265 #ifndef NO_FMOD
1266 //HANDLE SOUND LOADING
1267 int s;
1268 for(s=0;s<gview.supermovie_sound.str.size();s++)
1270 string filename="data/sound/";
1271 filename+=gview.supermovie_sound.str[s]->dat;
1272 filename+=".ogg";
1274 musicsound.set_sound(filename,s);
1276 #endif
1279 if(!fail)
1281 //READ IT
1282 f.read((char *)&gview.currentblocksize,sizeof(int));
1283 gview.currentblocksize=byteswap(gview.currentblocksize);
1284 f.read((char *)gview.supermoviebuffer_comp,gview.currentblocksize);
1286 gview.nextfilepos+=gview.currentblocksize+sizeof(int);
1288 //UNCOMPRESS IT
1289 z_stream d_stream; // decompression stream
1291 d_stream.zalloc = (alloc_func)0;
1292 d_stream.zfree = (free_func)0;
1293 d_stream.opaque = (voidpf)0;
1295 d_stream.next_in = (Bytef*)gview.supermoviebuffer_comp;
1296 d_stream.avail_in = gview.currentblocksize;
1298 int err = inflateInit(&d_stream);
1299 CHECK_ERR(err, "inflateInit");
1301 d_stream.next_out = gview.supermoviebuffer;
1302 d_stream.avail_out = MOVIEBUFFSIZE;
1304 while (d_stream.total_out < MOVIEBUFFSIZE && d_stream.total_in < gview.currentblocksize) {
1305 //d_stream.avail_in = d_stream.avail_out = 1; // force small buffers
1306 err = inflate(&d_stream, Z_NO_FLUSH);
1307 if (err == Z_STREAM_END) break;
1308 CHECK_ERR(err, "inflate");
1311 err = inflateEnd(&d_stream);
1312 CHECK_ERR(err, "inflateEnd");
1314 gview.supermovie_pos=0;
1315 maxmoviepos=d_stream.total_out;
1317 else
1319 is_playing=0;
1320 enabler.release_grid_size();
1321 if (gview.original_fps)
1322 enabler.set_fps(gview.original_fps);
1325 else
1327 is_playing=0;
1328 enabler.release_grid_size();
1329 if (gview.original_fps)
1330 enabler.set_fps(gview.original_fps);
1333 f.close();
1335 else
1337 is_playing=0;
1338 enabler.release_grid_size();
1339 if (gview.original_fps)
1340 enabler.set_fps(gview.original_fps);
1344 void interfacest::handlemovie(char flushall)
1346 //SAVE A MOVIE FRAME INTO THE CURRENT MOVIE BUFFER
1347 if(supermovie_on==1)
1349 if(supermovie_delaystep>0&&!flushall)supermovie_delaystep--;
1350 else
1352 if(!flushall)supermovie_delaystep=supermovie_delayrate;
1354 if(!flushall||supermovie_delaystep==0)
1356 //SAVING CHARACTERS, THEN COLORS
1357 short x2,y2;
1358 for(x2=0;x2<init.display.grid_x;x2++)
1360 for(y2=0;y2<init.display.grid_y;y2++)
1362 supermoviebuffer[supermovie_pos]=gps.screen[x2*gps.dimy*4 + y2*4 + 0];
1364 supermovie_pos++;
1367 char frame_col;
1368 for(x2=0;x2<init.display.grid_x;x2++)
1370 for(y2=0;y2<init.display.grid_y;y2++)
1372 frame_col=gps.screen[x2*gps.dimy*4 + y2*4 + 1];
1373 frame_col|=(gps.screen[x2*gps.dimy*4 + y2*4 + 2]<<3);
1374 if(gps.screen[x2*gps.dimy*4 + y2*4 + 3])frame_col|=64;
1375 supermoviebuffer[supermovie_pos]=frame_col;
1377 supermovie_pos++;
1382 int frame_size=init.display.grid_x*init.display.grid_y*2;
1383 if(supermovie_pos+frame_size>=MOVIEBUFFSIZE||flushall)
1385 int length=write_movie_chunk();
1387 if(length>5000000)
1389 finish_movie();
1391 else supermovie_pos=0;
1397 void interfacest::print_interface_token(InterfaceKey key,justification just)
1399 short o_screenf=gps.screenf,o_screenb=gps.screenb,o_screenbright=gps.screenbright;
1400 gps.changecolor(2,0,1);
1401 string tok = enabler.GetKeyDisplay(key);
1402 gps.addst(tok,just);
1403 gps.changecolor(o_screenf,o_screenb,o_screenbright);
1406 char standardstringentry(char *str,int maxlen,unsigned int flag,std::set<InterfaceKey> &events)
1408 string str2;
1409 str2=str;
1410 char ret=standardstringentry(str2,maxlen,flag,events);
1411 strcpy(str,str2.c_str());
1412 return ret;
1415 char standardstringentry(string &str,int maxlen,unsigned int flag,std::set<InterfaceKey> &events)
1417 unsigned char entry=255;
1418 if(flag & STRINGENTRY_LETTERS)
1420 if(events.count(INTERFACEKEY_STRING_A097))entry='a';
1421 if(events.count(INTERFACEKEY_STRING_A098))entry='b';
1422 if(events.count(INTERFACEKEY_STRING_A099))entry='c';
1423 if(events.count(INTERFACEKEY_STRING_A100))entry='d';
1424 if(events.count(INTERFACEKEY_STRING_A101))entry='e';
1425 if(events.count(INTERFACEKEY_STRING_A102))entry='f';
1426 if(events.count(INTERFACEKEY_STRING_A103))entry='g';
1427 if(events.count(INTERFACEKEY_STRING_A104))entry='h';
1428 if(events.count(INTERFACEKEY_STRING_A105))entry='i';
1429 if(events.count(INTERFACEKEY_STRING_A106))entry='j';
1430 if(events.count(INTERFACEKEY_STRING_A107))entry='k';
1431 if(events.count(INTERFACEKEY_STRING_A108))entry='l';
1432 if(events.count(INTERFACEKEY_STRING_A109))entry='m';
1433 if(events.count(INTERFACEKEY_STRING_A110))entry='n';
1434 if(events.count(INTERFACEKEY_STRING_A111))entry='o';
1435 if(events.count(INTERFACEKEY_STRING_A112))entry='p';
1436 if(events.count(INTERFACEKEY_STRING_A113))entry='q';
1437 if(events.count(INTERFACEKEY_STRING_A114))entry='r';
1438 if(events.count(INTERFACEKEY_STRING_A115))entry='s';
1439 if(events.count(INTERFACEKEY_STRING_A116))entry='t';
1440 if(events.count(INTERFACEKEY_STRING_A117))entry='u';
1441 if(events.count(INTERFACEKEY_STRING_A118))entry='v';
1442 if(events.count(INTERFACEKEY_STRING_A119))entry='w';
1443 if(events.count(INTERFACEKEY_STRING_A120))entry='x';
1444 if(events.count(INTERFACEKEY_STRING_A121))entry='y';
1445 if(events.count(INTERFACEKEY_STRING_A122))entry='z';
1446 if(events.count(INTERFACEKEY_STRING_A065))entry='A';
1447 if(events.count(INTERFACEKEY_STRING_A066))entry='B';
1448 if(events.count(INTERFACEKEY_STRING_A067))entry='C';
1449 if(events.count(INTERFACEKEY_STRING_A068))entry='D';
1450 if(events.count(INTERFACEKEY_STRING_A069))entry='E';
1451 if(events.count(INTERFACEKEY_STRING_A070))entry='F';
1452 if(events.count(INTERFACEKEY_STRING_A071))entry='G';
1453 if(events.count(INTERFACEKEY_STRING_A072))entry='H';
1454 if(events.count(INTERFACEKEY_STRING_A073))entry='I';
1455 if(events.count(INTERFACEKEY_STRING_A074))entry='J';
1456 if(events.count(INTERFACEKEY_STRING_A075))entry='K';
1457 if(events.count(INTERFACEKEY_STRING_A076))entry='L';
1458 if(events.count(INTERFACEKEY_STRING_A077))entry='M';
1459 if(events.count(INTERFACEKEY_STRING_A078))entry='N';
1460 if(events.count(INTERFACEKEY_STRING_A079))entry='O';
1461 if(events.count(INTERFACEKEY_STRING_A080))entry='P';
1462 if(events.count(INTERFACEKEY_STRING_A081))entry='Q';
1463 if(events.count(INTERFACEKEY_STRING_A082))entry='R';
1464 if(events.count(INTERFACEKEY_STRING_A083))entry='S';
1465 if(events.count(INTERFACEKEY_STRING_A084))entry='T';
1466 if(events.count(INTERFACEKEY_STRING_A085))entry='U';
1467 if(events.count(INTERFACEKEY_STRING_A086))entry='V';
1468 if(events.count(INTERFACEKEY_STRING_A087))entry='W';
1469 if(events.count(INTERFACEKEY_STRING_A088))entry='X';
1470 if(events.count(INTERFACEKEY_STRING_A089))entry='Y';
1471 if(events.count(INTERFACEKEY_STRING_A090))entry='Z';
1473 if(flag & STRINGENTRY_SPACE)
1475 if(events.count(INTERFACEKEY_STRING_A032))entry=' ';
1477 if(events.count(INTERFACEKEY_STRING_A000))entry='\x0';
1478 if(flag & STRINGENTRY_NUMBERS)
1480 if(events.count(INTERFACEKEY_STRING_A048))entry='0';
1481 if(events.count(INTERFACEKEY_STRING_A049))entry='1';
1482 if(events.count(INTERFACEKEY_STRING_A050))entry='2';
1483 if(events.count(INTERFACEKEY_STRING_A051))entry='3';
1484 if(events.count(INTERFACEKEY_STRING_A052))entry='4';
1485 if(events.count(INTERFACEKEY_STRING_A053))entry='5';
1486 if(events.count(INTERFACEKEY_STRING_A054))entry='6';
1487 if(events.count(INTERFACEKEY_STRING_A055))entry='7';
1488 if(events.count(INTERFACEKEY_STRING_A056))entry='8';
1489 if(events.count(INTERFACEKEY_STRING_A057))entry='9';
1491 if(flag & STRINGENTRY_SYMBOLS)
1493 if(events.count(INTERFACEKEY_STRING_A000))entry=0;
1494 if(events.count(INTERFACEKEY_STRING_A001))entry=1;
1495 if(events.count(INTERFACEKEY_STRING_A002))entry=2;
1496 if(events.count(INTERFACEKEY_STRING_A003))entry=3;
1497 if(events.count(INTERFACEKEY_STRING_A004))entry=4;
1498 if(events.count(INTERFACEKEY_STRING_A005))entry=5;
1499 if(events.count(INTERFACEKEY_STRING_A006))entry=6;
1500 if(events.count(INTERFACEKEY_STRING_A007))entry=7;
1501 if(events.count(INTERFACEKEY_STRING_A008))entry=8;
1502 if(events.count(INTERFACEKEY_STRING_A009))entry=9;
1503 if(events.count(INTERFACEKEY_STRING_A010))entry=10;
1504 if(events.count(INTERFACEKEY_STRING_A011))entry=11;
1505 if(events.count(INTERFACEKEY_STRING_A012))entry=12;
1506 if(events.count(INTERFACEKEY_STRING_A013))entry=13;
1507 if(events.count(INTERFACEKEY_STRING_A014))entry=14;
1508 if(events.count(INTERFACEKEY_STRING_A015))entry=15;
1509 if(events.count(INTERFACEKEY_STRING_A016))entry=16;
1510 if(events.count(INTERFACEKEY_STRING_A017))entry=17;
1511 if(events.count(INTERFACEKEY_STRING_A018))entry=18;
1512 if(events.count(INTERFACEKEY_STRING_A019))entry=19;
1513 if(events.count(INTERFACEKEY_STRING_A020))entry=20;
1514 if(events.count(INTERFACEKEY_STRING_A021))entry=21;
1515 if(events.count(INTERFACEKEY_STRING_A022))entry=22;
1516 if(events.count(INTERFACEKEY_STRING_A023))entry=23;
1517 if(events.count(INTERFACEKEY_STRING_A024))entry=24;
1518 if(events.count(INTERFACEKEY_STRING_A025))entry=25;
1519 if(events.count(INTERFACEKEY_STRING_A026))entry=26;
1520 if(events.count(INTERFACEKEY_STRING_A027))entry=27;
1521 if(events.count(INTERFACEKEY_STRING_A028))entry=28;
1522 if(events.count(INTERFACEKEY_STRING_A029))entry=29;
1523 if(events.count(INTERFACEKEY_STRING_A030))entry=30;
1524 if(events.count(INTERFACEKEY_STRING_A031))entry=31;
1525 if(events.count(INTERFACEKEY_STRING_A032))entry=32;
1526 if(events.count(INTERFACEKEY_STRING_A033))entry=33;
1527 if(events.count(INTERFACEKEY_STRING_A034))entry=34;
1528 if(events.count(INTERFACEKEY_STRING_A035))entry=35;
1529 if(events.count(INTERFACEKEY_STRING_A036))entry=36;
1530 if(events.count(INTERFACEKEY_STRING_A037))entry=37;
1531 if(events.count(INTERFACEKEY_STRING_A038))entry=38;
1532 if(events.count(INTERFACEKEY_STRING_A039))entry=39;
1533 if(events.count(INTERFACEKEY_STRING_A040))entry=40;
1534 if(events.count(INTERFACEKEY_STRING_A041))entry=41;
1535 if(events.count(INTERFACEKEY_STRING_A042))entry=42;
1536 if(events.count(INTERFACEKEY_STRING_A043))entry=43;
1537 if(events.count(INTERFACEKEY_STRING_A044))entry=44;
1538 if(events.count(INTERFACEKEY_STRING_A045))entry=45;
1539 if(events.count(INTERFACEKEY_STRING_A046))entry=46;
1540 if(events.count(INTERFACEKEY_STRING_A047))entry=47;
1541 if(events.count(INTERFACEKEY_STRING_A048))entry=48;
1542 if(events.count(INTERFACEKEY_STRING_A049))entry=49;
1543 if(events.count(INTERFACEKEY_STRING_A050))entry=50;
1544 if(events.count(INTERFACEKEY_STRING_A051))entry=51;
1545 if(events.count(INTERFACEKEY_STRING_A052))entry=52;
1546 if(events.count(INTERFACEKEY_STRING_A053))entry=53;
1547 if(events.count(INTERFACEKEY_STRING_A054))entry=54;
1548 if(events.count(INTERFACEKEY_STRING_A055))entry=55;
1549 if(events.count(INTERFACEKEY_STRING_A056))entry=56;
1550 if(events.count(INTERFACEKEY_STRING_A057))entry=57;
1551 if(events.count(INTERFACEKEY_STRING_A058))entry=58;
1552 if(events.count(INTERFACEKEY_STRING_A059))entry=59;
1553 if(events.count(INTERFACEKEY_STRING_A060))entry=60;
1554 if(events.count(INTERFACEKEY_STRING_A061))entry=61;
1555 if(events.count(INTERFACEKEY_STRING_A062))entry=62;
1556 if(events.count(INTERFACEKEY_STRING_A063))entry=63;
1557 if(events.count(INTERFACEKEY_STRING_A064))entry=64;
1558 if(events.count(INTERFACEKEY_STRING_A065))entry=65;
1559 if(events.count(INTERFACEKEY_STRING_A066))entry=66;
1560 if(events.count(INTERFACEKEY_STRING_A067))entry=67;
1561 if(events.count(INTERFACEKEY_STRING_A068))entry=68;
1562 if(events.count(INTERFACEKEY_STRING_A069))entry=69;
1563 if(events.count(INTERFACEKEY_STRING_A070))entry=70;
1564 if(events.count(INTERFACEKEY_STRING_A071))entry=71;
1565 if(events.count(INTERFACEKEY_STRING_A072))entry=72;
1566 if(events.count(INTERFACEKEY_STRING_A073))entry=73;
1567 if(events.count(INTERFACEKEY_STRING_A074))entry=74;
1568 if(events.count(INTERFACEKEY_STRING_A075))entry=75;
1569 if(events.count(INTERFACEKEY_STRING_A076))entry=76;
1570 if(events.count(INTERFACEKEY_STRING_A077))entry=77;
1571 if(events.count(INTERFACEKEY_STRING_A078))entry=78;
1572 if(events.count(INTERFACEKEY_STRING_A079))entry=79;
1573 if(events.count(INTERFACEKEY_STRING_A080))entry=80;
1574 if(events.count(INTERFACEKEY_STRING_A081))entry=81;
1575 if(events.count(INTERFACEKEY_STRING_A082))entry=82;
1576 if(events.count(INTERFACEKEY_STRING_A083))entry=83;
1577 if(events.count(INTERFACEKEY_STRING_A084))entry=84;
1578 if(events.count(INTERFACEKEY_STRING_A085))entry=85;
1579 if(events.count(INTERFACEKEY_STRING_A086))entry=86;
1580 if(events.count(INTERFACEKEY_STRING_A087))entry=87;
1581 if(events.count(INTERFACEKEY_STRING_A088))entry=88;
1582 if(events.count(INTERFACEKEY_STRING_A089))entry=89;
1583 if(events.count(INTERFACEKEY_STRING_A090))entry=90;
1584 if(events.count(INTERFACEKEY_STRING_A091))entry=91;
1585 if(events.count(INTERFACEKEY_STRING_A092))entry=92;
1586 if(events.count(INTERFACEKEY_STRING_A093))entry=93;
1587 if(events.count(INTERFACEKEY_STRING_A094))entry=94;
1588 if(events.count(INTERFACEKEY_STRING_A095))entry=95;
1589 if(events.count(INTERFACEKEY_STRING_A096))entry=96;
1590 if(events.count(INTERFACEKEY_STRING_A097))entry=97;
1591 if(events.count(INTERFACEKEY_STRING_A098))entry=98;
1592 if(events.count(INTERFACEKEY_STRING_A099))entry=99;
1593 if(events.count(INTERFACEKEY_STRING_A100))entry=100;
1594 if(events.count(INTERFACEKEY_STRING_A101))entry=101;
1595 if(events.count(INTERFACEKEY_STRING_A102))entry=102;
1596 if(events.count(INTERFACEKEY_STRING_A103))entry=103;
1597 if(events.count(INTERFACEKEY_STRING_A104))entry=104;
1598 if(events.count(INTERFACEKEY_STRING_A105))entry=105;
1599 if(events.count(INTERFACEKEY_STRING_A106))entry=106;
1600 if(events.count(INTERFACEKEY_STRING_A107))entry=107;
1601 if(events.count(INTERFACEKEY_STRING_A108))entry=108;
1602 if(events.count(INTERFACEKEY_STRING_A109))entry=109;
1603 if(events.count(INTERFACEKEY_STRING_A110))entry=110;
1604 if(events.count(INTERFACEKEY_STRING_A111))entry=111;
1605 if(events.count(INTERFACEKEY_STRING_A112))entry=112;
1606 if(events.count(INTERFACEKEY_STRING_A113))entry=113;
1607 if(events.count(INTERFACEKEY_STRING_A114))entry=114;
1608 if(events.count(INTERFACEKEY_STRING_A115))entry=115;
1609 if(events.count(INTERFACEKEY_STRING_A116))entry=116;
1610 if(events.count(INTERFACEKEY_STRING_A117))entry=117;
1611 if(events.count(INTERFACEKEY_STRING_A118))entry=118;
1612 if(events.count(INTERFACEKEY_STRING_A119))entry=119;
1613 if(events.count(INTERFACEKEY_STRING_A120))entry=120;
1614 if(events.count(INTERFACEKEY_STRING_A121))entry=121;
1615 if(events.count(INTERFACEKEY_STRING_A122))entry=122;
1616 if(events.count(INTERFACEKEY_STRING_A123))entry=123;
1617 if(events.count(INTERFACEKEY_STRING_A124))entry=124;
1618 if(events.count(INTERFACEKEY_STRING_A125))entry=125;
1619 if(events.count(INTERFACEKEY_STRING_A126))entry=126;
1620 if(events.count(INTERFACEKEY_STRING_A127))entry=127;
1621 if(events.count(INTERFACEKEY_STRING_A128))entry=128;
1622 if(events.count(INTERFACEKEY_STRING_A129))entry=129;
1623 if(events.count(INTERFACEKEY_STRING_A130))entry=130;
1624 if(events.count(INTERFACEKEY_STRING_A131))entry=131;
1625 if(events.count(INTERFACEKEY_STRING_A132))entry=132;
1626 if(events.count(INTERFACEKEY_STRING_A133))entry=133;
1627 if(events.count(INTERFACEKEY_STRING_A134))entry=134;
1628 if(events.count(INTERFACEKEY_STRING_A135))entry=135;
1629 if(events.count(INTERFACEKEY_STRING_A136))entry=136;
1630 if(events.count(INTERFACEKEY_STRING_A137))entry=137;
1631 if(events.count(INTERFACEKEY_STRING_A138))entry=138;
1632 if(events.count(INTERFACEKEY_STRING_A139))entry=139;
1633 if(events.count(INTERFACEKEY_STRING_A140))entry=140;
1634 if(events.count(INTERFACEKEY_STRING_A141))entry=141;
1635 if(events.count(INTERFACEKEY_STRING_A142))entry=142;
1636 if(events.count(INTERFACEKEY_STRING_A143))entry=143;
1637 if(events.count(INTERFACEKEY_STRING_A144))entry=144;
1638 if(events.count(INTERFACEKEY_STRING_A145))entry=145;
1639 if(events.count(INTERFACEKEY_STRING_A146))entry=146;
1640 if(events.count(INTERFACEKEY_STRING_A147))entry=147;
1641 if(events.count(INTERFACEKEY_STRING_A148))entry=148;
1642 if(events.count(INTERFACEKEY_STRING_A149))entry=149;
1643 if(events.count(INTERFACEKEY_STRING_A150))entry=150;
1644 if(events.count(INTERFACEKEY_STRING_A151))entry=151;
1645 if(events.count(INTERFACEKEY_STRING_A152))entry=152;
1646 if(events.count(INTERFACEKEY_STRING_A153))entry=153;
1647 if(events.count(INTERFACEKEY_STRING_A154))entry=154;
1648 if(events.count(INTERFACEKEY_STRING_A155))entry=155;
1649 if(events.count(INTERFACEKEY_STRING_A156))entry=156;
1650 if(events.count(INTERFACEKEY_STRING_A157))entry=157;
1651 if(events.count(INTERFACEKEY_STRING_A158))entry=158;
1652 if(events.count(INTERFACEKEY_STRING_A159))entry=159;
1653 if(events.count(INTERFACEKEY_STRING_A160))entry=160;
1654 if(events.count(INTERFACEKEY_STRING_A161))entry=161;
1655 if(events.count(INTERFACEKEY_STRING_A162))entry=162;
1656 if(events.count(INTERFACEKEY_STRING_A163))entry=163;
1657 if(events.count(INTERFACEKEY_STRING_A164))entry=164;
1658 if(events.count(INTERFACEKEY_STRING_A165))entry=165;
1659 if(events.count(INTERFACEKEY_STRING_A166))entry=166;
1660 if(events.count(INTERFACEKEY_STRING_A167))entry=167;
1661 if(events.count(INTERFACEKEY_STRING_A168))entry=168;
1662 if(events.count(INTERFACEKEY_STRING_A169))entry=169;
1663 if(events.count(INTERFACEKEY_STRING_A170))entry=170;
1664 if(events.count(INTERFACEKEY_STRING_A171))entry=171;
1665 if(events.count(INTERFACEKEY_STRING_A172))entry=172;
1666 if(events.count(INTERFACEKEY_STRING_A173))entry=173;
1667 if(events.count(INTERFACEKEY_STRING_A174))entry=174;
1668 if(events.count(INTERFACEKEY_STRING_A175))entry=175;
1669 if(events.count(INTERFACEKEY_STRING_A176))entry=176;
1670 if(events.count(INTERFACEKEY_STRING_A177))entry=177;
1671 if(events.count(INTERFACEKEY_STRING_A178))entry=178;
1672 if(events.count(INTERFACEKEY_STRING_A179))entry=179;
1673 if(events.count(INTERFACEKEY_STRING_A180))entry=180;
1674 if(events.count(INTERFACEKEY_STRING_A181))entry=181;
1675 if(events.count(INTERFACEKEY_STRING_A182))entry=182;
1676 if(events.count(INTERFACEKEY_STRING_A183))entry=183;
1677 if(events.count(INTERFACEKEY_STRING_A184))entry=184;
1678 if(events.count(INTERFACEKEY_STRING_A185))entry=185;
1679 if(events.count(INTERFACEKEY_STRING_A186))entry=186;
1680 if(events.count(INTERFACEKEY_STRING_A187))entry=187;
1681 if(events.count(INTERFACEKEY_STRING_A188))entry=188;
1682 if(events.count(INTERFACEKEY_STRING_A189))entry=189;
1683 if(events.count(INTERFACEKEY_STRING_A190))entry=190;
1684 if(events.count(INTERFACEKEY_STRING_A191))entry=191;
1685 if(events.count(INTERFACEKEY_STRING_A192))entry=192;
1686 if(events.count(INTERFACEKEY_STRING_A193))entry=193;
1687 if(events.count(INTERFACEKEY_STRING_A194))entry=194;
1688 if(events.count(INTERFACEKEY_STRING_A195))entry=195;
1689 if(events.count(INTERFACEKEY_STRING_A196))entry=196;
1690 if(events.count(INTERFACEKEY_STRING_A197))entry=197;
1691 if(events.count(INTERFACEKEY_STRING_A198))entry=198;
1692 if(events.count(INTERFACEKEY_STRING_A199))entry=199;
1693 if(events.count(INTERFACEKEY_STRING_A200))entry=200;
1694 if(events.count(INTERFACEKEY_STRING_A201))entry=201;
1695 if(events.count(INTERFACEKEY_STRING_A202))entry=202;
1696 if(events.count(INTERFACEKEY_STRING_A203))entry=203;
1697 if(events.count(INTERFACEKEY_STRING_A204))entry=204;
1698 if(events.count(INTERFACEKEY_STRING_A205))entry=205;
1699 if(events.count(INTERFACEKEY_STRING_A206))entry=206;
1700 if(events.count(INTERFACEKEY_STRING_A207))entry=207;
1701 if(events.count(INTERFACEKEY_STRING_A208))entry=208;
1702 if(events.count(INTERFACEKEY_STRING_A209))entry=209;
1703 if(events.count(INTERFACEKEY_STRING_A210))entry=210;
1704 if(events.count(INTERFACEKEY_STRING_A211))entry=211;
1705 if(events.count(INTERFACEKEY_STRING_A212))entry=212;
1706 if(events.count(INTERFACEKEY_STRING_A213))entry=213;
1707 if(events.count(INTERFACEKEY_STRING_A214))entry=214;
1708 if(events.count(INTERFACEKEY_STRING_A215))entry=215;
1709 if(events.count(INTERFACEKEY_STRING_A216))entry=216;
1710 if(events.count(INTERFACEKEY_STRING_A217))entry=217;
1711 if(events.count(INTERFACEKEY_STRING_A218))entry=218;
1712 if(events.count(INTERFACEKEY_STRING_A219))entry=219;
1713 if(events.count(INTERFACEKEY_STRING_A220))entry=220;
1714 if(events.count(INTERFACEKEY_STRING_A221))entry=221;
1715 if(events.count(INTERFACEKEY_STRING_A222))entry=222;
1716 if(events.count(INTERFACEKEY_STRING_A223))entry=223;
1717 if(events.count(INTERFACEKEY_STRING_A224))entry=224;
1718 if(events.count(INTERFACEKEY_STRING_A225))entry=225;
1719 if(events.count(INTERFACEKEY_STRING_A226))entry=226;
1720 if(events.count(INTERFACEKEY_STRING_A227))entry=227;
1721 if(events.count(INTERFACEKEY_STRING_A228))entry=228;
1722 if(events.count(INTERFACEKEY_STRING_A229))entry=229;
1723 if(events.count(INTERFACEKEY_STRING_A230))entry=230;
1724 if(events.count(INTERFACEKEY_STRING_A231))entry=231;
1725 if(events.count(INTERFACEKEY_STRING_A232))entry=232;
1726 if(events.count(INTERFACEKEY_STRING_A233))entry=233;
1727 if(events.count(INTERFACEKEY_STRING_A234))entry=234;
1728 if(events.count(INTERFACEKEY_STRING_A235))entry=235;
1729 if(events.count(INTERFACEKEY_STRING_A236))entry=236;
1730 if(events.count(INTERFACEKEY_STRING_A237))entry=237;
1731 if(events.count(INTERFACEKEY_STRING_A238))entry=238;
1732 if(events.count(INTERFACEKEY_STRING_A239))entry=239;
1733 if(events.count(INTERFACEKEY_STRING_A240))entry=240;
1734 if(events.count(INTERFACEKEY_STRING_A241))entry=241;
1735 if(events.count(INTERFACEKEY_STRING_A242))entry=242;
1736 if(events.count(INTERFACEKEY_STRING_A243))entry=243;
1737 if(events.count(INTERFACEKEY_STRING_A244))entry=244;
1738 if(events.count(INTERFACEKEY_STRING_A245))entry=245;
1739 if(events.count(INTERFACEKEY_STRING_A246))entry=246;
1740 if(events.count(INTERFACEKEY_STRING_A247))entry=247;
1741 if(events.count(INTERFACEKEY_STRING_A248))entry=248;
1742 if(events.count(INTERFACEKEY_STRING_A249))entry=249;
1743 if(events.count(INTERFACEKEY_STRING_A250))entry=250;
1744 if(events.count(INTERFACEKEY_STRING_A251))entry=251;
1745 if(events.count(INTERFACEKEY_STRING_A252))entry=252;
1746 if(events.count(INTERFACEKEY_STRING_A253))entry=253;
1747 if(events.count(INTERFACEKEY_STRING_A254))entry=254;
1748 if(events.count(INTERFACEKEY_STRING_A255))entry=255;
1751 if(entry!=255)
1753 if(entry=='\x0')
1755 if(str.length()>0)str.resize(str.length()-1);
1757 else
1759 int cursor=str.length();
1760 if(cursor>=maxlen)cursor=maxlen-1;
1761 if(cursor<0)cursor=0;
1763 if(str.length()<cursor+1)str.resize(cursor+1);
1765 if(entry>='a'&&entry<='z'&&(flag & STRINGENTRY_CAPS))str[cursor]=entry+'A'-'a';
1766 else str[cursor]=entry;
1770 return 1;
1773 return 0;
1776 //To Do
1777 //get the gview.c references inside the DEBUG_MOVIE defines
1778 //make scrolling and stringentry use newer pressed functions for better speed