Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++DirectX
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 4-Feb-13 17:18pm
Edited 5-Feb-13 11:29am
v4
Comments
Matthew Faithfull at 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 at 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 at 5-Feb-13 20:20pm
   
omg thank you so much! works perfectly!
Member 8417954 at 5-Feb-13 20:23pm
   
please submit this as a solution so i can add to your rep, thanks again!
Member 8417954 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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++) ...
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 457
1 OriginalGriff 380
2 Shai Vashdi 335
3 Peter Leow 171
4 Emre Ataseven 165
0 Sergey Alexandrovich Kryukov 8,944
1 OriginalGriff 5,280
2 Peter Leow 3,985
3 Maciej Los 3,535
4 Abhinav S 3,218


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid