gzz-commits
[Top][All Lists]
Advanced

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

[Gzz-commits] gzz/gzz/vob/vobs ColoredSectorVob.java ColoredS...


From: Asko Soukka
Subject: [Gzz-commits] gzz/gzz/vob/vobs ColoredSectorVob.java ColoredS...
Date: Thu, 13 Mar 2003 11:40:36 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Asko Soukka <address@hidden>    03/03/13 11:40:36

Modified files:
        gzz/vob/vobs   : ColoredSectorVob.java 
                         ColoredSquareSectorVob.java OvalBgVob.java 
                         RectBgVob.java 

Log message:
        vob update

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/vobs/ColoredSectorVob.java.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/vobs/ColoredSquareSectorVob.java.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/vobs/OvalBgVob.java.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/vob/vobs/RectBgVob.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: gzz/gzz/vob/vobs/ColoredSectorVob.java
diff -u gzz/gzz/vob/vobs/ColoredSectorVob.java:1.9 
gzz/gzz/vob/vobs/ColoredSectorVob.java:1.10
--- gzz/gzz/vob/vobs/ColoredSectorVob.java:1.9  Wed Mar  5 05:34:28 2003
+++ gzz/gzz/vob/vobs/ColoredSectorVob.java      Thu Mar 13 11:40:33 2003
@@ -1,7 +1,7 @@
 /*
 ColoredSectorVob.java
  *    
- *    Copyright (c) 1999-2002, Ted Nelson and Tuomas Lukka
+ *    Copyright (c) 2002, 2003 by Asko Soukka
  *
  *    This file is part of Gzz.
  *    
@@ -23,85 +23,31 @@
  *
  */
 /*
- * Written by Tuomas Lukka, Tero Mäyränen and Asko Soukka
+ * Written by Asko Soukka
  */
 
 package gzz.vob.vobs;
+
 import gzz.vob.*;
-import gzz.*;
-import gzz.util.*;
-import gzz.errors.*;
-import gzz.vob.*;
-import gzz.client.*;
 import gzz.gfx.gl.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import java.lang.Math;
+
+import gzz.util.ColorUtil;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
 import gzz.client.GraphicsAPI;
+import java.lang.Math;
 
 /** A vob which is a circular background and frame.
  * Draws a filled (possibly with several colors) sector,
  * surrounded by a sector of the current foreground color.
  */
-
-public class ColoredSectorVob extends Vob {
-public static final String rcsid = "$Id: ColoredSectorVob.java,v 1.9 
2003/03/05 10:34:28 humppake Exp $";
+public class ColoredSectorVob extends OvalBgVob {
+public static final String rcsid = "$Id: ColoredSectorVob.java,v 1.10 
2003/03/13 16:40:33 humppake Exp $";
     public static boolean dbg = false;
-    static final void p(String s) { if(dbg) System.out.println(s); }
-    static final void pa(String s) { System.out.println(s); }
-
-    static protected float [][] circleGL = new float[360][2];
-    static protected boolean circleGLReady = false;
-    static protected void prepareCircleGL(float r) {
-       if (!circleGLReady) {
-           for (int i=0;i<360;i++) {
-               float a = (float)((Math.PI / 180) * (360-i));
-               circleGL[i][0] = 0.5f + x(a, r);
-               circleGL[i][1] = 0.5f + y(a, r);
-           }
-           circleGLReady = true;
-       }
-    }
-    protected static float x(float angle, float radius) {
-       return (float)(Math.cos((double)angle) * radius);
-    }
-    protected static float y(float angle, float radius) {
-       return (float)(Math.sin((double)angle) * radius);
-    }
-
-    protected int start;
-    protected int sector;
-    protected int step;
-
-    /** Creates ColoredSectorVob
-     * @param start Start angle of the sector. 0 degree is at clock three.
-     *              90 degrees is at clock twelve.
-     * @param sector The angle of the sector to be drawn. Max 360 degrees. 
-     * @param step Every step:th vertex is drawn. This affects only the
-     *             GL implementation. Currently the maximum
-     *             resolution is 360 vertexes. XXX this will be removed
-     *             after DiceableMesh renderable works.
-     */
-    public ColoredSectorVob(int start, int sector, int step) {
-       super();
-       this.start = Math.abs(start);
-       this.sector = Math.abs(sector);
-       this.step = Math.abs(step);
-    }
-    /* Default valus for drawing a small circle. */
-    public ColoredSectorVob(){
-        this(90, 360, 10);
-    }
+    private static final void p(String s) { if(dbg) System.out.println(s); }
 
     static Rectangle rect = new Rectangle();
-    int nsolids = 0;
-    Color[] solids;
-    protected Color bg = Color.white;
-    public void setBg(Color c){ if( c != null ) bg = c; }
-    public Color getBg() { return bg; }
-    boolean drawBorder = true;
-
     public void render(Graphics g,
                                boolean fast,
                                Vob.RenderInfo info1,
@@ -112,20 +58,20 @@
 
        Color oldfg = g.getColor();
 
-       /** Heavier border with bigger cells */
-       if(drawBorder && mh >= 20) {
-            g.setColor(info1.getMixedFgColor());
-           g.fillArc(mx-1, my-1, mw+2, mh+2, start, sector);
-       }
+       // Draw an oval in the background color, wiping out
+       // the already drawn stuff a little wider than we will draw.
+       g.setColor(info1.getBgColor());
+       if(mh >= 14) g.fillArc(mx-2, my-2, mw+4, mh+4, start, sector);
+       else g.fillArc(mx-1, my-1, mw+2, mh+2, start, sector);
 
-       if(nsolids == 0) {
-           g.setColor(bg);
+       if(colors == null || NColors == 0) {
+           g.setColor(bgColor);
            g.fillArc(mx, my, mw, mh, start, sector);
        } else {
            // Draws multiple background colours as sectors
-           int arc = sector / nsolids;
-           for(int i=0; i<nsolids; i++) {
-               g.setColor(solids[i]);
+           int arc = sector / NColors;
+           for(int i=0; i<NColors; i++) {
+               g.setColor((Color)colors[i]);
                g.fillArc(mx, my, mw, mh, start + arc * i, arc);
            }
        }
@@ -143,21 +89,33 @@
                           mx+mw/2 + (int)x(a, mw/2),
                           my+mh/2 + (int)y(a, mh/2));
            }
+           if(mh >= 14) {
+               g.drawArc(mx-1, my-1, mw+2, mh+2, start, sector);
+               if (sector < 360) {
+                   float a = (float)((Math.PI / 180f) * (360f-(start)));
+                   g.drawLine(mx-1+mw/2, my-1+mh/2,
+                              mx-1+mw/2 + (int)x(a, (mw+2)/2),
+                              my-1+mh/2 + (int)y(a, (mh+2)/2));
+                   a = (float)((Math.PI / 180f) * (360f-(sector+start)));
+                   g.drawLine(mx-1+(mw+2)/2, my-1+(mh+2)/2,
+                              mx-1+(mw+2)/2 + (int)x(a, (mw+2)/2),
+                              my-1+(mh+2)/2 + (int)y(a, (mh+2)/2));
+               }
+           }
        }
-
+       
        g.setColor(oldfg);
     }
 
-    Vob glList;
-
     public int putGL(VobScene vs, int coordsys1) {
-        if(dbg) pa("Addtolistgl coloredsectorvob "+coordsys1);
+        p("Addtolistgl coloredsectorvob "+coordsys1);
        if(glList == null) {
            if (!circleGLReady) prepareCircleGL(0.5f);
 
            String bgcall = "";
-           if(nsolids > 0) bgcall += glSolidsString();
-           else bgcall += glBgString();
+           if(colors != null && NColors > 0)
+               bgcall += glColorsString();
+           else bgcall += glOvalBgString();
            if(drawBorder) bgcall += glBorderString();
                    
            glList = GLRen.createCallListBoxCoorded(
@@ -171,45 +129,13 @@
        return 0;
     }
 
-    protected String glBorderString() {
-       String glString = "";
-       glString += (
-                    "Color 0 0 0 1\n" +
-                    "Begin LINE_LOOP\n");
-       if (sector < 360) glString += ("Vertex 0.5 0.5\n");
-       for (int i=0;i<sector;i+=step) {
-           glString += ("Vertex " + circleGL[(i+start)%360][0] +
-                      " " + circleGL[(i+start)%360][1] + "\n");
-       }
-       glString += ("Vertex " + circleGL[(sector-1+start)%360][0] +
-                  " " + circleGL[(sector-1+start)%360][1] + "\n" +
-                  "End\n");
-       return glString;
-    }
-
-    protected String glBgString() {
+    protected String glColorsString() {
+       int arc = sector / NColors;
        String glString = "";
-       glString = (
-                   "Color "+ColorUtil.colorGLString(bg)+" 1\n" +
-                   "Begin POLYGON\n");
-       if (sector < 360) glString += ("Vertex 0.5 0.5\n");
-       for (int i=0;i<sector;i+=step) {
-           glString += ("Vertex " + circleGL[(i+start)%360][0] +
-                      " " + circleGL[(i+start)%360][1] + "\n");
-       }
-       glString += ("Vertex " + circleGL[(sector-1+start)%360][0] +
-                    " " + circleGL[(sector-1+start)%360][1] + "\n" +
-                    "End\n");
-       return glString;
-    }
-
-    protected String glSolidsString() {
-       int arc = sector / nsolids;
-       String glString = "";
-       for(int i=0; i<nsolids; i++) {
-           Color c = solids[i];
+       for(int i=0; i<NColors; i++) {
+           Color c = (Color)colors[i];
            glString += (
-                      "Color "+ColorUtil.colorGLString(solids[i])+" 1\n"+
+                      "Color "+ColorUtil.colorGLString((Color)colors[i])+" 
1\n"+
                       "Begin POLYGON\n"+
                       "Vertex 0.5 0.5\n");
            for (int j=i*arc;j<(i+1)*arc;j+=step) {
@@ -225,32 +151,4 @@
        }
        return glString;
     }
-
-    /** Adds one more solid color to be drawn inside
-     * the cell.
-     */
-    public boolean addColor(Color c) {
-       if(solids == null || nsolids >= solids.length) {
-           Color[] n= new Color[nsolids + 10];
-           if(solids != null) System.arraycopy(solids, 0, n, 0, nsolids);
-           solids = n;
-       }
-       solids[nsolids++] = c;
-       return false;
-    }
-    /** The currently put solid colors.
-     * null = none. There may be null references near the end
-     * of the array. Mostly useful for checking for nullness.
-     */
-    public Color[] getSolidColors() { return solids; }
 }
-
-
-
-
-
-
-
-
-
-
Index: gzz/gzz/vob/vobs/ColoredSquareSectorVob.java
diff -u gzz/gzz/vob/vobs/ColoredSquareSectorVob.java:1.7 
gzz/gzz/vob/vobs/ColoredSquareSectorVob.java:1.8
--- gzz/gzz/vob/vobs/ColoredSquareSectorVob.java:1.7    Wed Mar  5 09:34:23 2003
+++ gzz/gzz/vob/vobs/ColoredSquareSectorVob.java        Thu Mar 13 11:40:34 2003
@@ -1,7 +1,7 @@
 /*
 ColoredSquareSectorVob.java
  *    
- *    Copyright (c) 2003, Asko Soukka
+ *    Copyright (c) 2003 by Asko Soukka
  *
  *    This file is part of Gzz.
  *    
@@ -27,32 +27,24 @@
  */
 
 package gzz.vob.vobs;
+
 import gzz.vob.*;
-import gzz.*;
-import gzz.util.*;
-import gzz.errors.*;
-import gzz.vob.*;
-import gzz.client.*;
 import gzz.gfx.gl.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import java.lang.Math;
+
+import gzz.util.ColorUtil;
+import java.awt.Shape;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
 import gzz.client.GraphicsAPI;
 
 /** A vob with a square background and frame, but colors
  * drawn as sectors.
  */
-
 public class ColoredSquareSectorVob extends ColoredSectorVob {
-public static final String rcsid = "$Id: ColoredSquareSectorVob.java,v 1.7 
2003/03/05 14:34:23 humppake Exp $";
-
-    public ColoredSquareSectorVob() {
-       super(90, 360, 10);
-       start = 90;
-       sector = 360;
-       step = 10; 
-    }
+public static final String rcsid = "$Id: ColoredSquareSectorVob.java,v 1.8 
2003/03/13 16:40:34 humppake Exp $";
+    public static boolean dbg = false;
+    private static final void p(String s) { if(dbg) System.out.println(s); }
 
     public void render(Graphics g,
                                boolean fast,
@@ -65,20 +57,22 @@
        Color oldfg = g.getColor();
        g.setColor(info1.getBgColor());
 
+       // Draw a rectangle in the background color, wiping out
+       // the already drawn stuff a little wider than we will draw.
+       g.setColor(info1.getBgColor());
        if (mh > 14) g.fillRect(mx-2, my-2, mw+4, mh+4);
        else g.fillRect(mx-1, my-1, mw+2, mh+2);
 
-       if(nsolids == 0) {
-           g.setColor(bg);
+       if(colors == null || NColors == 0) {
+           g.setColor(bgColor);
            g.fillRect(mx, my, mw, mh);
        } else if (my+mh > 0) {
-           System.out.println("FOO!:" + my + " " +mh);
            Shape oldClip = g.getClip();
            g.clipRect(mx+1, my+1, mw-2, mh-2);
-           int arc = sector / nsolids;
+           int arc = sector / NColors;
            int r = (int)Math.sqrt((mw/2)*(mw/2) + (mh/2)*(mh/2));
-           for(int i=0; i<nsolids; i++) {
-               g.setColor(solids[i]);
+           for(int i=0; i<NColors; i++) {
+               g.setColor((Color)colors[i]);
                g.fillArc(mx-(r-mw/2), my-(r-mh/2),
                          2*r, 2*r,
                          start + arc * i, arc);
@@ -97,14 +91,14 @@
     }
 
     public int putGL(final VobScene vs, final int coordsys1) {
-        if(dbg) pa("Addtolistgl coloredsectorvob "+coordsys1);
+        p("Addtolistgl coloredsectorvob "+coordsys1);
        if(glList == null) {
            if (!circleGLReady) prepareCircleGL((float)Math.sqrt(50)/10);
 
            String bgcall = "";
-           if(nsolids > 0) {
-               bgcall += glSolidsString();
-           } else bgcall += glBgString();
+           if(colors != null && NColors > 0) {
+               bgcall += glColorsString();
+           } else bgcall += glRectBgString();
            if(drawBorder) bgcall += glBorderString();
                    
            glList = GLRen.createCallListBoxCoorded(
@@ -131,17 +125,6 @@
        return 0;
     }
     
-    protected String glBgString() {
-       String glString = "";
-       glString += (
-                    "Color "+ColorUtil.colorGLString(bg)+" 1\n" +
-                    "Begin QUAD_STRIP\n"+
-                    "Vertex 1 1\nVertex 1 0\n"+
-                    "Vertex 0 1\nVertex 0 0\n"+
-                    "End\n");
-       return glString;
-    }
-
     protected String glBorderString() {
        String glString = "";
        glString += (
@@ -157,13 +140,3 @@
        return glString;
     }
 }
-
-
-
-
-
-
-
-
-
-
Index: gzz/gzz/vob/vobs/OvalBgVob.java
diff -u gzz/gzz/vob/vobs/OvalBgVob.java:1.10 
gzz/gzz/vob/vobs/OvalBgVob.java:1.11
--- gzz/gzz/vob/vobs/OvalBgVob.java:1.10        Wed Mar  5 09:34:23 2003
+++ gzz/gzz/vob/vobs/OvalBgVob.java     Thu Mar 13 11:40:34 2003
@@ -1,7 +1,7 @@
 /*
 OvalBgVob.java
  *    
- *    Copyright (c) 2003, Asko Soukka
+ *    Copyright (c) 2002, 2003 by Asko Soukka
  *
  *    This file is part of Gzz.
  *    
@@ -27,33 +27,90 @@
  */
 
 package gzz.vob.vobs;
+
 import gzz.vob.*;
-import gzz.*;
-import gzz.util.*;
-import gzz.errors.*;
-import gzz.vob.*;
-import gzz.client.*;
 import gzz.gfx.gl.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-import java.lang.Math;
+
+import gzz.util.ColorUtil;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
 import gzz.client.GraphicsAPI;
+import java.lang.Math;
 
 /** A vob which is a circular background and frame.
  * Draws a filled (possibly with several colors) background circle,
  * surrounded by a circle of the current foreground color.
  */
+public class OvalBgVob extends Vob {
+public static final String rcsid = "$Id: OvalBgVob.java,v 1.11 2003/03/13 
16:40:34 humppake Exp $";
+    public static boolean dbg = false;
+    private static final void p(String s) { if(dbg) System.out.println(s); }
+
+    int NColors = 0;
+    Color[] colors;
+
+    /** Background color */
+    protected final Color bgColor;
+
+    /** Border drawing flag */
+    protected final boolean drawBorder;
+
+    static protected float [][] circleGL = new float[360][2];
+    static protected boolean circleGLReady = false;
+    static protected void prepareCircleGL(float r) {
+       if (!circleGLReady) {
+           for (int i=0;i<360;i++) {
+               float a = (float)((Math.PI / 180) * (360-i));
+               circleGL[i][0] = 0.5f + x(a, r);
+               circleGL[i][1] = 0.5f + y(a, r);
+           }
+           circleGLReady = true;
+       }
+    }
+    protected static float x(float angle, float radius) {
+       return (float)(Math.cos((double)angle) * radius);
+    }
+    protected static float y(float angle, float radius) {
+       return (float)(Math.sin((double)angle) * radius);
+    }
 
-public class OvalBgVob extends ColoredSectorVob {
-public static final String rcsid = "$Id: OvalBgVob.java,v 1.10 2003/03/05 
14:34:23 humppake Exp $";
-
-    public OvalBgVob() {
-       super(90, 360, 10);
-       start = 90;
-       sector = 360;
-       step = 10; 
+    protected int start;
+    protected int sector;
+    protected int step;
+
+    /** Constructor shorthands */
+    public OvalBgVob() { this(Color.white, true); }
+    public OvalBgVob(Color bgColor) { this(bgColor, true); }
+    public OvalBgVob(Color bgColor, boolean drawBorder) {
+       this(bgColor, drawBorder, 90, 360, 10);
+    }
+    public OvalBgVob(int start, int sector, int step) {
+       this(Color.white, true, start, sector, step);
     }
+  
+    /** Constructor for OvalBgVob.
+     * @param bgColor Background color.
+     * @param drawBorder Border drawing flag.
+     * @param start Start angle of the sector. 0 degree is at clock three.
+     *              90 degrees is at clock twelve.
+     * @param sector The angle of the sector to be drawn. Max 360 degrees. 
+     * @param step Every step:th vertex is drawn. This affects only the
+     *             GL implementation. Currently the maximum
+     *             resolution is 360 vertexes. XXX this will be removed
+     *             after DiceableMesh renderable works.
+     */
+    public OvalBgVob(Color bgColor, boolean drawBorder, 
+                    int start, int sector, int step) {
+       super();
+       this.bgColor = bgColor;
+       this.drawBorder = drawBorder;
+       this.start = Math.abs(start);
+       this.sector = Math.abs(sector);
+       this.step = Math.abs(step);
+    }
+
+    static Rectangle rect = new Rectangle();
 
     public void render(Graphics g,
                       boolean fast,
@@ -65,17 +122,17 @@
 
        Color oldfg = g.getColor();
 
-       /** Heavier border with bigger cells */
-       if(drawBorder && mh >= 20) {
-            g.setColor(info1.getMixedFgColor());
-           g.fillOval(mx-1, my-1, mw+2, mh+2);
-       }
+       // Draw an oval in the background color, wiping out
+       // the already drawn stuff a little wider than we will draw.
+       g.setColor(info1.getBgColor());
+       if(mh >= 14) g.fillOval(mx-2, my-2, mw+4, mh+4);
+       else g.fillOval(mx-1, my-1, mw+2, mh+2);
 
-       if(nsolids == 0) {
-           g.setColor(bg);
+       if(colors == null || NColors == 0) {
+           g.setColor(bgColor);
            g.fillOval(mx, my, mw, mh);
        } else {
-           /** Draws solids as colored stripes. Each stripe is composed of
+           /** Draws colored stripes. Each stripe is composed of
             * on filled rectangle and two filled arcs. Drawing proceeds from
             * the boundaries to the centre. Two stripes at time. If there is
             * odd number of stripes the centered stipes is drawn as two
@@ -86,55 +143,59 @@
             *         \__ second arc
             *
             */
-           g.setColor(solids[0]);
+           g.setColor(colors[0]);
            g.fillArc(mx, my, mw, mh, -90, 180);
-           g.setColor(solids[nsolids-1]);
+           g.setColor(colors[NColors-1]);
            g.fillArc(mx, my, mw, mh, 90, 180);
-           int lastsolid = nsolids-1;
-           int solidwidth = mw / nsolids;
+           int lastColor = NColors-1;
+           int colorWidth = mw / NColors;
            float a = mw/2;
            float b = mh/2;
-           for(int i=1; i<lastsolid; i++) {
-               float w = a-i*solidwidth;
+           for(int i=1; i<lastColor; i++) {
+               float w = a-i*colorWidth;
                float h = b * (float)Math.sqrt(1-(Math.pow(w,2)/Math.pow(a, 
2)));
                int arc = 90 - (int)((180/Math.PI) * Math.atan2(h*(a/b),w));
 
                // stripe on the left
-               g.setColor(solids[i]);
-               g.fillRect((int)(mx+(i*solidwidth)), (int)(my+(b-h)),
+               g.setColor(colors[i]);
+               g.fillRect((int)(mx+(i*colorWidth)), (int)(my+(b-h)),
                           (int)w, (int)(h*2));
                g.fillArc(mx, my, mw, mh, 90, arc);
                g.fillArc(mx, my, mw, mh, -90-arc, arc);
                
                // stripe on the right
-               g.setColor(solids[lastsolid-1]);
+               g.setColor(colors[lastColor-1]);
                g.fillRect((int)(mx+a), (int)(my+(b-h)), (int)w, (int)(h*2));
                g.fillArc(mx, my, mw, mh, 90-arc, arc);
                g.fillArc(mx, my, mw, mh, -90, arc);
                
-               lastsolid--;
+               lastColor--;
            }
        }
        
        if(drawBorder) {
             g.setColor(info1.getMixedFgColor());
            g.drawOval(mx, my, mw, mh);
+           if(mh >= 14) {
+               /** Heavier border for greter Vobs */
+               g.drawOval(mx-1, my-1, mw+2, mh+2);
+           }
        }
 
        g.setColor(oldfg);
     }
 
-    Vob glStencil, glBorder;
+    Vob glStencil, glBorder, glList;
 
     public int putGL(final VobScene vs, final int coordsys1) {
-        if(dbg) pa("Addtolistgl ovalbg "+coordsys1);
+       p("Addtolistgl ovalbg "+coordsys1);
 
        if(glList == null) {
            if (!circleGLReady) prepareCircleGL(0.5f);
            String bgcall = "";
-           if(nsolids > 0) {
-               bgcall += glSolidsString();
-           } else bgcall += glBgString();
+           if(colors != null && NColors > 0) {
+               bgcall += glColorsString();
+           } else bgcall += glRectBgString();
            
            glList = GLRen.createCallListBoxCoorded(
                "PushAttrib CURRENT_BIT ENABLE_BIT\n"+
@@ -148,7 +209,7 @@
            glStencil = GLRen.createCallListBoxCoorded(
                "PushAttrib CURRENT_BIT ENABLE_BIT\n"+
                "Disable TEXTURE_2D\n"+
-               super.glBgString() +
+               glOvalBgString() +
                "PopAttrib\n"
                );
        }
@@ -179,10 +240,26 @@
        return 0;
     }
 
-    protected String glBgString() {
+    protected String glBorderString() {
+       String glString = "";
+       glString += (
+                    "Color 0 0 0 1\n" +
+                    "Begin LINE_LOOP\n");
+       if (sector < 360) glString += ("Vertex 0.5 0.5\n");
+       for (int i=0;i<sector;i+=step) {
+           glString += ("Vertex " + circleGL[(i+start)%360][0] +
+                      " " + circleGL[(i+start)%360][1] + "\n");
+       }
+       glString += ("Vertex " + circleGL[(sector-1+start)%360][0] +
+                  " " + circleGL[(sector-1+start)%360][1] + "\n" +
+                  "End\n");
+       return glString;
+    }
+
+    protected String glRectBgString() {
        String glString = "";
        glString += (
-                    "Color "+ColorUtil.colorGLString(bg)+" 1\n" +
+                    "Color "+ColorUtil.colorGLString(bgColor)+" 1\n" +
                     "Begin QUAD_STRIP\n"+
                     "Vertex 1 1\nVertex 1 0\n"+
                     "Vertex 0 1\nVertex 0 0\n"+
@@ -190,15 +267,31 @@
        return glString;
     }
 
-    protected String glSolidsString() {
-       double w = 1.0 / nsolids;
+    protected String glOvalBgString() {
+       String glString = "";
+       glString = (
+                   "Color "+ColorUtil.colorGLString(bgColor)+" 1\n" +
+                   "Begin POLYGON\n");
+       if (sector < 360) glString += ("Vertex 0.5 0.5\n");
+       for (int i=0;i<sector;i+=step) {
+           glString += ("Vertex " + circleGL[(i+start)%360][0] +
+                      " " + circleGL[(i+start)%360][1] + "\n");
+       }
+       glString += ("Vertex " + circleGL[(sector-1+start)%360][0] +
+                    " " + circleGL[(sector-1+start)%360][1] + "\n" +
+                    "End\n");
+       return glString;
+    }
+
+    protected String glColorsString() {
+       double w = 1.0 / NColors;
        String glString = "";
-       for(int i=0; i<nsolids; i++) {
+       for(int i=0; i<NColors; i++) {
            double x1 = i*w;
            double x2 = x1 + w;
-           Color c = solids[i];
+           Color c = colors[i];
            glString += (
-             "Color "+ColorUtil.colorGLString(solids[i])+" 1\n"+
+             "Color "+ColorUtil.colorGLString(colors[i])+" 1\n"+
              "Begin QUAD_STRIP\n"+
              "TexCoord "+x1+" 1\n"+
              "Vertex "+x1+" 1\n"+
@@ -212,4 +305,22 @@
        }
        return glString;
     }
+
+    /** Adds one more solid color to be drawn inside
+     * the cell.
+     */
+    public boolean addColor(Color c) {
+       if(colors == null || NColors >= colors.length) {
+           Color[] n= new Color[NColors + 10];
+           if(colors != null) System.arraycopy(colors, 0, n, 0, NColors);
+           colors = n;
+       }
+       colors[NColors++] = c;
+       return false;
+    }
+    /** The currently put solid colors.
+     * null = none. There may be null references near the end
+     * of the array. Mostly useful for checking for nullness.
+     */
+    public Color[] getSolidColors() { return colors; }
 }
Index: gzz/gzz/vob/vobs/RectBgVob.java
diff -u gzz/gzz/vob/vobs/RectBgVob.java:1.8 gzz/gzz/vob/vobs/RectBgVob.java:1.9
--- gzz/gzz/vob/vobs/RectBgVob.java:1.8 Fri Feb 21 15:02:48 2003
+++ gzz/gzz/vob/vobs/RectBgVob.java     Thu Mar 13 11:40:34 2003
@@ -27,43 +27,54 @@
  */
 
 package gzz.vob.vobs;
+
 import gzz.vob.*;
-import gzz.*;
-import gzz.util.*;
-import gzz.errors.*;
-import gzz.vob.*;
-import gzz.client.*;
 import gzz.gfx.gl.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
+
+import gzz.util.ColorUtil;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
 import gzz.client.GraphicsAPI;
 
 /** A vob which is a rectangular background and frame.
  * Draws a filled (possibly with several colors) background rectangle,
  * surrounded by a rectangle of the current foreground color.
  */
-
 public class RectBgVob extends Vob {
-public static final String rcsid = "$Id: RectBgVob.java,v 1.8 2003/02/21 
20:02:48 tjl Exp $";
+public static final String rcsid = "$Id: RectBgVob.java,v 1.9 2003/03/13 
16:40:34 humppake Exp $";
     public static boolean dbg = false;
-    static final void pa(String s) { System.out.println(s); }
+    private static void pa(String s) { System.err.println(s); }
 
-    static Rectangle rect = new Rectangle();
+    int NColors = 0;
+    Color[] colors;
 
-    int nsolids = 0;
-    Color[] solids;
-    protected Color bg = Color.white;
+    /** Background color */
+    protected final Color bgColor;
 
-    public void setBg(Color c){ if( c != null ) bg = c; }
-    public Color getBg() { return bg; }
+    /** Border drawing flag */
+    protected final boolean drawBorder;
+
+    /** Constructor shorthands */
+    public RectBgVob() { this(Color.white, true); }
+    public RectBgVob(Color bgColor) { this(bgColor, true); }
+  
+    /** Construct RectBgVob.
+     * @param bgColor Background color.
+     * @param drawBorder Border drawing flag.
+     */
+    public RectBgVob(Color bgColor, boolean drawBorder) {
+       super();
+       this.bgColor = bgColor;
+       this.drawBorder = drawBorder;
+    }
 
-    boolean drawBorder = true;
+    static Rectangle rect = new Rectangle();
 
     public void render(Graphics g,
-                               boolean fast,
-                               Vob.RenderInfo info1,
-                               Vob.RenderInfo info2) {
+                      boolean fast,
+                      Vob.RenderInfo info1,
+                      Vob.RenderInfo info2) {
        info1.getExtRect(rect);
        int mx = rect.x, my=rect.y,
            mw = rect.width, mh = rect.height;
@@ -76,13 +87,14 @@
        if (mh > 14) g.fillRect(mx-2, my-2, mw+4, mh+4);
        else g.fillRect(mx-1, my-1, mw+2, mh+2);
 
-       if(nsolids == 0) {
-           g.setColor(bg);
+       if(colors == null || NColors == 0) {
+           g.setColor(bgColor);
            g.fillRect(mx, my, mw, mh);
        } else {
-           for(int i=0; i<nsolids; i++) {
-               g.setColor(solids[i]);
-               g.fillRect(mx+(mw*i)/nsolids, my, mw/nsolids, mh);
+           for(int i=0; i<NColors; i++) {
+               g.setColor(colors[i]);
+               g.fillRect(mx+(mw*i)/NColors, my,
+                          mw/NColors, mh);
            }
        }
 
@@ -103,15 +115,14 @@
         if(dbg) pa("Addtolistgl rectbg "+coordsys1);
        if(glList == null) {
            String bgcall = "";
-           if(nsolids > 0) {
-               double w = 1.0 / nsolids;
+           if(colors != null && NColors > 0) {
+               double w = 1.0 / NColors;
 
-               for(int i=0; i<nsolids; i++) {
+               for(int i=0; i<NColors; i++) {
                    double x1 = i*w;
                    double x2 = x1 + w;
-                   Color c = solids[i];
                     bgcall += (
-                       "Color "+ColorUtil.colorGLString(solids[i])+" 1\n"+
+                       "Color "+ColorUtil.colorGLString(colors[i])+" 1\n"+
                        "Begin QUAD_STRIP\n"+
                        "Vertex "+x1+" 1\n" +
                        "Vertex "+x1+" 0\n"+
@@ -121,7 +132,7 @@
                }
            } else {
                bgcall = (
-                   "Color "+ColorUtil.colorGLString(bg)+" 1\n" +
+                   "Color "+ColorUtil.colorGLString(bgColor)+" 1\n" +
                    "Begin QUAD_STRIP\n"+
                    "Vertex 1 1\nVertex 1 0\n"+
                    "Vertex 0 1\nVertex 0 0\n"+
@@ -154,19 +165,18 @@
      * the cell.
      */
     public boolean addColor(Color c) {
-       if(solids == null || nsolids >= solids.length) {
-           Color[] n= new Color[nsolids + 10];
-           if(solids != null) System.arraycopy(solids, 0, n, 0, nsolids);
-           solids = n;
+       if(colors == null || NColors >= colors.length) {
+           Color[] n= new Color[NColors + 10];
+           if(colors != null) System.arraycopy(colors, 0, n, 0, NColors);
+           colors = n;
        }
-       solids[nsolids++] = c;
+       colors[NColors++] = c;
        return false;
     }
     /** The currently put solid colors.
      * null = none. There may be null references near the end
      * of the array. Mostly useful for checking for nullness.
      */
-    public Color[] getSolidColors() { return solids; }
-
+    public Color[] getSolidColors() { return colors; }
 }
 




reply via email to

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