home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------------
-
- #include <fastgraf.h>
- #include <fstream.h>
- #include <stdlib.h>
- #include "standard.h"
- #include "viddir.h"
- #include "ascii.h"
- #include "scancode.h"
- #include "theatrix.h"
-
- int VideoDirector::vpage;
- patch_struct VideoDirector::patch[NUMPATCHES];
- int VideoDirector::patchcount;
- char VideoDirector::flic_context[16];
- FlicHdr VideoDirector::flic_header;
- int VideoDirector::flicplaying;
- int VideoDirector::flicframes;
- int VideoDirector::flicnonstop;
- int VideoDirector::delay;
- int VideoDirector::first;
-
- VideoDirector::VideoDirector()
- {
- request_keystroke_cue('|',(callback)&VideoDirector::on_s);
- request_hotkey_cue(SCAN_PRINTSCREEN,(callback)&VideoDirector::on_hs);
- }
-
- VideoDirector::~VideoDirector()
- {
- fg_setpage(0);
- fg_setvpage(0);
- vpage=0;
- }
-
- void VideoDirector::init_video()
- {
- fg_setpage(0);
- fg_setcolor(0);
- fg_rect(0,fg_getmaxx(),0,fg_getmaxy());
- fg_setvpage(0);
- fg_setpage(1);
- fg_sethpage(2);
- fg_rect(0,fg_getmaxx(),0,fg_getmaxy());
- vpage=0;
- }
-
- int VideoDirector::show_pcx(char* fname)
- {
- fg_move(0,0);
- return fg_showpcx(fname,2)==0;
- }
-
- void VideoDirector::show_video(char* fname,int x,int y, int nonstop)
- {
- if (fg_flichead(fname, (char*)&flic_header) != 0)
- Theatrix::fatal("Bad or missing FLC");
- fg_flicopen(fname, flic_context);
- fg_move(x,y);
- flicplaying = 1;
- flicnonstop = nonstop;
- flicframes = flic_header.frames;
- if (mouseinuse)
- fg_mousevis(0);
- fg_setvpage(1-vpage);
- delay = (int) ((flic_header.delay / 55) * fg_measure());
- first = 1;
- }
-
- void VideoDirector::iterate_director()
- {
- Director::iterate_director();
- if (flicplaying)
- {
- if (flicframes-- == 0)
- {
- if (!flicnonstop)
- {
- stop_video();
- return;
- }
- fg_flicskip(flic_context, -1);
- flicframes = flic_header.frames;
- }
- if (mouseinuse && !first)
- fg_mousevis(0);
- fg_flicplay(flic_context, 1, 3);
- if (mouseinuse)
- fg_mousevis(1);
- fg_stall(delay);
- first = 0;
- }
- }
-
- void VideoDirector::stop_video()
- {
- if (flicplaying)
- {
- fg_flicdone(flic_context);
- flicplaying = 0;
- fg_setvpage(vpage);
- }
- }
-
- void VideoDirector::fill_background_buffer(int frompage)
- {
- fg_copypage(frompage,BUFFERPAGE);
- }
-
- void VideoDirector::restore_page()
- {
- fg_copypage(BUFFERPAGE,1-vpage);
- }
-
- void VideoDirector::swap_video_pages()
- {
- fg_setpage(vpage);
- vpage=1-vpage;
- fg_setvpage(vpage);
- }
-
- void VideoDirector::synch_video_pages()
- {
- fg_copypage(vpage,1-vpage);
- }
-
- void VideoDirector::synch_patch(int x1,int y1,int x2,int y2)
- {
- fg_sethpage(vpage);
- fg_restore(x1,x2,y1,y2);
- }
-
- int VideoDirector::set_synch_patch(int x1,int y1,int x2,int y2)
- {
- if (patchcount>=NUMPATCHES) return ERROR;
- patch[patchcount].x1=x1;
- patch[patchcount].y1=y1;
- patch[patchcount].x2=x2;
- patch[patchcount].y2=y2;
- patchcount++;
- return OK;
- }
-
- int VideoDirector::synch_patches(int frvpage)
- {
- int i,ret=patchcount;
- if (frvpage)
- fg_sethpage(vpage);
- else
- fg_sethpage(BUFFERPAGE);
- for (i=0;i<patchcount;i++)
- fg_restore(patch[i].x1,patch[i].x2,patch[i].y1,patch[i].y2);
- patchcount=0;
- return ret;
- }
-
- void VideoDirector::restore_patch(int x1,int y1,int x2,int y2)
- {
- fg_sethpage(BUFFERPAGE);
- fg_restore(x1,x2,y1,y2);
- }
-
- void VideoDirector::flush_patch(int x1,int y1,int x2,int y2)
- {
- fg_sethpage(1-vpage);
- fg_setpage(vpage);
- fg_restore(x1,x2,y1,y2);
- fg_setpage(1-vpage);
- }
-
- int VideoDirector::install_palette(char* fname)
- {
- struct pal_entry // struct compadible with the
- { // fg_setdacs routine
- unsigned char r;
- unsigned char g;
- unsigned char b;
- };
- char str[80];
- int i,max;
- pal_entry* pal_array;
- int r,g,b;
- ifstream palfile(fname);
- if (palfile.bad()) return NOT_OK;
- palfile.getline(str,80);
- palfile.getline(str,80);
- palfile.getline(str,80);
- max=atoi(str);
- pal_array=new pal_entry[max];
- for (i=0;i<max;i++)
- {
- palfile >> r;
- palfile >> g;
- palfile >> b;
- pal_array[i].r=(unsigned char)r;
- pal_array[i].g=(unsigned char)g;
- pal_array[i].b=(unsigned char)b;
- }
- fg_setdacs(0,max,(char*)pal_array);
- delete pal_array;
- return OK;
- }
-
- void VideoDirector::on_s(int)
- {
- swap_video_pages();
- fg_makepcx(0,fg_getmaxx(),0,fg_getmaxy(),"screen.pcx");
- swap_video_pages();
- }
-
- void VideoDirector::on_hs(int)
- {
- static int flag;
- if (flag) return;
- flag=TRUE;
- on_s();
- }
-