1 <!-- Copyright 2004 - see COPYING for details [LGPL] -->
\r
5 Author: Charles Goodwin
\r
12 thisbox.interval; // user defined interval between steps
\r
13 thisbox.lowerlimit; // the lower limit of the value range
\r
14 thisbox.upperlimit; // the upper limit of the value range
\r
15 thisbox.step; // the current step (integer)
\r
16 thisbox.value; // the current value
\r
20 thisbox.th_track; // the track in which the slider runs
\r
21 thisbox.th_handle; // the slider handle
\r
23 // private variables
\r
25 var numsteps; // the number of steps
\r
27 // write trap adjust the step according to the mouse position
\r
28 action ++= function(v) {
\r
29 step = ibex.math.round(numsteps * (track[mousepos] - handle[dim] / 2) / (track[dim] - handle[dim]));
\r
32 var synclimits = function(v) {
\r
35 // we need all of the following to be set
\r
36 if (interval == null || lowerlimit == null || upperlimit == null) return;
\r
38 // interval should to be a factor of (upperlimit - lowerlimit)
\r
39 if ((upperlimit - lowerlimit) % interval)
\r
40 ibex.println("WARNING: limit difference is not divisible by interval");
\r
42 // work out the number of steps
\r
43 numsteps = (upperlimit - lowerlimit) / interval;
\r
46 interval ++= synclimits;
\r
47 lowerlimit ++= synclimits;
\r
48 upperlimit ++= synclimits;
\r
50 orient ++= function(v) {
\r
51 arguments.cascade(v);
\r
53 track[flip(mindim)] = handle[flip(dim)];
\r
56 step ++= function(v) {
\r
57 // make sure step has a valid value
\r
58 arguments.cascade((0 > v) ? 0 : (v > numsteps) ? numsteps : v);
\r
59 // adjust the handle position according to the step
\r
60 handle[pos] = step * (track[dim] - handle[dim]) / numsteps;
\r
63 // read trap to return value based on current step
\r
64 value ++= function() {
\r
65 return ibex.math.min(lowerlimit + step * interval, upperlimit);
\r
68 // write trap to set the step according to the given value
\r
69 value ++= function(v) {
\r
70 step = ibex.math.round((v - lowerlimit) / interval);
\r
75 handle ++= function(v) {
\r
76 // always absolute so we can be moved
\r
79 // make sure the widget always has the correct flip(dim)
\r
80 v.SizeChange ++= function(v) {
\r
81 track[flip(dim)] = handle[flip(dim)];
\r
85 KeyPressed ++= function(v) {
\r
86 if (v == "left" or v == "down") step -= 1;
\r
87 else if (v == "right" or v == "up") step += 1;
\r
90 Press1 ++= function(v) {
\r
91 // activate the slider handle
\r
92 var shift = surface.addEvent("_Move", thisbox, "Move");
\r
94 /* argh what to do? */
\r
95 if (root.Move == null) {
\r
97 root.Move = function() { action = true; }
\r
98 root.Release1 = function() { root._Move = null; root._Release1 = null; }
\r