Jump to content
  • Advertisement

Trackbar problem

This topic is 429 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm doing my little GUI,  200-300 lines of my own code instead of heavy IMGUI and such, and yes, I'm suck. I managed to draw stuff and make it even somewhat functional, but in case I'm drawing, let's assume, trackbar with size of 100 and MaxVal is 100 is okay, but in case MaxVal  is 5 I have to use 5 as a width and my trackbar become very short.  I would like to have static width regardless of MaxVal . The VariableValue is becoming wrong.

void Trackbar(const float X, const float Y, const float Width, bool Variable, const char* Caption, const float MaxVal, UINT& VariableValue)
    POINT            TrackbarPos;
    GetCursorPos   (&TrackbarPos);
    ScreenToClient (GetForegroundWindow(), &TrackbarPos);

    static float AbsolutePos = 0;

    if (Variable) {
        if (IsMouseCursorIn(X, Y-18, Width, 15)) {
            if (KeyState_LButton == OnKeyPressed) {
                AbsolutePos = TrackbarPos.x-X;
                float RelativePos = (AbsolutePos/MaxVal)*Width; // this is wrong
                VariableValue = RelativePos;
    D3DCOLOR Color = D3DCOLOR_ARGB(255, 96, 96, 96);
    if (Variable) {
        Color = D3DCOLOR_ARGB(255, 106, 106, 106);

    //! Bar
    ToolkitRenderer::GetToolkitRenderer().Box(X, Y-10, Width+4, 1, Color, true);

    //! Slider
    ToolkitRenderer::GetToolkitRenderer().Box(X+AbsolutePos, Y-11, 3, 2, D3DCOLOR_ARGB(255, 89, 89, 89), true );
    ToolkitRenderer::GetToolkitRenderer().Box(X+AbsolutePos, Y-11, 3, 2, D3DCOLOR_ARGB(255, 110, 110, 110), false);

    //! Text
    //ToolkitRenderer::GetToolkitRenderer().Text(X, Y-15, 0, Caption, Color);


Share this post

Link to post
Share on other sites

If absolute pos is the pos within the trackbar, e.g. 15 pixels out of 100 pixels wide, then if you do (AbsolutePos/Width), that'd be 15/100 which is 0.15f (meaning 15% of the way through).

float RelativePos = (AbsolutePos/Width);

I'm not sure what MaxVal is supposed to be doing though, so I may have misunderstood your question.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!