3 summary:: A view with a handle movable in two dimensions.
5 related:: Classes/TabletSlider2D, Classes/TabletView
9 A view that allows setting two numerical values represented by the horizontal and vertical position of a handle movable in two dimensions.
11 The values are always within the range between 0 and 1. Scaling the output and input values to your needs can easily be achieved by using a link::Classes/ControlSpec:: with its link::Classes/ControlSpec#-map#-map:: and link::Classes/ControlSpec#-unmap#-unmap:: methods.
13 The link::#-step:: variable determines the amount by which the values will change when the handle is controlled using the keyboard. By default, holding down the Shift, Ctrl, or Alt key will multiply this amount by 100, 10, or 0.1 respectively, though you can customize this by setting link::#-shift_scale::, link::#-ctrl_scale::, or link::#-alt_scale::.
15 Drag and drop gives and accepts a link::Classes/Point:: of which the two coordinates represent the two values of the Slider2D.
32 The value represented by the horizontal position of the handle. It will always be clipped to the range between 0 and 1.
38 The value represented by the vertical position of the handle. It will always be clipped to the range between 0 and 1.
44 Sets link::#-x:: and triggers the link::#-action::.
48 Sets link::#-y:: and triggers the link::#-action::.
51 Sets link::#-x:: and link::#-y:: to the two arguments.
54 Sets link::#-x:: and link::#-y:: to the two arguments, and triggers the link::#-action::.
57 Increments link::#-x:: by link::#-step:: multiplied by code::factor::.
60 Decrements link::#-x:: by link::#-step:: multiplied by code::factor::.
63 Increments link::#-y:: by link::#-step:: multiplied by code::factor::.
66 Decrements link::#-y:: by link::#-step:: multiplied by code::factor::.
71 SUBSECTION:: Appearance
74 The color of the handle.
81 SUBSECTION:: Interaction
84 The amount by which link::#-x:: or link::#-y:: will change when incremented or decremented, either by calling relevant methods, or when related keys are pressed.
90 The absolute amount by which link::#-x:: would change if the handle moved horizontally by one pixel.
96 The absolute amount by which link::#-y:: would change if the handle moved vertically by one pixel.
102 The factor by which link::#-step:: is multiplied when incrementing or decrementing the values by keyboard while the Shift key is pressed.
108 The factor by which link::#-step:: is multiplied when incrementing or decrementing the values by keyboard while the Ctrl key is pressed.
114 The factor by which link::#-step:: is multiplied when incrementing or decrementing the values by keyboard while the Alt key is pressed.
124 The action object evaluated whenever the user changes the position or size of the handle.
126 METHOD:: defaultKeyDownAction
128 Implements the default effects of key presses as follows:
131 ## strong::Key:: || strong::Effect::
132 ## r || x_(1.rand), y_(1.rand), and triggers action
133 ## n || x_(0), y_(0), and triggers action
134 ## x || x_(1), y_(1), and triggers action
135 ## c || x_(0.5), y_(0.5), and triggers action
136 ## up arrow || incrementY
137 ## down arrow || decrementY
138 ## right arrow || incrementX
139 ## left arrow || decrementX
144 SUBSECTION:: Drag and drop
146 METHOD:: defaultGetDrag
148 A Point of which the x and y coordinates are set to link::#-x:: and link::#-y::, respectively.
150 METHOD:: defaultCanReceiveDrag
152 True if the current drag data is a Point.
154 METHOD:: defaultReceiveDrag
155 Sets link::#-x:: and link::#-y:: to the two coordinates of the Point stored as the current drag data, respectively, and triggers the link::#-action::.
164 w = Window("Slider2D", Rect(100, 100, 140, 140));
165 t = Slider2D(w, Rect(20, 20, 80, 80))
166 .x_(0.5) // initial location of x
167 .y_(1) // initial location of y
169 [\sliderX, sl.x, \sliderY, sl.y].postln;
175 t.x_(0.25) // set the x loc
181 w = Window("Slider2D", Rect(100, 100, 500, 300));
182 w.view.decorator = FlowLayout(w.view.bounds);
183 t = Slider2D(w, Rect(20, 20, 280, 280))
184 .x_(0.5) // initial location of x
185 .y_(1) // initial location of y
186 .background_(Color.rand)
188 [\sliderX, sl.x, \sliderY, sl.y].postln;
192 n = CompositeView.new(w, 200@300);
193 n.decorator = FlowLayout(n.bounds);
195 v = { |i| DragBoth.new(n, Rect(0, i * 20, 200, 20)).background_(Color.rand).align_(\center) }.dup(5);
197 StaticText.new(n, 200@150).string_("hold down cmd and drag points from the slider to the drag slots, or reverse").stringColor_(Color.white);
207 a = {arg mod = 0.05, index = 0.05;
212 660 * mod, 3 * index, 0,
214 [out,Delay1.ar(out)];
217 w = Window("Slider2D", Rect(100,Window.screenBounds.height - 400, 300, 300));
218 w.view.decorator = FlowLayout(w.view.bounds);
219 t = Slider2D(w, Rect(0, 0,292, 292))
222 .background_(Color.rand)
223 .knobColor_(Color.rand)
225 a.set(\mod,sl.x,\index,sl.y);
228 CmdPeriod.doOnce({w.close});