blob: ea84bb80e35bb4d8be7d67b1edde77a614696d12 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "ViewController.h"
#include "View.h"
#include "Museum.h"
ViewController::ViewController(Museum & m) : museum(m) {};
void ViewController::update(View & view) {
this->update_size(view);
this->update_tiles(view);
this->update_artists(view);
}
void ViewController::update_size(View & view) {
view.set_size(
this->scale * this->museum.canvas.data.columns,
this->scale * this->museum.canvas.data.rows
);
}
void ViewController::update_tiles(View & view) {
for (unsigned y = 0; y < this->museum.canvas.data.rows; y++) {
for (unsigned x = 0; x < this->museum.canvas.data.columns; x++) {
Tile & tile = this->museum.canvas.get_tile(x, y);
Rectangle rect = {
.x = x * scale,
.y = y * scale,
.width = scale - line_width,
.height = scale - line_width,
};
view.draw_rect(rect, tile.color);
}
}
}
void ViewController::update_artists(View & view) {
People & people = this->museum.people;
for (size_t i = 0; i < people.artists_size(); i++) {
Artist & artist = people.get_artist(i);
Rectangle rect = {
.x = static_cast<unsigned int>(artist.data.x * scale),
.y = static_cast<unsigned int>(artist.data.y * scale),
.width = artist_size,
.height = artist_size,
};
view.draw_rect(rect, artist.color);
}
}
|