123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|582|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Cobra -> Value clipping help

Sat, 20 Feb 2010, 09:50
HoboBen
I think I'm too sleepy, can't get this to work...

For a slider gui element, I want to clip the slider to certain values, e.g. every tenth of the bar.

This works:

offset = offset - (offset mod (width/(divisions-1)))

However, this always clamps to the lower value. I'd like to clamp to the nearest value, meaning sometimes I need to clamp upwards.

Any ideas?

-=-=-
blog | work | code | more code
Sat, 20 Feb 2010, 12:05
JL235
Something like...

is what I think would work.

Index refers to which of the sections the slider is located in, from 0 (inclusive) to divisions (exclusive).

So if the width is 100, and there are 5 divisions, then the increment is 20. The first position (at index 0) is 10 (20/2 + 0*20) whilst the last position (at index 4) is 90 (20/2 + 4*20).

Hope that helps!

Sat, 20 Feb 2010, 12:34
HoboBen
Thanks very much!

I managed to work on it and got this




Result!!!



-=-=-
blog | work | code | more code
Sat, 20 Feb 2010, 16:00
Sticky
HoboBen


Do you really need the else of the if-then-else there? Setting a value to itself is effectively a no-op.

-=-=-
last.fm
Sun, 21 Feb 2010, 00:33
Jayenkai
It was probably a leftover from a trial+error thing. I leave loads of those things all over the place!

-=-=-
''Load, Next List!''
Mon, 22 Feb 2010, 10:52
HoboBen
Oops, turns out it's "slider.sliOffset = slider.sliOffset - o3"... don't know how that disappeared!

-=-=-
blog | work | code | more code