home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / n / newmarch.zip / MOTIF_HE.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  3KB  |  129 lines

  1. /* Author:   $Author: jan $
  2.  * File:     $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/motif_hello.c,v $
  3.  * Date:     $Date: 1992/09/09 00:10:04 $
  4.  * Revision: $Revision: 1.1 $
  5.  */
  6.  
  7. #include "copyright.h"
  8.  
  9. #include <stdio.h> 
  10.  
  11. #include <Xm/DrawingA.h> 
  12.  
  13. /*------------------------------------------------------
  14. **     Forward Declarations 
  15. */ 
  16.  
  17. void main ();           
  18. void CreateApplication ();  
  19. void display_somethingCB (); 
  20.  
  21. /*------------------------------------------------------
  22. **    Global Variables 
  23. */ 
  24.  
  25. #define MAX_ARGS 20 
  26. #define Class_name "Draw" 
  27.  
  28. Widget  draw_area;   /* Drawing Area widget */
  29. Display *display;    /* the display device   */    
  30. Screen  *screen;     /* the screen on the display */  
  31. Window  draw_window; /* the drawing area 
  32.                         widget's window */   
  33. GC      gc;    
  34.     
  35. /*-----------------------------------------------------
  36. ** Create a graphics context using default values, and
  37. ** return it in the pointer gc    
  38. */    
  39. GC
  40. getGC ()
  41. {   GC gc;  
  42.        
  43.     gc = XCreateGC (display, draw_window,     
  44.                 (unsigned long) 0, NULL);    
  45.     
  46.     XSetForeground (display, gc, 
  47.                    BlackPixelOfScreen (screen));
  48.     XSetBackground (display, gc,
  49.                     WhitePixelOfScreen (screen));
  50.     return (gc);
  51. }    
  52.     
  53. /*------------------------------------------------------
  54. ** Write a string    
  55. ** and draw a circle   
  56. */    
  57. void display_somethingCB (w, client_data, call_data)  
  58. Widget        w;    
  59. caddr_t       client_data; 
  60. caddr_t       call_data;  
  61. {
  62.     /* the proverbial string */    
  63.     XDrawImageString (display, draw_window, gc,    
  64.                       10, 10, "Hello world",    
  65.                       strlen ("Hello world"));    
  66.     
  67.     /* and a world (circle) to go with it */    
  68.     XDrawArc (display, draw_window, gc,    
  69.                30, 30,
  70.                100, 100, 
  71.                0, 360*64);
  72.     XFlush (display);
  73. }    
  74. /*------------------------------------------------------
  75. **    main        - main logic for application 
  76. */ 
  77. void main (argc,argv)  
  78.     unsigned int    argc; 
  79.     char         **argv; 
  80.     Widget        app_shell;  
  81.   
  82.     app_shell = XtInitialize(NULL,
  83.                Class_name,   
  84.                NULL,   
  85.                0,  
  86.                &argc, argv);    
  87.   
  88.     /* set up all the sub-widgets */ 
  89.     CreateApplication(app_shell);
  90.     XtRealizeWidget (app_shell);
  91.  
  92.     /* Now get info about windows, etc 
  93.     ** The XtWindow() _must_ occur after XtRealize() has
  94.     ** created the Drawing Area's window
  95.     */
  96.     display = XtDisplay (draw_area);
  97.     draw_window = XtWindow (draw_area);
  98.     screen = XtScreen (draw_area);
  99.     gc = getGC ();
  100.  
  101.     /*    Get and dispatch events. 
  102.     */ 
  103.     XtMainLoop (); 
  104.  
  105. /*--------------------------------------------------
  106. **     CreateApplication    - create main window 
  107. */ 
  108. void CreateApplication (parent)  
  109. Widget        parent;  
  110.  
  111.      Arg        args[MAX_ARGS]; 
  112.      register int    n;  
  113.  
  114.      /*    Create Drawing Area
  115.      **    Make it a reasonable size
  116.      */ 
  117.      n = 0; 
  118.      XtSetArg (args[n], XmNwidth, 300); n++;
  119.      XtSetArg (args[n], XmNheight, 300); n++;
  120.      draw_area = XmCreateDrawingArea (parent, "an_area",
  121.                                       args, n);    
  122.      XtAddCallback (draw_area, XmNexposeCallback,
  123.                              display_somethingCB, NULL);
  124.      XtManageChild (draw_area);     
  125. }
  126.