ubit
urendercontext.hpp
1 /* ***********************************************************************
2  *
3  * URenderContext.hpp: generic rendering context
4  * Ubit GUI Toolkit - Version 6.0
5  * (C) 2008 Eric Lecolinet | ENST Paris | www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _urendercontext_hpp_
18 #define _urendercontext_hpp_ 1
19 #include <ubit/uwinImpl.hpp>
20 namespace ubit {
21 
23 public:
24  virtual bool isGlcontext() const = 0;
25  virtual UGlcontext* toGlcontext() = 0;
26  virtual const UGlcontext* toGlcontext() const = 0;
27 
28  virtual bool isSharedWith(const URenderContext*) const = 0;
30 
31  UDisp* getDisp() const {return disp;}
32  UHardwinImpl* getDest() const {return dest;}
33 
34  virtual void setDest(UHardwinImpl* dest, double xoffset, double yoffset) = 0;
35  /* changes the destination drawable and the corresponding coordinate system.
36  * Note that this function does not only change the destination but also the coordinate
37  * system according to the destination's size. This is especially important when GL
38  * is used for rendering because the GL origin is the bottom left point of the drawable
39  * while the Ubit origin is the top left point (as for most GUI toolkits).
40  * Hence:
41  * - when GL is used, Y coordinates are converted to drawable_height - Y
42  * before calling drawing functions
43  * - besides, setDest() sets the 'logical offset' to 0,0 (@see setOffset())
44  */
45 
46  virtual void setOffset(double x, double y) = 0;
47  /* changes the 'logical offset'.
48  * this
49  * The 'logical offset' if applied to X,Y coordinates before calling drawing functions.
50  * This offset is 'logical' in that sense that it is related to the Ubit coordinate
51  * system, where the origin is the top left point of the drawable.
52  always related to the Ubit
53  */
54 
55  virtual void setPaintMode(UGraph&) = 0;
56  /* sets this context in paint mode (the default mode).
57  * paint mode is the default (and the only mode available when GL is used)
58  * the foreground color is initialized according to UGraph values.
59  */
60 
61  virtual void setXORMode(UGraph&, const UColor& backcolor) = 0;
62  /* sets this context in XOR mode (not available with GL).
63  * XOR mode is not available when GL is used
64  * the foreground color is initialized according to UGraph values and the
65  * background color according to the second argument.
66  */
67 
68  virtual void set3Dmode(bool state) = 0;
70 
71  virtual void setClip(double x, double y, double width, double height) = 0;
73 
74  const URect& getClip() const {return clip;}
75 
76  virtual void setColor(UGraph&, const UColor&) = 0;
77  virtual void setBackground(UGraph&, const UColor&) = 0;
78  virtual void setFont(UGraph&, const UFontDesc&) = 0;
79  virtual void setWidth(UGraph&, double) = 0;
80 
81  virtual void makeCurrent() const = 0;
82  /* makes this context the current rendering context.
83  * calls glMakeCurrent() if this context is a UGlcontext
84  */
85 
86  virtual void swapBuffers() = 0;
87  /* swaps the front and back buffers of the current destination drawable.
88  * calls glSwapBuffers() if this context is a UGlcontext
89  */
90 
91  virtual void flush() = 0;
92  /* flushes all drawing request.
93  * calls glFlush() when GL is used.
94  */
95 
96  virtual void drawArc(double x, double y, double w, double h,
97  double start, double ext, bool filled) const = 0;
98 
99  virtual void drawIma(const UGraph&, const UIma&, double x, double y,
100  double scale) const = 0;
101 
102  virtual void drawLine(double x1, double y1, double x2, double y2) const = 0;
103 
104  virtual void drawPolygon(const float* points, int card, int polytype) const = 0;
105  virtual void drawPolygon(const std::vector<UPoint>& points, int polytype) const = 0;
106 
107  virtual void drawRect(double x, double y, double w, double h, bool filled) const = 0;
108  virtual void drawRoundRect(double x, double y, double w, double h,
109  double arc_w, double arc_h, bool filled) const = 0;
110 
111  virtual void drawString(const UHardFont*, const char* str, int str_len,
112  double x, double y) const = 0;
113 
114  virtual void copyArea(double x, double y, double w, double h, double delta_x, double delta_y,
115  bool generate_refresh_events_when_obscured) const = 0;
116 
117 protected:
118  URenderContext(UDisp* d) : disp(d), dest(null), xwin(0), ywin(0), own_dest(false) {}
119  virtual ~URenderContext() {if (own_dest) delete dest;}
120 
121  friend class UGraph;
122  friend class UDisp;
123  UDisp* disp;
124  UHardwinImpl* dest; // where graphics are drawn (can be a Window or a Pixmap)
125  URect clip;
126  double xwin, ywin; // offset from 'dest' origin
127  bool own_dest; // true if 'dest' is a pixmap that must thus be destroyed with this GC
128 };
129 
130 }
131 #endif
[Impl] Native Font.
Definition: uhardfont.hpp:35
Image.
Definition: uima.hpp:50
class for drawing on widgets.
Definition: ugraph.hpp:44
virtual void setClip(double x, double y, double width, double height)=0
impl.
2D Rectangle.
Definition: ugeom.hpp:165
Display Context.
Definition: udisp.hpp:44
[impl] Internal representation for fonts.
Definition: ufontImpl.hpp:24
Color attribute of an element or a widget.
Definition: ucolor.hpp:73
Definition: uhardfont.hpp:31
Definition: urendercontext.hpp:22
Definition: uwinImpl.hpp:84
virtual bool isSharedWith(const URenderContext *) const =0
true if the same internal OpenGL reendering context is shared.
const URect & getClip() const
impl.
Definition: urendercontext.hpp:74