ugraph.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  ugraph.hpp
00004  *  Ubit Project
00005  *  Author: Eric Lecolinet
00006  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00007  *  (C) 1999-2006 / EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00008  *
00009  * ***********************************************************************
00010  * COPYRIGHT NOTICE : 
00011  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00012  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00013  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00014  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00015  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00016  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00017  * ***********************************************************************
00018  * ==================================================== [(c)Elc] ======= *
00019  * ==================================================== ======== ======= */
00020 
00021 #ifndef _ugraph_hpp_
00022 #define _ugraph_hpp_
00023 #include <ubit/uappli.hpp>
00024 #include <ubit/ufontMetrics.hpp>
00025 //pragma ident  "@(#)ugraph.hpp ubit:05.05.00"
00026 namespace ubit {
00027   
00028 /* ==================================================== ===== ======= */
00031 class UGraph {
00032 public:
00033   virtual ~UGraph();
00034 
00035   UGraph(UView&);
00036   UGraph(UMouseEvent&);
00037   UGraph(UPaintEvent&);
00066   UGraph(UHardWinImpl&);
00068   
00069   // ==== Related Data =========================================================
00070 
00071   UView* getView() const {return boxview;}
00073   
00074   UDisp* getDisp() const;
00076   
00077   void flush();
00079 
00080   // ==== Attributes ===========================================================
00081 
00082   void setPaintMode();
00083   void setXORMode(const UColor& background_color);
00084   bool isXORMode() const;
00090   void setColor(const UColor&);
00092   
00093   void setBackground(const UColor&);
00098   bool hasAlpha() const;
00104   float getAlpha() const {return alpha;}
00105   void setAlpha(float a);
00112   void setFont(const UFont&);
00113   void setFont(const UFontDesc&);
00115   
00116   UFontMetrics getFontMetrics(const UFont&);
00117   UFontMetrics getFontMetrics(const UFontDesc&);
00122   float getWidth() const;
00123   void setWidth(float);
00129   // ==== Clearing routines ==================================================
00130 
00131   void clearRect(float x, float y, float width, float height, bool paint = false);
00138   void clearView(bool paint = false);
00140   
00141   void copyArea(int x, int y, int width, int height,
00142                 int delta_x, int delta_y, bool paint_events_when_obscured);
00152   // ==== Drawing routines =====================================================
00153  
00154   void draw(const UShape&);
00156    
00157   void drawArc(float x, float y, float width, float height, float start_ang, float ext_ang);
00164   void drawIma(const UIma&, float x, float y, float scale = 1.);
00166 
00167   void drawLine(float x1, float y1, float x2, float y2);
00169 
00170   void drawPolyline(float xpoints[], float ypoints[], int card);
00171   void drawPolyline(std::vector<float> xpoints, std::vector<float> ypoints, int card);
00173 
00174   void drawPolygon(float xpoints[], float ypoints[], int card);  
00175   void drawPolygon(std::vector<float> xpoints, std::vector<float> ypoints, int card);
00177 
00178   void drawOval(float x, float y, float width, float height); 
00183   void drawRect(float x, float y, float width, float height);
00185  
00186   void drawRoundRect(float x, float y, float width, float height, 
00187                      float arc_w, float arc_h);
00192   void drawString(const UStr& string, float x, float y);
00193   void drawString(const char* string, int length, float x, float y);
00198   // ==== Filling routines =====================================================
00199  
00200   void fillArc(float x, float y, float width, float height, float start_ang, float ext_ang);
00205   void fillOval(float x, float y, float width, float height); 
00210   void fillPolygon(float xpoints[], float ypoints[], int card);
00211   void fillPolygon(std::vector<float> xpoints, std::vector<float> ypoints, int card);
00216   void fillRect(float x, float y, float width, float height);
00223   void fillRoundRect(float x, float y, float width, float height, 
00224                      float arc_w, float arc_h);
00229   void fillView(); 
00231       
00232   // ==== Coordinates and Clipping =============================================
00233   
00234   int XToXwin(int x_in_view);
00235   int YToYwin(int y_in_view);
00237   
00238   int XwinToX(int x_in_win);
00239   int YwintoY(int y_in_win);
00241   
00242   void setClip(const URegion&);
00243   void setClip(int x, int y, int width, int height);
00245 
00246   void setWinClip(const URegion&);
00247   void setWinClip(int x, int y, int width, int height);
00249   
00250   void getWinClip(URegion&);
00252 
00253   void getWinOffset(int& x, int& y);  
00254   void setWinOffset(int x, int y);  
00255 
00256   // === Native objects ========================================================
00257 
00258   UHardWinImpl* getHardWinImpl() const {return win;}
00259   UNatGraph* getNatGraph() const {return natgraph;}
00260   UNatDisp*  getNatDisp()  const;
00261   UNatWin*   getNatWin()   const;
00268   bool isUsing3d() const {return is_3d;}
00269 
00270   void drawNatIma(const UNatIma&, float x, float y);
00271   void drawNatPix(const UNatPix&, float x, float y);
00273   
00274   void drawNatGLIma(const UNatIma&, float x, float y, float scale = 1.);
00276   
00277   // === Implementation ========================================================
00278 #ifndef NO_DOC
00279   template<class TAB> void DrawPoly(TAB xpoints, TAB ypoints, int card, int polytype);
00280 
00281 private:
00282   friend class UGraphElem; 
00283   friend class UFontMetrics; 
00284   friend class UFrameView3d; 
00285   UGraph(UGraph&);
00286   UGraph& operator=(const UGraph&);
00287 
00288 protected:  
00289   enum {OPAQUE, UNIFORM_BLEND, PSEUDO_BLEND, TRUE_BLEND};
00290   char blend_mode;
00291   bool is_3d;
00292   float alpha;
00293   UView* boxview;           // View where the graphics are drawn
00294   UHardWinImpl* win;            // Hard Window 
00295   UNatGraph* natgraph;      // Native Graphics Context
00296   struct UGraphElem* gelem; // current pointer in graphics stack
00297 
00298   void constructs(UView&, UGraph*);
00300 
00301   void drawTexture(UGraphElem*, const UNatIma&, float x,float y,float w,float h);
00303 
00304   void blendLayers(UGraphElem* layer1, UGraphElem* layer2); //x11
00306 
00307   enum GType {NONE, WIN, CLIENT, CHILDWIN, DOUBLEBUF, BLEND};  
00308   void push(int gtype, UNatWin* dest, const URegion& clip, int xwin, int ywin);
00309   void push(int gtype, bool alloc, const URegion&);
00310   void pop();
00311   void popAll();
00312   UNatWin* allocBuffer(int width, int height);
00313   void releaseBuffer(UNatWin* buffer);
00314   
00315 public:
00316   void begin(const URegion& clip, bool xdoublebuf);
00317   void beginChildwin(const URegion& clip, int xwin, int ywin);
00318   void beginDoublebuf(const URegion& clip);
00319   void beginSubwin(const URegion& clip, int xwin, int ywin);
00320   void end();
00326   void beginBlend(const URegion& clip, float alpha);
00327   void endBlend();
00331   void blendColor(const URegion& clip, float alpha);
00337   void setClipImpl(const URegion&);
00338   void setClipImpl(int x, int y, int width, int height);  
00339 #endif
00340 };
00341 
00342 }
00343 #endif
00344 /* ==================================================== [TheEnd] ======= */
00345 /* ==================================================== [(c)Elc] ======= */

Generated on Mon Jan 29 00:20:38 2007 for Ubit by  doxygen 1.4.7