Skip to content

Commit bf503a5

Browse files
committed
Added comments. Moved the drawTexturedxxx to Renderer. Added some
comments for the more complicated code. Commented more code.
1 parent ea5cf4c commit bf503a5

File tree

5 files changed

+248
-203
lines changed

5 files changed

+248
-203
lines changed

include/Renderer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ void renderText(const std::string& font, int fontSize, const std::pair<float, fl
1919
void renderText(const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const GLuint& texture);
2020
void renderRectangle(const std::pair<float, float> bottomLeft, const std::pair<float, float> topRight, const std::tuple<float, float, float> color);
2121

22+
void renderTexturedCircle(const std::pair<float, float> texCenter, const float texRadius, const std::pair<float, float> screenCenter,
23+
const float screenRadius, const GLuint& texture, int articulation = 20);
24+
void renderTexturedRectangle(const std::pair<float, float> screenBottomLeft, const std::pair<float, float> screenTopRight,
25+
const std::pair<float, float> texBottomLeft, const std::pair<float, float> texTopRight, const GLuint& texture);
2226

2327
std::pair<float, float> coordToScreen(const Coordinate& coord);
2428
Coordinate screenToCoord(const std::pair<float, float>&);

include/ViewElement.h

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "Util.h"
1313

14-
1514
/**
1615
* An element that is drawn on screen and can receive inputs from the user. These all occupy a rectangular area on screen
1716
* and can choose to handle clicks from the user that are inside their area.
@@ -20,8 +19,11 @@ class ViewElement {
2019
private:
2120
std::pair<ScreenCoordinate, ScreenCoordinate> rect;
2221

23-
ViewElement(const ViewElement& vw) {} //deleted
24-
ViewElement& operator=(const ViewElement&) { return *this; } // deleted
22+
ViewElement(const ViewElement& vw) {
23+
} //deleted
24+
ViewElement& operator=(const ViewElement&) {
25+
return *this;
26+
} // deleted
2527
protected:
2628
virtual bool clicked(ScreenCoordinate coord) = 0;
2729
public:
@@ -34,11 +36,10 @@ class ViewElement {
3436
virtual void render() = 0;
3537
};
3638

37-
3839
/**
3940
* A view element that is invisible and calls a callback function when it is clicked.
4041
*/
41-
class ViewButton : public ViewElement {
42+
class ViewButton: public ViewElement {
4243
private:
4344
std::function<bool(ScreenCoordinate)> action;
4445

@@ -47,7 +48,8 @@ class ViewButton : public ViewElement {
4748
protected:
4849
virtual bool clicked(ScreenCoordinate coord);
4950
public:
50-
ViewButton(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect);
51+
ViewButton(std::function<bool(ScreenCoordinate)> action,
52+
std::pair<ScreenCoordinate, ScreenCoordinate> rect);
5153
virtual ~ViewButton();
5254

5355
virtual void render();
@@ -61,27 +63,29 @@ class ViewButton : public ViewElement {
6163
* @return An owning unique pointer to the constructed view button.
6264
*/
6365
template<class Fn>
64-
std::unique_ptr<ViewElement> makeViewButton(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect) {
66+
std::unique_ptr<ViewElement> makeViewButton(Fn fn,
67+
std::pair<ScreenCoordinate, ScreenCoordinate> rect) {
6568
return std::unique_ptr<ViewElement>(new ViewButton(fn, rect));
6669
}
6770

6871
/**
6972
* A view element drawn as a solid color that has a callback function that is called when it is clicked.
7073
*/
71-
class ViewButtonColor : public ViewButton {
74+
class ViewButtonColor: public ViewButton {
7275
private:
7376
std::tuple<float, float, float> color;
7477

7578
ViewButtonColor(const ViewButtonColor& vb) = delete;
7679
ViewButtonColor& operator=(const ViewButtonColor& vb) = delete;
7780
public:
78-
ViewButtonColor(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color);
81+
ViewButtonColor(std::function<bool(ScreenCoordinate)> action,
82+
std::pair<ScreenCoordinate, ScreenCoordinate> rect,
83+
std::tuple<float, float, float> color);
7984
virtual ~ViewButtonColor();
8085

8186
virtual void render();
8287
};
8388

84-
8589
/**
8690
* Constructs a ViewButtonColor using the same parameters as the ViewButtonColor. Exists because template inference exists only
8791
* for functions, not classes.
@@ -91,24 +95,29 @@ class ViewButtonColor : public ViewButton {
9195
* @return An owning unique pointer to the constructed view button.
9296
*/
9397
template<class Fn>
94-
std::unique_ptr<ViewElement> makeViewButtonColor(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::tuple<float, float, float> color) {
98+
std::unique_ptr<ViewElement> makeViewButtonColor(Fn fn,
99+
std::pair<ScreenCoordinate, ScreenCoordinate> rect,
100+
std::tuple<float, float, float> color) {
95101
return std::unique_ptr<ViewElement>(new ViewButtonColor(fn, rect, color));
96102
}
97103

98104
/**
99105
* A view element drawn as some text on the screen that has a callback function when it is clicked.
100106
*/
101-
class ViewButtonText : public ViewButton {
107+
class ViewButtonText: public ViewButton {
102108
private:
103109
GLuint texture;
104110

105111
ViewButtonText(const ViewButtonText& vb) = delete;
106112
ViewButtonText& operator=(const ViewButtonText& vb) = delete;
107113
public:
108-
ViewButtonText(std::function<bool(ScreenCoordinate)> action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, const std::string& font, int fontSize, const std::string& text);
114+
ViewButtonText(std::function<bool(ScreenCoordinate)> action,
115+
std::pair<ScreenCoordinate, ScreenCoordinate> rect,
116+
const std::string& font, int fontSize, const std::string& text);
109117
virtual ~ViewButtonText();
110118

111-
void setText(const std::string& font, int fontSize, const std::string& text);
119+
void setText(const std::string& font, int fontSize,
120+
const std::string& text);
112121

113122
virtual void render();
114123
};
@@ -123,11 +132,14 @@ class ViewButtonText : public ViewButton {
123132
* @param text The text to render.
124133
*/
125134
template<class Fn>
126-
std::unique_ptr<ViewElement> makeViewButtonText(Fn fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, const std::string& font, int fontSize, const std::string& text) {
127-
return std::unique_ptr<ViewElement>(new ViewButtonText(fn, rect, font, fontSize, text));
135+
std::unique_ptr<ViewElement> makeViewButtonText(Fn fn,
136+
std::pair<ScreenCoordinate, ScreenCoordinate> rect,
137+
const std::string& font, int fontSize, const std::string& text) {
138+
return std::unique_ptr<ViewElement>(
139+
new ViewButtonText(fn, rect, font, fontSize, text));
128140
}
129141

130-
class TradingView : public ViewElement {
142+
class TradingView: public ViewElement {
131143
private:
132144
std::string initiating;
133145
std::string receiving;
@@ -142,14 +154,16 @@ class TradingView : public ViewElement {
142154
protected:
143155
virtual bool clicked(ScreenCoordinate coord);
144156
public:
145-
TradingView(const std::string& initiating, const std::string& receiving, std::function<bool(std::array<int, 5>, ScreenCoordinate)> trade, std::function<bool(ScreenCoordinate)> cancel, std::array<int, 5> offer);
157+
TradingView(const std::string& initiating, const std::string& receiving,
158+
std::function<bool(std::array<int, 5>, ScreenCoordinate)> trade,
159+
std::function<bool(ScreenCoordinate)> cancel,
160+
std::array<int, 5> offer);
146161
virtual ~TradingView();
147162

148163
void render();
149164
};
150165

151-
152-
class ConfirmationDialogue : public ViewElement {
166+
class ConfirmationDialogue: public ViewElement {
153167
private:
154168
ScreenCoordinate topLeft;
155169
ScreenCoordinate bottomRight;
@@ -163,7 +177,10 @@ class ConfirmationDialogue : public ViewElement {
163177
virtual bool clicked(ScreenCoordinate coord);
164178

165179
public:
166-
ConfirmationDialogue(std::function<bool(ScreenCoordinate)> confirm_action, std::function<bool(ScreenCoordinate)> cancel_action, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::string message);
180+
ConfirmationDialogue(std::function<bool(ScreenCoordinate)> confirm_action,
181+
std::function<bool(ScreenCoordinate)> cancel_action,
182+
std::pair<ScreenCoordinate, ScreenCoordinate> rect,
183+
std::string message);
167184
void render();
168185
};
169186

@@ -177,20 +194,11 @@ class ConfirmationDialogue : public ViewElement {
177194
* @return a unique_ptr to a newly created confirmation dialogue in the form of a view element
178195
*/
179196
template<class Fn>
180-
std::unique_ptr<ViewElement> makeConfirmationDialogue(Fn confirm_fn, Fn cancel_fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect, std::string message) {
181-
return std::unique_ptr<ViewElement>(new ConfirmationDialogue(confirm_fn, cancel_fn, rect, message));
197+
std::unique_ptr<ViewElement> makeConfirmationDialogue(Fn confirm_fn,
198+
Fn cancel_fn, std::pair<ScreenCoordinate, ScreenCoordinate> rect,
199+
std::string message) {
200+
return std::unique_ptr<ViewElement>(
201+
new ConfirmationDialogue(confirm_fn, cancel_fn, rect, message));
182202
}
183203

184-
185-
186-
187-
188-
189-
190-
191-
192-
193-
194-
195-
196204
#endif

0 commit comments

Comments
 (0)