guit  0.1
 All Classes Functions Variables Typedefs Enumerations Friends
ggraphics.hpp
1 //
2 // Graphics Layer
3 // Guit GUI Toolkit
4 // Copyright © 2019/2020 Eric Lecolinet. All rights reserved.
5 // http://www.telecom-paris.fr/~elc
6 //
7 
8 #ifndef Guit_Graphics_hpp
9 #define Guit_Graphics_hpp
10 #include <gcolor.hpp>
11 #include <gfont.hpp>
12 namespace guit {
13 
14 class GFontValue;
15 class GIconValue;
16 
17 
19 class GClip {
20 public:
22  GClip() : x1(0.f), x2(0.f), y1(0.f), y2(0.f) {}
23 
25  GClip(GRect const& rect1, GRect const& rect2);
26 
27  bool empty() const {return x2 <= x1 || y2 <= y1;}
28 
29  GRect frame() const {return GRect(x1, y1, x2-x1+1, y2-y1+1);}
30 
32  void intersection(GRect const&);
33 
35  bool contain(GPoint const&) const;
36 
37  float x1, x2, y1, y2;
38 };
39 
40 
41 
83 class GGraphics {
84 protected:
86 
87 public:
88  GGraphics(GEvent&);
89 
93  float wx() const {return frame_.x;}
94  float wy() const {return frame_.y;}
95  GPoint wpos() const {return GPoint(frame_.x, frame_.y);}
97 
101  float glx() const {return frame_.x;}
102  float gly() const {return gly_;}
103  GPoint glpos() const {return GPoint(frame_.x, gly_);}
105 
108  float width() const {return frame_.w;}
109  float height() const {return frame_.h;}
110  GDim size() const {return GDim(frame_.w, frame_.h);}
112 
114  GWindow* window() {return win_;}
115 
118  GRect const& frame() const {return frame_;}
119 
121  void translate(float x, float y);
122 
123  void setScale(float scale);
124  float scale() const {return scale_;}
125 
128  void setWinClip(GRect const&);
129  void setWinClip(float x, float y, float w, float h);
130 
131  void save();
132  void restore();
133  void makeCurrent();
134  void swapBuffers();
135  void beginGL() {}
136  void endGL() {}
137 
138  GRgba const& color() const {return color_;}
139  void setColor(GRgba const* color);
140  void setColor(GColor const* color);
141  void setColor(GColor const& color);
142  void setColor(GColor const& color, float alfa);
143  void unsetColor();
144 
145  GRgba const& bgcolor() const {return bgcolor_;}
146  void setBgColor(GRgba const* color);
147  void setBgColor(GColor const* color);
148  void setBgColor(GColor const& color);
149  void setBgColor(GColor const& color, float alfa);
150  void unsetBgColor();
151 
152  void setFont(GFont const& font);
153  void setFont(GFontValue const& font);
154 
157  void setThickness(float);
158 
163  GDim drawString(float x, float y, GString const& str);
164  GDim drawString(GPoint const& p, GString const& str) {return drawString(p. x, p. y, str);}
166 
169  void drawImage(GRect const&, GIcon&);
170  void drawImage(float x, float y, float w, float h, GIconValue&);
171  void drawImage(GRect const& r, GIconValue& ima) {drawImage(r.x, r.y, r.w, r.h, ima);}
173 
176  static bool readImage(GIcon&);
177  static bool readImage(GIconValue&);
179 
182  void drawTexture(float x, float y, float w, float h, GTexture texture, GRgba const* = {});
183  static void deleteTexture(GTexture);
185 
186  void drawLine(float x1, float y1, float x2, float y2);
187  void drawLine(GPoint const& p1, GPoint const& p2) {drawLine(p1.x,p1.y,p2.x,p2.y);}
188 
189  void drawPolyline(std::vector<GPoint> const& points);
190  void drawPolygon(std::vector<GPoint> const& points);
191 
192  void drawRect(float x, float y, float w, float h);
193  void drawRect(GRect const& r) {drawRect(r.x, r.y, r.w, r.h);}
194 
195  void drawRoundRect(float x, float y, float w, float h, float xradius, float yradius);
196  void drawRoundRect(GRect const& r, float xradius, float yradius) {
197  drawRoundRect(r.x, r.y, r.w, r.h, xradius, yradius);
198  }
199 
200  void drawOval(float x, float y, float w, float h) {drawArc(x, y, w, h, 0,360,true);}
201  void drawOval(GRect const& r) {drawArc(r.x, r.y, r.w, r.h, 0,360,true);}
202 
210  void drawArc(float x, float y, float w, float h,
211  float start, float extent, bool pie = false);
212  void drawArc(GRect const& rect, float start, float extent, bool pie = false) {
213  drawArc(rect.x,rect.y,rect.w,rect.h, start, extent, pie);
214  }
216 
217  void drawPie(GRect const& rect, float start, float extent) {drawArc(rect,start,extent,true);}
218 
219  static bool pickOval(GRect const&, GPoint const&);
220  static bool pickPie(GRect const&, float start, float extent, GPoint const&);
221 
224 public:
225  bool drawfg_{}, drawbg_{};
226  float gly_{}, thickness_{}, scale_{1.0f}, savex_{}, savey_{};
227  GRgba color_, bgcolor_;
228  GFontValue font_;
229  GRect frame_;
230  GWindow* win_;
232 };
233 
234 }
235 #endif