drawing.c
来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,006 行 · 第 1/3 页
C
1,006 行
drawing_area->style->black_gc, TRUE, x, y, Width, Height);*/ break; case ELE_OUTPUT: case ELE_OUTPUT_NOT: case ELE_OUTPUT_SET: case ELE_OUTPUT_RESET: case ELE_OUTPUT_JUMP: case ELE_OUTPUT_CALL: /* hide the too much of lines - - before drawing arcs */ gdk_draw_rectangle(DrawPixmap, (DrawingOption!=DRAW_FOR_TOOLBAR)?drawing_area->style->white_gc:drawing_area->style->bg_gc[0], TRUE, x+WidDiv4,y+HeiDiv2-1, WidDiv2,3); /* draw the 2 arcs of the outputs */ gdk_draw_arc (DrawPixmap, TheGc, FALSE, x+WidDiv4, y+HeiDiv4, WidDiv2, HeiDiv2, (90+20)*64, 150*64); gdk_draw_arc (DrawPixmap, TheGc, FALSE, x+WidDiv4, y+HeiDiv4, WidDiv2, HeiDiv2, (270+20)*64, 150*64); break; } /* Drawing / */ switch(Element.Type) { case ELE_INPUT_NOT: case ELE_OUTPUT_NOT: gdk_draw_line(DrawPixmap, TheGc, x+WidDiv3,y+Height-HeiDiv4, x+WidDiv3*2,y+HeiDiv4); } /* Drawing ^ or \/ */ switch(Element.Type) { case ELE_RISING_INPUT: gdk_draw_line(DrawPixmap, TheGc, x+WidDiv3,y+HeiDiv3*2, x+WidDiv4*2,y+HeiDiv3); gdk_draw_line(DrawPixmap, TheGc, x+WidDiv4*2,y+HeiDiv3, x+WidDiv3*2,y+HeiDiv3*2); break; case ELE_FALLING_INPUT: gdk_draw_line(DrawPixmap, TheGc, x+WidDiv3,y+HeiDiv3, x+WidDiv4*2,y+HeiDiv3*2); gdk_draw_line(DrawPixmap, TheGc, x+WidDiv4*2,y+HeiDiv3*2, x+WidDiv3*2,y+HeiDiv3); break; } /* Drawing 'S'et or 'R'eset or 'J'ump or 'C'all for outputs */ switch(Element.Type) { case ELE_OUTPUT_SET:#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc, x+WidDiv3+2,y+HeiDiv3*2,"S",1);#else DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, "S" );#endif break; case ELE_OUTPUT_RESET:#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc, x+WidDiv3+2,y+HeiDiv3*2,"R",1);#else DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, "R" );#endif break; case ELE_OUTPUT_JUMP:#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc, x+WidDiv3+2,y+HeiDiv3*2,"J",1);#else DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, "J" );#endif break; case ELE_OUTPUT_CALL:#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc, x+WidDiv3+2,y+HeiDiv3*2,"C",1);#else DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, "C" );#endif break; } /* Drawing complex ones : Timer, Monostable, Compar, Operate */ switch(Element.Type) { case ELE_TIMER: if (DrawingOption==DRAW_FOR_TOOLBAR) break; Timer = &TimerArray[Element.VarNum]; /* the box */ gdk_draw_rectangle(DrawPixmap, drawing_area->style->white_gc, TRUE, x+WidDiv3-Width, y+HeiDiv3, Width+1*WidDiv3, Height+1*HeiDiv3); gdk_draw_rectangle(DrawPixmap, DynaGcOff, FALSE, x+WidDiv3-Width, y+HeiDiv3, Width+1*WidDiv3, Height+1*HeiDiv3); /* input : enable */ gdk_draw_line(DrawPixmap, (Timer->InputEnable)?DynaGcOn:DynaGcOff, x-Width,y+HeiDiv2, x-Width+WidDiv3,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1,"I",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y+HeiDiv2-1, -1, -1, "I" );#endif /* output : done */ gdk_draw_line(DrawPixmap, (Timer->OutputDone)?DynaGcOn:DynaGcOff, x+WidDiv3*2,y+HeiDiv2, x+Width,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1,"D",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1, -1, -1, "D" );#endif /* output : running */ gdk_draw_line(DrawPixmap, (Timer->OutputRunning)?DynaGcOn:DynaGcOff, x+WidDiv3*2,y+HeiDiv2+Height, x+Width,y+HeiDiv2+Height);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1+Height,"R",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1+Height, -1, -1, "R" );#endif /* Timer Number */ sprintf(BufTxt,"T%d",Element.VarNum);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv2-Width,y+HeiDiv4-2,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+WidDiv2-Width,y+HeiDiv4+2, -1, -1, BufTxt );#endif /* Current Value (or Preset if print/edit) */ if ( DrawingOption!=DRAW_FOR_PRINT && !EditDatas.ModeEdit ) sprintf(BufTxt,Timer->DisplayFormat,(float)Timer->Value/(float)Timer->Base); else sprintf(BufTxt,Timer->DisplayFormat,(float)Timer->Preset/(float)Timer->Base);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv2-2-Width,y+Height,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y, Width*2, Height*2, BufTxt );#endif break; case ELE_MONOSTABLE: if (DrawingOption==DRAW_FOR_TOOLBAR) break; Monostable = &MonostableArray[Element.VarNum]; /* the box */ gdk_draw_rectangle(DrawPixmap, drawing_area->style->white_gc, TRUE, x+WidDiv3-Width, y+HeiDiv3, Width+1*WidDiv3, Height+1*HeiDiv3); gdk_draw_rectangle(DrawPixmap, DynaGcOff, FALSE, x+WidDiv3-Width, y+HeiDiv3, Width+1*WidDiv3, Height+1*HeiDiv3); /* input */ gdk_draw_line(DrawPixmap, (Monostable->Input)?DynaGcOn:DynaGcOff, x-Width,y+HeiDiv2, x-Width+WidDiv3,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1,"I^",2);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1, -1, -1, "I^" );#endif /* output : running */ gdk_draw_line(DrawPixmap, (Monostable->OutputRunning)?DynaGcOn:DynaGcOff, x+WidDiv3*2,y+HeiDiv2, x+Width,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1,"R",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1, -1, -1, "R" );#endif /* Monostable Number */ sprintf(BufTxt,"M%d",Element.VarNum);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv2-Width,y+HeiDiv4-2,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+WidDiv2-Width,y+HeiDiv4+2, -1, -1, BufTxt );#endif /* Current Value (or Preset if print/edit) */ if ( DrawingOption!=DRAW_FOR_PRINT && !EditDatas.ModeEdit ) sprintf(BufTxt,Monostable->DisplayFormat,(float)Monostable->Value/(float)Monostable->Base); else sprintf(BufTxt,Monostable->DisplayFormat,(float)Monostable->Preset/(float)Monostable->Base);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv2-2-Width,y+Height,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y, Width*2, Height*2, BufTxt );#endif break; case ELE_COUNTER: if (DrawingOption==DRAW_FOR_TOOLBAR) break; Counter = &CounterArray[Element.VarNum]; /* the box */ gdk_draw_rectangle(DrawPixmap, drawing_area->style->white_gc, TRUE, x+WidDiv3-Width, y+HeiDiv3, Width+1*WidDiv3, 3*Height+1*HeiDiv3); gdk_draw_rectangle(DrawPixmap, DynaGcOff, FALSE, x+WidDiv3-Width, y+HeiDiv3, Width+1*WidDiv3, 3*Height+1*HeiDiv3); /* input : reset */ gdk_draw_line(DrawPixmap, (Counter->InputReset)?DynaGcOn:DynaGcOff, x-Width,y+HeiDiv2, x-Width+WidDiv3,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1,"R",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y+HeiDiv2-1, -1, -1, "R" );#endif /* input : preset */ gdk_draw_line(DrawPixmap, (Counter->InputPreset)?DynaGcOn:DynaGcOff, x-Width,y+HeiDiv2+Height, x-Width+WidDiv3,y+HeiDiv2+Height);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1+Height,"P",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y+HeiDiv2-1+Height, -1, -1, "P" );#endif /* input : count up */ gdk_draw_line(DrawPixmap, (Counter->InputCountUp)?DynaGcOn:DynaGcOff, x-Width,y+HeiDiv2+Height*2, x-Width+WidDiv3,y+HeiDiv2+Height*2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1+Height*2,"U",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y+HeiDiv2-1+Height*2, -1, -1, "U" );#endif /* input : count down */ gdk_draw_line(DrawPixmap, (Counter->InputCountDown)?DynaGcOn:DynaGcOff, x-Width,y+HeiDiv2+Height*3, x-Width+WidDiv3,y+HeiDiv2+Height*3);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x-Width,y+HeiDiv2-1+Height*3,"D",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y+HeiDiv2-1+Height*3, -1, -1, "D" );#endif /* output : empty */ gdk_draw_line(DrawPixmap, (Counter->OutputEmpty)?DynaGcOn:DynaGcOff, x+WidDiv3*2,y+HeiDiv2, x+Width,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1,"E",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1, -1, -1, "E" );#endif /* output : done */ gdk_draw_line(DrawPixmap, (Counter->OutputDone)?DynaGcOn:DynaGcOff, x+WidDiv3*2,y+HeiDiv2+Height, x+Width,y+HeiDiv2+Height);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1+Height,"D",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1+Height, -1, -1, "D" );#endif /* output : full */ gdk_draw_line(DrawPixmap, (Counter->OutputFull)?DynaGcOn:DynaGcOff, x+WidDiv3*2,y+HeiDiv2+Height*2, x+Width,y+HeiDiv2+Height*2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1+Height*2,"F",1);#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+Width-WidDiv4,y+HeiDiv2-1+Height*2, -1, -1, "F" );#endif /* Counter Number */ sprintf(BufTxt,"C%d",Element.VarNum);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv2-Width,y+HeiDiv4-2,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+WidDiv2-Width,y+HeiDiv4+2, -1, -1, BufTxt );#endif /* Current Value (or Preset if print/edit) */ if ( DrawingOption!=DRAW_FOR_PRINT && !EditDatas.ModeEdit ) sprintf(BufTxt,"%d",Counter->Value); else sprintf(BufTxt,"%d",Counter->Preset);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv2-2-Width,y+Height,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x-Width, y, Width*2, Height*2, BufTxt );#endif break; case ELE_COMPAR: if (DrawingOption==DRAW_FOR_TOOLBAR) break; /* the box */ gdk_draw_rectangle(DrawPixmap, drawing_area->style->white_gc, TRUE, x+WidDiv3-(Width*2), y+HeiDiv4, Width*2+1*WidDiv3, 2*HeiDiv4); gdk_draw_rectangle(DrawPixmap, DynaGcOff, FALSE, x+WidDiv3-(Width*2), y+HeiDiv4, Width*2+1*WidDiv3, 2*HeiDiv4); /* input */ gdk_draw_line(DrawPixmap, TheGc, x-Width*2,y+HeiDiv2, x-Width*2+WidDiv3,y+HeiDiv2); /* output */ gdk_draw_line(DrawPixmap, TheGc, x+WidDiv3*2,y+HeiDiv2, x+Width,y+HeiDiv2);#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv4-(Width*2)+3,y+HeiDiv4-1,"COMPARE",strlen("COMPARE"));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+WidDiv4-(Width*2)+3, y+HeiDiv4+1, -1, -1, "COMPARE" );#endif /* arithmetic expression */ if (!EditDatas.ModeEdit) strcpy(BufTxt,DisplayArithmExpr(ArithmExpr[Element.VarNum].Expr,(Width*2+1*WidDiv3)/8)); else strcpy(BufTxt,DisplayArithmExpr(EditArithmExpr[Element.VarNum].Expr,(Width*2+1*WidDiv3)/8));#ifndef GTK2 gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc, x+WidDiv3-(Width*2)+2,y+HeiDiv2+4,BufTxt,strlen(BufTxt));#else DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+WidDiv3-(Width*2)+2,y, -1, Height, BufTxt );#endif break; case ELE_OUTPUT_OPERATE: if (DrawingOption==DRAW_FOR_TOOLBAR) break; /* the box */ gdk_draw_rectangle(DrawPixmap, drawing_area->style->white_gc, TRUE, x+WidDiv3-(Width*2), y+HeiDiv4, Width*2+1*WidDiv3, 2*HeiDiv4); gdk_draw_rectangle(DrawPixmap, DynaGcOff, FALSE, x+WidDiv3-(Width*2), y+HeiDiv4, Width*2+1*WidDiv3, 2*HeiDiv4);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?