//################################################## class SliderV{ int x,y,w,h,cb; // cb is the clickBorder float maxVal, minVal, value; color colorBorder, colorFill, colorBar; //------------------------------------------------ SliderV(int x, int y, int w, int h, float minVal, float maxVal, float value) { this.x = x; this.y = y; this.w = w; this.h = h; this.maxVal = maxVal; this.minVal = minVal; this.value = value; this.colorBorder = color(0); this.colorFill = color(255,128); this.colorBar = color(128); cb = 3; } //------------------------------------------------ void setColors(color colorBorder, color colorFill, color colorBar) { this.colorBorder = colorBorder; this.colorFill = colorFill; this.colorBar = colorBar; } //------------------------------------------------ void visualize() { fill(colorFill); stroke(colorBorder); rect(x,y,w,h); fill(colorBar); rect(x,y+h-h*(value-minVal)/(maxVal-minVal),w,h*(value-minVal)/(maxVal-minVal) ); } //------------------------------------------------ float mouseInput(int mX, int mY) { if(mX>=x-cb && mX<=x+w+cb && mY>=y-cb && mY<=y+h+cb) value = constrain( minVal + (maxVal-minVal)*(h-mY+y)/h , minVal, maxVal) ; return value; } //------------------------------------------------ } //################################################## class SliderH{ int x,y,w,h,cb; // cb is the clickBorder float maxVal, minVal, value; color colorBorder, colorFill, colorBar; //------------------------------------------------ SliderH(int x, int y, int w, int h, float minVal, float maxVal, float value) { this.x = x; this.y = y; this.w = w; this.h = h; this.maxVal = maxVal; this.minVal = minVal; this.value = value; this.colorBorder = color(0); this.colorFill = color(255,128); this.colorBar = color(128); cb = 3; } //------------------------------------------------ void setColors(color colorBorder, color colorFill, color colorBar) { this.colorBorder = colorBorder; this.colorFill = colorFill; this.colorBar = colorBar; } //------------------------------------------------ void visualize() { fill(colorFill); stroke(colorBorder); rect(x,y,w,h); fill(colorBar); rect(x,y,w*(value-minVal)/(maxVal-minVal),h ); } //------------------------------------------------ float mouseInput(int mX, int mY) { if(mX>=x-cb && mX<=x+w+cb && mY>=y-cb && mY<=y+h+cb) value = constrain( minVal + (maxVal-minVal)*(mX-x)/w , minVal, maxVal) ; return value; } //------------------------------------------------ } //################################################## class Button{ int x,y,w,h,cb; // cb is the clickBorder int state, stateCount; color[] colorBorder, colorFill, colorText; PFont font; String[] caption; PImage[] icon; //------------------------------------------------ Button(int x, int y, int w, int h, PFont font, String caption) { this.x = x; this.y = y; this.w = w; this.h = h; this.state = 0; this.stateCount = 0; this.font = font; this.caption = new String[] { caption }; this.icon = new PImage[] { null }; this.colorBorder = new color[] { color(0) }; this.colorFill = new color[] { color(255,128) }; this.colorText = new color[] { color(128) }; cb = 3; } //------------------------------------------------ void setColors(color colorBorder, color colorFill, color colorText) { this.colorBorder[0] = colorBorder; this.colorFill[0] = colorFill; this.colorText[0] = colorText; } //------------------------------------------------ void setParameters(PFont font, String[] caption, PImage[] icon, color[] colorBorder, color[] colorFill, color[] colorText, int stateCount) { this.colorBorder = colorBorder; this.colorFill = colorFill; this.colorText = colorText; this.font = font; this.caption = caption; this.stateCount = stateCount; this.icon = icon; } //------------------------------------------------ void setStateCount(int stateCount) { this.stateCount = stateCount; this.colorBorder = new color[stateCount]; this.colorFill = new color[stateCount]; this.colorText = new color[stateCount]; this.font = font; this.caption = new String[stateCount]; this.icon = new PImage[stateCount]; } //------------------------------------------------ void makeState(int state, String caption, PImage icon, color colorBorder, color colorFill, color colorText) { this.colorBorder[state] = colorBorder; this.colorFill[state] = colorFill; this.colorText[state] = colorText; this.caption[state] = caption; this.icon[state] = icon; } //------------------------------------------------ void visualize() { fill(colorFill[state]); stroke(colorBorder[state]); rect(x,y,w,h); fill(colorText[state]); textFont(font); textAlign(CENTER); if(icon[state]==null){ text(caption[state],x+w/2,y+h/2+5); } else { image(icon[state],x+w/2-textWidth(caption[state])/2-icon[state].width/2,y+h/2-icon[state].height/2); text(caption[state],x+w/2+textWidth(caption[state])/2,y+h/2+5); } } //------------------------------------------------ boolean mouseInput(int mX, int mY) { boolean respond = (mX>x-cb && mXy && mY0) state = (state+1)%stateCount; return respond; } //------------------------------------------------ void setState(int state) { this.state = state; } //------------------------------------------------ int getState() { return state; } //------------------------------------------------ PImage makeAlpha(PImage icon, color transparent){ loadPixels(); for (int i=0; i < icon.pixels.length; i++) { if( icon.pixels[i] == transparent ) icon.pixels[i] = color(255,255,255,0); } updatePixels(); return icon; } //------------------------------------------------ } //#####################################################################