StanfordCPPLib
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 2019/03/07
10  * - added support for loading a GImage directly from istream (htiek)
11  * @version 2018/09/14
12  * - added opacity support
13  * - added GCanvas-to-GImage conversion support
14  * @version 2018/09/08
15  * - added doc comments for new documentation generation
16  * @version 2018/08/23
17  * - renamed to gobjects.h to replace Java version
18  * @version 2018/06/30
19  * - initial version
20  */
21 
22 #include "private/init.h" // ensure that Stanford C++ lib is initialized
23 
24 #ifndef INTERNAL_INCLUDE
25 // signal that GUI system is in use (so it will be initialized)
26 #define SPL_QT_GUI_IN_USE 1
27 #include "private/initstudent.h" // insert necessary included code by student
28 #endif // INTERNAL_INCLUDE
29 
30 #ifndef _gobjects_h
31 #define _gobjects_h
32 
33 #include <initializer_list>
34 #include <iostream>
35 #include <QFont>
36 #include <QImage>
37 #include <QPainter>
38 #include <QPen>
39 #include <QWidget>
40 
41 #define INTERNAL_INCLUDE 1
42 #include "gtypes.h"
43 #define INTERNAL_INCLUDE 1
44 #include "vector.h"
45 #undef INTERNAL_INCLUDE
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  virtual bool contains(double x, double y) const ;
693 
698  virtual void draw(QPainter* painter);
699 
700  /* @inherit */
701  virtual GRectangle getBounds() const ;
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  virtual string getType() const ;
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  virtual string toStringExtra() const ;
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  virtual bool contains(double x, double y) const ;
832 
837  virtual void draw(QPainter* painter);
838 
839  /* @inherit */
840  virtual GRectangle getBounds() const ;
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  virtual string getType() const ;
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  virtual void repaint();
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  virtual string toString() const ;
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  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  virtual void draw(QPainter* painter) ;
997 
1002  virtual string getFileName() const;
1003 
1008  virtual int getPixel(int x, int y) const;
1009 
1010  /* @inherit */
1011  virtual string getType() const ;
1012 
1018  virtual void setPixel(int x, int y, int rgb);
1019 
1020  /* @inherit */
1021  virtual string toStringExtra() const ;
1022 
1023 protected:
1028  GImage(QImage* qimage);
1029 
1033  QImage* getQImage() const;
1034 
1035 private:
1040  bool loadFromStream(std::istream& input);
1041 
1042  string _filename;
1043  QImage* _qimage;
1044 
1045  friend class GCanvas;
1046  friend class GDiffImage;
1047 };
1048 
1052 class GLine : public GObject {
1053 public:
1060  GLine(double x0 = 0, double y0 = 0, double x1 = 0, double y1 = 0, LineStyle lineStyle = LINE_SOLID);
1061 
1067  GLine(const GPoint& p0, const GPoint& p1);
1068 
1069  /* @inherit */
1070  virtual bool contains(double x, double y) const ;
1071 
1076  virtual void draw(QPainter* painter) ;
1077 
1078  /* @inherit */
1079  virtual GRectangle getBounds() const ;
1080 
1084  virtual GPoint getEndPoint() const;
1085 
1089  virtual double getEndX() const;
1090 
1094  virtual double getEndY() const;
1095 
1096  /* @inherit */
1097  virtual double getHeight() const ;
1098 
1103  virtual GPoint getStartPoint() const;
1104 
1109  virtual double getStartX() const;
1110 
1115  virtual double getStartY() const;
1116 
1117  /* @inherit */
1118  virtual string getType() const ;
1119 
1120  /* @inherit */
1121  virtual double getWidth() const ;
1122 
1128  virtual void setEndPoint(double x, double y);
1129 
1135  virtual void setStartPoint(double x, double y);
1136 
1137  /* @inherit */
1138  virtual string toStringExtra() const ;
1139 
1140 protected:
1141  /* Instance variables */
1142  double _dx; // the x displacement of the line
1143  double _dy; // the y displacement of the line
1144 };
1145 
1150 class GOval : public GObject {
1151 public:
1157  GOval(double x = 0, double y = 0, double width = 0, double height = 0);
1158 
1159  /* @inherit */
1160  virtual bool contains(double x, double y) const ;
1161 
1166  virtual void draw(QPainter* painter) ;
1167 
1168  /* @inherit */
1169  virtual string getType() const ;
1170 };
1171 
1179 class GPolygon : public GObject {
1180 public:
1184  GPolygon();
1185 
1189  GPolygon(std::initializer_list<double> coords);
1190  GPolygon(std::initializer_list<GPoint> points);
1191 
1196  virtual void addEdge(double dx, double dy);
1197 
1202  virtual void addEdge(const GPoint& pt);
1203 
1208  virtual void addEdges(std::initializer_list<double> coords);
1209 
1214  virtual void addEdges(std::initializer_list<GPoint> points);
1215 
1222  virtual void addPolarEdge(double r, double theta);
1223 
1228  virtual void addVertex(double x, double y);
1229 
1234  virtual void addVertex(const GPoint& pt);
1235 
1241  virtual void addVertexes(std::initializer_list<double> coords);
1242 
1248  virtual void addVertexes(std::initializer_list<GPoint> points);
1249 
1253  virtual void clear();
1254 
1255  /* @inherit */
1256  virtual bool contains(double x, double y) const;
1257 
1262  virtual void draw(QPainter* painter) ;
1263 
1264  /* @inherit */
1265  virtual GRectangle getBounds() const;
1266 
1267  /* @inherit */
1268  virtual double getHeight() const;
1269 
1270  /* @inherit */
1271  virtual string getType() const;
1272 
1277  virtual GPoint getVertex(int i) const;
1278 
1282  virtual int getVertexCount() const;
1283 
1287  virtual Vector<GPoint> getVertices() const;
1288 
1289  /* @inherit */
1290  virtual double getWidth() const;
1291 
1297  virtual void setVertex(int i, GPoint point);
1298 
1299  /* @inherit */
1300  virtual string toStringExtra() const;
1301 
1302 private:
1303  /* Instance variables */
1304  QVector<QPointF> _vertices; // the vertices of the polygon
1305  double _cx; // the most recent x coordinate
1306  double _cy; // the most recent y coordinate
1307 };
1308 
1313 class GRect : public GObject {
1314 public:
1320  GRect(double x = 0, double y = 0, double width = 0, double height = 0);
1321 
1326  virtual void draw(QPainter* painter) ;
1327 
1328  /* @inherit */
1329  virtual string getType() const ;
1330 };
1331 
1336 class GRoundRect : public GRect {
1337 public:
1342  static const double DEFAULT_CORNER;
1343 
1349  GRoundRect(double width = 0, double height = 0, double corner = DEFAULT_CORNER);
1350 
1356  GRoundRect(double x, double y, double width, double height, double corner = DEFAULT_CORNER);
1357 
1361  virtual bool contains(double x, double y) const;
1362 
1367  virtual void draw(QPainter* painter) ;
1368 
1373  virtual double getCorner() const;
1374 
1375  /* @inherit */
1376  virtual string getType() const ;
1377 
1382  virtual void setCorner(double corner);
1383 
1384  /* @inherit */
1385  virtual std::string toStringExtra() const ;
1386 
1387 protected:
1388  double _corner;
1389 };
1390 
1410 class GText : public GObject {
1411 public:
1415  static const string DEFAULT_FONT;
1416 
1423  GText(const string& str = "", double x = 0, double y = 0);
1424 
1429  virtual void draw(QPainter* painter);
1430 
1431  /* @inherit */
1432  virtual GRectangle getBounds() const ;
1433 
1437  virtual std::string getFont() const;
1438 
1443  virtual double getFontAscent() const;
1444 
1449  virtual double getFontDescent() const;
1450 
1455  virtual std::string getLabel() const;
1456 
1461  virtual std::string getText() const;
1462 
1463  /* @inherit */
1464  virtual std::string getType() const ;
1465 
1466  /* @inherit */
1467  virtual void setFont(const QFont& font) ;
1468 
1469  /* @inherit */
1470  virtual void setFont(const std::string& font) ;
1471 
1477  virtual void setLabel(const std::string& str);
1478 
1484  virtual void setText(const std::string& str);
1485 
1486  /* @inherit */
1487  virtual std::string toStringExtra() const ;
1488 
1489 private:
1490  /* Instance variables */
1491  std::string _text; // the string displayed by the label
1492  QFont _qfont;
1493 
1494  // update width and height when font or text changes
1495  void updateSize();
1496 };
1497 
1501 std::ostream& operator <<(std::ostream& out, const GObject& obj);
1502 
1503 #endif // _gobjects_h
virtual double getSweepAngle() const
Returns the sweep angle for this arc in degrees.
Definition: gobjects.cpp:668
virtual LineStyle getLineStyle() const
Returns the object&#39;s style such as solid or dashed.
Definition: gobjects.cpp:153
virtual double getWidth() const
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:1203
virtual void setBounds(double x, double y, double width, double height)
Changes the bounds of this object to the specified values.
Definition: gobjects.cpp:341
virtual double getHeight() const
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:149
virtual void repaint()
Instructs the compound to redraw all of its graphical objects.
Definition: gobjects.cpp:883
virtual void setColor(int r, int g, int b)
Sets the color used to display this object.
Definition: gobjects.cpp:369
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:694
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:120
virtual GCompound * getParent() const
Returns a pointer to the GCompound that contains this object.
Definition: gobjects.cpp:169
virtual double getRightX() const
Returns the x-coordinate of the right side of the object.
Definition: gobjects.cpp:173
Definition: gobjects.h:75
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:1376
virtual string toString() const
Returns a printable representation of the object.
Definition: gobjects.cpp:503
LineStyle _lineStyle
Definition: gobjects.h:607
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:706
virtual double getHeight() const
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:1397
virtual void setRightX(double x)
Sets the location of the rightmost x-coordinate of this object.
Definition: gobjects.cpp:329
static const double DEFAULT_CORNER
The default diameter of corners on rounded rectangles if none is supplied to the constructor.
Definition: gobjects.h:1342
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:1161
virtual void setCorner(double corner)
Sets the diameter of the arc forming the corner of this rounded rectangle.
Definition: gobjects.cpp:1521
virtual double getCorner() const
Returns the diameter of the arc forming the corner of this rounded rectangle.
Definition: gobjects.cpp:1513
virtual void setX(double x)
Sets the x location of the left side of this object.
Definition: gobjects.cpp:495
virtual void setBottomY(double y)
Sets the location of the bottom y-coordinate of this object.
Definition: gobjects.cpp:325
A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors...
Definition: gcanvas.h:87
This graphical object subclass represents an oval inscribed in a rectangular box. ...
Definition: gobjects.h:1150
virtual double getX() const
Returns the leftmost x-coordinate of the object.
Definition: gobjects.cpp:186
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1117
virtual void removeAll()
Removes all graphical objects from the compound.
Definition: gobjects.cpp:859
virtual string getFileName() const
Returns the file name used to load the image, as was passed to the constructor.
Definition: gobjects.cpp:1077
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:1315
virtual string getFillColor() const
Returns the color used to display the filled region of this object.
Definition: gobjects.cpp:145
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:818
virtual GPoint getVertex(int i) const
Returns the vertex at the given 0-based index in this polygon.
Definition: gobjects.cpp:1405
QImage * getQImage() const
Returns the inner Qt QImage object being wrapped.
Definition: gobjects.cpp:1086
virtual double getEndY() const
Returns the y-coordinate of the point at which the line ends.
Definition: gobjects.cpp:1179
virtual string toString() const
Returns a printable representation of the object.
Definition: gobjects.cpp:981
virtual double getHeight() const
Returns the height of this object, which is the same as the height of its bounding box...
Definition: gobjects.cpp:1183
double _y
Definition: gobjects.h:602
This class stores an ordered list of values similar to an array.
Definition: vector.h:86
virtual double getCenterY() const
Returns the y-coordinate of the center of the object.
Definition: gobjects.cpp:137
virtual void move(double dx, double dy)
Moves the object on the screen using the displacements dx and dy.
Definition: gobjects.cpp:256
static void setAntiAliasing(bool value)
Globally turns on/off the anti-aliasing feature that smooths out the edges of onscreen shapes...
Definition: gobjects.cpp:321
This class contains real-valued width and height fields.
Definition: gtypes.h:47
virtual void setWidth(double width)
Changes the width of this object to the specified width without changing its height.
Definition: gobjects.cpp:491
This graphical object subclass represents an image from a file.
Definition: gobjects.h:957
virtual double getWidth() const
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:1421
virtual bool isFilled() const
Returns true if the object is filled with color.
Definition: gobjects.cpp:244
virtual void addPolarEdge(double r, double theta)
Adds an edge to the polygon specified in polar coordinates.
Definition: gobjects.cpp:1300
QBrush _brush
Definition: gobjects.h:618
double _opacity
Definition: gobjects.h:606
virtual void rotate(double theta)
Transforms the object by rotating it theta degrees counterclockwise around its origin.
Definition: gobjects.cpp:277
STL namespace.
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:543
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:831
virtual string getColor() const
Returns the color used to display this object.
Definition: gobjects.cpp:141
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1476
virtual void setFont(const QFont &font)
Changes the font used to display the object as specified by the given Qt font.
Definition: gobjects.cpp:422
virtual void setFrameRectangle(const GRectangle &rect)
Changes the boundaries of the rectangle used to frame the arc.
Definition: gobjects.cpp:680
virtual void setHeight(double height)
Changes the height of this object to the specified height without changing its width.
Definition: gobjects.cpp:443
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:746
double _width
Definition: gobjects.h:603
virtual Vector< GPoint > getVertices() const
Returns a vector of the points in the polygon.
Definition: gobjects.cpp:1413
virtual void setOpacity(double opacity)
Sets how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1...
Definition: gobjects.cpp:467
Definition: gobjects.h:76
virtual void setSweepAngle(double start)
Sets the sweep angle for this arc in degrees.
Definition: gobjects.cpp:689
virtual void setCenterY(double y)
Sets the y-coordinate of the center of this object.
Definition: gobjects.cpp:357
double _height
Definition: gobjects.h:604
virtual double getCenterX() const
Returns the x-coordinate of the center of the object.
Definition: gobjects.cpp:133
virtual void setForeground(int r, int g, int b)
Sets the color used to display this object.
Definition: gobjects.cpp:431
virtual double getBottomY() const
Returns the y-coordinate of the bottom of the object.
Definition: gobjects.cpp:116
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1401
QTransform _transform
Definition: gobjects.h:619
A GRoundRect represents a graphical object whose appearance consists of a rectangular box with rounde...
Definition: gobjects.h:1336
static const string DEFAULT_FONT
The default font used in text labels if none is provided.
Definition: gobjects.h:1415
GPolygon()
Constructs a new empty polygon at the origin.
Definition: gobjects.cpp:1259
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:99
Definition: gobjects.h:73
virtual void setStartPoint(double x, double y)
Sets the initial point in the line to (x,&#160;y), leaving the end point unchanged.
Definition: gobjects.cpp:1213
double _dy
Definition: gobjects.h:1143
virtual double getStartX() const
Returns the x-coordinate of the point at which the line starts.
Definition: gobjects.cpp:1191
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1231
virtual bool isAutoRepaint() const
Returns whether the compound automatically repaints itself when its contents change.
Definition: gobjects.cpp:839
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:1226
GImage(string filename="", double x=0, double y=0)
Constructs a new image by loading the image from the specified file.
Definition: gobjects.cpp:986
virtual void clear()
Removes all vertexes from the polygon.
Definition: gobjects.cpp:1336
virtual void setVisible(bool flag)
Sets whether this object is visible.
Definition: gobjects.cpp:486
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:1279
This class contains real-valued x and y fields.
Definition: gtypes.h:216
virtual double getStartAngle() const
Returns the starting angle for this arc in degrees.
Definition: gobjects.cpp:660
This graphical object subclass represents a text string.
Definition: gobjects.h:1410
virtual GDimension getSize() const
Returns the size of the object as a GDimension.
Definition: gobjects.cpp:177
virtual void setBottomRightLocation(double x, double y)
Sets the location of the bottom/right of this object.
Definition: gobjects.cpp:333
virtual void setCenterLocation(double x, double y)
Sets the location of the center of this object.
Definition: gobjects.cpp:361
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:457
virtual void scale(double sf)
Scales the object by the specified scale factor.
Definition: gobjects.cpp:283
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:898
virtual int getVertexCount() const
Returns the number of vertexes in this polygon.
Definition: gobjects.cpp:1409
virtual void setStartAngle(double start)
Sets the starting angle for this arc in degrees.
Definition: gobjects.cpp:684
virtual GPoint getEndPoint() const
Returns the point at which the arc ends.
Definition: gobjects.cpp:652
virtual GPoint getBottomRightLocation() const
Returns the x/y coordinates of the bottom/right corner of the object.
Definition: gobjects.cpp:112
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:1438
virtual ~GObject()
Frees the storage for the object.
Definition: gobjects.cpp:95
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1098
virtual void setFilled(bool flag)
Sets the fill status for the object, where false is outlined and true is filled.
Definition: gobjects.cpp:417
void sendForward()
Moves this object one step toward the front in the z dimension.
Definition: gobjects.cpp:300
virtual void setSize(double width, double height)
Changes the size of this object to the specified width and height.
Definition: gobjects.cpp:473
virtual double getStartY() const
Returns the y-coordinate of the point at which the line starts.
Definition: gobjects.cpp:1195
int _colorInt
Definition: gobjects.h:609
double _x
Definition: gobjects.h:601
string _fillColor
Definition: gobjects.h:610
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:53
GCompound * _parent
Definition: gobjects.h:616
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1527
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1219
virtual void setY(double y)
Sets the y location of the top of this object.
Definition: gobjects.cpp:499
virtual GPoint getStartPoint() const
Returns the point at which the line starts.
Definition: gobjects.cpp:1187
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1453
virtual GPoint getStartPoint() const
Returns the point at which the arc starts.
Definition: gobjects.cpp:664
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:391
virtual ~GImage()
Frees memory allocated internally by the image.
Definition: gobjects.cpp:1029
double _corner
Definition: gobjects.h:1388
static bool isAntiAliasing()
Returns whether we should globally anti-alias graphical objects.
Definition: gobjects.cpp:240
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:1425
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:66
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:1094
A GRect is a graphical object whose appearance consists of a rectangular box.
Definition: gobjects.h:1313
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:538
virtual void setLineWidth(double lineWidth)
Sets the width of the line used to draw this object.
Definition: gobjects.cpp:452
virtual string getType() const =0
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.h:74
This graphical object subclass consists of a collection of other graphical objects.
Definition: gobjects.h:769
Definition: gobjects.h:77
virtual void setEndPoint(double x, double y)
Sets the end point in the line to (x,&#160;y), leaving the start point unchanged.
Definition: gobjects.cpp:1207
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:672
bool _visible
Definition: gobjects.h:614
virtual string toStringExtra() const
Returns a string containing any extra unique information about this type of graphical object...
Definition: gobjects.cpp:1431
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:1081
virtual int getElementCount() const
Returns the number of graphical objects stored in the compound.
Definition: gobjects.cpp:827
virtual GPoint getLocation() const
Returns the location of the top-left corner of object.
Definition: gobjects.cpp:161
LineStyle
Styles that can be used for the outline around various shapes.
Definition: gobjects.h:72
double _lineWidth
Definition: gobjects.h:605
string _font
Definition: gobjects.h:612
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:620
QPen _pen
Definition: gobjects.h:617
virtual double getY() const
Returns the topmost y-coordinate of the object.
Definition: gobjects.cpp:190
void sendToFront()
Moves this object to the front of the display in the z dimension.
Definition: gobjects.cpp:314
string _color
Definition: gobjects.h:608
virtual void clear()
Removes all graphical objects from the compound.
Definition: gobjects.cpp:736
virtual void repaint()
Instructs the object to redraw itself on screen.
Definition: gobjects.cpp:260
This class contains real-valued x, y, width, and height fields.
Definition: gtypes.h:324
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:814
friend class GText
Definition: gobjects.h:656
virtual bool isEmpty() const
Returns true if the compound does not contain any graphical objects.
Definition: gobjects.cpp:843
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:248
friend class GDiffImage
Definition: gobjects.h:1046
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1254
virtual double getEndX() const
Returns the x-coordinate of the point at which the line ends.
Definition: gobjects.cpp:1175
virtual void setAutoRepaint(bool autoRepaint)
Sets whether the compound automatically repaints itself when its contents change. ...
Definition: gobjects.cpp:973
double _dx
Definition: gobjects.h:1142
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:1464
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1517
virtual double getOpacity() const
Returns how opaque (non-transparent) this object will appear from 0.0 (completely transparent) to 1...
Definition: gobjects.cpp:165
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:557
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1090
virtual void addVertex(double x, double y)
Adds a vertex at (x, y) relative to the polygon origin.
Definition: gobjects.cpp:1304
int _fillColorInt
Definition: gobjects.h:611
void sendToBack()
Moves this object to the back of the display in the z dimension.
Definition: gobjects.cpp:307
virtual string getType() const
Returns the type of the object as a string, such as "GOval" or "GRect".
Definition: gobjects.cpp:1199
bool _transformed
Definition: gobjects.h:615
virtual double getLineWidth() const
Returns the width of the line used to draw this object.
Definition: gobjects.cpp:157
virtual bool isVisible() const
Returns true if this object is visible on screen.
Definition: gobjects.cpp:252
Definition: gobjects.h:78
GCompound()
Creates a compound with no internal components.
Definition: gobjects.cpp:701
virtual double getWidth() const
Returns the width of this object, which is equal to the width of the bounding box.
Definition: gobjects.cpp:182
virtual GPoint getEndPoint() const
Returns the point at which the line ends.
Definition: gobjects.cpp:1171
virtual GPoint getCenterLocation() const
Returns the x/y-coordinates of the center of the object.
Definition: gobjects.cpp:129
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:1271
virtual void resetTransform()
Undoes any previous scale/rotate transformations on this object.
Definition: gobjects.cpp:271
void sendBackward()
Moves this object one step toward the back in the z dimension.
Definition: gobjects.cpp:293
virtual GRectangle getFrameRectangle() const
Returns the boundaries of the rectangle used to frame the arc.
Definition: gobjects.cpp:656
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:1341
virtual void setCenterX(double x)
Sets the x-coordinate of the center of this object.
Definition: gobjects.cpp:353
This graphical object subclass represents a line segment.
Definition: gobjects.h:1052
This graphical object subclass represents a polygon bounded by line segments.
Definition: gobjects.h:1179
virtual bool contains(double x, double y) const
Returns true if the specified point is inside the object.
Definition: gobjects.cpp:758
This graphical object subclass represents an elliptical arc.
Definition: gobjects.h:676
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:1103
bool _fillFlag
Definition: gobjects.h:613
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:447
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:794
virtual void conditionalRepaint()
Repaints the compound only if it needs to be repainted (if any of its contents have changed)...
Definition: gobjects.cpp:740