Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.48 KB | None | 0 0
  1. package SixGen.SixUI.Components;
  2.  
  3. import SixGen.SixUI.SixAction;
  4. import SixGen.Utils.Utils.TextLocation;
  5. import java.awt.Color;
  6. import java.awt.Font;
  7. import java.awt.Graphics;
  8. import java.awt.image.BufferedImage;
  9. import java.util.LinkedList;
  10.  
  11. /**
  12.  * SixButton
  13.  * Extends :
  14.  *  SixComponent
  15.  * Abilities :
  16.  *  Button used in SixUI
  17.  *  inherts basic functions of buttons
  18. */
  19.  
  20. public class SixButton extends SixComponent{
  21.    
  22.     //VARIABLES
  23.    
  24.     // text that is rendered on the button
  25.     protected String text;
  26.     // color of the button background
  27.     protected Color backgroundColor;
  28.     // color of the text
  29.     protected Color foregroundColor;
  30.     // texture of the background
  31.     protected BufferedImage texture;
  32.     // font of the text
  33.     protected Font font;
  34.     // location of the text in the button *see TextLocation for more info
  35.     protected TextLocation textLocation;
  36.    
  37.     //CONSTRUCTORS
  38.    
  39.     public SixButton(SixAction buttonAction ,float x , float y , float width , float height) {
  40.         //@SixButton
  41.         super(x , y , width , height);
  42.         //@SixButton#constructorSetters
  43.         if(buttonAction!=null) {
  44.             actionList.add(buttonAction);
  45.         }
  46.         //@SixButton#defaultSetters
  47.         text = "";
  48.         backgroundColor = Color.green;
  49.         foregroundColor = Color.white;
  50.         texture = null;
  51.         font = null;
  52.         textLocation = TextLocation.center;
  53.     }
  54.    
  55.     public SixButton(SixAction buttonAction ,float x , float y , float width , float height , String text) {
  56.         //@SixButton
  57.         this(buttonAction , x , y , width , height);
  58.         this.text = text;
  59.     }
  60.    
  61.     public SixButton(SixAction buttonAction ,float x , float y , float width , float height , String text , Font font , TextLocation textLocation) {
  62.         //@SixButton
  63.         this(buttonAction , x , y , width , height);
  64.         this.text = text;
  65.         this.font = font;
  66.         this.textLocation = textLocation;
  67.     }
  68.    
  69.     public SixButton(   SixAction buttonAction ,float x , float y , float width ,
  70.                         float height ,Color backgroundColor , Color foregroundColor ,
  71.                         String text , Font font , TextLocation textLocation) {
  72.         //@SixButton
  73.         this(buttonAction , x , y , width , height);
  74.         this.backgroundColor = backgroundColor;
  75.         this.foregroundColor = foregroundColor;
  76.         this.text = text;
  77.         this.font = font;
  78.         this.textLocation = textLocation;
  79.     }
  80.     public SixButton(SixAction buttonAction ,float x , float y , float width , float height , String text, Color backgroundColor , Color foregroundColor) {
  81.         //@SixButton
  82.         this(buttonAction, x , y , width , height);
  83.         this.text = text;
  84.         this.backgroundColor = backgroundColor;
  85.         this.foregroundColor = foregroundColor;
  86.         this.textLocation = TextLocation.center;
  87.    
  88.     }
  89.     public SixButton(SixAction buttonAction,float x , float y ,BufferedImage texture) {
  90.         //@SixButton
  91.         this(buttonAction,x,y,texture.getWidth() , texture.getHeight());
  92.         this.texture = texture;
  93.     }
  94.    
  95.     public SixButton(SixAction buttonAction ,float x , float y , float width , float height , BufferedImage texture) {
  96.         //@SixButton
  97.         this(buttonAction, x , y , width , height);
  98.         this.texture = texture;
  99.     }
  100.    
  101.     //RENDER VOID
  102.    
  103.     @Override
  104.     public void acRender(Graphics g) {
  105.         if(texture!=null) {
  106.             g.drawImage(texture, (int)x, (int)y, (int)width, (int)height, null);
  107.         } else {
  108.             g.setColor(backgroundColor);
  109.             g.fillRect((int)x ,(int)y , (int)width ,(int)height);
  110.             g.setColor(foregroundColor);
  111.             if(font!=null) {
  112.             drawTextWithAlign(g, text, font , getBounds(), textLocation);
  113.             } else {
  114.                 drawTextWithAlign(g, text, g.getFont(), getBounds(), textLocation);
  115.             }
  116.         }
  117.     }
  118.    
  119.     //TICK VOID
  120.    
  121.     @Override
  122.     public void acTick() {
  123.        
  124.     }
  125.  
  126.     //GETTERS SETTERS
  127.    
  128.     public String getText() {
  129.         return text;
  130.     }
  131.  
  132.     public void setText(String text) {
  133.         this.text = text;
  134.     }
  135.  
  136.     public Color getBackgroundColor() {
  137.         return backgroundColor;
  138.     }
  139.  
  140.     public void setBackgroundColor(Color backgroundColor) {
  141.         this.backgroundColor = backgroundColor;
  142.     }
  143.  
  144.     public Color getForegroundColor() {
  145.         return foregroundColor;
  146.     }
  147.  
  148.     public void setForegroundColor(Color foregroundColor) {
  149.         this.foregroundColor = foregroundColor;
  150.     }
  151.  
  152.     public BufferedImage getTexture() {
  153.         return texture;
  154.     }
  155.  
  156.     public void setTexture(BufferedImage texture) {
  157.         this.texture = texture;
  158.     }
  159.  
  160.     public Font getFont() {
  161.         return font;
  162.     }
  163.  
  164.     public void setFont(Font font) {
  165.         this.font = font;
  166.     }
  167.  
  168.     public TextLocation getTextLocation() {
  169.         return textLocation;
  170.     }
  171.  
  172.     public void setTextLocation(TextLocation textLocation) {
  173.         this.textLocation = textLocation;
  174.     }
  175.  
  176.     public LinkedList<SixAction> getActionList() {
  177.         return actionList;
  178.     }
  179.  
  180.     public void setActionList(LinkedList<SixAction> actionList) {
  181.         this.actionList = actionList;
  182.     }
  183.  
  184.     public boolean isVisible() {
  185.         return visible;
  186.     }
  187.  
  188.     public void setVisible(boolean visible) {
  189.         this.visible = visible;
  190.     }
  191.    
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement