//#################################################################################################### // skanaarGUI : Graphical User Interface Components // one day this GUI will be released with a proper documentation //#################################################################################################### 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(){ } SkanaarGUI layer(String id){ return null; } void move(int tx, int ty){ this.x += tx; this.y += ty; } float getValue(String slid){ return 0f; } String getText(String textinput){ return null; } void showLayer(String id){ } void hideLayer(String id){ } void toggleLayer(String id){ } } //#################################################################################################### class SkanaarGUI extends GuiGizmo { color cSlidBar = #888888, cSlidStroke = #BBBBBB, cSlidBack = #444444; color cSlidBarHover = #BBBBBB, cSlidStrokeHover = #FFFFFF, cSlidBackHover = #444444; color cButtStroke = #BBBBBB, cButtFill = #444444, cButtText = #BBBBBB; color cButtStrokeHover = #FFFFFF, cButtFillHover = #444444, cButtTextHover = #FFFFFF; color cTextinputStroke = #BBBBBB, cTextinputFill = #888888, cTextinputText = #333333; color cTextinputStrokeHover = #FFFFFF, cTextinputFillHover = #888888, cTextinputTextHover = #000000; color cRectStroke = #FFFFFF, cRectFill = #666666; color cText = #FFFFFF; GuiGizmo[] gizmos; int buttonWidth=60, buttonHeight=15, sliderWidth=5, textinputHeight=13, textinputMargin=3; PFont font; boolean visible; //---------------------- SkanaarGUI(){ id = "gui_main"; gizmos = new GuiGizmo[0]; visible = true; } //---------------------- SkanaarGUI(String name){ id = name; gizmos = new GuiGizmo[0]; visible = true; } //---------------------- void setDesign(PFont font){ this.font = font; } //---------------------- void moveLayer(int x, int y){ for(int i=0;i=0;i--) gizmos[i].visualize(); } //---------------------- String mouseInput(int mx, int my){ String response = null; if(visible) 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 && myx-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 id) { if(this.id.equals(id)) return content; return null; } } //#####################################################################