00001
00002
00003 #define MODULE_UTILS 1
00004
00005 #include "animate.h"
00006
00007 void Nudge(int command){
00008 int sx,sy,step=1,grabbed=0;
00009 if(tool == GRABBER || tool == NOTOOL){
00010 GetWindowCoords(ActiveView,NpointerX,NpointerY,NpointerZ,&sx,&sy);
00011 if(tool == GRABBER)grabbed=StageGrabIdentify();
00012 if(GetAsyncKeyState(VK_SHIFT ) & 0x8000)step=5;
00013 if(command == IDM_PAN_LEFT) sx -= step;
00014 if(command == IDM_PAN_RIGHT)sx += step;
00015 if(command == IDM_PAN_UP) sy -= step;
00016 if(command == IDM_PAN_DOWN) sy += step;
00017 Draw3dCursor();
00018 GetWorldCoords(ActiveView,&NpointerX,&NpointerY,&NpointerZ,sx,sy);
00019 Draw3dCursor();
00020 if(coords_visible)UpdateRuler(0);
00021 if(tool == GRABBER && grabbed == 1)StageGrab(2,1);
00022 }
00023 if(tool == ROTATOR){
00024 BOOL do_it=FALSE;
00025 if(command == IDM_PAN_LEFT){
00026 do_it=TRUE;
00027 if (ActiveView == TRIRIGHT)command=IDM_PAN_UP;
00028 else if(ActiveView == TRIFRONT)command=IDM_ZOOM_OUT;
00029 else command=IDM_PAN_RIGHT;
00030 }
00031 else if(command == IDM_PAN_RIGHT){
00032 do_it=TRUE;
00033 if (ActiveView == TRIRIGHT)command=IDM_PAN_DOWN;
00034 else if(ActiveView == TRIFRONT)command=IDM_ZOOM_IN;
00035 else command=IDM_PAN_LEFT;
00036 }
00037 if(do_it)StageStepRotate(command);
00038 }
00039 }
00040
00041 void ReleaseNurbs(nurbs *n){
00042 long i;
00043 if(n->kvU != NULL)X__Free(n->kvU);
00044 n->kvU = NULL;
00045 if(n->kvV != NULL)X__Free(n->kvV);
00046 n->kvV = NULL;
00047 if(n->points == NULL)return;
00048 for(i=0;i < n->numV;i++)X__Free(n->points[i]);
00049 X__Free(n->points);
00050 n->points=NULL;
00051 return;
00052 }
00053
00054 BOOL AllocNurbs(nurbs *n, double *ukv, double *vkv){
00055 long i;
00056 if(ukv == NULL){
00057 if((n->kvU = (double *)X__Malloc((n->numU + n->orderU) * sizeof(double)))
00058 == NULL)return FALSE;
00059 }
00060 else n->kvU = ukv;
00061 if(vkv == NULL){
00062 if((n->kvV = (double *)X__Malloc((n->numV + n->orderV) * sizeof(double)))
00063 == NULL)return FALSE;
00064 }
00065 else n->kvV = vkv;
00066 if((n->points = (vector4 **)X__Malloc((long)n->numV
00067 * (long)sizeof(vector4 *))) == NULL)return FALSE;
00068 for (i = 0; i < n->numV; i++){
00069 if((n->points[i] = (vector4 *)X__Malloc((long)n->numU
00070 * (long)sizeof(vector4))) == NULL)return FALSE;
00071 }
00072 return TRUE;
00073 }
00074
00075 void FreeNurbs(long n, nurbs *Np){
00076 long i;
00077 if(n == 0 || Np == NULL)return;
00078 for(i=0;i<n;i++){
00079 ReleaseNurbs((Np+i));
00080 }
00081 X__Free(Np);
00082 return;
00083 }
00084
00085 pathpoint *AppendPathPoint(pathpoint *Ppp){
00086
00087
00088 pathpoint *tp;
00089 EDIT_ACTION=YES;
00090 if((tp = (pathpoint *)X__Malloc(sizeof(pathpoint))) == NULL){
00091 SendPrgmQuery(IDQ_NOMEM1,0);
00092 return NULL;
00093 }
00094 if(Ppp != NULL)Ppp->next=tp;
00095 tp->last=Ppp;
00096 tp->next=NULL;
00097 return tp;
00098 }
00099
00100 PATHEDITCONTROL *CreatePathEditControlPoint(int *nPec,
00101 PATHEDITCONTROL **Pec,
00102 PATHEDITCONTROL *last,
00103 PATHEDITCONTROL *next,
00104 int frame, double distance){
00105 PATHEDITCONTROL *temp,*pe,*pe1;
00106 if((temp=(PATHEDITCONTROL *)X__Malloc(sizeof(PATHEDITCONTROL))) == NULL){
00107 if((*Pec) != NULL){
00108 if((pe = *Pec) != NULL)while(pe != NULL){
00109 pe1=pe; pe=pe->next; X__Free(pe1);
00110 }
00111 }
00112 *nPec=0;
00113 *Pec=NULL;
00114 return NULL;
00115 }
00116 if(*Pec == NULL)*Pec=temp;
00117 temp->last=last; if(last != NULL)last->next=temp;
00118 temp->next=next; if(next != NULL)next->last=temp;
00119 temp->frame=frame;
00120 temp->distance=distance;
00121 temp->x=0; temp->y=0;
00122 *nPec = (*nPec)+1;
00123 return temp;
00124 }
00125
00126 void DeletePathEditControlPoint(int *nPec,
00127 PATHEDITCONTROL **Pec,
00128 PATHEDITCONTROL *here){
00129 if(here->last != NULL)here->last->next=here->next;
00130 if(here->next != NULL)here->next->last=here->last;
00131 if(here == *Pec){
00132 *Pec=here->next;
00133 }
00134 X__Free(here);
00135 *nPec = (*nPec)-1;
00136 return;
00137 }
00138
00139 void CreatePathPoint(void){
00140 int j;
00141 pathpoint *sp,*tp;
00142 EDIT_ACTION=YES;
00143 if(SelectedNode == NULL){
00144 SendPrgmQuery(IDQ_NOPATH,0);
00145 return;
00146 }
00147 if(SelectedPath == NULL || (sp=SelectedPathPoint) == NULL){
00148 ;
00149 return;
00150 }
00151 DrawInvertNode(ghdc_triview_Bitmap,SelectedNode,EDITING);
00152 if(sp->next == NULL){
00153 SendPrgmQuery(IDQ_PATH4,0);
00154 }
00155 else if((tp = (pathpoint *)X__Malloc(sizeof(pathpoint))) == NULL){
00156 SendPrgmQuery(IDQ_NOMEM1,0);
00157 }
00158 else{
00159 tp->last=sp;
00160 tp->next=sp->next;
00161 sp->next->last=tp;
00162 sp->next=tp;
00163 for(j=0;j<3;j++){
00164 tp->p[j]=(sp->p[j] + tp->next->p[j])/2;
00165 }
00166 tp->ptheta = (sp->ptheta + tp->next->ptheta)/2.0;
00167 tp->pfi = (sp->pfi + tp->next->pfi )/2.0;
00168 tp->distance=sp->distance+1.0;
00169 tp->tension_n=sp->tension_p;
00170 tp->tension_p=sp->tension_n;
00171 tp->status=sp->status;
00172 SelectedPath->npathpoints++;
00173 }
00174 SelectedPathPoint=NULL;
00175 DrawInvertNode(ghdc_triview_Bitmap,SelectedNode,EDITING);
00176 }
00177
00178 void DeletePathPoint(void){
00179 pathpoint *tp;
00180 EDIT_ACTION=YES;
00181 if(SelectedNode == NULL){
00182 SendPrgmQuery(IDQ_NOPATH,0);
00183 return;
00184 }
00185 else if(SelectedPath == NULL)return;
00186 DrawInvertNode(ghdc_triview_Bitmap,SelectedNode,EDITING);
00187 if(SelectedPath->pathtype == CLOSED && SelectedPath->npathpoints < 4){
00188 SendPrgmQuery(IDQ_PATH5,0);
00189 }
00190 else if((tp=SelectedPathPoint) == NULL){
00191 ;
00192 }
00193 else if(tp->next == NULL || tp->last == NULL){
00194 SendPrgmQuery(IDQ_PATH6,0);
00195 }
00196 else{
00197 tp->next->last = tp->last;
00198 tp->last->next = tp->next;
00199 X__Free(tp);
00200 SelectedPath->npathpoints--;
00201 }
00202 SelectedPathPoint=NULL;
00203 DrawInvertNode(ghdc_triview_Bitmap,SelectedNode,EDITING);
00204 }
00205
00206 pathpoint *CreateIPointPath(short type, node *Np, short firstframe,
00207 short *pathtype, short *npathpoints){
00208 pathpoint *temp1,*temp2,*temp3,*tp,*sp;
00209 object *Op;
00210 long lpx,lpy,lpz,fpx,fpy,fpz;
00211 HWND hwnd;
00212 EDIT_ACTION=YES;
00213 if((hwnd=GetFocus()) != ghwnd_main)hwnd=ghwndTimeline;
00214 if (type == LOADED){
00215 return LoadPath(pathtype,npathpoints,hwnd);
00216 }
00217 else if(type == COPIED)
00218 return CopyPath(pathtype,npathpoints,Np,firstframe,hwnd);
00219 *pathtype=type;
00220 if((temp1 = (pathpoint *)X__Malloc(sizeof(pathpoint))) == NULL){
00221 SendPrgmQuery(IDQ_NOMEM1,0);
00222 return NULL;
00223 }
00224 if((temp2 = (pathpoint *)X__Malloc(sizeof(pathpoint))) == NULL){
00225 SendPrgmQuery(IDQ_NOMEM1,0);
00226 X__Free(temp1); return NULL;
00227 }
00228 if(type == CLOSED){
00229 if((temp3 = (pathpoint *)X__Malloc(sizeof(pathpoint))) == NULL){
00230 SendPrgmQuery(IDQ_NOMEM1,0);
00231 X__Free(temp1); X__Free(temp2); return NULL;
00232 }
00233 }
00234 fpx=NpointerX; fpy=NpointerY; fpz=NpointerZ;
00235 lpx=NpointerX; lpy=NpointerY+TVsizeY; lpz=NpointerZ;
00236 if((Op=Np->fobj) != NULL)while(Op != NULL){
00237 if(Op->lastframe >= firstframe){
00238 if(Op->last != NULL){
00239 if(Op->last->pathtype == CLOSED)sp=Op->last->firstpathpoint;
00240 else{
00241 sp=NULL;
00242 if((tp=Op->last->firstpathpoint) != NULL)while(tp!=NULL){
00243 sp=tp;
00244 tp=tp->next;
00245 }
00246 }
00247 if(sp!=NULL){
00248 fpx=sp->p[0]; fpy=sp->p[1]; fpz=sp->p[2];
00249 lpx=NpointerX; lpy=NpointerY; lpz=NpointerZ;
00250 }
00251 }
00252 break;
00253 }
00254 Op=Op->next;
00255 }
00256 if(type == OPEN){
00257 temp1->last=NULL;
00258 temp1->next=temp2;
00259 temp2->last=temp1;
00260 temp2->next=NULL;
00261 temp1->ptheta=0; temp1->pfi=0;
00262 temp2->ptheta=0; temp2->pfi=0;
00263 temp1->p[0]=fpx; temp1->p[1]=fpy; temp1->p[2]=fpz;
00264 temp2->p[0]=lpx; temp2->p[1]=lpy; temp2->p[2]=lpz;
00265 temp1->distance=0.0;
00266 temp2->distance=0.0;
00267 temp1->status=temp2->status=0;
00268 temp1->tension_n=temp2->tension_n=0.5;
00269 temp1->tension_p=temp2->tension_p=0.5;
00270 *npathpoints=2;
00271 }
00272 else if(type ==CLOSED){
00273 temp1->last=NULL;
00274 temp1->next=temp2;
00275 temp2->last=temp1;
00276 temp2->next=temp3;
00277 temp3->last=temp2;
00278 temp3->next=NULL;
00279 temp1->ptheta=0; temp1->pfi=0;
00280 temp2->ptheta=0; temp2->pfi=0;
00281 temp3->ptheta=0; temp3->pfi=0;
00282 temp1->p[0]=fpx; temp1->p[1]=fpy; temp1->p[2]=fpz;
00283 temp2->p[0]=fpx+TVsizeX; temp2->p[1]=fpy+TVsizeY; temp2->p[2]=fpz;
00284 temp3->p[0]=fpx-TVsizeX; temp3->p[1]=fpy+TVsizeY; temp3->p[2]=fpz;
00285 temp1->distance=0.0;temp2->distance=0.0; temp3->distance=0.0;
00286 temp1->tension_n=temp2->tension_n=temp3->tension_n=0.5;
00287 temp1->tension_p=temp2->tension_p=temp3->tension_p=0.5;
00288 temp1->status=temp2->status=temp3->status=0;
00289 *npathpoints=3;
00290 }
00291 return temp1;
00292 }
00293
00294 void DeleteCostume(node *Np, long frame){
00295 object *temp;
00296 pathpoint *pp,*pp1;
00297 PATHEDITCONTROL *pe,*pe1;
00298 temp=Np->fobj;
00299 while(temp != NULL){
00300 if((temp->firstframe <= frame) && (temp->lastframe >= frame)){
00301 EDIT_ACTION=YES;
00302 if(temp->fileID >= 0)DeleteRamFile(temp->fileID, temp);
00303 if((pp=temp->firstpathpoint) != NULL){
00304 if(SelectedPath == temp){
00305 SelectedPath=NULL;
00306 SelectedPathPoint=NULL;
00307 }
00308 while(pp != NULL){
00309 pp1=pp; pp=pp->next; X__Free(pp1);
00310 }
00311 }
00312 if(temp->v != NULL)X__Free(temp->v);
00313 if((pe=temp->pec) != NULL)while(pe != NULL){
00314 pe1=pe; pe=pe->next; X__Free(pe1);}
00315 DeleteEffect(temp);
00316 if(temp->xip == NULL)X__Free(temp->xip); temp->xip=NULL;
00317 UnloadRamImage(&(temp->image));
00318 if(temp->next != NULL)temp->next->last = temp->last;
00319 if(temp->last != NULL)temp->last->next = temp->next;
00320 else Np->fobj=temp->next;
00321 X__Free(temp);
00322 return;
00323 }
00324 temp=temp->next;}
00325 }
00326
00327 object *CreateCostume(node *Np, long firstframe, long lastframe){
00328 object *temp,*p,*q;
00329 short ff,lf;
00330 int i;
00331 EDIT_ACTION=YES;
00332 ff=min(firstframe,lastframe);
00333 lf=max(firstframe,lastframe);
00334 if((temp = (object *)X__Malloc(sizeof(object))) == NULL){
00335 SendPrgmQuery(IDQ_NOMEM1,0);
00336 fail_op=YES; return NULL;
00337 }
00338 p=Np->fobj; q=NULL;
00339 LOOP:
00340 if(p != NULL){
00341 if(((lf >= p->firstframe) && (lf <= p->lastframe))
00342 ||((ff >= p->firstframe) && (ff <= p->lastframe))
00343 ||((ff <= p->firstframe) && (lf >= p->lastframe))){
00344 if((ff < p->firstframe) && (lf > p->lastframe))fail_op=YES;
00345 X__Free(temp); return NULL;}
00346 else if(lf < p->firstframe){
00347 temp->next=p;
00348 if(p->last == NULL)Np->fobj = temp;
00349 else p->last->next=temp;
00350 temp->last = p->last;
00351 p->last=temp;
00352 goto END;
00353 }
00354 q=p; p=p->next;
00355 goto LOOP;
00356 }
00357 else{
00358 if(q == NULL)Np->fobj=temp;
00359 else q->next=temp;
00360 temp->last=q;
00361 temp->next=NULL;
00362 goto END;
00363 }
00364 goto LOOP;
00365 END:
00366 temp->name[0]='\0';
00367 temp->firstframe = ff;
00368 temp->lastframe = lf;
00369 temp->type = Np->type;
00370 temp->quick_only=0;
00371 temp->fileID = -1;
00372 temp->npathpoints=0;
00373 temp->origin[0]=0; temp->origin[1]=0; temp->origin[2]=0;
00374 temp->offset[0]=0; temp->offset[1]=0; temp->offset[2]=0;
00375 temp->colour[0]=0;
00376 temp->colour[1]=255;
00377 temp->colour[2]=0;
00378 temp->acolour[0]=0;
00379 temp->acolour[1]=128;
00380 temp->acolour[2]=0;
00381 temp->morph=NO;
00382 temp->morphNo=0;
00383 temp->xip=NULL;
00384 temp->effect=NULL;
00385 temp->edges=NULL;
00386 temp->points=NULL;
00387 temp->skeleton=NULL;
00388 temp->w_frame.Np=temp->w_frame.Ne=0;
00389 temp->w_frame.e=NULL; temp->w_frame.p=NULL;
00390 temp->skid=NULL;
00391 temp->npoints=0;
00392 temp->nskeleton=0;
00393 temp->nedges=0;
00394 temp->in_ram=0;
00395 temp->bWireframe=0;
00396 temp->pathtype = -1;
00397 temp->groundtype=0;
00398 temp->lighttype =0;
00399 temp->light_intensity=1.0;
00400 temp->depth_cue=0;
00401 temp->depth_cue_c=1.0;
00402 temp->depth_cue_l=1.0;
00403 temp->depth_cue_q=0.0;
00404 temp->self_shadow=1;
00405 temp->cast_shadow=1;
00406 temp->show_shadow=1;
00407 temp->firstpathpoint = NULL;
00408 temp->pec=NULL;
00409 temp->npec=0;
00410 temp->v=NULL;
00411 temp->pathlength=0.0;
00412 temp->gspec=temp->gtran=temp->grefl=temp->gbump=0.0;
00413 temp->hEffect=NULL;
00414 temp->effectname[0]=0;
00415 temp->Nurbs=NULL;
00416 temp->nNurbs=0;
00417 temp->bIKchain=FALSE;
00418 InitialiseRamImage(&(temp->image));
00419 memset(&(temp->particles),0,sizeof(ParticleSystem));
00420 InitialiseParticleSystem(&(temp->particles));
00421 temp->groundTemperature=0.0;
00422 for(i=0;i<8;i++)temp->other_params[i]=0.0;
00423 return temp;
00424 }
00425
00426 void DeleteSize(node *Np, long frame){
00427 size *temp;
00428 EDIT_ACTION=YES;
00429 temp=Np->fsiz;
00430 while(temp != NULL){
00431 if((temp->firstframe <= frame) && (temp->lastframe >= frame)){
00432 if(temp->next != NULL)temp->next->last = temp->last;
00433 if(temp->last != NULL)temp->last->next = temp->next;
00434 else Np->fsiz=temp->next;
00435 X__Free(temp);
00436 return;
00437 }
00438 temp=temp->next;
00439 }
00440 }
00441
00442 static void SetDefaultCameraParams(cameraparam *c){
00443 c->f_number = 4;
00444 c->focal_length = 10;
00445 c->focus_distance = 10;
00446 c->polarn_angle = 0;
00447 c->polar_type = 0;
00448 c->stereo_separation = 0.1;
00449 c->parallax_distance = 100.0;
00450 }
00451
00452 size *CreateSize(node *Np, long firstframe, long lastframe){
00453 size *temp,*p,*q;
00454 short ff,lf;
00455 EDIT_ACTION=YES;
00456 ff=min(firstframe,lastframe);
00457 lf=max(firstframe,lastframe);
00458 if((temp = (size *)X__Malloc(sizeof(size))) == NULL){
00459 SendPrgmQuery(IDQ_NOMEM1,0);
00460 fail_op=YES; return NULL;
00461 }
00462 p=Np->fsiz; q=NULL;
00463 LOOP:
00464 if(p != NULL){
00465 if(((lf >= p->firstframe) && (lf <= p->lastframe))
00466 ||((ff >= p->firstframe) && (ff <= p->lastframe))
00467 ||((ff <= p->firstframe) && (lf >= p->lastframe))){
00468 if((ff < p->firstframe) && (lf > p->lastframe))fail_op=YES;
00469 X__Free(temp); return NULL;}
00470 else if(lf < p->firstframe){
00471 temp->next=p;
00472 if(p->last == NULL)Np->fsiz = temp;
00473 else p->last->next=temp;
00474 temp->last = p->last;
00475 p->last=temp;
00476 goto END;
00477 }
00478 q=p; p=p->next;
00479 goto LOOP;
00480 }
00481 else{
00482 if(q == NULL)Np->fsiz=temp;
00483 else q->next=temp;
00484 temp->last=q;
00485 temp->next=NULL;
00486 goto END;
00487 }
00488 goto LOOP;
00489 END:
00490 temp->firstframe=ff;
00491 temp->lastframe=lf;
00492 temp->tweentype=0;
00493 temp->tension_s=0.5;
00494 temp->tension_e=0.5;
00495 temp->easin=1.0;
00496 temp->easout=1.0;
00497 if(temp->last == NULL){
00498 if(Np->type == LIGHT){
00499 temp->Sx=15; temp->Sy=5; temp->Sz=1;
00500 }
00501 else{
00502 temp->Sx=1; temp->Sy=1; temp->Sz=1;
00503 }
00504 if(Np->type == CAMERA)SetDefaultCameraParams(&(temp->camera_params));
00505 }
00506 else{
00507 temp->Sx=temp->last->Sx;
00508 temp->Sy=temp->last->Sy;
00509 temp->Sz=temp->last->Sz;
00510 if(Np->type == CAMERA)memcpy(&(temp->camera_params),&(temp->last->camera_params),sizeof(cameraparam));
00511 }
00512 return temp;
00513 }
00514
00515 void DeleteAlign(node *Np, long frame){
00516 align *temp;
00517 EDIT_ACTION=YES;
00518 temp=Np->fali;
00519 while(temp != NULL){
00520 if((temp->firstframe <= frame) && (temp->lastframe >= frame)){
00521 if(temp->next != NULL)temp->next->last = temp->last;
00522 if(temp->last != NULL)temp->last->next = temp->next;
00523 else Np->fali=temp->next;
00524 X__Free(temp);
00525 return;
00526 }
00527 temp=temp->next;}
00528 }
00529
00530 align *CreateAlign(node *Np, long firstframe, long lastframe){
00531 align *temp,*p,*q;
00532 short ff,lf;
00533 EDIT_ACTION=YES;
00534 ff=min(firstframe,lastframe);
00535 lf=max(firstframe,lastframe);
00536 if((temp = (align *)X__Malloc(sizeof(align))) == NULL){
00537 SendPrgmQuery(IDQ_NOMEM1,0);
00538 fail_op=YES; return NULL;
00539 }
00540 p=Np->fali; q=NULL;
00541 LOOP:
00542 if(p != NULL){
00543 if(((lf >= p->firstframe) && (lf <= p->lastframe))
00544 ||((ff >= p->firstframe) && (ff <= p->lastframe))
00545 ||((ff <= p->firstframe) && (lf >= p->lastframe))){
00546 if((ff < p->firstframe) && (lf > p->lastframe))fail_op=YES;
00547 X__Free(temp); return NULL;}
00548 else if(lf < p->firstframe){
00549 temp->next=p;
00550 if(p->last == NULL)Np->fali = temp;
00551 else p->last->next=temp;
00552 temp->last = p->last;
00553 p->last=temp;
00554 goto END;
00555 }
00556 q=p; p=p->next;
00557 goto LOOP;
00558 }
00559 else{
00560 if(q == NULL)Np->fali=temp;
00561 else q->next=temp;
00562 temp->last=q;
00563 temp->next=NULL;
00564 goto END;
00565 }
00566 goto LOOP;
00567 END:
00568 temp->type=TWEEN;
00569 temp->firstframe=ff;
00570 temp->lastframe=lf;
00571 temp->topath=NULL;
00572 temp->tension_s=0.5;
00573 temp->tension_e=0.5;
00574 temp->easin=1.0;
00575 temp->easout=1.0;
00576 if(temp->last == NULL){
00577 temp->theta=0;
00578 temp->phi=0;
00579 temp->alpha=0;
00580 temp->im=0;
00581 temp->ima= -1.0;
00582 }
00583 else{
00584 temp->theta=temp->last->theta;
00585 temp->phi=temp->last->phi;
00586 temp->alpha=temp->last->alpha;
00587 temp->im=temp->last->im;
00588 temp->ima=temp->last->ima;
00589 }
00590 return temp;
00591 }
00592
00593 void DeletePosition(node *Np, long frame){
00594 position *temp;
00595 EDIT_ACTION=YES;
00596 temp=Np->fpos;
00597 while(temp != NULL){
00598 if((temp->firstframe <= frame) && (temp->lastframe >= frame)){
00599 if(temp->next != NULL)temp->next->last = temp->last;
00600 if(temp->last != NULL)temp->last->next = temp->next;
00601 else Np->fpos=temp->next;
00602 X__Free(temp);
00603 return;
00604 }
00605 temp=temp->next;}
00606 }
00607
00608 void DeletePositionIn(node *Np, long first_frame, long last_frame){
00609 int i;
00610 for(i=first_frame;i<=last_frame;i++)DeletePosition(Np,i);
00611 }
00612
00613 position *CreatePosition(node *Np, long firstframe, long lastframe){
00614 position *temp,*p,*q;
00615 short ff,lf;
00616 EDIT_ACTION=YES;
00617 ff=min(firstframe,lastframe);
00618 lf=max(firstframe,lastframe);
00619 if((temp = (position *)X__Malloc(sizeof(position))) == NULL){
00620 SendPrgmQuery(IDQ_NOMEM1,0);
00621 fail_op=YES; return NULL;
00622 }
00623 p=Np->fpos; q=NULL;
00624 LOOP:
00625 if(p != NULL){
00626 if(((lf >= p->firstframe) && (lf <= p->lastframe))
00627 ||((ff >= p->firstframe) && (ff <= p->lastframe))
00628 ||((ff <= p->firstframe) && (lf >= p->lastframe))){
00629 if((ff < p->firstframe) && (lf > p->lastframe))fail_op=YES;
00630 X__Free(temp); return NULL;}
00631 else if(lf < p->firstframe){
00632 temp->next=p;
00633 if(p->last == NULL)Np->fpos = temp;
00634 else p->last->next=temp;
00635 temp->last = p->last;
00636 p->last=temp;
00637 goto END;
00638 }
00639 q=p; p=p->next;
00640 goto LOOP;
00641 }
00642 else{
00643 if(q == NULL)Np->fpos=temp;
00644 else q->next=temp;
00645 temp->last=q;
00646 temp->next=NULL;
00647 goto END;
00648 }
00649 goto LOOP;
00650 END:
00651 temp->type=TWEEN;
00652 temp->firstframe=ff;
00653 temp->lastframe=lf;
00654 temp->onpath=NULL;
00655 temp->tension_s=0.5;
00656 temp->tension_e=0.5;
00657 temp->easin=1.0;
00658 temp->easout=1.0;
00659 temp->fx=0; temp->fy=0; temp->fz=0;
00660 if(Np->type == TARGET){
00661 temp->finish[0]=NpointerX;
00662 temp->finish[1]=NpointerY;
00663 temp->finish[2]=NpointerZ;
00664 }
00665 else if(temp->last == NULL){
00666 temp->finish[0]=0;
00667 temp->finish[1]=0;
00668 temp->finish[2]=0;
00669 }
00670 else{
00671 temp->finish[0]=temp->last->finish[0];
00672 temp->finish[1]=temp->last->finish[1];
00673 temp->finish[2]=temp->last->finish[2];
00674 }
00675 return temp;
00676 }
00677
00678 void DeleteSky(node *Np, long frame){
00679 sky *temp;
00680 EDIT_ACTION=YES;
00681 temp=Np->fsky;
00682 while(temp != NULL){
00683 if((temp->firstframe <= frame) && (temp->lastframe >= frame)){
00684 if(temp->next != NULL)temp->next->last = temp->last;
00685 if(temp->last != NULL)temp->last->next = temp->next;
00686 else Np->fsky=temp->next;
00687 UnloadRamImage(&(temp->image));
00688 X__Free(temp);
00689 return;
00690 }
00691 temp=temp->next;}
00692 }
00693
00694 sky *CreateSky(node *Np, long firstframe, long lastframe){
00695 int i;
00696 sky *temp,*p,*q;
00697 short ff,lf;
00698 EDIT_ACTION=YES;
00699 ff=min(firstframe,lastframe);
00700 lf=max(firstframe,lastframe);
00701 if((temp = (sky *)X__Malloc(sizeof(sky))) == NULL){
00702 SendPrgmQuery(IDQ_NOMEM1,0);
00703 fail_op=YES; return NULL;
00704 }
00705 p=Np->fsky; q=NULL;
00706 LOOP:
00707 if(p != NULL){
00708 if(((lf >= p->firstframe) && (lf <= p->lastframe))
00709 ||((ff >= p->firstframe) && (ff <= p->lastframe))
00710 ||((ff <= p->firstframe) && (lf >= p->lastframe))){
00711 if((ff < p->firstframe) && (lf > p->lastframe))fail_op=YES;
00712 X__Free(temp); return NULL;}
00713 else if(lf < p->firstframe){
00714 temp->next=p;
00715 if(p->last == NULL)Np->fsky = temp;
00716 else p->last->next=temp;
00717 temp->last = p->last;
00718 p->last=temp;
00719 goto END;
00720 }
00721 q=p; p=p->next;
00722 goto LOOP;
00723 }
00724 else{
00725 if(q == NULL)Np->fsky=temp;
00726 else q->next=temp;
00727 temp->last=q;
00728 temp->next=NULL;
00729 goto END;
00730 }
00731 goto LOOP;
00732 END:
00733 temp->firstframe=ff;
00734 temp->lastframe=lf;
00735 temp->colour[0]=128;
00736 temp->colour[1]=60;
00737 temp->colour[2]=60;
00738 temp->zcolour[0]=0;
00739 temp->zcolour[1]=128;
00740 temp->zcolour[2]=255;
00741 temp->type=0;
00742 temp->gamb=0.08; temp->oamb=0.1;
00743 temp->gamb_colour[0]=temp->gamb_colour[1]=temp->gamb_colour[2]=0.08;
00744 temp->oamb_colour[0]=temp->oamb_colour[1]=temp->oamb_colour[2]=0.08;
00745 temp->aff=1; temp->alf=9999; temp->ast=1;
00746 for(i=0;i<32;i++)temp->sky_params[i]=0.0;
00747 temp->sky_params[0]=15.0;
00748 temp->sky_params[1]=50.0;
00749 strcpy(temp->sky_params_file,"<none>");
00750 InitialiseRamImage(&(temp->image));
00751 return temp;
00752 }
00753
00754 void DeleteDirector(node *Np, long frame){
00755 director *temp;
00756 EDIT_ACTION=YES;
00757 temp=Np->fdirector;
00758 while(temp != NULL){
00759 if((temp->firstframe <= frame) && (temp->lastframe >= frame)){
00760 if(temp->next != NULL)temp->next->last = temp->last;
00761 if(temp->last != NULL)temp->last->next = temp->next;
00762 else Np->fdirector=temp->next;
00763 X__Free(temp);
00764 return;
00765 }
00766 temp=temp->next;}
00767 }
00768
00769 director *CreateDirector(node *Np, long firstframe, long lastframe){
00770 director *temp,*p,*q;
00771 short ff,lf;
00772 EDIT_ACTION=YES;
00773 ff=min(firstframe,lastframe);
00774 lf=max(firstframe,lastframe);
00775 if((temp = (director *)X__Malloc(sizeof(sky))) == NULL){
00776 SendPrgmQuery(IDQ_NOMEM1,0);
00777 fail_op=YES; return NULL;
00778 }
00779 p=Np->fdirector; q=NULL;
00780 LOOP:
00781 if(p != NULL){
00782 if(((lf >= p->firstframe) && (lf <= p->lastframe))
00783 ||((ff >= p->firstframe) && (ff <= p->lastframe))
00784 ||((ff <= p->firstframe) && (lf >= p->lastframe))){
00785 if((ff < p->firstframe) && (lf > p->lastframe))fail_op=YES;
00786 X__Free(temp); return NULL;}
00787 else if(lf < p->firstframe){
00788 temp->next=p;
00789 if(p->last == NULL)Np->fdirector = temp;
00790 else p->last->next=temp;
00791 temp->last = p->last;
00792 p->last=temp;
00793 goto END;
00794 }
00795 q=p; p=p->next;
00796 goto LOOP;
00797 }
00798 else{
00799 if(q == NULL)Np->fdirector=temp;
00800 else q->next=temp;
00801 temp->last=q;
00802 temp->next=NULL;
00803 goto END;
00804 }
00805 goto LOOP;
00806 END:
00807 temp->firstframe=ff;
00808 temp->lastframe=lf;
00809 temp->type=0;
00810 temp->ActiveCamera=FirstNp;
00811 return temp;
00812 }
00813
00814 void DeleteNode(node *Np){
00815 sky *Sp,*tSp;
00816 object *Op,*tOp;
00817 position *Pp,*tPp;
00818 director *Dp,*tDp;
00819 align *Ap,*tAp;
00820 size *Zp,*tZp;
00821 node *oldNp;
00822 if(Np == NULL)return;
00823 EDIT_ACTION=YES;
00824 oldNp=Np;
00825 if((Sp = Np->fsky) != NULL)while(Sp != NULL){
00826 DeleteSky(Np,Sp->lastframe);
00827 Sp=Np->fsky;
00828
00829 }
00830 if((Dp = Np->fdirector) != NULL)while(Dp != NULL){
00831 tDp=Dp->next; X__Free(Dp); Dp=tDp;}
00832 if((Op = Np->fobj) != NULL)while(Op != NULL){
00833 DeleteCostume(Np,Op->lastframe);
00834 Op=Np->fobj;
00835 }
00836 if((Pp = Np->fpos) != NULL)while(Pp != NULL){
00837 tPp=Pp->next; X__Free(Pp); Pp=tPp;}
00838 if((Ap = Np->fali) != NULL)while(Ap != NULL){
00839 tAp=Ap->next; X__Free(Ap); Ap=tAp;}
00840 if((Zp = Np->fsiz) != NULL)while(Zp != NULL){
00841 tZp=Zp->next; X__Free(Zp); Zp=tZp;}
00842 if(Np->last != NULL)Np->last->next=Np->next;
00843 if(Np->next != NULL)Np->next->last=Np->last;
00844 if(Np == MainNp )MainNp = Np->last;
00845 if(Np == FirstNp)FirstNp = Np->next;
00846 Nnodes--;
00847 X__Free(Np);
00848
00849
00850
00851
00852 if((Np=FirstNp) != NULL)while(Np != NULL){
00853 if((Pp=Np->fpos) != NULL)while(Pp != NULL){
00854 if(Pp->onpath == oldNp){Pp->onpath=NULL; Pp->type = TWEEN;}
00855 Pp=Pp->next;
00856 }
00857 if((Ap=Np->fali) != NULL)while(Ap != NULL){
00858 if(Ap->topath == oldNp){Ap->topath=NULL; Ap->type = TWEEN;}
00859 Ap=Ap->next;
00860 }
00861
00862
00863 if(Np->type == DIRECTOR){
00864 if((Dp=Np->fdirector) != NULL)while(Dp != NULL){
00865 if(Dp->ActiveCamera == oldNp)Dp->ActiveCamera=FirstNp;
00866 Dp=Dp->next;
00867 }
00868 }
00869 Np=Np->next;
00870 }
00871 }
00872
00873 node *CreateNode(void){
00874 node *temp;
00875 if((temp = (node *)X__Malloc(sizeof(node))) == NULL){
00876 SendPrgmQuery(IDQ_NOMEM1,0);
00877 return NULL;
00878 }
00879 EDIT_ACTION=YES;
00880 if(MainNp == NULL)FirstNp=temp;
00881 else MainNp->next=temp;
00882 temp->last=MainNp;
00883 temp->next=NULL;
00884 temp->fsky=NULL;
00885 temp->fdirector=NULL;
00886 temp->fobj=NULL;
00887 temp->fpos=NULL;
00888 temp->fali=NULL;
00889 temp->fsiz=NULL;
00890 temp->type=-1;
00891 temp->ID=MaxNodeID++;
00892 MainNp = temp;
00893 Nnodes++;
00894 return temp;
00895 }
00896
00897 pathpoint *CopyPath(short *pathtype, short *npathpoints, node *Nc,
00898 short firstframe, HWND parent){
00899 pathpoint *Ppp=NULL,*Fpp=NULL,*Lpp=NULL,*Cpp=NULL;
00900 char tempname[32];
00901 node *Np;
00902 object *Op;
00903 long i;
00904 if((Np=SelectNode(tempname,NO,parent)) == NULL || Np->type != PATH)return NULL;
00905 if((Op=Np->fobj) != NULL)while(Op != NULL){
00906 if(firstframe >= Op->firstframe && firstframe <= Op->lastframe){
00907 if(Op->npathpoints > 0 && (Cpp=Op->firstpathpoint) != NULL){
00908 for(i=0;i<Op->npathpoints;i++){
00909 if((Ppp=AppendPathPoint(Ppp)) == NULL)goto MEMFAIL;
00910 CopyPoint(Cpp->p,Ppp->p);
00911 Ppp->tension_n=Cpp->tension_n;
00912 Ppp->tension_p=Cpp->tension_p;
00913 Ppp->ptheta=0;Ppp->pfi=0;
00914 Ppp->distance=0.0;
00915 Lpp=Ppp;
00916 if(i == 0)Fpp=Ppp;
00917 Cpp=Cpp->next;
00918 }
00919 *npathpoints = Op->npathpoints;
00920 *pathtype = Op->pathtype;
00921 return Fpp;
00922 }
00923 }
00924 Op=Op->next;
00925 }
00926 return NULL;
00927 MEMFAIL:
00928 if(Lpp != NULL)while(Lpp!=NULL){Ppp=Lpp->last; X__Free(Lpp); Lpp=Ppp;}
00929 return NULL;
00930 }
00931
00932 void CheckRecursiveFollow(node *Np, short ff, short lf){
00933 position *Pp;
00934 align *Ap;
00935 char mess[256];
00936 object *Op;
00937 double alpha,theta,phi,sx,sy,sz,ima;
00938 short im;
00939 point Offset,TrackedOffset;
00940 long tframe;
00941 tframe=CurrentFrame;
00942 AGAIN:
00943 if(setjmp(r_buf) != 0){
00944 SendPrgmQuery(IDQ_SELFFOLLOW1,0);
00945 sprintf(mess,"Actor %s reset to TWEEN", Np->actorname);
00946 MessageBox (NULL,mess,"NOTE",
00947 MB_OK | MB_ICONINFORMATION | MB_TASKMODAL);
00948 if((Pp=Np->fpos) != NULL)while(Pp != NULL){
00949 if((CurrentFrame >= Pp->firstframe) && (CurrentFrame <= Pp->lastframe)){
00950 Pp->type=TWEEN; Pp->onpath=NULL; Pp->pnodename[0]='\0';
00951 }
00952 Pp=Pp->next;
00953 }
00954 if((Ap=Np->fali) != NULL)while(Ap != NULL){
00955 if((CurrentFrame >= Ap->firstframe) && (CurrentFrame <= Ap->lastframe)){
00956 Ap->type=TWEEN; Ap->topath=NULL; Ap->anodename[0]='\0';
00957 }
00958 Ap=Ap->next;
00959 }
00960 goto AGAIN;
00961 }
00962 for(CurrentFrame=ff; CurrentFrame <= lf; CurrentFrame++){
00963 if((Op=Np->fobj) != NULL)while(Op != NULL){
00964 if(CurrentFrame >= Op->firstframe && CurrentFrame <= Op->lastframe){
00965 GetTransform(0,CurrentFrame,1.0,Np,Op,Offset,TrackedOffset,
00966 &phi,&theta,&alpha,&sx,&sy,&sz,&im,&ima);
00967 }
00968 Op=Op->next;
00969 }
00970 }
00971 CurrentFrame=tframe;
00972 }
00973
00974 void ScrapEverything(void){
00975 XIP *Ip,*tIp;
00976 node *Np,*tNp;
00977 long i;
00978 char WorkfileName[64];
00979 if((Np=MainNp) != NULL)while(Np != NULL){
00980 tNp=Np->last;
00981 DeleteNode(Np);
00982 Np=tNp;
00983 }
00984 MainNp=NULL;
00985 FirstNp=NULL;
00986 SelectedNode=NULL;
00987 SelectedPath=NULL;
00988 SelectedPathPoint=NULL;
00989 SelectedCamera=NULL;
00990 Ncameras=0;
00991 Nnodes=0;
00992 Nground=0;
00993 Nrobots=0;
00994 Nskys=0;
00995 Ndirectors=0;
00996 MaxNodeID=0;
00997 if((Ip=MainIp) != NULL)while(Ip != NULL){
00998 tIp=Ip->last;
00999 DeleteImageProcess(Ip);
01000 Ip=tIp;
01001 }
01002 MainIp=NULL;
01003 FirstIp=NULL;
01004 NimageProcesses=0;
01005 fileID=0;
01006 Nframes=1;
01007 EnableMenuItem(GetMenu(ghwnd_main),IDM_FRAME_RENDERNOW,MF_GRAYED);
01008 CurrentFrame=1;
01009 FirstTimeRender=1;
01010 SelectedPathPhi=0.0;
01011 SelectedPathTheta=0.0;
01012 SelectedPathAlpha=0.0;
01013 SelectedPathOffset[0]=0;
01014 SelectedPathOffset[1]=0;
01015 SelectedPathOffset[2]=0;
01016 sprintf(WorkfileName,"%sW_$.SCR",TempPath);
01017 remove(WorkfileName);
01018 sprintf(WorkfileName,"%sX_$.SCR",TempPath);
01019 remove(WorkfileName);
01020 sprintf(WorkfileName,"%sY_$.SCR",TempPath);
01021 remove(WorkfileName);
01022 sprintf(WorkfileName,"%sW_$001.GIF",TempPath);
01023 remove(WorkfileName);
01024 sprintf(WorkfileName,"%sWIRE_$$$.APF",TempPath);
01025 remove(WorkfileName);
01026 FreePreview();
01027 EraseTempImageFiles();
01028 EDIT_ACTION=NO;
01029 }
01030
01031 long SelectNodeID(HWND parent){
01032 node *Np;
01033 char temp[256];
01034 temp[0]=0;
01035 if((Np=SelectNode(temp,NO,parent)) == NULL)return -1;
01036 return (long)(Np->ID);
01037 }
01038
01039 node *GetSelectedCamera(long cf, node *Sc){
01040 director *dp;
01041 node *np;
01042 if(Ndirectors < 1 || use_director == 0)return Sc;
01043 np=FirstNp; while (np != NULL){
01044 if(np->type == DIRECTOR){
01045 dp=np->fdirector;
01046 while(dp != NULL){
01047 if(cf >= dp->firstframe && cf <= dp->lastframe){
01048 Sc=dp->ActiveCamera;
01049 return Sc;
01050 }
01051 dp=dp->next;
01052 }
01053 return Sc;
01054 }
01055 np=np->next;
01056 }
01057 return Sc;
01058 }
01059
01060 typedef struct tagSELECTDLGLIST {
01061 int n;
01062 int maxlen;
01063 char *title;
01064 char **list;
01065 node **NpList;
01066 } SELECTDLGLIST;
01067
01068 static BOOL CALLBACK ActorListDlgProc(HWND hwnd, UINT msg,
01069 WPARAM wparam, LPARAM lparam ){
01070 static SELECTDLGLIST *dp;
01071 static HBITMAP hbmpPicture,hbmpOld;
01072 static HBITMAP hbmpImages[N_OBJECTTYPELIST];
01073 HWND hctl;
01074 TCHAR tchBuf[MAX_PATH];
01075 TEXTMETRIC tm;
01076 int i,y,nItem;
01077 int tc;
01078 HDC hdcMem;
01079 LPMEASUREITEMSTRUCT lpmis;
01080 LPDRAWITEMSTRUCT lpdis;
01081 RECT rcBitmap;
01082 switch( msg ) {
01083 case WM_INITDIALOG:{
01084 dp=(SELECTDLGLIST *)lparam;
01085 for(i=0;i<N_OBJECTTYPELIST;i++){
01086 hbmpImages[i]=LoadBitmap(ghinst_main,
01087 MAKEINTRESOURCE(ObjectSmallBitmapIdList[i]));
01088 }
01089 hctl=GetDlgItem(hwnd,DLG_SELECT_LIST);
01090 for(i=0;i<dp->n;i++){
01091 nItem=SendMessage(hctl,LB_ADDSTRING,0,(LPARAM)dp->list[i]);
01092 if(dp->NpList != NULL){
01093 node *Np;
01094 Np=dp->NpList[i];
01095 if(Np != NULL){
01096 hbmpPicture=hbmpImages[0];
01097 if(Np->type == PATH)hbmpPicture=hbmpImages[1];
01098 if(Np->type == TARGET)hbmpPicture=hbmpImages[2];
01099 if(Np->type == GROUND)hbmpPicture=hbmpImages[3];
01100 if(Np->type == LIGHT)hbmpPicture=hbmpImages[4];
01101 if(Np->type == ANIMOBJ)hbmpPicture=hbmpImages[5];
01102 if(Np->type == PARTICLE)hbmpPicture=hbmpImages[6];
01103 if(Np->type == SKY)hbmpPicture=hbmpImages[7];
01104 if(Np->type == ROBOT)hbmpPicture=hbmpImages[8];
01105 if(Np->type == CAMERA)hbmpPicture=hbmpImages[9];
01106 if(Np->type == IMAGEP)hbmpPicture=hbmpImages[10];
01107 if(Np->type == DIRECTOR)hbmpPicture=hbmpImages[11];
01108 SendMessage(hctl,LB_SETITEMDATA,nItem,(LPARAM)hbmpPicture);
01109 }
01110 }
01111 }
01112 SendMessage(hctl,LB_SETCURSEL,0,0);
01113 SendMessage(hctl,LB_SETCOLUMNWIDTH,(WPARAM)(dp->maxlen+1)*6+22,0);
01114 SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)dp->title);
01115 CentreDialogOnScreen(hwnd);
01116 }
01117 return (TRUE);
01118 case WM_MEASUREITEM:
01119 lpmis=(LPMEASUREITEMSTRUCT)lparam;
01120 lpmis->itemHeight=16;
01121 return TRUE;
01122 case WM_DRAWITEM:
01123 lpdis=(LPDRAWITEMSTRUCT)lparam;
01124 if(lpdis->itemID == -1)break;
01125 switch(lpdis->itemAction){
01126 case ODA_SELECT:
01127 case ODA_DRAWENTIRE:
01128 hbmpPicture=(HBITMAP)SendMessage(lpdis->hwndItem,LB_GETITEMDATA,
01129 lpdis->itemID,(LPARAM)0);
01130 hdcMem=CreateCompatibleDC(lpdis->hDC);
01131 hbmpOld=SelectObject(hdcMem,hbmpPicture);
01132 SendMessage(lpdis->hwndItem,LB_GETTEXT,lpdis->itemID,(LPARAM)tchBuf);
01133 GetTextMetrics(lpdis->hDC,&tm);
01134 y=(lpdis->rcItem.bottom+lpdis->rcItem.top-tm.tmHeight)/2;
01135 ExtTextOut(lpdis->hDC,
01136 lpdis->rcItem.left+16+6,y,
01137 ETO_OPAQUE | ETO_CLIPPED,
01138 &lpdis->rcItem,
01139 tchBuf,strlen(tchBuf),
01140 NULL);
01141 BitBlt(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
01142 lpdis->rcItem.right-lpdis->rcItem.left,
01143 lpdis->rcItem.bottom-lpdis->rcItem.top,
01144 hdcMem,0,0,SRCCOPY);
01145 SelectObject(hdcMem,hbmpOld);
01146 DeleteDC(hdcMem);
01147 if(lpdis->itemState & ODS_SELECTED){
01148 rcBitmap.left=lpdis->rcItem.left;
01149 rcBitmap.top=lpdis->rcItem.top;
01150 rcBitmap.right=lpdis->rcItem.left+
01151 16+6+strlen(tchBuf)*tm.tmAveCharWidth;
01152 rcBitmap.bottom=lpdis->rcItem.top+16;
01153
01154 InvertRect(lpdis->hDC,&lpdis->rcItem);
01155 }
01156 break;
01157 case ODA_FOCUS:
01158 break;
01159 }
01160 return TRUE;
01161 case WM_COMMAND:
01162 switch(LOWORD(wparam)){
01163 case DLG_SELECT_LIST:
01164 switch(HIWORD(wparam)){
01165 case LBN_SELCHANGE:
01166 hctl=GetDlgItem(hwnd,DLG_SELECT_LIST);
01167 i=SendMessage(hctl,LB_GETCURSEL,0,0);
01168 if(dp->NpList != NULL){
01169 node *Np;
01170 Np=dp->NpList[i];
01171 if(Np != NULL){
01172 if(Np->type == NORMAL ||
01173 Np->type == ROBOT ||
01174 Np->type == ANIMOBJ){
01175 object *Op;
01176 Op=GetObjectAtFrame(Np,CurrentFrame);
01177 if(Op == NULL)
01178 SetDlgItemText(hwnd,DLG_SELECT_INFO,Np->actorname);
01179 else
01180 SetDlgItemText(hwnd,DLG_SELECT_INFO,Op->name);
01181 }
01182 else
01183 SetDlgItemText(hwnd,DLG_SELECT_INFO," ");
01184 }
01185
01186 }
01187 break;
01188 case LBN_DBLCLK:
01189 SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDOK,0),0);
01190 break;
01191 default:
01192 break;
01193 }
01194 break;
01195 case IDCANCEL:
01196 EndDialog(hwnd, -1);
01197 return (TRUE);
01198 case IDOK:
01199 hctl=GetDlgItem(hwnd,DLG_SELECT_LIST);
01200 i=SendMessage(hctl,LB_GETCURSEL,0,0);
01201 EndDialog(hwnd,i);
01202 return(TRUE);
01203 default:
01204 break;
01205 }
01206 break;
01207 case WM_DESTROY:
01208 for(i=0;i<N_OBJECTTYPELIST;i++)DeleteObject(hbmpImages[i]);
01209 return TRUE;
01210 }
01211 return(FALSE);
01212 }
01213
01214 node *SelectNode(char *NodeName, short with_sky, HWND parent){
01215 SELECTDLGLIST SelectDlgList;
01216 node *Np,**NpList;
01217 int maxlen=0;
01218 short id,i,j;
01219 char **ItemList;
01220 char title[256];
01221 if((ItemList = (char **)X__Malloc(sizeof(char *)*Nnodes)) == NULL)
01222 return NULL;
01223 for(i=0;i<Nnodes;i++){
01224 if((ItemList[i] = (char *)X__Malloc(128)) == NULL){
01225 if(i > 0)for(j=0;j<i;j++)X__Free(ItemList[j]);
01226 X__Free(ItemList);
01227 return NULL;
01228 }
01229 }
01230 if((NpList = (node **)X__Malloc(sizeof(node *)*Nnodes)) == NULL){
01231 for(i=0;i<Nnodes;i++)X__Free(ItemList[i]);
01232 X__Free(ItemList);
01233 return NULL;
01234 }
01235 i=0; Np=FirstNp; while(Np != NULL){
01236 strcpy(ItemList[i]," ");
01237 strcat(ItemList[i],Np->actorname);
01238 NpList[i]=Np;
01239 maxlen=max(maxlen,strlen(ItemList[i]));
01240 i++; Np=Np->next;
01241 }
01242 TRYAGAIN:
01243 LoadString(ghinst_main,IDX_MISC_ACTOR,title,63);
01244 SelectDlgList.n=Nnodes;
01245 SelectDlgList.list=ItemList;
01246 SelectDlgList.title=title;
01247 SelectDlgList.maxlen=maxlen;
01248 SelectDlgList.NpList=NpList;
01249 id=DialogBoxParam(ghinst_main,MAKEINTRESOURCE(DLG_SELECT),parent,
01250 (DLGPROC)ActorListDlgProc,(LPARAM)&SelectDlgList);
01251
01252 if(id != FAIL && with_sky == NO && NpList[id]->type == SKY){
01253 MessageBeep(MB_OK);
01254 goto TRYAGAIN;
01255 }
01256 if(id == FAIL || (with_sky == NO && NpList[id]->type == SKY)){
01257 for(i=0;i<Nnodes;i++)X__Free(ItemList[i]);
01258 X__Free(ItemList);
01259 X__Free(NpList);
01260 return NULL;
01261 }
01262 strcpy(NodeName,ItemList[id]);
01263 Np=NpList[id];
01264 for(i=0;i<Nnodes;i++)X__Free(ItemList[i]);
01265 X__Free(ItemList);
01266 X__Free(NpList);
01267 return Np;
01268 }
01269
01270 void CentreDialogOnCursor(HWND hwnd){
01271 RECT rcDlg;
01272 POINT p;
01273 GetCursorPos(&p);
01274 GetWindowRect(hwnd,&rcDlg);
01275 OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
01276 OffsetRect(&rcDlg,p.x-rcDlg.right/2,p.y-rcDlg.bottom/2);
01277 if(rcDlg.left < 0)OffsetRect(&rcDlg,-rcDlg.left,0);
01278 if(rcDlg.top < 0)OffsetRect(&rcDlg,0,-rcDlg.top);
01279 if(rcDlg.right > Xres)OffsetRect(&rcDlg,Xres-rcDlg.right,0);
01280 if(rcDlg.bottom > Yres)OffsetRect(&rcDlg,0,Yres-rcDlg.bottom);
01281 SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
01282 return;
01283 }
01284
01285 void CentreDialogOnScreen(HWND hWnd){
01286 RECT rc;
01287 GetWindowRect(hWnd, &rc);
01288 SetWindowPos(hWnd, NULL,
01289 (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
01290 (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2,
01291 0, 0, SWP_NOSIZE | SWP_NOZORDER);
01292 }
01293
01294 void AppendFileExtension(char *filename, char *ext){
01295 if(strrchr(filename,'.') == NULL){
01296 strcat(filename,ext);
01297 }
01298 }
01299
01300 char *short_form(char *filename){
01301 char *sps,*spc;
01302 sps=spc=filename;
01303 while((spc=strchr(spc,'\\')) != NULL){spc++; sps=spc;}
01304 return sps;
01305 }
01306
01307 char *truncate_path(char *name, int n){
01308 static char compressed_path[256],newname[256];
01309 char *lp;
01310 int i,l;
01311 strcpy(newname,name);
01312 *short_form(newname) = '\0';
01313 if((l=strlen(newname)) == 0)return newname;
01314 if(strlen(newname) > n){
01315 strnset(compressed_path,'\0',255);
01316 strncpy(compressed_path,newname,3);
01317 strcat(compressed_path,"...");
01318 lp=strrchr(newname,'\\');
01319 if(lp != NULL)strcat(compressed_path,lp);
01320 }
01321 else strcpy(compressed_path,newname);
01322 AnsiLower(compressed_path);
01323 return compressed_path;
01324 }
01325
01326