/[gzz]/gzz/gzz/modules/pp/PPMouseEvents.java
ViewVC logotype

Diff of /gzz/gzz/modules/pp/PPMouseEvents.java

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

revision 1.7 by mudyc, Mon Dec 23 10:40:17 2002 UTC revision 1.8 by mudyc, Mon Dec 23 14:00:11 2002 UTC
# Line 1  Line 1 
1    
2    
3  // (c) Matti Katila  // (c) Matti Katila, Tuukka Hastrup and Tuomas Lukka
4    
5    
6  package gzz.modules.pp;  package gzz.modules.pp;
# Line 11  import gzz.vob.impl.*; Line 11  import gzz.vob.impl.*;
11    
12  import gzz.view.AbstractViewContext;  import gzz.view.AbstractViewContext;
13  import gzz.client.AbstractUpdateManager;  import gzz.client.AbstractUpdateManager;
14    import gzz.client.Params;
15    
16  import java.awt.event.*;  import java.awt.event.*;
17    
# Line 36  public class PPMouseEvents { Line 37  public class PPMouseEvents {
37      // set from outside      // set from outside
38      public VobScene vs;      public VobScene vs;
39      public AbstractViewContext context;      public AbstractViewContext context;
   
40    
41      public PPMouseEvents(PPView2 pv, PPActions pa, Space s) {      public PPMouseEvents(PPView2 pv, PPActions pa, Space s) {
42          this.ppv = pv;          this.ppv = pv;
# Line 62  public class PPMouseEvents { Line 62  public class PPMouseEvents {
62          // Main paper          // Main paper
63          EventHandling.i().assign("Click MAINVP", new SetCursorToMain() );          EventHandling.i().assign("Click MAINVP", new SetCursorToMain() );
64          EventHandling.i().assign("Drag MAINVP", new DragMainVP() );          EventHandling.i().assign("Drag MAINVP", new DragMainVP() );
65    
66            // Main paper object events
67            EventHandling.i().assign("DragObjectOfMainVP", new DragObjectOfMainVP() );
68      }      }
69    
70      /* Save press state      /* Save press state
71       * ================       * ================
72       */       */
73      protected float last_zoom, last_panx, last_pany;      private int kingCS;
74        public void setKingCS(int frame) { kingCS = frame; }
75    
76        private Cell accursed_obj = null;
77        private int[] orig_obj_pt = null;
78    
79        private float last_zoom, last_panx, last_pany;
80      public class SavePressState implements EventHandling.EventMouseObj {      public class SavePressState implements EventHandling.EventMouseObj {
81          public void event(MouseEvent ev, EventHandling.MousePressState p_state,          public void event(MouseEvent ev, EventHandling.MousePressState p_state,
82                            Object[] obs) {                            Object[] obs) {
83                  m_ev.last_zoom = ppv.zoom;              m_ev.last_zoom = ppv.zoom;
84                  m_ev.last_panx = ppv.panx;              m_ev.last_panx = ppv.panx;
85                  m_ev.last_pany = ppv.pany;              m_ev.last_pany = ppv.pany;
86    
87                m_ev.accursed_obj = null;
88    
89    
90                // KLUDGE!!!
91                // there are no good way in gzz to handle events :/
92                if (p_state.getCS() == kingCS) {
93                    if(notEmptyFrame(kingCS, p_state)) {
94                        float hit[] = new float[2];
95                        int objCS = getTouchedCS(kingCS, p_state, hit);
96    
97                        Object k = vs.matcher.getKey(objCS);
98                        if (k == null) {
99                            pa("NULLLI!!");
100                            return;
101                        }
102    
103                        pa("Hit: "+objCS+" "+k+" "+hit[0]+" "+hit[1]);
104                        if(!(k instanceof Cell)) {
105                            pa("Not a cell?!");
106                            return ;
107                        }
108                        m_ev.accursed_obj = (Cell)k;
109                        m_ev.orig_obj_pt = getNoteXY(m_ev.accursed_obj);
110    
111                        context.setAccursed((Cell)k);
112                        context.setCursorOffset(ppv.style.getOffsetInText(((Cell)k).t(), 1, hit[0]));
113                    }
114                }
115          }          }
116      }      }
117            
# Line 99  public class PPMouseEvents { Line 137  public class PPMouseEvents {
137          public void event(MouseEvent ev, EventHandling.MousePressState p_state,          public void event(MouseEvent ev, EventHandling.MousePressState p_state,
138                            Object[] obs) {                            Object[] obs) {
139    
140                pa("disabled demo-efect :)");
141              /** uncomment if you need this in demo              /** uncomment if you need this in demo
142               *  ----------------------------------               *  ----------------------------------
143               */               */
# Line 106  public class PPMouseEvents { Line 145  public class PPMouseEvents {
145              /*              /*
146              try {              try {
147                  JFileChooser fc = new JFileChooser();                  JFileChooser fc = new JFileChooser();
148                  int returnVal = fc.showOpenDialog(null);                  int returnVal = fc.showOpenDialog(null);
149                    
150                  if (returnVal == JFileChooser.APPROVE_OPTION) {                  if (returnVal == JFileChooser.APPROVE_OPTION) {
151                      File file = fc.getSelectedFile();                      File file = fc.getSelectedFile();
152                      Cell c = context.getAccursed();                      Cell c = context.getAccursed();
153                      // XXX no checks!!                      // XXX no checks!!
154                      ppactions.newNote(c.h(ppv.d.contains).getId(),                      ppactions.newNote(c.h(ppv.d.contains).getId(),
155                                        (int)ppv.panx, (int)ppv.pany,                (int)ppv.panx, (int)ppv.pany,
156                                        "IMG:" + file.getPath());                                        "IMG:" + file.getPath());
157                  } else {                  } else {
158                      pa("Open command cancelled by user.");                      pa("Open command cancelled by user.");
159                  }                  }
160              } catch (Exception e) { pa(e.getMessage()); }              } catch (Exception e) { pa(e.getMessage()); }
161              AbstractUpdateManager.chg();              AbstractUpdateManager.chg();
162              */              */
# Line 181  public class PPMouseEvents { Line 220  public class PPMouseEvents {
220                            Object[] obs) {                            Object[] obs) {
221              // obs{ mainctr, frame }              // obs{ mainctr, frame }
222    
             int frameCS = ((Integer)obs[1]).intValue();  
223              int mainctrCS = ((Integer)obs[0]).intValue();              int mainctrCS = ((Integer)obs[0]).intValue();
224                int frameCS = ((Integer)obs[1]).intValue();
225    
226                if (m_ev.accursed_obj != null) {
227                    pa("send event forwarded...");
228                }
229    
230              float[] hit = new float[2];              float[] hit = new float[2];
231              int vobcs = vs.coords.getCSAt( frameCS, ev.getX(), ev.getY(), hit);              int vobcs = vs.coords.getCSAt( frameCS, ev.getX(), ev.getY(), hit);
# Line 220  public class PPMouseEvents { Line 263  public class PPMouseEvents {
263      /* DRAGGING!      /* DRAGGING!
264       * =========       * =========
265       */       */
   
266      public class DragMainVP implements EventHandling.EventMouseObj {      public class DragMainVP implements EventHandling.EventMouseObj {
267          public void event(MouseEvent ev, EventHandling.MousePressState p_state, Object[] obs) {          public void event(MouseEvent ev, EventHandling.MousePressState p_state, Object[] obs) {
268                // obs{ mainctr, frame }
269    
270                int frameCS = ((Integer)obs[1]).intValue();
271    
272              // zoom              // set pan
273                context.setAccursed(context.getAccursed().h(ppv.d.contains));
274      
275                // Zooming
276              if (p_state.getButtons() == ev.BUTTON3_MASK) {              if (p_state.getButtons() == ev.BUTTON3_MASK) {
277                  ppv.zoom = m_ev.last_zoom * (float)                  ppv.zoom = m_ev.last_zoom * (float)
278                      Math.exp((p_state.getY() - ev.getY())/150.0);                      Math.exp((p_state.getY() - ev.getY())/150.0);
279                  pa(""+ppv.zoom);                  pa(""+ppv.zoom);
280              }              }
281              // moving in mainVP              // moving in mainVP and event passing
282              else if (p_state.getButtons() == ev.BUTTON1_MASK) {              else if (p_state.getButtons() == ev.BUTTON1_MASK) {
283                  ppv.panx = m_ev.last_panx - (ev.getX() - p_state.getX())/ppv.zoom;  
284                  ppv.pany = m_ev.last_pany - (ev.getY() - p_state.getY())/ppv.zoom;                  // pass event to object on paper
285                    if (m_ev.accursed_obj != null) {
286                        EventHandling.i().passEvent("DragObjectOfMainVP", ev, null);
287    
288                        // and move paper inverse direction
289                        ppv.panx = m_ev.last_panx + (ev.getX() - p_state.getX())/ppv.zoom;
290                        ppv.pany = m_ev.last_pany + (ev.getY() - p_state.getY())/ppv.zoom;
291                    }
292                    // moving around
293                    else {
294                        ppv.panx = m_ev.last_panx - (ev.getX() - p_state.getX())/ppv.zoom;
295                        ppv.pany = m_ev.last_pany - (ev.getY() - p_state.getY())/ppv.zoom;
296                    }
297              } else return;              } else return;
               
             ppv.setZoomPan(vs);  
298    
299                ppv.setZoomPan(vs);
300                
301              AbstractUpdateManager.setNoAnimation();              AbstractUpdateManager.setNoAnimation();
302              AbstractUpdateManager.chg();              AbstractUpdateManager.chg();
303          }          }
304      }      }
305    
306    
     /* Help methods  
      * ============  
      */  
307    
308        public class DragObjectOfMainVP implements EventHandling.EventMouseObj {
309            public void event(MouseEvent ev, EventHandling.MousePressState p_state, Object[] obs) {
310                // obs{ mainctr, frame }
311    
312      private int press_was_something(int frameCS) {              if(m_ev.accursed_obj == null) throw new Error("Object cell is NULL!!");
313              float[] hit = new float[2];              int x, y;
314              int vobcs = vs.coords.getCSAt( frameCS, ev.getX(), ev.getY(), hit);              x = (int)(orig_obj_pt[0] + 2*( ev.getX()-p_state.getX()) / ppv.zoom);
315              if(vobcs < 0) {              y = (int)(orig_obj_pt[1] + 2*( ev.getY()-p_state.getY()) / ppv.zoom);
316    
317                try {
318                    ppactions.moveNote(accursed_obj.getId(), x, y);
319                } catch(Exception e) { pa(e.getMessage()); }
320            }
321        }
322        
323        
324    
325    
326    
327        /* Help methods
328         * ============
329         */
330    
331        private boolean notEmptyFrame(int frameCS, EventHandling.MousePressState p_state) {
332            float[] hit = new float[2];
333            int vobcs = vs.coords.getCSAt( frameCS, p_state.getX(), p_state.getY(), hit);
334            if(vobcs < 0) return false;
335            else return true;
336        }
337    
338        
339        private int getTouchedCS(int frameCS, EventHandling.MousePressState p_state, float[] hit) {
340            hit = new float[2];
341            return vs.coords.getCSAt( frameCS, p_state.getX(), p_state.getY(), hit);
342        }
343    
344    
345        int[] getNoteXY(Cell note) {
346            if(note.s(ppv.d.pan) == null) {
347                pa("found null from cell's pan");
348                return null;
349            }
350            return Params.getInts(note.s(ppv.d.pan), ppv.d.pan, 2, null);
351        }
352  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

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