done scaling

This commit is contained in:
2026-06-01 12:18:45 +03:00
parent 669d26f595
commit 538ba5f06b
7 changed files with 70 additions and 34 deletions

View File

@ -2,23 +2,23 @@
<objecttypes>
<objecttype color="#a0a0a4" name="misato">
<property default="Solid" name="class" type="string"/>
<property default="3 4 197 3 168 191 72 189 " name="drawbox" type="string"/>
<property default="Circle -19 11 40" name="hitbox" type="string"/>
<property default="0 1 197 0 187 167 74 190 " name="drawbox" type="string"/>
<property default="Circle -18 11 40" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="starlight">
<property default="Solid" name="class" type="string"/>
<property default="4 3 162 9 129 121 53 140 " name="drawbox" type="string"/>
<property default="Circle 14 3 28" name="hitbox" type="string"/>
<property default="Circle 7 -2 28" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="tavern">
<property default="Solid" name="class" type="string"/>
<property default="93 47 303 55 245 301 90 286 " name="drawbox" type="string"/>
<property default="Rectangle 4036 2332 271 201" name="hitbox" type="string"/>
<property default="130 39 3977 65 4121 2479 117 2459 " name="drawbox" type="string"/>
<property default="Rectangle -32 42 2018 1992" name="hitbox" type="string"/>
</objecttype>
<objecttype color="#a0a0a4" name="TopHome">
<property default="Solid" name="class" type="string"/>
<property default="3 2 252 1 253 605 6 608" name="drawbox" type="string"/>
<property default="Rectangle 2212 1964 183 31" name="hitbox" type="string"/>
<property default="4 14 1780 0 1785 2162 58 2182 " name="drawbox" type="string"/>
<property default="Rectangle -5 0 858 887" name="hitbox" type="string"/>
</objecttype>
<objecttype color="000000" name="newtest">
<property default="solid" name="class" type="string"/>

BIN
res/маг_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -1,9 +1,9 @@
package gui;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
@ -26,6 +26,7 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
ShapeRenderingFunction renderingFunction;
Entity entity;
BufferedImage image;
private float scaleIndex = 1;
public EditableCanvas() {
@ -83,17 +84,33 @@ public class EditableCanvas extends JPanel implements MouseListener, MouseMotion
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(image!=null) {
g.drawImage(image, 0, 0, this);
g.setColor(Color.darkGray);
g.drawRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.RED);
g.fillOval(image.getWidth()/2, image.getHeight(), 2, 2);
calculatedScaledIndex();
g.drawImage(image, 0, 0, (int) (image.getWidth() * scaleIndex),
(int) (image.getHeight() * scaleIndex), this);
g.setColor(Color.green);
}
if(entity != null) {
drawing((Graphics2D)g);
}
}
//нерабочая херня
public void calculatedScaledIndex() {
int imageWidth = image.getWidth(), imageHeight = image.getHeight();
float iconMaxWidth = this.getWidth();
float iconMaxHeight = this.getHeight();
float scaleFactorX = iconMaxWidth / imageWidth, scaleFactorY = iconMaxHeight / imageHeight;
scaleIndex = scaleFactorX < scaleFactorY ? scaleFactorX : scaleFactorY;
entity.setScaleIndex(scaleIndex);
System.out.println("imageWidth: "+imageWidth);
System.out.println("imageHeight: "+imageHeight);
System.out.println("iconMaxWidth: "+iconMaxWidth);
System.out.println("iconMaxHeight: "+iconMaxHeight);
System.out.println("scaleFactorX: "+scaleFactorX);
System.out.println("scaleFactorY: "+scaleFactorY);
System.out.println("scaleIndex: "+scaleIndex);
System.out.println("_____________________: ");
}
public void setEntity(Entity e) {
entity = e;

View File

@ -22,12 +22,15 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
private List<EntityDrawboxChangedListener> listeners = new ArrayList<>();
Entity entity;
Logger logger = Logger.getLogger("gui.DrawboxRectangleEditor");
private float scaleIndex = 1;
public DrawboxRectengleRenderingFunction() {
}
@Override
public void drawing(Graphics2D g) {
scaleIndex = entity.getScaleIndex();
Drawbox drawbox = entity.getDrawbox();
drawboxPoints = drawbox.getDrawboxlistPoints();
basePoints = drawbox.getbaseListPoints();
@ -39,13 +42,13 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
if(drawboxPoints.size() >= 1 && drawboxPoints.size() < 4) {
Point lastPoint = drawboxPoints.get(drawboxPoints.size()-1);
g.drawLine((int)lastPoint.x, (int)lastPoint.y, (int)currentPoint.x, (int)currentPoint.y);
g.drawLine((int)(lastPoint.x*scaleIndex), (int)(lastPoint.y*scaleIndex), (int)(currentPoint.x*scaleIndex), (int)(currentPoint.y*scaleIndex));
for(int i = 0; i < drawboxPoints.size()-1;i++) {
int x1 = (int)drawboxPoints.get(i).x;
int y1 = (int)drawboxPoints.get(i).y;
int x2 = (int)drawboxPoints.get(i+1).x;
int y2 = (int)drawboxPoints.get(i+1).y;
g.drawLine(x1, y1, x2, y2);
g.drawLine((int)(x1*scaleIndex), (int)(y1*scaleIndex), (int)(x2*scaleIndex), (int)(y2*scaleIndex));
}
} else {
for(int i = 0; i < drawboxPoints.size();i++) {
@ -53,7 +56,7 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
int y1 = (int)drawboxPoints.get(i % drawboxPoints.size()).y;
int x2 = (int)drawboxPoints.get((i+1) % drawboxPoints.size()).x;
int y2 = (int)drawboxPoints.get((i+1) % drawboxPoints.size()).y;
g.drawLine(x1, y1, x2, y2);
g.drawLine((int)(x1*scaleIndex), (int)(y1*scaleIndex), (int)(x2*scaleIndex), (int)(y2*scaleIndex));
}
// ОТРИСОВКА ОСНОВАНИЯ
g.setColor(Color.BLUE);
@ -62,7 +65,7 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
int y1 = (int)basePoints.get(i).y;
int x2 = (int)basePoints.get(i+1).x;
int y2 = (int)basePoints.get(i+1).y;
g.drawLine(x1, y1+3, x2, y2+3);
g.drawLine((int)(x1*scaleIndex), (int)(y1*scaleIndex), (int)(x2*scaleIndex), (int)(y2*scaleIndex));
}
}
@ -71,7 +74,7 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
@Override
public void mousePressed(MouseEvent e) {
if(drawboxPoints.size() < 4) {
Point p = new Point(e.getX(), e.getY());
Point p = new Point(currentPoint.x, currentPoint.y);
drawboxPoints.add(p);
if(drawboxPoints.size() == 4) {
sortingDrawboxPoints();
@ -88,8 +91,8 @@ public class DrawboxRectengleRenderingFunction implements ShapeRenderingFunction
@Override
public void mouseMoved(MouseEvent e) {
currentPoint.x = e.getX();
currentPoint.y = e.getY();
currentPoint.x = e.getX()/scaleIndex;
currentPoint.y = e.getY()/scaleIndex;
}
/*Точки должны идти в определенном порядке:

View File

@ -16,6 +16,7 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
Point currentIsoPoint = new Point(0,0);
int currentDiametrX=0;
Entity entity;
private float scaleIndex = 1;
private List<EntityHitboxChangedListener> listeners = new ArrayList<>();
public void setEntityInHitboxCircle(Entity e) {
@ -24,29 +25,34 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
@Override
public void drawing(Graphics2D g) {
scaleIndex = entity.getScaleIndex();
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
if(nowHitbox.getRadius()!=0) {
g.drawOval((int)nowHitbox.getCurrentRefPoint().x, (int)(nowHitbox.getCurrentRefPoint().y-(nowHitbox.getDiametrY()/2)), (int)nowHitbox.getDiametrX(), (int)(nowHitbox.getDiametrY()));
g.drawOval((int)(nowHitbox.getCurrentRefPoint().x*scaleIndex), (int)((nowHitbox.getCurrentRefPoint().y-(nowHitbox.getDiametrY()/2))*scaleIndex ), (int)(nowHitbox.getDiametrX()*scaleIndex ), (int)(nowHitbox.getDiametrY()*scaleIndex ));
// System.out.println("READY: diametrX = "+nowHitbox.getDiametrX()+ ". diametrY = "+nowHitbox.getDiametrY());
// System.out.println("READY: coordX = "+(int)nowHitbox.getCurrentRefPoint().x+ ". coordY = "+(int)(nowHitbox.getCurrentRefPoint().y-(nowHitbox.getDiametrY()/2)));
}else if(firstIsoPoint != null) {
currentDiametrX = Math.abs((int)firstIsoPoint.x-(int)currentIsoPoint.x);
currentDiametrX = Math.abs((int)(firstIsoPoint.x )-(int)(currentIsoPoint.x ));
// System.out.println("CURRENT: coordX = "+(int)firstIsoPoint.x+ ". coordX = "+(int)(firstIsoPoint.y-currentDiametrX/4));
// System.out.println("CURRENT: diametrX = "+currentDiametrX+ ". diametrY = "+currentDiametrX/2);
g.drawOval((int)firstIsoPoint.x, (int)(firstIsoPoint.y-currentDiametrX/4), (int)currentDiametrX, (int)currentDiametrX/2);
g.drawOval((int)(firstIsoPoint.x*scaleIndex), (int)((firstIsoPoint.y - currentDiametrX/4)*scaleIndex), (int)(currentDiametrX*scaleIndex ), (int)(currentDiametrX/2*scaleIndex ));
}
}
//это рисование. Во время рисования, нам необходимо наоборот делить текущие координаты которые мы нажимаем на scaleIndex.
//так мы получим актуальные данные в entity
//и уже они пусть обратно умножаются и в drawing отрисовывается все правильно.
@Override
public void mousePressed(MouseEvent e) {
HitboxCircle nowHitbox = (HitboxCircle)entity.getHitbox();
if(nowHitbox.getRadius()==0 && firstIsoPoint == null) {
firstIsoPoint = new Point(e.getX(), e.getY());
firstIsoPoint = new Point(currentIsoPoint.x, currentIsoPoint.y);
}else if(nowHitbox.getRadius()==0 && firstIsoPoint != null) {
//Формула высчитывания радиуса из диаметров circle.
nowHitbox.getCurrentRefPoint().setXY(firstIsoPoint.x, firstIsoPoint.y);
nowHitbox.setDiametrXY(Math.abs(firstIsoPoint.x-e.getX()),Math.abs((firstIsoPoint.x-e.getX())/2));
nowHitbox.setDiametrXY(Math.abs(firstIsoPoint.x-currentIsoPoint.x),Math.abs((firstIsoPoint.x-currentIsoPoint.x)/2));
System.out.println("X = "+nowHitbox.getDiametrX()+ ". Y = "+nowHitbox.getDiametrY());
float temp = (float)Math.sqrt(2);
nowHitbox.setRadius((nowHitbox.getDiametrY()/2)*temp);
@ -64,8 +70,8 @@ public class HitboxCircleRenderingFunction implements ShapeRenderingFunction {
@Override
public void mouseMoved(MouseEvent e) {
currentIsoPoint.x = e.getX();
currentIsoPoint.y = e.getY();
currentIsoPoint.x = e.getX()/scaleIndex;
currentIsoPoint.y = e.getY()/scaleIndex;
}
public void functionClearHitboxJButton() {

View File

@ -22,6 +22,7 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
Entity entity;
private List<Point> LocalListPointsIso = new ArrayList<Point>();
private List<Point> LocalListPointsCartesian = new ArrayList<Point>();
private float scaleIndex = 1;
public List<Point> getLocalListPointsIso() {
return LocalListPointsIso;
@ -37,6 +38,7 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
@Override
public void drawing(Graphics2D g) {
scaleIndex = entity.getScaleIndex();
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
int x1,y1,x2,y2;
if(nowHitbox.getListPointsIso().size() == 4) {
@ -56,13 +58,13 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
y1 = (int)listPointsIso.get(i % size).y;
x2 = (int)listPointsIso.get((i+1) % size).x;
y2 = (int)listPointsIso.get((i+1) % size).y;
g.drawLine(x1, y1, x2, y2);
g.drawLine((int)(x1*scaleIndex), (int)(y1*scaleIndex), (int)(x2*scaleIndex), (int)(y2*scaleIndex));
}
x1 = (int)listPointsIso.get(0).x;
y1 = (int)listPointsIso.get(0).y;
x2 = (int)listPointsIso.get(3).x;
y2 = (int)listPointsIso.get(3).y;
g.drawLine(x1, y1, x2, y2);
g.drawLine((int)(x1*scaleIndex), (int)(y1*scaleIndex), (int)(x2*scaleIndex), (int)(y2*scaleIndex));
}
@Override
@ -93,8 +95,8 @@ public class HitboxRectengleRenderingFunction implements ShapeRenderingFunction
@Override
public void mouseMoved(MouseEvent e) {
currentIsoPoint.x = e.getX();
currentIsoPoint.y = e.getY();
currentIsoPoint.x = e.getX()/scaleIndex;
currentIsoPoint.y = e.getY()/scaleIndex;
HitboxRectangle nowHitbox = (HitboxRectangle)entity.getHitbox();
if(entity!=null) {
if(firstIsoPoint != null && nowHitbox.getListPointsIso().size() == 0) {

View File

@ -10,6 +10,7 @@ public class Entity {
private BufferedImage thisImage;
private int width = 0;
private int height = 0;
private float scaleIndex = 1;
public Entity(String name, String drawbox, String hitbox, BufferedImage sprite) {
thisName = new String(name);
@ -101,4 +102,11 @@ public class Entity {
public void setHeight(int height) {
this.height = height;
}
public void setScaleIndex(float index) {
scaleIndex = index;
}
public float getScaleIndex() {
return scaleIndex;
}
}