gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] fenfire/org/fenfire/util ControlBinding.java


From: Matti Katila
Subject: [Gzz-commits] fenfire/org/fenfire/util ControlBinding.java
Date: Sun, 22 Jun 2003 12:14:02 -0400

CVSROOT:        /cvsroot/fenfire
Module name:    fenfire
Branch:         
Changes by:     Matti Katila <address@hidden>   03/06/22 12:14:02

Modified files:
        org/fenfire/util: ControlBinding.java 

Log message:
        add directions

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/util/ControlBinding.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: fenfire/org/fenfire/util/ControlBinding.java
diff -u fenfire/org/fenfire/util/ControlBinding.java:1.2 
fenfire/org/fenfire/util/ControlBinding.java:1.3
--- fenfire/org/fenfire/util/ControlBinding.java:1.2    Thu Jun 19 11:23:44 2003
+++ fenfire/org/fenfire/util/ControlBinding.java        Sun Jun 22 12:14:02 2003
@@ -24,6 +24,14 @@
        DRAG = new Type(),
        WHEEL = new Type();
 
+    /** Direction(s) of controller to use.
+     */
+    public static final class Direction { private Direction() {} }
+    public static final Direction 
+       ALL = new Direction(),
+       HORIZONTAL = new Direction(),
+       VERTICAL = new Direction();
+
 
     static private boolean FAST = true;
     static private boolean ANIMATE = false;
@@ -32,14 +40,26 @@
     // -- Methods to handle events wisely.
 
     private MouseEvent pressState = null;
-    public void removePressState() { pressState = null; lastEvent=null;}
+    public void removePressState() { 
+       pressState = null; 
+       lastEvent = null;
+       accursedObj = null;
+    }
     public boolean hasPressState() { return pressState!=null; }
 
 
+    // keeping track of drags for specific object
+    private Object accursedObj = null;
+
     // for keeping change of dragging.
     private MouseEvent lastEvent;
     public boolean handleEvent(Object forObject, MouseEvent event, 
                                VobScene oldVS) {
+       if (accursedObj == null) 
+           accursedObj = forObject;
+       if (accursedObj == null) throw new Error("No accursed object!");
+       Object object = accursedObj;
+       
         if (event.getID() == event.MOUSE_PRESSED) {
             pressState = event;
             return FAST;
@@ -53,13 +73,16 @@
             for (int i=0; i<wheels.size(); i++) {
                 Event e = (Event)wheels.get(i);
                 Controller c = (Controller)e.obj;
-                c.set(forObject, oldVS);
+                c.set(object, oldVS);
                 float scale = e.scale; 
                 if (e.invert) scale *=-1;
                 MouseWheelEvent ev = (MouseWheelEvent)event;
                 if (c.isChangeable()) {
-                    c.change(ev.getWheelRotation()*scale,
-                             ev.getWheelRotation()*scale);
+                   x = - ev.getWheelRotation()*scale;
+                   y = - ev.getWheelRotation()*scale;
+                   if (e.dir == null) c.change(x,y);
+                   else if (e.dir == HORIZONTAL) c.change(x,0);
+                   else if (e.dir == VERTICAL) c.change(0,y);
                     return FAST;
                 } else {
                     c.controlPoint(x,y, scale);
@@ -74,7 +97,7 @@
                 Event e = (Event)clicks.get(i);
                 Controller c = (Controller)e.obj;
                 if (event.getModifiers() == e.mask) {
-                    c.set(forObject, oldVS);
+                    c.set(object, oldVS);
                     float scale = e.scale; 
                     if (e.invert) scale *=-1;
                     if (c.isChangeable()) 
@@ -89,7 +112,8 @@
             if (dbg) p("No press state!?");
             return FAST;
         }
-        
+
+        boolean ret = FAST;
         if (event.getID() == event.MOUSE_DRAGGED) {
             if (dbg) p("It's a drag!");
             for (int i=0; i<drags.size(); i++) {
@@ -97,25 +121,30 @@
                 Controller c = (Controller)e.obj;
                 if (dbg) p("event: "+event.getButton()+ ", mask: "+e.mask);
                 if (event.getModifiers() == e.mask) {
-                    c.set(forObject, oldVS);
+                    c.set(object, oldVS);
                     float scale = e.scale; 
                     if (e.invert) scale *=-1;
                     if (c.isChangeable()) {
-                        if (lastEvent != null)
-                            c.change((lastEvent.getX()-x)*scale,
-                                     (lastEvent.getY()-y)*scale 
-                                );
-                        else 
-                            c.change((pressState.getX()-x)*scale,
-                                     (pressState.getY()-y)*scale 
-                                );
-                        lastEvent = event; 
-                        return FAST;
+                       MouseEvent last;
+                        if (lastEvent != null) last = lastEvent;
+                       else last = pressState;
+
+                       float dx = (x - last.getX()) * scale;
+                       float dy = (y - last.getY()) * scale; 
+
+                       if (dbg) p("dir: "+e.dir);
+                       if (e.dir == ALL) c.change(dx,dy);
+                       else if (e.dir == HORIZONTAL) c.change(dx,0);
+                       else c.change(0,dy);
+
+                        ret = FAST;
                     }
                     else c.controlPoint(x, y, scale);
-                    return ANIMATE;
+                    ret = ANIMATE;
                 }
             }
+           lastEvent = event; 
+           return ret;
         }
 
         if (dbg) p("No events bound.");
@@ -135,20 +164,21 @@
     /** For example add(foo, WHEEL);
      */
     public void add(Controller controller, Type binding) {
-        add(controller, -1, binding, 1, false);
+        add(controller, -1, binding, 10, false, VERTICAL);
     }
 
     /** For example add(foo, 1, CLICK); or
      * add(bar, 3, DRAG);
      */
     public void add(Controller controller, int button, Type binding) {
-        add(controller, button, binding, 1, false);
+        add(controller, button, binding, 1, false, ALL);
     }
     public void add(Controller controller, int button,
-                    Type binding, float scale, boolean invert) {
+                    Type binding, float scale, boolean invert,
+                   Object direction) {
 
-        if (binding == WHEEL && button==-1) {
-            wheels.add(new Event(controller, -1, scale, invert));
+        if (binding == WHEEL) {
+            wheels.add(new Event(controller, -1, scale, invert, direction));
             return;
         }
 
@@ -162,20 +192,22 @@
         }
 
         if (binding == CLICK) {
-            clicks.add(new Event(controller, mask, scale, invert));
+            clicks.add(new Event(controller, mask, scale, invert, direction));
         } else if (binding == DRAG) {            
-            drags.add(new Event(controller, mask, scale, invert));
+            drags.add(new Event(controller, mask, scale, invert, direction));
         } else throw new Error("Shouldn't be reached.");
     }
     
     class Event {
-        public Object obj;
-        public int mask;
-        public boolean invert;
-        public float scale;
-        public boolean horiz=false;
-        public Event(Object obj, int mask, float scale, boolean invert) {
-            this.obj=obj; this.mask=mask; this.invert=invert; this.scale=scale;
+        final public Object obj;
+        final public int mask;
+        final public boolean invert;
+        final public float scale;
+        final public Object dir;
+        public Event(Object obj, int mask, float scale, 
+                    boolean invert, Object direction) {
+            this.obj=obj; this.mask=mask; this.invert=invert; 
+           this.scale=scale; this.dir=direction;
         }
     }    
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]