Guest User

Untitled

a guest
Mar 28th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. package net.minecraft.client.gui;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.util.ResourceLocation;
  7. import org.lwjgl.opengl.GL11;
  8.  
  9. @SideOnly(Side.CLIENT)
  10. public class GuiButton extends Gui
  11. {
  12. protected static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png");
  13.  
  14. /** Button width in pixels */
  15. protected int width;
  16.  
  17. /** Button height in pixels */
  18. protected int height;
  19.  
  20. /** The x position of this control. */
  21. public int xPosition;
  22.  
  23. /** The y position of this control. */
  24. public int yPosition;
  25.  
  26. /** The string displayed on this control. */
  27. public String displayString;
  28.  
  29. /** ID for this control. */
  30. public int id;
  31.  
  32. /** True if this control is enabled, false to disable. */
  33. public boolean enabled;
  34.  
  35. /** Hides the button completely if false. */
  36. public boolean drawButton;
  37. protected boolean field_82253_i;
  38.  
  39. public GuiButton(int par1, int par2, int par3, String par4Str)
  40. {
  41. this(par1, par2, par3, 200, 20, par4Str);
  42. }
  43.  
  44. public GuiButton(int par1, int par2, int par3, int par4, int par5, String par6Str)
  45. {
  46. this.width = 200;
  47. this.height = 20;
  48. this.enabled = true;
  49. this.drawButton = true;
  50. this.id = par1;
  51. this.xPosition = par2;
  52. this.yPosition = par3;
  53. this.width = par4;
  54. this.height = par5;
  55. this.displayString = par6Str;
  56. }
  57.  
  58. /**
  59. * Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
  60. * this button.
  61. */
  62. protected int getHoverState(boolean par1)
  63. {
  64. byte b0 = 1;
  65.  
  66. if (!this.enabled)
  67. {
  68. b0 = 0;
  69. }
  70. else if (par1)
  71. {
  72. b0 = 2;
  73. }
  74.  
  75. return b0;
  76. }
  77.  
  78. /**
  79. * Draws this button to the screen.
  80. */
  81. public void drawButton(Minecraft par1Minecraft, int par2, int par3)
  82. {
  83. if (this.drawButton)
  84. {
  85. FontRenderer fontrenderer = par1Minecraft.fontRenderer;
  86. par1Minecraft.getTextureManager().bindTexture(buttonTextures);
  87. GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
  88. this.field_82253_i = par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
  89. int k = this.getHoverState(this.field_82253_i);
  90. this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
  91. this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
  92. this.mouseDragged(par1Minecraft, par2, par3);
  93. int l = 14737632;
  94.  
  95. if (!this.enabled)
  96. {
  97. l = -6250336;
  98. }
  99. else if (this.field_82253_i)
  100. {
  101. l = 16777120;
  102. }
  103.  
  104. this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, l);
  105. }
  106. }
  107.  
  108. /**
  109. * Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
  110. */
  111. protected void mouseDragged(Minecraft par1Minecraft, int par2, int par3) {}
  112.  
  113. /**
  114. * Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
  115. */
  116. public void mouseReleased(int par1, int par2) {}
  117.  
  118. /**
  119. * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
  120. * e).
  121. */
  122. public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3)
  123. {
  124. return this.enabled && this.drawButton && par2 >= this.xPosition && par3 >= this.yPosition && par2 < this.xPosition + this.width && par3 < this.yPosition + this.height;
  125. }
  126.  
  127. public boolean func_82252_a()
  128. {
  129. return this.field_82253_i;
  130. }
  131.  
  132. public void func_82251_b(int par1, int par2) {}
  133. }
Advertisement
Add Comment
Please, Sign In to add comment