gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gzz/modules/pp EventHandling.java PPMouseEv...


From: Matti Katila
Subject: [Gzz-commits] gzz/gzz/modules/pp EventHandling.java PPMouseEv...
Date: Mon, 23 Dec 2002 09:00:11 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Matti Katila <address@hidden>   02/12/23 09:00:11

Modified files:
        gzz/modules/pp : EventHandling.java PPMouseEvents.java 
                         PPView2.java 

Log message:
        Added some bad infrastructure for moving notes.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/EventHandling.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/PPMouseEvents.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/modules/pp/PPView2.java.diff?tr1=1.29&tr2=1.30&r1=text&r2=text

Patches:
Index: gzz/gzz/modules/pp/EventHandling.java
diff -u gzz/gzz/modules/pp/EventHandling.java:1.5 
gzz/gzz/modules/pp/EventHandling.java:1.6
--- gzz/gzz/modules/pp/EventHandling.java:1.5   Sun Dec 22 07:26:44 2002
+++ gzz/gzz/modules/pp/EventHandling.java       Mon Dec 23 09:00:11 2002
@@ -56,10 +56,11 @@
        ev_handlers.put(key, obs);
     }
 
-    /** If someone wants to pass new time the event call
+    /** If someone wants to pass the event call to others 
      */
     public void passEvent(String key, MouseEvent ev, Object[] obs) {
        Object ev_h = ev_handlers.get(key);
+       if (ev_h == null) throw new Error("Null found in passed events");
        if (ev_h instanceof EventMouseObj) 
            ((EventMouseObj)ev_h).event(ev, press_state, obs);
     }
@@ -94,7 +95,7 @@
        switch(ev.getID()) {
        case MouseEvent.MOUSE_PRESSED: {
            press_state = new MousePressState(ev.getX(), ev.getY(),
-                                             ev.getModifiers());
+                                             ev.getModifiers(), cs);
            if (when_pressed != null)
                when_pressed.event(ev, press_state, null);
 
@@ -171,13 +172,14 @@
     }
 
     public class MousePressState {
-       private int x, y, buttons;
+       private int x, y, buttons, cs;
 
-       public MousePressState(int x, int y, int b) {
-           this.x=x; this.y=y; this.buttons=b;
+       public MousePressState(int x, int y, int b, int cs) {
+           this.x=x; this.y=y; this.buttons=b; this.cs = cs;
        }
        public int getX() { return x; }
        public int getY() { return y; }
        public int getButtons() { return buttons; }
+       public int getCS() { return cs; }
     }
 }
Index: gzz/gzz/modules/pp/PPMouseEvents.java
diff -u gzz/gzz/modules/pp/PPMouseEvents.java:1.7 
gzz/gzz/modules/pp/PPMouseEvents.java:1.8
--- gzz/gzz/modules/pp/PPMouseEvents.java:1.7   Mon Dec 23 05:40:17 2002
+++ gzz/gzz/modules/pp/PPMouseEvents.java       Mon Dec 23 09:00:11 2002
@@ -1,6 +1,6 @@
 
 
-// (c) Matti Katila
+// (c) Matti Katila, Tuukka Hastrup and Tuomas Lukka 
 
 
 package gzz.modules.pp;
@@ -11,6 +11,7 @@
 
 import gzz.view.AbstractViewContext;
 import gzz.client.AbstractUpdateManager;
+import gzz.client.Params;
 
 import java.awt.event.*;
 
@@ -36,7 +37,6 @@
     // set from outside
     public VobScene vs;
     public AbstractViewContext context;
- 
 
     public PPMouseEvents(PPView2 pv, PPActions pa, Space s) {
        this.ppv = pv;
@@ -62,18 +62,56 @@
        // Main paper
        EventHandling.i().assign("Click MAINVP", new SetCursorToMain() );
        EventHandling.i().assign("Drag MAINVP", new DragMainVP() );
+
+       // Main paper object events
+       EventHandling.i().assign("DragObjectOfMainVP", new DragObjectOfMainVP() 
);
     }
 
     /* Save press state
      * ================
      */
-    protected float last_zoom, last_panx, last_pany;
+    private int kingCS;
+    public void setKingCS(int frame) { kingCS = frame; }
+
+    private Cell accursed_obj = null;
+    private int[] orig_obj_pt = null;
+
+    private float last_zoom, last_panx, last_pany;
     public class SavePressState implements EventHandling.EventMouseObj {
        public void event(MouseEvent ev, EventHandling.MousePressState p_state,
                          Object[] obs) {
-               m_ev.last_zoom = ppv.zoom;
-               m_ev.last_panx = ppv.panx;
-               m_ev.last_pany = ppv.pany;
+           m_ev.last_zoom = ppv.zoom;
+           m_ev.last_panx = ppv.panx;
+           m_ev.last_pany = ppv.pany;
+
+           m_ev.accursed_obj = null;
+
+
+           // KLUDGE!!!
+           // there are no good way in gzz to handle events :/
+           if (p_state.getCS() == kingCS) {
+               if(notEmptyFrame(kingCS, p_state)) {
+                   float hit[] = new float[2];
+                   int objCS = getTouchedCS(kingCS, p_state, hit);
+
+                   Object k = vs.matcher.getKey(objCS);
+                   if (k == null) {
+                       pa("NULLLI!!");
+                       return;
+                   }
+
+                   pa("Hit: "+objCS+" "+k+" "+hit[0]+" "+hit[1]);
+                   if(!(k instanceof Cell)) {
+                       pa("Not a cell?!");
+                       return ;
+                   }
+                   m_ev.accursed_obj = (Cell)k;
+                   m_ev.orig_obj_pt = getNoteXY(m_ev.accursed_obj);
+
+                   context.setAccursed((Cell)k);
+                   
context.setCursorOffset(ppv.style.getOffsetInText(((Cell)k).t(), 1, hit[0]));
+               }
+           }
        }
     }
     
@@ -99,6 +137,7 @@
        public void event(MouseEvent ev, EventHandling.MousePressState p_state,
                          Object[] obs) {
 
+           pa("disabled demo-efect :)");
            /** uncomment if you need this in demo
             *  ----------------------------------
             */
@@ -106,18 +145,18 @@
            /*
            try {
                JFileChooser fc = new JFileChooser();
-                int returnVal = fc.showOpenDialog(null);
-
-                if (returnVal == JFileChooser.APPROVE_OPTION) {
-                    File file = fc.getSelectedFile();
+               int returnVal = fc.showOpenDialog(null);
+               
+               if (returnVal == JFileChooser.APPROVE_OPTION) {
+                   File file = fc.getSelectedFile();
                    Cell c = context.getAccursed();
                    // XXX no checks!!
                    ppactions.newNote(c.h(ppv.d.contains).getId(),
-                                     (int)ppv.panx, (int)ppv.pany,
+             (int)ppv.panx, (int)ppv.pany,
                                      "IMG:" + file.getPath());
-                } else {
-                    pa("Open command cancelled by user.");
-                }
+               } else {
+                   pa("Open command cancelled by user.");
+               }
            } catch (Exception e) { pa(e.getMessage()); }
            AbstractUpdateManager.chg();
            */
@@ -181,8 +220,12 @@
                          Object[] obs) {
            // obs{ mainctr, frame }
 
-           int frameCS = ((Integer)obs[1]).intValue();
            int mainctrCS = ((Integer)obs[0]).intValue();
+           int frameCS = ((Integer)obs[1]).intValue();
+
+           if (m_ev.accursed_obj != null) {
+               pa("send event forwarded...");
+           }
 
            float[] hit = new float[2];
            int vobcs = vs.coords.getCSAt( frameCS, ev.getX(), ev.getY(), hit);
@@ -220,42 +263,90 @@
     /* DRAGGING!
      * =========
      */
-
     public class DragMainVP implements EventHandling.EventMouseObj {
        public void event(MouseEvent ev, EventHandling.MousePressState p_state, 
Object[] obs) {
+           // obs{ mainctr, frame }
+
+           int frameCS = ((Integer)obs[1]).intValue();
 
-           // zoom
+           // set pan
+           context.setAccursed(context.getAccursed().h(ppv.d.contains));
+   
+           // Zooming
            if (p_state.getButtons() == ev.BUTTON3_MASK) {
                ppv.zoom = m_ev.last_zoom * (float) 
                    Math.exp((p_state.getY() - ev.getY())/150.0);
                pa(""+ppv.zoom);
            }
-           // moving in mainVP
+           // moving in mainVP and event passing
            else if (p_state.getButtons() == ev.BUTTON1_MASK) {
-               ppv.panx = m_ev.last_panx - (ev.getX() - 
p_state.getX())/ppv.zoom;
-               ppv.pany = m_ev.last_pany - (ev.getY() - 
p_state.getY())/ppv.zoom;
+
+               // pass event to object on paper
+               if (m_ev.accursed_obj != null) {
+                   EventHandling.i().passEvent("DragObjectOfMainVP", ev, null);
+
+                   // and move paper inverse direction
+                   ppv.panx = m_ev.last_panx + (ev.getX() - 
p_state.getX())/ppv.zoom;
+                   ppv.pany = m_ev.last_pany + (ev.getY() - 
p_state.getY())/ppv.zoom;
+               }
+               // moving around
+               else {
+                   ppv.panx = m_ev.last_panx - (ev.getX() - 
p_state.getX())/ppv.zoom;
+                   ppv.pany = m_ev.last_pany - (ev.getY() - 
p_state.getY())/ppv.zoom;
+               }
            } else return;
-           
-           ppv.setZoomPan(vs);
 
+           ppv.setZoomPan(vs);
+           
            AbstractUpdateManager.setNoAnimation();
            AbstractUpdateManager.chg();
        }
     }
 
 
-    /* Help methods
-     * ============
-     */
 
+    public class DragObjectOfMainVP implements EventHandling.EventMouseObj {
+       public void event(MouseEvent ev, EventHandling.MousePressState p_state, 
Object[] obs) {
+           // obs{ mainctr, frame }
 
-    private int press_was_something(int frameCS) {
-           float[] hit = new float[2];
-           int vobcs = vs.coords.getCSAt( frameCS, ev.getX(), ev.getY(), hit);
-           if(vobcs < 0) {
+           if(m_ev.accursed_obj == null) throw new Error("Object cell is 
NULL!!");
+           int x, y;
+           x = (int)(orig_obj_pt[0] + 2*( ev.getX()-p_state.getX()) / 
ppv.zoom);
+           y = (int)(orig_obj_pt[1] + 2*( ev.getY()-p_state.getY()) / 
ppv.zoom);
 
+           try {
+               ppactions.moveNote(accursed_obj.getId(), x, y);
+           } catch(Exception e) { pa(e.getMessage()); }
+       }
+    }
+    
+    
 
 
 
+    /* Help methods
+     * ============
+     */
 
+    private boolean notEmptyFrame(int frameCS, EventHandling.MousePressState 
p_state) {
+       float[] hit = new float[2];
+       int vobcs = vs.coords.getCSAt( frameCS, p_state.getX(), p_state.getY(), 
hit);
+       if(vobcs < 0) return false;
+       else return true;
+    }
+
+    
+    private int getTouchedCS(int frameCS, EventHandling.MousePressState 
p_state, float[] hit) {
+       hit = new float[2];
+       return vs.coords.getCSAt( frameCS, p_state.getX(), p_state.getY(), hit);
+    }
+
+
+    int[] getNoteXY(Cell note) {
+       if(note.s(ppv.d.pan) == null) {
+           pa("found null from cell's pan");
+           return null;
+       }
+       return Params.getInts(note.s(ppv.d.pan), ppv.d.pan, 2, null);
+    }
 }
Index: gzz/gzz/modules/pp/PPView2.java
diff -u gzz/gzz/modules/pp/PPView2.java:1.29 
gzz/gzz/modules/pp/PPView2.java:1.30
--- gzz/gzz/modules/pp/PPView2.java:1.29        Sun Dec 22 08:36:17 2002
+++ gzz/gzz/modules/pp/PPView2.java     Mon Dec 23 09:00:11 2002
@@ -376,11 +376,16 @@
        ev_handler.onClick(frameCS, "Click MAINVP",
                           new Object[]{ new Integer(mainctr), new 
Integer(frameCS)}
                           );
-       ev_handler.onDrag(frameCS, "Drag MAINVP");
+       ev_handler.onDrag(frameCS, "Drag MAINVP",
+                          new Object[]{ new Integer(mainctr), new 
Integer(frameCS)}
+                         );
+       pp_events.setKingCS(frameCS);
+
 
        // cell to frame CS
        int c2fCS = vs.coords.ortho(0, 0, 0, 0, 10, 10);
        vs.matcher.add(mainctr, c2fCS, "C2F");
+
 
        int[] coords = getCoords(context.getAccursed());
        if(coords != null) {



reply via email to

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