drawing.c

来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,006 行 · 第 1/3 页

C
1,006
字号
            /* 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,"OPERATE",strlen("OPERATE"));#else			DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x+WidDiv4-(Width*2)+3, y+HeiDiv4+1, -1, -1, "OPERATE" );#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;    }    /* Drawing Var */    if (DrawingOption!=DRAW_FOR_TOOLBAR)    {        switch(Element.Type)        {            case ELE_INPUT:            case ELE_INPUT_NOT:            case ELE_RISING_INPUT:            case ELE_FALLING_INPUT:            case ELE_OUTPUT:            case ELE_OUTPUT_NOT:            case ELE_OUTPUT_SET:            case ELE_OUTPUT_RESET:                strcpy(BufTxt,DisplayInfo(Element.VarType,Element.VarNum));#ifndef GTK2                gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc,                                x+WidDiv4,y+HeiDiv4-2,BufTxt,strlen(BufTxt));#else				DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x, y+HeiDiv4+1, Width, -1, BufTxt );#endif                break;            case ELE_OUTPUT_JUMP:#ifndef GTK2                gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc,                                x+1,y+HeiDiv4-2,RungArray[Element.VarNum].Label,                                strlen(RungArray[Element.VarNum].Label));#else				DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x, y+HeiDiv4+1, Width, -1, RungArray[Element.VarNum].Label );#endif                break;            case ELE_OUTPUT_CALL:                sprintf( BufTxt, "SR%d", Element.VarNum );#ifndef GTK2                gdk_draw_text(DrawPixmap, drawing_area->style->font, drawing_area->style->black_gc,                                x+1,y+HeiDiv4-2,BufTxt,strlen(BufTxt));#else				DrawTextGTK2( DrawPixmap, drawing_area->style->black_gc, x, y+HeiDiv4+1, Width, -1, BufTxt );#endif                break;        }    }    /* Drawing cnx with top */    if (Element.ConnectedWithTop)    {        if (Element.DynamicInput)            gdk_draw_line(DrawPixmap, DynaGcOn,                x,y+HeiDiv2 +1, x,y-HeiDiv2);        else            gdk_draw_line(DrawPixmap, drawing_area->style->black_gc,                x,y+HeiDiv2, x,y-HeiDiv2);    }    /* specials used for Editor */    if (DrawingOption==DRAW_FOR_TOOLBAR)    {        switch(Element.Type)        {            case EDIT_CNX_WITH_TOP:                gdk_draw_line(DrawPixmap, drawing_area->style->black_gc,                    x+WidDiv2,y+HeiDiv4, x+WidDiv2,y+Height-HeiDiv4);                break;            case EDIT_LONG_CONNECTION:                gdk_draw_line(DrawPixmap, TheGc,                                x,y+HeiDiv2, x+Width-1,y+HeiDiv2);                gdk_draw_line(DrawPixmap, TheGc,                                x+3*WidDiv4-1,y+HeiDiv4, x+Width-1,y+HeiDiv2);                gdk_draw_line(DrawPixmap, TheGc,                                x+3*WidDiv4-1,y+3*HeiDiv4, x+Width-1,y+HeiDiv2);                gdk_draw_line(DrawPixmap, TheGc,                                x+3*WidDiv4-1,y+HeiDiv4, x+3*WidDiv4 +3,y+HeiDiv2);                gdk_draw_line(DrawPixmap, TheGc,                                x+3*WidDiv4 +3,y+HeiDiv2, x+3*WidDiv4-1,y+3*HeiDiv4);                break;            /* little display used for the toolbar */            case ELE_TIMER:            case ELE_MONOSTABLE:            case ELE_COUNTER:                {                    char * Letter = "T";                    if ( Element.Type==ELE_MONOSTABLE )                        Letter = "M";                    if ( Element.Type==ELE_COUNTER )                        Letter = "C";                    gdk_draw_rectangle(DrawPixmap, drawing_area->style->black_gc, FALSE,                                    x+WidDiv4, y+HeiDiv4,                                    Width-2*WidDiv4, Height-2*HeiDiv4);#ifndef GTK2                    gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc,                            x+WidDiv3+2,y+HeiDiv3*2,Letter,1);#else				    DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, Letter );#endif                }                break;            case ELE_COMPAR:                gdk_draw_rectangle(DrawPixmap, drawing_area->style->black_gc, FALSE,                                    x+WidDiv4, y+HeiDiv4,                                    Width-2*WidDiv4, Height-2*HeiDiv4);#ifndef GTK2                gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc,                            x+WidDiv3+2,y+HeiDiv3*2,">",1);#else				DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, ">" );#endif                break;            case ELE_OUTPUT_OPERATE:                gdk_draw_rectangle(DrawPixmap, drawing_area->style->black_gc, FALSE,                                    x+WidDiv4, y+HeiDiv4,                                    Width-2*WidDiv4, Height-2*HeiDiv4);#ifndef GTK2                gdk_draw_text(DrawPixmap, drawing_area->style->font, TheGc,                            x+WidDiv3+2,y+HeiDiv3*2,"=",1);#else				DrawTextGTK2( DrawPixmap, TheGc, x, y, Width, Height, "=" );#endif                break;            default:                DrawCommonElementForToolbar(DrawPixmap, x, y, Width, Element.Type);                break;        }    }    if (!EditDatas.ModeEdit && DrawingOption!=DRAW_FOR_PRINT )        gdk_gc_unref(DynaGcOn);}void DrawBars( int PosiY, int IsTheCurrentRung ){    GdkColor DynaGdkColor;    GdkGC * DynaGcBarsColor;    DynaGdkColor.pixel = 0xEE5555;    DynaGdkColor.red = 0xEE;    DynaGdkColor.green = 0x55;    DynaGdkColor.blue = 0x55;    if (!IsTheCurrentRung )    {        DynaGcBarsColor = drawing_area->style->black_gc;    }    else    {        DynaGcBarsColor = gdk_gc_new(pixmap);        gdk_gc_set_foreground(DynaGcBarsColor,&DynaGdkColor);    }    gdk_draw_rectangle(pixmap, DynaGcBarsColor, TRUE,                                1, 1+PosiY,                                3, InfosGene->BlockHeight*RUNG_HEIGHT);    gdk_draw_rectangle(pixmap, DynaGcBarsColor, TRUE,                                InfosGene->BlockWidth*RUNG_WIDTH+OFFSET_X, 1+PosiY,                                3, InfosGene->BlockHeight*RUNG_HEIGHT);    if (IsTheCurrentRung )        gdk_gc_unref(DynaGcBarsColor);}void DrawGrid( int PosiY ){    int x,y;    GdkColor DynaGdkColor;    GdkGC * DynaGcOn;    DynaGdkColor.pixel = 0xA0D0D0;    DynaGdkColor.red = 0xA0;    DynaGdkColor.green = 0xD0;    DynaGdkColor.blue = 0xD0;        DynaGcOn = gdk_gc_new(pixmap);    gdk_gc_set_foreground(DynaGcOn,&DynaGdkColor);    for(x=InfosGene->BlockWidth; x<RUNG_WIDTH*InfosGene->BlockWidth; x=x+InfosGene->BlockWidth)    {        gdk_draw_line(pixmap, DynaGcOn,                x+OFFSET_X, OFFSET_Y+PosiY, x+OFFSET_X, RUNG_HEIGHT*InfosGene->BlockHeight+PosiY);    }    for(y=InfosGene->BlockHeight; y<RUNG_HEIGHT*InfosGene->BlockHeight; y=y+InfosGene->BlockHeight)    {        gdk_draw_line(pixmap, DynaGcOn,                OFFSET_X, y+OFFSET_Y+PosiY, RUNG_WIDTH*InfosGene->BlockWidth+OFFSET_X, y+OFFSET_Y+PosiY);    }    gdk_gc_unref(DynaGcOn);}void DrawRungPartition( int PosiY ){    GdkColor DynaGdkColor;    GdkGC * DynaGcOn;    DynaGdkColor.pixel = 0xCCCCCC;    DynaGdkColor.red = 0xCC;    DynaGdkColor.green = 0xCC;    DynaGdkColor.blue = 0xCC;    DynaGcOn = gdk_gc_new(pixmap);    gdk_gc_set_foreground(DynaGcOn,&DynaGdkColor);    gdk_draw_line(pixmap, DynaGcOn,            OFFSET_X,OFFSET_Y+PosiY, RUNG_WIDTH*InfosGene->BlockWidth+OFFSET_X,OFFSET_Y+PosiY);    gdk_gc_unref(DynaGcOn);}void GetTheSizesForRung(){    static int PageHeightBak = 0;    static int BlockHeightBak = 0;    InfosGene->BlockWidth = (GTK_WIDGET(drawing_area)->allocation.width - OFFSET_X -5) / RUNG_WIDTH;	// keep ratio aspect (if defaults values of size block not square)	InfosGene->BlockHeight = InfosGene->BlockWidth*BLOCK_HEIGHT_DEF/BLOCK_WIDTH_DEF;    InfosGene->PageHeight = GTK_WIDGET(drawing_area)->allocation.height - OFFSET_Y;    // used for sequential    InfosGene->PageWidth = GTK_WIDGET(drawing_area)->allocation.width - OFFSET_X;    // size of the page or block changed ?    if ( InfosGene->PageHeight!=PageHeightBak || InfosGene->BlockHeight!=BlockHeightBak )        UpdateVScrollBar();    PageHeightBak = InfosGene->PageHeight;    BlockHeightBak = InfosGene->BlockHeight;}void DrawRung(GdkPixmap * DrawPixmap, StrRung * Rung, int PosiY, int BlockWidth, int BlockHeight, char DrawingOption){    int x,y;    for (y=0;y<RUNG_HEIGHT;y++)    {        for(x=0;x<RUNG_WIDTH;x++)        {            DrawElement(DrawPixmap, x*BlockWidth+OFFSET_X, y*BlockHeight+OFFSET_Y+PosiY, BlockWidth,BlockHeight, Rung->Element[x][y], DrawingOption);        }    }}void DrawRungs(){    int ScanRung = InfosGene->TopRungDisplayed;    int ScanY = InfosGene->OffsetHiddenTopRungDisplayed;    StrRung * PtrRung;    int FlagAddOrInsertRung = FALSE;    int TheEnd = FALSE;    // If we are editing and adding a rung, we set a flag to indicate    // that there is an extra rung to add (before or after current rung)    if ( EditDatas.ModeEdit && EditDatas.DoBeforeFinalCopy == MODE_ADD )    {        // beware not the first rung displayed at the top...        if ( InfosGene->FirstRung!=InfosGene->CurrentRung )        {            if ( ScanRung!=InfosGene->LastRung )                ScanRung = RungArray[ ScanRung ].NextRung;            FlagAddOrInsertRung = TRUE;        }    }    if ( EditDatas.ModeEdit && EditDatas.DoBeforeFinalCopy == MODE_INSERT )        FlagAddOrInsertRung = TRUE;    // Clean all    gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE,                        0, 0, InfosGene->BlockWidth*RUNG_WIDTH+50, InfosGene->PageHeight+50);    for (ScanY = InfosGene->OffsetHiddenTopRungDisplayed*-1; ScanY<InfosGene->PageHeight && !TheEnd; ScanY=ScanY+(InfosGene->BlockHeight*RUNG_HEIGHT))    {        PtrRung = &RungArray[ ScanRung ];        /* displaying the current rung - in edit ? */        if ( ScanRung==InfosGene->CurrentRung && EditDatas.ModeEdit )        {            if ( ( FlagAddOrInsertRung && EditDatas.DoBeforeFinalCopy==MODE_INSERT )                || ( !FlagAddOrInsertRung && EditDatas.DoBeforeFinalCopy==MODE_ADD )                || EditDatas.DoBeforeFinalCopy==MODE_MODIFY )            {                /* grid for edit mode and display the rung under edition */                DrawGrid( ScanY );                PtrRung = &EditDatas.Rung;            }        }        DrawBars( ScanY, ScanRung==InfosGene->CurrentRung );        DrawRung( pixmap, PtrRung, ScanY, InfosGene->BlockWidth, InfosGene->BlockHeight, DRAW_NORMAL );        // if we are adding or inserting a rung, it is as if we have 2 current rungs...        // If inserting : display edited one, then the current.        // if adding : display current, then the edited one.        // Edited one is displayed at the current position (current before... well I hope        // you still follow, because I'm not sure for me ;-) )        if ( ! (ScanRung==InfosGene->CurrentRung  && FlagAddOrInsertRung) )        {            if ( ScanRung!=InfosGene->LastRung )                ScanRung = RungArray[ ScanRung ].NextRung;            else                TheEnd = TRUE;        }        else        {            FlagAddOrInsertRung = FALSE;        }        DrawRungPartition( ScanY + InfosGene->BlockHeight*RUNG_HEIGHT -5 );    }}void DrawCurrentSection( void ){	GdkRectangle update_rect;	int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language;	GetTheSizesForRung();	if ( iCurrentLanguage==SECTION_IN_LADDER )		DrawRungs( );#ifdef SEQUENTIAL_SUPPORT	if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL )		DrawSequentialPage( pixmap, SectionArray[ InfosGene->CurrentSection ].SequentialPage, 0 );#endif	update_rect.x = 0;	update_rect.y = 0;	update_rect.width = GTK_WIDGET(drawing_area)->allocation.width;	update_rect.height = GTK_WIDGET(drawing_area)->allocation.height;	gtk_widget_draw (drawing_area, &update_rect);}

⌨️ 快捷键说明

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