Search in sources :

Example 6 with WorldCoordinate

use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.

the class WorldPanel method placeGroupBoxModifySelection.

/**
 * Modifies the box/shift selection box (eg on shift + direction key)
 * @param x new coordinate
 * @param y new coordinate
 */
private void placeGroupBoxModifySelection(int x, int y) {
    placeGroup.clear();
    placeGroupBoxEnd = new WorldCoordinate(getPosition().getLayer(), x, y);
    // reset if layer changed
    if (placeGroupBoxStart != null && placeGroupBoxStart.getLayer() != placeGroupBoxEnd.getLayer())
        placeGroupBoxStart = null;
    // set start, if not set
    if (placeGroupBoxStart == null)
        placeGroupBoxStart = placeGroupBoxEnd;
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate)

Example 7 with WorldCoordinate

use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.

the class WorldTab method layerSelected.

// ========================= selection listener ============================
@Override
public void layerSelected(Layer layer) {
    worldPanel.pushPosition(new WorldCoordinate(layer.getId(), layer.getCenterX(), layer.getCenterY()));
    repaint();
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate)

Example 8 with WorldCoordinate

use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.

the class WorldTab method getMeta.

@Override
public JSONObject getMeta(HashMap<Integer, Integer> layerTranslation) {
    JSONObject root = new JSONObject();
    MapPainterDefault mapPainter = (MapPainterDefault) getWorldPanel().getMappainter();
    root.put("showPaths", mapPainter.getShowPaths());
    root.put("pathsCurved", mapPainter.getPathsCurved());
    root.put("showCursor", getWorldPanel().isCursorEnabled());
    root.put("showGrid", mapPainter.isGridEnabled());
    root.put("tileSize", getWorldPanel().getTileSize());
    JSONArray history = new JSONArray();
    root.put("history", history);
    Integer cnt = 0;
    for (WorldCoordinate coord : getWorldPanel().getHistory()) {
        if (layerTranslation.containsKey(coord.getLayer())) {
            JSONObject el = new JSONObject();
            el.put("l", layerTranslation.get(coord.getLayer()));
            el.put("x", coord.getX());
            el.put("y", coord.getY());
            history.put(el);
        }
        if (++cnt >= 25)
            break;
    }
    return root;
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate) JSONObject(org.json.JSONObject) MapPainterDefault(mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault) JSONArray(org.json.JSONArray)

Example 9 with WorldCoordinate

use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.

the class ExportImageDialog method drawLayer.

/**
 * Draws map
 * @param center layer and center information
 * @return image
 */
BufferedImage drawLayer(WorldCoordinate center) {
    BufferedImage image = null;
    Integer tileSize = (Integer) spTileSize.getValue();
    int width, height;
    // get image size and map center
    if (rbSelection.isSelected()) {
        HashSet<Place> places = worldTab.getWorldPanel().placeGroupGetSelection();
        Pair<Integer, Integer> selectionSize = getSelectionSize(places);
        width = selectionSize.first;
        height = selectionSize.second;
        Pair<Double, Double> selectionCenter = getSelectionCenter(places);
        center = new WorldCoordinate(center.getLayer(), selectionCenter.first, selectionCenter.second);
    } else if (rbCurrentView.isSelected()) {
        Dimension size = worldTab.getWorldPanel().getSize();
        width = size.width;
        height = size.height;
    } else {
        // whole map
        Pair<Integer, Integer> mapSize = getMapSize(worldTab.getWorld().getLayer(center.getLayer()));
        width = mapSize.first;
        height = mapSize.second;
        Layer layer = worldTab.getWorld().getLayer(center.getLayer());
        Pair<Double, Double> exactCenter = layer.getExactCenter();
        center = new WorldCoordinate(layer.getId(), exactCenter.first, exactCenter.second);
    }
    if (width != 0 && height != 0) {
        image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    }
    if (image != null) {
        Graphics graphics = image.createGraphics();
        graphics.setClip(0, 0, width, height);
        ((Graphics2D) graphics).setBackground(new Color(255, 255, 255, 0));
        graphics.clearRect(0, 0, width, height);
        graphics.setFont(worldTab.getFont());
        MapPainterDefault mappainter = new MapPainterDefault();
        mappainter.setGridEnabled(cbBackgroundGrid.isSelected());
        mappainter.paint(graphics, tileSize, width, height, worldTab.getWorld().getLayer(center.getLayer()), center);
    }
    return image;
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate) Color(java.awt.Color) Dimension(java.awt.Dimension) Layer(mudmap2.backend.Layer) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) MapPainterDefault(mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault) Place(mudmap2.backend.Place) Pair(mudmap2.utils.Pair)

Example 10 with WorldCoordinate

use of mudmap2.backend.WorldCoordinate in project mudmap2 by Neop.

the class WorldPanelTest method testPushPopPosition.

/**
 * Test of push/pop/get/restore/resetPosition method, of class WorldPanel.
 */
@Test
public void testPushPopPosition() {
    System.out.println("pushPosition");
    World world = new World();
    WorldPanel instance = new WorldPanel(null, world, false);
    WorldCoordinate home = new WorldCoordinate(1, 2, 3);
    WorldCoordinate pos1 = new WorldCoordinate(4, 6, 1);
    WorldCoordinate pos2 = new WorldCoordinate(1, 2, 6);
    WorldCoordinate pos3 = new WorldCoordinate(1, 8, 4);
    world.setHome(home);
    assertTrue(home.compareTo(instance.getPosition()) == 0);
    instance.popPosition();
    assertTrue(home.compareTo(instance.getPosition()) == 0);
    instance.pushPosition(pos1);
    WorldCoordinate push1 = instance.getPosition();
    // assertTrue(pos1.compareTo(instance.getPosition()) == 0);
    instance.pushPosition(pos2);
    WorldCoordinate push2 = instance.getPosition();
    // assertTrue(pos2.compareTo(instance.getPosition()) == 0);
    instance.pushPosition(pos3);
    WorldCoordinate push3 = instance.getPosition();
    // assertTrue(pos3.compareTo(instance.getPosition()) == 0);
    instance.popPosition();
    assertTrue(push2.compareTo(instance.getPosition()) == 0);
    instance.popPosition();
    assertTrue(push1.compareTo(instance.getPosition()) == 0);
    instance.popPosition();
    assertTrue(home.compareTo(instance.getPosition()) == 0);
    instance.popPosition();
    assertTrue(home.compareTo(instance.getPosition()) == 0);
    instance.restorePosition();
    assertTrue(push1.compareTo(instance.getPosition()) == 0);
    instance.restorePosition();
    assertTrue(push2.compareTo(instance.getPosition()) == 0);
    instance.restorePosition();
    assertTrue(push3.compareTo(instance.getPosition()) == 0);
    instance.restorePosition();
    assertTrue(push3.compareTo(instance.getPosition()) == 0);
    WorldCoordinate reset = new WorldCoordinate(12, 1, 6);
    instance.resetHistory(reset);
    assertTrue(reset.compareTo(instance.getPosition()) == 0);
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate) World(mudmap2.backend.World) Test(org.junit.Test)

Aggregations

WorldCoordinate (mudmap2.backend.WorldCoordinate)14 Layer (mudmap2.backend.Layer)6 Place (mudmap2.backend.Place)6 Color (java.awt.Color)4 World (mudmap2.backend.World)4 MapPainterDefault (mudmap2.frontend.GUIElement.WorldPanel.MapPainterDefault)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Path (mudmap2.backend.Path)3 Pair (mudmap2.utils.Pair)3 Test (org.junit.Test)3 Dimension (java.awt.Dimension)2 Graphics (java.awt.Graphics)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 PlaceGroup (mudmap2.backend.PlaceGroup)2 RiskLevel (mudmap2.backend.RiskLevel)2 WorldFileInvalidTypeException (mudmap2.backend.WorldFileReader.Exception.WorldFileInvalidTypeException)2