Archived Legacy DynamicHUD
  • Dynamic HUD
  • Import using Gradle
  • Widgets
    • Adding Widgets
      • TextWidget
      • ItemWidget
      • ArmorWidget
    • Creating your own Widget class
    • Widget class
    • WidgetManager
    • WidgetBox
  • Saving and Loading
    • Saving and Loading
    • Changing save file name and directory
  • Moveable Screen
    • AbstractMoveableScreen
    • Default Moveable Screen
    • Using the default Moveable Screen
    • Creating and using your own MoveableScreen class
  • ContextMenu
    • ContextMenu class
    • ContextMenuOptionsProvider interface
    • DoubleInputScreen
    • DataInputScreen
  • Slider Widget
    • Slider
  • SliderWidgetBuilder
  • ColorPicker
    • ColorGradientPicker
      • ColorPickerButton
      • GradientBox
      • GradientSlider
  • Helpers
    • ColorHelper
    • DrawHelper
    • TextureHelper
Powered by GitBook
On this page
  • GradientBox
  • Fields
  • Constructors
  • Methods
  1. ColorPicker
  2. ColorGradientPicker

GradientBox

This page talks about GradientBox

PreviousColorPickerButtonNextGradientSlider

GradientBox

The class provides functionality for creating and displaying gradient boxes in Minecraft Fabric.

Fields

  • size: The size of the gradient box.

  • selectedWidget: The widget that this gradient box is associated with.

  • x: The x position of the gradient box.

  • y: The y position of the gradient box.

  • hue: The hue of the gradient box.

  • saturation: The saturation of the gradient box.

  • value: The value of the gradient box.

  • isDragging: Whether the handle of the gradient box is currently being dragged.

Constructors

GradientBox(int x, int y, int size, Widget selectedWidget)

Constructs a GradientBox object with the given position, size, and selected widget.

Methods

tick()

Updates the alpha of the gradient box.

render(MatrixStack matrices)

Renders this gradient box on screen.

setPosition(int x, int y)

Sets the position of this gradient box.

onClick(double mouseX, double mouseY, int button)

Handles mouse clicks on this gradient box. This method sets the dragging state to true if the mouse is over the handle and the left mouse button was clicked. It also updates the saturation and value of the gradient box based on the mouse position if the mouse is over the gradient box.

isMouseOver(double mouseX, double mouseY)

Returns whether the mouse is currently over this gradient box.

onRelease(double mouseX, double mouseY, int button)

Handles mouse release events on this gradient box. This method stops dragging or scaling the handle.

onDrag(double mouseX, double mouseY, int button)

Handles mouse dragging on this gradient box. This method updates the saturation and value of the gradient box based on the mouse position if the handle is being dragged.

setHue(float hue)

Sets the hue of this gradient box.

setSaturation(float saturation)

Sets the saturation of this gradient box.

setValue(float value)

Sets the value of this gradient box.

getColor()

Returns the current color of this gradient box as an RGB integer.

// Create a new GradientBox
GradientBox box = new GradientBox(10, 10, 100);

// Render the GradientBox
box.render(matrices);

// Handle mouse input
if (box.onClick(mouseX, mouseY)) {
    // The mouse was clicked on the box
}
if (box.onDrag(mouseX, mouseY)) {
    // The mouse was dragged on the box
}
if (box.onRelease(mouseX, mouseY)) {
    // The mouse was released on the box
}

// Get and set values for the GradientBox
float hue = box.getHue();
float saturation = box.getSaturation();
float value = box.getValue();
box.setHue(hue);
box.setSaturation(saturation);
box.setValue(value);

In this example, we create a new GradientBox with a position of (10, 10) and a size of 100 pixels. We then render the GradientBox on screen using its render method. We also handle mouse input by calling its onClick, onDrag, and onRelease methods.

Finally, we get and set values for hue, saturation, and value using its getter and setter methods.

The GradientBox is already called and present in . But if you still want to add it yourself somewhere you can do it by:

GradientBox
ColorGradientPicker