需要一些帮助自定义滑块栏 [英] Need Some Help Custom Slider Bar

查看:75
本文介绍了需要一些帮助自定义滑块栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在尝试使用dx9在c ++中绘制自定义滑块。我有一个1像素宽的精灵用作进度条填充纹理,进度条的长度是128像素。



我调用函数就像:

DrawSlider(int x,int y,int max,int fill)

x = x location

y = y location

max =进度条实例的最大值

fill =要添加到条形以显示值的填充量。





我的数学失败了,但我相信我需要在这个函数中使用两个for循环:

1循环填充步骤和1循环将步骤添加到栏中。 />


尝试失败:

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



记住我的精灵是1像素宽。





好​​的,对不起,如果我不够清楚的话。比如说,我想滑块是最小值0和最大值100.我想绘制75%的最小值/最大值75.我的滑块是128像素宽,所以我需要绘制96像素的填充(填充是1像素宽)来绘制75%的滑块。我在编码时遇到了麻烦。



滑块的示例图片:http://i.imgur.com/5oUv6tb.png

.........


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
.........

推荐答案

发布的函数只使用参数max,x和y怎么样?



无法弄清楚为什么你认为你需要两个for循环。



计算你可以用1像素宽填充的填充物精灵



一个for循环



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


这篇关于需要一些帮助自定义滑块栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆