1 <!-- Copyleft 2004 - see COPYING for details [LGPL] -->
5 Author: Charles Goodwin
18 // theme box variables
27 var movefun1 = function(v) { th_thumb.action = true; }
28 var movefun2 = function(v) { recall["track"] = th_track.mouse[pos]; }
32 // attempt to shift slave by given amount
33 shift ++= function(v) {
35 slave[0][pos] = ibex.math.min(0, ibex.math.max(slave[dim] - slave[0][dim], slave[0][pos] - v));
41 slave ++= function(v) {
42 v.SizeChange ++= slaveFunc;
43 v[0].PosChange ++= slaveFunc;
44 v[0].SizeChange ++= slaveFunc;
50 smart ++= function(v) { cascade = v; syncThumb(); }
52 th_back ++= function(v) { v.action ++= function(w) { shift = -1*amount; } }
53 th_next ++= function(v) { v.action ++= function(w) { shift = amount; } }
55 th_track ++= function(v) {
56 v.action ++= function(w) {
57 if (th_thumb[pos] > recall["track"]) shift = -1*page;
58 else if (recall["track"] > th_thumb[pos] + th_thumb[dim]) shift = page;
61 v.repeat ++= function(w) {
62 if (w) { Move ++= movefun2; movefun2(); }
63 else { Move --= movefun2; recall["track"] = null; }
66 v.SizeChange ++= function(w) { syncThumb(); }
69 th_thumb ++= function(v) {
70 v.action ++= function(w) {
71 th_thumb[pos] = ibex.math.max(0,
72 ibex.math.min(th_track[dim] - th_thumb[dim],
73 recall["thumb"] + (surface.mouse[pos] - recall["start"])));
77 v.Press1 ++= function(w) {
79 recall["start"] = surface.mouse[pos];
80 recall["thumb"] = th_thumb[pos];
81 surface.Move ++= movefun1;
82 surface.Release1 ++= function(w) {
84 surface.Move --= movefun1;
85 surface.Release1 --= callee;
92 thisbox.addListener = function(v) {
93 listeners[v] = [v, v[0]];
94 v.SizeChange ++= listenerFunc;
95 v[0].PosChange ++= listenerFunc;
96 v[0].SizeChange ++= listenerFunc;
100 thisbox.removeListener = function(v) {
101 if (listeners[v] != null) {
102 listeners[v][0].SizeChange --= listenerFunc;
103 listeners[v][1].PosChange --= listenerFunc;
104 listeners[v][1].SizeChange --= listenerFunc;
111 var syncAllListeners = function(v) {
113 for (key in listeners) {
114 if (v == listeners[key][0]) continue;
115 syncListener(listeners[key][0]);
120 var syncListener = function(v) {
121 percent = slave[0][pos] / (slave[dim] - slave[0][dim]);
122 if (v and v[0]) v[0][pos] = percent * (v[dim] - v[0][dim]);
125 var syncSlave = function() {
127 percent = th_thumb[pos] / (th_track[dim] - th_thumb[dim]);
128 slave[0][pos] = percent * (slave[dim] - slave[0][dim]);
132 var syncThumb = function() {
133 if (slave == null || slave[0] == null || slave[dim] >= slave[0][dim]) {
134 if (enabled) enabled = false;
135 th_thumb[dim] = th_track[dim];
139 if (!enabled) enabled = true;
140 th_thumb[dim] = ibex.math.min(th_track[dim], (slave[dim] / slave[0][dim]) * th_track[dim]);
141 percent = slave[0][pos] / (slave[dim] - slave[0][dim]);
142 th_thumb[pos] = ibex.math.max(0, (th_track[dim] - th_thumb[dim]) * percent);
146 // reusable functions
148 var listenerFunc = function(v) {
149 if (!motion and trapee.constrain) {
151 syncAllListeners(trapee);
157 var slaveFunc = function(v) {