/[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.11 by tjl, Sat Aug 2 08:21:47 2003 UTC revision 1.12 by tjl, Sat Aug 2 08:29:54 2003 UTC
# Line 26  ControlBinding.java Line 26  ControlBinding.java
26    
27  package org.fenfire.util;  package org.fenfire.util;
28  import org.nongnu.libvob.VobScene;  import org.nongnu.libvob.VobScene;
29    import org.nongnu.libvob.VobMouseEvent;
30  import java.awt.event.*;  import java.awt.event.*;
31  import java.util.*;  import java.util.*;
32    
# Line 59  public class ControlBinding { Line 60  public class ControlBinding {
60            
61      // -- Methods to handle events wisely.      // -- Methods to handle events wisely.
62    
63      private MouseEvent pressState = null;      private VobMouseEvent pressState = null;
64      public void removePressState() {      public void removePressState() {
65          pressState = null;          pressState = null;
66          lastEvent = null;          lastEvent = null;
# Line 67  public class ControlBinding { Line 68  public class ControlBinding {
68      }      }
69      public boolean hasPressState() { return pressState!=null; }      public boolean hasPressState() { return pressState!=null; }
70    
71      public void setPressStateByForce(MouseEvent event) {      public void setPressStateByForce(VobMouseEvent event) {
72          pressState = event;          pressState = event;
73      }      }
74    
# Line 76  public class ControlBinding { Line 77  public class ControlBinding {
77      private Object accursedObj = null;      private Object accursedObj = null;
78    
79      // for keeping change of dragging.      // for keeping change of dragging.
80      private MouseEvent lastEvent;      private VobMouseEvent lastEvent;
81      public boolean handleEvent(Object forObject, MouseEvent event,      public boolean handleEvent(Object forObject, VobMouseEvent event,
82                                 VobScene oldVS) {                                 VobScene oldVS) {
83          if (accursedObj == null)          if (accursedObj == null)
84              accursedObj = forObject;              accursedObj = forObject;
85          if (forObject == null) throw new Error("Object is null!");          if (forObject == null) throw new Error("Object is null!");
86          Object object = forObject;          Object object = forObject;
87                                    
88          if (event.getID() == event.MOUSE_PRESSED) {          if (event.getType() == event.MOUSE_PRESSED) {
89              pressState = event;              pressState = event;
90              return FAST;              return FAST;
91          }          }
# Line 105  public class ControlBinding { Line 106  public class ControlBinding {
106          float x = event.getX();          float x = event.getX();
107          float y = event.getY();          float y = event.getY();
108                    
109          if (event.getID() == event.MOUSE_WHEEL) {          if (event.getType() == event.MOUSE_WHEEL) {
110              if (dbg) p("It's wheel!");              if (dbg) p("It's wheel!");
111              for (int i=0; i<wheels.size(); i++) {              for (int i=0; i<wheels.size(); i++) {
112                  Event e = (Event)wheels.get(i);                  Event e = (Event)wheels.get(i);
# Line 113  public class ControlBinding { Line 114  public class ControlBinding {
114                  c.set(object, oldVS);                  c.set(object, oldVS);
115                  float scale = e.scale;                  float scale = e.scale;
116                  if (e.invert) scale *=-1;                  if (e.invert) scale *=-1;
                 MouseWheelEvent ev = (MouseWheelEvent)event;  
117                  if (c.isChangeable()) {                  if (c.isChangeable()) {
118                      x = - ev.getWheelRotation()*scale;                      x = - event.getWheelDelta()*scale;
119                      y = - ev.getWheelRotation()*scale;                      y = - event.getWheelDelta()*scale;
120                      if (e.dir == null) c.change(x,y);                      if (e.dir == null) c.change(x,y);
121                      else if (e.dir == HORIZONTAL) c.change(x,0);                      else if (e.dir == HORIZONTAL) c.change(x,0);
122                      else if (e.dir == VERTICAL) c.change(0,y);                      else if (e.dir == VERTICAL) c.change(0,y);
# Line 128  public class ControlBinding { Line 128  public class ControlBinding {
128              }              }
129          }          }
130    
131          if (event.getID() == event.MOUSE_CLICKED) {          if (event.getType() == event.MOUSE_CLICKED) {
132              if (dbg) p("It's click!");              if (dbg) p("It's click!");
133              for (int i=0; i<clicks.size(); i++) {              for (int i=0; i<clicks.size(); i++) {
134                  Event e = (Event)clicks.get(i);                  Event e = (Event)clicks.get(i);
135                  Controller c = (Controller)e.obj;                  Controller c = (Controller)e.obj;
136                  if (event.getModifiers() == e.mask) {                  if (e.matches(event)) {
137                      c.set(object, oldVS);                      c.set(object, oldVS);
138                      float scale = e.scale;                      float scale = e.scale;
139                      if (e.invert) scale *=-1;                      if (e.invert) scale *=-1;
# Line 153  public class ControlBinding { Line 153  public class ControlBinding {
153          if (accursedObj == null) throw new Error("No accursed object!");          if (accursedObj == null) throw new Error("No accursed object!");
154          object = accursedObj;          object = accursedObj;
155          boolean ret = FAST;          boolean ret = FAST;
156          if (event.getID() == event.MOUSE_DRAGGED) {          if (event.getType() == event.MOUSE_DRAGGED) {
157              if (dbg) p("It's a drag!");              if (dbg) p("It's a drag!");
158              for (int i=0; i<drags.size(); i++) {              for (int i=0; i<drags.size(); i++) {
159                  Event e = (Event)drags.get(i);                  Event e = (Event)drags.get(i);
160                  Controller c = (Controller)e.obj;                  Controller c = (Controller)e.obj;
161                  if (dbg) p("event: "+event.getButton()+ ", mask: "+e.mask);                  if (dbg) p("event: "+event.getButton()+ ", mask: "+e.button);
162                  if (event.getModifiers() == e.mask) {                  if (e.matches(event)) {
163                      c.set(object, oldVS);                      c.set(object, oldVS);
164                      float scale = e.scale;                      float scale = e.scale;
165                      if (e.invert) scale *=-1;                      if (e.invert) scale *=-1;
166                      if (c.isChangeable()) {                      if (c.isChangeable()) {
167                          MouseEvent last;                          VobMouseEvent last;
168                          if (lastEvent != null) last = lastEvent;                          if (lastEvent != null) last = lastEvent;
169                          else last = pressState;                          else last = pressState;
170    
# Line 203  public class ControlBinding { Line 203  public class ControlBinding {
203      /** For example add(foo, WHEEL);      /** For example add(foo, WHEEL);
204       */       */
205      public void add(Controller controller, Type binding) {      public void add(Controller controller, Type binding) {
206          add(controller, -1, binding, 10, false, VERTICAL);          add(controller, -1, 0, binding, 10, false, VERTICAL);
207      }      }
208    
209      /** For example add(foo, 1, CLICK); or      /** For example add(foo, 1, CLICK); or
210       * add(bar, 3, DRAG);       * add(bar, 3, DRAG);
211       */       */
212      public void add(Controller controller, int button, Type binding) {      public void add(Controller controller, int button, Type binding) {
213          add(controller, button, binding, 1, false, ALL);          add(controller, button, 0, binding, 1, false, ALL);
214      }      }
215      public void add(Controller controller, int button,      public void add(Controller controller, int button,
216                        int modifiers,
217                      Type binding, float scale, boolean invert,                      Type binding, float scale, boolean invert,
218                      Object direction) {                      Object direction) {
219    
220          if (binding == WHEEL) {          if (binding == WHEEL) {
221              wheels.add(new Event(controller, -1, scale, invert, direction));              wheels.add(new Event(controller, -1, modifiers,
222                                scale, invert, direction));
223              return;              return;
224          }          }
225    
226          int mask;          Event ev = new Event(controller, button, modifiers,
227          switch (button) {                          scale, invert, direction);
         case 1 : mask = MouseEvent.BUTTON1_MASK; break;  
         case 2 : mask = MouseEvent.BUTTON2_MASK; break;  
         case 3 : mask = MouseEvent.BUTTON3_MASK; break;              
         default:  
             throw new Error("No button defined '"+button+"'.");  
         }  
   
228          if (binding == CLICK) {          if (binding == CLICK) {
229              clicks.add(new Event(controller, mask, scale, invert, direction));              clicks.add(ev);
230          } else if (binding == DRAG) {                      } else if (binding == DRAG) {            
231              drags.add(new Event(controller, mask, scale, invert, direction));              drags.add(ev);
232          } else throw new Error("Shouldn't be reached.");          } else throw new Error("Shouldn't be reached.");
233      }      }
234            
235      class Event {      class Event {
236          final public Object obj;          final public Object obj;
         final public int modifiers;  
237          final public int button;          final public int button;
238            final public int modifiers;
239          final public boolean invert;          final public boolean invert;
240          final public float scale;          final public float scale;
241          final public Object dir;          final public Object dir;
242          public Event(Object obj, int modifiers, int button,          public Event(Object obj, int button, int modifiers,
243                          float scale,                          float scale,
244                       boolean invert, Object direction) {                       boolean invert, Object direction) {
245              this.obj=obj; this.mask=mask; this.invert=invert;              this.obj=obj; this.button=button;
246                this.modifiers = modifiers; this.invert=invert;
247              this.scale=scale; this.dir=direction;              this.scale=scale; this.dir=direction;
248          }          }
249          public boolean matches(VobMouseEvent event) {          public boolean matches(VobMouseEvent event) {

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

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