Problem with my horizontal bar

Asked

Viewed 55 times

1

I am having problems with my horizontal bar, the problem is that it is not increasing the value of the variable "Ivar" 1 in 1, is increasing 5 in 5 or even more dependent on how much I pass the value Imax, how I fix this problem?

#define SLIDER_WIDTH        250
#define SLIDER_HEIGHT       8
#define MAX_SLIDERS     30

int SliderPos[MAX_SLIDERS] = { 0 };

int iNumSliders = 0;

void AddSliderBar(int iPosX, int iPosY, int iMinVal, int iMaxVal, std::string sText, int &iVar)
{
    Color SliderColor1 = Color(200, 000, 000);
    Color SliderColor2 = Color(200, 000, 000);

    SliderPos[qntSliders] = iPosX + (iVar - iMinVal) * SLIDER_WIDTH / (iMaxVal - iMinVal);

    if (bMouseInRegion(iPosX, iPosY + 11, SLIDER_WIDTH, SLIDER_HEIGHT) && bMouseClicked())
        iVar = (Cur.x - iPosX) * (iMaxVal - iMinVal) / SLIDER_WIDTH;

    (iVar > iMaxVal) ? iVar = iMaxVal : iVar = iVar;
    (iVar < iMinVal) ? iVar = iMinVal : iVar = iVar;

    PrintText(x, y - 3, SliderColor1, FL_RIGHT, "%s: %i", sText.c_str(), iVar);

    // Slider cursor
    Draw.FillRGB(SliderPos[qntSliders], iPosY + 8, 2, SLIDER_HEIGHT, SliderColor1);

    // Slider bar
    Draw.FillRGB(iPosX, iPosY + 11, SLIDER_WIDTH, 2, SliderColor2);

    iNumSliders++;
}
  • If the raise comes from here iVar = (Cur.x - iPosX) * (iMaxVal - iMinVal) / SLIDER_WIDTH; because it would be of 1 in 1 ?

  • I don’t know, I think I have a better way of calculating that so that the increase is 1 to 1, the point is that I broke my head and I couldn’t make that calculation work.

  • What is this? GUI programming?

  • Yes, for a Directx 9 application.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.