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, int).
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcenterOn(double worldX, double worldY) Centers the view on a world position.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(int keyCode, int scanCode, int modifiers) booleanmouseClicked(double mouseX, double mouseY, int button, boolean doubleClick) doubleClickis tracked by the owning widget: the same button pressed again within 250 ms.booleanmouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) booleanmouseReleased(double mouseX, double mouseY, int button) booleanmouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) protected voidLay out children here.protected final voidrenderContents(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 voidrenderViewBackground(net.minecraft.client.gui.GuiGraphics graphics) Screen-space background under the world (clipped to the panel).protected voidrenderViewForeground(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 voidrenderWorld(net.minecraft.client.gui.GuiGraphics graphics, double mouseWorldX, double mouseWorldY, boolean mouseInView, float partialTick) Draws the world.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, int button) 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 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
-
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
-
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
protected void onResized()Description copied from class:PanelLay out children here. -
renderContents
protected final void renderContents(net.minecraft.client.gui.GuiGraphics 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:
renderContentsin classPanel
-
mouseClicked
public boolean mouseClicked(double mouseX, double mouseY, int button, boolean doubleClick) Description copied from class:PaneldoubleClickis tracked by the owning widget: the same button pressed again within 250 ms.- Overrides:
mouseClickedin classPanel
-
mouseDragged
public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) - Overrides:
mouseDraggedin classPanel
-
mouseReleased
public boolean mouseReleased(double mouseX, double mouseY, int button) - Overrides:
mouseReleasedin classPanel
-
mouseScrolled
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) - Overrides:
mouseScrolledin classPanel
-
keyPressed
public boolean keyPressed(int keyCode, int scanCode, int modifiers) - Overrides:
keyPressedin classPanel
-