TODOPIC

Lenguajes de programación para PC => C, C#, C++ => Mensaje iniciado por: CompSystems en 30 de Septiembre de 2012, 22:15:25

Título: Un buen libro de C/C++ en castellano y con ejemplos muy didácticos y con GUIs
Publicado por: CompSystems en 30 de Septiembre de 2012, 22:15:25
Hay un libro de programación de lenguaje C y C++ llamado (C y C++ de afán), con muchos ejemplos didacticos, escrito por un profesor de la Universidad de Antioquia (Medellin Colombia) llamado (Manuel José Páez Mejía)

Pueden verlo 100% libremente y por completo en: o buscar en google (C y C ++ de afán)
http://books.google.com.co/books?id=E1CMxC4KKSYC&pg=PA157&lpg=PA157&dq=Manuel+Jos%C3%A9+P%C3%A1ez+Mej%C3%ADa+xgraphics&source=bl&ots=r_ayZLXuqb&sig=nTQMbs8653cKKBc5H4oZN_2bEbM&hl=es&sa=X&ei=Vc5pUJbsNIa09gTbz4HYBw&ved=0CB0Q6AEwAA#v=onepage&q=Manuel%20Jos%C3%A9%20P%C3%A1ez%20Mej%C3%ADa%20xgraphics&f=false

En el capitulo 8, pagina 155, habla sobre Graficacion utilizando una biblioteca llamada Xgraphics.c de muy fácil manejo, pero no logro compilar los ejemplos que muestra el libro, para la cual les solicito por favor me colaboren utilizando un compilador cualesquiera de C/C++ y detectando por que no compila satisfactoriamente.  :(


Esta biblioteca de graficacion Xgraphics.c sirve para crear interfaces gráficas (GUI) simples, para entrar datos con menús y visualizar resultados en ventanas, por que comúnmente la biblioteca I/O de C/C++ es de entrada y salida de datos en forma de texto y lineal, ademas pienso que esta biblioteca se podría portar fácilmente en pantallas para ser utilizadas en conjunto con microcontroladores


Anexo abajo los archivos de Xgraphics.c ,  Xgraphic.h y unos ejemplo de prueba para que traten de compilarlo y detectar fallas
Muchas Gracias

PD: les pregunto que tan importante les parece este libro?
Existe una biblioteca similar a Xgraphics.c para realizar GUI facilmente en C/C++
Título: RE: Un buen libro de C y C++ en castellano y con ejemplos muy didácticos
Publicado por: CompSystems en 30 de Septiembre de 2012, 22:35:22
1er Archivo del proyecto

Xgraphics.c

Código: C++
  1. /*
  2.  
  3. File Name: Xgraphics.c
  4. Version:  1.00 ( 28/04/96 )
  5. By:         Martin Lueders (lueders@physik.uni-wuerzburg.de)
  6.  
  7. Copyright (C)
  8. **  This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by
  9. **  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.
  10. **  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. **  You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
  13. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14.  
  15.  
  16. #include "Xgraphics.h" //
  17.  
  18. void InitX(){
  19.         char **fontlist;
  20.         int  i,count;
  21.         Font myfont;
  22.         char myfontpattern[40];
  23.         XColor col, colexact;
  24.  
  25.         /* set display to value of environment DISPLAY */
  26.         mydisplay=XOpenDisplay("");
  27.         if (mydisplay==NULL){
  28.                 printf("Cannot connect to X Server\n");
  29.                 exit(0);
  30.         }
  31.         myscreen=DefaultScreen(mydisplay);
  32.  
  33.         /* set colors */
  34.         mycmap = DefaultColormap(mydisplay,myscreen);
  35.  
  36.         black=BlackPixel(mydisplay,myscreen);
  37.         white=WhitePixel(mydisplay,myscreen);
  38.         global_color = black;
  39.         global_function = GXcopy;
  40.  
  41.         mygc    = XCreateGC(mydisplay,DefaultRootWindow(mydisplay),0,0);
  42.         cleargc = XCreateGC(mydisplay,DefaultRootWindow(mydisplay),0,0);
  43.         initgc  = XCreateGC(mydisplay,DefaultRootWindow(mydisplay),0,0);
  44.  
  45.         XSetForeground(mydisplay,mygc,black);
  46.         XSetBackground(mydisplay,mygc,white);
  47.  
  48.         XSetForeground(mydisplay,cleargc,white);
  49.         XSetBackground(mydisplay,cleargc,black);
  50.  
  51.         XFlush(mydisplay);
  52.  
  53.         if( DefaultDepth(mydisplay,myscreen) == 1 ) {
  54.  
  55.                 mycolors[0] = white;
  56.                 mycolors[1] = black;
  57.                 NofColors = 2;
  58.  
  59.         } else {
  60.                 if ( DefaultVisual(mydisplay,myscreen)->class < 2 ) {
  61.                         for(i=NofColors=0;i<MAX_COLORS;++i) {
  62.         if (XAllocNamedColor(mydisplay,mycmap,graylist[i],&col,&colexact) )
  63.                 mycolors[NofColors++] = col.pixel;
  64.                         }
  65.                 } else {
  66.                         for(i=NofColors=0;i<MAX_COLORS;++i) {
  67.         if (XAllocNamedColor(mydisplay,mycmap,colorlist[i],&col,&colexact) )
  68.                 mycolors[NofColors++] = col.pixel;
  69.                         }
  70.                 }
  71.         }
  72.  
  73.         /* set default font */
  74.         strcpy(myfontpattern,"-*-helvetica-bold-r-normal--14*");
  75.  
  76.         fontlist = XListFonts(mydisplay,myfontpattern,20,&count);
  77.         if(count) {
  78.                 myfont=XLoadFont(mydisplay,myfontpattern);
  79.                 XSetFont(mydisplay,mygc,myfont);
  80.         } /* if */
  81.         XFreeFontNames(fontlist);
  82.  
  83.         XCopyGC(mydisplay,mygc,-1,initgc);
  84.  
  85.         /* reset internal lists */
  86.  
  87.         worldlist = (struct win_node *) NULL;
  88.         buttonflag = 0;
  89.         buttonlist.buttons = (ButtonType *) NULL;
  90.         buttonlist.NofButtons = 0;
  91. }
  92.  
  93.  
  94. /*=====*\
  95. void ExitX(){
  96.         /* destroy remaining windows */
  97.         while(worldlist) DestroyWindow(worldlist->win);
  98.  
  99.         /* free memory */
  100.         if ( buttonlist.buttons ) free ( buttonlist.buttons );
  101.  
  102.         XFreeGC(mydisplay,mygc);
  103.         XFreeGC(mydisplay,cleargc);
  104.  
  105.         XCloseDisplay(mydisplay);
  106. }
  107.  
  108. /*=====*\
  109.  
  110. /* internal world- and win- handling */
  111.  
  112. struct world_node *make_world_node(){
  113.         return( (struct world_node *) calloc(1,sizeof(struct world_node)) );
  114. }
  115.  
  116. struct win_node *make_win_node(){
  117.         return( (struct win_node *) calloc(1,sizeof(struct win_node)) );
  118. }
  119.  
  120. struct win_node *find_win_node(Window window){
  121.         struct win_node *winptr;
  122.         int notfound=1;
  123.  
  124.         winptr = worldlist;
  125.  
  126.         while(winptr && notfound) {
  127.                 if( winptr->win == window ) notfound = 0;
  128.                 else winptr = winptr->nextwin;
  129.         }
  130.         return winptr;
  131. }
  132.  
  133. struct world_node *find_world_node(World world){
  134.         struct world_node *worldptr;
  135.         int notfound=1;
  136.  
  137.         worldptr = find_win_node(world->win)->nextworld;
  138.  
  139.         while(worldptr && notfound) {
  140.                 if( worldptr->world == world ) notfound = 0;
  141.                 else worldptr = worldptr->nextworld;
  142.         }
  143.         return worldptr;
  144. }
  145.  
  146. /*=====*\
  147.  
  148. Window CreateWindow(int width, int height, char *name){
  149.         Window tmp;
  150.         struct win_node *winptr;
  151.  
  152.         XSizeHints *sizehints;
  153.         XWMHints   *wmhints;
  154.         XClassHint *classhints;
  155.         XTextProperty windowname, iconname;
  156.  
  157.  
  158.         /* define window attributes */
  159.         if(!(sizehints=XAllocSizeHints())){
  160.                 fprintf(stderr,"Xgraphics: failure allocating memory\n");
  161.                 exit(-1);
  162.         }
  163.  
  164.         if(!(wmhints=XAllocWMHints())){
  165.                 fprintf(stderr,"Xgraphics: failure allocating memory\n");
  166.                 exit(-1);
  167.         }
  168.  
  169.         if(!(classhints=XAllocClassHint())){
  170.                 fprintf(stderr,"Xgraphics: failure allocating memory\n");
  171.                 exit(-1);
  172.         }
  173.  
  174.         if(XStringListToTextProperty(&name,1,&windowname) ==0) {
  175.                 fprintf(stderr,"Xgraphics: failure allocating structure\n");
  176.                 exit(-1);
  177.         }
  178.  
  179.         if(XStringListToTextProperty(&name,1,&iconname) ==0) {
  180.                 fprintf(stderr,"Xgraphics: failure allocating structure\n");
  181.                 exit(-1);
  182.         }
  183.  
  184.         wmhints->initial_state = NormalState;
  185.         wmhints->input = True;
  186.         wmhints->flags = StateHint | InputHint;
  187.  
  188. /*sizehints->base_width = width;
  189.         sizehints->base_height = height;
  190.         sizehints->flags = PBaseSize;
  191. */
  192.  
  193.         attributes.backing_store    = Always;
  194.         attributes.background_pixel = white;
  195.  
  196.         /* create a window */
  197.         tmp =  XCreateWindow(mydisplay,DefaultRootWindow(mydisplay),
  198.                                                  200,200,width,height,                      /* coords */
  199.                                                  17,CopyFromParent,            /* border width, depth */
  200.                                                  InputOutput,                                /* class */
  201.                                                  CopyFromParent,                       /* visual type */
  202.                                                  CWBackingStore|
  203.                          CWBackPixel,                            /* valuemask */
  204.                                                  &attributes);                          /* attributes */
  205.  
  206.         XSelectInput(mydisplay,tmp,
  207.                         OwnerGrabButtonMask |
  208.                                                 ButtonPressMask | ButtonReleaseMask |         /* Mouse */
  209.                                                 EnterWindowMask |               /* Mouse enters Window */
  210.                         StructureNotifyMask |              /* Geometry changes */
  211.                                                 KeyPressMask    |                          /* Keyboard */
  212.                                                 ExposureMask);                    /* Window - Exposure */
  213.  
  214.         XSetWMProperties(mydisplay,tmp,&windowname,&iconname,NULL,0,sizehints,
  215.                          wmhints,classhints);
  216.  
  217.  
  218.         /* update window/world - database */
  219.         winptr    = worldlist;
  220.         worldlist = make_win_node();
  221.  
  222.         worldlist->nextwin   = winptr;
  223.         worldlist->prevwin   = (struct win_node *) NULL;
  224.         worldlist->nextworld = (struct world_node *) NULL;
  225.         worldlist->win       = tmp;
  226.  
  227.         if(winptr) winptr->prevwin = worldlist;
  228.  
  229.         return tmp;
  230. }
  231.  
  232. /*=====*\
  233. void ShowWindow(Window win){
  234.         XMapRaised(mydisplay,win);
  235. }
  236.  
  237. void HideWindow(Window win){
  238.         XUnmapWindow(mydisplay,win);
  239.         XSync(mydisplay,True);
  240. }
  241.  
  242. /*=====*\
  243.  
  244. void DestroyWindow(Window win){
  245.         struct win_node   *winptr;
  246.         struct world_node *worldptr;
  247.  
  248.         /* find entry in database */
  249.         winptr = find_win_node(win);
  250.         worldptr = winptr->nextworld;
  251.  
  252.         /* destroy worlds within this window */
  253.         while(winptr->nextworld) DestroyWorld(winptr->nextworld->world);
  254.  
  255.         /* delete database-entry */
  256.         if(winptr->nextwin) winptr->nextwin->prevwin = winptr->prevwin;
  257.         if(winptr->prevwin) winptr->prevwin->nextwin = winptr->nextwin;
  258.         else worldlist = winptr->nextwin;
  259.  
  260.         /* destroy window */
  261.         XDestroyWindow(mydisplay,win);
  262.         free(winptr);
  263. }
  264.  
  265. void DestroyWorld(World world){
  266.         struct world_node *worldptr;
  267.  
  268.         /* find database-entry */
  269.         worldptr = find_world_node(world);
  270.  
  271.         /* free GC's */
  272.         if(world->clipping) XFreeGC(mydisplay,world->gcw);
  273.         if(world->gcp != mygc) XFreeGC(mydisplay,world->gcp);
  274.  
  275.         /* delete database-entry */
  276.         if(worldptr->nextworld) worldptr->nextworld->prevworld = worldptr->prevworld;
  277.         if(worldptr->prevworld) worldptr->prevworld->nextworld = worldptr->nextworld;
  278.         else find_win_node(world->win)->nextworld = worldptr->nextworld;
  279.  
  280.         /* destroy world */
  281.         free(world);
  282.         free(worldptr);
  283. }
  284.  
  285.  
  286. /*=====*\
  287.  
  288. void ClearWindow(Window win){
  289.         XClearWindow(mydisplay,win);
  290. }
  291.  
  292. /*=====*\
  293.  
  294. World CreateWorld(Window window, int px, int py, int pwidth, int pheight,
  295.                         double wx1, double wy1, double wx2, double wy2,
  296.                         int scalable, int gravity)
  297. {
  298.  
  299.         World  tmpworld;
  300.         struct win_node   *winptr;
  301.         struct world_node *worldptr;
  302.         Window tmp;
  303.         int    gx,gy;
  304.         unsigned int gb,gd;
  305.         XRectangle rect;
  306.  
  307.         /* create world (memory) */
  308.         tmpworld = (World) calloc(1,sizeof(Worldstruct));
  309.  
  310.         /* if neccessary create window */
  311.         if(window == 0) { tmpworld->win = CreateWindow(px+pwidth,py+pheight,"");
  312.                                 ShowWindow(tmpworld->win); }
  313.         else            tmpworld->win = window;
  314.  
  315.         /* create Backing-storage Pixmap */
  316.         if( !scalable ) {
  317.                 tmpworld->pixmap = XCreatePixmap(mydisplay,tmpworld->win,pwidth,pheight,
  318.                                                 DefaultDepth(mydisplay,myscreen));
  319.                 XFillRectangle(mydisplay,tmpworld->pixmap,cleargc,0,0,pwidth,pheight);
  320.         }
  321.         else
  322.                 tmpworld->pixmap = 0;
  323.  
  324.         /* set coords */
  325.         tmpworld->px = px;
  326.         tmpworld->py = py;
  327.         tmpworld->pwidth  = pwidth;
  328.         tmpworld->pheight = pheight;
  329.  
  330.         tmpworld->bbx = px;
  331.         tmpworld->bby = py;
  332.         tmpworld->bbwidth = pwidth;
  333.         tmpworld->bbheight = pheight;
  334.  
  335.         tmpworld->x1 = wx1;
  336.         tmpworld->y1 = wy1;
  337.         tmpworld->x2 = wx2;
  338.         tmpworld->y2 = wy2;
  339.  
  340.         tmpworld->fx = (double)(pwidth-1)/(wx2-wx1);
  341.         tmpworld->fy = (double)(pheight-1)/(wy2-wy1);
  342.  
  343.         tmpworld->aspect = (double)pheight/(double)pwidth;
  344.  
  345.         /* get coords of window */
  346.         XGetGeometry(mydisplay,tmpworld->win,&tmp,&gx,&gy,
  347.                                  &(tmpworld->winwidth),&(tmpworld->winheight),&gb,&gd);
  348.  
  349.         /* set params */
  350.         tmpworld->scalable = scalable;
  351.         tmpworld->gravity  = gravity;
  352.         tmpworld->clipping = CLIPPING;
  353.  
  354.         /* create CG for Pixmap */
  355.         tmpworld->gcp = XCreateGC(mydisplay,DefaultRootWindow(mydisplay),0,0);
  356.         XCopyGC(mydisplay,initgc,-1,tmpworld->gcp);
  357.  
  358.         /* create CG for world */
  359.         if (CLIPPING) {
  360.                 tmpworld->gcw = XCreateGC(mydisplay,DefaultRootWindow(mydisplay),0,0);
  361.                 XCopyGC(mydisplay,initgc,-1,tmpworld->gcw);
  362.                 rect.x = px;
  363.                 rect.y = py;
  364.                 rect.width  = pwidth;
  365.                 rect.height = pheight;
  366.                 XSetClipRectangles(mydisplay,tmpworld->gcw,0,0,&rect,1,Unsorted);
  367.         } else
  368.                 tmpworld->gcw = tmpworld->gcp;
  369.  
  370.         /* set default color */
  371.         tmpworld->color = black;
  372.         tmpworld->function = GXcopy;
  373.  
  374.         /* create database-entry */
  375.         winptr = find_win_node(tmpworld->win);
  376.         if(winptr){
  377.                 worldptr = winptr->nextworld;
  378.                 winptr->nextworld = make_world_node();
  379.                 winptr->nextworld->world = tmpworld;
  380.                 winptr->nextworld->nextworld = worldptr;
  381.                 winptr->nextworld->prevworld = (struct world_node *) NULL;
  382.  
  383.                 if(worldptr) worldptr->prevworld = winptr->nextworld;
  384.         }
  385.         else { fprintf(stderr,"Problems with alloc !\n"); exit(0); }
  386.  
  387.         return tmpworld;
  388. }
  389.  
  390. /*=====*\
  391.  
  392. void ClearWorld(World world){
  393.         ClearArea(world->win,world->px,world->py,world->pwidth,world->pheight);
  394.  
  395.         if(world->pixmap) XFillRectangle(mydisplay,world->pixmap,cleargc,
  396.                                         0,0,
  397.                                         world->pwidth,world->pheight);
  398.         XFlush(mydisplay);
  399. }
  400.  
  401. /*=====*\
  402. void ExposeWorld(World world){
  403.         if(world->pixmap) {
  404.                 XCopyArea(mydisplay,world->pixmap,world->win,mygc,0,0,
  405.                                 world->pwidth,world->pheight,
  406.                                 world->px,world->py);
  407.                 XFlush(mydisplay);
  408.         }
  409. }
  410.  
  411. /*=====*\
  412. void ResizeWorld(World world, int newwidth, int newheight)
  413. {
  414.         int delta_width, delta_height, bbx_a, bby_a;
  415.         XRectangle rect;
  416.  
  417.         /* differences in size */
  418.         delta_width  = (newwidth-world->winwidth);
  419.         delta_height = (newheight-world->winheight);
  420.  
  421.         /* bounding-box */
  422.         bbx_a = world->bbx;
  423.         bby_a = world->bby;
  424.  
  425.         /* new coords for non-scalable worlds */
  426.         if( !(world->scalable) )
  427.                 switch(world->gravity) {
  428.                 case NorthGravity:
  429.                         world->px += delta_width/2;
  430.                         break;
  431.  
  432.                 case EastGravity:
  433.                         world->px += delta_width;
  434.                         world->py += delta_height/2;
  435.                         break;
  436.  
  437.                 case SouthGravity:
  438.                         world->px += delta_width/2;
  439.                         world->py += delta_height;
  440.                         break;
  441.  
  442.                 case WestGravity:
  443.                         world->py += delta_height/2;
  444.                         break;
  445.  
  446.                 case NorthEastGravity:
  447.                         world->px += delta_width;
  448.                         break;
  449.  
  450.                 case SouthEastGravity:
  451.                         world->px += delta_width;
  452.                         world->py += delta_height;
  453.                         break;
  454.  
  455.                 case SouthWestGravity:
  456.                         world->py += delta_height;
  457.                         break;
  458.  
  459.                 case NorthWestGravity:
  460.                 default:
  461.                         break;
  462.  
  463.         } else {
  464.  
  465.         /* scalable worlds */
  466.                 if( world->scalable & FIXED_WIDTH ) {
  467.                         switch(world->gravity) {
  468.                         case NorthWestGravity:
  469.                         case WestGravity:
  470.                         case SouthWestGravity:
  471.         break;
  472.                         case NorthEastGravity:
  473.                         case EastGravity:
  474.                         case SouthEastGravity:
  475.         world->bbx += delta_width;
  476.         break;
  477.                         default:
  478.         world->bbx += delta_width/2;
  479.         break;
  480.                         }
  481.                 } else {
  482.                         world->bbx += (world->scalable & FLOAT_WEST)  ?
  483.         world->bbx*(delta_width/(double)(world->winwidth)) : 0;
  484.  
  485.                         world->bbwidth = (world->scalable & FLOAT_EAST) ?
  486.         (bbx_a + world->bbwidth)*
  487.                 (newwidth/(double)(world->winwidth)) - world->bbx:
  488.                 (world->bbwidth + delta_width) + (bbx_a - world->bbx);
  489.                 }
  490.  
  491.                 if( world->scalable & FIXED_HEIGHT ) {
  492.                         switch(world->gravity) {
  493.                         case NorthEastGravity:
  494.                         case NorthGravity:
  495.                         case NorthWestGravity:
  496.         break;
  497.                         case SouthEastGravity:
  498.                         case SouthGravity:
  499.                         case SouthWestGravity:
  500.         world->bby += delta_height;
  501.         break;
  502.                         default:
  503.         world->bby += delta_height/2;
  504.         break;
  505.                         }
  506.                 } else {
  507.  
  508.                         world->bby += (world->scalable & FLOAT_NORTH) ?
  509.         world->bby*(delta_height/(double)(world->winheight)) : 0;
  510.  
  511.                         world->bbheight = (world->scalable & FLOAT_SOUTH) ?
  512.         (bby_a + world->bbheight)*
  513.                 (newheight/(double)(world->winheight)) - world->bby:
  514.                 (world->bbheight + delta_height) + (bby_a - world->bby);
  515.                 }
  516.  
  517.                 if ( world->scalable & FREE_ASPECT ) {
  518.                         world->px = world->bbx; world->py = world->bby;
  519.                         world->pwidth = world->bbwidth; world->pheight = world->bbheight;
  520.                 } else {
  521.                         if ( world->bbwidth * world->aspect > world->bbheight ) {
  522.         world->pheight = world->bbheight;
  523.         world->pwidth = world->pheight/world->aspect;
  524.         world->py = world->bby;
  525.         world->px = world->bbx + (world->bbwidth - world->pwidth)/2;
  526.                         } else {
  527.         world->pwidth = world->bbwidth;
  528.         world->pheight = world->pwidth*world->aspect;
  529.         world->px = world->bbx;
  530.         world->py = world->bby + (world->bbheight - world->pheight)/2;
  531.                         }
  532.                 }
  533.  
  534.                 world->fx = (double)(world->pwidth-1)/(world->x2 - world->x1);
  535.                 world->fy = (double)(world->pheight-1)/(world->y2 - world->y1);
  536.         }
  537.         world->winwidth  = newwidth;
  538.         world->winheight = newheight;
  539.  
  540.         if ( world->pwidth  < 1 ) world->pwidth  = 1;
  541.         if ( world->pheight < 1 ) world->pheight = 1;
  542.  
  543.         world->aspect = (double)world->pheight/(double)world->pwidth;
  544.         if (world->clipping) {
  545.                 rect.x = world->px;
  546.                 rect.y = world->py;
  547.                 rect.width  = world->pwidth;
  548.                 rect.height = world->pheight;
  549.                 XSetClipRectangles(mydisplay,world->gcw,0,0,&rect,1,Unsorted);
  550.         }
  551. }
  552.  
  553. /*=====*\
  554.  
  555. void    RescaleWorld(World world, double nx1, double ny1, double nx2, double ny2)
  556. {
  557.         world->x1 = nx1;
  558.         world->y1 = ny1;
  559.         world->x2 = nx2;
  560.         world->y2 = ny2;
  561.  
  562.         world->fx = (double)(world->pwidth-1)/(nx2-nx1);
  563.         world->fy = (double)(world->pheight-1)/(ny2-ny1);
  564. }
  565.  
  566. /*=====*\
  567.  
  568. void InitButtons(Window win, const char* buttonstring,
  569.                  int width)
  570. {
  571.         struct blist { char type; char text[20]; char key; } *list;
  572.  
  573.         XSetWindowAttributes b_attributes;
  574.         const char *ptr;
  575.         char  *ptr2;
  576.         int i, j, count = 1,bcount = 0, x, height, gx, gy;
  577.         unsigned int gwidth, gheight, gb, gd;
  578.         Window tmp;
  579.  
  580.         ptr = buttonstring;
  581.         while(*ptr) if(*ptr++ == ',') (count)++;
  582.         count /= 3;
  583.  
  584.         /* parse buttonstring */
  585.  
  586.         list = (struct blist *) calloc(count,sizeof(struct blist));
  587.  
  588.         ptr = buttonstring; i=0;
  589.         while(*ptr && i<count) {
  590.                 list[i].type = *ptr++;
  591.                 while ( (*ptr++ != ',') && *ptr);
  592.                 ptr2 = list[i].text;
  593.                 for(j=0; (*ptr!=',') && (*ptr) && j<30 ; *ptr2++ = *ptr++,j++ );
  594.                 if(*ptr++ !=',') { printf("Fehler 2 ! %d \n",i); exit(0); };
  595.                 if (list[i].type == 'b' ) list[i].key = *ptr++; else list[i].key = ' ';
  596.                 while (*ptr++ !=',' && i<count-1);
  597.                 i++;
  598.         }
  599.  
  600.         /* count buttons */
  601.         for(i=0,bcount=0;i<count;++i) if (list[i].type == 'b') ++bcount;
  602.  
  603.         /* calculate geometry */
  604.         height = (count + 1) * BUTTONHEIGHT;
  605.         XGetGeometry(mydisplay, win, &tmp, &gx, &gy, &gwidth, &gheight, &gb, &gd );
  606.         x = gwidth - width;
  607.  
  608.         /* remove existing buttons */
  609.         if ( buttonlist.buttons ) {
  610.                 free( buttonlist.buttons );
  611.                 ClearWorld( buttonlist.world );
  612.                 DestroyWorld( buttonlist.world );
  613.         }
  614.  
  615.         /* create button-world */
  616.         buttonlist.buttons = (ButtonType *) calloc(bcount,sizeof(ButtonType));
  617.         buttonlist.world = CreateWorld(win,x,0,width,height,0,0,
  618.                                  width-1,height-1,0,NorthEastGravity);
  619.         buttonlist.NofButtons = bcount;
  620.  
  621.         b_attributes.win_gravity = NorthEastGravity;
  622.  
  623.         /* create buttons */
  624.         for(i=0,j=0;i<count;++i) {
  625.                 if ( list[i].type == 'b' ) {
  626. /*
  627.                         WFillRectangle(buttonlist.world,5,i*BUTTONHEIGHT+2,
  628.                                  width-10,(i+1)*BUTTONHEIGHT-4,0);
  629. */
  630.                         WDrawRectangle(buttonlist.world,5,i*BUTTONHEIGHT+2,
  631.                                  width-10,(i+1)*BUTTONHEIGHT-4,1);
  632.                         WDrawString(buttonlist.world,10,(i+1)*BUTTONHEIGHT-13,list[i].text,1);
  633.  
  634.                         buttonlist.buttons[j].win =
  635.         XCreateWindow(mydisplay,win,x+5,i*BUTTONHEIGHT+2,
  636.                                         width-12,BUTTONHEIGHT-4,0,CopyFromParent,
  637.                                         InputOnly,CopyFromParent,
  638.                                         CWWinGravity,&b_attributes);
  639.  
  640.                         XSelectInput(mydisplay,buttonlist.buttons[j].win,ButtonPressMask);
  641.                         ShowWindow(buttonlist.buttons[j].win);
  642.                         buttonlist.buttons[j].keycode = XKeysymToKeycode(mydisplay,list[i].key);
  643.                         if ( XKeycodeToKeysym(mydisplay,buttonlist.buttons[j].keycode,0)
  644.                 == list[i].key )
  645.         buttonlist.buttons[j++].state = 0;
  646.                         else
  647.         buttonlist.buttons[j++].state = 1;
  648.  
  649.                 } else {
  650.  
  651.                         WDrawString(buttonlist.world,5,(i+1)*BUTTONHEIGHT-13,list[i].text,1);
  652.                 }
  653.         }
  654.         buttonflag = 1;
  655.         free(list);
  656. }
  657.  
  658. /*=====*\
  659.  
  660. int GetEvent(XEvent* event, int wait_flag)
  661. {
  662.         int i, ret;
  663.         int newwidth, newheight;
  664.         struct win_node   *winptr;
  665.         struct world_node *worldptr;
  666.         static int configure_flag=0;
  667.         char buffer[2];
  668.  
  669.         if(wait_flag)
  670.         {
  671.                 /* wait for next event */
  672.                 XNextEvent(mydisplay,event);
  673.                 ret = 1;
  674.         }
  675.         else
  676.         {
  677.                 /* check whether an event is queued */
  678.                 if(XEventsQueued(mydisplay,QueuedAfterFlush))
  679.                 {
  680.                         /* read event */
  681.                         XNextEvent(mydisplay,event);
  682.                         ret = 1;
  683.                 }
  684.                 else
  685.                 {
  686.                         /* if no event queued, return 0 */
  687.                         event->type = 0;
  688.                         ret = 0;
  689.                 }
  690.         };
  691.  
  692.         /* serve standard-events */
  693.         if(ret)
  694.                 {
  695.                         switch(event->type) {
  696.  
  697.                         case EnterNotify:
  698.         /* mouse entered window */
  699. /*  XSetInputFocus(mydisplay,event->xcrossing.window,
  700.                                          RevertToParent,CurrentTime);
  701. */
  702.         break;
  703.  
  704.                         case MappingNotify:
  705.         /* someone changed keyboard-layout */
  706.         XRefreshKeyboardMapping(&(event->xmapping));
  707.         break;
  708.  
  709.                         case Expose:
  710.         /* window gets visible again */
  711.         if(configure_flag) {
  712.                 XClearWindow(mydisplay,event->xexpose.window);
  713.  
  714.                 winptr = find_win_node(event->xexpose.window);
  715.                 worldptr = winptr->nextworld;
  716.  
  717.                 while(worldptr) {
  718.                         ExposeWorld(worldptr->world);
  719.                         worldptr = worldptr->nextworld;
  720.                 }
  721.         } else {
  722.                 event->type = 0;
  723.                 ret = 0;
  724.         }
  725.         configure_flag = 0;
  726.         break;
  727.  
  728.                         case ConfigureNotify:
  729.         /* window geometry changed */
  730.         newwidth  = event->xconfigure.width;
  731.         newheight = event->xconfigure.height;
  732.  
  733.         winptr = find_win_node(event->xconfigure.window);
  734.         worldptr = winptr->nextworld;
  735.  
  736.         while(worldptr) {
  737.  
  738.                 ResizeWorld(worldptr->world,newwidth,newheight);
  739.                 worldptr = worldptr->nextworld;
  740.         }
  741.         configure_flag = 1;
  742.         break;
  743.  
  744.                         case ButtonPress:
  745.         /* someone pressed a mouse button */
  746.         if (buttonflag) {
  747.                 /* check whether it was in a 'button' and return key-event */
  748.                 for(i=0; i<buttonlist.NofButtons; i++) {
  749.                         if (event->xbutton.window == buttonlist.buttons[i].win) {
  750.                                 event->type = KeyPress;
  751.                                 event->xkey.keycode = buttonlist.buttons[i].keycode;
  752.                                 event->xkey.state = buttonlist.buttons[i].state;
  753.  
  754.                         }
  755.                 }
  756.         }
  757.         break;
  758.  
  759.                         case KeyPress:
  760.         /* someone pressed a key */
  761.         if (XLookupString(&(event->xkey),buffer,2,0,0) != 1) {
  762.                 event->type = 0;
  763.                 ret = 0;
  764.         }
  765.         break;
  766.  
  767.                         default:
  768.         break;
  769.                         }
  770.                 };
  771.         return ret;
  772. }
  773.  
  774. /*=====*\
  775.  
  776. char ExtractChar(XEvent event)
  777. {
  778.         char buffer[2];
  779.  
  780.         if(event.type != KeyPress) return 0;
  781.         if(XLookupString(&event.xkey,buffer,2,0,0)==1) return buffer[0];
  782.         else return 0;
  783. }
  784.  
  785. /*=====*\
  786.  
  787. int WGetMousePos(World world, XEvent event, double *x, double *y)
  788. {
  789.         int ret = 0;
  790.  
  791.         if(event.type != ButtonPress) return 0;
  792.  
  793.         /* get coords and convert to world-coords */
  794.         *x = (event.xbutton.x - world->px)/world->fx + world->x1;
  795.         *y = (event.xbutton.y - world->py)/world->fy + world->y1;
  796.  
  797.         /* in world ? */
  798.         if ( (*x >= world->x1) && (*x <= world->x2) &&
  799.                          (*y >= world->y1) && (*y <= world->y2) ) ret = event.xbutton.button;
  800.  
  801.         return ret;
  802. }
  803.  
  804. /*=====*\
  805.  
  806.  
  807. int GetNumber( Window win, int x, int y, double *value )
  808. {
  809.         char   str[30],  zeichen = ' ';
  810.         int    i=1;
  811.         XEvent myevent;
  812.  
  813.         str[0] = ' ';str[1] = '\0';
  814.  
  815.         while ( zeichen != '\15' )           /* repeat until RETURN pressed */
  816.                 {
  817.                         GetEvent(&myevent,1);
  818.  
  819.                         switch (myevent.type){
  820.  
  821.                         case KeyPress:
  822.         zeichen = ExtractChar(myevent);
  823.         switch(zeichen){
  824.  
  825.                                         /**********   BACK SPACE  ***************************************/
  826.  
  827.         case '\10':
  828.                 {
  829.                         if(i>0)
  830.                                 {
  831.  
  832.                 DrawString (win, x,y,str,1);
  833.  
  834.                 str[i+1] = '\0'; str[i] = ' '; str[--i] = ' ';
  835.                 DrawString (win, x,y,str,1);
  836.                 break;
  837.                                 }
  838.                         else XBell(mydisplay,0);
  839.                 }
  840.  
  841.                                         /**********   RETURN   ******************************************/
  842.  
  843.         case '\15':
  844.                 {     str[i] = '\0';
  845.                 break; }
  846.  
  847.  
  848.                                         /**********   MINUS SIGN  ***************************************/
  849.  
  850.         case '-'  :
  851.                 {     if (i>0) i--; }
  852.  
  853.  
  854.                                         /**********   NUMBER   ******************************************/
  855.  
  856.         case '0'  :
  857.         case '1'  :
  858.         case '2'  :
  859.         case '3'  :
  860.         case '4'  :
  861.         case '5'  :
  862.         case '6'  :
  863.         case '7'  :
  864.         case '8'  :
  865.         case '9'  :
  866.         case '.'  :
  867.  
  868.  
  869.                 {        str[i++] = zeichen;
  870.                          str[i] = ' ';
  871.                          str[i+1] = ' ';
  872.                          str[i+2] = '\0';
  873.                          DrawString (win, x,y,str,1);
  874.                          break;}
  875.         } /* switch zeichen */
  876.         break;
  877.  
  878.                         default: break;
  879.                         } /* switch */
  880.                 } /* while */
  881.  
  882.  
  883.         /**************   Conversion to double *******************************/
  884.  
  885.         if ( !( str[0] == '\0' || str[1] == '\0') ) {
  886.                 *value = atof(str);
  887.                 return 1;
  888.         } else return 0;
  889. }
  890.  
  891.  
  892.  
  893. /*=====*\
  894.  
  895. int WGetNumber( World world, double x, double y, double *value )
  896. {
  897.         char   str[30],  zeichen = ' ';
  898.         int    i=1;
  899.         XEvent myevent;
  900.  
  901.         str[0] = ' ';str[1] = '\0';
  902.  
  903.         while ( zeichen != '\15' )           /* repeat until RETURN pressed */
  904.                 {
  905.                         GetEvent(&myevent,1);
  906.  
  907.                         switch (myevent.type){
  908.  
  909.                         case KeyPress:
  910.         zeichen = ExtractChar(myevent);
  911.         switch(zeichen){
  912.  
  913.                                         /**********   BACK SPACE  ***************************************/
  914.  
  915.         case '\10':
  916.                 {     if(i>0)
  917.                         {
  918.  
  919.                                 WDrawString (world, x,y,str,1);
  920.  
  921.                                 str[i+1] = '\0'; str[i] = ' '; str[--i] = ' ';
  922.                                 WDrawString (world, x,y,str,1);
  923.                                 break;
  924.                         }
  925.                 else XBell(mydisplay,0);
  926.                                 }
  927.  
  928.                                         /**********   RETURN   ******************************************/
  929.  
  930.         case '\15':
  931.                 {     str[i] = '\0';
  932.                 break; }
  933.  
  934.  
  935.                                         /**********   MINUS SIGN  ***************************************/
  936.  
  937.         case '-'  :
  938.                 {     if (i>0) i--; }
  939.  
  940.  
  941.                                         /**********   NUMBER   ******************************************/
  942.  
  943.         case '0'  :
  944.         case '1'  :
  945.         case '2'  :
  946.         case '3'  :
  947.         case '4'  :
  948.         case '5'  :
  949.         case '6'  :
  950.         case '7'  :
  951.         case '8'  :
  952.         case '9'  :
  953.         case '.'  :
  954.  
  955.  
  956.                 {        str[i++] = zeichen;
  957.                          str[i] = ' ';
  958.                          str[i+1] = ' ';
  959.                          str[i+2] = '\0';
  960.                          WDrawString (world, x,y,str,1);
  961.                          break;}
  962.         } /* switch zeichen */
  963.         break;
  964.  
  965.                         default: break;
  966.                         } /* switch */
  967.                 } /* while */
  968.  
  969.  
  970.         /**************   Conversion to double *******************************/
  971.  
  972.         if ( !( str[0] == '\0' || str[1] == '\0') ) {
  973.                 *value = atof(str);
  974.                 return 1;
  975.         }
  976.         else return 0;
  977. }
  978.  
  979. /*=====*\
  980.  
  981. int GetString( Window win, int x, int y, int length, char *str )
  982. {
  983.         char   zeichen = ' ';
  984.         int    i=0;
  985.         XEvent myevent;
  986.  
  987.         str[0] = ' ';str[1] = '\0';
  988.  
  989.         while ( zeichen != '\15' )           /* repeat until RETURN pressed */
  990.                 {
  991.                         GetEvent(&myevent,1);
  992.  
  993.                         switch (myevent.type){
  994.  
  995.                         case KeyPress:
  996.         zeichen = ExtractChar(myevent);
  997.         switch(zeichen){
  998.  
  999.                                         /**********   BACK SPACE  ***************************************/
  1000.  
  1001.         case '\10':
  1002.                 {
  1003.                         if(i>0)
  1004.                                 {
  1005.  
  1006.                 DrawString (win, x,y,str,1);
  1007.  
  1008.                 XBell(mydisplay,0);
  1009.  
  1010.                 str[i+1] = '\0'; str[i] = ' '; str[--i] = ' ';
  1011.                 DrawString (win, x,y,str,1);
  1012.                 break;
  1013.                                 }
  1014.                         else XBell(mydisplay,0);
  1015.                 }
  1016.  
  1017.                                         /**********   RETURN   ******************************************/
  1018.  
  1019.         case '\15':
  1020.                 {     str[i] = '\0';
  1021.                 break; }
  1022.  
  1023.  
  1024.                                         /**********  CHARACTER   ****************************************/
  1025.  
  1026.         default  :
  1027.  
  1028.  
  1029.                 {        str[i++] = zeichen;
  1030.                          str[i] = ' ';
  1031.                          str[i+1] = ' ';
  1032.                          str[i+2] = '\0';
  1033.                          DrawString (win, x,y,str,1);
  1034.                          break;}
  1035.         } /* switch zeichen */
  1036.         break;
  1037.  
  1038.                         } /* switch */
  1039.                 } /* while */
  1040.  
  1041.  
  1042.         /******************************************************************/
  1043.  
  1044.         if ( !( str[0] == '\0' || str[1] == '\0') ) {
  1045.                 str[i] = '\0';
  1046.                 return 1;
  1047.         } else return 0;
  1048. }
  1049.  
  1050.  
  1051.  
  1052. /*=====*\
  1053.  
  1054. int WGetString( World world, double x, double y, int length, char *string )
  1055. {
  1056.         char   str[30],  zeichen = ' ';
  1057.         int    i=0;
  1058.         XEvent myevent;
  1059.  
  1060.         str[0] = ' ';str[1] = '\0';
  1061.  
  1062.         while ( zeichen != '\15' )           /* repeat until RETURN pressed */
  1063.                 {
  1064.                         GetEvent(&myevent,1);
  1065.  
  1066.                         switch (myevent.type){
  1067.  
  1068.                         case KeyPress:
  1069.         zeichen = ExtractChar(myevent);
  1070.         switch(zeichen){
  1071.  
  1072.                                         /**********   BACK SPACE  ***************************************/
  1073.  
  1074.         case '\10':
  1075.                 {     if(i>0)
  1076.                         {
  1077.  
  1078.                                 WDrawString (world, x,y,str,1);
  1079.  
  1080.                                 str[i+1] = '\0'; str[i] = ' '; str[--i] = ' ';
  1081.                                 WDrawString (world, x,y,str,1);
  1082.                                 break;
  1083.                         }
  1084.                 else XBell(mydisplay,0);
  1085.                                 }
  1086.  
  1087.                                         /**********   RETURN   ******************************************/
  1088.  
  1089.         case '\15':
  1090.                 {     str[i] = '\0';
  1091.                 break; }
  1092.  
  1093.  
  1094.                                         /**********   CHARACTER   ***************************************/
  1095.  
  1096.         default  :
  1097.  
  1098.  
  1099.                 {        str[i++] = zeichen;
  1100.                          str[i] = ' ';
  1101.                          str[i+1] = ' ';
  1102.                          str[i+2] = '\0';
  1103.                          WDrawString (world, x,y,str,1);
  1104.                          break;}
  1105.         } /* switch zeichen */
  1106.         break;
  1107.  
  1108.                         } /* switch */
  1109.                 } /* while */
  1110.  
  1111.  
  1112.         /***************************************************************/
  1113.  
  1114.         if ( !( str[0] == '\0' || str[1] == '\0') ) {
  1115.                 str[i] = '\0';
  1116.                 strcpy(string,str);
  1117.                 return 1;
  1118.         }
  1119.         else return 0;
  1120. }
  1121.  
  1122.  
  1123.  
  1124. /*=====*\
  1125.  
  1126. void WSetColor(World world, unsigned long color_func)
  1127. {
  1128.         unsigned long color;
  1129.         unsigned function;
  1130.  
  1131.         /* extract color and drawing-function */
  1132.         function  = (color_func&4096)?(color_func/256)%16:3;
  1133.         color     = (function==GXxor)?                  /* colors should appear */
  1134.                 mycolors[(color_func%256)%NofColors]^white:   /* normal on white      */
  1135.                         mycolors[(color_func%256)%NofColors];       /* background           */
  1136.  
  1137.         if(color != world->color) {
  1138.                 XSetForeground(mydisplay,world->gcw,color);
  1139.                 if(world->pixmap) XSetForeground(mydisplay,world->gcp,color);
  1140.                 world->color = color;
  1141.         }
  1142.  
  1143.         if(function != world->function) {
  1144.                 XSetFunction(mydisplay,world->gcw,function);
  1145.                 if(world->pixmap) XSetFunction(mydisplay,world->gcp,function);
  1146.                 world->function = function;
  1147.         }
  1148. }
  1149.  
  1150.  
  1151. void SetColor(unsigned long color_func)
  1152. {
  1153.         unsigned long color;
  1154.         unsigned function;
  1155.  
  1156.         function  = (color_func&4096)?(color_func/256)%16:3;
  1157.         color     = (function==GXxor)?
  1158.                 mycolors[(color_func%256)%NofColors]^white:
  1159.                         mycolors[(color_func%256)%NofColors];
  1160.  
  1161.         if(color != global_color) {
  1162.                 XSetForeground(mydisplay,mygc,color);
  1163.                 global_color = color;
  1164.         }
  1165.  
  1166.         if(function != global_function) {
  1167.                 XSetFunction(mydisplay,mygc,function);
  1168.                 global_function = function;
  1169.         }
  1170.  
  1171. }
  1172.  
  1173.  
  1174. /*=====*\
  1175.  
  1176. void ClearArea(Window win, int x, int y, int width, int height)
  1177. {
  1178.         XClearArea(mydisplay,win,x,y,width,height,False);
  1179. }
  1180.  
  1181. /*=====*\
  1182.  
  1183. void DrawPoint(Window win, int x, int y, int c)
  1184. {
  1185.         SetColor(c);
  1186.  
  1187.         XDrawPoint(mydisplay,win,mygc,x,y);
  1188. }
  1189.  
  1190. /*=====*\
  1191.  
  1192. void DrawPoints(Window win, XPoint *points, int NofPoints, int c)
  1193. {
  1194.         SetColor(c);
  1195.  
  1196.         XDrawPoints(mydisplay, win, mygc, points, NofPoints, CoordModeOrigin);
  1197. }
  1198.  
  1199. /*=====*\
  1200.  
  1201. void DrawLine(Window win, int x1,int y1, int x2, int y2, int c)
  1202. {
  1203.         SetColor(c);
  1204.  
  1205.         XDrawLine(mydisplay,win,mygc,x1,y1,x2,y2);
  1206. }
  1207.  
  1208. /*=====*\
  1209.  
  1210. void DrawLines(Window win, XPoint *points, int NofPoints, int c)
  1211. {
  1212.         SetColor(c);
  1213.  
  1214.         XDrawLines(mydisplay, win, mygc, points, NofPoints, CoordModeOrigin);
  1215. }
  1216.  
  1217.  
  1218. /*=====*\
  1219.  
  1220. void DrawCircle(Window win, int x, int y, int r, int c)
  1221. {
  1222.         int rr;
  1223.  
  1224.         rr = abs(r);
  1225.         SetColor(c);
  1226.  
  1227.         XDrawArc(mydisplay,win,mygc,x-rr,y-rr,2*rr,2*rr,0,23040);
  1228. }
  1229.  
  1230. void FillCircle(Window win, int x, int y, int r, int c)
  1231. {
  1232.         int rr;
  1233.  
  1234.         rr = abs(r);
  1235.         SetColor(c);
  1236.  
  1237.         XFillArc(mydisplay,win,mygc,x-rr,y-rr,2*rr,2*rr,0,23040);
  1238. }
  1239.  
  1240.  
  1241. /*=====*\
  1242.  
  1243. void DrawString(Window win, int x, int y, const char* text, int c)
  1244. {
  1245.         SetColor(c);
  1246.  
  1247.         XDrawImageString(mydisplay,win,mygc,x,y,text,strlen(text));
  1248.         XFlush(mydisplay);
  1249. }
  1250.  
  1251. /*=====*\
  1252.  
  1253. void DrawRectangle(Window win, int x1, int y1, int x2, int y2, int c)
  1254. {
  1255.         int temp;
  1256.         SetColor(c);
  1257.  
  1258.         if (x1 > x2) { temp=x1; x1=x2; x2=temp; };
  1259.         if (y1 > y2) { temp=y1; y1=y2; y2=temp; };
  1260.  
  1261.         XDrawRectangle(mydisplay, win, mygc, x1, y1, x2-x1, y2-y1);
  1262.         XFlush(mydisplay);
  1263. }
  1264.  
  1265. void FillRectangle(Window win, int x1, int y1, int x2, int y2, int c)
  1266. {
  1267.         int temp;
  1268.         SetColor(c);
  1269.  
  1270.         if (x1 > x2) { temp=x1; x1=x2; x2=temp; };
  1271.         if (y1 > y2) { temp=y1; y1=y2; y2=temp; };
  1272.  
  1273.         XFillRectangle(mydisplay, win, mygc, x1, y1, x2-x1, y2-y1);
  1274.         XFlush(mydisplay);
  1275. }
  1276.  
  1277. /*=====*\
  1278.  
  1279. void DrawPoly(Window win, XPoint *points, int NofPoints, int c)
  1280. {
  1281.         int i;
  1282.         XPoint *xpoints;
  1283.  
  1284.         if( !(xpoints = (XPoint*) calloc(NofPoints+1,sizeof(XPoint)) ) ) {
  1285.                 fprintf(stderr,"Calloc error XLines !!!\n");
  1286.                 exit(-1);
  1287.         }
  1288.  
  1289.  
  1290.         for(i=0; i<NofPoints; ++i) {
  1291.                 xpoints[i].x = points[i].x;
  1292.                 xpoints[i].y = points[i].y;
  1293.         }
  1294.  
  1295.         if ((xpoints[0].x != xpoints[NofPoints-1].x)
  1296.                 ||(xpoints[0].y != xpoints[NofPoints-1].y)) {
  1297.                         xpoints[NofPoints].x = xpoints[0].x;
  1298.                         xpoints[NofPoints].y = xpoints[0].y;
  1299.                         NofPoints ++;
  1300.                 }
  1301.  
  1302.  
  1303.         SetColor(c);
  1304.  
  1305.         XDrawLines(mydisplay,win,mygc,
  1306.                                 xpoints,NofPoints,CoordModeOrigin);
  1307.  
  1308.         free(xpoints);
  1309.  
  1310.         XFlush(mydisplay);
  1311. }
  1312.  
  1313. /*=====*\
  1314.  
  1315. void FillPoly(Window win, XPoint *points, int NofPoints, int c, int cfill)
  1316. {
  1317.         int i;
  1318.         XPoint *xpoints;
  1319.  
  1320.         if( !(xpoints = (XPoint*) calloc(NofPoints+1,sizeof(XPoint)) ) ) {
  1321.                 fprintf(stderr,"Calloc error XLines !!!\n");
  1322.                 exit(-1);
  1323.         }
  1324.  
  1325.  
  1326.         for(i=0; i<NofPoints; ++i) {
  1327.                 xpoints[i].x = points[i].x;
  1328.                 xpoints[i].y = points[i].y;
  1329.         }
  1330.  
  1331.         if ((xpoints[0].x != xpoints[NofPoints-1].x)
  1332.                 ||(xpoints[0].y != xpoints[NofPoints-1].y)) {
  1333.                         xpoints[NofPoints].x = xpoints[0].x;
  1334.                         xpoints[NofPoints].y = xpoints[0].y;
  1335.                         NofPoints ++;
  1336.                 }
  1337.  
  1338.         SetColor(cfill);
  1339.  
  1340.         XFillPolygon(mydisplay, win, mygc, points, NofPoints, Complex,
  1341.                                  CoordModeOrigin);
  1342.  
  1343.  
  1344.         SetColor(c);
  1345.  
  1346.         XDrawLines(mydisplay,win,mygc,
  1347.                                 xpoints,NofPoints,CoordModeOrigin);
  1348.  
  1349.         free(xpoints);
  1350.  
  1351.         XFlush(mydisplay);
  1352. }
  1353.  
  1354. /*=====*\
  1355.  
  1356.  
  1357. void WDrawPoint(World world, double x, double y, int c)
  1358. {
  1359.         int px, py;
  1360.  
  1361.         px = (x-world->x1)*world->fx;
  1362.         py = (y-world->y1)*world->fy;
  1363.  
  1364.         WSetColor(world,c);
  1365.  
  1366.         XDrawPoint(mydisplay,world->win,world->gcw,world->px+px,world->py+py);
  1367.         if(world->pixmap) XDrawPoint(mydisplay,world->pixmap,world->gcp,px,py);
  1368.         XFlush(mydisplay);
  1369. }
  1370.  
  1371. /*=====*\
  1372.  
  1373. void WDrawPoints(World world, WPoint *points, int NofPoints, int c)
  1374. {
  1375.         int i;
  1376.         XPoint *xpoints;
  1377.  
  1378.         if( !(xpoints = (XPoint*) calloc(NofPoints,sizeof(XPoint)) ) ) {
  1379.                 fprintf(stderr,"Calloc error XPoints !!!\n");
  1380.                 exit(-1);
  1381.         }
  1382.  
  1383.  
  1384.         for(i=0; i<NofPoints; ++i) {
  1385.                 xpoints[i].x = world->px + (points[i].x-world->x1)*world->fx;
  1386.                 xpoints[i].y = world->py + (points[i].y-world->y1)*world->fy;
  1387.         }
  1388.  
  1389.         WSetColor(world,c);
  1390.  
  1391.         XDrawPoints(mydisplay,world->win,world->gcw,
  1392.                                 xpoints,NofPoints,CoordModeOrigin);
  1393.  
  1394.         if(world->pixmap){
  1395.                 for(i=0; i<NofPoints; ++i) {
  1396.                         xpoints[i].x -= world->px;
  1397.                         xpoints[i].y -= world->py;
  1398.                 }
  1399.  
  1400.                 XDrawPoints(mydisplay,world->pixmap,world->gcp,
  1401.                 xpoints,NofPoints,CoordModeOrigin);
  1402.         }
  1403.         free(xpoints);
  1404. }
  1405.  
  1406. /*=====*\
  1407.  
  1408. void WDrawLine(World world, double x1, double y1, double x2, double y2, int c)
  1409. {
  1410.         int px1, px2, py1, py2;
  1411.  
  1412.         px1 = (x1-world->x1)*world->fx;
  1413.         py1 = (y1-world->y1)*world->fy;
  1414.         px2 = (x2-world->x1)*world->fx;
  1415.         py2 = (y2-world->y1)*world->fy;
  1416.  
  1417.         WSetColor(world,c);
  1418.  
  1419.         XDrawLine(mydisplay,world->win,world->gcw,
  1420.                         world->px+px1,world->py+py1,world->px+px2,world->py+py2);
  1421.  
  1422.         if(world->pixmap) XDrawLine(mydisplay,world->pixmap,world->gcp,
  1423.                                                 px1,py1,px2,py2);
  1424.  
  1425.         XFlush(mydisplay);
  1426. }
  1427.  
  1428. /*=====*\
  1429.  
  1430. void WDrawLines(World world, WPoint *points, int NofPoints, int c)
  1431. {
  1432.         int i;
  1433.         XPoint *xpoints;
  1434.  
  1435.         if( !(xpoints = (XPoint*) calloc(NofPoints,sizeof(XPoint)) ) ) {
  1436.                 fprintf(stderr,"Calloc error XLines !!!\n");
  1437.                 exit(-1);
  1438.         }
  1439.  
  1440.  
  1441.         for(i=0; i<NofPoints; ++i) {
  1442.                 xpoints[i].x = world->px + (points[i].x-world->x1)*world->fx;
  1443.                 xpoints[i].y = world->py + (points[i].y-world->y1)*world->fy;
  1444.         }
  1445.  
  1446.         WSetColor(world,c);
  1447.  
  1448.         XDrawLines(mydisplay,world->win,world->gcw,
  1449.                                 xpoints,NofPoints,CoordModeOrigin);
  1450.  
  1451.         if(world->pixmap){
  1452.                 for(i=0; i<NofPoints; ++i) {
  1453.                         xpoints[i].x -= world->px;
  1454.                         xpoints[i].y -= world->py;
  1455.                 }
  1456.  
  1457.                 XDrawLines(mydisplay,world->pixmap,world->gcp,
  1458.                 xpoints,NofPoints,CoordModeOrigin);
  1459.         }
  1460.         free(xpoints);
  1461.  
  1462.         XFlush(mydisplay);
  1463. }
  1464.  
  1465. /*=====*\
  1466.  
  1467. void WDrawCircle(World world, double x, double y, double r, int c)
  1468. {
  1469.         int px, py, prx, pry;
  1470.  
  1471.         px = (x-world->x1)*world->fx;
  1472.         py = (y-world->y1)*world->fy;
  1473.         prx = abs((int) (r*world->fx));
  1474.         pry = abs((int) (r*world->fy));
  1475.  
  1476.         if(prx==0) prx=1;
  1477.         if(pry==0) pry=1;
  1478.  
  1479.         WSetColor(world,c);
  1480.  
  1481.         XDrawArc(mydisplay,world->win,world->gcw,world->px+px-prx,
  1482.                  world->py+py-pry,2*prx,2*pry,0,23040);
  1483.  
  1484.         if(world->pixmap) XDrawArc(mydisplay,world->pixmap,world->gcp,px-prx,
  1485.                                         py-pry,2*prx,2*pry,0,23040);
  1486. }
  1487.  
  1488. void WFillCircle(World world, double x, double y, double r, int c)
  1489. {
  1490.         int px, py, prx, pry;
  1491.  
  1492.         px = (x-world->x1)*world->fx;
  1493.         py = (y-world->y1)*world->fy;
  1494.         prx = abs((int) (r*world->fx));
  1495.         pry = abs((int) (r*world->fy));
  1496.  
  1497.         if(prx==0) prx=1;
  1498.         if(pry==0) pry=1;
  1499.  
  1500.         WSetColor(world,c);
  1501.  
  1502.         XFillArc(mydisplay,world->win,world->gcw,world->px+px-prx,
  1503.                  world->py+py-pry,2*prx,2*pry,0,23040);
  1504.  
  1505.         if(world->pixmap) XFillArc(mydisplay,world->pixmap,world->gcp,px-prx,
  1506.                                         py-pry,2*prx,2*pry,0,23040);
  1507. }
  1508.  
  1509.  
  1510. /*=====*\
  1511.  
  1512. void WDrawString(World world, double x, double y, const char* text, int c)
  1513. {
  1514.         int px,py;
  1515.  
  1516.         px = (x-world->x1)*world->fx;
  1517.         py = (y-world->y1)*world->fy;
  1518.  
  1519.         WSetColor(world,c);
  1520.  
  1521.         XDrawImageString(mydisplay,world->win,world->gcw,
  1522.                          world->px+px,world->py+py,text,strlen(text));
  1523.  
  1524.         if(world->pixmap)   XDrawImageString(mydisplay,world->pixmap,world->gcp,
  1525.                                                         px,py,text,strlen(text));
  1526.         XFlush(mydisplay);
  1527. }
  1528.  
  1529. /*=====*\
  1530.  
  1531. void WDrawRectangle(World world, double x1, double y1, double x2, double y2, int c)
  1532. {
  1533.         int px1,px2,py1,py2, temp;
  1534.  
  1535.         px1 = (x1-world->x1)*world->fx;
  1536.         py1 = (y1-world->y1)*world->fy;
  1537.         px2 = (x2-world->x1)*world->fx;
  1538.         py2 = (y2-world->y1)*world->fy;
  1539.  
  1540.         if (px1>px2) { temp=px1; px1=px2; px2=temp; };
  1541.         if (py1>py2) { temp=py1; py1=py2; py2=temp; };
  1542.  
  1543.         WSetColor(world,c);
  1544.  
  1545.         XDrawRectangle(mydisplay, world->win, world->gcw,
  1546.                  world->px+px1, world->py+py1, px2-px1, py2-py1);
  1547.         if(world->pixmap) XDrawRectangle(mydisplay, world->pixmap, world->gcp,
  1548.                                         px1, py1, px2-px1, py2-py1);
  1549.         XFlush(mydisplay);
  1550. }
  1551.  
  1552.  
  1553. void WFillRectangle(World world, double x1, double y1, double x2, double y2, int c)
  1554. {
  1555.         int px1,px2,py1,py2, temp;
  1556.  
  1557.         px1 = (x1-world->x1)*world->fx;
  1558.         py1 = (y1-world->y1)*world->fy;
  1559.         px2 = (x2-world->x1)*world->fx;
  1560.         py2 = (y2-world->y1)*world->fy;
  1561.  
  1562.         if (px1>px2) { temp=px1; px1=px2; px2=temp; };
  1563.         if (py1>py2) { temp=py1; py1=py2; py2=temp; };
  1564.  
  1565.         WSetColor(world,c);
  1566.  
  1567.         XFillRectangle(mydisplay, world->win, world->gcw,
  1568.                  world->px+px1, world->py+py1, px2-px1, py2-py1);
  1569.         if(world->pixmap) XFillRectangle(mydisplay, world->pixmap, world->gcp,
  1570.                                         px1, py1, px2-px1, py2-py1);
  1571.         XFlush(mydisplay);
  1572. }
  1573.  
  1574. /*=====*\
  1575.  
  1576. void WDrawPoly(World world, WPoint *points, int NofPoints, int c)
  1577. {
  1578.         int i;
  1579.         XPoint *xpoints;
  1580.  
  1581.         if( !(xpoints = (XPoint*) calloc(NofPoints+1,sizeof(XPoint)) ) ) {
  1582.                 fprintf(stderr,"Calloc error XLines !!!\n");
  1583.                 exit(-1);
  1584.         }
  1585.  
  1586.  
  1587.         for(i=0; i<NofPoints; ++i) {
  1588.                 xpoints[i].x = world->px + (points[i].x-world->x1)*world->fx;
  1589.                 xpoints[i].y = world->py + (points[i].y-world->y1)*world->fy;
  1590.         }
  1591.  
  1592.         if ((xpoints[0].x != xpoints[NofPoints-1].x)
  1593.                 ||(xpoints[0].y != xpoints[NofPoints-1].y)) {
  1594.                         xpoints[NofPoints].x = xpoints[0].x;
  1595.                         xpoints[NofPoints].y = xpoints[0].y;
  1596.                         NofPoints ++;
  1597.                 }
  1598.  
  1599.  
  1600.         WSetColor(world,c);
  1601.  
  1602.         XDrawLines(mydisplay,world->win,world->gcw,
  1603.                                 xpoints,NofPoints,CoordModeOrigin);
  1604.  
  1605.         if(world->pixmap){
  1606.                 for(i=0; i<NofPoints; ++i) {
  1607.                         xpoints[i].x -= world->px;
  1608.                         xpoints[i].y -= world->py;
  1609.                 }
  1610.  
  1611.                 XDrawLines(mydisplay,world->pixmap,world->gcp,
  1612.                 xpoints,NofPoints,CoordModeOrigin);
  1613.         }
  1614.         free(xpoints);
  1615.  
  1616.         XFlush(mydisplay);
  1617. }
  1618.  
  1619. /*=====*\
  1620.  
  1621. void WFillPoly(World world, WPoint *points, int NofPoints, int c, int cfill)
  1622. {
  1623.         int i;
  1624.         XPoint *xpoints;
  1625.  
  1626.         if( !(xpoints = (XPoint*) calloc(NofPoints+1,sizeof(XPoint)) ) ) {
  1627.                 fprintf(stderr,"Calloc error XLines !!!\n");
  1628.                 exit(-1);
  1629.         }
  1630.  
  1631.         for(i=0; i<NofPoints; ++i) {
  1632.                 xpoints[i].x = world->px + (points[i].x-world->x1)*world->fx;
  1633.                 xpoints[i].y = world->py + (points[i].y-world->y1)*world->fy;
  1634.         }
  1635.  
  1636.         WSetColor(world,cfill);
  1637.  
  1638.         XFillPolygon(mydisplay, world->win, world->gcw, xpoints, NofPoints,
  1639.                                  Complex, CoordModeOrigin);
  1640.  
  1641.         if ((xpoints[0].x != xpoints[NofPoints-1].x)
  1642.                 ||(xpoints[0].y != xpoints[NofPoints-1].y)) {
  1643.                         xpoints[NofPoints].x = xpoints[0].x;
  1644.                         xpoints[NofPoints].y = xpoints[0].y;
  1645.                         NofPoints ++;
  1646.                 }
  1647.  
  1648.         WSetColor(world,c);
  1649.  
  1650.         XDrawLines(mydisplay,world->win,world->gcw,
  1651.                                 xpoints,NofPoints,CoordModeOrigin);
  1652.  
  1653.         if(world->pixmap){
  1654.                 for(i=0; i<NofPoints; ++i) {
  1655.                         xpoints[i].x -= world->px;
  1656.                         xpoints[i].y -= world->py;
  1657.                 }
  1658.  
  1659.                 WSetColor(world,cfill);
  1660.  
  1661.                 XFillPolygon(mydisplay, world->pixmap, world->gcp, xpoints, NofPoints,
  1662.                  Complex, CoordModeOrigin);
  1663.  
  1664.                 WSetColor(world,c);
  1665.  
  1666.                 XDrawLines(mydisplay,world->pixmap,world->gcp,
  1667.                 xpoints,NofPoints,CoordModeOrigin);
  1668.         }
  1669.         free(xpoints);
  1670.  
  1671.         XFlush(mydisplay);
  1672. }
  1673. /*End*/
Título: Re: Un buen libro de C y C++ en castellano y con ejemplos muy didácticos
Publicado por: CompSystems en 30 de Septiembre de 2012, 22:40:42
2do Archivo del proyecto

Xgraphics.h

Código: C++
  1. /*
  2.  
  3. File Name: Xgraphics.h
  4. Version:  1.00 ( 28/March/1996 )
  5. By:         Martin Lueders (lueders@physik.uni-wuerzburg.de)
  6.  
  7.  
  8. Copyright (C)
  9. **  This program is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by
  10. **  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.
  11. **  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. **  You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
  14. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  15.  
  16. #include <X11/V10R3/include/X/Xlib.h>  // Nota: la biblioteca Xlib.h se encuentra en http://ftp.x.org/pub/?C=M;O=A
  17. #include <X11/V10R3/xshell/Xutils.c>   //  mas info en: http://en.wikipedia.org/wiki/Xlib
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23.  
  24.  
  25. #ifndef _XGRAPHICS_
  26.         //#then
  27.         #define _XGRAPHICS_
  28.  
  29.  
  30.         #define BUTTONHEIGHT 35
  31.         #define MAX_COLORS   16
  32.         #define CLIPPING      1
  33.         #define XOR          4096+256*GXxor
  34.  
  35.         /* Constants for scalable */
  36.  
  37.         #define SCALABLE       1
  38.         #define FREE_ASPECT    2
  39.         #define FLOAT_NORTH    4
  40.         #define FLOAT_SOUTH    8
  41.         #define FLOAT_EAST    16
  42.         #define FLOAT_WEST    32
  43.         #define FIXED_WIDTH   64
  44.         #define FIXED_HEIGHT 128
  45.  
  46.  
  47.         /* Declarations of used datatypes */
  48.  
  49.         typedef struct world_type {
  50.           Window   win;
  51.           Pixmap   pixmap;
  52.           GC       gcw, gcp;
  53.           int      px, py, pwidth, pheight,
  54.                    bbx, bby;
  55.           unsigned int bbwidth, bbheight,
  56.                    winwidth, winheight;
  57.           double   x1, y1, x2, y2;
  58.           double   fx, fy, aspect;
  59.           int      scalable;
  60.           int      clipping;
  61.           int      gravity;
  62.           unsigned long color;
  63.           int      function;
  64.         } Worldstruct, *World;
  65.  
  66.  
  67.         typedef struct w_point {
  68.           double x, y;
  69.         } WPoint;
  70.  
  71.  
  72.         typedef struct button_type {
  73.           Window  win;
  74.           int     keycode;
  75.           int     state;
  76.         } ButtonType;
  77.  
  78.         typedef struct button_list {
  79.           ButtonType *buttons;
  80.           World      world;
  81.           int        NofButtons;
  82.         } ButtonList;
  83.  
  84.         /* Declaration of variables */
  85.  
  86.         Display         *mydisplay;
  87.         int             myscreen;
  88.         Window          mywindow;
  89.         World           myworld;
  90.         unsigned long   black,white,global_color;
  91.         int             global_function;
  92.         GC              mygc,cleargc,initgc;
  93.         XEvent          myevent;
  94.         XSetWindowAttributes attributes;
  95.         int             buttonflag;
  96.         ButtonList      buttonlist;
  97.         unsigned long   mycolors[MAX_COLORS];
  98.         int             NofColors;
  99.         Colormap        mycmap;
  100.  
  101.         static char *colorlist[] = {
  102.           "white",
  103.           "black",
  104.           "red",
  105.           "green",
  106.           "blue",
  107.           "yellow",
  108.           "orange",
  109.           "brown",
  110.           "cyan",
  111.           "gray",
  112.           "tomato1",
  113.           "limegreen",
  114.           "lightblue",
  115.           "yellow4",
  116.           "orangered",
  117.           "darkgreen",
  118.           "blueviolet"
  119.         };
  120.  
  121.         static char *graylist[] = {
  122.           "white",
  123.           "black",
  124.           "gray90",
  125.           "gray85",
  126.           "gray80",
  127.           "gray75",
  128.           "gray70",
  129.           "gray65",
  130.           "gray60",
  131.           "gray55",
  132.           "gray50",
  133.           "gray45",
  134.           "gray40",
  135.           "gray35",
  136.           "gray30",
  137.           "gray25",
  138.           "gray20"
  139.         };
  140.  
  141.         struct world_node {
  142.           World  world;
  143.           struct world_node *prevworld,
  144.                             *nextworld;
  145.         } *make_world_node(), *find_world_node(World world);
  146.  
  147.         struct win_node {
  148.           Window win;
  149.           struct world_node *nextworld;
  150.           struct win_node   *prevwin,
  151.                             *nextwin;
  152.         } *worldlist, *make_win_node(), *find_win_node(Window window);
  153.  
  154.         void WSetColor(World world, unsigned long color);
  155.         void SetColor(unsigned long color);
  156.  
  157.         /*****************************************************************************/
  158.  
  159.         /* Initialisation of X-parameters */
  160.  
  161.         void  InitX();
  162.  
  163.         /*
  164.            InitX() provides the connection to the X-server and sets defaults for
  165.            the appearance of the windows.
  166.         */
  167.  
  168.  
  169.         void  ExitX();
  170.  
  171.         /*
  172.            ExitX() closes all remaining windows, frees the allocated memory and
  173.            in the end shuts down the connection to the X-server.
  174.         */
  175.  
  176.  
  177.         /*****************************************************************************/
  178.  
  179.         /* Window-handling */
  180.  
  181.         Window  CreateWindow(
  182.                              int width, int height,         /* window size           */
  183.                              char *name                     /* window title          */
  184.                              );
  185.         /*
  186.            Creates a window with th given defaults.
  187.         */
  188.  
  189.  
  190.         void  ShowWindow(Window win);
  191.  
  192.         /*
  193.            Displays the window.
  194.         */
  195.  
  196.  
  197.         void  HideWindow(Window win);
  198.  
  199.         /*
  200.            Removes the window from the screen.
  201.         */
  202.  
  203.  
  204.         void  DestroyWindow(Window win);
  205.  
  206.         /*
  207.            Closes the window.
  208.         */
  209.  
  210.  
  211.         void  ClearWindow(Window win);
  212.  
  213.         /*
  214.            Clears the window.
  215.         */
  216.  
  217.         /*****************************************************************************/
  218.  
  219.         /* World handling */
  220.         World CreateWorld(
  221.                             Window win,
  222.                             int px, int py,
  223.                             int pwidth, int pheight,
  224.                             double wx1, double wy1, double wx2, double wy2,
  225.                             int scalable,
  226.                             int gravity
  227.                             );
  228.  
  229.         /*
  230.            Creates a world in the window win with the window-coordinates (px,py)
  231.            and the size (pwidth, pheight). Defines a new coordinatesystem with
  232.            the upper left corner (wx1,wy1) and the lower right corner (wx2,wy2).
  233.            The resizing behavior is defined by scalable and gravity.
  234.         */
  235.  
  236.  
  237.         void ClearWorld(World world);
  238.  
  239.         /*
  240.            Clears a World.
  241.         */
  242.  
  243.         void  DestroyWorld(World world);
  244.  
  245.         /*
  246.            Destroys a world and frees allocated memory.
  247.         */
  248.  
  249.         void ExposeWorld(World world);
  250.  
  251.         /*
  252.            Redraws non-scalable worlds. Used internal to handle Expose-events.
  253.         */
  254.  
  255.  
  256.         void ResizeWorld(World world, int newwidth, int newheight);
  257.  
  258.         /*
  259.            Changes the size of a scalable world after the window is resized.
  260.         */
  261.  
  262.  
  263.         void RescaleWorld(World world, double nx1, double ny1, double nx2, double ny2);
  264.  
  265.         /*
  266.            Changes the world-coordinate system.
  267.         */
  268.  
  269.         /*****************************************************************************/
  270.         /* Event handling */
  271.  
  272.         void  InitButtons(Window win, const char* buttonstring, int width);
  273.  
  274.         /*
  275.            Creates a row of buttons at the right side of te window.
  276.            The syntax of buttonstring is:
  277.              "[t/b],[text],[key], [t/b],[text],[key],  ... "
  278.            Entries with 't' create a textline, entries with 'b' create a button,
  279.            which when clicked with the mouse, returns a KeyPress event for the
  280.            key 'key'. This can be handled as a normal KeyPress event.
  281.         */
  282.  
  283.         int GetEvent(XEvent* event, int wait_flag);
  284.  
  285.         /*
  286.            GetEvent reads an event from the event queue of the program.
  287.            If wait_flag > 0, the function waits until the next event ( to
  288.            conserv computing time ), otherwise the function return 0 and a
  289.            event type 0 if no event is in the queue.
  290.         */
  291.  
  292.  
  293.         char ExtractChar(XEvent event);
  294.  
  295.         /*
  296.            ExtractChar() returns the character code of the key pressed from an
  297.            KeyEvent.
  298.         */
  299.  
  300.  
  301.         int GetNumber(Window win, int x, int y, double *value);
  302.  
  303.         /*
  304.            GetNumber allows to enter a number in the window with editing the
  305.            line by using BACKSPACE. The input appears in the window at (x,y).
  306.         */
  307.  
  308.         int WGetNumber(World world, double x, double y, double *value);
  309.  
  310.         /*
  311.            Like GetNumber, but with world-coordinates.
  312.         */
  313.  
  314.  
  315.         int GetString(Window win, int x, int y, int length, char *string);
  316.  
  317.         /*
  318.            GetNumber allows to enter a string in the window with editing the
  319.            line by using BACKSPACE. The input appears in the window at (x,y).
  320.         */
  321.  
  322.         int WGetString(World world, double x, double y, int length, char *string);
  323.  
  324.         /*
  325.            Like GetString, but with world-coordinates.
  326.         */
  327.  
  328.         int   WGetMousePos(World world, XEvent event, double *x, double *y);
  329.  
  330.         /*
  331.            Returns the position of a mouse click in coordinates of the world
  332.            given as argument.
  333.         */
  334.  
  335.         /* Drawingroutines for Windows */
  336.  
  337.         void  ClearArea(Window win, int x, int y, int width, int height);
  338.  
  339.         void  SetColor(unsigned long color);
  340.         void  SetFunction(int func);
  341.  
  342.         void  DrawPoint(Window win, int x, int y, int c);
  343.         void  DrawPoints(Window win, XPoint *points, int NofPoints, int c);
  344.         void  DrawLine(Window win, int x1, int y1, int x2, int y2, int c);
  345.         void  DrawLines(Window win, XPoint *points, int NofPoints, int c);
  346.         void  DrawCircle(Window win, int x, int y, int r, int c);
  347.         void  FillCircle(Window win, int x, int y, int r, int c);
  348.         void  DrawString(Window win, int x, int y, const char* text, int c);
  349.         void  DrawRectangle(Window win, int x1, int y1, int x2, int y2, int c);
  350.         void  FillRectangle(Window win, int x1, int y1, int x2, int y2, int c);
  351.         void  DrawPoly(Window win, XPoint *points, int NofPoints, int c);
  352.         void  FillPoly(Window win, XPoint *points, int NofPoints, int c, int cfill);
  353.  
  354.  
  355.         /* Drawingroutines for worlds */
  356.  
  357.         void  WSetColor(World world, unsigned long color);
  358.         void  WSetFunction(World world, int func);
  359.  
  360.         void  WDrawPoint(World world, double x, double y, int c);
  361.         void  WDrawPoints(World world, WPoint *points, int NofPoints, int c);
  362.         void  WDrawLine(World world, double x1, double y1, double x2, double y2, int c);
  363.         void  WDrawLines(World world, WPoint *points, int NofPoints, int c);
  364.         void  WDrawCircle(World world, double x, double y, double r, int c);
  365.         void  WFillCircle(World world, double x, double y, double r, int c);
  366.         void  WDrawString(World world, double x, double y, const char* text, int c);
  367.         void  WDrawRectangle(World world,
  368.                                double x1, double y1, double x2, double y2, int c);
  369.         void  WFillRectangle(World world,
  370.                                double x1, double y1, double x2, double y2, int c);
  371.         void  WDrawPoly(World world, WPoint *points, int NofPoints, int c);
  372.         void  WFillPoly(World world,
  373.                             WPoint *points, int NofPoints, int c, int cfill);
  374.  
  375. #endif
Título: Re: Un buen libro de C y C++ con ejemplos muy buenos en castellano
Publicado por: CompSystems en 30 de Septiembre de 2012, 22:51:49
3cer archivo del proyecto

"Ejemplo63.c"

Código: C++
  1. // Ejemplo 63 pagina 158 By: Manuel José Páez Mejía
  2. /*
  3. En el siguiente programa informático escrito en lenguaje c, se utiliza el mínimo numero de instrucciones que debe tener una aplicación utilizando la biblioteca Xgraphics.c
  4.  
  5. Las partes del programa son:
  6.  
  7. A: La inclusión del encabezado "Xgraphics.h"
  8. B: Declaración del tipo de objeto myVentana, la cual es una estructura de datos con la información de la ventana
  9. C: Declaración de un identificador para detectar el evento para tomar una acción (presionar el botón izquierdo del ratón por ejemplo para cerrar la ventana),
  10. D: Especificar anchura, altura y nombre de la ventana con la funcion CreateWindow( ... )
  11. E: Se dibujan diferentes figuras geométricas con las funciones DrawLine, DrawCircle, FillCircle, DrawRectangle, DrawString
  12.  
  13. */
  14.  
  15. #include <stdlib.h>
  16. #include "Xgraphics.h"
  17.  
  18. // Declaracion de identificadores y objetos.
  19. Window myVentana;
  20. XEvent miEvento;
  21. int i, done;
  22.  
  23. // Inicializacion de identificadores.
  24. done = 0;
  25.  
  26. main( ){
  27.  
  28.         InitX(); // Habilita modo gráfico
  29.         miVentana = CreateWindow( 400, 410, "TITLE: PRIMITIVOS"); // Crea una ventana de 400 * 390 pixeles en blanco
  30.         ShowWindow( miVentana ); // Despliega la ventana en el PC
  31.  
  32.         for( count = 1; count < 20; count = count + 1;) {
  33.                 DrawLine( miVentana, 10+5*count, 300, 10+5*count, count );//  Dibuja rectas.
  34.         }
  35.  
  36.         DrawCircle( miVentana, 150, 150, 40, 4 ); // Dibuja un circulo
  37.         DrawString( miVentana, 150, 250, "Mi circulo", 6 ); // Etiqueta el circulo
  38.         FillCircle( miVentana, 300, 250, 10, 7); // Dibuja un circulo relleno.
  39.         DrawRentangle( miVentana, 2, 2, 398, 398, 3 ); // Crea un marco.
  40.  
  41.         while( !done ){
  42.                 GetEvent( &miEvento, 1); // Cierra ventana si ...
  43.                 if( miEvento.type == ButtomPress){
  44.                         done = 1;
  45.                 }
  46.         Exit();
  47.         }
  48. }
Título: Re: Un buen libro de C y C++ en castellano y con ejemplos muy didácticos
Publicado por: CompSystems en 01 de Octubre de 2012, 10:29:41
3cer archivo (alternativo)  del proyecto

Ejemplo66.c

Ejemplo 66: Grafica de A*sin( x ) con amplitud Ay en el intervalo 0.0 <= x <= 2*PI By: Manuel José Páez Mejía

Código: C++
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "Xgraphics.h"
  4.  
  5. // Definicion de constantes
  6. #define PI 3.141592
  7.  
  8. // Declaracion de identificadores y objetos.
  9. Window myVentana;
  10. XEvent miEvento;
  11. int i, done;
  12. World miMnd;
  13.  
  14. // Inicializacion de identificadores.
  15. done = 0;
  16.  
  17. iniciarWin( ){
  18.   int maxX, maxY; // Anchura y altura de la ventana.
  19.   int p1X, p1Y, p2X, p2Y; // Coordenadas de la ventana.
  20.   maxX = 400; // Anchura para los margenes de la ventana
  21.   maxY = 250; // Altura para los margenes de la ventana
  22.   p1X = (int) (0.1*maxX);
  23.   p1Y = (int) (0.1*maxY);
  24.   p2X = (int) (0.8*maxX);
  25.   p2Y = (int) (0.8*maxY);
  26.   InitX();
  27.   miVentana = CreateWindow( maxX, maxY, "SIN" );
  28.   miWrd = CreateWorld( miVentana, p1X, p1Y, p2X, p2Y, 0, 1.0, 2.0*PI, -1.0, SCALABLE, 0 );
  29.   showWindow( miVentana );
  30. }
  31.  
  32.  
  33. grafique( float A, int color){
  34.   int i;
  35.   WPoint puntos [52];
  36.   float incr, x, y;
  37.   incr = 2.0*PI/50.0;
  38.   i=0;
  39.   for( x = 0; x <= 2.0*PI+INCR; x = x + incr){
  40.      puntos[i].x = x;
  41.      puntos[i].y = A*sin(x);
  42.      i = i+1;
  43.   }
  44.   wDrawLines( miWrd, puntos, 50, color);
  45.   wDrawLine( miWrd, 0, 0, 2*PI, 0, 2);
  46.   wDrawLine( miWrd, PI, 1.0, PI, -1.0, 2);
  47.   wDrawString( miWrd, 4.0, 0.9, "A*sin(x)", 8);
  48. }
  49.  
  50. pausa(){
  51.   int i, j, k;
  52.   ...
  53. }
  54.  
  55. movimiento(){
  56.   int i, j, col1, col2;
  57.   float amplitud;
  58.   ...
  59. }
  60.  
  61. eventos(){
  62.   int done = 0;
  63.   while ( !done ) {
  64.     GetEvent( &miEvento, 1 );
  65.     switch( miEvento.type ) {
  66.        case ButtomPress:{
  67.           done = 1;
  68.           break;
  69.        }    
  70.  
  71.  
  72.  
  73. }
  74.    
  75.  }
  76.  ExitX();
  77. }
  78.  
  79.  
  80.  
  81. main( ){
  82.    iniciarWin( );
  83.    movimiento();
  84. }



Redactando ...
Título: Re: Un buen libro de C y C++ en castellano y con ejemplos muy didácticos
Publicado por: CompSystems en 01 de Octubre de 2012, 15:21:24
Quien ha tenido éxito compilando los ejemplos anteriores?

HELP MAESTROS DEL C/C++: Creo que el problema esta en la inclusión de los archivos de la biblioteca "Xlib.h", por que el compilador dice que no encuentra el directorio de Xlib  :huh:
Título: Re: Un buen libro de C y C++ en castellano y con ejemplos muy didácticos
Publicado por: CompSystems en 02 de Octubre de 2012, 17:31:04
El Proyecto consta básicamente de 4 archivos:

Citar
Xgraphics.c // Biblioteca con funciones basicas de una GUI
Xgraphics.h
xlib.h         // Biblioteca requerida por Xgraphics
Ejemplo63.c o Ejemplo66.c // Ejemplos de prueba

Posibles causas de una compilación NO satisfactoria:

A- Compilador adecuado, yo uso el compilador "ZINJAI" http://zinjai.sourceforge.net/

B- Ubicación de los archivos Xlib

#include <X11/V10R3/include/X/Xlib.h>  // Nota: la biblioteca Xlib.h se encuentra en http://ftp.x.org/pub/?C=M;O=A
#include <X11/V10R3/xshell/Xutils.c>   //  mas info en: http://en.wikipedia.org/wiki/Xlib

Muchos subdirectorios

C- Hay diferentes versiones de Xlib que pueden generar conflictos

       http://ftp.x.org/pub/?C=M;O=A
   Parent Directory        -
   X10R3/   04-May-2001 08:00    -
   X10R4/   04-May-2001 08:00    -
   X11R1/   04-May-2001 08:00    -
   X11R2/   04-May-2001 08:00    -
   X11R3/   04-May-2001 08:00    -
   X11R4/   04-May-2001 08:00    -
   X11R5/   04-May-2001 08:00    -
   X11R6.1/   04-May-2001 08:00    -
   X11R6.3/   04-May-2001 08:00    -
   X11R6/   04-May-2001 08:00    -
   unsupported/   04-May-2001 08:00    -
   X11R6.5.1/   09-Aug-2001 08:00    -
   X11R6.7/   14-May-2004 09:22    -
   X11R6.4/   21-Sep-2004 08:00    -
   X11R6.6/   21-Sep-2004 08:00    -
   X11R6.7.0/   29-Dec-2004 15:09    -
   X11R6.8.0/   29-Dec-2004 15:09    -
   X11R6.8.1/   29-Dec-2004 15:09    -
   X11R6.8.2/   09-Feb-2005 16:45    -
   XTS5.0.2/   18-Apr-2005 08:00    -
   X11R7.0/   21-Dec-2005 11:56    -
   X11R6.9.0/   21-Dec-2005 16:25    -
   X11R7.1/   22-May-2006 19:30    -
   XTS/   13-Dec-2006 10:59    -
   X11R7.2/   15-Feb-2007 17:56    -
   X11R7.3/   06-Sep-2007 05:45    -
   X11R7.4/   23-Sep-2008 16:27    -
   X11R7.5-RC1/   18-Oct-2009 02:00    -
   X11R7.6-RC1/   12-Nov-2010 23:00    -
   X11R7.5/   19-Dec-2010 04:02    -
   individual/   24-May-2011 20:39    -
   X11R7.7-RC1/   05-Jun-2012 23:08    -
   X11R7.6/   05-Jun-2012 23:08    -
   X11R7.7/   06-Jun-2012 18:50    -
   current/   06-Jun-2012 18:50



EDITO:

EL LIBRO http://books.google.com.co/books?id=E1CMxC4KKSYC&pg=PA157&lpg=PA157&dq=Manuel+Jos%C3%A9+P%C3%A1ez+Mej%C3%ADa+xgraphics&source=bl&ots=r_ayZLXuqb&sig=nTQMbs8653cKKBc5H4oZN_2bEbM&hl=es&sa=X&ei=Vc5pUJbsNIa09gTbz4HYBw&ved=0CB0Q6AEwAA#v=onepage&q=Manuel%20Jos%C3%A9%20P%C3%A1ez%20Mej%C3%ADa%20xgraphics&f=false


EL LIBRO Ha sido recortado por GOOGLE, desde que yo coloque los links en varios foros.  ANTES se podía verlo completamente  :5]
Título: Re:Un buen libro de C/C++ en castellano y con ejemplos muy didácticos y con GUIs
Publicado por: CompSystems en 17 de Julio de 2016, 01:36:44
.
Título: Re:Un buen libro de C/C++ en castellano y con ejemplos muy didácticos y con GUIs
Publicado por: Geo en 21 de Julio de 2016, 01:24:30
¿En qué sistema operativo estás intentando compilar?

El código que estás tratando de utilizar es muy viejo. Xgraphics parece ser un "wrapper" o una biblioteca de funciones de dibujado que utiliza X11, el problema es que la versión de X11 a la que hace referencia (10R3) tiene fecha de 1995, además de que en el README de dicha versión se menciona que nisiquera corre para IBM/PC:

Citar
X is a network transparent window system for bitmap displays that
currently runs on 6 different types of displays.  These include the DEC
VS100, VS1, VS2, VS2-GPX, the Lexidata 90, and most Sun Microsystems
displays, (not yet finished).  The implementations for the IBM RT/PC
displays (ACIS experimental display, APA8, APA16 did not quite make this
release.