fenfire-dev
[Top][All Lists]
Advanced

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

[Fenfire-dev] Ugly copypaste problem


From: Matti Katila
Subject: [Fenfire-dev] Ugly copypaste problem
Date: Thu, 23 Oct 2003 10:01:56 +0300 (EEST)

Selecting text area needs 3 selectable areas:
asdfasdfaXXXXXXXXXX
XXXXXXXXXXXXXXXXXXX
XXXXXXasdfasdfasfas   where X is selected.

Currently we provide only one area to be selected
but what's the best choige for those two addition areas:
copypaste 2 more, using array or List?

Here is one solution but it's rather ugly, I think.

  
   -Matti


--- orig/org/fenfire/view/AreaSelectingView2D.java
+++ mod/org/fenfire/view/AreaSelectingView2D.java
@@ -40,12 +40,57 @@
     public View2D getChildView2D() { return child; }
     protected View2D child;
 
+    private void clear() {
+       setArea(0,0,0,0); setBeginArea(0,0,0,0); setEndArea(0,0,0,0);
+    }
+
+
     private float x0,y0,x1,y1;
     public void setArea(float x0, float y0, float x1, float y1) {
         this.x0 = x0; this.y0 = y0;
         this.x1 = x1; this.y1 = y1;
     }
 
+    private float ax0,ay0,ax1,ay1;
+    public void setBeginArea(float x0, float y0, float x1, float y1) {
+        this.ax0 = x0; this.ay0 = y0;
+        this.ax1 = x1; this.ay1 = y1;
+    }
+
+    private float bx0,by0,bx1,by1;
+    public void setEndArea(float x0, float y0, float x1, float y1) {
+        this.bx0 = x0; this.by0 = y0;
+        this.bx1 = x1; this.by1 = y1;
+    }
+
+
+    /** Set text area.
+     * b prefix is begin, e prefix is end.
+     */
+    public void setTextArea(float bx, float byTop, float byBot,
+                           float ex, float eyTop, float eyBot,
+                           float edgeL, float edgeR) {
+       clear();
+       if (dbg) {
+           p("begin: "+bx+", "+byTop+", "+byBot);
+           p("end:   "+ex+", "+eyTop+", "+eyBot);
+           p("edges: "+edgeL+", "+edgeR);
+       }
+       // keep up the good work
+       // we have at least two lines here..
+       if (byBot <= eyTop) {
+           if (dbg) p("at least two lines");
+           setBeginArea(bx, byTop, edgeR, byBot);
+           setArea(edgeL,byBot,edgeR,eyTop);
+           setEndArea(edgeL, eyTop, ex, eyBot);
+       }
+       // one line only
+       else {
+           if (dbg) p("one line");
+           setArea(bx,byTop, ex,eyBot);
+       }
+    }
+
     private Object current = null;
     public void setCurrentPlane(Object obj) { current = obj; }
 
@@ -63,8 +108,10 @@
         pq = GLRen.createFixedPaperQuad(paper, 0, 0, 1, 1, 0, 10, 10, 
10);
     }
 
-    private final String CONCAT = "AreaSelectingView_concat";
-    private final String SELECT = "AreaSelectingView_selection";
+    static private final String CONCAT = "AreaSelectingView_concat";
+    static private final String SELECT = "AreaSelectingView_selection";
+    static private final String SELECT_END = 
"AreaSelectingView_selection_begin";
+    static private final String SELECT_BEGIN = 
"AreaSelectingView_selection_end";
 
     public Object getSelectedObject(Object plane, float x, float y, float 
w, float h) {
        return child.getSelectedObject(plane, x, y, w, h);
@@ -83,10 +130,14 @@
        int paper2screen = vs.concatCS(box2screen, CONCAT,
                                    paper2box);
        int cs = vs.orthoCS(paper2screen, SELECT, 0, 1,2,3,4);
+       int cs_begin = vs.orthoCS(paper2screen, SELECT_END, 0, 1,2,3,4);
+       int cs_end = vs.orthoCS(paper2screen, SELECT_BEGIN, 0, 1,2,3,4);
 
-       if (current != plane) setArea(0,0,0,0);
+       if (current != plane) clear();
        chgFast(vs, box2screen);
         vs.put(pq, cs);
+        vs.put(pq, cs_begin);
+        vs.put(pq, cs_end);
     }

     public void chgFast(VobScene oldVS, int parent) {
@@ -96,11 +147,17 @@
         if (dbg) p("parent cs: "+parent);
        int concatCs = oldVS.matcher.getCS(parent, CONCAT);
        int cs = oldVS.matcher.getCS(concatCs, SELECT);
+       int cs2 = oldVS.matcher.getCS(concatCs, SELECT_END);
+       int cs3 = oldVS.matcher.getCS(concatCs, SELECT_BEGIN);
        if (dbg) p("cs: "+cs);
 
        if (cs < 1) throw new Error(cs+" is not possible!");
+       if (cs2 < 1) throw new Error(cs+" is not possible!");
+       if (cs3 < 1) throw new Error(cs+" is not possible!");
 
         oldVS.coords.setOrthoParams(cs, 0,  x0,y0,x1-x0,y1-y0);
+        oldVS.coords.setOrthoParams(cs2, 0,  ax0,ay0,ax1-ax0,ay1-ay0);
+        oldVS.coords.setOrthoParams(cs3, 0,  bx0,by0,bx1-bx0,by1-by0);
     }
 
     public void getSize(Object plane, float[] wh) {








reply via email to

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