Usando el estado en los graficos
This commit is contained in:
@@ -22,9 +22,10 @@ void SDLTextureDestroyer::operator()(SDL_Texture* texture) const {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
Graphics::Graphics(): width(64 * 30),
|
||||
height(35 * 30),
|
||||
scale(30) {}
|
||||
Graphics::Graphics(std::shared_ptr<MachineState> machine_state): machine_state{std::move(machine_state)},
|
||||
width{64 * 30},
|
||||
height{32 * 30},
|
||||
scale{30} {}
|
||||
|
||||
|
||||
bool Graphics::init() {
|
||||
@@ -51,18 +52,18 @@ bool Graphics::init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Graphics::draw(std::array<bool, 2048> display, std::string info) {
|
||||
void Graphics::draw() {
|
||||
SDL_SetRenderDrawColor(renderer.get(), 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(renderer.get());
|
||||
|
||||
draw_display(display);
|
||||
draw_info(info);
|
||||
draw_display();
|
||||
|
||||
SDL_RenderPresent(renderer.get());
|
||||
}
|
||||
|
||||
void Graphics::draw_display(std::array<bool, 2048> display) {
|
||||
void Graphics::draw_display() {
|
||||
SDL_Surface* surface = nullptr;
|
||||
auto& display = machine_state->display;
|
||||
|
||||
if (SDL_LockTextureToSurface(texture.get(), nullptr, &surface)) {
|
||||
SDL_FillSurfaceRect(surface, nullptr, SDL_MapRGB(SDL_GetPixelFormatDetails(surface->format), nullptr, 0, 0, 0));
|
||||
@@ -92,21 +93,3 @@ void Graphics::draw_display(std::array<bool, 2048> display) {
|
||||
SDL_RenderTexture(renderer.get(), texture.get(), nullptr, &destination_rect);
|
||||
}
|
||||
|
||||
void Graphics::draw_info(std::string info) {
|
||||
const int charsize = SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE;
|
||||
const float screen_scale = static_cast<float>(scale);
|
||||
const float text_scale = 2.0f;
|
||||
|
||||
const float info_area_start = 32.0f * screen_scale;
|
||||
const float info_area_height = (35.0f - 32.0f) * screen_scale;
|
||||
const float info_area_center = info_area_start + (info_area_height / 2.0f);
|
||||
|
||||
const float text_line = info_area_center / text_scale - (static_cast<float>(charsize) / 2.0f);
|
||||
|
||||
SDL_SetRenderScale(renderer.get(), text_scale, text_scale);
|
||||
SDL_SetRenderDrawColor(renderer.get(), 255, 255, 255, SDL_ALPHA_OPAQUE);
|
||||
|
||||
SDL_RenderDebugText(renderer.get(), 10 / text_scale, text_line, info.data());
|
||||
|
||||
SDL_SetRenderScale(renderer.get(), 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user