ubit
ugraph.hpp
1 /*************************************************************************
2  *
3  * ugraph.hpp: Graphics Layer
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://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 _ugraph_hpp_
18 #define _ugraph_hpp_ 1
19 #include <vector>
20 #include <ubit/udefs.hpp>
21 #include <ubit/ucolor.hpp>
22 #include <ubit/ugeom.hpp>
23 namespace ubit {
24 
25 
27  UGraphAttributes() : color_rgba(0u,0u,0u,255u), bgcolor_rgba(255u,255u,255u,255u) {}
28  short font_styles;
29  float width;
30  unsigned long color, bgcolor; // for 2D_GRAPHICS
31  URgba color_rgba, bgcolor_rgba; // for GL
32  enum {OPAQUE, UNIFORM_BLEND, PSEUDO_BLEND, TRUE_BLEND} blend_mode;
33  bool in_xor_mode;
34  bool in_3d_mode; // true when displaying inside a 3Dcanvas
35 };
36 
37 
44 class UGraph : public UGraphAttributes {
45 public:
48  class Glpaint {
49  public:
50  Glpaint(UPaintEvent&, bool _push_attrib);
51  Glpaint(UView*, bool _push_attrib);
52  virtual ~Glpaint();
53  virtual void begin(UView*, bool _push_attrib);
54  virtual void end();
55  protected:
56  static int count;
57  int no;
58  bool push_attrib;
59  UHardwinImpl* hardwin;
60  };
61 
62 
106  virtual ~UGraph();
107 
108  UBox* getBox() const;
114  UView* getView() const {return boxview;}
120  UDisp* getDisp() const {return disp;}
122 
123  URect getClip() const {URect r; getClip(r); return r;}
125 
126  void getClip(URect&) const;
128 
129  void setClip(const URect&);
131 
132  // ==== Attributes ===========================================================
133 
134  void setPaintMode();
142  void setXORMode(const UColor& background_color);
152  bool isXORMode() const {return in_xor_mode;}
157  void setColor(const UColor&);
172  void setColor(const UColor&, float alpha);
177  void setColor(const UColor&, unsigned int alpha);
182  void setBackground(const UColor&);
186  void setFont(const UFont&);
190  void setFont(const UFontDesc&);
194  void getFontMetrics(const UFont&, UFontMetrics&) const;
198  void setWidth(float);
203  float getWidth() const;
208  void flush() const;
210 
211  // ==== Drawing routines =====================================================
212 
213  void draw(const UShape&) const;
215 
216  void fill(const UShape&) const;
218 
219  void drawArc(double x, double y, double width, double height,
220  double start_angle, double ext_angle) const;
227  void fillArc(double x, double y, double width, double height,
228  double start_angle, double ext_angle) const;
230 
231  void drawEllipse(double x, double y, double width, double height) const;
233 
234  void fillEllipse(double x, double y, double width, double height) const;
236 
237  void drawIma(const UIma&, double x, double y, double scale = 1.) const;
239 
240  void drawLine(double x1, double y1, double x2, double y2) const;
242 
243  void drawLine(const UPoint& p1, const UPoint& p2) const;
245 
246  static const int LINE_STRIP, LINE_LOOP, FILLED;
247 
248  void drawPolygon(const std::vector<UPoint>& points, int type = LINE_LOOP) const;
253  void drawPolygon(const float* points, int npoints, int type = LINE_LOOP) const;
259  void drawPolyline(const std::vector<UPoint>& points) const {drawPolygon(points, LINE_STRIP);}
261 
262  void fillPolygon(const std::vector<UPoint>& points) const {drawPolygon(points, FILLED);}
264 
265  void drawRect(double x, double y, double width, double height) const;
267 
268  void fillRect(double x, double y, double width, double height) const;
270 
271  void drawRoundRect(double x, double y, double width, double height,
272  double arc_w, double arc_h) const;
277  void fillRoundRect(double x, double y, double width, double height,
278  double arc_w, double arc_h) const;
280 
281  void drawString(const UStr& string, double x, double y) const;
283 
284  void drawString(const char* string, int length, double x, double y) const;
286 
287  void copyArea(double x, double y, double width, double height,
288  double delta_x, double delta_y,
289  bool paint_events_when_obscured) const;
299  // === Impl. =================================================================
300 #ifndef NO_DOC
301 
302  UGraph(UView*);
308  UHardwinImpl* getHardwin() const {return hardwin;}
309  /* [Impl] returns the hard window where this UGraph can draw on.
310  * Ubit Windows (UWin and subclasses) can either be hard (system windows) or
311  * soft (simulated), in which case they are drawn on the top of a hard window.
312  * getHardwin() always returns the hard window.
313  */
314 
315  void getHardwinClip(URect&) const;
317 
318  void setHardwinClip(const URect&);
320 
321  void set3Dmode(bool state);
322  bool in3Dmode() const {return in_3d_mode;}
323 
324  void getWinOffset(float& x, float& y) const;
325  void setWinOffset(float x, float y) const;
326  static void setViewportOrtho(UHardwinImpl*);
327 
328 private:
329  UGraph(UGraph&);
330  UGraph& operator=(const UGraph&);
331 protected:
332  friend class UView;
333  friend class U3DcanvasView;
334  friend class UPaintEvent;
335  friend class UFontMetrics;
336  friend class URenderContext;
337  friend class UGlcontext;
338  friend class UX11context;
339  UDisp* disp; // display
340  UView* boxview; // view where the graphics are drawn
341  UHardwinImpl* hardwin; // corresponding hard window
342  UHardFont* font; // native font that is currently used
343  URenderContext* rc; // corresponding rendering context
344  bool is_client;
345 #endif // NO_DOC
346 };
347 
348 }
349 #endif
UView * getView() const
returns the view of the widget where this UGraph can draw on.
Definition: ugraph.hpp:114
[Impl] Native Font.
Definition: uhardfont.hpp:35
Image.
Definition: uima.hpp:50
Box container.
Definition: ubox.hpp:64
2D Point.
Definition: ugeom.hpp:25
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
Display Context.
Definition: udisp.hpp:44
URect getClip() const
returns the drawing zone relatively to the origin of getView().
Definition: ugraph.hpp:123
[impl] Internal representation for fonts.
Definition: ufontImpl.hpp:24
Color attribute of an element or a widget.
Definition: ucolor.hpp:73
void fillPolygon(const std::vector< UPoint > &points) const
fills a polygon (that must be convex).
Definition: ugraph.hpp:262
for client GL Graphics.
Definition: ugraph.hpp:48
Paint event.
Definition: uevent.hpp:377
Specifies a RGBA value for defining UColor(s).
Definition: ucolor.hpp:24
UDisp * getDisp() const
returns the display that is related to this UGraph.
Definition: ugraph.hpp:120
Abstract Base class for geometrical shapes.
Definition: ugeom.hpp:85
Box View.
Definition: uview.hpp:65
Font of a UElem or UBox container.
Definition: ufont.hpp:30
Definition: u3d.hpp:173
Definition: uhardfont.hpp:31
Definition: urendercontext.hpp:22
Definition: uwinImpl.hpp:84
Definition: ufontmetrics.hpp:21
void drawPolyline(const std::vector< UPoint > &points) const
draws a polyline.
Definition: ugraph.hpp:259
bool isXORMode() const
sets the drawing mode in XOR mode.
Definition: ugraph.hpp:152
Definition: ugraph.hpp:26
Ubit String.
Definition: ustr.hpp:72