/* OvalBgVob.java * * Copyright (c) 1999-2002, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka, Tero Mäyränen and Asko Soukka */ package 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.client.GraphicsAPI; /** 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.1 2002/10/17 13:03:29 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 Rectangle rect = new Rectangle(); static private GL.Texture tex; static private boolean texLoaded = false; static private void loadTex() { if (!texLoaded) { String[] texparam = {"type", "8"}; tex = GL.createTexture(); /** !!! Should texture's size be relative to vob's physical size? * Then texture should be reloaded when greater needed. */ tex.shade(128, 128, 0, 1, "ALPHA", "ALPHA", "geometric", texparam); texLoaded = true; } } 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, Vob.RenderInfo info2) { info1.getExtRect(rect); int mx = rect.x, my=rect.y, mw = rect.width, mh = rect.height; /** Origo and radius for circle. Point co = new Point(mx+mw/2, my+h/2); int cr; if (mw < mh) cr = mw; else cr = mh; */ Color oldfg = g.getColor(); // 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.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); g.fillOval(mx, my, mw, mh); } else { for(int i=0; i= 14) { g.drawOval(mx+1, my+1, mw-3, mh-3); } } g.setColor(oldfg); } Vob glList; public int addToListGL(GraphicsAPI.Window win, int[] list, int curs, int coordsys1, int coordsys2) { if(dbg) pa("Addtolistgl rectbg "+coordsys1); if(glList == null) { if (!texLoaded) loadTex(); String bgcall = ""; if(nsolids > 0) { double w = 1.0 / nsolids; for(int i=0; i= 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; } }