1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
void DrawSlider(float x, float y, float w, int min, int max, int &Sliderx, int &SliderValue)
{
float sliderw = 5.f;
float sliderh = 15.f;
POINT MousePos = GetMousePos();
float clickx = Sliderx - MousePos.x;
float moveto = Sliderx - clickx - sliderw / 2;
if (MousePos.x >= x - sliderw / 2 && MousePos.y >= y - 2 && MousePos.x <= x + w + sliderw / 2 && MousePos.y <= y + sliderh + 2)
{
if (GetAsyncKeyState(0x1))
{
Sliderx = moveto;
}
}
if (Sliderx < x - sliderw / 2){ Sliderx = x - sliderw / 2; }
if (Sliderx > x + w - sliderw / 2){ Sliderx = x + w - sliderw / 2; }
BoxFilled(x, y, w, sliderh, GRAY(170));
//this->BoxFilled(x, y, sliderx - x, sliderh, RED(170));
BoxFilled(x, y, w, sliderh, BLACK(170));
BoxFilled(Sliderx, y, sliderw, sliderh, GREEN(170));
SliderValue = ((max - min) / (w))*(Sliderx - x + sliderw / 2) + min;
char chSliderValue[20];
sprintf_s(chSliderValue, " [%1.0f]", (float)SliderValue);
DrawText(x + w + 120, y + 1, RED(255), chSliderValue, DT_CENTER);
}
// My call
DrawSlider(10, 10, 200, 100, 255, Sliderx, SliderValue);
| |