Skip to content

Commit

Permalink
Zoom on mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-short committed Oct 31, 2015
1 parent 4f78c96 commit 0ddf3ad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
50 changes: 33 additions & 17 deletions src/net/buddat/wgenerator/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class MainWindow extends JFrame {

private static final long serialVersionUID = -407206109473532425L;

private static final String version = "2.4";
private static final String version = "2.4.2";
private WurmAPI api;
private HeightMap heightMap;
private TileMap tileMap;
Expand Down Expand Up @@ -134,7 +134,6 @@ public class MainWindow extends JFrame {
private JLabel lblMapCoords;
private JCheckBox chcekbox_showGrid;
private JTextField textField_mapGridSize;
// private static MainWindow instance;
private JTextField textField_biomeDensity;
private JButton btnViewErrors;
private JTextArea textArea_Errors;
Expand Down Expand Up @@ -168,7 +167,6 @@ public MainWindow() {
setTitle("Wurm Map Generator - v"+version);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 951, 650);
// instance = this;
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
Expand Down Expand Up @@ -369,12 +367,12 @@ public void actionPerformed(ActionEvent arg0) {

JLabel lblMaxHeight = new JLabel("Max Height");
labelPanel.add(lblMaxHeight);

checkbox_moreLand = new JCheckBox("More Land", Constants.MORE_LAND);
labelPanel.add(checkbox_moreLand);

checkbox_mapRandomSeed = new JCheckBox("Random Seed", true);
labelPanel.add(checkbox_mapRandomSeed);
JLabel label = new JLabel("");
labelPanel.add(label);
JLabel lblNewLabel = new JLabel("");
labelPanel.add(lblNewLabel);

JPanel inputPanel = new JPanel();
panel.add(inputPanel);
Expand All @@ -386,6 +384,7 @@ public void actionPerformed(ActionEvent arg0) {
comboBox_mapSize.setSelectedIndex(1);

textField_mapSeed = new JTextField("" + System.currentTimeMillis());
textField_mapSeed.setEnabled(false);
inputPanel.add(textField_mapSeed);
textField_mapSeed.setColumns(10);

Expand All @@ -408,12 +407,17 @@ public void actionPerformed(ActionEvent arg0) {
textField_mapMaxHeight = new JTextField("" + (int) Constants.MAP_HEIGHT);
inputPanel.add(textField_mapMaxHeight);
textField_mapMaxHeight.setColumns(10);

JLabel label = new JLabel("");
inputPanel.add(label);

JLabel lblNewLabel = new JLabel("");
inputPanel.add(lblNewLabel);

checkbox_moreLand = new JCheckBox("More Land", Constants.MORE_LAND);
inputPanel.add(checkbox_moreLand);

checkbox_mapRandomSeed = new JCheckBox("Random Seed", true);
inputPanel.add(checkbox_mapRandomSeed);
checkbox_mapRandomSeed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField_mapSeed.setEnabled(!checkbox_mapRandomSeed.isSelected());
}
});

JPanel panel_7 = new JPanel();

Expand Down Expand Up @@ -569,6 +573,7 @@ public void actionPerformed(ActionEvent arg0) {
panel_12.setLayout(new GridLayout(0, 1, 0, 2));

textField_biomeSeed = new JTextField("" + System.currentTimeMillis());
textField_biomeSeed.setEnabled(false);
textField_biomeSeed.setColumns(10);
panel_12.add(textField_biomeSeed);

Expand Down Expand Up @@ -607,6 +612,11 @@ public void actionPerformed(ActionEvent e) {
panel_12.add(checkBox_landSlide);

checkbox_biomeRandomSeed = new JCheckBox("Random Seed");
checkbox_biomeRandomSeed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textField_biomeSeed.setEnabled(!checkbox_biomeRandomSeed.isSelected());
}
});
panel_12.add(checkbox_biomeRandomSeed);
checkbox_biomeRandomSeed.setSelected(true);

Expand Down Expand Up @@ -1084,6 +1094,10 @@ public void actionPerformed(ActionEvent arg0) {
@Override
public void run() {
mapName = textField_mapName.getText();
if(mapName.equals("")) {
textField_mapName.setText("empty");
mapName = "empty";
}
if (!apiClosed) {
getAPI().close();
}
Expand Down Expand Up @@ -1975,6 +1989,7 @@ private void parseAction(String action) {
textField_mapMaxHeight.setText(options[6]);
checkbox_moreLand.setSelected(Boolean.parseBoolean(options[7]));
checkbox_mapRandomSeed.setSelected(false);
textField_mapSeed.setEnabled(true);

actionGenerateHeightmap();
} catch (Exception nfe) {
Expand Down Expand Up @@ -2006,6 +2021,7 @@ private void parseAction(String action) {
textField_maxDiagSlope.setText(options[4]);
textField_maxDirtHeight.setText(options[5]);
checkbox_biomeRandomSeed.setSelected(false);
textField_biomeSeed.setEnabled(true);

actionDropDirt();
break;
Expand Down Expand Up @@ -2137,7 +2153,7 @@ private void parseAction(String action) {
}
}

public class TextFileView extends FileFilter {
private class TextFileView extends FileFilter {

public boolean accept(File f) {
if (f.isDirectory()) {
Expand Down Expand Up @@ -2169,7 +2185,7 @@ public String getDescription() {
}
}

class ImageFileView extends FileFilter {
private class ImageFileView extends FileFilter {

public boolean accept(File f) {
if (f.isDirectory()) {
Expand Down
15 changes: 9 additions & 6 deletions src/net/buddat/wgenerator/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ public MapPanel(MainWindow w) {
public void mouseWheelMoved(MouseWheelEvent e) {
startX = e.getX();
startY = e.getY();
double delta = 0.05f * e.getPreciseWheelRotation();
double ratioX = ((startX-imageX)/scale/mapSize);
double ratioY = ((startY-imageY)/scale/mapSize);
double delta = 0.1f * e.getPreciseWheelRotation();
if(e.isShiftDown())
delta *= 2;
int preH = getImageHeight();
int preW = getImageWidth();
scale -= delta;
if(scale <= minScale)
scale = minScale;
int deltaX = (int)((getImageWidth() - preW) / 2);
int deltaY = (int)((getImageHeight() - preH) / 2);
double ratioX = ((startX-imageX)/scale/getImageWidth());
double ratioY = ((startY-imageY)/scale/getImageHeight());
int deltaX = (int)((getImageWidth() - preW));
int deltaY = (int)((getImageHeight() - preH));
imageX -= (int)(deltaX*ratioX);
imageY -= (int)(deltaY*ratioY);
checkBounds();
Expand Down Expand Up @@ -217,12 +217,15 @@ public void setMapSize(int newMapSize) {
}

public void setMapImage(BufferedImage newImage) {
int newSize = newImage.getWidth();
int oldSize = mapImage.getWidth();
if (mapImage != null)
mapImage.flush();
mapImage = newImage;
updateScale();
checkBounds();
scale = minScale;
if (oldSize != newSize)
scale = minScale;
}

public BufferedImage getMapImage() {
Expand Down

0 comments on commit 0ddf3ad

Please sign in to comment.