SGL
gobjects.h
1 /*
2  * File: gobjects.h
3  * ----------------
4  * This file exports a hierarchy of graphical shapes based on
5  * the model developed for the ACM Java Graphics.
6  * <include src="pictures/ClassHierarchies/GObjectHierarchy-h.html">
7  *
8  * @author Marty Stepp
9  * @version 2021/04/09
10  * - added sgl namespace
11  * @version 2021/04/03
12  * - removed dependency on custom collections
13  * @version 2019/05/05
14  * - added predictable GLine point ordering
15  * @version 2019/04/23
16  * - bug fix for loading GImage from file on Windows related to istream change
17  * @version 2019/03/07
18  * - added support for loading a GImage directly from istream (htiek)
19  * @version 2018/09/14
20  * - added opacity support
21  * - added GCanvas-to-GImage conversion support
22  * @version 2018/09/08
23  * - added doc comments for new documentation generation
24  * @version 2018/08/23
25  * - renamed to gobjects.h to replace Java version
26  * @version 2018/06/30
27  * - initial version
28  */
29 
30 
31 #ifndef _gobjects_h
32 #define _gobjects_h
33 
34 #include <initializer_list>
35 #include <iostream>
36 #include <vector>
37 #include <QFont>
38 #include <QImage>
39 #include <QPainter>
40 #include <QPen>
41 #include <QWidget>
42 
43 #include "gtypes.h"
44 
45 namespace sgl {
46 
47 class GCanvas;
48 class GCompound;
49 class GDiffImage;
50 
66 class GObject {
67 public:
72  enum LineStyle {
79  };
80 
84  virtual ~GObject();
85 
89  virtual bool contains(double x, double y) const;
90 
94  virtual bool contains(const GPoint& pt) const;
95 
101  virtual void draw(QPainter* painter) = 0;
102 
106  virtual GPoint getBottomRightLocation() const;
107 
112  virtual double getBottomY() const;
113 
124  virtual GRectangle getBounds() const;
125 
130  virtual GPoint getCenterLocation() const;
131 
136  virtual double getCenterX() const;
137 
142  virtual double getCenterY() const;
143 
151  virtual string getColor() const;
152 
157  virtual string getFillColor() const;
158 
163  virtual double getHeight() const;
164 
168  virtual LineStyle getLineStyle() const;
169 
174  virtual double getLineWidth() const;
175 
179  virtual GPoint getLocation() const;
180 
185  virtual double getOpacity() const;
186 
196  virtual GCompound* getParent() const;
197 
202  virtual double getRightX() const;
203 
207  virtual GDimension getSize() const;
208 
214  virtual string getType() const = 0;
215 
220  virtual double getWidth() const;
221 
225  virtual double getX() const;
226 
230  virtual double getY() const;
231 
236  static bool isAntiAliasing();
237 
241  virtual bool isFilled() const;
242 
249  virtual bool isTransformed() const;
250 
254  virtual bool isVisible() const;
255 
260  virtual void move(double dx, double dy);
261 
265  virtual void repaint();
266 
270  virtual void resetTransform();
271 
279  virtual void rotate(double theta);
280 
289  virtual void scale(double sf);
290 
300  virtual void scale(double sx, double sy);
301 
306  void sendBackward();
307 
312  void sendForward();
313 
320  void sendToBack();
321 
328  void sendToFront();
329 
335  static void setAntiAliasing(bool value);
336 
340  virtual void setBounds(double x, double y, double width, double height);
341 
345  virtual void setBounds(const GRectangle& size);
346 
350  virtual void setBottomY(double y);
351 
355  virtual void setRightX(double x);
356 
360  virtual void setBottomRightLocation(double x, double y);
361 
365  virtual void setBottomRightLocation(const GPoint& pt);
366 
370  virtual void setCenterX(double x);
371 
375  virtual void setCenterY(double y);
376 
380  virtual void setCenterLocation(double x, double y);
381 
385  virtual void setCenterLocation(const GPoint& pt);
386 
397  virtual void setColor(int r, int g, int b);
398 
407  virtual void setColor(int rgb);
408 
417  virtual void setColor(const string& color);
418 
429  virtual void setFillColor(int r, int g, int b);
430 
438  virtual void setFillColor(int rgb);
439 
448  virtual void setFillColor(const string& color);
449 
454  virtual void setFilled(bool flag);
455 
461  virtual void setFont(const QFont& font);
462 
476  virtual void setFont(const string& font);
477 
488  virtual void setForeground(int r, int g, int b);
489 
498  virtual void setForeground(int rgb);
499 
508  virtual void setForeground(const string& color);
509 
514  virtual void setHeight(double height);
515 
520  virtual void setLineStyle(LineStyle lineStyle);
521 
526  virtual void setLineWidth(double lineWidth);
527 
532  virtual void setLocation(double x, double y);
533 
538  virtual void setLocation(const GPoint& pt);
539 
545  virtual void setOpacity(double opacity);
546 
550  virtual void setSize(double width, double height);
551 
555  virtual void setSize(const GDimension& size);
556 
561  virtual void setVisible(bool flag);
562 
567  virtual void setWidth(double width);
568 
572  virtual void setX(double x);
573 
577  virtual void setY(double y);
578 
582  virtual string toString() const;
583 
584 // Private section
585 private:
586  // forbid assignment between objects
587  const GObject& operator =(const GObject&) {
588  return *this;
589  }
590 
591  // forbid copy construction
592  GObject(const GObject&) {
593  // empty
594  }
595 
596  // whether to anti-alias graphical objects; default true
597  static bool _sAntiAliasing;
598 
599  /* Instance variables */
600 protected:
601  double _x; // the x coordinate of the origin
602  double _y; // the y coordinate of the origin
603  double _width; // the width of the bounding rectangle
604  double _height; // the height of the bounding rectangle
605  double _lineWidth; // the width of the line in pixels
606  double _opacity; // 0.0 (transparent) - 1.0 (opaque, default)
607  LineStyle _lineStyle; // line style such as solid or dashed
608  string _color; // the color of the object
610  string _fillColor; // color used to fill the object
612  string _font; // the font string of the label
613  bool _fillFlag; // indicates whether the object is filled
614  bool _visible; // indicates if object is visible
615  bool _transformed; // indicates if object is transformed
616  GCompound* _parent; // pointer to the parent
617  QPen _pen; // for outlines
618  QBrush _brush; // for filling
619  QTransform _transform; // for transformations (rotate, scale)
620 
621 protected:
626  GObject(double x = 0, double y = 0, double width = 0, double height = 0);
627 
633  virtual void initializeBrushAndPen(QPainter* painter = nullptr);
634 
639  static Qt::PenStyle toQtPenStyle(LineStyle lineStyle);
640 
645  virtual string toStringExtra() const;
646 
647  friend class GArc;
648  friend class GCompound;
649  friend class GImage;
650  friend class GInteractor;
651  friend class GLine;
652  friend class GOval;
653  friend class GPolygon;
654  friend class GRect;
655  friend class GRoundRect;
656  friend class GText;
657 };
658 
676 class GArc : public GObject {
677 public:
682  GArc(double width = 0, double height = 0, double start = 0, double sweep = 0);
683 
689  GArc(double x, double y, double width, double height, double start, double sweep);
690 
691  /* @inherit */
692  bool contains(double x, double y) const override;
693 
698  void draw(QPainter* painter) override;
699 
700  /* @inherit */
701  GRectangle getBounds() const override;
702 
706  virtual GPoint getEndPoint() const;
707 
711  virtual GRectangle getFrameRectangle() const;
712 
716  virtual double getStartAngle() const;
717 
721  virtual GPoint getStartPoint() const;
722 
726  virtual double getSweepAngle() const;
727 
728  /* @inherit */
729  string getType() const override;
730 
734  virtual void setFrameRectangle(const GRectangle& rect);
735 
739  virtual void setFrameRectangle(double x, double y, double width, double height);
740 
744  virtual void setStartAngle(double start);
745 
749  virtual void setSweepAngle(double start);
750 
751  /* @inherit */
752  string toStringExtra() const override;
753 
754 private:
755  virtual bool containsAngle(double theta) const;
756  virtual GPoint getArcPoint(double theta) const;
757 
758  /* Instance variables */
759  double _start; /* Starting angle of the arc */
760  double _sweep; /* How many degrees the arc runs */
761 };
762 
769 class GCompound : public GObject {
770 public:
774  GCompound();
775 
782  virtual void add(GObject* gobj);
783 
791  virtual void add(GObject* gobj, double x, double y);
792 
796  virtual void add(GObject& gobj);
797 
804  virtual void add(GObject& gobj, double x, double y);
805 
810  virtual void clear();
811 
816  virtual void conditionalRepaint();
817 
822  virtual void conditionalRepaintRegion(int x, int y, int width, int height);
823 
828  virtual void conditionalRepaintRegion(const GRectangle& bounds);
829 
830  /* @inherit */
831  bool contains(double x, double y) const override;
832 
837  void draw(QPainter* painter) override;
838 
839  /* @inherit */
840  GRectangle getBounds() const override;
841 
847  virtual GObject* getElement(int index) const;
848 
853  virtual GObject* getElementAt(double x, double y) const;
854 
858  virtual int getElementCount() const;
859 
860  /* @inherit */
861  string getType() const override;
862 
871  virtual QWidget* getWidget() const;
872 
877  virtual bool isAutoRepaint() const;
878 
882  virtual bool isEmpty() const;
883 
888  virtual void remove(GObject* gobj);
889 
893  virtual void remove(GObject& gobj);
894 
899  virtual void removeAll();
900 
904  void repaint() override;
905 
910  virtual void repaintRegion(int x, int y, int width, int height);
911 
916  virtual void repaintRegion(const GRectangle& bounds);
917 
922  virtual void setAutoRepaint(bool autoRepaint);
923 
932  virtual void setWidget(QWidget* widget);
933 
934  /* @inherit */
935  string toString() const override;
936 
937 private:
938  // methods to move an object in the z-ordering
939  void sendBackward(GObject* gobj);
940  void sendForward(GObject* gobj);
941  void sendToBack(GObject* gobj);
942  void sendToFront(GObject* gobj);
943  virtual int findGObject(GObject* gobj) const;
944  virtual void removeAt(int index);
945 
946  // instance variables
947  std::vector<GObject*> _contents;
948  QWidget* _widget = nullptr; // widget containing this compound
949  bool _autoRepaint; // automatically repaint on any change; default true
950 
951  friend class GObject;
952 };
953 
957 class GImage : public GObject {
958 public:
967  GImage(const string& filename = "", double x = 0, double y = 0);
968 
977  GImage(std::istream& source, double x = 0, double y = 0);
978 
983  GImage(double width, double height);
984 
988  virtual ~GImage();
989 
990 
991 
996  void draw(QPainter* painter) override;
997 
1002  virtual string getFileName() const;
1003 
1008  virtual int getPixel(int x, int y) const;
1009 
1010  /* @inherit */
1011  string getType() const override;
1012 
1018  virtual void setPixel(int x, int y, int rgb);
1019 
1020  /* @inherit */
1021  string toStringExtra() const override;
1022 
1023 protected:
1028  GImage(QImage* qimage);
1029 
1033  QImage* getQImage() const;
1034 
1035 private:
1040  bool load(const string& filename);
1041 
1046  bool loadFromStream(std::istream& input);
1047 
1048  string _filename;
1049  QImage* _qimage;
1050 
1051  friend class GCanvas;
1052  friend class GDiffImage;
1053 };
1054 
1058 class GLine : public GObject {
1059 public:
1066  GLine(double x0 = 0, double y0 = 0, double x1 = 0, double y1 = 0, LineStyle lineStyle = LINE_SOLID);
1067 
1073  GLine(const GPoint& p0, const GPoint& p1);
1074 
1075  /* @inherit */
1076  bool contains(double x, double y) const override;
1077 
1082  void draw(QPainter* painter) override;
1083 
1084  /* @inherit */
1085  GRectangle getBounds() const override;
1086 
1090  virtual GPoint getEndPoint() const;
1091 
1095  virtual double getEndX() const;
1096 
1100  virtual double getEndY() const;
1101 
1102  /* @inherit */
1103  double getHeight() const override;
1104 
1109  virtual GPoint getStartPoint() const;
1110 
1115  virtual double getStartX() const;
1116 
1121  virtual double getStartY() const;
1122 
1123  /* @inherit */
1124  string getType() const override;
1125 
1126  /* @inherit */
1127  double getWidth() const override;
1128 
1134  virtual void setEndPoint(double x1, double y1);
1135 
1141  virtual void setEndPoint(const GPoint& p);
1142 
1149  virtual void setPoints(double x0, double y0, double x1, double y1);
1150 
1157  virtual void setPoints(const GPoint& p0, const GPoint& p1);
1158 
1164  virtual void setStartPoint(double x0, double y0);
1165 
1171  virtual void setStartPoint(const GPoint& p);
1172 
1173  /* @inherit */
1174  string toStringExtra() const override;
1175 
1176 protected:
1177  /* Instance variables */
1178  double _dx; // the x displacement of the line
1179  double _dy; // the y displacement of the line
1180 };
1181 
1186 class GOval : public GObject {
1187 public:
1193  GOval(double x = 0, double y = 0, double width = 0, double height = 0);
1194 
1195  /* @inherit */
1196  bool contains(double x, double y) const override;
1197 
1202  void draw(QPainter* painter) override;
1203 
1204  /* @inherit */
1205  string getType() const override;
1206 };
1207 
1215 class GPolygon : public GObject {
1216 public:
1220  GPolygon();
1221 
1225  GPolygon(std::initializer_list<double> coords);
1226  GPolygon(std::initializer_list<GPoint> points);
1227 
1232  virtual void addEdge(double dx, double dy);
1233 
1238  virtual void addEdge(const GPoint& pt);
1239 
1244  virtual void addEdges(std::initializer_list<double> coords);
1245 
1250  virtual void addEdges(std::initializer_list<GPoint> points);
1251 
1258  virtual void addPolarEdge(double r, double theta);
1259 
1264  virtual void addVertex(double x, double y);
1265 
1270  virtual void addVertex(const GPoint& pt);
1271 
1277  virtual void addVertexes(std::initializer_list<double> coords);
1278 
1284  virtual void addVertexes(std::initializer_list<GPoint> points);
1285 
1289  virtual void clear();
1290 
1291  /* @inherit */
1292  bool contains(double x, double y) const override;
1293 
1298  void draw(QPainter* painter) override;
1299 
1300  /* @inherit */
1301  GRectangle getBounds() const override;
1302 
1303  /* @inherit */
1304  double getHeight() const override;
1305 
1306  /* @inherit */
1307  string getType() const override;
1308 
1313  virtual GPoint getVertex(int i) const;
1314 
1318  virtual int getVertexCount() const;
1319 
1323  virtual std::vector<GPoint> getVertices() const;
1324 
1325  /* @inherit */
1326  double getWidth() const override;
1327 
1333  virtual void setVertex(int i, GPoint point);
1334 
1335  /* @inherit */
1336  string toStringExtra() const override;
1337 
1338 private:
1339  /* Instance variables */
1340  QVector<QPointF> _vertices; // the vertices of the polygon
1341  double _cx; // the most recent x coordinate
1342  double _cy; // the most recent y coordinate
1343 };
1344 
1349 class GRect : public GObject {
1350 public:
1356  GRect(double x = 0, double y = 0, double width = 0, double height = 0);
1357 
1362  void draw(QPainter* painter) override;
1363 
1364  /* @inherit */
1365  string getType() const override;
1366 };
1367 
1372 class GRoundRect : public GRect {
1373 public:
1378  static const double DEFAULT_CORNER;
1379 
1385  GRoundRect(double width = 0, double height = 0, double corner = DEFAULT_CORNER);
1386 
1392  GRoundRect(double x, double y, double width, double height, double corner = DEFAULT_CORNER);
1393 
1397  bool contains(double x, double y) const override;
1398 
1403  void draw(QPainter* painter) override;
1404 
1409  virtual double getCorner() const;
1410 
1411  /* @inherit */
1412  string getType() const override;
1413 
1418  virtual void setCorner(double corner);
1419 
1420  /* @inherit */
1421  string toStringExtra() const override;
1422 
1423 protected:
1424  double _corner;
1425 };
1426 
1446 class GText : public GObject {
1447 public:
1451  static const string DEFAULT_FONT;
1452 
1459  GText(const string& str = "", double x = 0, double y = 0);
1460 
1465  void draw(QPainter* painter) override;
1466 
1467  /* @inherit */
1468  GRectangle getBounds() const override;
1469 
1473  virtual string getFont() const;
1474 
1479  virtual double getFontAscent() const;
1480 
1485  virtual double getFontDescent() const;
1486 
1491  virtual string getLabel() const;
1492 
1497  virtual string getText() const;
1498 
1499  /* @inherit */
1500  string getType() const override;
1501 
1502  /* @inherit */
1503  void setFont(const QFont& font) override;
1504 
1505  /* @inherit */
1506  void setFont(const string& font) override;
1507 
1513  virtual void setLabel(const string& str);
1514 
1520  virtual void setText(const string& str);
1521 
1522  /* @inherit */
1523  string toStringExtra() const override;
1524 
1525 private:
1526  /* Instance variables */
1527  string _text; // the string displayed by the label
1528  QFont _qfont;
1529 
1530  // update width and height when font or text changes
1531  void updateSize();
1532 };
1533 
1537 std::ostream& operator <<(std::ostream& out, const GObject& obj);
1538 
1539 } // namespace sgl
1540 
1541 #endif // _gobjects_h
virtual string getText() const
Returns the string displayed by this object.
Definition: gobjects.cpp:1612
virtual GDimension getSize() const
Returns the size of the object as a GDimension.
Definition: gobjects.cpp:180
This struct contains real-valued x, y, width, and height fields.
Definition: gtypes.h:293
LineStyle _lineStyle
Definition: gobjects.h:607
GCompound * _parent
Definition: gobjects.h:616
virtual void setX(double x)
Sets the x location of the left side of this object.
Definition: gobjects.cpp:502
virtual string getLabel() const
Returns the string displayed by this object.
Definition: gobjects.cpp:1608
bool _visible
Definition: gobjects.h:614
void setFont(const QFont &font) override
Changes the font used to display the object as specified by the given Qt font.
Definition: gobjects.cpp:1620
virtual void setFillColor(int r, int g, int b)
Sets the color used to display the filled region of this object, if any.
Definition: gobjects.cpp:398
virtual void setFilled(bool flag)
Sets the fill status for the object, where false is outlined and true is filled.
Definition: gobjects.cpp:424
virtual void setCenterLocation(double x, double y)
Sets the location of the center of this object.
Definition: gobjects.cpp:368
virtual string getFillColor() const
Returns the color used to display the filled region of this object.
Definition: gobjects.cpp:148
virtual void conditionalRepaint()
Repaints the compound only if it needs to be repainted (if any of its contents have changed)...
Definition: gobjects.cpp:747
virtual void setCenterY(double y)
Sets the y-coordinate of the center of this object.
Definition: gobjects.cpp:364
virtual ~GImage()
Frees memory allocated internally by the image.
Definition: gobjects.cpp:1027
virtual void setBottomY(double y)
Sets the location of the bottom y-coordinate of this object.
Definition: gobjects.cpp:332
virtual bool isAutoRepaint() const
Returns whether the compound automatically repaints itself when its contents change.
Definition: gobjects.cpp:846
A GRoundRect represents a graphical object whose appearance consists of a rectangular box with rounde...
Definition: gobjects.h:1372
double _corner
Definition: gobjects.h:1424
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1566
virtual GObject * getElement(int index) const
Returns a pointer to the graphical object at the specified index, numbering from back to front in the...
Definition: gobjects.cpp:821
virtual void setWidth(double width)
Changes the width of this object to the specified width without changing its height.
Definition: gobjects.cpp:498
virtual double getEndX() const
Returns the x-coordinate of the point at which the line ends.
Definition: gobjects.cpp:1196
virtual void setCorner(double corner)
Sets the diameter of the arc forming the corner of this rounded rectangle.
Definition: gobjects.cpp:1560
virtual void addEdges(std::initializer_list< double > coords)
Adds multiple edges to the polygon whose components are given by the displacements dx and dy from the...
Definition: gobjects.cpp:1317
virtual void setOpacity(double opacity)
Sets how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1...
Definition: gobjects.cpp:474
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1114
virtual ~GObject()
Frees the storage for the object.
Definition: gobjects.cpp:98
virtual void setRightX(double x)
Sets the location of the rightmost x-coordinate of this object.
Definition: gobjects.cpp:336
virtual void addVertex(double x, double y)
Adds a vertex at (x, y) relative to the polygon origin.
Definition: gobjects.cpp:1342
bool _fillFlag
Definition: gobjects.h:613
virtual void setCenterX(double x)
Sets the x-coordinate of the center of this object.
Definition: gobjects.cpp:360
This graphical object subclass represents an image from a file.
Definition: gobjects.h:957
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1439
virtual void setVisible(bool flag)
Sets whether this object is visible.
Definition: gobjects.cpp:493
GPolygon()
Constructs a new empty polygon at the origin.
Definition: gobjects.cpp:1297
virtual double getEndY() const
Returns the y-coordinate of the point at which the line ends.
Definition: gobjects.cpp:1200
virtual void clear()
Removes all graphical objects from the compound.
Definition: gobjects.cpp:743
virtual void setStartPoint(double x0, double y0)
Sets the initial point in the line to (x0,&#160;y0), leaving the end point unchanged.
Definition: gobjects.cpp:1248
GLine(double x0=0, double y0=0, double x1=0, double y1=0, LineStyle lineStyle=LINE_SOLID)
Constructs a line segment from its endpoints.
Definition: gobjects.cpp:1119
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1106
virtual void setVertex(int i, GPoint point)
Sets the vertex at the given 0-based index in this polygon to the given coordinates.
Definition: gobjects.cpp:1463
virtual bool isFilled() const
Returns true if the object is filled with color.
Definition: gobjects.cpp:251
GRectangle getBounds() const override
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers ev...
Definition: gobjects.cpp:1586
std::ostream & operator<<(std::ostream &out, const GEvent &event)
Writes the given event to the given output stream.
Definition: gevent.cpp:494
double getWidth() const override
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:1224
LineStyle
Styles that can be used for the outline around various shapes.
Definition: gobjects.h:72
virtual void clear()
Removes all vertexes from the polygon.
Definition: gobjects.cpp:1374
virtual double getFontAscent() const
Returns the maximum distance strings in this font extend above the baseline.
Definition: gobjects.cpp:1598
virtual double getCenterX() const
Returns the x-coordinate of the center of the object.
Definition: gobjects.cpp:136
virtual double getStartY() const
Returns the y-coordinate of the point at which the line starts.
Definition: gobjects.cpp:1216
virtual void rotate(double theta)
Transforms the object by rotating it theta degrees counterclockwise around its origin.
Definition: gobjects.cpp:284
GRectangle getBounds() const override
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers ev...
Definition: gobjects.cpp:801
This graphical object subclass represents an elliptical arc.
Definition: gobjects.h:676
virtual double getCorner() const
Returns the diameter of the arc forming the corner of this rounded rectangle.
Definition: gobjects.cpp:1552
virtual string getFileName() const
Returns the file name used to load the image, as was passed to the constructor.
Definition: gobjects.cpp:1093
virtual int getVertexCount() const
Returns the number of vertexes in this polygon.
Definition: gobjects.cpp:1447
virtual bool isTransformed() const
Returns true if this object has been transformed by calling methods such as rotate() or scale() on it...
Definition: gobjects.cpp:255
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1491
string _color
Definition: gobjects.h:608
virtual void setFont(const QFont &font)
Changes the font used to display the object as specified by the given Qt font.
Definition: gobjects.cpp:429
static const double DEFAULT_CORNER
The default diameter of corners on rounded rectangles if none is supplied to the constructor.
Definition: gobjects.h:1378
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:66
static void setAntiAliasing(bool value)
Globally turns on/off the anti-aliasing feature that smooths out the edges of onscreen shapes...
Definition: gobjects.cpp:328
A GRect is a graphical object whose appearance consists of a rectangular box.
Definition: gobjects.h:1349
virtual GPoint getStartPoint() const
Returns the point at which the arc starts.
Definition: gobjects.cpp:671
double _dy
Definition: gobjects.h:1179
virtual string getColor() const
Returns the color used to display this object.
Definition: gobjects.cpp:144
virtual void removeAll()
Removes all graphical objects from the compound.
Definition: gobjects.cpp:866
QBrush _brush
Definition: gobjects.h:618
string _font
Definition: gobjects.h:612
Definition: console.h:45
This graphical object subclass represents a line segment.
Definition: gobjects.h:1058
virtual double getX() const
Returns the leftmost x-coordinate of the object.
Definition: gobjects.cpp:189
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
virtual GCompound * getParent() const
Returns a pointer to the GCompound that contains this object.
Definition: gobjects.cpp:172
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:679
virtual void setSize(double width, double height)
Changes the size of this object to the specified width and height.
Definition: gobjects.cpp:480
Definition: gobjects.h:73
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1134
A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors...
Definition: gcanvas.h:75
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:545
virtual void move(double dx, double dy)
Moves the object on the screen using the displacements dx and dy.
Definition: gobjects.cpp:263
virtual std::vector< GPoint > getVertices() const
Returns a vector of the points in the polygon.
Definition: gobjects.cpp:1451
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:765
double _height
Definition: gobjects.h:604
virtual GPoint getCenterLocation() const
Returns the x/y-coordinates of the center of the object.
Definition: gobjects.cpp:132
virtual double getSweepAngle() const
Returns the sweep angle for this arc in degrees.
Definition: gobjects.cpp:675
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1514
virtual GRectangle getFrameRectangle() const
Returns the boundaries of the rectangle used to frame the arc.
Definition: gobjects.cpp:663
Definition: gobjects.h:75
virtual void setLineStyle(LineStyle lineStyle)
Sets the object&#39;s style such as solid (GObject::LINE_SOLID) or dashed (GObject::LINE_DASH).
Definition: gobjects.cpp:454
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1616
virtual void setBounds(double x, double y, double width, double height)
Changes the bounds of this object to the specified values.
Definition: gobjects.cpp:348
string toString() const override
Returns a printable representation of the object.
Definition: gobjects.cpp:988
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1556
virtual void setY(double y)
Sets the y location of the top of this object.
Definition: gobjects.cpp:506
virtual void setEndPoint(double x1, double y1)
Sets the end point in the line to (x1,&#160;y1), leaving the start point unchanged.
Definition: gobjects.cpp:1228
virtual GRectangle getBounds() const
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers ev...
Definition: gobjects.cpp:123
GCompound()
Creates a compound with no internal components.
Definition: gobjects.cpp:708
virtual void repaint()
Instructs the object to redraw itself on screen.
Definition: gobjects.cpp:267
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1256
double getHeight() const override
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:1435
virtual void setLabel(string str)
Changes the string stored within the text label, so that a new text string appears on the display...
Definition: gobjects.cpp:1630
GRoundRect(double width=0, double height=0, double corner=DEFAULT_CORNER)
Constructs a new rectangle with the specified width and height, located at (0, 0).
Definition: gobjects.cpp:1502
virtual void setForeground(int r, int g, int b)
Sets the color used to display this object.
Definition: gobjects.cpp:438
double getWidth() const override
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:1459
This graphical object subclass represents a text string.
Definition: gobjects.h:1446
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1220
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1379
friend class GDiffImage
Definition: gobjects.h:1052
virtual bool isVisible() const
Returns true if this object is visible on screen.
Definition: gobjects.cpp:259
virtual double getWidth() const
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:185
double getHeight() const override
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:1204
GRect(double x=0, double y=0, double width=0, double height=0)
Constructs a rectangle with the specified width and height.
Definition: gobjects.cpp:1476
This struct contains real-valued width and height fields.
Definition: gtypes.h:43
QPen _pen
Definition: gobjects.h:617
void sendToBack()
Moves this object to the back of the display in the z dimension.
Definition: gobjects.cpp:314
virtual GPoint getVertex(int i) const
Returns the vertex at the given 0-based index in this polygon.
Definition: gobjects.cpp:1443
virtual void setBottomRightLocation(double x, double y)
Sets the location of the bottom/right of this object.
Definition: gobjects.cpp:340
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:102
This graphical object subclass consists of a collection of other graphical objects.
Definition: gobjects.h:769
double _lineWidth
Definition: gobjects.h:605
GArc(double width=0, double height=0, double start=0, double sweep=0)
Creates a new GArc object consisting of an elliptical arc.
Definition: gobjects.cpp:550
double _opacity
Definition: gobjects.h:606
int _colorInt
Definition: gobjects.h:609
virtual void add(GObject *gobj)
Adds a new graphical object to the compound, if that object was not already present in the compound...
Definition: gobjects.cpp:713
virtual void setFrameRectangle(const GRectangle &rect)
Changes the boundaries of the rectangle used to frame the arc.
Definition: gobjects.cpp:687
virtual double getLineWidth() const
Returns the width of the line used to draw this object.
Definition: gobjects.cpp:160
virtual GPoint getLocation() const
Returns the location of the top-left corner of object.
Definition: gobjects.cpp:164
static bool isAntiAliasing()
Returns whether we should globally anti-alias graphical objects.
Definition: gobjects.cpp:247
GRectangle getBounds() const override
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers ev...
Definition: gobjects.cpp:627
void sendToFront()
Moves this object to the front of the display in the z dimension.
Definition: gobjects.cpp:321
virtual GObject * getElementAt(double x, double y) const
Returns a pointer to the first graphical object that contains the given (x, y) point, or a null pointer if no object in this compound touches it.
Definition: gobjects.cpp:825
virtual string getType() const =0
Returns the type of the object as a string, such as "GOval" or "GRect".
virtual void setStartAngle(double start)
Sets the starting angle for this arc in degrees.
Definition: gobjects.cpp:691
GOval(double x=0, double y=0, double width=0, double height=0)
Constructs a new oval inscribed in the specified rectangle.
Definition: gobjects.cpp:1263
virtual void repaintRegion(int x, int y, int width, int height)
Instructs the compound to redraw the given rectangular region within itself, including any graphical ...
Definition: gobjects.cpp:905
virtual double getBottomY() const
Returns the y-coordinate of the bottom of the object.
Definition: gobjects.cpp:119
Definition: gobjects.h:77
virtual double getOpacity() const
Returns how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1...
Definition: gobjects.cpp:168
virtual GPoint getEndPoint() const
Returns the point at which the line ends.
Definition: gobjects.cpp:1192
virtual void setHeight(double height)
Changes the height of this object to the specified height without changing its width.
Definition: gobjects.cpp:450
QImage * getQImage() const
Returns the inner Qt QImage object being wrapped.
Definition: gobjects.cpp:1102
virtual void conditionalRepaintRegion(int x, int y, int width, int height)
Repaints the given rectangular region of the compound only if it needs to be repainted (if any of its...
Definition: gobjects.cpp:753
virtual int getElementCount() const
Returns the number of graphical objects stored in the compound.
Definition: gobjects.cpp:834
virtual void setPixel(int x, int y, int rgb)
Sets the pixel at the given x/y location to the given color, represented as an RGB integer...
Definition: gobjects.cpp:1110
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:838
virtual void setText(string str)
Changes the string stored within the text label, so that a new text string appears on the display...
Definition: gobjects.cpp:1636
int _fillColorInt
Definition: gobjects.h:611
virtual GPoint getEndPoint() const
Returns the point at which the arc ends.
Definition: gobjects.cpp:659
virtual double getY() const
Returns the topmost y-coordinate of the object.
Definition: gobjects.cpp:193
virtual GPoint getBottomRightLocation() const
Returns the x/y coordinates of the bottom/right corner of the object.
Definition: gobjects.cpp:115
virtual int getPixel(int x, int y) const
Returns the color of the pixel at the given x/y location as an RGB integer.
Definition: gobjects.cpp:1097
virtual void resetTransform()
Undoes any previous scale/rotate transformations on this object.
Definition: gobjects.cpp:278
static const string DEFAULT_FONT
The default font used in text labels if none is provided.
Definition: gobjects.h:1451
void sendBackward()
Moves this object one step toward the back in the z dimension.
Definition: gobjects.cpp:300
Definition: gobjects.h:78
Definition: gobjects.h:76
bool _transformed
Definition: gobjects.h:615
virtual double getStartAngle() const
Returns the starting angle for this arc in degrees.
Definition: gobjects.cpp:667
virtual bool isEmpty() const
Returns true if the compound does not contain any graphical objects.
Definition: gobjects.cpp:850
virtual void addVertexes(std::initializer_list< double > coords)
Adds multiple edges to the polygon whose components are given by the coordinates dx and dy relative t...
Definition: gobjects.cpp:1353
GRectangle getBounds() const override
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers ev...
Definition: gobjects.cpp:1182
This struct contains real-valued x and y fields.
Definition: gtypes.h:202
virtual void setAutoRepaint(bool autoRepaint)
Sets whether the compound automatically repaints itself when its contents change. ...
Definition: gobjects.cpp:980
This graphical object subclass represents an oval inscribed in a rectangular box. ...
Definition: gobjects.h:1186
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:564
virtual void setColor(int r, int g, int b)
Sets the color used to display this object.
Definition: gobjects.cpp:376
virtual double getHeight() const
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:152
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1640
GRectangle getBounds() const override
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers ev...
Definition: gobjects.cpp:1414
double _width
Definition: gobjects.h:603
string _fillColor
Definition: gobjects.h:610
virtual void addPolarEdge(double r, double theta)
Adds an edge to the polygon specified in polar coordinates.
Definition: gobjects.cpp:1338
virtual double getRightX() const
Returns the x-coordinate of the right side of the object.
Definition: gobjects.cpp:176
virtual void setPoints(double x0, double y0, double x1, double y1)
Sets this line&#39;s two end points to (x0, y0) and (x1, y1).
Definition: gobjects.cpp:1236
Definition: gobjects.h:74
double _x
Definition: gobjects.h:601
virtual double getCenterY() const
Returns the y-coordinate of the center of the object.
Definition: gobjects.cpp:140
void sendForward()
Moves this object one step toward the front in the z dimension.
Definition: gobjects.cpp:307
double _dx
Definition: gobjects.h:1178
This graphical object subclass represents a polygon bounded by line segments.
Definition: gobjects.h:1215
virtual double getStartX() const
Returns the x-coordinate of the point at which the line starts.
Definition: gobjects.cpp:1212
GImage(string filename="", double x=0, double y=0)
Constructs a new image by loading the image from the specified file.
Definition: gobjects.cpp:993
virtual string getFont() const
Returns the current font for the label.
Definition: gobjects.cpp:1594
void repaint() override
Instructs the compound to redraw all of its graphical objects.
Definition: gobjects.cpp:890
virtual LineStyle getLineStyle() const
Returns the object&#39;s style such as solid or dashed.
Definition: gobjects.cpp:156
virtual void setLineWidth(double lineWidth)
Sets the width of the line used to draw this object.
Definition: gobjects.cpp:459
virtual void addEdge(double dx, double dy)
Adds an edge to the polygon whose components are given by the displacements dx and dy from the last v...
Definition: gobjects.cpp:1309
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1469
virtual double getFontDescent() const
Returns the maximum distance strings in this font descend below the baseline.
Definition: gobjects.cpp:1603
virtual void setSweepAngle(double start)
Sets the sweep angle for this arc in degrees.
Definition: gobjects.cpp:696
double _y
Definition: gobjects.h:602
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:701
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1292
QTransform _transform
Definition: gobjects.h:619
GText(string str="", double x=0, double y=0)
Creates a GText object containing the specified string.
Definition: gobjects.cpp:1571
virtual GPoint getStartPoint() const
Returns the point at which the line starts.
Definition: gobjects.cpp:1208
virtual void setLocation(double x, double y)
Sets the location of the top-left corner of this object to the specified coordinates.
Definition: gobjects.cpp:464
virtual string toString() const
Returns a printable representation of the object.
Definition: gobjects.cpp:510
virtual void scale(double sf)
Scales the object by the specified scale factor.
Definition: gobjects.cpp:290
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1268