git.haldean.org ana / 8be87ea src / ui.cpp
8be87ea

Tree @8be87ea (Download .tar.gz)

ui.cpp @8be87earaw · history · blame

#include "ui.hpp"

namespace ana {

void ui::set_aspect(int w, int h) {
    width = w;
    height = h;
    aspect = (float) h / w;
}

void ui::view_step(int dir) {
    if (dir > 0) {
        view *= 1.2;
        if (view > 20) {
            view = 20;
        }
    } else if (dir < 0) {
        view /= 1.2;
        if (view < 0.05) {
            view = 0.05;
        }
    }
}

void ui::translate(int xpixels, int ypixels) {
    float x = 2.f * view * xpixels / width;
    float y = 2.f * view * aspect * ypixels / height;
    center.x += x;
    center.y += y;
}

}