#include "ViewController.h" #include "Scancode.h" #include "View.h" #include "Museum.h" ViewController::ViewController(Museum & m, View & v) : museum(m), view(v) {}; void ViewController::update() { this->update_size(); this->update_tiles(); this->update_artists(); } void ViewController::update_size() { this->view.window_size( this->scale * this->museum.canvas.data.columns, this->scale * this->museum.canvas.data.rows ); } void ViewController::update_tiles() { 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, }; this->view.draw_rect(rect, tile.color); } } } void ViewController::update_artists() { People & people = this->museum.people; for (Artist * artist : people.get_artists()) { if (artist == nullptr) continue; Rectangle rect = { .x = static_cast(artist->data.x * scale), .y = static_cast(artist->data.y * scale), .width = artist_size, .height = artist_size, }; this->view.draw_rect(rect, artist->color); } } void ViewController::keypress(Scancode scancode) { switch (scancode) { KEY_SPACE: { printf("TODO: toggle museum.pause\n"); break; } KEY_ENTER: { break; } KEY_O: { printf("TODO: open dialog\n"); this->view.dialog_file(); break; } KEY_A: { break; } KEY_LEFT: { break; } KEY_RIGHT: { break; } default: break; } }