Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

on screen parameter

edited August 2013 in General Posts: 147

hi,

is it possigble to make a parameter in the program itself?
and if it possible, does anyone have a code for me?

Comments

  • edited August 2013 Posts: 2,043

    @jessevanderheide, do you mean something like the integer slider, but on the screen and not the side window?

  • @JakAttak yes thats what i mean.

  • Posts: 2,043

    It's possible, but you'd have to write a class that does it.

  • @JakAttak ooh thats a bum :(

  • Posts: 391

    Check out Cider 7. I also saw another UI project around somewhere too, I forget what it's called though.

  • Posts: 2,043

    @slashin8r there is cider and there's one by I think Luatee.

  • Posts: 2,043

    @jessevanderheide, here is something I wrote that is essentially a copy of the integer slider:


    --# Main -- IntegerSlider -- Use this function to perform your initial setup function setup() slider = Slider("noodle", 1, 5, 1, WIDTH/2, HEIGHT/2, function() print(noodle) end) parameter.integer("noodle", 1, 5, 1, function() print(noodle) end) end -- This function gets called once every frame function draw() -- This sets a dark background color background(40, 40, 50) -- This sets the line thickness strokeWidth(5) -- Do your drawing here slider:draw() end function touched(touch) slider:touched(touch) end --# Slider Slider = class() function Slider:init(variable, min, max, init, x, y, callback) self.variable = variable self.x, self.y = x, y self.min, self.max = min, max self.prevValue, self.curValue = init, init self.callback = callback self.length = 250 self.sliderX = (self.x - self.length/2) + (self.length / (self.max - 1)) * (self.curValue - 1) end function Slider:draw() pushStyle() strokeWidth(2) stroke(127) line(self.x - self.length/2, self.y, self.x + self.length/2, self.y) strokeWidth(5) stroke(255) line(self.x - self.length/2, self.y, self.sliderX, self.y) strokeWidth(2) stroke(255) if self.touching then fill(255) else fill(0) end ellipse(self.sliderX, self.y, 20) fill(255, 151, 0, 255) local w,h = textSize(self.curValue) text(self.curValue, self.x + self.length/2 + 5 - w/2, self.y + 10 + h/2) local w,h = textSize(self.variable) text(self.variable, self.x - self.length/2 - 5 + w/2, self.y + 10 + h/2) popStyle() if self.touching then self.sliderX = math.max(math.min(CurrentTouch.x, self.x + self.length/2), self.x - self.length/2) self.curValue = math.floor((((self.sliderX - (self.x - self.length/2)) / self.length) * (self.max - 1) + 1) + 0.49) if self.callback ~= nil and self.curValue ~= self.prevValue then _G[self.variable] = self.curValue self.callback() self.prevValue = self.curValue end end end function Slider:touched(touch) if touch.x > self.sliderX - 10 and touch.x < self.sliderX + 10 and touch.y > self.y - 10 and touch.y < self.y + 10 then self.touching = true end if touch.state == ENDED then self.touching = false self.sliderX = (self.x - self.length/2) + (self.length / (self.max - 1)) * (self.curValue - 1) end end
  • @JakAttak Thanks! I will try it out!

  • IgnatzIgnatz Mod
    Posts: 5,396

    what? the mini dress? :))

  • edited September 22 Posts: 9

    Can I use this code? I will give credit! : D

Sign In or Register to comment.