/* * Daniel King * gtg351x * 901856535 * * CS 4496 Project 4 * Professor Jarek Rossignac */ /* Label user interface object. */ class Label { float x; float y; float z; color textColor; String label; /* Creates a new label. */ Label(float x, float y, float z, color sel, String l) { this.x = x; this.y = y; this.z = z; textColor = sel; label = l; } /* Draws the label. */ void drawLabel() { stroke(0); fill(textColor); textFont(font, 18); text(label, x, y, 0); } } /* Button user interface object. */ class Button { float h; float w; float x; float y; float z; boolean selected; color fillColor; color selectedColor; color highlightColor; String label; /* Creates a new button. */ Button(float w, float h, float x, float y, float z, boolean s, color col, color sel, color hi, String l) { this.h = h; this.w = w; this.x = x; this.y = y; this.z = z; selected = s; fillColor = col; selectedColor = sel; highlightColor = hi; label = l; } /* Draws the button. */ void drawButton() { stroke(0); if (selected) { fill(selectedColor); } else if (mouseOver()) { fill(highlightColor); } else { fill(fillColor); } rect(x, y, w, h); if (selected) { fill(fillColor); } else { fill(selectedColor); } textFont(font, 18); text(label, x + 5, y + h - 6, 0); } /* Handles mouse overs. */ boolean mouseOver() { mouse.setToMouse(); if (mouse.x > x && mouse.x < (x + w) && mouse.y > y && mouse.y < (y + h)) { return true; } return false; } } /* Scrollbar user interface object. */ class Scrollbar { float h; float w; float sh; float sw; float x; float y; float z; boolean selected; color fillColor; color selectedColor; color highlightColor; float percent; /* Creates a new scrollbar. */ Scrollbar(float w, float h, float sw, float x, float y, float z, float percent, color col, color sel, color hi) { this.h = h; this.w = w; this.x = x; this.y = y; this.z = z; this.sw = sw; fillColor = col; selectedColor = sel; highlightColor = hi; this.percent = percent; } /* Gets the slider's x-position. */ float sliderX() { return (x + percent * (w - sw)); } /* Returns the percentage of the slider along the bar. */ float percentage(float pos) { return (pos - x) / (w - sw); } /* Draws the scrollbar. */ void drawScrollbar() { drawBar(); drawSlider(); } /* Draws the bar. */ void drawBar() { stroke(0); fill(fillColor); rect(x, y, w, h); } /* Draws the slider. */ void drawSlider() { stroke(0); if (selected) { fill(selectedColor); } else if (mouseOver()) { fill(highlightColor); } else { fill(fillColor); } rect(sliderX(), y, sw, h); if (selected) { fill(fillColor); } else { fill(selectedColor); } textFont(font, 18); text("<>", sliderX() + 3, y + h - 5, 0); } /* Handles mouse overs. */ boolean mouseOver() { mouse.setToMouse(); if (mouse.x > sliderX() && mouse.x < (sliderX() + sw) && mouse.y > y && mouse.y < (y + h)) { return true; } return false; } /* Updates the slider according to the mouse position. */ float update() { mouse.setToMouse(); if (selected) { if (mouse.x > x + sw / 2 && mouse.x < x + w - sw / 2) { percent = percentage(mouse.x - sw / 2); } else if (mouse.x > x + sw / 2) { percent = 1.0; } else { percent = 0.0; } } return percent; } }