forked from Ermentrout/xppaut
-
Notifications
You must be signed in to change notification settings - Fork 1
/
aniparse.c
executable file
·2772 lines (2444 loc) · 57.1 KB
/
aniparse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "aniparse.h"
#include "color.h"
#include "parserslow.h"
#include "form_ode.h"
#include "my_rhs.h"
#include "nullcline.h"
#include "dialog_box.h"
#include "ggets.h"
#include "init_conds.h"
#include "many_pops.h"
#include "menudrive.h"
#include "pop_list.h"
#include <unistd.h>
#include "scrngif.h"
#include "load_eqn.h"
#include "integrate.h"
#include "sys/types.h"
#include "sys/stat.h"
#include <sys/time.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
/* A simple animator
*/
/*************** NOTES ON MPEG STUFF ********************
To prepare for mpeg encoding in order to make your movies
permanent, I have to do some image manipulation - the main
routine is writeframe()
The current version works for most 8 bit color servers. I have
a version also working for TrueColor 16 bit and I think it works on
24 bit color as well but havent tried it. I really dont know
how all colors are organized. For my machine the 15 lowest order bits
code color as
xrrrrrgggggbbbbb
in binary so lobits are blue etc. If the colors seem screwy, then you might
want to alter the ordering below
************************************************************/
#define INIT_C_SHIFT 0
/* who knows how the colors are ordered */
#ifdef BGR
#define MY_BLUE hibits
#define MY_GREEN midbits
#define MY_RED lobits
#else
#define MY_BLUE lobits
#define MY_GREEN midbits
#define MY_RED hibits
#endif
/**************************************************************/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <stdio.h>
#include <math.h>
#ifndef WCTYPE
#include <ctype.h>
#else
#include <wctype.h>
#endif
#include "xpplim.h"
#include "browse.h"
#include "toons.h"
#include "aniwin.bitmap"
#define MAX_LEN_SBOX 25
#define LINE 0
#define RLINE 1
#define CIRC 2
#define FCIRC 3
#define RECT 4
#define FRECT 5
#define TEXT 6
#define VTEXT 7
#define ELLIP 9
#define FELLIP 10
#define COMET 11
#define PCURVE 12
#define AXNULL 13
#define AYNULL 14
#define GRAB 25
/* not for drawing */
#define SETTEXT 8
/* Not in command list */
#define TRANSIENT 20
#define PERMANENT 21
#define END 50
#define DIMENSION 22
#define COMNT 30
#define SPEED 23
/*************** stuff for grabber *******************/
typedef struct {
double x0,y0;
double x,y;
double ox,oy;
double t1,t2,tstart;
double vx,vy;
double vax,vay;
}
ANI_MOTION_INFO;
ANI_MOTION_INFO ami;
ANI_GRAB ani_grab[MAX_ANI_GRAB];
int n_ani_grab=0;
int show_grab_points=0;
int ani_grab_flag=0;
int who_was_grabbed;
double get_ivar(int);
extern double last_ic[MAXODE],T0;
/************************8 end grabber **********************/
#define FIRSTCOLOR 30
int on_the_fly_speed=10;
int animation_on_the_fly=0;
extern int TrueColorFlag;
extern char *color_names[11];
extern int colorline[];
extern Display *display;
extern XFontStruct *symfonts[5],*romfonts[5];
extern int avsymfonts[5],avromfonts[5];
extern int color_total,screen;
extern int DCURX,DCURXs,DCURY,DCURYs,CURY_OFFs,CURY_OFF,NODE;
extern int FIX_VAR,NMarkov;
extern GC small_gc;
double evaluate();
double atof();
extern BROWSER my_browser;
int aniflag;
int LastAniColor;
int ani_line;
int ani_speed=10;
int ani_speed_inc=2;
/*extern char this_file[100];*/
extern char this_file[XPP_MAX_NAME];
double ani_xlo=0,ani_xhi=1,ani_ylo=0,ani_yhi=1;
double ani_lastx,ani_lasty;
Pixmap ani_pixmap;
/*
typedef struct {
int flag;
int skip;
char root[100];
char filter[256];
int aviflag,filflag;
} MPEG_SAVE;
MPEG_SAVE mpeg;
typedef struct {
int n;
int *x,*y,*col;
int i;
} Comet;
typedef struct {
Comet c;
int type, flag;
int *col,*x1,*y1,*x2,*y2,*who;
double zcol,zx1,zy1,zx2,zy2,zrad,zval;
int zthick,tfont,tsize,tcolor;
} ANI_COM;
*/
MPEG_SAVE mpeg;
ANI_COM my_ani[MAX_ANI_LINES];
typedef struct {
Window base, wfile,wgo,wpause,wreset,wfast,wslow,wmpeg;
Window wfly,kill,slider;
Window wup,wdn,wskip;
Window view,wgrab;
int hgt,wid,iexist,ok;
int pos,inc;
int slipos,sliwid;
char file[XPP_MAX_NAME];
/*char file[256];*/
} VCR;
VCR vcr;
int n_anicom;
int ani_text_size;
int ani_text_color;
int ani_text_font;
GC ani_gc;
extern int use_ani_file;
extern char anifile[256];
char *get_first(/* char *string,char *src */);
char *get_next(/* char *src */);
/* Colors
no color given is default black on white background or white on black
$name is named color -- red ... purple
otherwise evaluated - if between 0 and 1 a spectral color
*/
/* scripting language is very simple:
dimension xlo;ylo;xhi;yh
transient
permanent
line x1;y1;x2;y2;col;thick -- last two optional
rline x2;y2;col;thick -- last two optional
circle x1;x2;r;col;thick -- last optional
fcircle x1;x2;r;col -- last 2 optional
rect x1;y1;x2;y2;col;thick -- last 2 optional
frect x1;y1;x2;y2;col -- last optional
ellip x1;y1;rx;ry;col;thick
fellip x1;y1;rx;ry;col;thick
text x1;y1;s
vtext x1;y1;s;v
settext size;font;color -- size 1-5,font roman symbol,color as above
speed delay in msec
comet x1;y1;type;n;color -- use last n points to draw n objects at
x1,y1 of type type>=0 draws a line
with thickness type
type<0 draws filled circles of
radius |type|
*****
rline is relative to end of last point
fcircle filled circle
rect rectangle
frect filled rect
text string s at (x,y) if v included then a number
eg text .3;.3;t=%g;t
will do a sprintf(string,"t=%g",t);
and put text at .3,.3
*/
/* CREATION STUFF
[File] [Go ] [Pause] [<<<<] [>>>>] [fly]
[Fast] [Slow] [Reset] [Mpeg] [Skip] [Grab]
-----------------------
| |
|_______________________|
*/
#define MYMASK (ButtonPressMask |\
ButtonReleaseMask |\
KeyPressMask |\
ExposureMask |\
StructureNotifyMask |\
LeaveWindowMask |\
EnterWindowMask)
void new_vcr()
{
int tt,i;
if(vcr.iexist==1)return;
tt=gettimenow();
i=(10+(tt%10))%10;
if(i>=0&&i<10)
create_vcr(toons[i]);
else
create_vcr("Wanna be a member");
}
void create_vcr(name)
char *name;
{
unsigned int valuemask=0;
XGCValues values;
Window base;
int wid=280,hgt=350;
/*XWMHints wm_hints;*/
XSizeHints size_hints;
XTextProperty winname,iconname;
base=make_plain_window(RootWindow(display,screen),0,0,5*12*DCURXs+8*DCURXs+4,20*(DCURYs+6),1);
vcr.base=base;
size_hints.flags=PPosition|PSize|PMinSize;
size_hints.min_width=51*DCURXs;
size_hints.min_height=300;
XStringListToTextProperty(&name,1,&winname);
XStringListToTextProperty(&name,1,&iconname);
XSetWMProperties(display,base,&winname,&iconname,NULL,0,&size_hints,NULL,NULL);
make_icon((char *)aniwin_bits,aniwin_width,aniwin_height,base);
vcr.wfile = br_button(base,0,0,"File",0);
vcr.wgo = br_button(base,0,1,"Go",0);
vcr.wreset = br_button(base,0,2,"Reset",0);
vcr.wskip=br_button(base,0,3,"Skip",0);
vcr.wfast = br_button(base,1,0,"Fast",0);
vcr.wslow = br_button(base,1,1,"Slow",0);
vcr.wup = br_button(base,1,2,">>>>",0);
vcr.wdn = br_button(base,1,3,"<<<<",0);
vcr.wgrab=br_button(base,2,3,"Grab",0);
vcr.slider=make_window(base,DCURXs,7+4*DCURYs,48*DCURXs,DCURYs+4,1);
vcr.slipos=0;
vcr.sliwid=48*DCURXs;
vcr.wpause = br_button(base,2,0,"Pause",0);
vcr.wmpeg = br_button(base,2,1,"MPeg",0);
vcr.kill=br_button(base,2,2,"Close",0);
vcr.wfly=make_window(base,4*12*DCURXs,4,5+DCURXs+5,(DCURYs+6)-4,1);
/* vcr.kill=make_window(base,5*12*DCURXs,(DCURYs+6)+4,8*DCURXs,DCURYs+1,1); */
vcr.view=make_plain_window(base,10,100,wid,hgt,2);
ani_gc=XCreateGC(display,vcr.view,valuemask,&values);
vcr.hgt=hgt;
vcr.wid=wid;
ani_pixmap= XCreatePixmap(display,RootWindow(display,screen),vcr.wid,vcr.hgt,
DefaultDepth(display,screen));
if(ani_pixmap==0){
err_msg("Failed to get the required pixmap");
XFlush(display);
waitasec(ClickTime);
XDestroySubwindows(display,base);
XDestroyWindow(display,base);
vcr.iexist=0;
return;
}
vcr.iexist=1;
XSetFunction(display,ani_gc,GXcopy);
XSetForeground(display,ani_gc,WhitePixel(display,screen));
XFillRectangle(display,ani_pixmap,ani_gc,0,0,vcr.wid,vcr.hgt);
XSetForeground(display,ani_gc,BlackPixel(display,screen));
XSetFont(display,ani_gc,romfonts[0]->fid);
tst_pix_draw();
get_global_colormap(ani_pixmap);
mpeg.flag=0;
mpeg.filflag=0;
strcpy(mpeg.root,"frame");
mpeg.filter[0]=0;
mpeg.skip=1;
vcr.pos=0;
if(use_ani_file)
get_ani_file(vcr.file);
}
void ani_border(w,i)
Window w;
int i;
{
if(w==vcr.wgrab||w==vcr.wgo||w==vcr.wreset||w==vcr.wpause||w==vcr.wfast||w==vcr.wfile
||w==vcr.wslow||w==vcr.wmpeg||w==vcr.wup||w==vcr.wdn||w==vcr.wskip||w==vcr.kill)
XSetWindowBorderWidth(display,w,i);
}
void destroy_vcr()
{
vcr.iexist=0;
XDestroySubwindows(display,vcr.base);
XDestroyWindow(display,vcr.base);
}
int check_ani_pause(ev)
XEvent ev;
{
if((vcr.iexist==0)||(!animation_on_the_fly)) return 0;
if(ev.type==ButtonPress && ev.xbutton.window==vcr.wpause) return(27);
return(0);
}
void do_ani_events(ev)
XEvent ev;
{
int x,y;
/*Window w;*/
if(vcr.iexist==0)return;
switch(ev.type){
case ConfigureNotify:
if(ev.xconfigure.window!=vcr.base)return;
x=ev.xconfigure.width;
y=ev.xconfigure.height;
x=(x)/8;
x=8*x;
y=(y)/8;
y=y*8;
ani_resize(x,y);
break;
case EnterNotify:
ani_border(ev.xexpose.window,2);
break;
case LeaveNotify:
ani_border(ev.xexpose.window,1);
break;
case MotionNotify:
do_ani_slider_motion(ev.xmotion.window,ev.xmotion.x);
if(ani_grab_flag == 0)break;
ani_motion_stuff(ev.xmotion.window,ev.xmotion.x,ev.xmotion.y);
break;
case ButtonRelease:
if(ani_grab_flag==0)break;
ani_buttonx(ev,0);
break;
case ButtonPress:
ani_buttonx(ev,1);
break;
}
}
/************************* NEW ANIMaTION STUFF ***********************/
void ani_motion_stuff(Window w,int x,int y)
{
if(w==vcr.view)
update_ani_motion_stuff(x,y);
}
double get_current_time()
{
double t1;
struct timeval tim;
gettimeofday(&tim,NULL);
t1=tim.tv_sec+(tim.tv_usec/1000000.0);
return t1;
}
void update_ani_motion_stuff(int x,int y)
{
double dt;
ami.t2=ami.t1;
ami.t1=get_current_time();
/* printf("%d %d %g %g %g \n",x,y,ami.x,ami.y,ami.t1-ami.t2); */
ami.ox=ami.x;
ami.oy=ami.y;
ani_ij_to_xy(x,y,&ami.x,&ami.y);
dt=ami.t1-ami.t2;
if(dt==0.0)dt=10000000000;
ami.vx=(ami.x-ami.ox)/dt;
ami.vy=(ami.y-ami.oy)/dt;
dt=ami.tstart-ami.t2;
if(dt==0.0)dt=100000000000;
ami.vax=(ami.x0-ami.x)/dt;
ami.vay=(ami.y0-ami.y)/dt;
set_val("mouse_x",ami.x);
set_val("mouse_y",ami.y);
set_val("mouse_vx",ami.vx);
set_val("mouse_vy",ami.vy);
/* printf("%g %g %g %g\n",ami.x,ami.y,ami.vx,ami.vy); */
do_grab_tasks(1);
fix_only();
ani_frame(0);
}
/*************************** End motion & speed stuff ****************/
void ani_buttonx(XEvent ev,int flag)
{
Window w=ev.xbutton.window;
/* ADDED FOR THE GRAB FEATURE IN ANIMATOR This is BUTTON PRESS */
if((w==vcr.view)&&(ani_grab_flag==1)){
if(flag==1){
ami.t1=get_current_time();
ami.tstart=ami.t1;
ani_ij_to_xy(ev.xbutton.x,ev.xbutton.y,&ami.x,&ami.y);
ami.x0=ami.x;
ami.y0=ami.y;
who_was_grabbed=search_for_grab(ami.x,ami.y);
if(who_was_grabbed<0)
printf("Nothing grabbed\n");
/* printf("found %d\n",who_was_grabbed); */
}
if(flag==0){ /* This is BUTTON RELEASE */
/* update_ani_motion_stuff(ev.xbutton.x,ev.xbutton.y); */
if(who_was_grabbed<0){
/* ani_grab_flag=0; */
return;
}
/* printf("Final position %g %g %g %g \n",ami.x,ami.y,ami.vx,ami.vy); */
do_grab_tasks(2);
set_to_init_data();
ani_grab_flag=0;
redraw_params();
if(run_now_grab()){
run_now();
ani_grab_flag=0;
}
}
return;
}
if(flag==0)return;
/* END OF ADDED STUFF ************************/
ani_button(w);
}
void ani_button(w)
Window w;
{
if((ani_grab_flag==1))return;
/* Grab button resets and shows first frame */
if(w==vcr.wgrab){
if(n_ani_grab==0)return;
if(vcr.ok){
vcr.pos=0;
show_grab_points=1;
/* ani_flip1(0); */
ani_frame(1);
ani_frame(0);
ani_grab_flag=1;
}
}
if(w==vcr.wmpeg)
ani_create_mpeg();
if(w==vcr.wgo)
{ani_flip();}
if(w==vcr.wskip)
ani_newskip();
if(w==vcr.wup)
ani_flip1(1);
if(w==vcr.wdn)
ani_flip1(-1);
if(w==vcr.wfile)
get_ani_file(NULL);
if(w==vcr.wfly){
animation_on_the_fly=1-animation_on_the_fly;
check_on_the_fly();
}
if(w==vcr.wreset){
vcr.pos=0;
reset_comets();
redraw_ani_slider();
ani_flip1(0);
}
if(w==vcr.kill){
destroy_vcr();
}
}
void ani_create_mpeg()
{
static char *n[]={"PPM 0/1","Basename","AniGif(0/1)" };
char values[3][MAX_LEN_SBOX];
int status;
mpeg.flag=0;
sprintf(values[0],"%d",mpeg.flag);
sprintf(values[1],"%s",mpeg.root);
sprintf(values[2],"%d",mpeg.aviflag);
status=do_string_box(3,3,1,"Frame saving",n,values,28);
if(status!=0){
mpeg.flag=atoi(values[0]);
if(mpeg.flag>0)mpeg.flag=1;
mpeg.aviflag=atoi(values[2]);
sprintf(mpeg.root,"%s",values[1]);
if(mpeg.aviflag==1)mpeg.flag=0;
}
else
mpeg.flag=0;
if(mpeg.flag==1)
ani_disk_warn();
}
void do_ani_slider_motion(Window w, int x)
{
int l=48*DCURXs,x0=x;
int mr=my_browser.maxrow;
int k;
if(w!=vcr.slider)
return;
if(mr<2)return;
if(x0>l-2)x0=l-2;
vcr.slipos=x0;
draw_ani_slider(w,x0);
k=x0*mr/l;
vcr.pos=0;
ani_flip1(0);
ani_flip1(k);
}
void redraw_ani_slider()
{
int k=vcr.pos;
int l=48*DCURXs;
int xx;
int mr=my_browser.maxrow;
if(mr<2)return;
xx=(k*l)/mr;
draw_ani_slider(vcr.slider,xx);
}
void draw_ani_slider(Window w,int x)
{
int hgt=DCURYs+4,l=48*DCURXs;
int x0=x-2,i;
if(x0<0)x0=0;
if(x0>(l-4))x0=l-4;
XClearWindow(display,w);
for(i=0;i<4;i++)
XDrawLine(display,w,small_gc,x0+i,0,x0+i,hgt);
}
void ani_expose(w)
Window w;
{
if(vcr.iexist==0)return;
if(w==vcr.wgrab)XDrawString(display,w,small_gc,5,CURY_OFFs,"Grab",4);
if(w==vcr.view)
XCopyArea(display,ani_pixmap,vcr.view,ani_gc,0,0,vcr.wid,vcr.hgt,0,0);
if(w==vcr.wgo)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Go ",4);
if(w==vcr.wup)
XDrawString(display,w,small_gc,5,CURY_OFFs," >>>>",5);
if(w==vcr.wskip)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Skip",4);
if(w==vcr.wdn)
XDrawString(display,w,small_gc,5,CURY_OFFs," <<<<",5);
if(w==vcr.wfast)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Fast",4);
if(w==vcr.wslow)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Slow",4);
if(w==vcr.slider)
draw_ani_slider(w,vcr.slipos);
if(w==vcr.wpause)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Pause",5);
if(w==vcr.wreset)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Reset",5);
if(w==vcr.kill)
XDrawString(display,w,small_gc,5,CURY_OFFs,"Close",5);
if(w==vcr.wfile)
XDrawString(display,w,small_gc,5,CURY_OFFs,"File",4);
if(w==vcr.wmpeg)
XDrawString(display,w,small_gc,5,CURY_OFFs,"MPEG",4);
if(w==vcr.wfly)
check_on_the_fly();
}
void ani_resize(x,y)
int x,y;
{
int ww=x-(2*4);
int hh=y-((2.5*(DCURYs+6))+5);
if(ww==vcr.wid&&hh==vcr.hgt)return;
XFreePixmap(display,ani_pixmap);
vcr.hgt=5*((y-((4.5*(DCURYs+6))+5))/5);
vcr.wid=4*((x-(2*4))/4);
/*This little safety check prevents a <X Error of failed request: BadValue>
from occuring if the user shrinks the window size smaller than the vcr.hgt | vcr.wid
*/
if (vcr.hgt < 1)
vcr.hgt = 1;
if (vcr.wid < 1)
vcr.wid = 1;
XMoveResizeWindow(display,vcr.view,4,4.5*(DCURYs+6),vcr.wid,vcr.hgt);
ani_pixmap= XCreatePixmap(display,RootWindow(display,screen),vcr.wid,vcr.hgt,
DefaultDepth(display,screen));
if(ani_pixmap==0){
err_msg("Failed to get the required pixmap");
XFlush(display);
XDestroySubwindows(display,vcr.base);
XDestroyWindow(display,vcr.base);
vcr.iexist=0;
return;
}
/* XSetFunction(display,ani_gc,GXclear);
XCopyArea(display,ani_pixmap,ani_pixmap,ani_gc,0,0,vcr.wid,vcr.hgt,0,0);
*/
XSetFunction(display,ani_gc,GXcopy);
XSetForeground(display,ani_gc,WhitePixel(display,screen));
XFillRectangle(display,ani_pixmap,ani_gc,0,0,vcr.wid,vcr.hgt);
XSetForeground(display,ani_gc,BlackPixel(display,screen));
tst_pix_draw();
}
void ani_newskip()
{
char bob[20];
Window w;
int rev,status;
XGetInputFocus(display,&w,&rev);
sprintf(bob,"%d",vcr.inc);
status=get_dialog("Frame skip","Increment:",bob,"Ok","Cancel",20);
if(status!=0){
vcr.inc=atoi(bob);
if(vcr.inc<=0)vcr.inc=1;
}
XSetInputFocus(display,w,rev,CurrentTime);
}
void check_on_the_fly()
{
XClearWindow(display,vcr.wfly);
if(animation_on_the_fly)
{
XDrawString(display,vcr.wfly,small_gc,5,1.5*CURY_OFFs,"*",1);
}
}
void on_the_fly(int task)
{
if(vcr.iexist==0||n_anicom==0)return;
ani_frame(task);
waitasec(on_the_fly_speed);
}
void ani_frame(int task)
{
XSetForeground(display,ani_gc,WhitePixel(display,screen));
XFillRectangle(display,ani_pixmap,ani_gc,0,0,vcr.wid,vcr.hgt);
XSetForeground(display,ani_gc,BlackPixel(display,screen));
if(task==1){
set_ani_perm();
reset_comets();
return;
}
/* now draw the stuff */
render_ani();
/* done drawing */
XCopyArea(display,ani_pixmap,vcr.view,ani_gc,0,0,vcr.wid,vcr.hgt,0,0);
XFlush(display);
}
void set_to_init_data()
{
int i;
for(i=0;i<NODE;i++){
last_ic[i]=get_ivar(i+1);
}
for(i=NODE+FIX_VAR;i<NODE+FIX_VAR+NMarkov;i++){
last_ic[i-FIX_VAR]=get_ivar(i+1);
}
redraw_ics();
}
void set_from_init_data()
{
double y[MAXODE];
int i;
for(i=0;i<NODE+NMarkov;i++){
y[i]=last_ic[i];
}
set_fix_rhs(T0,y);
}
void ani_flip1(n)
int n;
{
int row;
float **ss;
double y[MAXODE];
double t;
int i;
if(n_anicom==0)return;
if(my_browser.maxrow<2)return;
ss=my_browser.data;
XSetForeground(display,ani_gc,WhitePixel(display,screen));
XFillRectangle(display,ani_pixmap,ani_gc,0,0,vcr.wid,vcr.hgt);
XSetForeground(display,ani_gc,BlackPixel(display,screen));
if(vcr.pos==0) set_ani_perm();
vcr.pos=vcr.pos+n;
if(vcr.pos>=my_browser.maxrow)
vcr.pos=my_browser.maxrow-1;
if(vcr.pos<0)vcr.pos=0;
row=vcr.pos;
t=(double)ss[0][row];
for(i=0;i<NODE+NMarkov;i++)
y[i]=(double)ss[i+1][row];
set_fix_rhs(t,y);
/* now draw the stuff */
render_ani();
/* done drawing */
XCopyArea(display,ani_pixmap,vcr.view,ani_gc,0,0,vcr.wid,vcr.hgt,0,0);
XFlush(display);
}
void ani_flip()
{
double y[MAXODE];
double t;
char fname[256];
FILE *angiffile=NULL;
float **ss;
int i,row,done;
int mpeg_frame=0,mpeg_write=0,count=0;
XEvent ev;
Window w;
/*Window root;
unsigned int he,wi,bw,d;
int x0,y0;
*/
done=0;
if(n_anicom==0)return;
if(my_browser.maxrow<2)return;
ss=my_browser.data;
set_ani_perm(); /* evaluate all permanent structures */
/* check avi_flags for initialization */
if(mpeg.aviflag==1){
angiffile=fopen("anim.gif","wb");
set_global_map(1);
}
count=0;
while(!done){ /* Ignore all events except the button presses */
if(XPending(display)>0)
{
XNextEvent(display,&ev);
switch(ev.type){
case ButtonPress:
w=ev.xbutton.window;
if(w==vcr.wpause){
done=1;
break;
}
if(w==vcr.wfast){
ani_speed=ani_speed-ani_speed_inc;
if(ani_speed<0)ani_speed=0;
break;
}
if(w==vcr.wslow){
ani_speed=ani_speed+ani_speed_inc;
if(ani_speed>100)ani_speed=100;
break;
}
break;
}
}
/* Okay no events so lets go! */
/* first set all the variables */
XSetForeground(display,ani_gc,WhitePixel(display,screen));
XFillRectangle(display,ani_pixmap,ani_gc,0,0,vcr.wid,vcr.hgt);
XSetForeground(display,ani_gc,BlackPixel(display,screen));
row=vcr.pos;
t=(double)ss[0][row];
for(i=0;i<NODE+NMarkov;i++)
y[i]=(double)ss[i+1][row];
set_fix_rhs(t,y);
/* now draw the stuff */
render_ani();
/* done drawing */
XCopyArea(display,ani_pixmap,vcr.view,ani_gc,0,0,vcr.wid,vcr.hgt,0,0);
XFlush(display);
waitasec(ani_speed);
if(mpeg.aviflag==1||mpeg.flag>0)
waitasec(5*ani_speed);
vcr.pos=vcr.pos+vcr.inc;
if(vcr.pos>=my_browser.maxrow){
done=1;
vcr.pos=0;
reset_comets();
}
/* now check mpeg stuff */
if(mpeg.flag>0&&((mpeg_frame%mpeg.skip)==0)){
sprintf(fname,"%s_%d.ppm",mpeg.root,mpeg_write);
mpeg_write++;
writeframe(fname,ani_pixmap,vcr.wid,vcr.hgt);
}
mpeg_frame++;
/* now check AVI stuff */
if(mpeg.aviflag==1)
/* add_ani_gif(ani_pixmap,angiffile,count); */
{
add_ani_gif(vcr.view,angiffile,count);
}
count++;
}
/* always stop mpeg writing */
mpeg.flag=0;
if(mpeg.aviflag==1){
end_ani_gif(angiffile);
fclose(angiffile);
set_global_map(0);
}
}
void ani_disk_warn()
{
unsigned int total=(my_browser.maxrow*vcr.wid*vcr.hgt*3)/(mpeg.skip*vcr.inc);
char junk[256];
char ans;
total=total/(1024*1024);
if(total>10){
sprintf(junk," %d Mb disk space needed! Continue?",total);
ans=(char)TwoChoice("YES","NO",junk,"yn");
if(ans!='y')mpeg.flag=0;
}
}
int getppmbits(Window window,int *wid,int *hgt, unsigned char *out)
{
XImage *ximage;
Colormap cmap;
unsigned long value;
int i;
int CMSK=0,CSHIFT=0,CMULT=0;
int bbp=0,bbc=0;
int lobits,midbits,hibits;
/*int vv; Not used anywhere?*/
unsigned x,y;
XColor palette[256];
XColor pix;
unsigned char *dst,*pixel;
cmap = DefaultColormap(display,screen);
ximage=XGetImage(display,window,0,0,*wid,*hgt,AllPlanes,ZPixmap);
if(!ximage){
return -1;
}
/* this is only good for 256 color displays */
for(i = 0; i < 256; i++)
palette[i].pixel = i;
XQueryColors(display,
cmap,
palette,
256);
if(TrueColorFlag==1){
bbp=ximage->bits_per_pixel; /* is it 16 or 24 bit */
if(bbp>24)bbp=24;
bbc=bbp/3; /* divide up the 3 colors equally to bbc bits */