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/03
10  * - removed dependency on custom collections
11  * @version 2019/05/05
12  * - added predictable GLine point ordering
13  * @version 2019/04/23
14  * - bug fix for loading GImage from file on Windows related to istream change
15  * @version 2019/03/07
16  * - added support for loading a GImage directly from istream (htiek)
17  * @version 2018/09/14
18  * - added opacity support
19  * - added GCanvas-to-GImage conversion support
20  * @version 2018/09/08
21  * - added doc comments for new documentation generation
22  * @version 2018/08/23
23  * - renamed to gobjects.h to replace Java version
24  * @version 2018/06/30
25  * - initial version
26  */
27 
28 
29 #ifndef _gobjects_h
30 #define _gobjects_h
31 
32 #include <initializer_list>
33 #include <iostream>
34 #include <vector>
35 #include <QFont>
36 #include <QImage>
37 #include <QPainter>
38 #include <QPen>
39 #include <QWidget>
40 
41 #include "gtypes.h"
42 
43 class GCanvas;
44 class GCompound;
45 class GDiffImage;
46 
62 class GObject {
63 public:
68  enum LineStyle {
75  };
76 
80  virtual ~GObject();
81 
85  virtual bool contains(double x, double y) const;
86 
90  virtual bool contains(const GPoint& pt) const;
91 
97  virtual void draw(QPainter* painter) = 0;
98 
102  virtual GPoint getBottomRightLocation() const;
103 
108  virtual double getBottomY() const;
109 
120  virtual GRectangle getBounds() const;
121 
126  virtual GPoint getCenterLocation() const;
127 
132  virtual double getCenterX() const;
133 
138  virtual double getCenterY() const;
139 
147  virtual string getColor() const;
148 
153  virtual string getFillColor() const;
154 
159  virtual double getHeight() const;
160 
164  virtual LineStyle getLineStyle() const;
165 
170  virtual double getLineWidth() const;
171 
175  virtual GPoint getLocation() const;
176 
181  virtual double getOpacity() const;
182 
192  virtual GCompound* getParent() const;
193 
198  virtual double getRightX() const;
199 
203  virtual GDimension getSize() const;
204 
210  virtual string getType() const = 0;
211 
216  virtual double getWidth() const;
217 
221  virtual double getX() const;
222 
226  virtual double getY() const;
227 
232  static bool isAntiAliasing();
233 
237  virtual bool isFilled() const;
238 
245  virtual bool isTransformed() const;
246 
250  virtual bool isVisible() const;
251 
256  virtual void move(double dx, double dy);
257 
261  virtual void repaint();
262 
266  virtual void resetTransform();
267 
275  virtual void rotate(double theta);
276 
285  virtual void scale(double sf);
286 
296  virtual void scale(double sx, double sy);
297 
302  void sendBackward();
303 
308  void sendForward();
309 
316  void sendToBack();
317 
324  void sendToFront();
325 
331  static void setAntiAliasing(bool value);
332 
336  virtual void setBounds(double x, double y, double width, double height);
337 
341  virtual void setBounds(const GRectangle& size);
342 
346  virtual void setBottomY(double y);
347 
351  virtual void setRightX(double x);
352 
356  virtual void setBottomRightLocation(double x, double y);
357 
361  virtual void setBottomRightLocation(const GPoint& pt);
362 
366  virtual void setCenterX(double x);
367 
371  virtual void setCenterY(double y);
372 
376  virtual void setCenterLocation(double x, double y);
377 
381  virtual void setCenterLocation(const GPoint& pt);
382 
393  virtual void setColor(int r, int g, int b);
394 
403  virtual void setColor(int rgb);
404 
413  virtual void setColor(const string& color);
414 
425  virtual void setFillColor(int r, int g, int b);
426 
434  virtual void setFillColor(int rgb);
435 
444  virtual void setFillColor(const string& color);
445 
450  virtual void setFilled(bool flag);
451 
457  virtual void setFont(const QFont& font);
458 
472  virtual void setFont(const string& font);
473 
484  virtual void setForeground(int r, int g, int b);
485 
494  virtual void setForeground(int rgb);
495 
504  virtual void setForeground(const string& color);
505 
510  virtual void setHeight(double height);
511 
516  virtual void setLineStyle(LineStyle lineStyle);
517 
522  virtual void setLineWidth(double lineWidth);
523 
528  virtual void setLocation(double x, double y);
529 
534  virtual void setLocation(const GPoint& pt);
535 
541  virtual void setOpacity(double opacity);
542 
546  virtual void setSize(double width, double height);
547 
551  virtual void setSize(const GDimension& size);
552 
557  virtual void setVisible(bool flag);
558 
563  virtual void setWidth(double width);
564 
568  virtual void setX(double x);
569 
573  virtual void setY(double y);
574 
578  virtual string toString() const;
579 
580 // Private section
581 private:
582  // forbid assignment between objects
583  const GObject& operator =(const GObject&) {
584  return *this;
585  }
586 
587  // forbid copy construction
588  GObject(const GObject&) {
589  // empty
590  }
591 
592  // whether to anti-alias graphical objects; default true
593  static bool _sAntiAliasing;
594 
595  /* Instance variables */
596 protected:
597  double _x; // the x coordinate of the origin
598  double _y; // the y coordinate of the origin
599  double _width; // the width of the bounding rectangle
600  double _height; // the height of the bounding rectangle
601  double _lineWidth; // the width of the line in pixels
602  double _opacity; // 0.0 (transparent) - 1.0 (opaque, default)
603  LineStyle _lineStyle; // line style such as solid or dashed
604  string _color; // the color of the object
606  string _fillColor; // color used to fill the object
608  string _font; // the font string of the label
609  bool _fillFlag; // indicates whether the object is filled
610  bool _visible; // indicates if object is visible
611  bool _transformed; // indicates if object is transformed
612  GCompound* _parent; // pointer to the parent
613  QPen _pen; // for outlines
614  QBrush _brush; // for filling
615  QTransform _transform; // for transformations (rotate, scale)
616 
617 protected:
622  GObject(double x = 0, double y = 0, double width = 0, double height = 0);
623 
629  virtual void initializeBrushAndPen(QPainter* painter = nullptr);
630 
635  static Qt::PenStyle toQtPenStyle(LineStyle lineStyle);
636 
641  virtual string toStringExtra() const;
642 
643  friend class GArc;
644  friend class GCompound;
645  friend class GImage;
646  friend class GInteractor;
647  friend class GLine;
648  friend class GOval;
649  friend class GPolygon;
650  friend class GRect;
651  friend class GRoundRect;
652  friend class GText;
653 };
654 
672 class GArc : public GObject {
673 public:
678  GArc(double width = 0, double height = 0, double start = 0, double sweep = 0);
679 
685  GArc(double x, double y, double width, double height, double start, double sweep);
686 
687  /* @inherit */
688  bool contains(double x, double y) const override;
689 
694  void draw(QPainter* painter) override;
695 
696  /* @inherit */
697  GRectangle getBounds() const override;
698 
702  virtual GPoint getEndPoint() const;
703 
707  virtual GRectangle getFrameRectangle() const;
708 
712  virtual double getStartAngle() const;
713 
717  virtual GPoint getStartPoint() const;
718 
722  virtual double getSweepAngle() const;
723 
724  /* @inherit */
725  string getType() const override;
726 
730  virtual void setFrameRectangle(const GRectangle& rect);
731 
735  virtual void setFrameRectangle(double x, double y, double width, double height);
736 
740  virtual void setStartAngle(double start);
741 
745  virtual void setSweepAngle(double start);
746 
747  /* @inherit */
748  string toStringExtra() const override;
749 
750 private:
751  virtual bool containsAngle(double theta) const;
752  virtual GPoint getArcPoint(double theta) const;
753 
754  /* Instance variables */
755  double _start; /* Starting angle of the arc */
756  double _sweep; /* How many degrees the arc runs */
757 };
758 
765 class GCompound : public GObject {
766 public:
770  GCompound();
771 
778  virtual void add(GObject* gobj);
779 
787  virtual void add(GObject* gobj, double x, double y);
788 
792  virtual void add(GObject& gobj);
793 
800  virtual void add(GObject& gobj, double x, double y);
801 
806  virtual void clear();
807 
812  virtual void conditionalRepaint();
813 
818  virtual void conditionalRepaintRegion(int x, int y, int width, int height);
819 
824  virtual void conditionalRepaintRegion(const GRectangle& bounds);
825 
826  /* @inherit */
827  bool contains(double x, double y) const override;
828 
833  void draw(QPainter* painter) override;
834 
835  /* @inherit */
836  GRectangle getBounds() const override;
837 
843  virtual GObject* getElement(int index) const;
844 
849  virtual GObject* getElementAt(double x, double y) const;
850 
854  virtual int getElementCount() const;
855 
856  /* @inherit */
857  string getType() const override;
858 
867  virtual QWidget* getWidget() const;
868 
873  virtual bool isAutoRepaint() const;
874 
878  virtual bool isEmpty() const;
879 
884  virtual void remove(GObject* gobj);
885 
889  virtual void remove(GObject& gobj);
890 
895  virtual void removeAll();
896 
900  void repaint() override;
901 
906  virtual void repaintRegion(int x, int y, int width, int height);
907 
912  virtual void repaintRegion(const GRectangle& bounds);
913 
918  virtual void setAutoRepaint(bool autoRepaint);
919 
928  virtual void setWidget(QWidget* widget);
929 
930  /* @inherit */
931  string toString() const override;
932 
933 private:
934  // methods to move an object in the z-ordering
935  void sendBackward(GObject* gobj);
936  void sendForward(GObject* gobj);
937  void sendToBack(GObject* gobj);
938  void sendToFront(GObject* gobj);
939  virtual int findGObject(GObject* gobj) const;
940  virtual void removeAt(int index);
941 
942  // instance variables
943  std::vector<GObject*> _contents;
944  QWidget* _widget = nullptr; // widget containing this compound
945  bool _autoRepaint; // automatically repaint on any change; default true
946 
947  friend class GObject;
948 };
949 
953 class GImage : public GObject {
954 public:
963  GImage(const string& filename = "", double x = 0, double y = 0);
964 
973  GImage(std::istream& source, double x = 0, double y = 0);
974 
979  GImage(double width, double height);
980 
984  virtual ~GImage();
985 
986 
987 
992  void draw(QPainter* painter) override;
993 
998  virtual string getFileName() const;
999 
1004  virtual int getPixel(int x, int y) const;
1005 
1006  /* @inherit */
1007  string getType() const override;
1008 
1014  virtual void setPixel(int x, int y, int rgb);
1015 
1016  /* @inherit */
1017  string toStringExtra() const override;
1018 
1019 protected:
1024  GImage(QImage* qimage);
1025 
1029  QImage* getQImage() const;
1030 
1031 private:
1036  bool load(const string& filename);
1037 
1042  bool loadFromStream(std::istream& input);
1043 
1044  string _filename;
1045  QImage* _qimage;
1046 
1047  friend class GCanvas;
1048  friend class GDiffImage;
1049 };
1050 
1054 class GLine : public GObject {
1055 public:
1062  GLine(double x0 = 0, double y0 = 0, double x1 = 0, double y1 = 0, LineStyle lineStyle = LINE_SOLID);
1063 
1069  GLine(const GPoint& p0, const GPoint& p1);
1070 
1071  /* @inherit */
1072  bool contains(double x, double y) const override;
1073 
1078  void draw(QPainter* painter) override;
1079 
1080  /* @inherit */
1081  GRectangle getBounds() const override;
1082 
1086  virtual GPoint getEndPoint() const;
1087 
1091  virtual double getEndX() const;
1092 
1096  virtual double getEndY() const;
1097 
1098  /* @inherit */
1099  double getHeight() const override;
1100 
1105  virtual GPoint getStartPoint() const;
1106 
1111  virtual double getStartX() const;
1112 
1117  virtual double getStartY() const;
1118 
1119  /* @inherit */
1120  string getType() const override;
1121 
1122  /* @inherit */
1123  double getWidth() const override;
1124 
1130  virtual void setEndPoint(double x1, double y1);
1131 
1137  virtual void setEndPoint(const GPoint& p);
1138 
1145  virtual void setPoints(double x0, double y0, double x1, double y1);
1146 
1153  virtual void setPoints(const GPoint& p0, const GPoint& p1);
1154 
1160  virtual void setStartPoint(double x0, double y0);
1161 
1167  virtual void setStartPoint(const GPoint& p);
1168 
1169  /* @inherit */
1170  string toStringExtra() const override;
1171 
1172 protected:
1173  /* Instance variables */
1174  double _dx; // the x displacement of the line
1175  double _dy; // the y displacement of the line
1176 };
1177 
1182 class GOval : public GObject {
1183 public:
1189  GOval(double x = 0, double y = 0, double width = 0, double height = 0);
1190 
1191  /* @inherit */
1192  bool contains(double x, double y) const override;
1193 
1198  void draw(QPainter* painter) override;
1199 
1200  /* @inherit */
1201  string getType() const override;
1202 };
1203 
1211 class GPolygon : public GObject {
1212 public:
1216  GPolygon();
1217 
1221  GPolygon(std::initializer_list<double> coords);
1222  GPolygon(std::initializer_list<GPoint> points);
1223 
1228  virtual void addEdge(double dx, double dy);
1229 
1234  virtual void addEdge(const GPoint& pt);
1235 
1240  virtual void addEdges(std::initializer_list<double> coords);
1241 
1246  virtual void addEdges(std::initializer_list<GPoint> points);
1247 
1254  virtual void addPolarEdge(double r, double theta);
1255 
1260  virtual void addVertex(double x, double y);
1261 
1266  virtual void addVertex(const GPoint& pt);
1267 
1273  virtual void addVertexes(std::initializer_list<double> coords);
1274 
1280  virtual void addVertexes(std::initializer_list<GPoint> points);
1281 
1285  virtual void clear();
1286 
1287  /* @inherit */
1288  bool contains(double x, double y) const override;
1289 
1294  void draw(QPainter* painter) override;
1295 
1296  /* @inherit */
1297  GRectangle getBounds() const override;
1298 
1299  /* @inherit */
1300  double getHeight() const override;
1301 
1302  /* @inherit */
1303  string getType() const override;
1304 
1309  virtual GPoint getVertex(int i) const;
1310 
1314  virtual int getVertexCount() const;
1315 
1319  virtual std::vector<GPoint> getVertices() const;
1320 
1321  /* @inherit */
1322  double getWidth() const override;
1323 
1329  virtual void setVertex(int i, GPoint point);
1330 
1331  /* @inherit */
1332  string toStringExtra() const override;
1333 
1334 private:
1335  /* Instance variables */
1336  QVector<QPointF> _vertices; // the vertices of the polygon
1337  double _cx; // the most recent x coordinate
1338  double _cy; // the most recent y coordinate
1339 };
1340 
1345 class GRect : public GObject {
1346 public:
1352  GRect(double x = 0, double y = 0, double width = 0, double height = 0);
1353 
1358  void draw(QPainter* painter) override;
1359 
1360  /* @inherit */
1361  string getType() const override;
1362 };
1363 
1368 class GRoundRect : public GRect {
1369 public:
1374  static const double DEFAULT_CORNER;
1375 
1381  GRoundRect(double width = 0, double height = 0, double corner = DEFAULT_CORNER);
1382 
1388  GRoundRect(double x, double y, double width, double height, double corner = DEFAULT_CORNER);
1389 
1393  bool contains(double x, double y) const override;
1394 
1399  void draw(QPainter* painter) override;
1400 
1405  virtual double getCorner() const;
1406 
1407  /* @inherit */
1408  string getType() const override;
1409 
1414  virtual void setCorner(double corner);
1415 
1416  /* @inherit */
1417  string toStringExtra() const override;
1418 
1419 protected:
1420  double _corner;
1421 };
1422 
1442 class GText : public GObject {
1443 public:
1447  static const string DEFAULT_FONT;
1448 
1455  GText(const string& str = "", double x = 0, double y = 0);
1456 
1461  void draw(QPainter* painter) override;
1462 
1463  /* @inherit */
1464  GRectangle getBounds() const override;
1465 
1469  virtual string getFont() const;
1470 
1475  virtual double getFontAscent() const;
1476 
1481  virtual double getFontDescent() const;
1482 
1487  virtual string getLabel() const;
1488 
1493  virtual string getText() const;
1494 
1495  /* @inherit */
1496  string getType() const override;
1497 
1498  /* @inherit */
1499  void setFont(const QFont& font) override;
1500 
1501  /* @inherit */
1502  void setFont(const string& font) override;
1503 
1509  virtual void setLabel(const string& str);
1510 
1516  virtual void setText(const string& str);
1517 
1518  /* @inherit */
1519  string toStringExtra() const override;
1520 
1521 private:
1522  /* Instance variables */
1523  string _text; // the string displayed by the label
1524  QFont _qfont;
1525 
1526  // update width and height when font or text changes
1527  void updateSize();
1528 };
1529 
1533 std::ostream& operator <<(std::ostream& out, const GObject& obj);
1534 
1535 #endif // _gobjects_h
virtual double getSweepAngle() const
Returns the sweep angle for this arc in degrees.
Definition: gobjects.cpp:671
virtual LineStyle getLineStyle() const
Returns the object&#39;s style such as solid or dashed.
Definition: gobjects.cpp:152
virtual void setBounds(double x, double y, double width, double height)
Changes the bounds of this object to the specified values.
Definition: gobjects.cpp:344
virtual double getHeight() const
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:148
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1262
virtual void setColor(int r, int g, int b)
Sets the color used to display this object.
Definition: gobjects.cpp:372
string toString() const override
Returns a printable representation of the object.
Definition: gobjects.cpp:984
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:119
This struct contains real-valued width and height fields.
Definition: gtypes.h:39
virtual GCompound * getParent() const
Returns a pointer to the GCompound that contains this object.
Definition: gobjects.cpp:168
virtual double getRightX() const
Returns the x-coordinate of the right side of the object.
Definition: gobjects.cpp:172
Definition: gobjects.h:71
virtual string toString() const
Returns a printable representation of the object.
Definition: gobjects.cpp:506
LineStyle _lineStyle
Definition: gobjects.h:603
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:709
virtual void setRightX(double x)
Sets the location of the rightmost x-coordinate of this object.
Definition: gobjects.cpp:332
static const double DEFAULT_CORNER
The default diameter of corners on rounded rectangles if none is supplied to the constructor.
Definition: gobjects.h:1374
virtual void setCorner(double corner)
Sets the diameter of the arc forming the corner of this rounded rectangle.
Definition: gobjects.cpp:1553
void repaint() override
Instructs the compound to redraw all of its graphical objects.
Definition: gobjects.cpp:886
virtual double getCorner() const
Returns the diameter of the arc forming the corner of this rounded rectangle.
Definition: gobjects.cpp:1545
virtual void setX(double x)
Sets the x location of the left side of this object.
Definition: gobjects.cpp:498
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:1222
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1109
virtual void setBottomY(double y)
Sets the location of the bottom y-coordinate of this object.
Definition: gobjects.cpp:328
A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors...
Definition: gcanvas.h:70
This graphical object subclass represents an oval inscribed in a rectangular box. ...
Definition: gobjects.h:1182
virtual double getX() const
Returns the leftmost x-coordinate of the object.
Definition: gobjects.cpp:185
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:1230
virtual void removeAll()
Removes all graphical objects from the compound.
Definition: gobjects.cpp:862
virtual string getFileName() const
Returns the file name used to load the image, as was passed to the constructor.
Definition: gobjects.cpp:1088
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:1346
void setFont(const QFont &font) override
Changes the font used to display the object as specified by the given Qt font.
Definition: gobjects.cpp:1613
virtual string getFillColor() const
Returns the color used to display the filled region of this object.
Definition: gobjects.cpp:144
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:821
virtual GPoint getVertex(int i) const
Returns the vertex at the given 0-based index in this polygon.
Definition: gobjects.cpp:1436
QImage * getQImage() const
Returns the inner Qt QImage object being wrapped.
Definition: gobjects.cpp:1097
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1484
virtual double getEndY() const
Returns the y-coordinate of the point at which the line ends.
Definition: gobjects.cpp:1194
virtual string getText() const
Returns the string displayed by this object.
Definition: gobjects.cpp:1605
double _y
Definition: gobjects.h:598
virtual double getCenterY() const
Returns the y-coordinate of the center of the object.
Definition: gobjects.cpp:136
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:797
virtual void move(double dx, double dy)
Moves the object on the screen using the displacements dx and dy.
Definition: gobjects.cpp:259
static void setAntiAliasing(bool value)
Globally turns on/off the anti-aliasing feature that smooths out the edges of onscreen shapes...
Definition: gobjects.cpp:324
double getHeight() const override
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:1198
virtual void setWidth(double width)
Changes the width of this object to the specified width without changing its height.
Definition: gobjects.cpp:494
This graphical object subclass represents an image from a file.
Definition: gobjects.h:953
virtual bool isFilled() const
Returns true if the object is filled with color.
Definition: gobjects.cpp:247
virtual void addPolarEdge(double r, double theta)
Adds an edge to the polygon specified in polar coordinates.
Definition: gobjects.cpp:1331
QBrush _brush
Definition: gobjects.h:614
double _opacity
Definition: gobjects.h:602
virtual void rotate(double theta)
Transforms the object by rotating it theta degrees counterclockwise around its origin.
Definition: gobjects.cpp:280
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1609
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:546
virtual string getColor() const
Returns the color used to display this object.
Definition: gobjects.cpp:140
double getWidth() const override
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:1452
virtual void setFont(const QFont &font)
Changes the font used to display the object as specified by the given Qt font.
Definition: gobjects.cpp:425
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:834
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:623
virtual void setFrameRectangle(const GRectangle &rect)
Changes the boundaries of the rectangle used to frame the arc.
Definition: gobjects.cpp:683
virtual void setHeight(double height)
Changes the height of this object to the specified height without changing its width.
Definition: gobjects.cpp:446
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:749
double _width
Definition: gobjects.h:599
virtual void setOpacity(double opacity)
Sets how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1...
Definition: gobjects.cpp:470
Definition: gobjects.h:72
virtual void setSweepAngle(double start)
Sets the sweep angle for this arc in degrees.
Definition: gobjects.cpp:692
virtual string getLabel() const
Returns the string displayed by this object.
Definition: gobjects.cpp:1601
virtual void setCenterY(double y)
Sets the y-coordinate of the center of this object.
Definition: gobjects.cpp:360
double _height
Definition: gobjects.h:600
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1129
virtual double getCenterX() const
Returns the x-coordinate of the center of the object.
Definition: gobjects.cpp:132
virtual void setForeground(int r, int g, int b)
Sets the color used to display this object.
Definition: gobjects.cpp:434
virtual double getBottomY() const
Returns the y-coordinate of the bottom of the object.
Definition: gobjects.cpp:115
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1633
QTransform _transform
Definition: gobjects.h:615
A GRoundRect represents a graphical object whose appearance consists of a rectangular box with rounde...
Definition: gobjects.h:1368
static const string DEFAULT_FONT
The default font used in text labels if none is provided.
Definition: gobjects.h:1447
GPolygon()
Constructs a new empty polygon at the origin.
Definition: gobjects.cpp:1290
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:98
Definition: gobjects.h:69
double _dy
Definition: gobjects.h:1175
virtual double getStartX() const
Returns the x-coordinate of the point at which the line starts.
Definition: gobjects.cpp:1206
virtual std::vector< GPoint > getVertices() const
Returns a vector of the points in the polygon.
Definition: gobjects.cpp:1444
virtual bool isAutoRepaint() const
Returns whether the compound automatically repaints itself when its contents change.
Definition: gobjects.cpp:842
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:1257
GImage(string filename="", double x=0, double y=0)
Constructs a new image by loading the image from the specified file.
Definition: gobjects.cpp:989
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:1176
virtual void clear()
Removes all vertexes from the polygon.
Definition: gobjects.cpp:1367
virtual void setVisible(bool flag)
Sets whether this object is visible.
Definition: gobjects.cpp:489
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:1310
virtual double getStartAngle() const
Returns the starting angle for this arc in degrees.
Definition: gobjects.cpp:663
This graphical object subclass represents a text string.
Definition: gobjects.h:1442
virtual GDimension getSize() const
Returns the size of the object as a GDimension.
Definition: gobjects.cpp:176
virtual void setBottomRightLocation(double x, double y)
Sets the location of the bottom/right of this object.
Definition: gobjects.cpp:336
virtual void setCenterLocation(double x, double y)
Sets the location of the center of this object.
Definition: gobjects.cpp:364
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:460
virtual string getFont() const
Returns the current font for the label.
Definition: gobjects.cpp:1587
virtual void scale(double sf)
Scales the object by the specified scale factor.
Definition: gobjects.cpp:286
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:901
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:1623
virtual double getFontAscent() const
Returns the maximum distance strings in this font extend above the baseline.
Definition: gobjects.cpp:1591
virtual int getVertexCount() const
Returns the number of vertexes in this polygon.
Definition: gobjects.cpp:1440
virtual void setStartAngle(double start)
Sets the starting angle for this arc in degrees.
Definition: gobjects.cpp:687
virtual GPoint getEndPoint() const
Returns the point at which the arc ends.
Definition: gobjects.cpp:655
virtual GPoint getBottomRightLocation() const
Returns the x/y coordinates of the bottom/right corner of the object.
Definition: gobjects.cpp:111
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:1469
virtual ~GObject()
Frees the storage for the object.
Definition: gobjects.cpp:94
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1507
virtual void setFilled(bool flag)
Sets the fill status for the object, where false is outlined and true is filled.
Definition: gobjects.cpp:420
void sendForward()
Moves this object one step toward the front in the z dimension.
Definition: gobjects.cpp:303
virtual void setSize(double width, double height)
Changes the size of this object to the specified width and height.
Definition: gobjects.cpp:476
virtual double getStartY() const
Returns the y-coordinate of the point at which the line starts.
Definition: gobjects.cpp:1210
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:675
int _colorInt
Definition: gobjects.h:605
double _x
Definition: gobjects.h:597
string _fillColor
Definition: gobjects.h:606
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:48
GCompound * _parent
Definition: gobjects.h:612
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1549
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:560
virtual void setY(double y)
Sets the y location of the top of this object.
Definition: gobjects.cpp:502
virtual GPoint getStartPoint() const
Returns the point at which the line starts.
Definition: gobjects.cpp:1202
virtual GPoint getStartPoint() const
Returns the point at which the arc starts.
Definition: gobjects.cpp:667
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:394
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:697
virtual ~GImage()
Frees memory allocated internally by the image.
Definition: gobjects.cpp:1023
double _corner
Definition: gobjects.h:1420
static bool isAntiAliasing()
Returns whether we should globally anti-alias graphical objects.
Definition: gobjects.cpp:243
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:1456
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:62
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:1629
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:1105
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1214
A GRect is a graphical object whose appearance consists of a rectangular box.
Definition: gobjects.h:1345
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:541
virtual void setLineWidth(double lineWidth)
Sets the width of the line used to draw this object.
Definition: gobjects.cpp:455
virtual string getType() const =0
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.h:70
This graphical object subclass consists of a collection of other graphical objects.
Definition: gobjects.h:765
Definition: gobjects.h:73
GText(string str="", double x=0, double y=0)
Creates a GText object containing the specified string.
Definition: gobjects.cpp:1564
double getWidth() const override
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:1218
bool _visible
Definition: gobjects.h:610
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:1092
virtual int getElementCount() const
Returns the number of graphical objects stored in the compound.
Definition: gobjects.cpp:830
virtual GPoint getLocation() const
Returns the location of the top-left corner of object.
Definition: gobjects.cpp:160
LineStyle
Styles that can be used for the outline around various shapes.
Definition: gobjects.h:68
double _lineWidth
Definition: gobjects.h:601
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1462
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1285
string _font
Definition: gobjects.h:608
QPen _pen
Definition: gobjects.h:613
virtual double getY() const
Returns the topmost y-coordinate of the object.
Definition: gobjects.cpp:189
void sendToFront()
Moves this object to the front of the display in the z dimension.
Definition: gobjects.cpp:317
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1559
string _color
Definition: gobjects.h:604
virtual void clear()
Removes all graphical objects from the compound.
Definition: gobjects.cpp:739
virtual void repaint()
Instructs the object to redraw itself on screen.
Definition: gobjects.cpp:263
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:817
virtual bool isEmpty() const
Returns true if the compound does not contain any graphical objects.
Definition: gobjects.cpp:846
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:251
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1372
friend class GDiffImage
Definition: gobjects.h:1048
bool contains(double x, double y) const override
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:761
virtual double getEndX() const
Returns the x-coordinate of the point at which the line ends.
Definition: gobjects.cpp:1190
virtual void setAutoRepaint(bool autoRepaint)
Sets whether the compound automatically repaints itself when its contents change. ...
Definition: gobjects.cpp:976
double _dx
Definition: gobjects.h:1174
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:1495
virtual double getOpacity() const
Returns how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1...
Definition: gobjects.cpp:164
virtual void addVertex(double x, double y)
Adds a vertex at (x, y) relative to the polygon origin.
Definition: gobjects.cpp:1335
int _fillColorInt
Definition: gobjects.h:607
void sendToBack()
Moves this object to the back of the display in the z dimension.
Definition: gobjects.cpp:310
bool _transformed
Definition: gobjects.h:611
virtual double getLineWidth() const
Returns the width of the line used to draw this object.
Definition: gobjects.cpp:156
virtual bool isVisible() const
Returns true if this object is visible on screen.
Definition: gobjects.cpp:255
This struct contains real-valued x, y, width, and height fields.
Definition: gtypes.h:289
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1101
Definition: gobjects.h:74
GCompound()
Creates a compound with no internal components.
Definition: gobjects.cpp:704
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:1579
virtual double getWidth() const
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:181
string toStringExtra() const override
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1250
string getType() const override
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1432
virtual GPoint getEndPoint() const
Returns the point at which the line ends.
Definition: gobjects.cpp:1186
virtual GPoint getCenterLocation() const
Returns the x/y-coordinates of the center of the object.
Definition: gobjects.cpp:128
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:1302
virtual void resetTransform()
Undoes any previous scale/rotate transformations on this object.
Definition: gobjects.cpp:274
void sendBackward()
Moves this object one step toward the back in the z dimension.
Definition: gobjects.cpp:296
virtual GRectangle getFrameRectangle() const
Returns the boundaries of the rectangle used to frame the arc.
Definition: gobjects.cpp:659
double getHeight() const override
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:1428
virtual void setCenterX(double x)
Sets the x-coordinate of the center of this object.
Definition: gobjects.cpp:356
This struct contains real-valued x and y fields.
Definition: gtypes.h:198
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:1242
This graphical object subclass represents a line segment.
Definition: gobjects.h:1054
This graphical object subclass represents a polygon bounded by line segments.
Definition: gobjects.h:1211
This graphical object subclass represents an elliptical arc.
Definition: gobjects.h:672
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:1114
bool _fillFlag
Definition: gobjects.h:609
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:450
virtual void conditionalRepaint()
Repaints the compound only if it needs to be repainted (if any of its contents have changed)...
Definition: gobjects.cpp:743
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:1407
virtual double getFontDescent() const
Returns the maximum distance strings in this font descend below the baseline.
Definition: gobjects.cpp:1596