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

📄 graph_c.cc

📁 certi-SHM-3.0.tar 不错的开源的分布式方针软件 大家多多支持 他是linux
💻 CC
📖 第 1 页 / 共 4 页
字号:
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- // ---------------------------------------------------------------------------// libgraphc - X11 drawing library// Copyright (C) 2002, 2003  ONERA//// 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 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 program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA//// $Id: graph_c.cc,v 3.3 2003/02/19 17:20:28 breholee Exp $ // ---------------------------------------------------------------------------#ifdef WITH_X11#include <config.h>#include <X11/Xlib.h>#include <X11/Xutil.h> #include <X11/cursorfont.h> #include "graph_c.hh"#include <X11/bitmaps/cntr_ptr>#include <X11/bitmaps/dot>#include <X11/bitmaps/dropbar8>#include <X11/bitmaps/left_ptr> #include <X11/bitmaps/right_ptr>#include <X11/bitmaps/menu16>#include <X11/bitmaps/opendotMask>#include <X11/bitmaps/star>#include <X11/bitmaps/xlogo16>#include <stdio.h>#include <string.h>#include <stdlib.h>/*---------------------------------------------------------------------------*//*    definition des variables globales                                      *//*---------------------------------------------------------------------------*/   static Display       *canal_aff;   static GC            contexte_graph;   static Window        nouv_fen;     static Pixmap        damier;   static XEvent        evenem;    static XGCValues     val_gc;   static unsigned long masq_bin;    static unsigned long masq_attrib;   static XSetWindowAttributes xswa;   static XColor        couleu;   /* composante RVB ,donne la valeur de pixel				     en retour */   static XColor        exact;    /* definition RVB exacte souhaitee */   static Status        code_ret;                static Colormap      palette;  /* id de la palette de couleurs par defaut				     de l ecran */    static unsigned long carrplan;   static unsigned long cavplan;    static const char         * nom_coul;   static mode_remp     b;    static style         c;//   static policecar     d;   //   static taillecar     t;   static KeySym        touche;     static Font          fonte;   static Cursor        curseur;      /*---definition des styles de pointilles-----*/  /*===========================================*/   static char dots1 [] = {5,5};    /* 5 pixels lumineux puis 5 eteints */   static char dots2 [] = {20,10};   static char dots3 [] = {20,2};/*---------------------------------------------------------------------------*//*    definition des procedures et des fonctions globales                    *//*---------------------------------------------------------------------------*/   static const char * rech(couleur a);   static void rempli(mode_remp b);     static void lignestyle(style c);    static void choixfonte(policecar d,taillecar t); /*---------------------------------------------------------------------------*//*    body des procedures et des fonctions globales                          *//*---------------------------------------------------------------------------*/                /*----recherche chaine de caracteres identifiant la couleur-----*/ /*==============================================================*/static const char * rech(couleur a)   {  const char * nom_coub;    switch(a) {  case BLACK:   nom_coub = "Black";   break;  case RED:     nom_coub = "Red";     break;  case GREEN:   nom_coub = "Green";   break;  case BLUE:    nom_coub = "Blue";    break;  case GRAY:    nom_coub = "Gray";    break;  case CYAN:    nom_coub = "Cyan";    break;  case YELLOW:  nom_coub = "Yellow";  break;  case MAGENTA: nom_coub = "Magenta"; break;  case BROWN:   nom_coub = "Brown";   break;  case ORANGE:  nom_coub = "Orange";  break;  case PINK:    nom_coub = "Pink";    break;  case VIOLET:  nom_coub = "Violet";  break;  case WHITE:   nom_coub = "White";   break;  default:      nom_coub = "Black";  }    return nom_coub;}        /*---------------------------------------------------------------------------*/ /*-----affectation du mode de remplissage au contexte graphique---*/ /*================================================================*/                                    static void rempli(mode_remp b)  {                       int i;     i = 0;     if(b == COUL_UNIE)      XSetFillStyle(canal_aff,                    contexte_graph,                    FillSolid) ;            if(b == MOTIF1)  {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)cntr_ptr_bits,                                     cntr_ptr_width,                                     cntr_ptr_height);       i = 1; }        if(b == MOTIF2)  {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)dot_bits,                                     dot_width,                                     dot_height);      i = 1; }      if(b == MOTIF3)  {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)dropbar8_bits,                                     dropbar8_width,                                     dropbar8_height);       i = 1; }     if(b == MOTIF4)   {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)left_ptr_bits,                                     left_ptr_width,                                     left_ptr_height);      i = 1; }     if(b == MOTIF5)   {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)right_ptr_bits,                                     right_ptr_width,                                     right_ptr_height);         i = 1; }        if(b == MOTIF6)   {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)menu16_bits,                                     menu16_width,                                     menu16_height);        i = 1; }     if(b == MOTIF7)   {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)opendotMask_bits,                                     opendotMask_width,                                     opendotMask_height);       i = 1; }     if(b == MOTIF8)   {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)star_bits,                                     star_width,                                     star_height);       i = 1; }      if(b == MOTIF9)   {     damier = XCreateBitmapFromData(canal_aff,                                     nouv_fen,(const char *)xlogo16_bits,                                     xlogo16_width,                                     xlogo16_height);        i = 1; }                                        if(i == 1) {     XSetStipple(canal_aff,                  contexte_graph,                  damier);     XSetFillStyle(canal_aff,                    contexte_graph,                    FillOpaqueStippled); }     } /*---------------------------------------------------------------------------*/ /*---affectation de la police de caractere au contexte graphique--*/ /*================================================================*/                                    static void choixfonte(policecar d, taillecar t)  {              if(t == TAILLE8) {     if(d == COURIER)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-r-normal--8-80-75-75-m-50-iso8859-1");                   if(d == COURIER_GRAS)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-r-normal--8-80-75-75-m-50-iso8859-1");     if(d == COURIER_OBLIQUE)       fonte = XLoadFont(canal_aff,                       "-adobe-courier-medium-o-normal--8-80-75-75-m-50-iso8859-1");     if(d == COURIER_GRAS_OBLIQUE)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-o-normal--8-80-75-75-m-50-iso8859-1");     if(d == HELVETICA)        fonte = XLoadFont(canal_aff,			 "-adobe-helvetica-bold-o-normal--8-80-75-75-p-50-iso8859-1");      if(d == TIMES)        fonte = XLoadFont(canal_aff,			 "-adobe-times-bold-i-normal--8-80-75-75-p-47-iso8859-1");      if(d == SYMBOL)        fonte = XLoadFont(canal_aff,			 "-adobe-symbol-medium-r-normal--8-80-75-75-p-51-adobe-fontspecific");    }      if(t == TAILLE10) {     if(d == COURIER)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1");                   if(d == COURIER_GRAS)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1");          if(d == COURIER_OBLIQUE)       fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-o-normal--10-100-75-75-m-60-iso8859-1");          if(d == COURIER_GRAS_OBLIQUE)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-o-normal--10-100-75-75-m-60-iso8859-1");          if(d == HELVETICA)        fonte = XLoadFont(canal_aff,			 "-adobe-helvetica-bold-o-normal--10-100-75-75-p-60-iso8859-1");           if(d == TIMES)        fonte = XLoadFont(canal_aff,			 "-adobe-times-bold-i-normal--10-100-75-75-p-61-iso8859-1");           if(d == SYMBOL)      fonte = XLoadFont(canal_aff,                       "-adobe-symbol-medium-r-normal--10-100-75-75-p-61-adobe-fontspecific");    }         if(t == TAILLE12) {     if(d == COURIER)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1");          if(d == COURIER_GRAS)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1");          if(d == COURIER_OBLIQUE)               fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-o-normal--12-120-75-75-m-70-iso8859-1");          if(d == COURIER_GRAS_OBLIQUE)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1");          if(d == HELVETICA)        fonte = XLoadFont(canal_aff,			 "-adobe-helvetica-bold-o-normal--12-120-75-75-p-69-iso8859-1");           if(d == TIMES)        fonte = XLoadFont(canal_aff,			 "-adobe-times-bold-i-normal--12-120-75-75-p-68-iso8859-1");           if(d == SYMBOL)        fonte = XLoadFont(canal_aff,			 "-adobe-symbol-medium-r-normal--12-120-75-75-p-74-adobe-fontspecific");    }      if(t == TAILLE14) {     if(d == COURIER)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-r-normal--14-140-75-75-m-90-iso8859-1");          if(d == COURIER_GRAS)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-r-normal--14-140-75-75-m-90-iso8859-1");          if(d == COURIER_OBLIQUE)       fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-o-normal--14-140-75-75-m-90-iso8859-1");          if(d == COURIER_GRAS_OBLIQUE)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-o-normal--14-140-75-75-m-90-iso8859-1");          if(d == HELVETICA)        fonte = XLoadFont(canal_aff,			 "-adobe-helvetica-bold-o-normal--14-140-75-75-p-82-iso8859-1");           if(d == TIMES)        fonte = XLoadFont(canal_aff,			 "-adobe-times-bold-i-normal--14-140-75-75-p-77-iso8859-1");           if(d == SYMBOL)        fonte = XLoadFont(canal_aff,			 "-adobe-symbol-medium-r-normal--14-140-75-75-p-85-adobe-fontspecific");    }      if(t == TAILLE18) {     if(d == COURIER)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-r-normal--18-180-75-75-m-110-iso8859-1");          if(d == COURIER_GRAS)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1");     if(d == COURIER_OBLIQUE)       fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-o-normal--18-180-75-75-m-110-iso8859-1");     if(d == COURIER_GRAS_OBLIQUE)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-o-normal--18-180-75-75-m-110-iso8859-1");          if(d == HELVETICA)        fonte = XLoadFont(canal_aff,			 "-adobe-helvetica-bold-o-normal--18-180-75-75-p-104-iso8859-1");           if(d == TIMES)        fonte = XLoadFont(canal_aff,			 "-adobe-times-bold-i-normal--18-180-75-75-p-98-iso8859-1");           if(d == SYMBOL)        fonte = XLoadFont(canal_aff,			 "-adobe-symbol-medium-r-normal--18-180-75-75-p-107-adobe-fontspecific");    }      if(t == TAILLE24) {     if(d == COURIER)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-r-normal--24-240-75-75-m-150-iso8859-1");          if(d == COURIER_GRAS)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1");          if(d == COURIER_OBLIQUE)       fonte = XLoadFont(canal_aff,			 "-adobe-courier-medium-o-normal--24-240-75-75-m-150-iso8859-1");          if(d == COURIER_GRAS_OBLIQUE)        fonte = XLoadFont(canal_aff,			 "-adobe-courier-bold-o-normal--24-240-75-75-m-150-iso8859-1");          if(d == HELVETICA)        fonte = XLoadFont(canal_aff,			 "-adobe-helvetica-bold-o-normal--24-240-75-75-p-138-iso8859-1");           if(d == TIMES)        fonte = XLoadFont(canal_aff,			 "-adobe-times-bold-i-normal--24-240-75-75-p-128-iso8859-1");           if(d == SYMBOL)        fonte = XLoadFont(canal_aff,			 "-adobe-symbol-medium-r-normal--24-240-75-75-p-142-adobe-fontspecific");    }         XSetFont(canal_aff,	     contexte_graph,	     fonte);}/*---------------------------------------------------------------------------*/    /*-----affectation du style de ligne au contexte graphique---*/ /*===========================================================*/                                    static void lignestyle(style c)  {           if(c == PLEIN)     XSetLineAttributes(canal_aff,                         contexte_graph,                         5,                         LineSolid,                         CapButt,                         JoinMiter);     if(c == POINTILLE1)       { XSetDashes(canal_aff,                   contexte_graph,                   0,                   dots1,                   2);     XSetLineAttributes(canal_aff,                         contexte_graph,                         5,                         LineOnOffDash,                         CapButt,                         JoinMiter); };          if(c == POINTILLE2)     { XSetDashes(canal_aff,                   contexte_graph,                   0,                   dots2,                   2);     XSetLineAttributes(canal_aff,                         contexte_graph,                         5,                         LineOnOffDash,                         CapButt,                         JoinMiter); };     if(c == POINTILLE3)     { XSetDashes(canal_aff,                   contexte_graph,                   0,                   dots3,                   2);     XSetLineAttributes(canal_aff,                         contexte_graph,                         5,                         LineOnOffDash,                         CapButt,                         JoinMiter); };}  /*---------------------------------------------------------------------------*//*==================================================*//*      corps des fonctions et des procedures       *//*               figures simples                    *//*==================================================*/                /*---module POINT-----*/ /*====================*/pointt Definex(point    COORD,                couleur  WCOULEUR) {       pointt Pointloc;       Pointloc.POI_COORD   = COORD;       Pointloc.POI_COULEUR = WCOULEUR;       return  Pointloc;  }      void Drawx(pointt P)  {           nom_coul =  rech(P.POI_COULEUR);     code_ret = XAllocNamedColor(canal_aff,                                  palette,                                  nom_coul,                                  &couleu,                                  &exact);      masq_bin = GCForeground | GCFillStyle;      val_gc.foreground = couleu.pixel;      val_gc.fill_style = FillSolid;        XChangeGC(canal_aff,                contexte_graph,                masq_bin,                &val_gc);       XDrawPoint(canal_aff,                nouv_fen,                contexte_graph,                P.POI_COORD.X,                P.POI_COORD.Y);     XFlush(canal_aff);  }    void Undrawx(pointt P)  {                                  masq_bin = GCForeground | GCFillStyle;      val_gc.foreground = carrplan;     val_gc.fill_style = FillSolid;         XChangeGC(canal_aff,                contexte_graph,                masq_bin,                &val_gc);       XDrawPoint(canal_aff,                nouv_fen,                contexte_graph,                P.POI_COORD.X,                P.POI_COORD.Y);     XFlush(canal_aff);                    }  void Change_attribx(pointt   *P,                     couleur  WCOULEUR)  {                              Undrawx(*P);      P->POI_COULEUR   = WCOULEUR;       Drawx(*P);  }void Movex(pointt *P,             point  COORD) {      Undrawx(*P);       P->POI_COORD = COORD;      Drawx(*P);}       void Duplicx(pointt P,

⌨️ 快捷键说明

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