X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=_UIFramework.pde;h=f4a0a40796fe4a3a42e5360985eb032ab76ca282;hb=6b163a98976a5f2adf9da1b7bd3297e39d6dd7bf;hp=3ca493b1658d365258104bc62381f826a35d8042;hpb=34327c962351112e07c3d93f56ffc543fac45b58;p=SugarCubes.git diff --git a/_UIFramework.pde b/_UIFramework.pde index 3ca493b..f4a0a40 100644 --- a/_UIFramework.pde +++ b/_UIFramework.pde @@ -314,15 +314,39 @@ public class UILabel extends UIObject { } } +public class UICheckbox extends UIButton { + + private boolean firstDraw = true; + + public UICheckbox(float x, float y, float w, float h) { + super(x, y, w, h); + setMomentary(false); + } + + public void onDraw(PGraphics pg) { + pg.stroke(borderColor); + pg.fill(active ? activeColor : inactiveColor); + pg.rect(0, 0, h, h); + if (firstDraw) { + pg.fill(labelColor); + pg.textFont(defaultItemFont); + pg.textAlign(LEFT, CENTER); + pg.text(label, h + 4, h/2); + firstDraw = false; + } + } + +} + public class UIButton extends UIObject { - private boolean active = false; - private boolean isMomentary = false; - private color borderColor = #666666; - private color inactiveColor = #222222; - private color activeColor = #669966; - private color labelColor = #999999; - private String label = ""; + protected boolean active = false; + protected boolean isMomentary = false; + protected color borderColor = #666666; + protected color inactiveColor = #222222; + protected color activeColor = #669966; + protected color labelColor = #999999; + protected String label = ""; public UIButton(float x, float y, float w, float h) { super(x, y, w, h); @@ -359,6 +383,10 @@ public class UIButton extends UIObject { } } + public boolean isActive() { + return active; + } + public UIButton setActive(boolean active) { this.active = active; onToggle(active); @@ -675,7 +703,7 @@ public class UIScrollList extends UIObject { itemColor = #707070; } float factor = even ? .92 : 1.08; - itemColor = color(hue(itemColor), saturation(itemColor), min(100, factor*brightness(itemColor))); + itemColor = lx.scaleBrightness(itemColor, factor); pg.noStroke(); pg.fill(itemColor); @@ -690,7 +718,7 @@ public class UIScrollList extends UIObject { } if (hasScroll) { pg.noStroke(); - pg.fill(color(0, 0, 100, 15)); + pg.fill(0x26ffffff); pg.rect(w-12, 0, 12, h); pg.fill(#333333); pg.rect(w-12, scrollYStart, 12, scrollYHeight); @@ -750,9 +778,9 @@ public class UIScrollList extends UIObject { } public void setScrollOffset(int offset) { - scrollOffset = constrain(offset, 0, items.size() - numVisibleItems); - scrollYStart = (int) (scrollOffset * h / items.size()); - scrollYHeight = (int) (numVisibleItems * h / (float) items.size()); + scrollOffset = constrain(offset, 0, max(0, items.size() - numVisibleItems)); + scrollYStart = round(scrollOffset * h / items.size()); + scrollYHeight = round(numVisibleItems * h / items.size()); redraw(); }