We have implemented what we believe to be a solid fix to an issue that was
happening with autoscrolling. If you were moving the mouse to the edge of the
screen, it works very well in that you can move it all the way to the left,
right, or bottom of the screen, and it automatically moves the window. However,
it doesn't work very well when trying to autoscroll up, since the MouseMotion
events don't register in the menu, so you have to get it to within one pixel of
the top of the screen, not including the menu.
Our fix adds a very simple MouseMotionListener to the menu of the Map Editor
and the In-Game menu, so that you can simply move your mouse to the very top of
the screen, and it will autoscroll up. To make this happen smoothly, we
disabled the autoscrolling at the point where the menu meets the canvas. That
is, if you move your mouse to exactly one pixel below the menubar, it won't
autoscroll anymore.
The patch is attached. Please let us know if there are any issues.
-Charlie and Saagar
Index: src/net/sf/freecol/client/gui/CanvasMapEditorMouseListener.java
===================================================================
--- src/net/sf/freecol/client/gui/CanvasMapEditorMouseListener.java
(revision 10243)
+++ src/net/sf/freecol/client/gui/CanvasMapEditorMouseListener.java
(working copy)
@@ -250,7 +250,9 @@
if (getMap() == null) {
return;
}
-
+ if (e.getY() < AUTO_SCROLLSPACE){
+ return; // handle this in the menu bar
+ }
performAutoScrollIfActive(e);
}
Index: src/net/sf/freecol/client/gui/AbstractCanvasListener.java
===================================================================
--- src/net/sf/freecol/client/gui/AbstractCanvasListener.java (revision 10243)
+++ src/net/sf/freecol/client/gui/AbstractCanvasListener.java (working copy)
@@ -12,7 +12,7 @@
protected ScrollThread scrollThread;
protected FreeColClient freeColClient;
private static final int DRAG_SCROLLSPACE = 100;
- private static final int AUTO_SCROLLSPACE = 1;
+ protected static final int AUTO_SCROLLSPACE = 1;
public AbstractCanvasListener(FreeColClient freeColClient, MapViewer
mapViewer) {
this.freeColClient = freeColClient;
@@ -32,7 +32,7 @@
if (e.getComponent().isEnabled()
&& freeColClient.getClientOptions()
.getBoolean(ClientOptions.AUTO_SCROLL)) {
- autoScroll(e.getX(), e.getY());
+ autoScroll(e.getX(), e.getY());
} else
stopScrollIfScrollIsActive();
}
Index: src/net/sf/freecol/client/gui/CanvasMouseMotionListener.java
===================================================================
--- src/net/sf/freecol/client/gui/CanvasMouseMotionListener.java
(revision 10243)
+++ src/net/sf/freecol/client/gui/CanvasMouseMotionListener.java
(working copy)
@@ -61,7 +61,9 @@
*/
public void mouseMoved(MouseEvent e) {
- performAutoScrollIfActive(e);
+ if (e.getY() >= AUTO_SCROLLSPACE){
+ performAutoScrollIfActive(e);
+ }
if (mapViewer.isGotoStarted()) {
if (mapViewer.getActiveUnit() == null) {
Index: src/net/sf/freecol/client/gui/menu/MenuMouseMotionListener.java
===================================================================
--- src/net/sf/freecol/client/gui/menu/MenuMouseMotionListener.java
(revision 0)
+++ src/net/sf/freecol/client/gui/menu/MenuMouseMotionListener.java
(revision 0)
@@ -0,0 +1,40 @@
+package net.sf.freecol.client.gui.menu;
+
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+
+import net.sf.freecol.client.FreeColClient;
+import net.sf.freecol.client.gui.AbstractCanvasListener;
+import net.sf.freecol.client.gui.MapViewer;
+
+/**
+ * This class is meant to make the autoscrolling work better, so that you don't
+ * have to hover the mouse exactly one pixel below the menu bar to make it
+ * scroll up. This is the MouseMotionListener added to the menu bar, allowing
+ * you to scroll by just moving the mouse all the way to the top of the screen.
+ *
+ * Note: This doesn't cause it to scroll down when you reach the bottom of the
+ * menu bar, because the performAutoScrollIfActive will compare the Y
+ * coordinate to the size of the entire canvas (which should always be bigger).
+ *
+ */
+public class MenuMouseMotionListener extends AbstractCanvasListener implements
MouseMotionListener {
+
+ public MenuMouseMotionListener(FreeColClient freeColClient, MapViewer
mapViewer) {
+ super(freeColClient, mapViewer);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ //Don't do anything
+ return;
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ performAutoScrollIfActive(e);
+ }
+
+
+}
Index: src/net/sf/freecol/client/gui/menu/InGameMenuBar.java
===================================================================
--- src/net/sf/freecol/client/gui/menu/InGameMenuBar.java (revision 10243)
+++ src/net/sf/freecol/client/gui/menu/InGameMenuBar.java (working copy)
@@ -82,6 +82,9 @@
super(f, gui);
+ //add a mouse listener so that autoscrolling can happen in this menubar
+ this.addMouseMotionListener(new MenuMouseMotionListener(f,
gui.getMapViewer()));
+
reset();
}
Index: src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java
===================================================================
--- src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java (revision 10243)
+++ src/net/sf/freecol/client/gui/menu/MapEditorMenuBar.java (working copy)
@@ -77,6 +77,9 @@
public MapEditorMenuBar(final FreeColClient freeColClient, GUI gui) {
super(freeColClient, gui);
+ //add a mouse listener so that autoscrolling can happen in this menubar
+ this.addMouseMotionListener(new MenuMouseMotionListener(freeColClient,
gui.getMapViewer()));
+
reset();
}
------------------------------------------------------------------------------
WINDOWS 8 is here.
Millions of people. Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/
_______________________________________________
Freecol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freecol-developers