This is my code for sliders in my D3D menu:
Code:
if (this->Data.ControlType == SLIDER) // New control type
{
int max = this->Data.Size.x;
pDrawing.DrawFilledRectangle(this->Data.Position + this->Data.WindowProperties->Position, V(this->Data.Size.x, 1), CLRWHITE);
pDrawing.DrawOutlinedRectangle(this->Data.Position + this->Data.WindowProperties->Position, V(this->Data.Size.x, 1), 1.0f, CLRBLACK);
pDrawing.DrawFilledRectangle(V(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos, this->Data.Position.y + this->Data.WindowProperties->Position.y - 4), V(6, 9), BUTTON_BACKGROUND);
pDrawing.DrawOutlinedRectangle(V(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos, this->Data.Position.y + this->Data.WindowProperties->Position.y - 4), V(6, 9), 1.0f, CLRBLUE);
printf("Slider position: %i\n", this->Vars.sliderpos);
if (Tools.MouseIsOver(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos-2, this->Data.Position.y + this->Data.WindowProperties->Position.y - 6, 9, 12) && !pMenu.Holding && this->Data.Enabled)
{
pDrawing.DrawFilledRectangle(V(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos, this->Data.Position.y + this->Data.WindowProperties->Position.y - 4), V(6, 9), BUTTON_HOVER);
pDrawing.DrawOutlinedRectangle(V(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos, this->Data.Position.y + this->Data.WindowProperties->Position.y - 4), V(6, 9), 1.0f, CLRBLUE);
if ((GetAsyncKeyState(VK_LBUTTON) || GetAsyncKeyState(VK_RBUTTON)) && (this->Vars.sliderpos <= max) && (this->Vars.sliderpos >= 0))
{
pDrawing.DrawFilledRectangle(V(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos, this->Data.Position.y + this->Data.WindowProperties->Position.y - 4), V(6, 9), CLRWHITE);
pDrawing.DrawOutlinedRectangle(V(this->Data.Position.x + this->Data.WindowProperties->Position.x + this->Vars.sliderpos, this->Data.Position.y + this->Data.WindowProperties->Position.y - 4), V(6, 9), 1.0f, CLRBLUE);
POINT cur;
GetCursorPos(&cur);
ScreenToClient(GetForegroundWindow(), &cur);
this->Vars.sliderpos = cur.x - (this->Data.Position.x + this->Data.WindowProperties->Position.x+3);
if (this->Vars.sliderpos < 0)
this->Vars.sliderpos = 1;
if (this->Vars.sliderpos > max)
this->Vars.sliderpos = max;
printf("%f\n", this->Vars.sliderpos);
}
}
}
The idea behind sliders is incredibly simple
X-----|-------------X
Basically the X's are the boundaries of the slider, an the | is the slider to drag. The value of the slider is just based on where it is positioned on the length of the slider.