
#include "TpnlSky.h"

// -----------------------
// --- le constructeur ---
// -----------------------

TpnlSky::TpnlSky()
{
    //
}

// ----------------------
// --- le destructeur ---
// ----------------------

TpnlSky::~TpnlSky()
{
    //
}

// --------------------
// --- les méthodes ---
// --------------------

void TpnlSky::create(OTextureList& textureList, int aLeft, int aTop, int aRight)
{
    ORect_i src,dst;
    s_texParam texParam;
	int refX = 0, refY = 0;

    OTextureList::P_setPath(PATH_INTERFACE);
    textureList.add("interface.png");

    // ---

    panel.create(220,140,aLeft,aTop,aRight,-1);

    // ---

    texParam = textureList.getParam("interface.png");

    refX = panel.getLeft() + 8;
    refY = panel.getTop() - 8;

    dst.set(refX,refY,50,16);
    lblHeure.create(dst, "Hour");

    OLevelBox::P_setModeSlider(true);
    //OLevelBox::P_setCursorStep(2.0f);
    dst.set(refX+50,refY,100,20);
    src.set(400,0,100,20);
    sldHeure.create(dst, texParam, src);
        sldHeure.setRange(0, 2400, 1);
        sldHeure.setCursorStep(10.0f);

    dst.set(refX+160, refY+2, 40, 20);
    src.set(380,80,40,20);
    lblValHeure.create(dst, "12", texParam, src);

    // ---

    refY -= 24;
    src.set(380,120,80,80);
    dst.set(refX,refY,60,60);
    imgAide.create(dst, texParam, src);

    // ---

    refX = panel.getLeft() + 8 +86;
    refY = panel.getTop() - 8 -30;

    OButtonCkd::P_setTextZone(8,4,64,20);
    src.set(100,0,100,20);
    dst.set(refX,refY,64,20);
    ckdCycle.create(dst, "cycle", texParam, src);
    OButtonCkd::P_setTextZone(20+8,4,128,16);

	src.set(460,120, 50,20);
	dst.set(refX +70, refY, 50,20);
	sldCycle.create(dst, texParam, src);
	sldCycle.setRange(1.0f, 10.0f);
	sldCycle.setStep(1.0f);
	sldCycle.setIndex(0);

	// ---

    refX = panel.getLeft() + 8 +86;
    refY = panel.getTop() - 8 -60;

    OButtonCkd::P_setTextZone(8,4,64,20);
    src.set(100,0,100,20);
    dst.set(refX,refY,64,20);
    ckdGleam.create(dst, "gleam", texParam, src);
    OButtonCkd::P_setTextZone(20+8,4,128,16);

    // ---

    refX = panel.getLeft() + 8;
    refY = panel.getTop() - 8 -90;

    dst.set(refX,refY,50,16);
    lblPhase.create(dst, "phase");

    OLevelBox::P_setModeSlider(true);
    //OLevelBox::P_setCursorStep(2.0f);
    dst.set(refX+50,refY,100,20);
    src.set(400,0,100,20);
    sldPhase.create(dst, texParam, src);
        sldPhase.setCursorStep(10.0f);
        sldPhase.setValue(50.0f);

    dst.set(refX+160, refY+2, 40, 20);
    src.set(380,80,40,20);
    lblValPhase.create(dst, "5", texParam, src);
}

void TpnlSky::draw()
{
    panel.draw();

    lblHeure.draw();
    sldHeure.draw();
    lblValHeure.draw();

    ckdCycle.draw();
    sldCycle.draw();

    imgAide.draw();

    ckdGleam.draw();

    lblPhase.draw();
    sldPhase.draw();
    lblValPhase.draw();


}




bool TpnlSky::getCycle()
{
    return ckdCycle.getChecked();
}

bool TpnlSky::getGleam()
{
    return ckdGleam.getChecked();
}

int TpnlSky::getHeight()
{
    return panel.getHeight();
}

float TpnlSky::getHour()
{
    return sldHeure.getValue() / 100.0f;
}

int TpnlSky::getPhase()
{
    return sldPhase.getValueI() / 10;
}

float TpnlSky::getStep()
{
    return sldCycle.getValue() / 250.0f;
}


int TpnlSky::mouseDown(int x, int y)
{
    if (sldHeure.mouseDown(x,y))
    {
        _setHour();
        return TPNLSKY_CYCLE;
    }

    if (ckdCycle.mouseDown())
    {
        if (ckdCycle.getChecked())
        {
            sldHeure.setEnabled(true);
        }
        else
        {
            sldHeure.setEnabled(false);
        }
        return TPNLSKY_CYCLE;
    }
    if (ckdGleam.mouseDown())
    {
        return TPNLSKY_GLEAM;
    }
    if (sldPhase.mouseDown(x,y))
    {
        _setPhase();
        return TPNLSKY_PHASE;
    }

    if (panel.mouseDown(x,y))
    {
        return CLICK_ON;
    }

	return CLICK_NULL;
}

void TpnlSky::mouseMove(int x, int y)
{
    sldHeure.mouseMove(x,y);
    ckdCycle.mouseMove(x,y);
    sldCycle.mouseMove(x,y);
    ckdGleam.mouseMove(x,y);
    sldPhase.mouseMove(x,y);
}

void TpnlSky::mouseUp()
{
    //
}

int TpnlSky::mouseWheel(int delta)
{
    if (sldHeure.mouseWheel(delta))
    {
        _setHour();
        return TPNLSKY_HOUR;
    }
    sldCycle.mouseWheel(delta);
    if (sldPhase.mouseWheel(delta))
    {
        _setPhase();
        return TPNLSKY_PHASE;
    }
    return CLICK_NULL;
}





void TpnlSky::setHour(float value)
{
    sldHeure.setValue(value*100);
    _setHour();
}

void TpnlSky::_setHour()
{
    lblValHeure.setText( ECO_floatToStr( sldHeure.getValue() / 100.0f, "##,#") );
}

void TpnlSky::_setPhase()
{
    lblValPhase.setText( ECO_intToStr(sldPhase.getValueI() / 10 ) );
}

/*
le dynpanel est ancré = on récupère son décalage
*/
void TpnlSky::shift()
{
    int dx = 0, dy = 0;

    panel.shift(&dx, &dy);

    lblHeure.shift(dx, dy);
    sldHeure.shift(dx, dy);
    lblValHeure.shift(dx, dy);

    ckdCycle.shift(dx,dy);
    sldCycle.shift(dx,dy);

    imgAide.shift(dx,dy);

    ckdGleam.shift(dx,dy);

    lblPhase.shift(dx,dy);
    lblValPhase.shift(dx,dy);
    sldPhase.shift(dx,dy);

}




