Horizontal Slider Problem

For general discussion related FlowStone
Post Reply
Wassaka
Posts: 85
Joined: Wed Dec 30, 2015 3:41 am

Horizontal Slider Problem

Post by Wassaka »

Hi! Well, I am making an horizontal Slider and, i have no idea how to code it :cry: . I will like to learn how to do this... Here is the code:

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 !!!!
User avatar
martinvicanek
Posts: 1334
Joined: Sat Jun 22, 2013 8:28 pm

Re: Horizontal Slider Problem

Post by martinvicanek »

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?
Wassaka
Posts: 85
Joined: Wed Dec 30, 2015 3:41 am

Re: Horizontal Slider Problem

Post by Wassaka »

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 :roll:
Post Reply