Beginning improved scaling feature
This commit is contained in:
parent
5c9d049819
commit
4cbd0e5316
1 changed files with 33 additions and 17 deletions
|
|
@ -19,7 +19,7 @@ import javax.swing.border.*;
|
||||||
*/
|
*/
|
||||||
public class Editor
|
public class Editor
|
||||||
extends JComponent
|
extends JComponent
|
||||||
implements MouseListener, MouseMotionListener
|
implements MouseListener, MouseMotionListener, MouseWheelListener
|
||||||
{
|
{
|
||||||
// Given from input image
|
// Given from input image
|
||||||
BufferedImage img;
|
BufferedImage img;
|
||||||
|
|
@ -49,7 +49,7 @@ public class Editor
|
||||||
roi.left = -0.4f;
|
roi.left = -0.4f;
|
||||||
roi.right = 0.4f;
|
roi.right = 0.4f;
|
||||||
|
|
||||||
rescale(imgScale * 680);
|
rescale(imgScale * 680, null);
|
||||||
/*
|
/*
|
||||||
Dimension size = new Dimension(680, 680);
|
Dimension size = new Dimension(680, 680);
|
||||||
setPreferredSize(size);
|
setPreferredSize(size);
|
||||||
|
|
@ -69,12 +69,19 @@ public class Editor
|
||||||
*/
|
*/
|
||||||
addMouseListener(this);
|
addMouseListener(this);
|
||||||
addMouseMotionListener(this);
|
addMouseMotionListener(this);
|
||||||
|
addMouseWheelListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void rescale(double newScale) {
|
void rescale(double newScale, Point center) {
|
||||||
|
|
||||||
|
// TODO Get the visible rect
|
||||||
|
// TODO find "center" in visible rect. If null or not there make it the actual center
|
||||||
|
// TODO Make up a virtual visible rect by scaling actual visible rect
|
||||||
|
// TODO calculate top left coordinate in new virtual visible rect
|
||||||
|
// TODO translate visible rect to same top left as virtual
|
||||||
|
// TODO scroll to visible rect
|
||||||
scale = newScale;
|
scale = newScale;
|
||||||
side = (int)Math.round(scale / imgScale);
|
side = (int)Math.round(scale / imgScale);
|
||||||
Dimension size = new Dimension(side, side);
|
Dimension size = new Dimension(side, side);
|
||||||
|
|
@ -94,22 +101,17 @@ public class Editor
|
||||||
super.paintComponent(g1);
|
super.paintComponent(g1);
|
||||||
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
// System.out.println("Recalculating");
|
|
||||||
AffineTransform screenToCoord = new AffineTransform();
|
|
||||||
screenToCoord.translate(side/2d, side/2d);
|
|
||||||
screenToCoord.scale(side, -side);
|
|
||||||
|
|
||||||
AffineTransform coordToScreen = new AffineTransform();
|
AffineTransform coordToScreen = new AffineTransform();
|
||||||
coordToScreen.scale(1d/side, -1d/side);
|
coordToScreen.translate(side/2d, side/2d);
|
||||||
coordToScreen.translate(-side/2d, -side/2d);
|
coordToScreen.scale(side, -side);
|
||||||
|
|
||||||
this.screenToCoord = coordToScreen;
|
|
||||||
this.coordToScreen = screenToCoord;
|
|
||||||
|
|
||||||
|
AffineTransform screenToCoord = new AffineTransform();
|
||||||
|
screenToCoord.scale(1d/side, -1d/side);
|
||||||
|
screenToCoord.translate(-side/2d, -side/2d);
|
||||||
|
|
||||||
|
this.screenToCoord = screenToCoord;
|
||||||
|
this.coordToScreen = coordToScreen;
|
||||||
dirty = false;
|
dirty = false;
|
||||||
} else {
|
|
||||||
// System.out.println("using cached transform");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Graphics2D g = (Graphics2D)g1;
|
Graphics2D g = (Graphics2D)g1;
|
||||||
|
|
@ -191,7 +193,7 @@ public class Editor
|
||||||
int value = zoomSlider.getValue();
|
int value = zoomSlider.getValue();
|
||||||
if (value != previousValue) {
|
if (value != previousValue) {
|
||||||
previousValue = value;
|
previousValue = value;
|
||||||
rescale(value * 0.01);
|
rescale(value * 0.01, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -228,7 +230,9 @@ public class Editor
|
||||||
Container c = frame.getContentPane();
|
Container c = frame.getContentPane();
|
||||||
c.setLayout(new BorderLayout());
|
c.setLayout(new BorderLayout());
|
||||||
c.add(x.createControlPanel(), BorderLayout.EAST);
|
c.add(x.createControlPanel(), BorderLayout.EAST);
|
||||||
c.add(new JScrollPane(x), BorderLayout.CENTER);
|
JScrollPane scroller = new JScrollPane(x);
|
||||||
|
scroller.setWheelScrollingEnabled(false);
|
||||||
|
c.add(scroller, BorderLayout.CENTER);
|
||||||
|
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
@ -386,6 +390,17 @@ public class Editor
|
||||||
setCursor(cursors[findRegion(e.getX(), e.getY())]);
|
setCursor(cursors[findRegion(e.getX(), e.getY())]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
|
int units = e.getUnitsToScroll();
|
||||||
|
System.out.println(units);
|
||||||
|
rescale(scale * (1f + units / 100f), e.getPoint());
|
||||||
|
// this.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void log(String x) {
|
static void log(String x) {
|
||||||
System.out.println(x);
|
System.out.println(x);
|
||||||
}
|
}
|
||||||
|
|
@ -453,6 +468,7 @@ public class Editor
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// eof
|
// eof
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue