aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAiden Woodruff <aiden.woodruff@gmail.com>2023-12-31 19:38:51 -0600
committerAiden Woodruff <aiden.woodruff@gmail.com>2023-12-31 19:38:51 -0600
commitbe462cacb89a26c5cef204210d386ef3a79e4928 (patch)
treee04019837bd4689c325173745ec69809afe01381
parentf1849116d7225a49f7b5d1fdef6117af84cf861c (diff)
downloadstars-be462cacb89a26c5cef204210d386ef3a79e4928.tar.gz
stars-be462cacb89a26c5cef204210d386ef3a79e4928.tar.bz2
stars-be462cacb89a26c5cef204210d386ef3a79e4928.zip
Move View to View.cc and remove unused things
Moved all View definitions to View.cc Removed View::print_done Removed unused App::screenwidth, App::screenheight. Rearranged View member data. Removed unused reference in Controller::collect_input Update TODOs
-rw-r--r--README.md1
-rw-r--r--include/app/App.h1
-rw-r--r--include/app/View.h72
-rw-r--r--src/app/Controller.cc1
-rw-r--r--src/app/Model.cc3
-rw-r--r--src/app/View.cc49
6 files changed, 71 insertions, 56 deletions
diff --git a/README.md b/README.md
index 541e895..d2122b6 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,7 @@ cmake --build build
25- Remove dynamic_cast from default ClickHandlerAggregate::handle. 25- Remove dynamic_cast from default ClickHandlerAggregate::handle.
26- Maybe add Action dispatcher to Controller or make App a Singleton 26- Maybe add Action dispatcher to Controller or make App a Singleton
27 ActionDispatcher. 27 ActionDispatcher.
28- Add fallback font.
28 29
29## Future 30## Future
30 31
diff --git a/include/app/App.h b/include/app/App.h
index b80a577..f2a8fdf 100644
--- a/include/app/App.h
+++ b/include/app/App.h
@@ -28,7 +28,6 @@ private:
28 Model m; 28 Model m;
29 View v; 29 View v;
30 Controller c; 30 Controller c;
31 int screenwidth, screenheight;
32}; 31};
33 32
34} // namespace stars 33} // namespace stars
diff --git a/include/app/View.h b/include/app/View.h
index 921d0c1..6adc921 100644
--- a/include/app/View.h
+++ b/include/app/View.h
@@ -10,66 +10,34 @@
10 10
11namespace stars { 11namespace stars {
12class View { 12class View {
13 int width, height, star_radius;
14 sf::RenderWindow* window;
15 std::vector<sf::Vector2f> starPos;
16 sf::VertexArray edges;
17 sf::CircleShape star;
18 std::vector<Widget*> widgets;
19
20public: 13public:
21 View(int w, int h, int sr): 14 View(int w, int h, int sr);
22 width(w), height(h), star_radius(sr), window(nullptr), star(star_radius), 15 ~View();
23 edges(sf::Lines) {
24 star.setOrigin(star_radius, star_radius);
25 }
26
27 ~View() {
28 if (window) { delete window; }
29 }
30
31 void make_window() {
32 if (!window) {
33 window =
34 new sf::RenderWindow(sf::VideoMode(width, height), "Constellations");
35 }
36 }
37
38 void attachWidget(Widget* w) { widgets.push_back(w); }
39
40 void detachWidget(Widget* w) {
41 widgets.erase(std::remove(widgets.begin(), widgets.end(), w),
42 widgets.end());
43 }
44 16
45 void close_window() { window->close(); } 17 void make_window();
18 void close_window();
19 void display();
46 20
47 void add_star(const sf::Vector2f& v) { starPos.push_back(v); } 21 void attachWidget(Widget* w);
22 void detachWidget(Widget* w);
48 23
49 void clear_stars() { starPos.clear(); } 24 void add_star(const sf::Vector2f& v);
25 void clear_stars();
50 26
51 void add_edge(const sf::Vertex& v, const sf::Vertex& u) { 27 void add_edge(const sf::Vertex& v, const sf::Vertex& u);
52 edges.append(v); 28 void clear_edges();
53 edges.append(u);
54 }
55
56 void clear_edges() { edges.clear(); }
57
58 void print_done() { std::cout << "Done." << std::endl; }
59
60 void display() {
61 window->clear();
62 window->draw(edges);
63 for (const sf::Vector2f& p : starPos) {
64 star.setPosition(p);
65 window->draw(star);
66 }
67 for (const Widget* w : widgets) { window->draw(*w); }
68 window->display();
69 }
70 29
71 friend class Controller; 30 friend class Controller;
31
32private:
33 int width, height, star_radius;
34 sf::RenderWindow* window;
35 sf::CircleShape star;
36 std::vector<sf::Vector2f> starPos;
37 sf::VertexArray edges;
38 std::vector<Widget*> widgets;
72}; // class View 39}; // class View
40
73} // namespace stars 41} // namespace stars
74 42
75#endif // STARS_VIEW_H_ 43#endif // STARS_VIEW_H_
diff --git a/src/app/Controller.cc b/src/app/Controller.cc
index 0962ec0..6ddf994 100644
--- a/src/app/Controller.cc
+++ b/src/app/Controller.cc
@@ -54,7 +54,6 @@ void Controller::show_popup() {
54 } 54 }
55 } else if (mode == Mode::control_popup) { 55 } else if (mode == Mode::control_popup) {
56 if (event.type == sf::Event::MouseButtonReleased) { 56 if (event.type == sf::Event::MouseButtonReleased) {
57 sf::Event::MouseButtonEvent &mbe = event.mouseButton;
58 handle(Click(*(view->window), event)); 57 handle(Click(*(view->window), event));
59 } 58 }
60 } 59 }
diff --git a/src/app/Model.cc b/src/app/Model.cc
index ef9c0f9..f1407a3 100644
--- a/src/app/Model.cc
+++ b/src/app/Model.cc
@@ -68,4 +68,5 @@ void Model::generate_edges() {
68 } 68 }
69 } 69 }
70} 70}
71} // namespace stars \ No newline at end of file 71
72} // namespace stars
diff --git a/src/app/View.cc b/src/app/View.cc
index 7266cd3..cffc7f7 100644
--- a/src/app/View.cc
+++ b/src/app/View.cc
@@ -2,4 +2,51 @@
2 2
3namespace stars { 3namespace stars {
4 4
5} // namespace stars 5View::View(int w, int h, int sr):
6 width(w), height(h), star_radius(sr), window(nullptr), star(star_radius),
7 edges(sf::Lines) {
8 star.setOrigin(star_radius, star_radius);
9}
10
11View::~View() {
12 if (window) { delete window; }
13}
14
15void View::make_window() {
16 if (!window) {
17 window =
18 new sf::RenderWindow(sf::VideoMode(width, height), "Constellations");
19 }
20}
21
22void View::attachWidget(Widget* w) { widgets.push_back(w); }
23
24void View::detachWidget(Widget* w) {
25 widgets.erase(std::remove(widgets.begin(), widgets.end(), w), widgets.end());
26}
27
28void View::close_window() { window->close(); }
29
30void View::add_star(const sf::Vector2f& v) { starPos.push_back(v); }
31
32void View::clear_stars() { starPos.clear(); }
33
34void View::add_edge(const sf::Vertex& v, const sf::Vertex& u) {
35 edges.append(v);
36 edges.append(u);
37}
38
39void View::clear_edges() { edges.clear(); }
40
41void View::display() {
42 window->clear();
43 window->draw(edges);
44 for (const sf::Vector2f& p : starPos) {
45 star.setPosition(p);
46 window->draw(star);
47 }
48 for (const Widget* w : widgets) { window->draw(*w); }
49 window->display();
50}
51
52} // namespace stars