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

📄 classicladder_gtk.c

📁 电路仿真程序 Classic Ladder is coded 100% in C.It can be used for educational purposes or anything you wan
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Classic Ladder Project *//* Copyright (C) 2001 Marc Le Douarain *//* mavati@club-internet.fr *//* http://www.multimania.com/mavati/classicladder *//* February 2001 *//* Last update : 22 January 2002 *//* ---------------------------- *//* GTK Interface & Main *//* Inspired from the scribble example. *//* ---------------------------------- *//* 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 "classicladder_gtk.h"GdkPixmap *pixmap = NULL;GtkWidget *drawing_area;GtkWidget *chkvar[40];GtkWidget *EntryVarSpy[3*2];int VarSpy[3][2] = { {VAR_MEM_WORD,0}, {VAR_MEM_WORD,1}, {VAR_MEM_WORD,2} }; /* defaults vars to spy */GtkWidget *entrylabel,*entrycomment;GtkWidget *ButtonPrev,*ButtonNext,*ButtonRunStop;GtkWidget *FileSelector;GtkWidget *ConfirmDialog;char LadderDirectory[400] = "example/";#include "drawing.h"#include "vars_access.h"#include "calc.h"#include "files.h"#include "edit.h"#include "edit_gtk.h"#include "editproperties_gtk.h"/* Create a new backing pixmap of the appropriate size */static gint configure_event( GtkWidget         *widget,                            GdkEventConfigure *event ){    if (pixmap)        gdk_pixmap_unref(pixmap);    pixmap = gdk_pixmap_new(widget->window,                            widget->allocation.width,                            widget->allocation.height,                            -1);    gdk_draw_rectangle (pixmap,                        widget->style->white_gc,                        TRUE,                        0, 0,                        widget->allocation.width,                        widget->allocation.height);    return TRUE;}/* Redraw the screen from the backing pixmap */static gint expose_event( GtkWidget      *widget,                        GdkEventExpose *event ){    gdk_draw_pixmap(widget->window,                    widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                    pixmap,                    event->area.x, event->area.y,                    event->area.x, event->area.y,                    event->area.width, event->area.height);    return FALSE;}/* Draw a rectangle on the screen *//*static void draw_brush( GtkWidget *widget,                        gdouble    x,                        gdouble    y){    GdkRectangle update_rect;    update_rect.x = x - 5;    update_rect.y = y - 5;    update_rect.width = 100;    update_rect.height = 100;    gdk_draw_rectangle (pixmap,                        widget->style->black_gc,                        TRUE,                        update_rect.x, update_rect.y,                        update_rect.width, update_rect.height);    gtk_widget_draw (widget, &update_rect);}*/static gint button_press_event( GtkWidget      *widget,                                GdkEventButton *event ){    if (EditDatas.ModeEdit)    {        if (event->button == 1 && pixmap != NULL)            EditElementInRung(event->x,event->y);    }    return TRUE;}static gint chkvar_press_event( GtkWidget      *widget, void * var ){    if (gtk_toggle_button_get_active((GtkToggleButton *)widget))        WriteVar(VAR_MEM_BIT,(int)var,1);    else        WriteVar(VAR_MEM_BIT,(int)var,0);    return TRUE;}static gint EntryVarSpy_activate_event(GtkWidget *widget, int * NumVarSpy){    int NewVarType,NewVarOffset;    char BufferVar[30];    strcpy(BufferVar, gtk_entry_get_text((GtkEntry *)widget) );    if (TextParserForAVar(BufferVar , &NewVarType, &NewVarOffset))    {        *NumVarSpy++ = NewVarType;        *NumVarSpy = NewVarOffset;    }    else    {        int OldType,OldOffset;        OldType = *NumVarSpy++;        OldOffset = *NumVarSpy;        /* put back old correct var */        gtk_entry_set_text((GtkEntry *)widget,DisplayInfo(OldType,OldOffset));    }    return TRUE;}void refresh_label_comment(StrRung * RfhRung){    gtk_entry_set_text((GtkEntry *)entrylabel,RfhRung->Label);    gtk_entry_set_text((GtkEntry *)entrycomment,RfhRung->Comment);}void clear_label_comment(){    gtk_entry_set_text((GtkEntry *)entrylabel,"");    gtk_entry_set_text((GtkEntry *)entrycomment,"");}void save_label_comment_edited(){    strcpy(EditDatas.Rung.Label,gtk_entry_get_text((GtkEntry *)entrylabel));    strcpy(EditDatas.Rung.Comment,gtk_entry_get_text((GtkEntry *)entrycomment));}void ButtonPrev_click(){    if (InfosGene->CurrentRung!=InfosGene->FirstRung)    {        InfosGene->CurrentRung = RungArray[InfosGene->CurrentRung].PrevRung;        refresh_label_comment(&RungArray[InfosGene->CurrentRung]);        DrawRung(&RungArray[InfosGene->CurrentRung],TRUE);    }}void ButtonNext_click(){    if (InfosGene->CurrentRung!=InfosGene->LastRung)    {        InfosGene->CurrentRung = RungArray[InfosGene->CurrentRung].NextRung;        refresh_label_comment(&RungArray[InfosGene->CurrentRung]);        DrawRung(&RungArray[InfosGene->CurrentRung],TRUE);    }}void autorize_prevnext_buttons(int Yes){    if (Yes)    {        gtk_widget_show(ButtonPrev);        gtk_widget_show(ButtonNext);    }    else    {        gtk_widget_hide(ButtonPrev);        gtk_widget_hide(ButtonNext);    }}void ButtonRunStop_click(){    if (InfosGene->LadderState==STATE_RUN)    {        InfosGene->LadderState = STATE_STOP;        gtk_label_set_text(GTK_LABEL(GTK_BIN(ButtonRunStop)->child),"Run");    }    else    {        InfosGene->LadderState = STATE_RUN;        gtk_label_set_text(GTK_LABEL(GTK_BIN(ButtonRunStop)->child),"Stop");    }}void StoreDirectorySelected(GtkFileSelection *selector){    char * TempDir;    TempDir = gtk_file_selection_get_filename (GTK_FILE_SELECTION(FileSelector));    strcpy(LadderDirectory,TempDir);    if (strlen(LadderDirectory)>1)    {        if (LadderDirectory[strlen(LadderDirectory)-1]!='/')        {            char * End = &LadderDirectory[strlen(LadderDirectory)-1];            do            {                End--;            }            while(*End!='/');            End++;            *End = '\0';        }    }printf("DIRECTORY = %s\n",LadderDirectory);}void LoadNewLadder(){    StoreDirectorySelected(GTK_FILE_SELECTION(FileSelector));    if (InfosGene->LadderState==STATE_RUN)        ButtonRunStop_click();    InfosGene->LadderState = STATE_LOADING;    LoadAllLadderDatas(LadderDirectory,0,0);    DrawRung(&RungArray[InfosGene->CurrentRung],TRUE);    refresh_label_comment(&RungArray[InfosGene->CurrentRung]);    InfosGene->LadderState = STATE_STOP;}void ButtonSave_click(){    SaveAllLadderDatas(LadderDirectory);}void SaveAsLadder(void){    StoreDirectorySelected(GTK_FILE_SELECTION(FileSelector));    SaveAllLadderDatas(LadderDirectory);}void CreateFileSelection(char * Prompt,int Save){    /* From the example in gtkfileselection help */    /* Create the selector */    FileSelector = gtk_file_selection_new(Prompt);    if (Save)        gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->ok_button),                            "clicked", GTK_SIGNAL_FUNC (SaveAsLadder), NULL);    else        gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->ok_button),                           "clicked", GTK_SIGNAL_FUNC (LoadNewLadder), NULL);    /* Ensure that the dialog box is destroyed when the user clicks a button. */    gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->ok_button),                                           "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),                                           (gpointer) FileSelector);    gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION(FileSelector)->cancel_button),                                           "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy),                                           (gpointer) FileSelector);   /* Display that dialog */   gtk_widget_show (FileSelector);}void ButtonNew_click(){    ShowConfirmationBox("New","Do you really want to clear all datas ?",InitAllLadderDatas);}void ButtonLoad_click(){    CreateFileSelection("Please select the directory to load",FALSE);}void ButtonSaveAs_click(){    CreateFileSelection("Please select the directory where to save",TRUE);}void ButtonAbout_click(){    /* From the example in gtkdialog help */    GtkWidget *dialog, *label, *okay_button;    /* Create the widgets */    dialog = gtk_dialog_new();    label = gtk_label_new ("ClassicLadder v" RELEASE_VER_STRING "\n" RELEASE_DATE_STRING "\n"                           "Copyright (C) 2001 Marc Le Douarain\nmavati@club-internet.fr\n"                           "   http://www.sourceforge.net/projects/classicladder   \n"                           "Released under the terms of the\nGNU Lesser General Public License v2.1");    okay_button = gtk_button_new_with_label("Okay");    /* Ensure that the dialog box is destroyed when the user clicks ok. */    gtk_signal_connect_object (GTK_OBJECT (okay_button), "clicked",                               GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT(dialog));    gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),                       okay_button);    gtk_widget_grab_focus(okay_button);    /* Add the label, and show everything we've added to the dialog. */    gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),                       label);    gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);    gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);    gtk_widget_show_all (dialog);}void ShowMessageBox(char * title,char * text,char * button)

⌨️ 快捷键说明

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