⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window_manager.c

📁 LastWave
💻 C
📖 第 1 页 / 共 5 页
字号:
	    yShortTick1 = (int) (yAxis1+PXTICK);	  }	} 	else {	  vstrMode = VPositionBaseStr;	  if (!flagTicksIn) {	    yLongTick = (int) (yAxis-2*PXTICK);	    yLongTick1 = (int) (yAxis1+2*PXTICK);	    yStrTick =(int)  (yLongTick - 2);	    yShortTick = (int) (yAxis-PXTICK);	    yShortTick1 =(int)  (yAxis1+PXTICK);	  }	  else {	    yLongTick = (int) (yAxis+2*PXTICK);	    yLongTick1 = (int) (yAxis1-2*PXTICK);	    yStrTick = (int) (yAxis - 2);	    yShortTick = (int) (yAxis+PXTICK);	    yShortTick1 = (int) (yAxis1-PXTICK);	  }	}	for (i = 0; i < nXLongTicks + 1; i++){      sprintf(tempStr, "%.8g", theXLongTicks[i]);	  if (flagReverse & XFlagReverse) x0 = (int) ((xMax-theXLongTicks[i]) *(w-1)/(xMax-xMin) + x + 0.5);      else x0 = (int) ((theXLongTicks[i] - xMin) *(w-1)/(xMax-xMin) + x + 0.5);	    	  /* Draw the string */	  WDrawString((GOBJECT) win,tempStr,HPositionMiddleNStr,x0,vstrMode,yStrTick,0);	    	  /* And the tick */	  WDrawLine((GOBJECT) win,x0,yLongTick,x0,yAxis);	  if (flagFrame) WDrawLine((GOBJECT) win,x0,yLongTick1,x0,yAxis1);	}		/* draw the short ticks */	for (i = 0; i < nXShortTicks + 1; i++){	  if (flagReverse & XFlagReverse) x0 = (int) ((xMax-theXShortTicks[i]) *(w-1)/(xMax-xMin) + x + 0.5);      else x0 = (int) ((theXShortTicks[i] - xMin) *(w-1)/(xMax-xMin) + x + 0.5);	  WDrawLine((GOBJECT) win,x0,yShortTick,x0,yAxis);	  if (flagFrame) WDrawLine((GOBJECT) win,x0,yShortTick1,x0,yAxis1);	}	/* Label the x axis */    if (xText) {	  if (flagReverse & YFlagReverse) y0 = yStrTick+4;	  else y0 = yStrTick-4;	  if (flagReverse & XFlagReverse) {	    hstrMode = HPositionLeftStr;	    x0 = x +10;	  }	  else {	    hstrMode = HPositionRightNStr;	    x0 = x+w -10;	  }	  WDrawString((GOBJECT) win,xText,hstrMode,x0,vstrMode,y0,0); 	}    /*	 * Draw in the y-axis	 */    /* Draw the axis line */    if (flagReverse & XFlagReverse) {      xAxis = x+w-1+pixelMargin;      xAxis1 = x-pixelMargin;    }    else {      xAxis = x-pixelMargin;      xAxis1 = x+w-1+pixelMargin;    }	WDrawLine((GOBJECT) win,xAxis,y-pixelMargin, xAxis, y+h-1+pixelMargin);	if (flagFrame) 	WDrawLine((GOBJECT) win,xAxis1,y-pixelMargin, xAxis1, y+h-1+pixelMargin);	/* Draw the long ticks and label them */	if (flagReverse & XFlagReverse) {	  hstrMode = HPositionLeftStr;	  if (!flagTicksIn) {	    xLongTick = (int) (xAxis+2*PXTICK);	    xShortTick = (int) (xAxis+PXTICK);	    xLongTick1 = (int) (xAxis1-2*PXTICK);	    xShortTick1 = (int) (xAxis1-PXTICK);	  }	  else {	    xLongTick = (int) (xAxis-2*PXTICK);	    xShortTick = (int) (xAxis-PXTICK);	    xLongTick1 = (int) (xAxis1+2*PXTICK);	    xShortTick1 = (int) (xAxis1+PXTICK);      }	  	} 	else {	  hstrMode = HPositionRightNStr;	  if (!flagTicksIn) {	    xLongTick = (int) (xAxis-2*PXTICK);	    xShortTick = (int) (xAxis-PXTICK);	    xLongTick1 = (int) (xAxis1+2*PXTICK);	    xShortTick1 = (int) (xAxis1+PXTICK);	  }	  else {	    xLongTick = (int) (xAxis+2*PXTICK);	    xShortTick = (int) (xAxis+PXTICK);	    xLongTick1 = (int) (xAxis1-2*PXTICK);	    xShortTick1 = (int) (xAxis1-PXTICK);	  }	}	for (i = 0; i < nYLongTicks + 1; i++){           sprintf(tempStr, "%.8g", theYLongTicks[i]);	 	  if (!flagTicksIn) {	    if (flagReverse & XFlagReverse) xStrTick = xLongTick + 2;	    else xStrTick = xLongTick - 2;	  } 	  else {	    if (flagReverse & XFlagReverse) xStrTick = xAxis + 2;	    else xStrTick = xAxis - 2;      }           	  if (flagReverse & YFlagReverse) y0 = (int) ((yMax-theYLongTicks[i]) *(h-1)/(yMax-yMin) + y + 0.5);      else y0 = (int) ((theYLongTicks[i] - yMin) *(h-1)/(yMax-yMin) + y + 0.5);	  yStrTick = y0;		    	  /* Draw the string */	  WDrawString((GOBJECT) win,tempStr,hstrMode,xStrTick,VPositionMiddleUpStr, yStrTick,0);	    	  /* And the tick */	  WDrawLine((GOBJECT) win,xLongTick,y0,xAxis,y0);	 if (flagFrame) WDrawLine((GOBJECT) win,xLongTick1,y0,xAxis1,y0);	}		/* draw the short ticks */	for (i = 0; i < nYShortTicks + 1; i++){	  if (flagReverse & YFlagReverse) y0 = (int) ((yMax-theYShortTicks[i]) *(h-1)/(yMax-yMin) + y + 0.5);      else y0 = (int) ((theYShortTicks[i] - yMin) *(h-1)/(yMax-yMin) + y + 0.5);	  WDrawLine((GOBJECT) win,xShortTick,y0,xAxis,y0);	  if (flagFrame) WDrawLine((GOBJECT) win,xShortTick1,y0,xAxis1,y0);	}			/* Label the y axis */    if (yText) {	  if (flagReverse & XFlagReverse) x0 = xStrTick+2;	  else x0 = xStrTick-2;	  if (flagReverse & YFlagReverse) {	    vstrMode = VPositionUpStr;	    y0 = y + 10;	  }	  else {	    vstrMode = VPositionDownStr;	    y0 = y+h - 10;	  }	  WDrawString((GOBJECT) win,yText,hstrMode,x0,vstrMode,y0,0); 	}		/*	 * Now do the title	 */	    if (titleText) {      if (flagReverse & YFlagReverse) y0 = y-5;      else y0 = y+h+5;		  WDrawString((GOBJECT) win,titleText,HPositionMiddleNStr,x+w/2,VPositionMiddleStr, y0,0); 	}}void DrawAxis(GOBJECT o, LWFLOAT x, LWFLOAT y, LWFLOAT dx, LWFLOAT dy, LWFLOAT xMin, LWFLOAT xMax, LWFLOAT yMin, LWFLOAT yMax,              char *xTitle, char *yTitle, char *title, int pixelMargin, char flagTicksIn, char flagFrame,char flagReverse){  int i,j,m,n;  WINDOW win = GetWin(o);    if (win->flagHide) return;  if (win->frame == (FRAME) NULL && !PSMode) Errorf("Weird error");  Local2GlobalRect(o,x,y,dx,dy,NormalRect,&i,&j,&m,&n);  ComputeTicks(xMin,xMax,yMin,yMax);  DrawAxis_(win, i,j,m,n,xMin,xMax,yMin,yMax,xTitle,yTitle,title,pixelMargin,flagTicksIn,flagFrame,flagReverse);}  /*  * Function to take care of the options of the C_Draw command  *    It sets the color, the pensize, the linestyle, the clipRect and the pen mode  *    If argv == NULL then it resets everything  * This function must be called twice : one time for setting the graphic attributes and the  * second time for resetting them.  * Both times it must be called with the SAME arguments for clipWin, clipX, clipY, clipW, clipH.  * It returns YES if the flag '-n' is set otherwise it returns NO.  */#define FlagSizeIsInPixel 256#define FlagFill 512#define FlagCentered 1024static unsigned long DoDrawOptions(WINDOW win, GOBJECT o, char **argv,RectType *rectType,WINDOW *clipWin,int *clipX,int *clipY, int *clipW, int *clipH){  char *str;  int pen;  unsigned long flag;  unsigned long color;  int x,y,w,h,l,t,r,b;  FONT font;  VALUE val;    flag = 0;  *rectType = NormalRect;    /* Set the graphic attributes */  if (argv != NULL) {        *clipWin = NULL;        while (*argv != NULL) {      if (!strcmp(*argv,"-pen")) {        argv++;        argv = ParseArgv(argv,tINT,&pen,-1);        if (pen <= 0) Errorf("DoDrawOptions() : Bad pen size '%d'",pen);        WSetPenSize(win,pen);        continue;      }        if (!strcmp(*argv,"-line")) {        argv++;        argv = ParseArgv(argv,tSTR,&str,-1);        if (!strcmp(str,"solid")) WSetLineStyle(win,LinePlain);        else if (!strcmp(str,"dash")) WSetLineStyle(win,LineDash);        else Errorf("DoDrawOptions() : Bad line style '%s'",str);        continue;      }      if (!strcmp(*argv,"-mode")) {        argv++;        argv = ParseArgv(argv,tSTR,&str,-1);        if (!strcmp(str,"normal")) WSetPenMode(win,PenPlain);        else if (!strcmp(str,"inverse")) WSetPenMode(win,PenInverse);        else Errorf("DoDrawOptions() : Bad pen mode '%s'",str);        continue;      }      if (!strcmp(*argv,"-color")) {        argv++;        argv = ParseArgv(argv,tCOLOR,&color,-1);        WSetColor(win,color);        continue;      }      if (!strcmp(*argv,"-font")) {        argv++;        argv = ParseArgv(argv,tFONT,&font,-1);        WSetFont(win,font);        continue;      }      if (!strcmp(*argv,"-clip")) {        argv++;        WGetClipRect(clipWin,clipX,clipY,clipW,clipH);        x = 0; y = 0; w = INT_MAX/2; h = INT_MAX/2;        GetVisibleRect(o,&x,&y,&w,&h);        WSetClipRect(win,x,y,w,h);        continue;      }        if (!strcmp(*argv,"-pixel")) {        argv++;        flag = flag | FlagSizeIsInPixel;        continue;      }      if (!strcmp(*argv,"-centered")) {        argv++;        flag = flag | FlagCentered;        continue;      }            if (!strcmp(*argv,"-rectType")) {        argv++;        ParseArgv(argv,tVAL,&val,-1);        if (GetTypeValue(val) == strType) {          argv++;          str = CastValue(val,STRVALUE)->str;          if (!strcmp(str,"normal")) *rectType = NormalRect;          else if (!strcmp(str,"large")) *rectType = LargeRect;          else if (!strcmp(str,"small")) *rectType = SmallRect;          else Errorf("Bad value '%s' for -recType",str);        }        else {          argv = ParseArgv(argv,tINT,&l,tINT,&t,tINT,&r,tINT,&b,-1);          rectType->left = l;          rectType->right = r;          rectType->top = t;          rectType->bottom = b;        }        continue;      }      if (!strcmp(*argv,"-fill")) {        argv++;        flag = flag | FlagFill;        continue;      }       Errorf("DoDrawOptions() : Bad option '%s'",*argv);    }        return(flag);  }  /* or Unset them */  WSetLineStyle(win,o->lineStyle);  WSetPenSize(win,o->penSize);  WSetColor(win,o->fgColor);  WSetFont(win,o->font);  WSetPenMode(win,o->penMode);  if (*clipWin != NULL) WSetClipRect(*clipWin,*clipX,*clipY,*clipW,*clipH);  return(NO);} /*    * General Command to Draw different things on a gobjects */ void C_Draw (char **argv){  static LWFLOAT oldX,oldY;  static GOBJECT oldObj = NULL;  GOBJECT o,o1;  GLIST list;  GCLASS class;  WINDOW w;  char *action,name[50];  LWFLOAT x,y,dx,dy,x1,y1,angle;  LWFLOAT xMin,xMax,yMin,yMax;  char *str,*title,*xlabel,*ylabel;  char flagTicksIn,flagFrame,flagReverse;  int pixelMargin;    unsigned long flag;  RectType rectType;  WINDOW clipWin;  int clipX,clipY,clipW,clipH;  char flagClip;  char *hModeStr,*vModeStr;  int hMode,vMode;    argv = ParseArgv(argv,tWORD,&action,tGOBJECT,&o,-1);  /* Should we display it ? */  for (o1 = o;o1 !=NULL; o1 = (GOBJECT) o1->father) {    if (o1->flagHide) return;  }    /* Set some default graphic attributes */    w = GetWin(o);  WSetLineStyle(w,o->lineStyle);  WSetPenSize(w,o->penSize);  WSetColor(w,o->fgColor);  WSetPenMode(w,o->penMode);  /* rect */  if (!strcmp(action,"rect")) {    argv = ParseArgv(argv,tFLOAT,&x,tFLOAT,&y,tFLOAT,&dx,tFLOAT,&dy,-1);    flag = DoDrawOptions(w,o,argv,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    if (flag & FlagCentered) {      if (flag & FlagFill) WFillCenteredRect(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel);          else  WDrawCenteredRect(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel);        }    else {      if (flag & FlagFill) WFillRect(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel, rectType);          else  WDrawRect(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel, rectType);        }    DoDrawOptions(w,o,NULL,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    oldObj = NULL;    return;  }    /* ellipse */  if (!strcmp(action,"ellipse")) {    argv = ParseArgv(argv,tFLOAT,&x,tFLOAT,&y,tFLOAT,&dx,tFLOAT,&dy,-1);    flag = DoDrawOptions(w,o,argv,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    if (flag & FlagCentered) {      if (flag & FlagFill) WFillCenteredEllipse(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel);          else  WDrawCenteredEllipse(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel);        }    else {      if (flag & FlagFill) WFillEllipse(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel,rectType);          else  WDrawEllipse(o,x,y,dx,dy,(flag & FlagSizeIsInPixel)==FlagSizeIsInPixel, rectType);        }    DoDrawOptions(w,o,NULL,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    oldObj = NULL;    return;  }    /* cross */  if (!strcmp(action,"cross")) {    argv = ParseArgv(argv,tFLOAT,&x,tFLOAT,&y,tFLOAT,&dx,-1);    flag = DoDrawOptions(w,o,argv,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    WDrawCenteredCross(o,x,y,dx,YES);        DoDrawOptions(w,o,NULL,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    oldObj = NULL;    return;  }    /* line */  if (!strcmp(action,"line")) {    argv = ParseArgv(argv,tFLOAT,&x,tFLOAT,&y,tFLOAT,&x1,tFLOAT,&y1,-1);    flag = DoDrawOptions(w,o,argv,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    WDrawLine(o,x,y,x1,y1);        DoDrawOptions(w,o,NULL,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    oldX = x1;    oldY = y1;    oldObj = o;    return;  }    /* Draw a lineto */  if (!strcmp(action,"lineto")) {    if (o != oldObj) Errorf("No former point in the same gobject to draw a line from");    argv = ParseArgv(argv,tFLOAT,&x,tFLOAT,&y,-1);    flag = DoDrawOptions(w,o,argv,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    WDrawLine(o,oldX,oldY,x,y);        DoDrawOptions(w,o,NULL,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    oldX = x;    oldY = y;    oldObj = o;    return;  }        /* Draw a point */  if (!strcmp(action,"point")) {    argv = ParseArgv(argv,tFLOAT,&x,tFLOAT,&y,-1);    flag = DoDrawOptions(w,o,argv,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    WDrawPoint(o,x,y);        DoDrawOptions(w,o,NULL,&rectType,&clipWin,&clipX,&clipY,&clipW,&clipH);    oldX = x;    oldY = y;    oldObj = o;    return;  }    /* Draw a string */  if (!strcmp(action,"string")) {    argv = ParseArgv(argv,tSTR,&str,-1);    if (ParseFloat_(*argv,0.0,&x)) {      hMode = HPositionLeftStr;      argv++;    }    else {      argv = ParseArgv(argv,tWORD,&hModeStr,tFLOAT,&x,-1);      if (!strcmp(hModeStr,"left")) hMode = HPositionLeftStr;      else if (!strcmp(hModeStr,"right1")) hMode = HPositionRight1Str;      else if (!strcmp(hModeStr,"rightN") || !strcmp(hModeStr,"right")) hMode = HPositionRightNStr;      else if (!strcmp(hModeStr,"middle1")) hMode = HPositionMiddle1Str;      else if (!strcmp(hModeStr,"middleN") || !strcmp(hModeStr,"middle")) hMode = HPositionMiddleNStr;      else Errorf("Bad horizontal string position mode '%s'",hModeStr);    }        if (ParseFloat_(*argv,0.0,&y)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -