Horizontal Slider Problem
Posted: Sat Mar 05, 2016 11:57 pm
Hi! Well, I am making an horizontal Slider and, i have no idea how to code it
. I will like to learn how to do this... Here is the code:
Thanks !!!!
Code: Select all
def init
@startAngle = 0
@sweepAngle = 360
if @value == nil then @value = 0.0 end
end
# DRAWING (scroll down for interaction)
def draw v
# Work out how many cells we have
x = (@cells.widthPixels / @cellSize).to_i
y = (@cells.heightPixels / @cellSize).to_i
cellCount = [x,y].max
# We only allow vertical or horizontal strips
x = x > y ? 1:0
y = y > x ? 1:0
# Calculate the angle based on the 0-1 current value
angle = @value*@sweepAngle + @startAngle
while angle < 0 do angle += 360 end
while angle > 360 do angle -= 360 end
# Work out the current cell and its source rect in the bitmap
cell = (angle/360.0 * (cellCount-1) + 0.5).to_i
srcRect = [x*cell*@cellSize,y*cell*@cellSize,@cellSize,@cellSize]
# Draw the cell
sf = 1.0
@sizeInSqrs = @cellSize/v.defaultGridStep * sf
v.drawBitmapSection @cells,srcRect,[0,0,@sizeInSqrs,@sizeInSqrs]
end
def rotatePoint p,x,y,a
# Angle to radians
a *= Math::PI / 180.0
px = p[0];
py = p[1];
# Rotate then transform to rotation point
p[0] = px*Math.cos(a)-py*Math.sin(a) + x
p[1] = px*Math.sin(a)+py*Math.cos(a) + y
return p
end
# INTERACTION
def isInMousePoint x,y
return x < @sizeInSqrs && y < @sizeInSqrs
end
def mouseLDown x,y
captureMouse
@downY = y
mouseMoveCaptured x,y
return 1
end
def mouseMoveCaptured x,y
sensitivity = ((isKeyPressed "SHIFT") ? 10:1) * @sensitivity
@value += (@downY-y)/sensitivity
@downY = y
@value = [[@value,1.0].min,0.0].max
output 0,@value
output 1,true
redraw
end
def mouseLUpCaptured x,y
releaseMouse
output 1,false
end
def event i,v
if i==2
@value = [0,v,1].sort[1]
output @value
end
redraw
end
def saveState
@value
end
def loadState v
@value=v
end
Thanks !!!!