aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-12 14:03:21 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-12 14:03:21 +0200
commite113e6e65be07ab31d69243bd8d219d2bc02d094 (patch)
tree55babde607b6928a9bc62bf730d972f73bd7fd16
parent31dbd326f69656473067dde6d4f008cd7c04f0b1 (diff)
add simple view
-rw-r--r--ViewController.cpp20
-rw-r--r--ViewController.h4
-rw-r--r--main.cpp7
3 files changed, 22 insertions, 9 deletions
diff --git a/ViewController.cpp b/ViewController.cpp
index 256be90..2ed68b5 100644
--- a/ViewController.cpp
+++ b/ViewController.cpp
@@ -1,12 +1,28 @@
#include "ViewController.h"
#include "View.h"
+#include "Museum.h"
ViewController::ViewController(View & v, Museum & m) : view(v), museum(m) {};
void ViewController::update() {
- this->view.set_size(100, 100);
+ Canvas & canvas = this->museum.canvas;
+ unsigned width = canvas.data.columns;
+ unsigned height = canvas.data.rows;
+ this->view.set_size(scale * width, scale * height);
+
this->view.draw_begin();
- this->view.draw_rect({ 10, 10, 50, 50 }, { 255, 0, 255 });
+ for (unsigned y = 0; y < height; y++) {
+ for (unsigned x = 0; x < width; x++) {
+ Tile & tile = canvas.get_tile(x, y);
+ Rectangle rect = {
+ .x = x * scale,
+ .y = y * scale,
+ .width = scale - line_width,
+ .height = scale - line_width,
+ };
+ this->view.draw_rect(rect, tile.color);
+ }
+ }
this->view.draw_end();
}
diff --git a/ViewController.h b/ViewController.h
index 418082f..00db87f 100644
--- a/ViewController.h
+++ b/ViewController.h
@@ -13,5 +13,9 @@ public:
private:
View & view;
Museum & museum;
+
+private:
+ unsigned int scale = 16;
+ unsigned int line_width = 1;
};
diff --git a/main.cpp b/main.cpp
index 55fb627..d86cb0d 100644
--- a/main.cpp
+++ b/main.cpp
@@ -38,17 +38,10 @@ void load_museum(Museum & m, int argc, char** argv) {
d.finalize();
}
-void load_view(View & v, Museum & m) {
- // v.set_target(&m);
-
-}
-
int main(int argc, char** argv) {
Museum m {};
load_museum(m, argc, argv);
- printf("%s", m.canvas.to_string(true).c_str());
-
View v {};
ViewController vc {v, m};