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

📄 drawing.c

📁 Source code for an Numeric Cmputer
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Classic Ladder Project *//* Copyright (C) 2001-2003 Marc Le Douarain *//* mavati@club-internet.fr *//* http://www.multimania.com/mavati/classicladder *//* February 2001 *//* ----------- *//* Draw a rung *//* ----------- *//* This library is free software; you can redistribute it and/or *//* modify it under the terms of the GNU Lesser General Public *//* License as published by the Free Software Foundation; either *//* version 2.1 of the License, or (at your option) any later version. *//* This library is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *//* Lesser General Public License for more details. *//* You should have received a copy of the GNU Lesser General Public *//* License along with this library; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <gtk/gtk.h>#include <stdio.h>#include <string.h>#include "classicladder.h"#include "global.h"#include "arithm_eval.h"#include "classicladder_gtk.h"#include "edit.h"#ifdef SEQUENTIAL_SUPPORT#include "drawing_sequential.h"#endif#include "drawing.h"char *DisplayInfo(int Type, int Offset){    static char Buffer[20];    switch (Type) {    case VAR_MEM_BIT:	sprintf(Buffer, "B%d", Offset);	break;    case VAR_TIMER_DONE:	sprintf(Buffer, "T%d,D", Offset);	break;    case VAR_TIMER_RUNNING:	sprintf(Buffer, "T%d,R", Offset);	break;    case VAR_MONOSTABLE_RUNNING:	sprintf(Buffer, "M%d,R", Offset);	break;    case VAR_STEP_ACTIVITY:	sprintf(Buffer, "X%d", Offset);	break;    case VAR_PHYS_INPUT:	sprintf(Buffer, "I%d", Offset);	break;    case VAR_PHYS_OUTPUT:	sprintf(Buffer, "Q%d", Offset);	break;    case VAR_MEM_WORD:	sprintf(Buffer, "W%d", Offset);	break;    case VAR_STEP_TIME:	sprintf(Buffer, "X%d,V", Offset);	break;    default:	sprintf(Buffer, "???");	break;    }    return Buffer;}char *DisplayArithmExpr(char *Expr, int NumCarMax){    static char Buffer[ARITHM_EXPR_SIZE + 30];    char *Ptr = Expr;    int Fill = 0;    Buffer[0] = '\0';    /* null expression ? */    if (Expr[0] == '\0')	return Buffer;    do {	/* start of a variable ? */	if (*Ptr == '@') {	    int NumVar, TypeVar;	    char VarBuffer[20];	    if (IdentifyVariable(Ptr, &NumVar, &TypeVar))		strcpy(VarBuffer, DisplayInfo(NumVar, TypeVar));	    else		strcpy(VarBuffer, "??");	    strcpy(&Buffer[Fill], VarBuffer);	    /* flush until end of a variable */	    do {		Ptr++;	    }	    while (*Ptr != '@');	    Ptr++;	    Fill = Fill + strlen(VarBuffer);	} else {	    Buffer[Fill++] = *Ptr++;	}    }    while (*Ptr != '\0');    Buffer[Fill] = '\0';    /* size limited ? */    if (NumCarMax > 0) {	if (strlen(Buffer) > NumCarMax) {	    Buffer[NumCarMax - 1] = '.';	    Buffer[NumCarMax] = '.';	    Buffer[NumCarMax + 1] = '\0';	}    }    return Buffer;}void DrawElement(GdkPixmap * DrawPixmap, int x, int y, int Width, int Height,    StrElement Element, char DrawForToolBar){    char BufTxt[50];    StrTimer *Timer;    StrMonostable *Monostable;    int WidDiv2 = Width / 2;    int WidDiv3 = Width / 3;    int WidDiv4 = Width / 4;    int HeiDiv2 = Height / 2;    int HeiDiv3 = Height / 3;    int HeiDiv4 = Height / 4;    GdkGC *DynaGcOff;    GdkGC *TheGc;    GdkColor DynaGdkColor;    GdkGC *DynaGcOn;    DynaGdkColor.pixel = 0xFF22FF;    DynaGdkColor.red = 0xFF;    DynaGdkColor.green = 0x22;    DynaGdkColor.blue = 0xFF;    DynaGcOn = gdk_gc_new(DrawPixmap);    gdk_gc_set_foreground(DynaGcOn, &DynaGdkColor);#ifdef THICK_LINE_ELE_ACTIVATED    gdk_gc_set_line_attributes(DynaGcOn, THICK_LINE_ELE_ACTIVATED,	GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);#endif    DynaGcOff = drawing_area->style->black_gc;    /* State with color */    TheGc = drawing_area->style->black_gc;    if ((!DrawForToolBar) && (!EditDatas.ModeEdit) && (Element.DynamicState))	TheGc = DynaGcOn;    if (EditDatas.ModeEdit) {	gdk_gc_unref(DynaGcOn);	DynaGcOn = drawing_area->style->black_gc;    }    /* Drawing - - */    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:    case ELE_OUTPUT_JUMP:    case ELE_OUTPUT_CALL:	gdk_draw_line(DrawPixmap, TheGc,	    x, y + HeiDiv2, x + WidDiv3, y + HeiDiv2);	gdk_draw_line(DrawPixmap, TheGc,	    x + WidDiv3 * 2, y + HeiDiv2, x + Width, y + HeiDiv2);    }    /* Drawing || or () or --- */    switch (Element.Type) {    case ELE_INPUT:    case ELE_INPUT_NOT:    case ELE_RISING_INPUT:    case ELE_FALLING_INPUT:	gdk_draw_line(DrawPixmap, TheGc,	    x + WidDiv3, y + HeiDiv4, x + WidDiv3, y + Height - HeiDiv4);	gdk_draw_line(DrawPixmap, TheGc,	    x + WidDiv3 * 2, y + HeiDiv4, x + WidDiv3 * 2,	    y + Height - HeiDiv4);	break;    case ELE_CONNECTION:	gdk_draw_line(DrawPixmap, TheGc,	    x, y + HeiDiv2, x + Width, y + HeiDiv2);/*                           gdk_draw_rectangle (DrawPixmap,                                               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, drawing_area->style->white_gc, TRUE,	    x + WidDiv4, y + HeiDiv2 - 1, WidDiv2, 3);	/* draw the 2 arcs of the outputs */	gdk_draw_arc(DrawPixmap, TheGc, FALSE,	    x + WidDiv4, y + WidDiv4, WidDiv2, HeiDiv2, (90 + 20) * 64,	    150 * 64);	gdk_draw_arc(DrawPixmap, TheGc, FALSE, x + WidDiv4, y + WidDiv4,	    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:	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    TheGc, x + WidDiv3 + 2, y + HeiDiv3 * 2, "S", 1);	break;    case ELE_OUTPUT_RESET:	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    TheGc, x + WidDiv3 + 2, y + HeiDiv3 * 2, "R", 1);	break;    case ELE_OUTPUT_JUMP:	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    TheGc, x + WidDiv3 + 2, y + HeiDiv3 * 2, "J", 1);	break;    case ELE_OUTPUT_CALL:	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    TheGc, x + WidDiv3 + 2, y + HeiDiv3 * 2, "C", 1);	break;    }    /* Drawing complex ones : Timer, Monostable, Compar, Operate */    switch (Element.Type) {    case ELE_TIMER:	if (DrawForToolBar)	    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);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x - Width, y + HeiDiv2 - 1, "I",	    1);	/* output : done */	gdk_draw_line(DrawPixmap, (Timer->OutputDone) ? DynaGcOn : DynaGcOff,	    x + WidDiv3 * 2, y + HeiDiv2, x + Width, y + HeiDiv2);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x + Width - WidDiv4,	    y + HeiDiv2 - 1, "D", 1);	/* output : running */	gdk_draw_line(DrawPixmap,	    (Timer->OutputRunning) ? DynaGcOn : DynaGcOff, x + WidDiv3 * 2,	    y + HeiDiv2 + Height, x + Width, y + HeiDiv2 + Height);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x + Width - WidDiv4,	    y + HeiDiv2 - 1 + Height, "R", 1);	/* Timer Number */	sprintf(BufTxt, "T%d", Element.VarNum);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x + WidDiv2 - Width,	    y + HeiDiv4 - 2, BufTxt, strlen(BufTxt));	/* Current Value */	if (!EditDatas.ModeEdit) {	    sprintf(BufTxt, Timer->DisplayFormat,		(float) Timer->Value / (float) Timer->Base);	    gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),		drawing_area->style->black_gc, x + WidDiv2 - 2 - Width,		y + Height, BufTxt, strlen(BufTxt));	}	break;    case ELE_MONOSTABLE:	if (DrawForToolBar)	    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);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x - Width, y + HeiDiv2 - 1, "I^",	    2);	/* output : running */	gdk_draw_line(DrawPixmap,	    (Monostable->OutputRunning) ? DynaGcOn : DynaGcOff,	    x + WidDiv3 * 2, y + HeiDiv2, x + Width, y + HeiDiv2);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x + Width - WidDiv4,	    y + HeiDiv2 - 1, "R", 1);	/* Monostable Number */	sprintf(BufTxt, "M%d", Element.VarNum);	gdk_draw_text(DrawPixmap, gtk_style_get_font(drawing_area->style),	    drawing_area->style->black_gc, x + WidDiv2 - Width,	    y + HeiDiv4 - 2, BufTxt, strlen(BufTxt));	/* Current Value */	if (!EditDatas.ModeEdit) {	    sprintf(BufTxt, Monostable->DisplayFormat,		(float) Monostable->Value / (float) Monostable->Base);

⌨️ 快捷键说明

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