home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / freedraft.tar.gz / freedraft.tar / FREEdraft-050298 / HACKV / fd_vbglcnv.h < prev    next >
C/C++ Source or Header  |  1997-11-16  |  8KB  |  223 lines

  1. //===============================================================
  2. // vglcnv.h GL Canvas C++ class .h file - X11R5
  3. //
  4. // Copyright (C) 1995,1996  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11.  
  12. #ifndef VGLCNV_H
  13. #define VGLCNV_H
  14.  
  15. #include <v/v_defs.h>        // Basic defs
  16. #include <v/vapp.h>        // for theApp
  17. #include <v/vpane.h>        // we are derived from vPane
  18. #include <v/vfont.h>        // for font stuff
  19.  
  20. extern "C"
  21. {
  22. #include <X11/Xlib.h>
  23. #include <X11/cursorfont.h>
  24.  
  25. // OpenGL stuff here
  26.  
  27. #include <GLwDrawA.h>    // Xt OpenGL drawing area widget.
  28. #include <GL/gl.h>
  29. #include <GL/glu.h>
  30. #include <GL/glx.h>
  31.  
  32.  
  33.     void CchangeCB(Widget w, XtPointer client_data, XtPointer call_data);
  34.  
  35.     void CHJumpProcCB(Widget w, XtPointer This, XtPointer pc_ptr);
  36.     void CHScrollProcCB(Widget w, XtPointer This, XtPointer position);
  37.     void CVJumpProcCB(Widget w, XtPointer This, XtPointer pc_ptr);
  38.     void CVScrollProcCB(Widget w, XtPointer This, XtPointer position);
  39.  
  40.     void CgraphicsInit(Widget w, XtPointer clientData, XtPointer call);
  41.  
  42.     void CExposeEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  43.  
  44.     void CEnterEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  45.     void CLeaveEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  46.  
  47.     void CMouseDownEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  48.     void CMouseUpEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  49.     void CMouseMoveEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  50.     void CNVKeyInEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  51. }
  52.  
  53. const unsigned int vGL_Default = 0;
  54. const unsigned int vGL_RGB = 0x0001;
  55. const unsigned int vGL_Alpha = 0x0002;
  56. const unsigned int vGL_Indexed = 0x0004;
  57. const unsigned int vGL_DoubleBuffer = 0x0008;
  58. const unsigned int vGL_Stereo = 0x0010;
  59. const unsigned int vGL_Stencil = 0x0020;
  60. const unsigned int vGL_Accum = 0x0040;
  61. const unsigned int vGL_Depth = 0x0080;
  62.  
  63.     typedef int VCursor;        // For cursors
  64.  
  65. // Define Cursor stuff
  66.  
  67. const VCursor VC_None = 0;        // No/Default cursor
  68. const VCursor VC_Arrow = 1;        // XC_top_left_arrow
  69. const VCursor VC_CenterArrow = 2;    // XC_center_ptr
  70. const VCursor VC_CrossHair = 3;        // XC_crosshair
  71. const VCursor VC_EWArrows = 4;        // XC_sb_h_double_arrow
  72. const VCursor VC_Hand = 5;        // XC_hand2
  73. const VCursor VC_IBar = 6;        // XC_xterm
  74. const VCursor VC_Icon = 7;        // XC_icon
  75. const VCursor VC_NSArrows = 8;        // XC_sb_v_double_arrow
  76. const VCursor VC_Pencil = 9;        // XC_Pencil
  77. const VCursor VC_Question = 10;        // XC_question_arrow
  78. const VCursor VC_Sizer = 11;        // XC_sizing
  79. const VCursor VC_Wait = 12;        // XC_watch
  80. const VCursor VC_X = 13;        // XC_X_cursor
  81. const VCursor VC_LAST = 13;
  82. const int maxCursors = 13;
  83.  
  84.     class vWindow;        // we are part of a window
  85.  
  86.     class vBaseGLCanvasPane : public vPane
  87.       {
  88.     friend void CchangeCB(Widget w, XtPointer client_data, XtPointer call_data);
  89.     friend void CHJumpProcCB(Widget w, XtPointer This, XtPointer pc_ptr);
  90.     friend void CHScrollProcCB(Widget w, XtPointer This, XtPointer position);
  91.     friend void CVJumpProcCB(Widget w, XtPointer This, XtPointer pc_ptr);
  92.     friend void CVScrollProcCB(Widget w, XtPointer This, XtPointer position);
  93.  
  94.     friend void CgraphicsInit(Widget w, XtPointer clientData, XtPointer call);
  95.     friend void CExposeEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  96.  
  97.     friend void CEnterEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  98.     friend void CLeaveEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  99.  
  100.     friend void CMouseDownEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  101.     friend void CMouseUpEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  102.     friend void CMouseMoveEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  103.     friend void CNVKeyInEV(Widget w, XtPointer client_data, XEvent* event, char *x);
  104.  
  105.       public:        //---------------------------------------- public
  106.  
  107.     vBaseGLCanvasPane(unsigned int vGLmode = vGL_Default, PaneType pt = P_Canvas);
  108.  
  109.      virtual ~vBaseGLCanvasPane();
  110.  
  111.     virtual void ShowPane(int OnOrOff);
  112.  
  113.     void SetWidthHeight(int width, int height);
  114.     // Cursor
  115.     void SetCursor(VCursor id);
  116.         VCursor GetCursor() { return _currentCursor; }
  117.  
  118.     void UnSetCursor(void);
  119.  
  120.     // Scrolling
  121.     virtual void HPage(int Shown, int Top);    // Horiz page event
  122.     virtual void VPage(int Shown, int Top);    // Vert page event
  123.     virtual void HScroll(int step);        // Horiz scroll event
  124.     virtual void VScroll(int step);        // Vert scroll event
  125.     virtual void SetHScroll(int Shown, int Top);  // Set Horiz Scroll bar
  126.     virtual void SetVScroll(int Shown, int Top);  // Set Vert Scroll bar
  127.     virtual int GetVScroll(int& Shown, int& Top);
  128.     virtual int GetHScroll(int& Shown, int& Top);
  129.     virtual void ShowHScroll(int OnOff);
  130.     virtual void ShowVScroll(int OnOff);
  131.  
  132.     // Events
  133.     virtual void MouseDown(int x, int y, int button);    // Mouse Down at x,y
  134.     virtual void MouseUp(int x, int y, int button);        // Mouse Up at x,y
  135.     virtual void MouseMove(int x, int y, int button);    // Mouse Moved to x,y
  136.     virtual void MouseMotion(int x, int y) {}    // no button: Mouse Moved to x,y
  137.  
  138.     virtual void EnterFocus();
  139.     virtual void LeaveFocus();
  140.  
  141.     // Expose/redraw event
  142.     virtual void Redraw(int x, int y, int width , int height);
  143.     virtual void Resize(int newW, int newH);  // Resize event
  144.  
  145.     // Information
  146.     virtual int GetWidth() { return _width; }   // Get width of canvas
  147.     virtual int GetHeight() { return _height; } // Get Height of canvas
  148.  
  149.     // OpenGL specific stuff
  150.  
  151.     virtual void graphicsInit(void);
  152.  
  153.     void vglMakeCurrent(void)
  154.       {
  155.         glXMakeCurrent(theApp->display(), XtWindow(_drawWindow), glxContext);
  156.       }
  157.  
  158.      virtual void vglFlush();
  159.  
  160.     
  161.     XVisualInfo* GetXVisualInfo() { return _visinfo; }
  162.  
  163.     // Platform dependent
  164.  
  165.     Widget DrawingWindow() { return _drawWindow; }
  166.     Drawable GetXDrawable() { return (_Drawable == 0) ? 
  167.             (_Drawable = (Drawable)XtWindow(_drawWindow)) : _Drawable;}
  168.  
  169.       protected:    //--------------------------------------- protected
  170.  
  171.     virtual void initialize(vWindow* pWindow, Widget pWidget);
  172.     XVisualInfo* chooseIndexed(unsigned int glMode);
  173.     XVisualInfo* chooseRGB(unsigned int glMode);
  174.  
  175.     int _height;    // height of draw window
  176.     int _width;    // width of draw window
  177.     
  178.     GLXContext glxContext;
  179.  
  180.       private:        //--------------------------------------- private
  181.  
  182.     // Widgets for the canvas
  183.     Widget _drawCanvas;        // whole canvas window
  184.     Widget _drawHScroll;        // horiz scroll
  185.     Widget _drawVScroll;        // vertical scroll
  186.     Widget _drawWindow;        // window for drawing
  187.     Drawable _Drawable;
  188.  
  189.     static VCursor _currentCursor;    // for cursor
  190.     static XVisualInfo* _visinfo;
  191.     static int _doubleBuffer;        // if we have double buffering
  192.     static unsigned int _vGLmode;
  193.  
  194.     int _hasFocus;            // for focus workaround
  195.     int _mouseDown;            // for tracking mouse
  196.  
  197.     int _HOn;        // on or off
  198.     int _VOn;
  199.  
  200.     int _HScrlShown;
  201.     int _HScrlTop;
  202.     int _VScrlShown;
  203.     int _VScrlTop;
  204.  
  205.     void ChangeCB(void);
  206.     // Allow dual use for Athena and Motif
  207.     void HJumpProcCB(float percent, int motifValue);
  208.     void VJumpProcCB(float percent, int motifValue);
  209.     void HScrollProcCB(int);
  210.     void VScrollProcCB(int);
  211.  
  212.     void DrawHScroll(int Shown, int Top);
  213.     void DrawVScroll(int Shown, int Top);
  214.  
  215.     void ExposeEV(int x, int y, int width, int height);
  216.     void EnterEV(void);
  217.     void LeaveEV(void);
  218.     void MouseUpEV(int x, int y, int button);
  219.     void MouseDownEV(int x, int y, int button);
  220.     void MouseMoveEV(int x, int y, int button);
  221.       };
  222. #endif
  223.