Widget.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * This file is licensed under the MIT License, part of Roughly Enough Items.
  3. * Copyright (c) 2018, 2019, 2020 shedaniel
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package me.shedaniel.rei.gui.widget;
  24. import me.shedaniel.math.api.Point;
  25. import net.minecraft.client.MinecraftClient;
  26. import net.minecraft.client.font.TextRenderer;
  27. import net.minecraft.client.gui.AbstractParentElement;
  28. import net.minecraft.client.gui.Drawable;
  29. /**
  30. * The base class for a screen widget
  31. *
  32. * @see WidgetWithBounds for a widget with bounds
  33. */
  34. public abstract class Widget extends AbstractParentElement implements Drawable {
  35. /**
  36. * The Minecraft Client instance
  37. */
  38. protected final MinecraftClient minecraft = MinecraftClient.getInstance();
  39. /**
  40. * The font for rendering text
  41. */
  42. protected final TextRenderer font = minecraft.textRenderer;
  43. public int getZ() {
  44. return this.getBlitOffset();
  45. }
  46. public void setZ(int z) {
  47. this.setBlitOffset(z);
  48. }
  49. public boolean containsMouse(double mouseX, double mouseY) {
  50. return false;
  51. }
  52. public final boolean containsMouse(int mouseX, int mouseY) {
  53. return containsMouse((double) mouseX, (double) mouseY);
  54. }
  55. public final boolean containsMouse(Point point) {
  56. return containsMouse(point.x, point.y);
  57. }
  58. @Override
  59. public final boolean isMouseOver(double double_1, double double_2) {
  60. return containsMouse(double_1, double_2);
  61. }
  62. }