Control.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package me.shedaniel.gui.widget;
  2. import com.mojang.blaze3d.platform.GlStateManager;
  3. import me.shedaniel.api.TriBooleanProducer;
  4. import me.shedaniel.gui.Drawable;
  5. import net.minecraft.client.render.BufferBuilder;
  6. import net.minecraft.client.render.Tessellator;
  7. import net.minecraft.client.render.VertexFormats;
  8. import java.awt.*;
  9. import java.util.function.BiConsumer;
  10. import java.util.function.IntFunction;
  11. /**
  12. * Created by James on 7/29/2018.
  13. */
  14. public abstract class Control extends Drawable {
  15. private boolean enabled = true;
  16. public IntFunction<Boolean> onClick;
  17. public TriBooleanProducer onKeyDown;
  18. public BiConsumer<Character, Integer> charPressed;
  19. public Control(int x, int y, int width, int height) {
  20. super(x, y, width, height);
  21. }
  22. public Control(Rectangle rect) {
  23. super(rect);
  24. }
  25. public boolean isEnabled() {
  26. return enabled;
  27. }
  28. public void setEnabled(boolean enabled) {
  29. this.enabled = enabled;
  30. }
  31. public void move(int x, int y) {
  32. rect.x += x;
  33. rect.y += y;
  34. //rect.move(x+rect.x,rect.y+y);//Why the fuck?
  35. }
  36. protected static void drawRect(int p_drawRect_0_, int p_drawRect_1_, int p_drawRect_2_, int p_drawRect_3_, int p_drawRect_4_) {
  37. int lvt_5_3_;
  38. if (p_drawRect_0_ < p_drawRect_2_) {
  39. lvt_5_3_ = p_drawRect_0_;
  40. p_drawRect_0_ = p_drawRect_2_;
  41. p_drawRect_2_ = lvt_5_3_;
  42. }
  43. if (p_drawRect_1_ < p_drawRect_3_) {
  44. lvt_5_3_ = p_drawRect_1_;
  45. p_drawRect_1_ = p_drawRect_3_;
  46. p_drawRect_3_ = lvt_5_3_;
  47. }
  48. float lvt_5_3_1 = (float) (p_drawRect_4_ >> 24 & 255) / 255.0F;
  49. float lvt_6_1_ = (float) (p_drawRect_4_ >> 16 & 255) / 255.0F;
  50. float lvt_7_1_ = (float) (p_drawRect_4_ >> 8 & 255) / 255.0F;
  51. float lvt_8_1_ = (float) (p_drawRect_4_ & 255) / 255.0F;
  52. Tessellator lvt_9_1_ = Tessellator.getInstance();
  53. BufferBuilder lvt_10_1_ = lvt_9_1_.getBufferBuilder();
  54. GlStateManager.enableAlphaTest();
  55. GlStateManager.enableBlend();
  56. GlStateManager.disableTexture();
  57. GlStateManager.blendFuncSeparate(GlStateManager.SrcBlendFactor.SRC_ALPHA, GlStateManager.DstBlendFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcBlendFactor.ONE, GlStateManager.DstBlendFactor.ZERO);
  58. GlStateManager.color4f(lvt_6_1_, lvt_7_1_, lvt_8_1_, lvt_5_3_1);
  59. lvt_10_1_.begin(7, VertexFormats.POSITION);
  60. lvt_10_1_.vertex((double) p_drawRect_0_, (double) p_drawRect_3_, 0.0D).next();
  61. lvt_10_1_.vertex((double) p_drawRect_2_, (double) p_drawRect_3_, 0.0D).next();
  62. lvt_10_1_.vertex((double) p_drawRect_2_, (double) p_drawRect_1_, 0.0D).next();
  63. lvt_10_1_.vertex((double) p_drawRect_0_, (double) p_drawRect_1_, 0.0D).next();
  64. lvt_9_1_.draw();
  65. GlStateManager.enableTexture();
  66. GlStateManager.disableBlend();
  67. GlStateManager.disableAlphaTest();
  68. }
  69. protected void drawTexturedModalRect(int x, int y, int u, int v, int width, int height) {
  70. float lvt_7_1_ = 0.00390625F;
  71. float lvt_8_1_ = 0.00390625F;
  72. Tessellator lvt_9_1_ = Tessellator.getInstance();
  73. BufferBuilder lvt_10_1_ = lvt_9_1_.getBufferBuilder();
  74. lvt_10_1_.begin(7, VertexFormats.POSITION_UV);
  75. lvt_10_1_.vertex((double) (x + 0), (double) (y + height), (double) 200).texture((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).next();
  76. lvt_10_1_.vertex((double) (x + width), (double) (y + height), (double) 200).texture((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).next();
  77. lvt_10_1_.vertex((double) (x + width), (double) (y + 0), (double) 200).texture((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).next();
  78. lvt_10_1_.vertex((double) (x + 0), (double) (y + 0), (double) 200).texture((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).next();
  79. lvt_9_1_.draw();
  80. }
  81. protected void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, float zLevel) {
  82. float lvt_7_1_ = 0.00390625F;
  83. float lvt_8_1_ = 0.00390625F;
  84. Tessellator lvt_9_1_ = Tessellator.getInstance();
  85. BufferBuilder lvt_10_1_ = lvt_9_1_.getBufferBuilder();
  86. lvt_10_1_.begin(7, VertexFormats.POSITION_UV);
  87. lvt_10_1_.vertex((double) (x + 0), (double) (y + height), zLevel).texture((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).next();
  88. lvt_10_1_.vertex((double) (x + width), (double) (y + height), zLevel).texture((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + height) * 0.00390625F)).next();
  89. lvt_10_1_.vertex((double) (x + width), (double) (y + 0), zLevel).texture((double) ((float) (u + width) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).next();
  90. lvt_10_1_.vertex((double) (x + 0), (double) (y + 0), zLevel).texture((double) ((float) (u + 0) * 0.00390625F), (double) ((float) (v + 0) * 0.00390625F)).next();
  91. lvt_9_1_.draw();
  92. }
  93. public void tick() {
  94. }
  95. public void setOnClick(IntFunction<Boolean> onClick) {
  96. this.onClick = onClick;
  97. }
  98. }