Advertisement
Mouamle

processing Button object : )

Apr 15th, 2016
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.38 KB | None | 0 0
  1.  
  2. public class Button{
  3.   public int x, y, w, h;
  4.   public float rectFill;
  5.  
  6.   public float rectFillR, rectFillG, rectFillB;
  7.  
  8.   public int textSize;
  9.   public int textFillR, textFillG, textFillB;
  10.   public String text;
  11.  
  12.   private float swap;
  13.   private float[] swap2 = {0, 0, 0};
  14.  
  15.   private int checkThingy = 0;
  16.   private int checkThingy2 = 0;
  17.   private int type;
  18.  
  19.   public Button(){
  20.    
  21.   }
  22.  
  23.   public Button(int x, int y, int w, int h, float rectFill, int textFillR, int textFillG, int textFillB, String text, int textSize ){
  24.     this.x = x;
  25.     this.y = y;
  26.     this.w = w;
  27.     this.h = h;
  28.     this.rectFill = rectFill;
  29.     this.swap = rectFill;
  30.     this.textFillR = textFillR;
  31.     this.textFillG = textFillG;
  32.     this.textFillB = textFillB;
  33.     this.text = text;
  34.     this.textSize = textSize;
  35.     this.type = 1;
  36.   }
  37.  
  38.   public Button(int x, int y, int w, int h, float rectFillR, float rectFillG, float rectFillB, int textFillR, int textFillG, int textFillB, String text, int textSize ){
  39.     this.x = x;
  40.     this.y = y;
  41.     this.w = w;
  42.     this.h = h;
  43.     this.rectFill = rectFill;
  44.     this.swap = rectFill;
  45.     this.textFillR = textFillR;
  46.     this.textFillG = textFillG;
  47.     this.textFillB = textFillB;
  48.     this.text = text;
  49.     this.textSize = textSize;
  50.     this.rectFillR = rectFillR; swap2[0] = rectFillR;
  51.     this.rectFillG = rectFillG; swap2[1] = rectFillG;
  52.     this.rectFillB = rectFillB; swap2[2] = rectFillB;
  53.     this.type = 2;
  54.   }
  55.  
  56.   public void render(){
  57.     if( this.type == 1 ){
  58.       fill(rectFill);
  59.       rect(x, y, w, h);
  60.       textSize(32);
  61.       fill(textFillR, textFillG, textFillB);
  62.       text(text, x + x, y + 30);        
  63.     }else if ( this.type == 2 ) {
  64.       fill(rectFillR, rectFillG, rectFillB, 255);
  65.       rect(x, y, w, h);
  66.       textSize(32);
  67.       fill(textFillR, textFillG, textFillB);
  68.       text(text, x + x, y + 30);        
  69.     }
  70.   }
  71.  
  72.   public void render2(){
  73.     render();
  74.   }
  75.  
  76.   public void click(){
  77.     if ( this.type == 1 ){
  78.       this.rectFill = this.rectFill + 100;
  79.     }else if ( this.type == 2 ){
  80.       this.rectFillR = this.rectFillR + 100;
  81.       this.rectFillG = this.rectFillG + 100;
  82.       this.rectFillB = this.rectFillB + 100;
  83.     }
  84.   }
  85.  
  86.   public void highLight(float value){
  87.     if ( checkThingy == 0 ) {
  88.      swap = this.rectFill;
  89.      checkThingy = 1;
  90.     }
  91.     this.rectFill = value;
  92.   }
  93.  
  94.   public void deHighLight(){
  95.     this.rectFill = swap;
  96.   }
  97.  
  98.     public void highLight2(float r, float g, float b){
  99.     if ( checkThingy2 == 0 ) {
  100.      swap2[0] = this.rectFillR;
  101.      swap2[1] = this.rectFillG;
  102.      swap2[2] = this.rectFillB;
  103.      checkThingy2 = 1;
  104.     }
  105.     this.rectFillR = r;
  106.     this.rectFillG = g;
  107.     this.rectFillB = b;
  108.   }
  109.  
  110.   public void deHighLight2(){
  111.     this.rectFillR = swap2[0];
  112.     this.rectFillG = swap2[1];
  113.     this.rectFillB = swap2[2];
  114.   }
  115.  
  116.  
  117.  
  118.   public boolean isMosueInside(){
  119.     if ( mouseX > this.getX() && mouseX <= this.getW() + 10 && mouseY > this.getY()  && mouseY - this.getY() <= this.getH() + 10 ){
  120.     //println("Inside");
  121.     return true;
  122.     }
  123.     //println("not Inside");
  124.     return false;
  125.   }
  126.  
  127.   public void setX(int x){
  128.     this.x = x;
  129.   }
  130.  
  131.   public void setY(int y){
  132.     this.y = y;
  133.   }  
  134.  
  135.   public void setW(int w){
  136.     this.w = w;
  137.   }  
  138.  
  139.   public void setH(int h){
  140.     this.h = h;
  141.   }  
  142.  
  143.   public void setText(String text){
  144.     this.text = text;
  145.   }
  146.  
  147.   public void setTextSize(int size){
  148.     this.textSize = size;
  149.   }
  150.  
  151.   public void setRectFill(float rectFill){
  152.     this.rectFill = rectFill;
  153.   }
  154.  
  155.   public void setTextFill(int textFillR, int textFillG, int textFillB){
  156.     this.textFillR = textFillR;
  157.     this.textFillG = textFillG;
  158.     this.textFillB = textFillB;
  159.   }
  160.  
  161.   public int getX(){
  162.     return this.x;
  163.   }
  164.  
  165.   public int getY(){
  166.     return this.y;
  167.   }
  168.  
  169.   public int getW(){
  170.     return this.w;
  171.   }  
  172.  
  173.   public int getH(){
  174.     return this.h;
  175.   }
  176.  
  177.   public String getText(){
  178.     return this.text;
  179.   }
  180.  
  181.   public float getRectFill(){
  182.     return this.rectFill;
  183.   }  
  184.  
  185.   public float getRectFillR(){
  186.     return this.rectFillR;
  187.   }  
  188.   public float getRectFillG(){
  189.     return this.rectFillG;
  190.   }  
  191.   public float getRectFillB(){
  192.     return this.rectFillB;
  193.   }
  194.  
  195.   public int getTextSize(){
  196.     return this.textSize;
  197.   }
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement