// IntScroller class IntScroller { private String name; private int value; private int minValue; private int maxValue; private int x; private int y; private int w = ScrollerWidth; private int h = ScrollerHeight; private int textColor = color(0); private int backgroundColor = color(200); private int selectColor = color(128); public IntScroller(String name, int value, int minValue, int maxValue, int x, int y) { this.name = name; this.value = value; this.minValue = minValue; this.maxValue = maxValue; this.x = x; this.y = y; } public void draw() { noStroke(); if (isOver()) fill(selectColor); else fill(backgroundColor); rect(x, y, w, h); fill(textColor); text(" " + name + str(value), x, y, w, h); } public void keyPressed() { if ((key == CODED) && isOver()) { switch (keyCode) { case RIGHT: value++; break; case UP: value += 10; break; case LEFT: value--; break; case DOWN: value -= 10; break; } if (value < minValue) value = minValue; else if (value > maxValue) value = maxValue; } } private boolean isOver() { if ((mouseX >= x) && (mouseX < (x + w)) && (mouseY >= y) && (mouseY < (y + h))) return true; else return false; } public int getValue() { return value; } public void setName(String name) { this.name = name; } }