//#################################################################################################### // skanaarGUI : Graphical User Interface Components //#################################################################################################### class GuiGizmo { String id; SkanaarGUI parent; int x,y,w,h,cb; //---------------------- boolean mouseIsInside(int mx, int my){ return (mx>=x-cb && mx<=x+w+cb && my>=y-cb && my<=y+h+cb) ; } String mouseInput(int mx, int my){ return null ; } String keyInput(char k){ return null ; } void mouseHover(int mx, int my){ } void mouseDrag(int mx, int my){ } void visualize(){ } float getValue(String slid){ return 0f; } String getText(String textinput){ return ""; } } //#################################################################################################### class SkanaarGUI extends GuiGizmo { color cSlidBar = #CCCCCC, cSlidStroke = #000000, cSlidBack = #666666; color cSlidBarHover = #FFFFFF, cSlidStrokeHover = #000000, cSlidBackHover = #888888; color cButtStroke = color(0), cButtFill = #555555, cButtText = color(220); color cButtStrokeHover = #000000, cButtFillHover = #777777, cButtTextHover = #FFFFFF; color cTextinputStroke = #000000, cTextinputFill = #888888, cTextinputText = #000000; color cTextinputStrokeHover = #000000, cTextinputFillHover = #AAAAAA, cTextinputTextHover = #444444; GuiGizmo[] gizmos; int buttonWidth=60, buttonHeight=15, sliderWidth=10, textinputHeight=13, textinputMargin=3; PFont font; //---------------------- SkanaarGUI(){ id = "gui_main"; gizmos = new GuiGizmo[0]; } //---------------------- SkanaarGUI(String name){ id = name; } //---------------------- void setDesign(PFont font){ this.font = font; } //---------------------- void addButton(String id, String caption, int x, int y){ GuiGizmo[] temp = new GuiGizmo[gizmos.length+1]; for(int i=0;i=x-cb && mx<=x+w+cb && my>=y-cb && my<=y+h+cb){ value = constrain( (mx-x)/(float)w , 0, 1) ; } return id; } //---------------------- void mouseDrag(int mx, int my) { mouseInput(mx,my); } //---------------------- float getValue(String a) { return value; } } //#################################################################################################### class SliderV extends GuiGizmo{ float value; //---------------------- SliderV(String id, SkanaarGUI parent, int x, int y, int h, float value) { this.id = id; this.parent = parent; this.x = x; this.y = y; this.w = parent.sliderWidth; this.h = h; this.value = value; cb = 2; } //---------------------- void visualize() { if(mouseIsInside(mouseX,mouseY)){ fill(parent.cSlidBackHover); stroke(parent.cSlidStrokeHover); rect(x,y,w,h); fill(parent.cSlidBarHover); rect(x,y,w*value,h ); } else { fill(parent.cSlidBack); stroke(parent.cSlidStroke); rect(x,y,w,h); fill(parent.cSlidBar); rect(x,y,w*value,h ); } } //---------------------- String mouseInput(int mx, int my) { if(mx>=x-cb && mx<=x+w+cb && my>=y-cb && my<=y+h+cb){ value = constrain( (h-my+y)/h , 0, 1) ; } return id; } //---------------------- void mouseDrag(int mx, int my) { mouseInput(mx,my); } //---------------------- float getValue(String a) { return value; } } //#################################################################################################### class Button extends GuiGizmo{ String caption; //---------------------- Button(String id, SkanaarGUI parent, int x, int y, String caption) { this.id = id; this.parent = parent; this.x = x; this.y = y; this.w = parent.buttonWidth; this.h = parent.buttonHeight; this.caption = caption; } //---------------------- void visualize() { if(mouseIsInside(mouseX,mouseY)){ fill(parent.cButtFillHover); stroke(parent.cButtStrokeHover); rect(x,y,w,h); fill(parent.cButtTextHover); textFont(parent.font); textAlign(CENTER); text(caption,x+w/2,y+h/2+4); } else { fill(parent.cButtFill); stroke(parent.cButtStroke); rect(x,y,w,h); fill(parent.cButtText); textFont(parent.font); textAlign(CENTER); text(caption,x+w/2,y+h/2+4); } } //---------------------- String mouseInput(int mx, int my) { if(mx>x-cb && mxy && my0){ content = content.substring(0,content.length()-1); } break; case 13: // Avoid special keys case 10: case 65535: case 127: case 27: break; default: if(textWidth(content+k)>w-margin) return null; content=content+k; break; } return null; } //---------------------- String getText(String a) { return content; } } //#####################################################################