From: <aki...@us...> - 2006-12-16 21:30:29
|
Revision: 1115 http://svn.sourceforge.net/gridarta/?rev=1115&view=rev Author: akirschbaum Date: 2006-12-16 13:30:26 -0800 (Sat, 16 Dec 2006) Log Message: ----------- Unify map cursor and non-rectangular selection. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/resource/system/seltile.png trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/MapViewIFrame.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/action.properties trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/map/MapModel.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties Added Paths: ----------- trunk/crossfire/resource/system/cursor.png trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/ChangeLog 2006-12-16 21:30:26 UTC (rev 1115) @@ -1,3 +1,13 @@ +2006-12-16 Andreas Kirschbaum + + * Implement non-rectangular selections. For now, it does not take + effect on any operation. + + * Implement map cursor. It affects flood filling, enter exit and + pasting. + + * Allow archetype selection by cursor in archetype panel. + 2006-12-15 Andreas Kirschbaum * Invert sorting order of archetype panels. Added: trunk/crossfire/resource/system/cursor.png =================================================================== (Binary files differ) Property changes on: trunk/crossfire/resource/system/cursor.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/crossfire/resource/system/seltile.png =================================================================== (Binary files differ) Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -29,6 +29,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gameobject.anim.AnimationObjects; import cfeditor.gameobject.face.FaceObjects; +import cfeditor.gui.map.MapCursorControl; import cfeditor.gui.map.MapPropertiesDialog; import cfeditor.gui.prefs.GUIPrefs; import cfeditor.gui.prefs.ResPrefs; @@ -113,6 +114,8 @@ private static ImageIcon mapGridIcon; + private static ImageIcon mapCursorIcon; + private static ImageIcon unknownTileIcon; private static ImageIcon nofaceTileIcon; @@ -176,11 +179,14 @@ /** Pickmaps cannot be edited while lockedPickmaps is true. */ private boolean lockAllPickmaps = false; + private final MapCursorControl mapCursorControl; + /** Constructs the main controller and its model and view. */ public CMainControl() { instance = this; archetypeSet = new ArchetypeSet(this); scriptControl = new CScriptController(this); + mapCursorControl = new MapCursorControl(this); mainView = new CMainView(); } @@ -1232,7 +1238,7 @@ public void enterExit() { GameObject exit = getMainView().getMapTileSelection(); if (exit == null || !CFArchTypeList.isExitType(exit)) { - exit = currentMap.getMapModel().getExit(currentMap.getMapViewFrame().getHighlightStart()); + exit = currentMap.getMapModel().getExit(currentMap.getMapViewFrame().getView().getCursorPosition()); } if (exit == null) { // no exit found @@ -1654,6 +1660,10 @@ return mapGridIcon; } + public static ImageIcon getMapCursorIcon() { + return mapCursorIcon; + } + public static ImageIcon getUnknownTileIcon() { return unknownTileIcon; } @@ -1677,6 +1687,7 @@ private static void loadDefTiles() { mapGridIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_GRID_TILE); mapSelIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_SEL_TILE); + mapCursorIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_CURSOR); unknownTileIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_UNKNOWN); nofaceTileIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_NOFACE); noarchTileIcon = CGUIUtils.getSysIcon(IGUIConstants.TILE_NOARCH); @@ -1796,6 +1807,10 @@ return null; } + public MapCursorControl getMapCursorControl() { + return mapCursorControl; + } + /** * Runs the garbage collection. */ Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -32,6 +32,7 @@ import java.awt.Component; import java.awt.Dimension; import java.awt.Rectangle; +import java.awt.Point; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; @@ -339,8 +340,9 @@ if (pmap != null && pmap.getMapViewFrame().isHighlight()) { // now try to get the topmost object GameObject arch = null; - if (pmap.isPointValid(pmap.getMapViewFrame().getHighlightStart())) { - arch = pmap.getMapModel().getMapSquare(pmap.getMapViewFrame().getHighlightStart()).getFirst(); + final Point cursor = pmap.getMapViewFrame().getView().getCursorPosition(); + if (pmap.isPointValid(cursor)) { + arch = pmap.getMapModel().getMapSquare(cursor).getFirst(); } if (arch != null) { // so here we return the arch from the pickmap @@ -822,12 +824,19 @@ private final String[] directionsMap = {"enterNorthMap", "enterEastMap", "enterSouthMap", "enterWestMap", "enterUpperMap", "enterLowerMap"}; + private final String[] directionsGo = {"goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest"}; + private void initActions() { ACTION_FACTORY.createActions(true, mainControl, "createNew", "open", "options", "exit", "gc", "onlineHelp", "about"); ACTION_FACTORY.createActions(true, mainControl.getScriptController().getView(), "editPlugins", "savePlugins", "exportPluginAs", "importPlugin"); ACTION_FACTORY.createActions(true, mainControl, directionsMap); ACTION_FACTORY.createActions(true, this, "resetView"); ACTION_FACTORY.createToggles(true, mainControl, "autoJoin"); + ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), directionsGo); + ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "selectTile", "startStopDrag", "addToSelection", "subFromSelection", "releaseDrag"); + ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "insertArch", "deleteArch"); + ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "selectArchAbove", "selectArchBelow"); + ACTION_FACTORY.createAction(true, "archAttributes", mainControl.getMapCursorControl()); ACTION_FACTORY.createToggles(true, this, "lockAllPickmaps"); aTileShow.setEnabled(false); // not yet implemented @@ -932,10 +941,13 @@ //aTileShow.setEnabled(mapState); aMapProperties.setEnabled(mapState); aReplace.setEnabled(mapState); - for (int direction = 0; direction < IGUIConstants.DIRECTIONS; direction++) { + for (int direction = 0; direction < directionsMap.length; direction++) { final String mtp = mapState ? mainControl.getCurrentMap().getMapArch().getTilePath(direction) : null; ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); } + for (int direction = 0; direction < directionsGo.length; direction++) { + ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(selState); + } aClear.setEnabled(selState); aCut.setEnabled(selState); aCopy.setEnabled(selState); @@ -969,6 +981,10 @@ MenuManager.getMenuManager().addMenuLocation(currentmapLocation); } + public CMapTileList getMapTileList() { + return mapTileList; + } + private final class LookAndFeelAction extends AbstractAction { private final String className; Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -53,6 +53,10 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.sf.gridarta.gameobject.GameObjectContainer; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -61,7 +65,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class CMapTileList extends JPanel { +public final class CMapTileList extends JPanel implements MapCursorListener { /** Serial Version UID. */ private static final long serialVersionUID = 1L; @@ -213,6 +217,17 @@ }); } + public void selectArchBelow() { + list.setSelectedIndex(list.getSelectedIndex() + 1); + } + + public void selectArchAbove() { + final int index = list.getSelectedIndex(); + if (index > 0) { + list.setSelectedIndex(index - 1); + } + } + /** * Determine the list index for a given mouse event. This function differs * from <code>list.locationTopIndex(e.getPoint())</code> in that it always @@ -309,7 +324,7 @@ } listCounter = 0; - currentSquare = mapControl.getMapModel().getMouseRightPos(); + currentSquare = mapControl.getMapCursor().getLocation(); int postSelect = -1; boolean foundSIndex = false; int sIndex = 0; @@ -375,6 +390,22 @@ return selListCounter; } + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + if (e.getSource().isActive()) { + // Position changed + setMapTileList(mainControl.getCurrentMap(), null); + } else { + // Cursor was disabled + setMapTileList(null, null); + } + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + // A mode change can be ignored + } + /** CellRenderer for rendering ArchObjects on a certain map tile in a list. */ private final class MyCellRenderer extends DefaultListCellRenderer { Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -45,8 +45,14 @@ import javax.swing.ScrollPaneConstants; import net.sf.gridarta.EditOperation; import net.sf.gridarta.Size2D; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -69,7 +75,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class CMapViewBasic extends JScrollPane { +public final class CMapViewBasic extends JScrollPane implements MapModelListener, MapCursorListener { private static final Logger log = Logger.getLogger(CMapViewBasic.class); @@ -92,15 +98,10 @@ private boolean gridVisible = false; - // this is needed to check the diamond tile areas and convert rectangles to diamond - private final Point mapMousePos = new Point(); + private MapCursor mapCursor; private final Point mapMouseRightPos = new Point(); // coordinates of selected tile on the map - private final Point mapMouseRightOff = new Point(); // offset from the selected tile while left-click draging - - private boolean highlightOn; // Is map-tile selection highlighted? true/false - private final boolean[] needMpanelUpdate; // indicates that the mapArchPanel needs private MapGrid mapGrid; @@ -120,21 +121,23 @@ //super("Map ["+control.getMapFileName()+"]", true, true, true, true); super(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.mapControl = mapControl; + final MapModel mapModel = mapControl.getMapModel(); + mapGrid = new MapGrid(mapModel.getMapSize()); + mapCursor = new MapCursor(mapGrid); + mapCursor.addMapCursorListener(this); + if (!mapControl.isPickmap()) { + mapCursor.addMapCursorListener(mainControl.getMainView().getMapTileList()); + mapCursor.addMapCursorListener(mainControl.getMainView().getStatusBar()); + } this.mainControl = mainControl; - mapGrid = new MapGrid(mapControl.getMapModel().getMapSize()); frame = fi; - highlightOn = false; needMpanelUpdate = new boolean[3]; needMpanelUpdate[0] = false; needMpanelUpdate[1] = false; needMpanelUpdate[2] = false; - mapMousePos.x = -1; - mapMousePos.y = -1; mapMouseRightPos.x = -1; mapMouseRightPos.y = -1; - mapMouseRightOff.x = 0; - mapMouseRightOff.y = 0; if (isPickmap()) { setBackground(IGUIConstants.BG_COLOR); @@ -143,6 +146,7 @@ setViewportView(renderer); getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + mapModel.addMapModelListener(this); refreshDataFromModel(); // set the pixel increment scrolling for clicking once on a scrollbar arrow @@ -161,6 +165,8 @@ } renderer.updateLookAndFeel(); mapGrid.addMapGridListener(renderer); + renderer.setFocusable(true); + setFocusable(true); } public boolean isChanged() { @@ -171,10 +177,26 @@ changed = state; } - public Point getMapMouseRightPos() { - return mapMouseRightPos; + /** + * Get MapGrid of this view. + * @return MapGrid of this view. + */ + public MapGrid getMapGrid() { + return mapGrid; } + /** + * Get MapCursor of this view. + * @return MapCursor of this view. + */ + public MapCursor getMapCursor() { + return mapCursor; + } + + @Nullable public Point getCursorPosition() { + return mapCursor.getLocation(); + } + public boolean isPickmap() { return mapControl.isPickmap(); } @@ -193,17 +215,17 @@ } /** - * Returns whether there is a highlighted area in this MapView. + * Returns whether there is a highlighted area in this mapview. * @return <code>true</code> if there is a highlighted area, otherwise <code>false</code>. */ public boolean isHighlight() { - return highlightOn; + return mapCursor.isActive(); } /** Turn the highlight off. */ public void unHighlight() { - if (highlightOn) { - highlightOn = false; + if (mapCursor.isActive()) { + mapCursor.deactivate(); mainControl.getMainView().refreshMenus(); } @@ -240,23 +262,16 @@ } /** - * Returns the starting coordinates of the highlighted tile-selection. - * @return The starting coordinates of the highlighted tile-selection. + * This method returns the bounding rectangle of the selection + * There may be non-selected tiles in that rectangle + * This method is mainly useful for creating a submap for copy/paste operations. + * @return selected Rectangle */ - public Point getHighlightStart() { - return mapMouseRightPos; + public Rectangle getSelectionRec() { + return mapGrid.getSelectedRec(); } /** - * Returns the ending coordinates of the highlighted tile-selection. - * @return The ending coordinates of the highlighted tile-selection. - * @todo fix naming or comment: The method name suggests ending is relative to start, while the original description suggests its absolute. - */ - public Point getHighlightOffset() { - return mapMouseRightOff; - } - - /** * Highlight the tile at given coordinates (just as * if it had been selected with leftclick). Besides, the mapview is * always centered on the coordinates as far as possible. @@ -266,8 +281,6 @@ // set the highlighted spot: mapMouseRightPos.x = point.x; mapMouseRightPos.y = point.y; - mapMouseRightOff.x = 0; - mapMouseRightOff.y = 0; // set scroll position accordingly to center on target final Rectangle scrollto = new Rectangle((point.x + 1) * 32 + 16 - getViewport().getViewRect().width / 2, @@ -289,16 +302,15 @@ getViewport().setViewPosition(scrollto.getLocation()); //getViewport().scrollRectToVisible(scrollto); - if (!highlightOn) { - highlightOn = true; - mainControl.getMainView().refreshMenus(); - } - // repaint map to display selection mapControl.repaint(); mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), null); } + public void setCursorPosition(final Point cursorPosition) { + mapCursor.setLocation(cursorPosition); + } + /** * Convert the map into a png file. * @param file the file to write to @@ -426,15 +438,6 @@ return mapSize; } - public Point getMapMousePos() { - return mapMousePos; - } - - public void setMapMousePos(final Point point) { - mapMousePos.x = point.x; - mapMousePos.y = point.y; - } - /** The mouse listener for the view. */ public final class CListener extends MouseAdapter implements MouseMotionListener { @@ -444,16 +447,12 @@ private Rectangle previewRect = null; - private Point[] needRedraw = null; // array of tile coords which need to be redrawn - /** {@inheritDoc} */ @Override public void mousePressed(final MouseEvent e) { + requestFocus(); changedFlagNotify(); // set flag: map has changed final Point clickPoint = e.getPoint(); final Point mapLoc = renderer.getTileLocationAt(clickPoint, null); - needRedraw = null; - Point[] preRedraw = null; // array of tile coords which need to be redrawn - boolean needFullRepaint = false; // true if full repaint of map needed previewRect = null; if (mapLoc != null) { @@ -462,58 +461,60 @@ return; } - if (highlightOn) { - // if we had a selected rect, we must remove it: - if (Math.abs(mapMouseRightOff.x + 1) * Math.abs(mapMouseRightOff.y + 1) <= 16) { - // the rect is relatively small, so we remove it per-tile - preRedraw = calcRectRedraw(mapMouseRightPos.x, mapMouseRightPos.y, - mapMouseRightPos.x + mapMouseRightOff.x, - mapMouseRightPos.y + mapMouseRightOff.y); - paintTileArray(preRedraw); - needRedraw = null; - } else { - // the rect is big, we redraw the whole map later - needFullRepaint = true; - } - } - // right mouse button: insert arch if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { + mapCursor.setLocation(mapLoc); insertObject(mapLoc); } else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { - if (e.isShiftDown()) { - insertObject(mapLoc); - } else if (e.isControlDown()) { - deleteObject(mapLoc); - } else { + final boolean selChange = mapCursor.isActive(); + // Throw away old selection if CTRL is not pressed + if (!e.isControlDown()) { + mapCursor.deactivate(); + } + mapCursor.setLocation(mapLoc); + mapCursor.dragStart(); + if (mapCursor.isActive() && mapControl.isPickmap()) { + // an arch of a pickmap was selected + CMainControl.getInstance().showArchPanelQuickObject(mapControl.getMapModel().getMapSquare(mapLoc).getFirst()); + } + // Change edit menu if there was a selection before and has gone or the other way around + if (!(selChange == mapCursor.isActive())) { + CMainControl.getInstance().getMainView().refreshMenus(); + } + + if (!e.isShiftDown() && !e.isControlDown()) { selectTile(mapLoc); } } else { // middle mouse button: delete arch // (I intenionally used "else" here. BUTTON2_MASK seems not to work for some systems) + mapCursor.setLocation(mapLoc); deleteObject(mapLoc); } } else { + mapCursor.setLocation(mapLoc); mainControl.getMainView().setMapTileList(null, null); // for secure... } /* UndoAndRedo.getInstance(mapControl).add(new CPaintOp(previewRect, aOrigData, (short)mapControl.getSelectedTile())); */ endFill(); - - // finally redraw the map: - if (!needFullRepaint) { - // redraw only tiles that need an update - paintTileArray(preRedraw); - paintTileArray(needRedraw); - } else { - //repaint(); // redraw full map - renderer.modelChanged(); - } } /** {@inheritDoc} */ @Override public void mouseReleased(final MouseEvent event) { + final Point clickPoint = event.getPoint(); + final Point mapLoc = renderer.getTileLocationAt(clickPoint, null); + if (!mapCursor.isOnGrid(mapLoc)) { + mapCursor.dragRelease(); + } else if (event.isShiftDown()) { + mapCursor.dragSelect(MapGrid.SelectionMode.FLIP); + } else if (event.isControlDown()) { + mapCursor.dragSelect(MapGrid.SelectionMode.SUB); + } else { + mapCursor.dragSelect(MapGrid.SelectionMode.ADD); + } + final int buttonNr; // Number of released mouse button if (event.getModifiers() == InputEvent.BUTTON1_MASK) { @@ -546,7 +547,6 @@ /** {@inheritDoc} */ public void mouseDragged(final MouseEvent event) { changedFlagNotify(); - Point[] needRedraw = null; // array of tile coords which need to be redrawn final Point dragPoint = event.getPoint(); // Mouse pointer Point temp = renderer.getTileLocationAt(dragPoint, null); // tile under Mouse pointer @@ -554,65 +554,45 @@ temp = new Point(-1, -1); } - if (event.getModifiers() == InputEvent.BUTTON1_MASK) { + if ((event.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { // Left Mouse Button: Selected area gets highlighted - // Update offset (from starting-dragpoint) only when mouse moved - // over new tile and mouse is still on the map - if (temp.x != -1 && temp.y != -1 && (mapMouseRightOff.x != temp.x - mapMouseRightPos.x || mapMouseRightOff.y != temp.y - mapMouseRightPos.y)) { - // update offset and redraw mapview - mapMouseRightOff.x = temp.x - mapMouseRightPos.x; - mapMouseRightOff.y = temp.y - mapMouseRightPos.y; + mapCursor.dragTo(temp); + } else if ((event.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { + mapCursor.setLocation(temp); - renderer.modelChanged(); - } - } else if (event.getModifiers() == InputEvent.BUTTON3_MASK) { // Right Mouse Button: Arches get inserted all the way - if (temp.x != mapMouseRightPos.x || mapMouseRightPos.y != temp.y) { - mapMouseRightPos.x = temp.x; - mapMouseRightPos.y = temp.y; - - if (temp.x == -1 || temp.y == -1) { - mainControl.getMainView().setMapTileList(null, null); - } else { - needRedraw = mapControl.insertSelArchToMap(temp, false); - needMpanelUpdate[2] = true; // when dragging is done, update map panel - } + if (temp.x == -1 || temp.y == -1) { + mainControl.getMainView().setMapTileList(null, null); + } else { + mapControl.insertSelArchToMap(temp, false); } } else { + mapCursor.setLocation(temp); + // Middle Mouse Button: Arches get deleted all the way - if (temp.x != mapMouseRightPos.x || mapMouseRightPos.y != temp.y) { - mapMouseRightPos.x = temp.x; - mapMouseRightPos.y = temp.y; + if (temp.x == -1 || temp.y == -1) { + mainControl.getMainView().setMapTileList(null, null); + } else { + // delete the topmost arch (matching the view settings) + // on that square and redraw the map + GameObject tmpArch = null; + final Iterator<GameObject> it = mapControl.getMapModel().getMapSquare(temp).reverse().iterator(); + for (final GameObject gameObject : mapControl.getMapModel().getMapSquare(temp).reverse()) { + tmpArch = gameObject; - if (temp.x == -1 || temp.y == -1) { - mainControl.getMainView().setMapTileList(null, null); - } else { - // delete the topmost arch (matching the view settings) - // on that square and redraw the map - GameObject tmpArch = null; - final Iterator<GameObject> it = mapControl.getMapModel().getMapSquare(temp).reverse().iterator(); - for (final GameObject gameObject : mapControl.getMapModel().getMapSquare(temp).reverse()) { - tmpArch = gameObject; - - // now search backwards for matching view settings - if (mainControl.getTileEdit() == 0 || mainControl.isTileEdit(tmpArch.getEditType())) { - break; - } + // now search backwards for matching view settings + if (mainControl.getTileEdit() == 0 || mainControl.isTileEdit(tmpArch.getEditType())) { + break; } - if (tmpArch != null) { - needRedraw = mapControl.calcArchRedraw(tmpArch); // get redraw info - mapControl.deleteMapArch(tmpArch, temp, false, MapModel.JOIN_ENABLE); - } - - needMpanelUpdate[1] = true; // when dragging is done, update map panel } + if (tmpArch != null) { + mapControl.calcArchRedraw(tmpArch); // get redraw info + mapControl.deleteMapArch(tmpArch, temp, false, MapModel.JOIN_ENABLE); + } } } - - // finally redraw all map-squares that need an update - paintTileArray(needRedraw); } private void insertObject(final Point mapLoc) { @@ -623,22 +603,14 @@ previewRect.height = 1; startMapLoc = mapLoc; - if (highlightOn && !mapControl.isPickmap()) { - highlightOn = false; // no longer highlighting tiles - mainControl.getMainView().refreshMenus(); - } - if (mapLoc.x != -1 && mapLoc.y != -1) { if (mapControl.isPickmap()) { // insert on pickmap - needRedraw = insertMapArchToPickmap(mapLoc); + insertMapArchToPickmap(mapLoc); } else { // insert on normal map - mapMouseRightPos.x = mapLoc.x; - mapMouseRightPos.y = mapLoc.y; + mapControl.insertSelArchToMap(mapLoc, true); - needRedraw = mapControl.insertSelArchToMap(mapLoc, true); - // get name of inserted arch (this is display in status bar while dragging) @Nullable final GameObject insArch = mainControl.getArchPanelHighlight(); final String insertArchName; @@ -662,56 +634,22 @@ } private void selectTile(final Point mapLoc) { - // left mouse button: select tiles - mapMouseRightPos.x = mapLoc.x; // position of selected tile - mapMouseRightPos.y = mapLoc.y; - mapMouseRightOff.x = 0; // dragging offset - mapMouseRightOff.y = 0; - if (mapLoc.x == -1 || mapLoc.y == -1) { if (!mapControl.isPickmap()) { mainControl.getMainView().setMapTileList(null, null); - - if (highlightOn) { - highlightOn = false; - mainControl.getMainView().refreshMenus(); - } } } else { if (!mapControl.isPickmap()) { mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), null); } - if (!highlightOn) { - highlightOn = true; // highlight the selected area - mainControl.getMainView().refreshMenus(); - } - // paint the highlight-icon renderer.setHighlightTile(/*((JComponent)renderer).getGraphics(), */mapLoc); - - if (mapControl.isPickmap()) { - final GameObject arch = mapControl.getBottomArchObject(mapLoc); - if (arch != null) { - // an arch of a pickmap was selected - mainControl.showArchPanelQuickObject(arch); - } - } } } private void deleteObject(final Point mapLoc) { - if (highlightOn && !mapControl.isPickmap()) { - highlightOn = false; // no longer highlighting tiles - mainControl.getMainView().refreshMenus(); - } - if (mapLoc.x != -1 && mapLoc.y != -1) { - if (!mapControl.isPickmap()) { - mapMouseRightPos.x = mapLoc.x; - mapMouseRightPos.y = mapLoc.y; - } - // delete the topmost arch (matching the view settings) on that square // and redraw the map GameObject tmpArch = null; @@ -723,7 +661,7 @@ } } if (tmpArch != null) { - needRedraw = mapControl.calcArchRedraw(tmpArch); // get redraw info + mapControl.calcArchRedraw(tmpArch); // get redraw info mapControl.deleteMapArch(tmpArch, mapLoc, false, MapModel.JOIN_ENABLE); // update mapArch panel @@ -735,14 +673,10 @@ /** * This method is only called for pickmaps. Take the currently * highlighted arch on the map (if any) and insert it on this pickmap. - * Redraw info is stored to 'needRedraw', no views get redrawn/updated - * here. * @param pos tile-coordinates in pickmap * @return array of coordinates for tiles that need to be redrawn */ - private Point[] insertMapArchToPickmap(final Point pos) { - Point[] needRedraw = null; // returned array of points which need redraw - + private void insertMapArchToPickmap(final Point pos) { final MapControl currentMap = mainControl.getCurrentMap(); // insertion is only allowed for valid *empty* squares if (currentMap != null && mapControl.isPickmap() && mapControl.isPointValid(pos) && !mapControl.containsArchObject(pos)) { @@ -753,7 +687,7 @@ // insert single tile from pickmap newarch = newarch.createClone(pos.x, pos.y); mapControl.addArchObjectToMap(newarch); - needRedraw = mapControl.calcArchRedraw(newarch); + mapControl.calcArchRedraw(newarch); } else { // insert multi tile from pickmap: newarch = newarch.getHead(); @@ -782,14 +716,12 @@ newdef.resetMsgText(); newdef.addMsgText(newarch.getMsgText()); - needRedraw = mapControl.calcArchRedraw(newdef); + mapControl.calcArchRedraw(newdef); } } } } } - - return needRedraw; } void endFill() { @@ -803,6 +735,24 @@ } } + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent e) { + mapGrid.resize(e.getMapModel().getMapSize()); + refreshDataFromModel(); + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent e) { + modelChanged(); + // TODO: only repaint a specific region + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent e) { + modelChanged(); + // TODO: only repaint a specific region + } + public final class CPaintOp implements EditOperation { final Rectangle fillRect; @@ -853,4 +803,18 @@ } } + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + final MapCursor mapCursor = e.getSource(); + if (mapCursor.isActive()) { + final Rectangle rec = renderer.getTileBounds(mapCursor.getLocation()); + renderer.scrollRectToVisible(rec); + } + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + // Ignore mode change events + } + } // class CMapViewBasic Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -139,26 +139,11 @@ * @param mode defines if we have a cut, copy or paste action */ private void copyNCut(final MapControl mapControl, final Mode mode) { - final Point startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect - final Point offset = mapControl.getMapViewFrame().getHighlightOffset(); // offset of rect from startp - - if (!mapControl.getMapViewFrame().isHighlight()) { - return; // should actually never happen + final Rectangle selRec = mapControl.getMapGrid().getSelectedRec(); + if (selRec == null) { + return; } - // convert negative 'offset' into positive by flipping 'startp' - if (offset.x < 0) { - startp.x += offset.x; - offset.x = Math.abs(offset.x); - } - if (offset.y < 0) { - startp.y += offset.y; - offset.y = Math.abs(offset.y); - } - - final Rectangle selRec = new Rectangle(startp.x, startp.y, offset.x, offset.y); - assert selRec != null; - // Prepare the buffer (if it's a cut or copy) if (mode == Mode.DO_CUT || mode == Mode.DO_COPY) { if (empty) { @@ -167,8 +152,8 @@ } // recycle and resize buffer - bufWidth = Math.abs(offset.x) + 1; // new width - bufHeight = Math.abs(offset.y) + 1; // new height + bufWidth = Math.abs(selRec.width) + 1; // new width + bufHeight = Math.abs(selRec.height) + 1; // new height mapArch.setMapSize(new Size2D(bufWidth, bufHeight)); copyMap = null; // free objects (at least that is the plan and theory) copyMapCtrl = null; @@ -180,8 +165,8 @@ final Point pos = new Point(); mapControl.getMapModel().beginTransaction("Cut / Clear"); // TODO: I18N/L10N final HashSet<GameObject> gameObjectsToDelete = new HashSet<GameObject>(); - for (pos.x = startp.x; pos.x - startp.x <= offset.x; pos.x++) { - for (pos.y = startp.y; pos.y - startp.y <= offset.y; pos.y++) { + for (pos.x = selRec.x; pos.x - selRec.x <= selRec.width; pos.x++) { + for (pos.y = selRec.y; pos.y - selRec.y <= selRec.height; pos.y++) { // do the copying for one tile position: for (final GameObject gameObject : mapControl.getMapModel().getMapSquare(pos)) { // store a clone of the gameObject in the CopyBuffer @@ -189,7 +174,7 @@ // arches that don't match the view settings are ignored! if ((mode == Mode.DO_CUT || mode == Mode.DO_COPY) && gameObject.isHead() && !gameObject.isInContainer() && (mainControl.getTileEdit() == 0 || mainControl.isTileEdit(gameObject.getEditType()))) { // copy this gameObject - final GameObject clone = gameObject.createClone(pos.x - startp.x, pos.y - startp.y); + final GameObject clone = gameObject.createClone(pos.x - selRec.x, pos.y - selRec.y); assert copyMapCtrl != null; copyMapCtrl.addArchObjectToMap(clone); } @@ -223,14 +208,12 @@ /** * Excecuting the Paste command. * @param mapControl MapControl of the active map we paste on + * @todo paste only subregions when a region is selected */ public void paste(final MapControl mapControl) { - final Point startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect + final Point startp = mapControl.getMapCursor().getLocation(); + assert startp != null; - if (!mapControl.getMapViewFrame().isHighlight()) { - return; // should actually never happen - } - // cycle through all tile coordinates which are highlighted: mapControl.getMapModel().beginTransaction("Paste"); // TODO: I18N/L10N final Point pos = new Point(); @@ -283,8 +266,8 @@ * @todo the fill density is ignored for floodfill */ public void fill(final MapControl mapControl, final boolean fillBelow, final int density) { - final Point startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect - final Point offset = mapControl.getMapViewFrame().getHighlightOffset(); // offset of rect from startp + final Rectangle selRec = mapControl.getMapGrid().getSelectedRec();; + final Point cursor = mapControl.getMapViewFrame().getView().getCursorPosition(); final Point pos = new Point(); if (!mapControl.getMapViewFrame().isHighlight()) { @@ -295,31 +278,20 @@ return; } - // If offset is zero and map-spot empty, a floodfill is done + // If selection is empty and map-spot empty, a floodfill is done final GameObject arch; - if (offset.x == 0 && offset.y == 0 && !mapControl.containsArchObject(startp)) { + if ((selRec == null || (selRec.x == 0 && selRec.height == 0)) && !mapControl.containsArchObject(cursor)) { arch = mainControl.getArchPanelHighlight(); if (arch != null) { - floodfill(mapControl, startp.x, startp.y, arch); + floodfill(mapControl, cursor.x, cursor.y, arch); } } else { - // Rectangular fill: - // convert negative 'offset' into positive by flipping 'startp' - if (offset.x < 0) { - startp.x += offset.x; - offset.x = Math.abs(offset.x); - } - if (offset.y < 0) { - startp.y += offset.y; - offset.y = Math.abs(offset.y); - } - // get the arch to fill with arch = mainControl.getArchPanelHighlight(); // cycle through all tile coordinates which are highlighted: - for (pos.x = startp.x; pos.x - startp.x <= offset.x; pos.x++) { - for (pos.y = startp.y; pos.y - startp.y <= offset.y; pos.y++) { + for (pos.x = selRec.x; pos.x - selRec.x <= selRec.width; pos.x++) { + for (pos.y = selRec.y; pos.y - selRec.y <= selRec.height; pos.y++) { if (density != -1 && density != 100 && density < MainControl.rnd.nextInt(100) + 1) { continue; } Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -214,6 +214,8 @@ String TILE_SEL_TILE = "seltile.png"; + String TILE_CURSOR = "cursor.png"; + String TILE_UNKNOWN = "unknown.png"; String TILE_NOFACE = "noface.png"; @@ -243,6 +245,14 @@ int BOTTOM = 5; + int NORTH_EAST = 4; + + int SOUTH_EAST = 5; + + int SOUTH_WEST = 6; + + int NORTH_WEST = 7; + int DIRECTIONS = 6; } // interface IGUIConstants Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -111,10 +111,6 @@ // following a bunch of wrapper methods which just pass access // to the basic mapview object 'view': - public Point getMapMouseRightPos() { - return view.getMapMouseRightPos(); - } - public JViewport getViewPort() { return view.getViewport(); } @@ -159,14 +155,6 @@ view.closeNotify(); } - public Point getHighlightStart() { - return view.getHighlightStart(); - } - - public Point getHighlightOffset() { - return view.getHighlightOffset(); - } - public void setHotspot(final Point point) { view.setHotspot(point); } @@ -226,6 +214,10 @@ view.freeMap(); } + public CMapViewBasic getView() { + return view; + } + /** Action class for selecting this window. */ public final class WindowAction extends AbstractAction { Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -28,6 +28,7 @@ import cfeditor.map.MapControl; import java.awt.FlowLayout; import java.awt.Point; +import java.awt.Rectangle; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; @@ -294,20 +295,11 @@ final Size2D mapSize = mapControl.getMapSize(); offset = new Point(mapSize.getWidth() - 1, mapSize.getHeight() - 1); } else { - startp = mapControl.getMapViewFrame().getHighlightStart(); // start of highlighted rect - offset = mapControl.getMapViewFrame().getHighlightOffset(); // offset of rect from startp + final Rectangle selRec = mapControl.getMapGrid().getSelectedRec(); + startp = new Point(selRec.x, selRec.y); + offset = new Point(selRec.width, selRec.height); } - // convert negative 'offset' into positive by flipping 'startp' - if (offset.x < 0) { - startp.x += offset.x; - offset.x = Math.abs(offset.x); - } - if (offset.y < 0) { - startp.y += offset.y; - offset.y = Math.abs(offset.y); - } - // cycle through all tile coordinates between startpoint and offset: final Point pos = new Point(); int replaceCount = 0; Modified: trunk/crossfire/src/cfeditor/action.properties =================================================================== --- trunk/crossfire/src/cfeditor/action.properties 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/action.properties 2006-12-16 21:30:26 UTC (rev 1115) @@ -7,11 +7,12 @@ ######## # Menus -main.menubar=file edit map pickmaps resources tools analyze view plugins window help +main.menubar=file edit map cursor pickmaps resources tools analyze view plugins window help file.menu=createNew open close - save saveAs revert createImg - options - exit edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow map.menu=autoJoin - gridVisible enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterUpperMap enterLowerMap tileShow - mapProperties +cursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes pickmaps.menu=lockAllPickmaps - addNewPickmap closePickmap - openPickmapMap - savePickmap revertPickmap resources.menu=collectArches collectSpells - viewTreasurelists tools.menu=gc @@ -21,11 +22,12 @@ window.menu=closeAll help.menu=onlineHelp about -mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowView +mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor mapwindowView mapwindowFile.menu=save saveAs createImg - revert - close mapwindowEdit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow mapwindowMap.menu=autoJoin - gridVisible enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterUpperMap enterLowerMap tileShow - mapProperties +mapwindowCursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes mapwindowView.menu=showMonster showExit showBackground showDoor showWall showEquipment showTreasure showConnected resetView ####### @@ -72,6 +74,10 @@ mapProperties.icon=general/Properties16 + +moveCursor.menu=goNorth goEast goSouth goWest goNorthEast goSouthEast goSouthWest goNorthWest + + addNewPickmap.icon=general/New16 closePickmap.icon=EmptySmallIcon Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-16 21:22:20 UTC (rev 1114) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -59,7 +59,7 @@ /** * The component that does the actual rendering of tiles in the palette. * Flat version. - * @author unknown (probably Ragnor) +b * @author unknown (probably Ragnor) */ public final class DefaultLevelRenderer extends LevelRenderer implements MapGridListener { @@ -132,6 +132,8 @@ } tmpIcon = new ImageIcon(); + setFocusable(true); + borderOffset = !pickmap ? 32 : 0; renderTransform = new AffineTransform(1.0f, 0.0f, 0.0f, 1.0f, (float) borderOffset, (float) borderOffset); highLightMask = new Color[]{ @@ -209,7 +211,22 @@ } } + private final Rectangle tmpRec = new Rectangle(); + /** + * Get coordinates, length and width of map tile. + * @param p Map coordinates + * @return Boundary rectangle of tile + */ + public Rectangle getTileBounds(final Point p) { + tmpRec.x = borderOffset + p.x * 32; + tmpRec.y = borderOffset + p.y * 32; + tmpRec.width = 32; + tmpRec.height = 32; + return tmpRec; + } + + /** * Paints this component. * @param grfx The graphics context to paint to. * @param isSnapshot true when this drawing is for a @@ -394,63 +411,16 @@ * @param grfx graphics context to draw in */ public void paintHighlightTile(final Graphics grfx, final Point point) { - // if tile is highlighted, draw the highlight icon: - if (mapViewBasic.isHighlight() && mapViewBasic.getMapMouseRightPos().y != -1 && mapViewBasic.getMapMouseRightPos().x != -1) { - // get rect. coords of highlighted area: top(left) and bot(tomright) corner - final int topx = Math.min(mapViewBasic.getMapMouseRightPos().x, mapViewBasic.getMapMouseRightPos().x + mapViewBasic.getHighlightOffset().x); - final int topy = Math.min(mapViewBasic.getMapMouseRightPos().y, mapViewBasic.getMapMouseRightPos().y + mapViewBasic.getHighlightOffset().y); - final int botx = Math.max(mapViewBasic.getMapMouseRightPos().x, mapViewBasic.getMapMouseRightPos().x + mapViewBasic.getHighlightOffset().x); - final int boty = Math.max(mapViewBasic.getMapMouseRightPos().y, mapViewBasic.getMapMouseRightPos().y + mapViewBasic.getHighlightOffset().y); - - // Highlight the selected square - if (point.x >= topx && point.x <= botx && point.y >= topy && point.y <= boty) { - CMainControl.getMapSelIcon().paintIcon(this, grfx, point.x * 32, point.y * 32); - } + final int gridFlags = mapGrid.getFlags(point.x, point.y); + if ((gridFlags & MapGrid.GRID_FLAG_SELECTING) != 0) { + CMainControl.getMapSelIcon().paintIcon(this, grfx, point.x * 32, point.y * 32); } - } - - /** - * Paints the highlighted (selected) area on the map. - * - * @param grfx graphics context of mapview - */ - public void paintHighlightArea(final Graphics grfx) { - final int signX, signY; // sign = "direction" of the dragging offset - - if (mapViewBasic.getHighlightOffset().x > 0) { - signX = 1; - } else if (mapViewBasic.getHighlightOffset().x < 0) { - signX = -1; - } else { - signX = 0; + if ((gridFlags & MapGrid.GRID_FLAG_SELECTION) != 0) { + CMainControl.getMapSelIcon().paintIcon(this, grfx, point.x * 32, point.y * 32); } - - if (mapViewBasic.getHighlightOffset().y > 0) { - signY = 1; - } else if (mapViewBasic.getHighlightOffset().y < 0) { - signY = -1; - } else { - signY = 0; + if ((gridFlags & MapGrid.GRID_FLAG_CURSOR) != 0) { + CMainControl.getMapCursorIcon().paintIcon(this, grfx, point.x * 32, point.y * 32); } - - // Highlight all tiles that are in the rectangle between drag-start and mouse - for (int posx = mapViewBasic.getMapMouseRightPos().x; Math.abs(posx - mapViewBasic.getMapMouseRightPos().x) - <= Math.abs(mapViewBasic.getHighlightOffset().x); posx += signX) { - for (int posy = mapViewBasic.getMapMouseRightPos().y; Math.abs(posy - mapViewBasic.getMapMouseRightPos().y) - <= Math.abs(mapViewBasic.getHighlightOffset().y); posy += signY) { - // Draw the Icon: - - // Rectangular view - CMainControl.getMapSelIcon().paintIcon(this, grfx, posx * 32 + borderOffset, posy * 32 + borderOffset); - - if (signY == 0) { - break; - } - } - if (signX == 0) { - break; - } - } } /** @@ -459,9 +429,21 @@ * @param grfx Graphics for painting */ private void paintSelection(final Graphics2D grfx) { - if (mapViewBasic.isHighlight() && mapViewBasic.getMapMouseRightPos().y != -1 && mapViewBasic.getMapMouseRightPos().x != -1) { - // Highlight the selected area - paintHighlightArea(grfx); + for (int y = 0; y < mapSize.getHeight(); y++) { + for (int x = 0; x < mapSize.getWidth(); x++) { + if (grfx.hitClip(x * 32 + borderOffset, y * 32 + borderOffset, 32, 32)) { + final int gridFlags = mapGrid.getFlags(x, y); + if ((gridFlags & MapGrid.GRID_FLAG_SELECTION) != 0) { + CMainControl.getMapSelIcon().paintIcon(this, grfx, x * 32 + borderOffset, y * 32 + borderOffset); + } + if ((gridFlags & MapGrid.GRID_FLAG_SELECTING) != 0) { + CMainControl.getMapSelIcon().paintIcon(this, grfx, x * 32 + borderOffset, y * 32 + borderOffset); + } + if ((gridFlags & MapGrid.GRID_FLAG_CURSOR) != 0) { + CMainControl.getMapCursorIcon().paintIcon(this, grfx, x * 32 + borderOffset, y * 32 + borderOffset); + } + } + } } } @@ -497,16 +479,17 @@ renderTransform.inverseTransform(point, point); } catch (final NoninvertibleTransformException e) { } - mapViewBasic.setMapMousePos(new Point(-1, -1)); final Size2D mapSize = mapViewBasic.getMapControl().getMapSize(); + final int xm, ym; if (point.x >= 0 && point.x < mapSize.getWidth() * 32 && point.y >= 0 && point.y < mapSize.getHeight() * 32) { - mapViewBasic.setMapMousePos(new Point(point.x / 32, point.y / 32)); + xm = point.x / 32; + ym = point.y / 32; + } else { + xm = -1; + ym = -1; } - final int xm = mapViewBasic.getMapMousePos().x; - final int ym = mapViewBasic.getMapMousePos().y; - if (xm < 0 || xm >= mapSize.getWidth() || ym < 0 || ym >= mapSize.getHeight()) { return null; } @@ -520,13 +503,13 @@ /** {@inheritDoc} */ public void mapGridChanged(@NotNull final MapGridEvent e) { - repaint(); + modelChanged(); } /** {@inheritDoc} */ public void mapGridResized(@NotNull final MapGridEvent e) { mapSize = e.getSource().getSize(); - repaint(); + modelChanged(); } @Override public boolean resizeBackBuffer() { Added: trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-16 21:30:26 UTC (rev 1115) @@ -0,0 +1,213 @@ +/* + * Daimonin Java Editor. + * Copyright (C) 2006 Daniel Viegas + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package cfeditor.gui.map; + +import cfeditor.CMainControl; +import cfeditor.CMainView; +import cfeditor.CMapTileList; +import cfeditor.IGUIConstants; +import cfeditor.gameobject.GameObject; +import cfeditor.map.MapControl; +import java.awt.Point; +import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapGrid; + +/** + * This class processes events from the cursor menu. + * Moving the cursor, selecting map tiles/arches, inserting/deleting arches and open arch property dialog is supported. + * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + */ +public class MapCursorControl { + + /** The MainControl. */ + private final CMainControl mainControl; + + /** + * Create a MapCursorControl. + * @param mainControl MainControl to use (used for getting the current map etc.) + */ + public MapCursorControl(final CMainControl mainControl) { + this.mainControl = mainControl; + } + + /** + * Move cursor to specified direction. + * @param dir Constants in #IGUIConstants + */ + public void goTo(final int dir) { + final MapCursor mapCursor = getMapCursor(); + if (mapCursor.isActive()) { + mapCursor.goTo(dir); + } else { + mapCursor.setLocation(new Point(0, 0)); + } + } + + public void goNorth() { + goTo(IGUIConstants.NORTH); + } + + public void goSouth() { + goTo(IGUIConstants.SOUTH); + } + + public void goEast() { + goTo(IGUIConstants.EAST); + } + + public void goWest() { + goTo(IGUIConstants.WEST); + } + + public void goNorthEast() { + goTo(IGUIConstants.NORTH_EAST); + } + + public void goNorthWest() { + goTo(IGUIConstants.NORTH_WEST); + } + + public void goSouthEast() { + goTo(IGUIConstants.SOUTH_EAST); + } + + public void goSouthWest() { + goTo(IGUIConstants.SOUTH_WEST); + } + + public void selectTile() { + selectTile(MapGrid.SelectionMode.FLIP); + } + + public void addToSelection() { + selectTile(MapGrid.SelectionMode.ADD); + } + + public void subFromSelection() { + selectTile(MapGrid.SelectionMode.SUB); + } + + public void insertArch() { + final MapControl mapControl = mainControl.getCurrentMap(); + assert mapControl != null; + final MapCursor mapCursor = mapControl.getMapCursor(); + assert mapCursor != null; + if (mapCursor.isActive()) { + mapControl.insertSelArchToMap(mapCursor.getLocation(), true); + mainControl.getMain... [truncated message content] |