java.lang.Object
net.ixdarklord.coolcatcanvas.api.client.gui.components.widgets.panel.Panel
net.ixdarklord.coolcatcanvas.api.client.gui.components.widgets.panel.ViewportPanel
All Implemented Interfaces:
net.minecraft.client.gui.components.Renderable

@Experimental public abstract class ViewportPanel extends Panel
A panel showing a 2D "world" that can be panned by dragging and zoomed with the mouse wheel (anchored at the cursor, smoothly animated). Subclasses draw in world coordinates and describe the extent of their content, which the view is kept within.

Controls: drag (any button) to pan, wheel to zoom, +/- to zoom, 0/Home to fit, arrow keys to pan. A press that isn't dragged counts as a click and goes to worldClicked(double, double, int).

  • Field Summary

    Fields inherited from class net.ixdarklord.coolcatcanvas.api.client.gui.components.widgets.panel.Panel

    font, minecraft
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    centerOn(double worldX, double worldY)
    Centers the view on a world position.
    protected abstract net.minecraft.client.gui.navigation.ScreenRectangle
    The area (in world coordinates) that holds content; the view can't be panned far away from it.
    double
     
    double
    The lowest zoom allowed right now: the configured minimum, or less if that's what it takes to fit the whole content in the view.
    double
     
    double
    Zoom mapped onto [0, 1] logarithmically (so each step feels the same); handy for sliders.
    boolean
     
    boolean
    keyPressed(int keyCode, int scanCode, int modifiers)
     
    boolean
    mouseClicked(double mouseX, double mouseY, int button)
     
    boolean
    mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY)
     
    boolean
    mouseReleased(double mouseX, double mouseY, int button)
     
    boolean
    mouseScrolled(double mouseX, double mouseY, double delta)
     
    protected void
    Lay out children here.
    protected final void
    renderContents(net.minecraft.client.gui.GuiGraphics graphics, int mouseX, int mouseY, float partialTick)
    Draws the panel's own contents; children are drawn on top afterwards.
    protected void
    renderViewBackground(net.minecraft.client.gui.GuiGraphics graphics)
    Screen-space background under the world (clipped to the panel).
    protected void
    renderViewForeground(net.minecraft.client.gui.GuiGraphics graphics, int mouseX, int mouseY, float partialTick)
    Screen-space overlay on top of the world (not clipped); for tooltips, labels...
    protected abstract void
    renderWorld(net.minecraft.client.gui.GuiGraphics graphics, double mouseWorldX, double mouseWorldY, boolean mouseInView, float partialTick)
    Draws the world.
    void
    Fits the whole content in the view (within the zoom limits) on the next frame.
    setEdgeFade(int size, IntSupplier color)
    Fades the edges of the view into color (the panel's background) wherever content continues past them, hinting that there's more to pan to.
    setMargin(int margin)
    Extra world space allowed around the content bounds.
    setVignette(int size, float strength)
    A subtle dark vignette along every edge (strength is the alpha at the very edge; 0 disables it).
    setZoomLimits(double min, double max)
     
    void
    setZoomProgress(double progress)
     
    setZoomStep(double step)
    Zoom factor applied per wheel notch.
    double
    toScreenX(double worldX)
     
    double
    toScreenY(double worldY)
     
    double
    toWorldX(double screenX)
     
    double
    toWorldY(double screenY)
     
    protected boolean
    worldClicked(double worldX, double worldY, int button)
    A press released without dragging.
    void
    zoomBy(double factor, double screenX, double screenY)
     
    void
    zoomTo(double zoom, double screenX, double screenY, boolean animate)
    Zooms to zoom, keeping the world point under the given screen position fixed.

    Methods inherited from class net.ixdarklord.coolcatcanvas.api.client.gui.components.widgets.panel.Panel

    addChild, attach, charTyped, children, getBounds, getOwner, isModal, isMouseOver, isVisible, keyReleased, mouseMoved, onHidden, onShown, removeChild, render, setBounds, setModal, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ViewportPanel

      public ViewportPanel()
  • Method Details

    • getContentBounds

      protected abstract net.minecraft.client.gui.navigation.ScreenRectangle getContentBounds()
      The area (in world coordinates) that holds content; the view can't be panned far away from it.
    • renderWorld

      protected abstract void renderWorld(net.minecraft.client.gui.GuiGraphics graphics, double mouseWorldX, double mouseWorldY, boolean mouseInView, float partialTick)
      Draws the world. The pose is already translated/scaled; draw at world coordinates.
      Parameters:
      mouseInView - false while panning or when the cursor is outside the panel, so hover effects can be skipped
    • worldClicked

      protected boolean worldClicked(double worldX, double worldY, int button)
      A press released without dragging.
    • renderViewBackground

      protected void renderViewBackground(net.minecraft.client.gui.GuiGraphics graphics)
      Screen-space background under the world (clipped to the panel).
    • renderViewForeground

      protected void renderViewForeground(net.minecraft.client.gui.GuiGraphics graphics, int mouseX, int mouseY, float partialTick)
      Screen-space overlay on top of the world (not clipped); for tooltips, labels...
    • setZoomLimits

      public ViewportPanel setZoomLimits(double min, double max)
    • setZoomStep

      public ViewportPanel setZoomStep(double step)
      Zoom factor applied per wheel notch.
    • setVignette

      public ViewportPanel setVignette(int size, float strength)
      A subtle dark vignette along every edge (strength is the alpha at the very edge; 0 disables it).
    • setEdgeFade

      public ViewportPanel setEdgeFade(int size, IntSupplier color)
      Fades the edges of the view into color (the panel's background) wherever content continues past them, hinting that there's more to pan to. Each fade shrinks into its side as the end of the content on that side comes into view, and slides back out when there's more again. size 0 disables it.
    • setMargin

      public ViewportPanel setMargin(int margin)
      Extra world space allowed around the content bounds.
    • getZoom

      public double getZoom()
    • getMinZoom

      public double getMinZoom()
      The lowest zoom allowed right now: the configured minimum, or less if that's what it takes to fit the whole content in the view.
    • getMaxZoom

      public double getMaxZoom()
    • getZoomProgress

      public double getZoomProgress()
      Zoom mapped onto [0, 1] logarithmically (so each step feels the same); handy for sliders.
    • setZoomProgress

      public void setZoomProgress(double progress)
    • zoomTo

      public void zoomTo(double zoom, double screenX, double screenY, boolean animate)
      Zooms to zoom, keeping the world point under the given screen position fixed.
    • zoomBy

      public void zoomBy(double factor, double screenX, double screenY)
    • centerOn

      public void centerOn(double worldX, double worldY)
      Centers the view on a world position.
    • requestFit

      public void requestFit()
      Fits the whole content in the view (within the zoom limits) on the next frame.
    • isPanning

      public boolean isPanning()
    • toWorldX

      public double toWorldX(double screenX)
    • toWorldY

      public double toWorldY(double screenY)
    • toScreenX

      public double toScreenX(double worldX)
    • toScreenY

      public double toScreenY(double worldY)
    • onResized

      protected void onResized()
      Description copied from class: Panel
      Lay out children here.
      Overrides:
      onResized in class Panel
    • renderContents

      protected final void renderContents(net.minecraft.client.gui.GuiGraphics graphics, int mouseX, int mouseY, float partialTick)
      Description copied from class: Panel
      Draws the panel's own contents; children are drawn on top afterwards.
      Specified by:
      renderContents in class Panel
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Overrides:
      mouseClicked in class Panel
    • mouseDragged

      public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY)
      Overrides:
      mouseDragged in class Panel
    • mouseReleased

      public boolean mouseReleased(double mouseX, double mouseY, int button)
      Overrides:
      mouseReleased in class Panel
    • mouseScrolled

      public boolean mouseScrolled(double mouseX, double mouseY, double delta)
      Overrides:
      mouseScrolled in class Panel
    • keyPressed

      public boolean keyPressed(int keyCode, int scanCode, int modifiers)
      Overrides:
      keyPressed in class Panel