#include "Medidores.h"

//======= MEDIDOR CUADRADO=======

itfzMedS::itfzMedS(int hor, int ver, string tit, float valuef, bool updtabl, string id, SDL_Surface * screen) {
    posX = hor;
    posY = ver;
    value = valuef;
    scr = screen;
    fondo = itfz_LoadIMG("bgs");
    frente = itfz_LoadIMG("fs");
    textotitulo = tit;
    updateable = updtabl;
    ID = id;
    textovalor = NULL;
    titulo = itfz_DrawText(futurab12, GRIS, textotitulo.c_str());
    paint();
}

void itfzMedS::paint(void) {
    itfz_PosIMG(fondo, posX, posY + 40, scr);
    itfz_PosIMG(titulo, posX + 105, posY + 43, scr);
    rescale();
    itfz_PosIMG(textovalor, posX + 120, posY + 65, scr);
}

void itfzMedS::rescale(void) {
    SDL_Rect dest;
    SDL_Rect orig;
    char txtvalor[5];
    sprintf(txtvalor, "%3.1f", value);
    SDL_FreeSurface(textovalor);
    textovalor = itfz_DrawText(futurab30, NEGRO, txtvalor);
    orig.y = (Sint16) ((frente->h)-(frente->h)*(value / 700));
    orig.x = 0;
    orig.h = (frente->h)-(orig.y);
    orig.w = frente->w;
    dest.x = (posX + 36);
    dest.y = (posY + 60)+(frente->h)-(orig.h);
    SDL_BlitSurface(frente, &orig, scr, &dest);
}

//======= MEDIDOR CIRCULAR =======

itfzMedC::itfzMedC(int hor, int ver, string tit, float valuef, bool updtabl, string id, SDL_Surface * screen) {
    posX = hor;
    posY = ver;
    value = valuef;
    scr = screen;
    fondo = itfz_LoadIMG("bgc");
    frente = itfz_LoadIMG("fc");
    textotitulo = tit;
    updateable = updtabl;
    ID = id;
    textovalor = NULL;
    titulo = itfz_DrawText(futurab12, GRIS, textotitulo.c_str());
    paint();

}

void itfzMedC::paint(void) {
    itfz_PosIMG(fondo, posX, posY+40, scr);
    itfz_PosIMG(titulo, posX + 105, posY + 43, scr);
    rescale();
    itfz_PosIMG(textovalor, posX + 125, posY + 65, scr);
}

void itfzMedC::rescale(void) {
    char txtvalor[5];
    sprintf(txtvalor, "%3.1f", value);
    SDL_FreeSurface(textovalor);
    textovalor = itfz_DrawText(futurab30, NEGRO, txtvalor);
}


//====== MEDIDOR TEXTO ======

itfzMedT::itfzMedT(int hor, int ver, string tit, float valuef, bool updtabl, string id, SDL_Surface * screen) {
    posX = hor;
    posY = ver;
    value = valuef;
    scr = screen;
    fondo = itfz_LoadIMG("bgt");
    textotitulo = tit;
    updateable = updtabl;
    ID = id;
    textovalor = NULL;
    titulo = itfz_DrawText(futurab12, GRIS, textotitulo.c_str());
    grados = itfz_DrawText(futurab12, GRIS, "*C");
    paint();

}

void itfzMedT::paint(void) {
    itfz_PosIMG(fondo, posX+5, posY+50, scr);
    itfz_PosIMG(titulo, posX, posY+35, scr);
    itfz_PosIMG(grados, posX + 40, posY + 100, scr);
    rescale();
    itfz_PosIMG(textovalor, posX + 25, posY + 70, scr);
}

void itfzMedT::rescale(void) {
    char txtvalor[5];
    sprintf(txtvalor, "%3.1f", value);
    SDL_FreeSurface(textovalor);
    textovalor = itfz_DrawText(futurab24, NEGRO, txtvalor);
}
