Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Ok, i am trying to draw a custom slider bar in c++ using dx9. I have a sprite that is 1 pixel wide to use as the progress bar fill texture, The lengh of the progress bar is 128 pixels.

I am calling the function like:
DrawSlider(int x, int y, int max, int fill)
x = x location
y = y location
max = max value of progress bar instance
fill = amount of fill to add to bar to show value.


my math is failing me but i believe i need two for loops in this function:
1 loop to fill the steps and 1 loop to add the steps to the bar.

failed attempt:
void DrawSlider(int x, int y, int max, int fill)
{
    int step = 128 / max;
    DrawSprite(v3SliderBar,texSliderBar);
    for(int i = 0; i <= max; i++)
    {
        for(int j = 0; j <=step; j++)
        {
            DrawSprite(D3DXVECTOR3(v3SliderBar.x+j,v3SliderBar.y,0),texSliderFill);
        }
    }
}

remember my sprite is 1 pixel wide.


Ok, sorry if i wasnt clear enough. Let's say for example, I want the slider bar to be a min value of 0 and max value of 100. I want to draw 75% of the min/max which would be 75. My slider bar is 128 pixels wide, So i would need to draw 96 pixels for fill (fill is 1 pixel wide) to draw the slider at 75%. I am having trouble coding this though.

Example picture of slider: http://i.imgur.com/5oUv6tb.png
.........
Posted
Updated 5-Feb-13 11:29am
v4
Comments
Matthew Faithfull 5-Feb-13 4:25am    
Doesn't look like you're having much luck with a solution. I suspect because your code actually runs right? It just doesn't produce the output you want? The problem is no one here can see what it produces or know exactly what you want so I reckon you need to describe what's wrong with the output a little more. What do see vs what you would like to see. I notice you're not making any use of the fill parameter?
merano 5-Feb-13 18:17pm    
This member does only use the parameter max what about x and y ?

Not able to figure out why you think you need two for loops.

when you calculate the fillpos you can fill with 1 pixel wide sprite

with one for loop

fillpos = (fill * 128)/(max -min);

for(int i=0; i<fillpos; i++) ...
Member 8417954 5-Feb-13 20:20pm    
omg thank you so much! works perfectly!
Member 8417954 5-Feb-13 20:23pm    
please submit this as a solution so i can add to your rep, thanks again!
Member 8417954 5-Feb-13 9:55am    
Ok, sorry if i wasnt clear enough.
Let's say for example, I want the slider bar to be a min value of 0 and max value of 100. I want to draw 75% of the min/max which would be 75. My slider bar is 128 pixels wide, So i would need to draw 96 pixels for fill (fill is 1 pixel wide) to draw the slider at 75%. I am having trouble coding this though.

1 solution

The posted Function does only use the parameter max, what about x and y ?

Not able to figure out why you think you need two for loops.

when you calculate the fillpos you can fill with 1 pixel wide sprite

with one for loop

fillpos = (fill * 128)/(max -min);

for(int i=0; i<fillpos; i++) ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900