// // File "gwindow.h" // Simple graphic window, based on Xlib primitives // #ifndef _GWINDOW_H #define _GWINDOW_H // Classes for simple 2-dimensional objects #include "R2Graph/R2Graph.h" // include the X library headers extern "C" { #include #include #include }; //=============================== class ListHeader { public: ListHeader* next; ListHeader* prev; public: ListHeader(): next(0), prev(0) { } ListHeader(ListHeader* n, ListHeader* p): next(n), prev(p) { } ListHeader(const ListHeader& h): next(h.next), prev(h.prev) { } ~ListHeader() {} ListHeader& operator=(const ListHeader& h) { next = h.next; prev = h.prev; return *this; } void link(ListHeader& h) { next = &h; h.prev = this; } }; const int BORDER_WIDTH = 5; class GWindow: public ListHeader { public: // Xlib objects: // Display and screen are the same for all windows static Display* m_Display; static int m_Screen; Window m_Window; GC m_GC; // Coordinates in window I2Rectangle m_IWinRect; // Window rectangle in (local) pixel coordinates R2Rectangle m_RWinRect; // Window rectangle in inner (real) coordinates I2Point m_ICurPos; // Current position, integer R2Point m_RCurPos; // real double m_xcoeff; // Optimization: Coeff. for real->integer conversion double m_ycoeff; char m_WindowTitle[128]; private: // Window state bool m_WindowCreated; // Static members: // List of all windows static int m_NumWindows; static int m_NumCreatedWindows; static ListHeader m_WindowList; public: GWindow(); GWindow(const I2Rectangle& frameRect, const char *title = 0); GWindow( const I2Rectangle& frameRect, const R2Rectangle& coordRect, const char *title = 0 ); virtual ~GWindow(); void createWindow(); void createWindow( const I2Rectangle& frameRect, const char *title = 0 ); void createWindow( const I2Rectangle& frameRect, const R2Rectangle& coordRect, const char *title = 0 ); static bool initX(); static void closeX(); static int screenMaxX(); static int screenMaxY(); private: static GWindow* findWindow(Window w); public: void drawFrame(); void setCoordinates(double xmin, double ymin, double xmax, double ymax); void setCoordinates(const R2Rectangle& coordRect); void setCoordinates(const R2Point& leftBottom, const R2Point& rightTop); double getXMin() const { return m_RWinRect.getXMin(); } double getXMax() const { return m_RWinRect.getXMax(); } double getYMin() const { return m_RWinRect.getYMin(); } double getYMax() const { return m_RWinRect.getYMax(); } void drawAxes(); I2Rectangle getWindowRect() const { return m_IWinRect; } R2Rectangle getCoordRect() const { return m_RWinRect; } void moveTo(const I2Point& p); void moveTo(const R2Point& p); void moveTo(int x, int y); void moveTo(double x, double y); void moveRel(const I2Vector& p); void moveRel(const R2Vector& p); void moveRel(int x, int y); void moveRel(double x, double y); void drawLineTo(const I2Point& p); void drawLineTo(const R2Point& p); void drawLineTo(int x, int y); void drawLineTo(double x, double y); void drawLineRel(const I2Vector& p); void drawLineRel(const R2Vector& p); void drawLineRel(int x, int y); void drawLineRel(double x, double y); void drawLine(const I2Point& p1, const I2Point& p2); void drawLine(const I2Point& p, const I2Vector& v); void drawLine(int x1, int y1, int x2, int y2); void drawLine(const R2Point& p1, const R2Point& p2); void drawLine(const R2Point& p, const R2Vector& v); void drawLine(double x1, double y1, double x2, double y2); void drawString(int x, int y, const char *str, int len); void drawString(const I2Point& p, const char *str, int len); void drawString(const R2Point& p, const char *str, int len); void drawString(double x, double y, const char *str, int len); void setBackground(unsigned long bg); void setBackground(const char *colorName); void setForeground(unsigned long fg); void setForeground(const char *colorName); void fillRectangle(const I2Rectangle&); void fillRectangle(const R2Rectangle&); void redraw(); I2Point map(const R2Point& p) const; I2Point map(double x, double y) const; int mapX(double x) const; int mapY(double y) const; R2Point invMap(const I2Point& p) const; // Callbacks: virtual void onExpose(XEvent& event); virtual void onResizeRequest(XEvent& event); virtual void onKeyPress(XEvent& event); virtual void onButtonPress(XEvent& event); virtual void onButtonRelease(XEvent& event); virtual void onMotionNotify(XEvent& event); // Message loop static void messageLoop(); // Some methods implementing X-primitives void destroyWindow(); void mapRaised(); void raise(); private: int clip(const R2Point& p1, const R2Point& p2, R2Point& c1, R2Point& c2); }; #endif // // End of file "gwindow.h"