aboutsummaryrefslogtreecommitdiff
path: root/ViewController.cpp
blob: 269edaaa5623ac7f9cf4427b098dab3f0d466b72 (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 (Artist * artist : people.get_artists()) {
		if (artist == nullptr) continue;
		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);
	}
}