@@ -16,6 +16,10 @@ class GameController;
1616class ViewElement ;
1717class GameView ;
1818
19+ /* *
20+ * An element that is drawn on screen and can receive inputs from the user. These all occupy a rectangular area on screen
21+ * and can choose to handle clicks from the user that are inside their area.
22+ */
1923class ViewElement {
2024private:
2125 std::pair<ScreenCoordinate, ScreenCoordinate> rect;
@@ -34,6 +38,9 @@ class ViewElement {
3438 virtual void render () = 0;
3539};
3640
41+ /* *
42+ * The class in charge of drawing the view to the screen, using OpenGL calls.
43+ */
3744class GameView {
3845private:
3946 GameBoard& model;
@@ -52,6 +59,9 @@ class GameView {
5259 void addElement (std::unique_ptr<ViewElement>);
5360};
5461
62+ /* *
63+ * A visitor of the GameBoard hierarchy that draws the entire model.
64+ */
5565class DrawingGameVisitor : public GameVisitor {
5666private:
5767 GameView& view;
@@ -71,6 +81,9 @@ class DrawingGameVisitor : public GameVisitor {
7181 virtual void visit (DevelopmentCard&);
7282};
7383
84+ /* *
85+ * A view element that is invisible and calls a callback function when it is clicked.
86+ */
7487template <class Fn >
7588class ViewButton : public ViewElement {
7689private:
@@ -89,11 +102,21 @@ class ViewButton : public ViewElement {
89102 virtual void render () {}
90103};
91104
105+ /* *
106+ * Constructs a ViewButton using the same parameters as the ViewButton. Exists because template inference exists only
107+ * for functions, not classes.
108+ * @param fn The callback function to be called with the ScreenCoordinate clicked and returning a boolean on if it was handled.
109+ * @param rect The location on screen that the invisible button receives clicks from.
110+ * @return An owning unique pointer to the constructed view button.
111+ */
92112template <class Fn >
93113std::unique_ptr<ViewElement> makeViewButton (Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect) {
94114 return std::unique_ptr<ViewElement>(new ViewButton<Fn>(fn, rect));
95115}
96116
117+ /* *
118+ * A view element drawn as a solid color that has a callback function that is called when it is clicked.
119+ */
97120template <class Fn >
98121class ViewButtonColor : public ViewButton <Fn> {
99122private:
@@ -119,6 +142,14 @@ class ViewButtonColor : public ViewButton<Fn> {
119142 }
120143};
121144
145+ /* *
146+ * Constructs a ViewButtonColor using the same parameters as the ViewButtonColor. Exists because template inference exists only
147+ * for functions, not classes.
148+ * @param fn The callback function to be called with the ScreenCoordinate clicked and returning a boolean on if it was handled.
149+ * @param rect The location on screen to draw to and receive clicks from.
150+ * @param color The color to draw the button. RGB floats from 0 to 1 for intensity.
151+ * @return An owning unique pointer to the constructed view button.
152+ */
122153template <class Fn >
123154std::unique_ptr<ViewElement> makeViewButtonColor (Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float , float , float > color) {
124155 return std::unique_ptr<ViewElement>(new ViewButtonColor<Fn>(fn, rect, color));
0 commit comments