/[fenfire]/fenfire/org/fenfire/util/ControlBinding.java
ViewVC logotype

Diff of /fenfire/org/fenfire/util/ControlBinding.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by benja, Thu Jun 19 15:23:44 2003 UTC revision 1.3 by mudyc, Sun Jun 22 16:14:02 2003 UTC
# Line 24  public class ControlBinding { Line 24  public class ControlBinding {
24          DRAG = new Type(),          DRAG = new Type(),
25          WHEEL = new Type();          WHEEL = new Type();
26    
27        /** Direction(s) of controller to use.
28         */
29        public static final class Direction { private Direction() {} }
30        public static final Direction
31            ALL = new Direction(),
32            HORIZONTAL = new Direction(),
33            VERTICAL = new Direction();
34    
35    
36      static private boolean FAST = true;      static private boolean FAST = true;
37      static private boolean ANIMATE = false;      static private boolean ANIMATE = false;
# Line 32  public class ControlBinding { Line 40  public class ControlBinding {
40      // -- Methods to handle events wisely.      // -- Methods to handle events wisely.
41    
42      private MouseEvent pressState = null;      private MouseEvent pressState = null;
43      public void removePressState() { pressState = null; lastEvent=null;}      public void removePressState() {
44            pressState = null;
45            lastEvent = null;
46            accursedObj = null;
47        }
48      public boolean hasPressState() { return pressState!=null; }      public boolean hasPressState() { return pressState!=null; }
49    
50    
51        // keeping track of drags for specific object
52        private Object accursedObj = null;
53    
54      // for keeping change of dragging.      // for keeping change of dragging.
55      private MouseEvent lastEvent;      private MouseEvent lastEvent;
56      public boolean handleEvent(Object forObject, MouseEvent event,      public boolean handleEvent(Object forObject, MouseEvent event,
57                                 VobScene oldVS) {                                 VobScene oldVS) {
58            if (accursedObj == null)
59                accursedObj = forObject;
60            if (accursedObj == null) throw new Error("No accursed object!");
61            Object object = accursedObj;
62            
63          if (event.getID() == event.MOUSE_PRESSED) {          if (event.getID() == event.MOUSE_PRESSED) {
64              pressState = event;              pressState = event;
65              return FAST;              return FAST;
# Line 53  public class ControlBinding { Line 73  public class ControlBinding {
73              for (int i=0; i<wheels.size(); i++) {              for (int i=0; i<wheels.size(); i++) {
74                  Event e = (Event)wheels.get(i);                  Event e = (Event)wheels.get(i);
75                  Controller c = (Controller)e.obj;                  Controller c = (Controller)e.obj;
76                  c.set(forObject, oldVS);                  c.set(object, oldVS);
77                  float scale = e.scale;                  float scale = e.scale;
78                  if (e.invert) scale *=-1;                  if (e.invert) scale *=-1;
79                  MouseWheelEvent ev = (MouseWheelEvent)event;                  MouseWheelEvent ev = (MouseWheelEvent)event;
80                  if (c.isChangeable()) {                  if (c.isChangeable()) {
81                      c.change(ev.getWheelRotation()*scale,                      x = - ev.getWheelRotation()*scale;
82                               ev.getWheelRotation()*scale);                      y = - ev.getWheelRotation()*scale;
83                        if (e.dir == null) c.change(x,y);
84                        else if (e.dir == HORIZONTAL) c.change(x,0);
85                        else if (e.dir == VERTICAL) c.change(0,y);
86                      return FAST;                      return FAST;
87                  } else {                  } else {
88                      c.controlPoint(x,y, scale);                      c.controlPoint(x,y, scale);
# Line 74  public class ControlBinding { Line 97  public class ControlBinding {
97                  Event e = (Event)clicks.get(i);                  Event e = (Event)clicks.get(i);
98                  Controller c = (Controller)e.obj;                  Controller c = (Controller)e.obj;
99                  if (event.getModifiers() == e.mask) {                  if (event.getModifiers() == e.mask) {
100                      c.set(forObject, oldVS);                      c.set(object, oldVS);
101                      float scale = e.scale;                      float scale = e.scale;
102                      if (e.invert) scale *=-1;                      if (e.invert) scale *=-1;
103                      if (c.isChangeable())                      if (c.isChangeable())
# Line 89  public class ControlBinding { Line 112  public class ControlBinding {
112              if (dbg) p("No press state!?");              if (dbg) p("No press state!?");
113              return FAST;              return FAST;
114          }          }
115            
116            boolean ret = FAST;
117          if (event.getID() == event.MOUSE_DRAGGED) {          if (event.getID() == event.MOUSE_DRAGGED) {
118              if (dbg) p("It's a drag!");              if (dbg) p("It's a drag!");
119              for (int i=0; i<drags.size(); i++) {              for (int i=0; i<drags.size(); i++) {
# Line 97  public class ControlBinding { Line 121  public class ControlBinding {
121                  Controller c = (Controller)e.obj;                  Controller c = (Controller)e.obj;
122                  if (dbg) p("event: "+event.getButton()+ ", mask: "+e.mask);                  if (dbg) p("event: "+event.getButton()+ ", mask: "+e.mask);
123                  if (event.getModifiers() == e.mask) {                  if (event.getModifiers() == e.mask) {
124                      c.set(forObject, oldVS);                      c.set(object, oldVS);
125                      float scale = e.scale;                      float scale = e.scale;
126                      if (e.invert) scale *=-1;                      if (e.invert) scale *=-1;
127                      if (c.isChangeable()) {                      if (c.isChangeable()) {
128                          if (lastEvent != null)                          MouseEvent last;
129                              c.change((lastEvent.getX()-x)*scale,                          if (lastEvent != null) last = lastEvent;
130                                       (lastEvent.getY()-y)*scale                          else last = pressState;
131                                  );  
132                          else                          float dx = (x - last.getX()) * scale;
133                              c.change((pressState.getX()-x)*scale,                          float dy = (y - last.getY()) * scale;
134                                       (pressState.getY()-y)*scale  
135                                  );                          if (dbg) p("dir: "+e.dir);
136                          lastEvent = event;                          if (e.dir == ALL) c.change(dx,dy);
137                          return FAST;                          else if (e.dir == HORIZONTAL) c.change(dx,0);
138                            else c.change(0,dy);
139    
140                            ret = FAST;
141                      }                      }
142                      else c.controlPoint(x, y, scale);                      else c.controlPoint(x, y, scale);
143                      return ANIMATE;                      ret = ANIMATE;
144                  }                  }
145              }              }
146                lastEvent = event;
147                return ret;
148          }          }
149    
150          if (dbg) p("No events bound.");          if (dbg) p("No events bound.");
# Line 135  public class ControlBinding { Line 164  public class ControlBinding {
164      /** For example add(foo, WHEEL);      /** For example add(foo, WHEEL);
165       */       */
166      public void add(Controller controller, Type binding) {      public void add(Controller controller, Type binding) {
167          add(controller, -1, binding, 1, false);          add(controller, -1, binding, 10, false, VERTICAL);
168      }      }
169    
170      /** For example add(foo, 1, CLICK); or      /** For example add(foo, 1, CLICK); or
171       * add(bar, 3, DRAG);       * add(bar, 3, DRAG);
172       */       */
173      public void add(Controller controller, int button, Type binding) {      public void add(Controller controller, int button, Type binding) {
174          add(controller, button, binding, 1, false);          add(controller, button, binding, 1, false, ALL);
175      }      }
176      public void add(Controller controller, int button,      public void add(Controller controller, int button,
177                      Type binding, float scale, boolean invert) {                      Type binding, float scale, boolean invert,
178                        Object direction) {
179    
180          if (binding == WHEEL && button==-1) {          if (binding == WHEEL) {
181              wheels.add(new Event(controller, -1, scale, invert));              wheels.add(new Event(controller, -1, scale, invert, direction));
182              return;              return;
183          }          }
184    
# Line 162  public class ControlBinding { Line 192  public class ControlBinding {
192          }          }
193    
194          if (binding == CLICK) {          if (binding == CLICK) {
195              clicks.add(new Event(controller, mask, scale, invert));              clicks.add(new Event(controller, mask, scale, invert, direction));
196          } else if (binding == DRAG) {                      } else if (binding == DRAG) {            
197              drags.add(new Event(controller, mask, scale, invert));              drags.add(new Event(controller, mask, scale, invert, direction));
198          } else throw new Error("Shouldn't be reached.");          } else throw new Error("Shouldn't be reached.");
199      }      }
200            
201      class Event {      class Event {
202          public Object obj;          final public Object obj;
203          public int mask;          final public int mask;
204          public boolean invert;          final public boolean invert;
205          public float scale;          final public float scale;
206          public boolean horiz=false;          final public Object dir;
207          public Event(Object obj, int mask, float scale, boolean invert) {          public Event(Object obj, int mask, float scale,
208              this.obj=obj; this.mask=mask; this.invert=invert; this.scale=scale;                       boolean invert, Object direction) {
209                this.obj=obj; this.mask=mask; this.invert=invert;
210                this.scale=scale; this.dir=direction;
211          }          }
212      }          }    
213    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26