fenfire-commits
[Top][All Lists]
Advanced

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

[ff-cvs] libvob/org/nongnu/libvob/vobs SelectListVob.jav...


From: Matti Katila
Subject: [ff-cvs] libvob/org/nongnu/libvob/vobs SelectListVob.jav...
Date: Mon, 25 Aug 2003 16:33:00 -0400

CVSROOT:        /cvsroot/libvob
Module name:    libvob
Branch:         
Changes by:     Matti Katila <address@hidden>   03/08/25 16:33:00

Modified files:
        org/nongnu/libvob/vobs: SelectListVob.java 
Added files:
        org/nongnu/libvob/vobs: SelectItemVob.java 

Log message:
        select list reimplemented - pre and post colorizing added

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/vobs/SelectItemVob.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/org/nongnu/libvob/vobs/SelectListVob.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: libvob/org/nongnu/libvob/vobs/SelectListVob.java
diff -u libvob/org/nongnu/libvob/vobs/SelectListVob.java:1.4 
libvob/org/nongnu/libvob/vobs/SelectListVob.java:1.5
--- libvob/org/nongnu/libvob/vobs/SelectListVob.java:1.4        Mon Aug 11 
10:14:07 2003
+++ libvob/org/nongnu/libvob/vobs/SelectListVob.java    Mon Aug 25 16:33:00 2003
@@ -26,104 +26,69 @@
 
 package org.nongnu.libvob.vobs;
 import org.nongnu.libvob.*;
-import java.util.*;
 import java.awt.*;
 
-/** Vob usefull for listing items. Can be used i.e., 
- * to show a list after mouse click. Click can be recognized
- * through Key object.
+/** Immutable class to contain items in list. 
+ * This Vob is usefull for listing items. Can be used i.e., 
+ * to show a list after mouse click.
+ * @see SelectItemVob
  */
 public class SelectListVob extends AbstractVob {
     public static boolean dbg = false;
     private static void p(String s) { System.out.println("SelectListVob:: 
"+s); }
 
-
-    public class Key {
-       public Object object = null;
-       public Key(Object obj) { this.object = obj; }
-    }
-
-    private RectBgVob bg;
-
-    private TextStyle style;
-    private Color textColor = Color.black;
-
+    private final SelectItemVob[] items;
     private final float scale;
+    private final RectBgVob bg;
 
-    public SelectListVob(TextStyle style) {
-       this(style, new Color(.9f, .9f, 1));
+    public SelectListVob(SelectItemVob[] items) {
+       this(items, 2.5f);
+    }
+    public SelectListVob(SelectItemVob[] items, float scale) {
+       this(items, scale, new Color(.9f, .9f, 1));
     }
-    public SelectListVob(TextStyle style, Color bgColor) {
-       this.style = style;
+    /** @param items the items in list.
+     * @param scale scales the list XXX not implemented!
+     * @param bgColor background color of list 
+     */
+    public SelectListVob(SelectItemVob[] items, float scale, Color bgColor) {
+       this.items = items;
+       this.scale = scale;
        this.bg = new RectBgVob(bgColor); 
-       scale = style.getScaleByHeight(22);
     }
 
 
-    private ArrayList keys = new ArrayList();
-    private ArrayList vobs = new ArrayList();
-
-    public void add(String text, Object key) {
-       this.add(text, new Key(key));
-    }
-    public void add(String text, Key key) {
-       keys.add(key);
-       vobs.add(new TextVob(style, text, false));
-    }
-
-    
     public void render(Graphics g, boolean fast,
                       RenderInfo info1, RenderInfo info2) {
        throw new Error("Not implemented");
     }
 
-    private Color accursedColor = null;
-    private Key accursed = null;
-    public void colorize(Key key, Color color) {
-       accursed = key;
-       accursedColor = color;
-    }
     
+    private float xRatio = 0, yRatio = 0;
     public int putGL(VobScene vs, int into) {
        vs.put(bg, into);
 
-       if (vobs.size() == 0) return 0;
-
        float [] size = new float[3];
        vs.coords.getSqSize(into, size);
        if (dbg) p("size:"+size[0]+","+size[1]);
-
-       float w = getWidth(), h = getHeight();
-       float y = 0, hInc = size[1]/vobs.size(), x = 0.065f * size[0];
-
        
-
-       for (int i=0; i<vobs.size(); i++) {
-           TextVob item = (TextVob)vobs.get(i);
-           if (keys.get(i) == accursed) {
-               vobs.remove(i);
-               vobs.add(i, new TextVob(style, item.text, false, 
accursedColor));
-               item = (TextVob)vobs.get(i);
-           }
-
-           if (dbg) 
p("d:"+item.getDepth(scale)+"w:"+item.getWidth(scale)+"h:"+item.getHeight(scale));
-
-           float width = item.getWidth(scale);
-           float height = item.getHeight(scale); // + item.getDepth(scale);
-
-           int textFrame =
-               vs.orthoBoxCS(into, keys.get(i),0, x,y,  1,1,
-                             size[0]-x, (size[1]/h)*height);
-           vs.activate(textFrame);
-
-           height = item.getHeight(scale) + item.getDepth(scale);
-           int textCS =
-               vs.scaleCS(textFrame, "CS"+keys.get(i).toString(),
-                          height * size[0]/w,
-                          height * size[1]/h );
-           vs.map.put(item, textCS);
+       float x = 0, y = 0;
+       xRatio = size[0]/getWidth();
+       yRatio = size[1]/getHeight();
+
+       for (int i=0; i<items.length; i++) {
+           SelectItemVob item = items[i];
+           int itemFrame =
+               vs.orthoBoxCS(into, item.getKey(), 0, x,y,  1,1,
+                             xRatio * getWidth(), yRatio * item.getHeight());
+           vs.activate(itemFrame);
+
+           int itemCS =
+               vs.orthoBoxCS(into, item.getKey().toString()+"_item", 0, x,y,  
1,1,
+                             xRatio * item.getWidth(), yRatio * 
item.getHeight());
+           item.place(vs, itemFrame, itemCS);
            
-           y += hInc;
+           y += yRatio * item.getHeight();
        }
        
        return 0;
@@ -131,20 +96,63 @@
 
 
     public float getWidth() {
-       if (vobs.size() == 0) return 0;
-
        float max = 0;
-       for (int i=0; i<vobs.size(); i++) {
-           max = Math.max(max, ((TextVob)vobs.get(i)).getWidth(scale));
+       for (int i=0; i<items.length; i++) {
+           max = Math.max(max, items[i].getWidth());
        }
-       return max * 1.25f;
+       return max;
     }
 
     public float getHeight() {
-       if (vobs.size() == 0) return 0;
-       TextVob t = (TextVob)vobs.get(0);
-       return 1.1f * vobs.size() * t.getHeight(scale);
+       float height = 0;
+       for (int i=0; i<items.length; i++) {
+           height += items[i].getHeight();
+       }
+       return height;
+    }
+
+    /** Before slecting the item - colorize the thing like 
+     * saing: "You are being to hit me!"
+     */
+    public void preSelect(float x, float y) {
+       cleanSelects();
+       if (miss(x,y)) return;
+       getItem(x,y).preSelect = true;
+    }
+
+    /** After slecting the item - colorize the thing like 
+     * saing: "Ouh, you really hit me and that hurt."
+     */
+    public void postSelect(float x, float y) {
+       cleanSelects();
+       if (miss(x,y)) return;
+       getItem(x,y).postSelect = true;
     }
 
+
+    private SelectItemVob getItem(float x, float y) {
+       float y_tmp = 0;
+       for (int i=0; i<items.length; i++) {
+           if (y >= y_tmp   && 
+               y < y_tmp + yRatio * items[i].getHeight()) 
+                   return items[i];
+           y_tmp += items[i].getHeight() * yRatio;
+       }
+       return null;
+    }
+
+    private boolean miss(float x, float y) {
+       if (x < 0 || x > xRatio * getWidth() ||
+           y < 0 || y > yRatio * getHeight()) {
+           p("miss");
+           return true;
+       } return false;
+    }
+    private void cleanSelects() {
+       for (int i=0; i<items.length; i++) {
+           items[i].preSelect = false;
+           items[i].postSelect = false;
+       }
+    }
 
 }




reply via email to

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