Ejemplo n.º 1
0
void IMGUI::doText(int id, const Vector2& position, TextManager::STRING text, unsigned int flags)
{
	doText(id, position, TextManager::getSingleton()->getString(text), flags);
}
Ejemplo n.º 2
0
int doCommand(int command, param pList) {
/*
output the LaTeX bits for this command, updating the coords, coord list
etc. as required
*/

    static int init = 0;
    aTag *tempTag;
    char params[10][80];
    char *trackStr = "vector";
    float dimen,x,y,x1,y1;
    int i,xs,ys;
    coord t;
               
    dimen = 0.;
    
    params[0][0]=0;  /* so Up / Down / Left / Right can find *'s for line
			drawing                                            */


    if (CurTrack == LineS) trackStr = "line";

    if (fcom[command].HasText) {
	if ((command != Choice && sscanf(pList,"%f %f",&x,&y) == 2) ||
	    (command == Choice && sscanf(pList,"%s %s %s %s %f %f",
				       params[0],
				       params[0],
				       params[0],
				       params[0],
				       &x,&y) == 6)) {
	    fcom[command].size.x = x;
	    fcom[command].size.y = y;
	}
    }

    if (!init && CurSize.x == 0. && CurSize.y == 0.) {
	    CurSize.x = fcom[command].size.x*CurScale.x;
	    CurSize.y = fcom[command].size.y*CurScale.y;
    }

    if ( init && (fcom[command].size.x != 0 || fcom[command].size.y != 0 )) {

	switch (CurDirec) {

	case DownD :

            t.x = Coords[CurCoord].x+CurSize.x/2;
            t.y = Coords[CurCoord].y-CurSize.y;

            if (CurTrack != NoneS)
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
		               t.x,
                       t.y,
                       trackStr,
                       0,-1,
                       VertGap);
                       
            checkBounds(&pic,&t);                       

            Coords[CurCoord+1].x = Coords[CurCoord].x + CurSize.x/2 -
                                   fcom[command].size.x*CurScale.x / 2;

            Coords[CurCoord+1].y = Coords[CurCoord].y - CurSize.y
                                   - VertGap;
                                   
            checkBounds(&pic,Coords+CurCoord+1);
            
            break;

        case UpD :

            t.x = Coords[CurCoord].x+CurSize.x/2;
            t.y = Coords[CurCoord].y;
            
            if (CurTrack != NoneS)
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
                       t.x,
                       t.y,
                       trackStr,
		       0,1,
                       VertGap);

            checkBounds(&pic,&t);                       
            
            Coords[CurCoord+1].x = Coords[CurCoord].x + CurSize.x/2 -
                                   fcom[command].size.x*CurScale.x / 2;

            Coords[CurCoord+1].y = Coords[CurCoord].y + 
                                   fcom[command].size.y*CurScale.y
				   + VertGap;
            checkBounds(&pic,Coords+CurCoord+1);
            
            break;

        case RightD :

            t.x = Coords[CurCoord].x+CurSize.x;
            t.y = Coords[CurCoord].y-CurSize.y/2;

            if (CurTrack != NoneS)
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
                       t.x,
                       t.y,
                       trackStr,
                       1,0,
                       HorzGap);

            checkBounds(&pic,&t);                       
            
            Coords[CurCoord+1].x = Coords[CurCoord].x + CurSize.x
                                   + HorzGap;
            Coords[CurCoord+1].y = Coords[CurCoord].y - CurSize.y/2 +
                                   fcom[command].size.y*CurScale.y / 2;

            checkBounds(&pic,Coords+CurCoord+1);
            
            break;

	case LeftD :

            t.x = Coords[CurCoord].x;
            t.y = Coords[CurCoord].y-CurSize.y/2;

            if (CurTrack != NoneS)
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
                       t.x,
                       t.y,
                       trackStr,
                       -1,0,
                       HorzGap);

            checkBounds(&pic,&t);                       
            
            Coords[CurCoord+1].x = Coords[CurCoord].x - 
                                   fcom[command].size.x*CurScale.x
				   - HorzGap;
	    Coords[CurCoord+1].y = Coords[CurCoord].y - CurSize.y/2 +
				   fcom[command].size.y*CurScale.y / 2;

            checkBounds(&pic,Coords+CurCoord+1);
            
	    break;

	default:
	    break;
	}
	CurCoord++;
	CurSize.x = fcom[command].size.x*CurScale.x;
	CurSize.y = fcom[command].size.y*CurScale.y;

    }

    switch (command) {

    case Skip :
	if (sscanf(pList,"%f %f %f %f",&x,&y,&x1,&y1) == 4) {
	    VertGap = y;
	    HorzGap = x;
	    TrackX = x1;
	    TrackY = y1;
	}
	break;

    case TxtPos :
	CurPos[0]=CurBoxPos[0]=leader[0]=tailer[0]=0;
	sscanf(pList,"%s %s %s %s",CurPos,CurBoxPos,leader,tailer);
	break;

    case Box :
	init=1;
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\framebox(%3.4f,%3.4f)%s{\\shortstack%s{\n",
               Coords[CurCoord].x,
		       Coords[CurCoord].y-CurSize.y,
		       CurSize.x,
		       CurSize.y,
		       CurBoxPos,
		       CurPos);
	    doText();
	    fprintf(outFile,"}}}\n");
    
        checkBoundsRng(
            &pic,
            Coords[CurCoord].x,
            Coords[CurCoord].y-CurSize.y,
            CurSize.x,
            CurSize.y
        );

	break;

    case Tilt :
	init=1;
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(%3.4f,%3.4f)%s{\\shortstack%s{\n",
		       Coords[CurCoord].x,
		       Coords[CurCoord].y-CurSize.y,
		       CurSize.x,
		       CurSize.y,
		       CurBoxPos,
		       CurPos);
	doText();
	fprintf(outFile,"}}}\n");

	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x+1./6.*CurSize.y,
		       Coords[CurCoord].y,
		       1,0,
		       CurSize.x);
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x-1./6.*CurSize.y,
		       Coords[CurCoord].y-CurSize.y,
		       1,0,
		       CurSize.x);
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x-1./6.*CurSize.y,
		       Coords[CurCoord].y-CurSize.y,
		       1,3,
		       CurSize.y*1./3.);
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x-1./6.*CurSize.y+CurSize.x,
		       Coords[CurCoord].y-CurSize.y,
		       1,3,
		       CurSize.y*1./3.);

    checkBoundsRng(
        &pic,
        Coords[CurCoord].x-1./6.*CurSize.y,
        Coords[CurCoord].y-CurSize.y,
        CurSize.x + 1./6.*CurSize.y,
        CurSize.y
    );

	break;

    case Text :
	init=1;
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(%3.4f,%3.4f)%s{\\shortstack%s{\n",
		       Coords[CurCoord].x,
		       Coords[CurCoord].y-CurSize.y,
		       CurSize.x,
		       CurSize.y,
		       CurBoxPos,
		       CurPos);
	doText();
	fprintf(outFile,"}}}\n");

    checkBoundsRng(
        &pic,
        Coords[CurCoord].x,
        Coords[CurCoord].y-CurSize.y,
        CurSize.x,
        CurSize.y
    );
	break;

    case Oval :
	init=1;
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\oval(%3.4f,%3.4f)}\n",
		       Coords[CurCoord].x+CurSize.x/2,
		       Coords[CurCoord].y-CurSize.y/2,
		       CurSize.x,
		       CurSize.y );
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(%3.4f,%3.4f)%s{\\shortstack%s{\n",
		       Coords[CurCoord].x,
		       Coords[CurCoord].y-CurSize.y,
		       CurSize.x,
		       CurSize.y,
		       CurBoxPos,
		       CurPos );
	doText();
	fprintf(outFile,"}}}\n");
    checkBoundsRng(
        &pic,
        Coords[CurCoord].x,
        Coords[CurCoord].y-CurSize.y,
        CurSize.x,
        CurSize.y
    );

	break;

    case Choice :

	init=1;
    
    xs = (int)CurSize.x; ys = (int)CurSize.y; 
    
    for (i = (xs>ys) ? xs : ys; i>1; i--) {
        if ( (xs % i) == 0 && (ys % i) == 0 ) {
            xs /= i;
            ys /= i;
            i = (xs>ys) ? xs : ys;
        }
    }
    
    if (xs>6) {
        fprintf(stderr,"Flow warning - illegal Choice aspect ratio\n");
        xs = 6;
    }
    if (ys>6) {
        fprintf(stderr,"Flow warning - illegal Choice aspect ratio\n");
        ys = 6;
    }
    
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		      Coords[CurCoord].x,
		      Coords[CurCoord].y-CurSize.y/2,
		      xs,ys,CurSize.x/2
		      );
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		      Coords[CurCoord].x,
		      Coords[CurCoord].y-CurSize.y/2,
		      xs,-ys,CurSize.x/2
		      );
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		      Coords[CurCoord].x+CurSize.x,
		      Coords[CurCoord].y-CurSize.y/2,
		      -xs,-ys,CurSize.x/2
		      );
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\line(%d,%d){%3.4f}}\n",
		      Coords[CurCoord].x+CurSize.x,
		      Coords[CurCoord].y-CurSize.y/2,
		      -xs,ys,CurSize.x/2
		      );
	fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(%3.4f,%3.4f)%s{\\shortstack%s{\n",
		       Coords[CurCoord].x,
		       Coords[CurCoord].y-CurSize.y,
		       CurSize.x,
		       CurSize.y,
		       CurBoxPos,
		       CurPos );
	doText();
        fprintf(outFile,"}}}\n");
        
        sscanf(pList,"%s %s %s %s",params[0],params[1],params[2],params[3]);

        if (params[0][0] != '.')
	    fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(0,0)[lt]{%s}}\n",
                           Coords[CurCoord].x+
                           CurSize.x*0.65,
                           Coords[CurCoord].y,
                           params[0]
                          );
                           
        if (params[1][0] != '.')
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(0,0)[rt]{%s}}\n",
                           Coords[CurCoord].x,
                           Coords[CurCoord].y-
                           CurSize.y/2.*0.7,
                           params[1]
                          );
                           
        if (params[2][0] != '.')
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(0,0)[lt]{%s}}\n",
                           Coords[CurCoord].x+
			   CurSize.x,
                           Coords[CurCoord].y-
			   CurSize.y/2.*0.7,
                           params[2]
                          );
                           
        if (params[3][0] != '.')
            fprintf(outFile,"\\put(%3.4f,%3.4f){\\makebox(0,0)[lb]{%s}}\n",
                           Coords[CurCoord].x+
                           CurSize.x*0.65,
                           Coords[CurCoord].y-
                           CurSize.y,
                           params[3]
                          );
                           
    checkBoundsRng(
        &pic,
        Coords[CurCoord].x,
        Coords[CurCoord].y-CurSize.y,
        CurSize.x,
        CurSize.y
    );
        break;

    case SetTrack :
        sscanf(pList,"%s",params[0]);
        
	if ( strcmp("arrow",params[0]) == 0)
            CurTrack = ArrowS;
	if ( strcmp("line",params[0]) == 0)
            CurTrack = LineS;
        if ( strcmp("none",params[0]) == 0)
            CurTrack = NoneS;
    
        break;

    case Scale :
        sscanf(pList,"%f %f",&CurScale.x,&CurScale.y);
        break;

    case Tag :
        tempTag = (aTag*)malloc(sizeof(aTag));
        tempTag->size.x = CurSize.x;
        tempTag->size.y = CurSize.y;
        tempTag->pos.x = Coords[CurCoord].x;
        tempTag->pos.y = Coords[CurCoord].y;
        tempTag->next = CurTag;
	CurTag = tempTag;
        break;

    case ToTag :
    
        if (CurTag == NULL) {
            fprintf(stderr,"flow error - Tag stack empty \n");
            break;
        }
        tempTag = CurTag;
        CurSize.x = tempTag->size.x;
        CurSize.y = tempTag->size.y;
        Coords[CurCoord].x = tempTag->pos.x;
        Coords[CurCoord].y = tempTag->pos.y;
        
        CurTag = tempTag->next;
        
        free(tempTag);
        
        break;

    case Right :
	CurDirec = RightD;
	if (sscanf(pList,"%f %19s",&dimen,params[0])>=1) {
	    init=1;
	    dimen *= TrackX;
	    if (CurTrack != NoneS)
	    fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x+CurSize.x,
		       Coords[CurCoord].y-CurSize.y/2,
		       (params[0][0]=='*')?"vector":"line",
		       1,0,
		       dimen);

	    Coords[CurCoord+1].x = Coords[CurCoord].x + CurSize.x +
				   dimen;

	    Coords[CurCoord+1].y = Coords[CurCoord].y - CurSize.y/2;

	    CurCoord++;

	    CurSize = fcom[command].size;
	}
        checkBounds(&pic,&(Coords[CurCoord]));
	break;

    case Down :
	CurDirec = DownD;

	if (sscanf(pList,"%f %19s",&dimen,params[0])>=1) {
	    init=1;
	    dimen *= TrackY;
	    if (CurTrack != NoneS)
	    fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x+CurSize.x/2,
		       Coords[CurCoord].y-CurSize.y,
		       (params[0][0]=='*')?"vector":"line",
		       0,-1,
		       dimen);

	    Coords[CurCoord+1].x = Coords[CurCoord].x + CurSize.x/2 -
				   fcom[command].size.x / 2;

	    Coords[CurCoord+1].y = Coords[CurCoord].y - CurSize.y
				   - dimen;

	    CurCoord++;

	    CurSize = fcom[command].size;
	}
        checkBounds(&pic,&(Coords[CurCoord]));

	break;

    case Left :
	CurDirec = LeftD;
	if (sscanf(pList,"%f %19s",&dimen,params[0])>=1) {
	    init=1;
	    dimen *= TrackX;
	    if (CurTrack != NoneS)
	    fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x,
		       Coords[CurCoord].y-CurSize.y/2,
		       (params[0][0]=='*')?"vector":"line",
		       -1,0,
		       dimen);

	    Coords[CurCoord+1].x = Coords[CurCoord].x -
				   dimen;

	    Coords[CurCoord+1].y = Coords[CurCoord].y - CurSize.y/2;

	    CurCoord++;

	    CurSize = fcom[command].size;
	}
        checkBounds(&pic,&(Coords[CurCoord]));
	break;

    case Up :
	CurDirec = UpD;
	if (sscanf(pList,"%f %19s",&dimen,params[0])>=1) {
	    init=1;
	    dimen *= TrackY;
	    if (CurTrack != NoneS)
	    fprintf(outFile,"\\put(%3.4f,%3.4f){\\%s(%d,%d){%3.4f}}\n",
		       Coords[CurCoord].x+CurSize.x/2,
		       Coords[CurCoord].y,
                       (params[0][0]=='*')?"vector":"line",
                       0,1,
                       dimen);
                       
            Coords[CurCoord+1].x = Coords[CurCoord].x + CurSize.x/2 -
                                   fcom[command].size.x / 2;

            Coords[CurCoord+1].y = Coords[CurCoord].y +
                                   dimen;
                                   
            CurCoord++;
                                   
            CurSize = fcom[command].size;
        }
        checkBounds(&pic,&(Coords[CurCoord]));
        break;

    case Comment :
	break;

    default:
        fprintf(stderr,"flow error : unknown command %4d\n",command);
        return 0;
    }
    
    if (command != Scale) CurScale.x = CurScale.y = 1.;

    if (fcom[command].HasText == FALSE) {
        line[0]=0;
        fgets(line,LineLen,inFile);
        InputLine++;
    }

    return 1;

}