
-----------------------------------
Raknarg
Sat Aug 04, 2012 5:33 pm

[Class] Sliders
-----------------------------------
To add to my collection of random GUI objects, I made a slider class. Lets go through the essentials:
proc initialize (x1_, y1_, x2_, y2_, borderc_, backc_, linec_, barc_, value_, minValue_, maxValue_ : int)

x1, y1, x2, y2: works like box coordinates. Make sure the 1's are smaller than the 2's. 

borderc, backc, linec, barc: The colours of the slider. Border colour, background colour, the line in the middle's colour, and the sliding bar colour.

value, minValue, maxValue: Min value and max value are the parameters for the slider. It goes in segments from minValue to maxValue, so if it's from 5 to 10, the bar will have six different possible positions and values, ranging from 5 to 10. Value keeps track of the slider bar.

Here's an example I made with this, a colour mixer (make sure this program and the unit are saved in the same file):



import "Slider.tu"

setscreen ("offscreenonly")

var r, g, b : real := 0
var font : int := Font.New ("Arial:10")
var SliderR, SliderG, SliderB : ^Slider
new Slider, SliderR
new Slider, SliderG
new Slider, SliderB

SliderR -> initialize (50, 50, 300, 80, black, 19, red, brightred, 0, 0, 100)
SliderG -> initialize (50, 90, 300, 120, black, 19, green, brightgreen, 0, 0, 100)
SliderB -> initialize (50, 130, 300, 160, black, 19, blue, brightblue, 0, 0, 100)
loop
    SliderR -> update
    SliderR -> draw
    SliderG -> update
    SliderG -> draw
    SliderB -> update
    SliderB -> draw
    r := SliderR -> value / 100
    g := SliderG -> value / 100
    b := SliderB -> value / 100
    Font.Draw (intstr (SliderR -> value) + "%", 303, 60, font, black)
    Font.Draw (intstr (SliderG -> value) + "%", 303, 100, font, black)
    Font.Draw (intstr (SliderB -> value) + "%", 303, 140, font, black)
    Draw.FillBox (0, maxy, 100, maxy - 100, RGB.AddColour (r, g, b))
    View.Update
    cls
end loop
[/b][/i]

-----------------------------------
Raknarg
Sat Aug 04, 2012 9:20 pm

RE:[Class] Sliders
-----------------------------------
also if anyone is actually interested, 2 things: I made it adjustable between horizontal and vertical if wanted. Also If anyone wants anything or has any ideas, I'm open to suggestions, I'm just compiling a bunch of gui widgets

-----------------------------------
Raknarg
Sat Aug 04, 2012 11:05 pm

Re: [Class] Sliders
-----------------------------------
Nevermind I'm updating anyways.
Also added reversability

-----------------------------------
Atma Weapon
Thu Sep 13, 2012 3:31 pm

RE:[Class] Sliders
-----------------------------------
I'm getting an error. "Unit symbol is button. Not 'Buttons' " ? What am I doing wrong?

-----------------------------------
QuantumPhysics
Thu Sep 13, 2012 7:04 pm

RE:[Class] Sliders
-----------------------------------
I like it.

-----------------------------------
evildaddy911
Sat Sep 15, 2012 10:15 am

RE:[Class] Sliders
-----------------------------------
i suggest using real values for the "maxvalue", "minValue" and "value" variables, other than that, pretty damn good!

-----------------------------------
Raknarg
Mon Sep 17, 2012 5:47 pm

RE:[Class] Sliders
-----------------------------------
@evildaddy personal preference :P You can easily change it yourself.

@Atma Weapon.. I don't really know. Did you try making your own program? Are you missing anything?
