Computer Science Canada

[Class] Sliders

Author:  Raknarg [ Sat Aug 04, 2012 5:33 pm ]
Post subject:  [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):

Turing:


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]

Author:  Raknarg [ Sat Aug 04, 2012 9:20 pm ]
Post subject:  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

Author:  Raknarg [ Sat Aug 04, 2012 11:05 pm ]
Post subject:  Re: [Class] Sliders

Nevermind I'm updating anyways.
Also added reversability

Author:  Atma Weapon [ Thu Sep 13, 2012 3:31 pm ]
Post subject:  RE:[Class] Sliders

I'm getting an error. "Unit symbol is button. Not 'Buttons' " ? What am I doing wrong?

Author:  QuantumPhysics [ Thu Sep 13, 2012 7:04 pm ]
Post subject:  RE:[Class] Sliders

I like it.

Author:  evildaddy911 [ Sat Sep 15, 2012 10:15 am ]
Post subject:  RE:[Class] Sliders

i suggest using real values for the "maxvalue", "minValue" and "value" variables, other than that, pretty damn good!

Author:  Raknarg [ Mon Sep 17, 2012 5:47 pm ]
Post subject:  RE:[Class] Sliders

@evildaddy personal preference Razz You can easily change it yourself.

@Atma Weapon.. I don't really know. Did you try making your own program? Are you missing anything?


: