If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
Horizontal Slider Problem
3 posts
• Page 1 of 1
Horizontal Slider Problem
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 !!!!
- Wassaka
- Posts: 85
- Joined: Wed Dec 30, 2015 3:41 am
Re: Horizontal Slider Problem
Hi Wassaka, the code appears to be for a rotating knob, not for a slider. There are both vertical and horizontal sliders already shipped with FS, so why don't you start from there?
-
martinvicanek - Posts: 1328
- Joined: Sat Jun 22, 2013 8:28 pm
Re: Horizontal Slider Problem
martinvicanek wrote:Hi Wassaka, the code appears to be for a rotating knob, not for a slider. There are both vertical and horizontal sliders already shipped with FS, so why don't you start from there?
OMG! I never saw the sliders, I am very very newbie, sorry
- Wassaka
- Posts: 85
- Joined: Wed Dec 30, 2015 3:41 am
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 62 guests