Advertisement

Trackbar problem

Started by September 11, 2017 03:31 AM
1 comment, last by Servant of the Lord 7 years, 2 months ago

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);
}

 

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.

This topic is closed to new replies.

Advertisement