SGL
gdrawingsurface.h
1 /*
2  * File: gdrawingsurface.h
3  * -----------------------
4  *
5  * @author Marty Stepp
6  * @version 2018/09/10
7  * - added doc comments for new documentation generation
8  * @version 2018/08/23
9  * - renamed to gdrawingsurface.h to replace Java version
10  * @version 2018/07/11
11  * - initial version
12  */
13 
14 
15 #ifndef _gdrawingsurface_h
16 #define _gdrawingsurface_h
17 
18 #include <string>
19 #include <QFont>
20 #include <QWidget>
21 
22 #include "gobjects.h"
23 #include "grid.h"
24 #include "gtypes.h"
25 
32 public:
36  virtual void clear() = 0;
37 
41  virtual void conditionalRepaint();
42 
46  virtual void conditionalRepaintRegion(int x, int y, int width, int height);
47 
51  virtual void conditionalRepaintRegion(const GRectangle& bounds);
52 
58  virtual void draw(GObject* gobj) = 0;
59 
65  virtual void draw(GObject* gobj, double x, double y);
66 
71  virtual void draw(GObject& gobj);
72 
77  virtual void draw(GObject& gobj, double x, double y);
78 
83  virtual void draw(QPainter* painter) = 0;
84 
90  virtual void drawArc(double x, double y, double width, double height, double start, double sweep);
91 
99  virtual void drawImage(const string& filename, double x = 0, double y = 0);
100 
106  virtual void drawLine(const GPoint& p0, const GPoint& p1);
107 
113  virtual void drawLine(double x0, double y0, double x1, double y1);
114 
120  virtual void drawOval(const GRectangle& bounds);
121 
127  virtual void drawOval(double x, double y, double width, double height);
128 
137  virtual GPoint drawPolarLine(const GPoint& p0, double r, double theta);
138 
147  virtual GPoint drawPolarLine(double x0, double y0, double r, double theta);
148 
153  virtual void drawPixel(double x, double y);
154 
159  virtual void drawPixel(double x, double y, int color);
160 
165  virtual void drawPixel(double x, double y, const string& color);
166 
172  virtual void drawPolygon(std::initializer_list<double> coords);
173 
179  virtual void drawPolygon(std::initializer_list<GPoint> points);
180 
186  virtual void drawRect(const GRectangle& bounds);
187 
193  virtual void drawRect(double x, double y, double width, double height);
194 
200  virtual void drawString(const string& text, double x, double y);
201 
207  virtual void fillArc(double x, double y, double width, double height, double start, double sweep);
208 
215  virtual void fillOval(const GRectangle& bounds);
216 
223  virtual void fillOval(double x, double y, double width, double height);
224 
230  virtual void fillPolygon(std::initializer_list<double> coords);
231 
237  virtual void fillPolygon(std::initializer_list<GPoint> coords);
238 
244  virtual void fillRect(const GRectangle& bounds);
245 
251  virtual void fillRect(double x, double y, double width, double height);
252 
257  virtual int getARGB(double x, double y) const;
258 
263  virtual string getBackground() const;
264 
269  virtual int getBackgroundInt() const;
270 
279  virtual string getColor() const;
280 
289  virtual int getColorInt() const;
290 
296  virtual string getFillColor() const;
297 
303  virtual int getFillColorInt() const;
304 
310  virtual string getFont() const;
311 
320  virtual string getForeground() const;
321 
330  virtual int getForegroundInt() const;
331 
337  virtual GObject::LineStyle getLineStyle() const;
338 
343  virtual double getLineWidth() const;
344 
358  virtual int getPixel(double x, double y) const = 0;
359 
374  virtual int getPixelARGB(double x, double y) const = 0;
375 
380  virtual Grid<int> getPixels() const = 0;
381 
389  virtual Grid<int> getPixelsARGB() const = 0;
390 
398  virtual string getPixelString(double x, double y) const;
399 
413  virtual int getRGB(double x, double y) const;
414 
426  virtual string getRGBString(double x, double y) const;
427 
436  virtual bool isAutoRepaint() const;
437 
446  virtual bool isRepaintImmediately() const;
447 
456  virtual void repaint() = 0;
457 
464  virtual void repaintRegion(int x, int y, int width, int height) = 0;
465 
472  virtual void repaintRegion(const GRectangle& bounds);
473 
483  virtual void setAutoRepaint(bool autoRepaint);
484 
489  virtual void setBackground(int color);
490 
495  virtual void setBackground(const string& color);
496 
505  virtual void setColor(int color);
506 
515  virtual void setColor(const string& color);
516 
522  virtual void setFillColor(int color);
523 
529  virtual void setFillColor(const string& color);
530 
536  virtual void setFont(const QFont& font);
537 
543  virtual void setFont(const string& font);
544 
553  virtual void setForeground(int color);
554 
563  virtual void setForeground(const string& color);
564 
569  virtual void setLineWidth(double lineWidth);
570 
576  virtual void setLineStyle(GObject::LineStyle lineStyle);
577 
590  virtual void setPixel(double x, double y, int rgb) = 0;
591 
604  virtual void setPixel(double x, double y, int r, int g, int b);
605 
618  virtual void setPixel(double x, double y, const string& color);
619 
631  virtual void setPixelARGB(double x, double y, int argb) = 0;
632 
644  virtual void setPixelARGB(double x, double y, int a, int r, int g, int b);
645 
653  virtual void setPixels(const Grid<int>& pixels) = 0;
654 
662  virtual void setPixelsARGB(const Grid<int>& pixelsARGB) = 0;
663 
673  virtual void setRepaintImmediately(bool autoRepaint);
674 
687  virtual void setRGB(double x, double y, int rgb);
688 
701  virtual void setRGB(double x, double y, int r, int g, int b);
702 
715  virtual void setRGB(double x, double y, const string& color);
716 
717 protected:
718  GDrawingSurface();
719  virtual ~GDrawingSurface();
720 
723  string _color;
724  string _fillColor;
725  string _font;
730  double _lineWidth;
732 
736  void checkBounds(const string& member, double x, double y, double width, double height) const;
737 
741  void checkColor(const string& member, int rgb) const;
742 
746  void checkSize(const string& member, double width, double height) const;
747 
754  virtual void initializeGObject(GObject& obj, bool filled = false);
755 
762  virtual void initializeGObject(GObject* obj, bool filled = false);
763 
769  virtual void setDrawingForwardTarget(GDrawingSurface* forwardTarget);
770 };
771 
779 class GForwardDrawingSurface : public virtual GDrawingSurface {
780 public:
781  void clear() override;
782  void draw(GObject* gobj) override;
783  void draw(GObject* gobj, double x, double y) override;
784  void draw(GObject& gobj) override;
785  void draw(GObject& gobj, double x, double y) override;
786  void draw(QPainter* painter) override;
787  int getPixel(double x, double y) const override;
788  int getPixelARGB(double x, double y) const override;
789  Grid<int> getPixels() const override;
790  Grid<int> getPixelsARGB() const override;
791  bool isAutoRepaint() const override;
792  void repaint() override;
793  void repaintRegion(int x, int y, int width, int height) override;
794  void setAutoRepaint(bool autoRepaint) override;
795  void setBackground(int color) override;
796  void setBackground(const string& color) override;
797  void setColor(int color) override;
798  void setColor(const string& color) override;
799  void setFillColor(int color) override;
800  void setFillColor(const string& color) override;
801  void setFont(const QFont& font) override;
802  void setFont(const string& font) override;
803  void setLineWidth(double lineWidth) override;
804  void setPixel(double x, double y, int rgb) override;
805  void setPixel(double x, double y, int r, int g, int b) override;
806  void setPixelARGB(double x, double y, int argb) override;
807  void setPixelARGB(double x, double y, int a, int r, int g, int b) override;
808  void setPixels(const Grid<int>& pixels) override;
809  void setPixelsARGB(const Grid<int>& pixelsARGB) override;
810  void setRepaintImmediately(bool repaintImmediately) override;
811 
812 protected:
813  virtual void ensureForwardTarget() = 0;
814  virtual void ensureForwardTargetConstHack() const;
815 };
816 
817 #endif // _gcanvas_h
virtual Grid< int > getPixels() const =0
Returns all pixels of the surface as a Grid, where rows represent y values and columns represent x va...
virtual void conditionalRepaintRegion(int x, int y, int width, int height)
Repaints the given region of the interactor only if its contents have changed.
Definition: gdrawingsurface.cpp:71
virtual void setColor(int color)
Sets the current foreground outline color of the interactor as as RGB integer.
Definition: gdrawingsurface.cpp:375
virtual void initializeGObject(GObject &obj, bool filled=false)
Initializes a new graphical object to be drawn.
Definition: gdrawingsurface.cpp:314
virtual int getFillColorInt() const
Returns the current fill color of the interactor as an RGB integer.
Definition: gdrawingsurface.cpp:262
virtual void drawImage(string filename, double x=0, double y=0)
Draws an image loaded from the given file name onto the background pixel layer of this interactor at ...
Definition: gdrawingsurface.cpp:104
void checkSize(string member, double width, double height) const
Throws an error if the given width/height values are out of bounds.
Definition: gdrawingsurface.cpp:50
virtual void setFillColor(int color)
Sets the current fill color of the interactor as an RGB integer.
Definition: gdrawingsurface.cpp:405
virtual string getRGBString(double x, double y) const
Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor...
Definition: gdrawingsurface.cpp:310
virtual int getColorInt() const
Returns the current foreground outline color of the interactor as an RGB integer. ...
Definition: gdrawingsurface.cpp:246
virtual string getBackground() const
Returns the current background color of the interactor as a string.
Definition: gdrawingsurface.cpp:222
virtual string getForeground() const
Returns the current foreground outline color of the interactor as a string.
Definition: gdrawingsurface.cpp:278
string _font
Definition: gdrawingsurface.h:725
int _fillColorInt
Definition: gdrawingsurface.h:728
virtual string getColor() const
Returns the current foreground outline color of the interactor as a string.
Definition: gdrawingsurface.cpp:238
virtual int getPixelARGB(double x, double y) const =0
Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor...
GDrawingSurface is an abstract superclass for types that allow drawing shapes and pixels onto themsel...
Definition: gdrawingsurface.h:31
virtual void drawString(string text, double x, double y)
Draws a text string onto the background pixel layer of this interactor at the given x/y location in t...
Definition: gdrawingsurface.cpp:174
virtual void setLineStyle(GObject::LineStyle lineStyle)
Sets the current line style which will be used to draw outlines of shapes and lines.
Definition: gdrawingsurface.cpp:447
virtual string getFillColor() const
Returns the current fill color of the interactor as a string.
Definition: gdrawingsurface.cpp:254
virtual GPoint drawPolarLine(const GPoint &p0, double r, double theta)
Draws a line using polar coordinates onto the background pixel layer of this interactor in the curren...
Definition: gdrawingsurface.cpp:129
string _fillColor
Definition: gdrawingsurface.h:724
virtual void setForeground(int color)
Sets the current foreground outline color of the interactor as an RGB integer.
Definition: gdrawingsurface.cpp:439
virtual void setRepaintImmediately(bool autoRepaint)
Sets whether the interactor should repaint itself automatically whenever any change is made to its gr...
Definition: gdrawingsurface.cpp:475
virtual void fillOval(const GRectangle &bounds)
Draws a filled oval with the given bounding box onto the background pixel layer of this interactor at...
Definition: gdrawingsurface.cpp:186
virtual int getBackgroundInt() const
Returns the current background color of the interactor as an RGB integer.
Definition: gdrawingsurface.cpp:230
virtual void drawRect(const GRectangle &bounds)
Draws an unfilled rectangle of the given dimensions onto the background pixel layer of this interacto...
Definition: gdrawingsurface.cpp:164
void checkBounds(string member, double x, double y, double width, double height) const
Throws an error if the given x/y values are out of bounds.
Definition: gdrawingsurface.cpp:38
virtual Grid< int > getPixelsARGB() const =0
Returns all pixels of the background layer of the surface as a Grid, where rows represent y values an...
int _backgroundColorInt
Definition: gdrawingsurface.h:726
virtual string getPixelString(double x, double y) const
Returns the color of the pixel at the given x/y coordinates of the image as a string such as "#ff00cc...
Definition: gdrawingsurface.cpp:302
virtual void setBackground(int color)
Sets the current background color of the interactor as an RGB integer.
Definition: gdrawingsurface.cpp:357
virtual void repaintRegion(int x, int y, int width, int height)=0
Instructs the interactor to repaint the given region of pixel data.
virtual void drawPolygon(std::initializer_list< double > coords)
Draws an unfilled polygon containing the given points onto the background pixel layer of this interac...
Definition: gdrawingsurface.cpp:152
virtual void drawArc(double x, double y, double width, double height, double start, double sweep)
Draws an unfilled arc with the given attributes onto the background pixel layer of this interactor in...
Definition: gdrawingsurface.cpp:98
GObject::LineStyle _lineStyle
Definition: gdrawingsurface.h:729
virtual string getFont() const
Returns the current text font of the interactor as a font string.
Definition: gdrawingsurface.cpp:270
int _colorInt
Definition: gdrawingsurface.h:727
virtual void setAutoRepaint(bool autoRepaint)
Sets whether the interactor should repaint itself automatically whenever any change is made to its gr...
Definition: gdrawingsurface.cpp:349
string _color
Definition: gdrawingsurface.h:723
virtual void setRGB(double x, double y, int rgb)
Sets the color of the given x/y pixel in the background layer of the interactor to the given RGB valu...
Definition: gdrawingsurface.cpp:479
virtual int getARGB(double x, double y) const
Returns the pixel color data at the given x/y location, retaining alpha-channel transparency in the t...
Definition: gdrawingsurface.cpp:218
virtual void fillRect(const GRectangle &bounds)
Draws a filled rectangle of the given dimensions onto the background pixel layer of this interactor i...
Definition: gdrawingsurface.cpp:208
GDrawingSurface * _forwardTarget
Definition: gdrawingsurface.h:721
virtual int getForegroundInt() const
Returns the current foreground outline color of the interactor as an RGB integer. ...
Definition: gdrawingsurface.cpp:282
virtual GObject::LineStyle getLineStyle() const
Returns the current line style which will be used to draw outlines of shapes and lines.
Definition: gdrawingsurface.cpp:286
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:62
void checkColor(string member, int rgb) const
Throws an error if the given rgb value is not a valid color.
Definition: gdrawingsurface.cpp:42
double _lineWidth
Definition: gdrawingsurface.h:730
virtual void setPixelARGB(double x, double y, int argb)=0
Sets the color of the given x/y pixel in the background layer of the interactor to the given ARGB val...
LineStyle
Styles that can be used for the outline around various shapes.
Definition: gobjects.h:68
virtual void setLineWidth(double lineWidth)
Sets the thickness used when drawing outlines of shapes and lines.
Definition: gdrawingsurface.cpp:455
virtual void drawPixel(double x, double y)
Colors the given x/y pixel of the background layer of this interactor using the interactor&#39;s current ...
Definition: gdrawingsurface.cpp:140
virtual bool isAutoRepaint() const
Returns true if the interactor should repaint itself automatically whenever any change is made to its...
Definition: gdrawingsurface.cpp:332
virtual int getRGB(double x, double y) const
Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor...
Definition: gdrawingsurface.cpp:306
GDrawingSurface()
Definition: gdrawingsurface.cpp:19
virtual int getPixel(double x, double y) const =0
Returns the color of the pixel at the given x/y coordinates of the background layer of the interactor...
virtual double getLineWidth() const
Returns the thickness used when drawing outlines of shapes and lines.
Definition: gdrawingsurface.cpp:294
virtual void fillPolygon(std::initializer_list< double > coords)
Draws a filled polygon containing the given points onto the background pixel layer of this interactor...
Definition: gdrawingsurface.cpp:196
virtual void fillArc(double x, double y, double width, double height, double start, double sweep)
Draws a filled arc with the given attributes onto the background pixel layer of this interactor in th...
Definition: gdrawingsurface.cpp:180
virtual bool isRepaintImmediately() const
Returns true if the interactor should repaint itself automatically whenever any change is made to its...
Definition: gdrawingsurface.cpp:340
virtual void setPixelsARGB(const Grid< int > &pixelsARGB)=0
Sets the color of the all pixels in the background layer of the interactor to the given ARGB values...
bool _autoRepaint
Definition: gdrawingsurface.h:731
This struct contains real-valued x, y, width, and height fields.
Definition: gtypes.h:289
virtual ~GDrawingSurface()
Definition: gdrawingsurface.cpp:34
virtual void setPixels(const Grid< int > &pixels)=0
Sets the color of the all pixels in the background layer of the interactor to the given RGB values...
virtual void drawLine(const GPoint &p0, const GPoint &p1)
Draws a line between the given two points onto the background pixel layer of this interactor at the g...
Definition: gdrawingsurface.cpp:109
virtual void drawOval(const GRectangle &bounds)
Draws an unfilled oval with the given bounding box onto the background pixel layer of this interactor...
Definition: gdrawingsurface.cpp:119
virtual void conditionalRepaint()
Repaints the interactor only if its contents have changed.
Definition: gdrawingsurface.cpp:61
virtual void draw(GObject *gobj)=0
Draws the given graphical object onto the background pixel layer of this interactor.
This struct contains real-valued x and y fields.
Definition: gtypes.h:198
string _backgroundColor
Definition: gdrawingsurface.h:722
virtual void repaint()=0
Instructs the interactor to redraw itself on the screen.
virtual void setPixel(double x, double y, int rgb)=0
Sets the color of the given x/y pixel in the background layer of the interactor to the given RGB valu...
virtual void clear()=0
Erases any pixel data from the drawing surface.