Make double-clicking a knob reset it to its default value
[SugarCubes.git] / _UIFramework.pde
1 /**
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
11 * Little UI framework in progress to handle mouse events, layout,
12 * redrawing, etc.
13 */
14
15 final color lightGreen = #669966;
16 final color lightBlue = #666699;
17 final color bgGray = #444444;
18 final color defaultTextColor = #999999;
19 final PFont defaultItemFont = createFont("Lucida Grande", 11);
20 final PFont defaultTitleFont = createFont("Myriad Pro", 10);
21
22 public abstract class UIObject {
23
24 protected final static int DOUBLE_CLICK_THRESHOLD = 300;
25
26 protected final List<UIObject> children = new ArrayList<UIObject>();
27
28 protected boolean needsRedraw = true;
29 protected boolean childNeedsRedraw = true;
30
31 protected float x=0, y=0, w=0, h=0;
32
33 public UIContainer parent = null;
34
35 protected boolean visible = true;
36
37 public UIObject() {}
38
39 public UIObject(float x, float y, float w, float h) {
40 this.x = x;
41 this.y = y;
42 this.w = w;
43 this.h = h;
44 }
45
46 public boolean isVisible() {
47 return visible;
48 }
49
50 public UIObject setVisible(boolean visible) {
51 if (visible != this.visible) {
52 this.visible = visible;
53 redraw();
54 }
55 return this;
56 }
57
58 public final UIObject setPosition(float x, float y) {
59 this.x = x;
60 this.y = y;
61 redraw();
62 return this;
63 }
64
65 public final UIObject setSize(float w, float h) {
66 this.w = w;
67 this.h = h;
68 redraw();
69 return this;
70 }
71
72 public final UIObject addToContainer(UIContainer c) {
73 c.children.add(this);
74 this.parent = c;
75 return this;
76 }
77
78 public final UIObject removeFromContainer(UIContainer c) {
79 c.children.remove(this);
80 this.parent = null;
81 return this;
82 }
83
84 public final UIObject redraw() {
85 _redraw();
86 UIObject p = this.parent;
87 while (p != null) {
88 p.childNeedsRedraw = true;
89 p = p.parent;
90 }
91 return this;
92 }
93
94 private final void _redraw() {
95 needsRedraw = true;
96 for (UIObject child : children) {
97 childNeedsRedraw = true;
98 child._redraw();
99 }
100 }
101
102 public final void draw(PGraphics pg) {
103 if (!visible) {
104 return;
105 }
106 if (needsRedraw) {
107 needsRedraw = false;
108 onDraw(pg);
109 }
110 if (childNeedsRedraw) {
111 childNeedsRedraw = false;
112 for (UIObject child : children) {
113 if (needsRedraw || child.needsRedraw || child.childNeedsRedraw) {
114 pg.pushMatrix();
115 pg.translate(child.x, child.y);
116 child.draw(pg);
117 pg.popMatrix();
118 }
119 }
120 }
121 }
122
123 public final boolean contains(float x, float y) {
124 return
125 (x >= this.x && x < (this.x + this.w)) &&
126 (y >= this.y && y < (this.y + this.h));
127 }
128
129 protected void onDraw(PGraphics pg) {}
130 protected void onMousePressed(float mx, float my) {}
131 protected void onMouseReleased(float mx, float my) {}
132 protected void onMouseDragged(float mx, float my, float dx, float dy) {}
133 protected void onMouseWheel(float mx, float my, float dx) {}
134 }
135
136 public class UIContainer extends UIObject {
137
138 private UIObject focusedChild = null;
139
140 public UIContainer() {}
141
142 public UIContainer(float x, float y, float w, float h) {
143 super(x, y, w, h);
144 }
145
146 public UIContainer(UIObject[] children) {
147 for (UIObject child : children) {
148 child.addToContainer(this);
149 }
150 }
151
152 protected void onMousePressed(float mx, float my) {
153 for (int i = children.size() - 1; i >= 0; --i) {
154 UIObject child = children.get(i);
155 if (child.contains(mx, my)) {
156 child.onMousePressed(mx - child.x, my - child.y);
157 focusedChild = child;
158 break;
159 }
160 }
161 }
162
163 protected void onMouseReleased(float mx, float my) {
164 if (focusedChild != null) {
165 focusedChild.onMouseReleased(mx - focusedChild.x, my - focusedChild.y);
166 }
167 focusedChild = null;
168 }
169
170 protected void onMouseDragged(float mx, float my, float dx, float dy) {
171 if (focusedChild != null) {
172 focusedChild.onMouseDragged(mx - focusedChild.x, my - focusedChild.y, dx, dy);
173 }
174 }
175
176 protected void onMouseWheel(float mx, float my, float delta) {
177 for (UIObject child : children) {
178 if (child.contains(mx, my)) {
179 child.onMouseWheel(mx - child.x, mx - child.y, delta);
180 }
181 }
182 }
183
184 }
185
186 public class UIContext extends UIContainer {
187
188 final public PGraphics pg;
189
190 UIContext(float x, float y, float w, float h) {
191 super(x, y, w, h);
192 pg = createGraphics((int)w, (int)h, JAVA2D);
193 pg.smooth();
194 }
195
196 public void draw() {
197 if (!visible) {
198 return;
199 }
200 if (needsRedraw || childNeedsRedraw) {
201 pg.beginDraw();
202 draw(pg);
203 pg.endDraw();
204 }
205 image(pg, x, y);
206 }
207
208 private float px, py;
209 private boolean dragging = false;
210
211 public boolean mousePressed(float mx, float my) {
212 if (!visible) {
213 return false;
214 }
215 if (contains(mx, my)) {
216 dragging = true;
217 px = mx;
218 py = my;
219 onMousePressed(mx - x, my - y);
220 return true;
221 }
222 return false;
223 }
224
225 public boolean mouseReleased(float mx, float my) {
226 if (!visible) {
227 return false;
228 }
229 dragging = false;
230 onMouseReleased(mx - x, my - y);
231 return true;
232 }
233
234 public boolean mouseDragged(float mx, float my) {
235 if (!visible) {
236 return false;
237 }
238 if (dragging) {
239 float dx = mx - px;
240 float dy = my - py;
241 onMouseDragged(mx - x, my - y, dx, dy);
242 px = mx;
243 py = my;
244 return true;
245 }
246 return false;
247 }
248
249 public boolean mouseWheel(float mx, float my, float delta) {
250 if (!visible) {
251 return false;
252 }
253 if (contains(mx, my)) {
254 onMouseWheel(mx - x, my - y, delta);
255 return true;
256 }
257 return false;
258 }
259 }
260
261 public class UIWindow extends UIContext {
262
263 protected final static int titleHeight = 24;
264
265 public UIWindow(String label, float x, float y, float w, float h) {
266 super(x, y, w, h);
267 new UILabel(6, 8, w-6, titleHeight-8) {
268 protected void onMouseDragged(float mx, float my, float dx, float dy) {
269 parent.x = constrain(parent.x + dx, 0, width - w);
270 parent.y = constrain(parent.y + dy, 0, height - h);
271 }
272 }.setLabel(label).setFont(defaultTitleFont).addToContainer(this);
273 }
274
275 protected void onDraw(PGraphics pg) {
276 pg.noStroke();
277 pg.fill(#444444);
278 pg.stroke(#292929);
279 pg.rect(0, 0, w-1, h-1);
280 }
281 }
282
283 public class UILabel extends UIObject {
284
285 private PFont font = defaultTitleFont;
286 private color fontColor = #CCCCCC;
287 private String label = "";
288
289 public UILabel(float x, float y, float w, float h) {
290 super(x, y, w, h);
291 }
292
293 protected void onDraw(PGraphics pg) {
294 pg.textAlign(LEFT, TOP);
295 pg.textFont(font);
296 pg.fill(fontColor);
297 pg.text(label, 0, 0);
298 }
299
300 public UILabel setFont(PFont font) {
301 this.font = font;
302 redraw();
303 return this;
304 }
305
306 public UILabel setFontColor(color fontColor) {
307 this.fontColor = fontColor;
308 redraw();
309 return this;
310 }
311
312 public UILabel setLabel(String label) {
313 this.label = label;
314 redraw();
315 return this;
316 }
317 }
318
319 public class UICheckbox extends UIButton {
320
321 private boolean firstDraw = true;
322
323 public UICheckbox(float x, float y, float w, float h) {
324 super(x, y, w, h);
325 setMomentary(false);
326 }
327
328 public void onDraw(PGraphics pg) {
329 pg.stroke(borderColor);
330 pg.fill(active ? activeColor : inactiveColor);
331 pg.rect(0, 0, h, h);
332 if (firstDraw) {
333 pg.fill(labelColor);
334 pg.textFont(defaultItemFont);
335 pg.textAlign(LEFT, CENTER);
336 pg.text(label, h + 4, h/2);
337 firstDraw = false;
338 }
339 }
340
341 }
342
343 public class UIButton extends UIObject {
344
345 protected boolean active = false;
346 protected boolean isMomentary = false;
347 protected color borderColor = #666666;
348 protected color inactiveColor = #222222;
349 protected color activeColor = #669966;
350 protected color labelColor = #999999;
351 protected String label = "";
352
353 public UIButton(float x, float y, float w, float h) {
354 super(x, y, w, h);
355 }
356
357 public UIButton setMomentary(boolean momentary) {
358 isMomentary = momentary;
359 return this;
360 }
361
362 protected void onDraw(PGraphics pg) {
363 pg.stroke(borderColor);
364 pg.fill(active ? activeColor : inactiveColor);
365 pg.rect(0, 0, w, h);
366 if (label != null && label.length() > 0) {
367 pg.fill(active ? #FFFFFF : labelColor);
368 pg.textFont(defaultItemFont);
369 pg.textAlign(CENTER);
370 pg.text(label, w/2, h-5);
371 }
372 }
373
374 protected void onMousePressed(float mx, float my) {
375 if (isMomentary) {
376 setActive(true);
377 } else {
378 setActive(!active);
379 }
380 }
381
382 protected void onMouseReleased(float mx, float my) {
383 if (isMomentary) {
384 setActive(false);
385 }
386 }
387
388 public boolean isActive() {
389 return active;
390 }
391
392 public UIButton setActive(boolean active) {
393 this.active = active;
394 onToggle(active);
395 redraw();
396 return this;
397 }
398
399 public UIButton toggle() {
400 return setActive(!active);
401 }
402
403 protected void onToggle(boolean active) {}
404
405 public UIButton setBorderColor(color borderColor) {
406 if (this.borderColor != borderColor) {
407 this.borderColor = borderColor;
408 redraw();
409 }
410 return this;
411 }
412
413 public UIButton setActiveColor(color activeColor) {
414 if (this.activeColor != activeColor) {
415 this.activeColor = activeColor;
416 if (active) {
417 redraw();
418 }
419 }
420 return this;
421 }
422
423 public UIButton setInactiveColor(color inactiveColor) {
424 if (this.inactiveColor != inactiveColor) {
425 this.inactiveColor = inactiveColor;
426 if (!active) {
427 redraw();
428 }
429 }
430 return this;
431 }
432
433 public UIButton setLabelColor(color labelColor) {
434 if (this.labelColor != labelColor) {
435 this.labelColor = labelColor;
436 redraw();
437 }
438 return this;
439 }
440
441 public UIButton setLabel(String label) {
442 if (!this.label.equals(label)) {
443 this.label = label;
444 redraw();
445 }
446 return this;
447 }
448
449 public void onMousePressed() {
450 setActive(!active);
451 }
452 }
453
454 public class UIToggleSet extends UIObject {
455
456 private String[] options;
457 private int[] boundaries;
458 private String value;
459
460 public UIToggleSet(float x, float y, float w, float h) {
461 super(x, y, w, h);
462 }
463
464 public UIToggleSet setOptions(String[] options) {
465 this.options = options;
466 boundaries = new int[options.length];
467 int totalLength = 0;
468 for (String s : options) {
469 totalLength += s.length();
470 }
471 int lengthSoFar = 0;
472 for (int i = 0; i < options.length; ++i) {
473 lengthSoFar += options[i].length();
474 boundaries[i] = (int) (lengthSoFar * w / totalLength);
475 }
476 value = options[0];
477 redraw();
478 return this;
479 }
480
481 public String getValue() {
482 return value;
483 }
484
485 public UIToggleSet setValue(String option) {
486 value = option;
487 onToggle(value);
488 redraw();
489 return this;
490 }
491
492 public void onDraw(PGraphics pg) {
493 pg.stroke(#666666);
494 pg.fill(#222222);
495 pg.rect(0, 0, w, h);
496 for (int b : boundaries) {
497 pg.line(b, 1, b, h-1);
498 }
499 pg.noStroke();
500 pg.textAlign(CENTER);
501 pg.textFont(defaultItemFont);
502 int leftBoundary = 0;
503
504 for (int i = 0; i < options.length; ++i) {
505 boolean isActive = options[i] == value;
506 if (isActive) {
507 pg.fill(lightGreen);
508 pg.rect(leftBoundary + 1, 1, boundaries[i] - leftBoundary - 1, h-1);
509 }
510 pg.fill(isActive ? #FFFFFF : #999999);
511 pg.text(options[i], (leftBoundary + boundaries[i]) / 2., h-6);
512 leftBoundary = boundaries[i];
513 }
514 }
515
516 public void onMousePressed(float mx, float my) {
517 for (int i = 0; i < boundaries.length; ++i) {
518 if (mx < boundaries[i]) {
519 setValue(options[i]);
520 break;
521 }
522 }
523 }
524
525 protected void onToggle(String option) {}
526
527 }
528
529
530 public abstract class UIParameterControl extends UIObject implements LXParameter.Listener {
531 protected LXParameter parameter = null;
532
533 protected UIParameterControl(float x, float y, float w, float h) {
534 super(x, y, w, h);
535 }
536
537 public void onParameterChanged(LXParameter parameter) {
538 redraw();
539 }
540
541 public UIParameterControl setParameter(LXParameter parameter) {
542 if (this.parameter != null) {
543 if (this.parameter instanceof LXListenableParameter) {
544 ((LXListenableParameter)this.parameter).removeListener(this);
545 }
546 }
547 this.parameter = parameter;
548 if (this.parameter != null) {
549 if (this.parameter instanceof LXListenableParameter) {
550 ((LXListenableParameter)this.parameter).addListener(this);
551 }
552 }
553 redraw();
554 return this;
555 }
556 }
557
558 public class UIParameterKnob extends UIParameterControl {
559 private int knobSize = 28;
560 private final float knobIndent = .4;
561 private final int knobLabelHeight = 14;
562
563 public UIParameterKnob(float x, float y) {
564 this(x, y, 0, 0);
565 setSize(knobSize, knobSize + knobLabelHeight);
566 }
567
568 public UIParameterKnob(float x, float y, float w, float h) {
569 super(x, y, w, h);
570 }
571
572 protected void onDraw(PGraphics pg) {
573 float knobValue = (parameter != null) ? parameter.getValuef() : 0;
574
575 pg.ellipseMode(CENTER);
576 pg.noStroke();
577
578 pg.fill(bgGray);
579 pg.rect(0, 0, knobSize, knobSize);
580
581 // Full outer dark ring
582 pg.fill(#222222);
583 pg.arc(knobSize/2, knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, HALF_PI + knobIndent + (TWO_PI-2*knobIndent));
584
585 // Light ring indicating value
586 pg.fill(lightGreen);
587 pg.arc(knobSize/2, knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, HALF_PI + knobIndent + knobValue*(TWO_PI-2*knobIndent));
588
589 // Center circle of knob
590 pg.fill(#333333);
591 pg.ellipse(knobSize/2, knobSize/2, knobSize/2, knobSize/2);
592
593 String knobLabel = (parameter != null) ? parameter.getLabel() : null;
594 if (knobLabel == null) {
595 knobLabel = "-";
596 } else if (knobLabel.length() > 4) {
597 knobLabel = knobLabel.substring(0, 4);
598 }
599 pg.fill(#000000);
600 pg.rect(0, knobSize + 2, knobSize, knobLabelHeight - 2);
601 pg.fill(#999999);
602 pg.textAlign(CENTER);
603 pg.textFont(defaultTitleFont);
604 pg.text(knobLabel, knobSize/2, knobSize + knobLabelHeight - 2);
605 }
606
607 private long lastMousePress = 0;
608 public void onMousePressed(float mx, float my) {
609 super.onMousePressed(mx, my);
610 long now = millis();
611 if (now - lastMousePress < DOUBLE_CLICK_THRESHOLD) {
612 parameter.reset();
613 lastMousePress = 0;
614 } else {
615 lastMousePress = now;
616 }
617 }
618
619 public void onMouseDragged(float mx, float my, float dx, float dy) {
620 if (parameter != null) {
621 float value = constrain(parameter.getValuef() - dy / 100., 0, 1);
622 parameter.setValue(value);
623 }
624 }
625 }
626
627 public class UIParameterSlider extends UIParameterControl {
628
629 private static final float handleWidth = 12;
630
631 UIParameterSlider(float x, float y, float w, float h) {
632 super(x, y, w, h);
633 }
634
635 protected void onDraw(PGraphics pg) {
636 pg.noStroke();
637 pg.fill(#333333);
638 pg.rect(0, 0, w, h);
639 pg.fill(#222222);
640 pg.rect(4, h/2-2, w-8, 4);
641 pg.fill(#666666);
642 pg.stroke(#222222);
643 pg.rect((int) (4 + parameter.getValuef() * (w-8-handleWidth)), 4, handleWidth, h-8);
644 }
645
646 private boolean editing = false;
647 private long lastClick = 0;
648 private float doubleClickMode = 0;
649 private float doubleClickX = 0;
650 protected void onMousePressed(float mx, float my) {
651 long now = millis();
652 float handleLeft = 4 + parameter.getValuef() * (w-8-handleWidth);
653 if (mx >= handleLeft && mx < handleLeft + handleWidth) {
654 editing = true;
655 } else {
656 if ((now - lastClick) < DOUBLE_CLICK_THRESHOLD && abs(mx - doubleClickX) < 3) {
657 parameter.setValue(doubleClickMode);
658 }
659 doubleClickX = mx;
660 if (mx < w*.25) {
661 doubleClickMode = 0;
662 } else if (mx > w*.75) {
663 doubleClickMode = 1;
664 } else {
665 doubleClickMode = 0.5;
666 }
667 }
668 lastClick = now;
669 }
670
671 protected void onMouseReleased(float mx, float my) {
672 editing = false;
673 }
674
675 protected void onMouseDragged(float mx, float my, float dx, float dy) {
676 if (editing) {
677 parameter.setValue(constrain((mx - handleWidth/2. - 4) / (w-8-handleWidth), 0, 1));
678 }
679 }
680 }
681
682 public class UIScrollList extends UIObject {
683
684 private List<ScrollItem> items = new ArrayList<ScrollItem>();
685
686 private PFont itemFont = defaultItemFont;
687 private int itemHeight = 20;
688 private color selectedColor = lightGreen;
689 private color pendingColor = lightBlue;
690 private int scrollOffset = 0;
691 private int numVisibleItems = 0;
692
693 private boolean hasScroll;
694 private float scrollYStart;
695 private float scrollYHeight;
696
697 public UIScrollList(float x, float y, float w, float h) {
698 super(x, y, w, h);
699 }
700
701 protected void onDraw(PGraphics pg) {
702 int yp = 0;
703 boolean even = true;
704 for (int i = 0; i < numVisibleItems; ++i) {
705 if (i + scrollOffset >= items.size()) {
706 break;
707 }
708 ScrollItem item = items.get(i + scrollOffset);
709 color itemColor;
710 color labelColor = #FFFFFF;
711 if (item.isSelected()) {
712 itemColor = selectedColor;
713 } else if (item.isPending()) {
714 itemColor = pendingColor;
715 } else {
716 labelColor = #000000;
717 itemColor = #707070;
718 }
719 float factor = even ? .92 : 1.08;
720 itemColor = lx.scaleBrightness(itemColor, factor);
721
722 pg.noStroke();
723 pg.fill(itemColor);
724 pg.rect(0, yp, w, itemHeight);
725 pg.fill(labelColor);
726 pg.textFont(itemFont);
727 pg.textAlign(LEFT, TOP);
728 pg.text(item.getLabel(), 6, yp+4);
729
730 yp += itemHeight;
731 even = !even;
732 }
733 if (hasScroll) {
734 pg.noStroke();
735 pg.fill(0x26ffffff);
736 pg.rect(w-12, 0, 12, h);
737 pg.fill(#333333);
738 pg.rect(w-12, scrollYStart, 12, scrollYHeight);
739 }
740
741 }
742
743 private boolean scrolling = false;
744 private ScrollItem pressedItem = null;
745
746 public void onMousePressed(float mx, float my) {
747 pressedItem = null;
748 if (hasScroll && mx >= w-12) {
749 if (my >= scrollYStart && my < (scrollYStart + scrollYHeight)) {
750 scrolling = true;
751 dAccum = 0;
752 }
753 } else {
754 int index = (int) my / itemHeight;
755 if (scrollOffset + index < items.size()) {
756 pressedItem = items.get(scrollOffset + index);
757 pressedItem.onMousePressed();
758 redraw();
759 }
760 }
761 }
762
763 public void onMouseReleased(float mx, float my) {
764 scrolling = false;
765 if (pressedItem != null) {
766 pressedItem.onMouseReleased();
767 redraw();
768 }
769 }
770
771 private float dAccum = 0;
772 public void onMouseDragged(float mx, float my, float dx, float dy) {
773 if (scrolling) {
774 dAccum += dy;
775 float scrollOne = h / items.size();
776 int offset = (int) (dAccum / scrollOne);
777 if (offset != 0) {
778 dAccum -= offset * scrollOne;
779 setScrollOffset(scrollOffset + offset);
780 }
781 }
782 }
783
784 private float wAccum = 0;
785 public void onMouseWheel(float mx, float my, float delta) {
786 wAccum += delta;
787 int offset = (int) (wAccum / 5);
788 if (offset != 0) {
789 wAccum -= offset * 5;
790 setScrollOffset(scrollOffset + offset);
791 }
792 }
793
794 public void setScrollOffset(int offset) {
795 scrollOffset = constrain(offset, 0, max(0, items.size() - numVisibleItems));
796 scrollYStart = round(scrollOffset * h / items.size());
797 scrollYHeight = round(numVisibleItems * h / items.size());
798 redraw();
799 }
800
801 public UIScrollList setItems(List<ScrollItem> items) {
802 this.items = items;
803 numVisibleItems = (int) (h / itemHeight);
804 hasScroll = items.size() > numVisibleItems;
805 setScrollOffset(0);
806 redraw();
807 return this;
808 }
809 }
810
811 public interface ScrollItem {
812 public boolean isSelected();
813 public boolean isPending();
814 public String getLabel();
815 public void onMousePressed();
816 public void onMouseReleased();
817 }
818
819 public abstract class AbstractScrollItem implements ScrollItem {
820 public boolean isPending() {
821 return false;
822 }
823 public void select() {}
824 public void onMousePressed() {}
825 public void onMouseReleased() {}
826 }
827
828 public class UIIntegerBox extends UIObject {
829
830 private int minValue = 0;
831 private int maxValue = MAX_INT;
832 private int value = 0;
833
834 UIIntegerBox(float x, float y, float w, float h) {
835 super(x, y, w, h);
836 }
837
838 public UIIntegerBox setRange(int minValue, int maxValue) {
839 this.minValue = minValue;
840 this.maxValue = maxValue;
841 setValue(constrain(value, minValue, maxValue));
842 return this;
843 }
844
845 protected void onDraw(PGraphics pg) {
846 pg.stroke(#666666);
847 pg.fill(#222222);
848 pg.rect(0, 0, w, h);
849 pg.textAlign(CENTER, CENTER);
850 pg.textFont(defaultItemFont);
851 pg.fill(#999999);
852 pg.text("" + value, w/2, h/2);
853 }
854
855 protected void onValueChange(int value) {}
856
857 float dAccum = 0;
858 protected void onMousePressed(float mx, float my) {
859 dAccum = 0;
860 }
861
862 protected void onMouseDragged(float mx, float my, float dx, float dy) {
863 dAccum -= dy;
864 int offset = (int) (dAccum / 5);
865 dAccum = dAccum - (offset * 5);
866 setValue(value + offset);
867 }
868
869 public int getValue() {
870 return value;
871 }
872
873 public UIIntegerBox setValue(int value) {
874 if (this.value != value) {
875 int range = (maxValue - minValue + 1);
876 while (value < minValue) {
877 value += range;
878 }
879 this.value = minValue + (value - minValue) % range;
880 this.onValueChange(this.value);
881 redraw();
882 }
883 return this;
884 }
885 }