Class ViewportPanel
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
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, MouseButtonEvent).
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcenterOn(double worldX, double worldY) Centers the view on a world position.protected final voidextractContents(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTick) Draws the panel's own contents; children are drawn on top afterwards.protected voidextractViewBackground(net.minecraft.client.gui.GuiGraphicsExtractor graphics) Screen-space background under the world (clipped to the panel).protected voidextractViewForeground(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTick) Screen-space overlay on top of the world (not clipped); for tooltips, labels...protected abstract voidextractWorld(net.minecraft.client.gui.GuiGraphicsExtractor graphics, double mouseWorldX, double mouseWorldY, boolean mouseInView, float partialTick) Draws the world.protected abstract net.minecraft.client.gui.navigation.ScreenRectangleThe area (in world coordinates) that holds content; the view can't be panned far away from it.doubledoubleThe lowest zoom allowed right now: the configured minimum, or less if that's what it takes to fit the whole content in the view.doublegetZoom()doubleZoom mapped onto [0, 1] logarithmically (so each step feels the same); handy for sliders.booleanbooleankeyPressed(net.minecraft.client.input.KeyEvent event) booleanmouseClicked(net.minecraft.client.input.MouseButtonEvent event, boolean doubleClick) booleanmouseDragged(net.minecraft.client.input.MouseButtonEvent event, double dragX, double dragY) booleanmouseReleased(net.minecraft.client.input.MouseButtonEvent event) booleanmouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) protected voidLay out children here.voidFits 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 intocolor(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 (strengthis the alpha at the very edge; 0 disables it).setZoomLimits(double min, double max) voidsetZoomProgress(double progress) setZoomStep(double step) Zoom factor applied per wheel notch.doubletoScreenX(double worldX) doubletoScreenY(double worldY) doubletoWorldX(double screenX) doubletoWorldY(double screenY) protected booleanworldClicked(double worldX, double worldY, net.minecraft.client.input.MouseButtonEvent event) A press released without dragging.voidzoomBy(double factor, double screenX, double screenY) voidzoomTo(double zoom, double screenX, double screenY, boolean animate) Zooms tozoom, keeping the world point under the given screen position fixed.Methods inherited from class Panel
addChild, attach, charTyped, children, extractRenderState, getBounds, getOwner, isModal, isMouseOver, isVisible, keyReleased, mouseMoved, onHidden, onShown, removeChild, setBounds, setModal, setVisible
-
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. -
extractWorld
protected abstract void extractWorld(net.minecraft.client.gui.GuiGraphicsExtractor 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, net.minecraft.client.input.MouseButtonEvent event) A press released without dragging. -
extractViewBackground
protected void extractViewBackground(net.minecraft.client.gui.GuiGraphicsExtractor graphics) Screen-space background under the world (clipped to the panel). -
extractViewForeground
protected void extractViewForeground(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTick) Screen-space overlay on top of the world (not clipped); for tooltips, labels... -
setZoomLimits
-
setZoomStep
Zoom factor applied per wheel notch. -
setVignette
A subtle dark vignette along every edge (strengthis the alpha at the very edge; 0 disables it). -
setEdgeFade
Fades the edges of the view intocolor(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.size0 disables it. -
setMargin
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 tozoom, 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
-
extractContents
protected final void extractContents(net.minecraft.client.gui.GuiGraphicsExtractor graphics, int mouseX, int mouseY, float partialTick) Description copied from class:PanelDraws the panel's own contents; children are drawn on top afterwards.- Specified by:
extractContentsin classPanel
-
mouseClicked
public boolean mouseClicked(net.minecraft.client.input.MouseButtonEvent event, boolean doubleClick) - Overrides:
mouseClickedin classPanel
-
mouseDragged
public boolean mouseDragged(net.minecraft.client.input.MouseButtonEvent event, double dragX, double dragY) - Overrides:
mouseDraggedin classPanel
-
mouseReleased
public boolean mouseReleased(net.minecraft.client.input.MouseButtonEvent event) - Overrides:
mouseReleasedin classPanel
-
mouseScrolled
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) - Overrides:
mouseScrolledin classPanel
-
keyPressed
public boolean keyPressed(net.minecraft.client.input.KeyEvent event) - Overrides:
keyPressedin classPanel
-