Zoom fix to 9patch plugin

This commit is contained in:
fgnm
2021-08-11 19:28:03 +02:00
parent 234e9e87be
commit 7a6a17fe35
7 changed files with 20 additions and 19 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -37,7 +37,7 @@ public class EditingZone extends Actor {
private int[] splits = new int[4];
public interface PatchChangeListener {
public void changed(int[] splits);
void changed(int[] splits);
}
private PatchChangeListener listener;
@@ -120,6 +120,12 @@ public class EditingZone extends Actor {
mouseOverSplit = splitCollision(x, y);
return false;
}
@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY) {
zoomBy(amountY);
return true;
}
});
}
@@ -153,14 +159,15 @@ public class EditingZone extends Actor {
public void draw (Batch batch, float parentAlpha) {
Rectangle scissors = new Rectangle();
Rectangle clipBounds = new Rectangle(getX(),getY(),getWidth(),getHeight());
batch.flush();
ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), clipBounds, scissors);
ScissorStack.pushScissors(scissors);
drawBg(batch, parentAlpha);
batch.draw(texture,
getX() + getWidth() / 2 - texture.getRegionWidth() / 2 + shift.x,
getY() + getHeight() / 2 - texture.getRegionHeight() / 2 + shift.y,
getX() + getWidth() / 2 - texture.getRegionWidth() / 2f + shift.x,
getY() + getHeight() / 2 - texture.getRegionHeight() / 2f + shift.y,
texture.getRegionWidth() / 2f,
texture.getRegionHeight() / 2f,
texture.getRegionWidth(), texture.getRegionHeight(),
@@ -213,8 +220,8 @@ public class EditingZone extends Actor {
splitPositions[0] = shift.x + getWidth() / 2f + (-texture.getRegionWidth() / 2f + splits[0]) * currZoom;
splitPositions[1] = shift.x + getWidth() / 2f + (texture.getRegionWidth() / 2f - splits[1]) * currZoom;
splitPositions[2] = shift.y + getHeight()/2f + (texture.getRegionHeight()/2 - splits[2])*currZoom;
splitPositions[3] = shift.y + getHeight() / 2f + (-texture.getRegionHeight() / 2 + splits[3]) * currZoom;
splitPositions[2] = shift.y + getHeight()/2f + (texture.getRegionHeight() / 2f - splits[2])*currZoom;
splitPositions[3] = shift.y + getHeight() / 2f + (-texture.getRegionHeight() / 2f + splits[3]) * currZoom;
if(mouseOverSplit == 0) shapeRenderer.setColor(overColor); else shapeRenderer.setColor(guideColor);
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.kotcrab.vis.ui.widget.VisLabel;
@@ -33,7 +32,7 @@ public class MainPanel extends H2DDialog {
private PreviewWidget previewWidget;
public MainPanel(IFacade facade) {
super("Nine Patch");
super("Nine Patch", false);
addCloseButton();
this.facade = facade;
@@ -53,6 +52,13 @@ public class MainPanel extends H2DDialog {
editingZone = new EditingZone();
editingZone.setTexture(texture);
editingTable.add(editingZone);
addListener(new InputListener() {
@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY) {
editingZone.zoomBy(amountY);
return true;
}
});
editingZone.setWidth(310);
editingZone.setHeight(310);
@@ -96,16 +102,6 @@ public class MainPanel extends H2DDialog {
initPreView();
}
public void setListeners(Stage stage) {
stage.addListener(new InputListener() {
@Override
public boolean scrolled(InputEvent event, float x, float y, float amountX, float amountY) {
editingZone.zoomBy(amountX);
return false;
}
});
}
public int[] getSplits() {
return editingZone.getSplits();
}
@@ -150,8 +150,6 @@ public class MainPanelMediator extends Mediator<MainPanel> {
TextureAtlas.AtlasRegion region = plugin.getAPI().getProjectTextureRegion(name);
validateNinePatchTextureRegion(region);
viewComponent.setTexture(region);
viewComponent.setListeners(plugin.getAPI().getUIStage());
}
private void validateNinePatchTextureRegion(TextureAtlas.AtlasRegion texture) {