Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4636/src/net/sourceforge/bprocessor/gl/model
Added Files:
SpaceBox.java Widget.java Label.java
Log Message:
Widgets are being implemented
--- NEW FILE: SpaceBox.java ---
//---------------------------------------------------------------------------------
// $Id: SpaceBox.java,v 1.1 2007/01/26 14:04:56 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.gl.model;
import net.sourceforge.bprocessor.model.Project;
import net.sourceforge.bprocessor.model.Space;
/**
*
*/
public class SpaceBox extends Label {
private Space space;
/**
* Create SpaceBox for specified space
* @param space Space
*/
public SpaceBox(Space space) {
super(space.getDisplayName());
}
/**
* Returns the space.
* @return the space.
*/
public Space space() {
return space;
}
/**
* {@inheritDoc}
*/
public void action() {
Project.getInstance().setActiveSpace(space);
}
}
--- NEW FILE: Widget.java ---
//---------------------------------------------------------------------------------
// $Id: Widget.java,v 1.1 2007/01/26 14:04:56 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.gl.model;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
/**
* Widget represents button-like 2d objects, displayed
* on top of the 3d model.
*
* The x y coordinates are the top-left corner.
*/
public abstract class Widget {
private int x;
private int y;
/**
* Sets the x coordinate.
* @param x the new x coordinate
*/
public void setX(int x) {
this.x = x;
}
/**
* Sets the y coordinate.
* @param y the new y coordinate
*/
public void setY(int y) {
this.y = y;
}
/**
* Returns the x coordinate.
* @return the x coordinate
*/
public int getX() {
return x;
}
/**
* Returns the y coordinate.
* @return the y coordinate
*/
public int getY() {
return y;
}
/**
* Displays this Widget in the local coordinatesystem of this Widget.
* @param gl the GL containing the OpenGL interface.
* @param glu the GLU containing the GLU interface.
*/
public abstract void draw(GL gl, GLU glu);
/**
* Performs the action for this Widget.
*/
public void action() { }
/**
* Displays this Widget for hit detection
* in the local coordinatesystem of this Widget.
* @param gl the GL containing the OpenGL interface.
* @param glut the GLU containing the GLU interface.
*/
public void drawHit(GL gl, GLU glut) {
int width = width();
int height = height();
gl.glBegin(GL.GL_POLYGON);
gl.glVertex3d(0, 0, 0);
gl.glVertex3d(width, 0, 0);
gl.glVertex3d(width, height, 0);
gl.glVertex3d(0, height, 0);
gl.glEnd();
}
/**
* Returns the computed width of this Widget.
* @return the computed width.
*/
public abstract int width();
/**
* Returns the computed height of this Widget.
* @return the computed height.
*/
public abstract int height();
/**
* Displays this Widget in the global coordinatesystem of the window.
* @param gl the GL containing the OpenGL interface.
* @param glu the GLU containing the GLU interface.
* @param selection true if selection-mode is applied
*/
public void display(GL gl, GLU glu, boolean selection) {
gl.glPushMatrix();
gl.glTranslatef(x, y, 0);
if (selection) {
drawHit(gl, glu);
} else {
//drawHit(gl, glu);
draw(gl, glu);
}
gl.glPopMatrix();
}
}
--- NEW FILE: Label.java ---
//---------------------------------------------------------------------------------
// $Id: Label.java,v 1.1 2007/01/26 14:04:56 henryml Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.gl.model;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;
import com.sun.opengl.util.GLUT;
import net.sourceforge.bprocessor.model.Edge;
import net.sourceforge.bprocessor.model.Plane;
import net.sourceforge.bprocessor.model.Vertex;
/**
*
*/
public class Label extends Widget {
private String label;
/**
* Creates a label.
* @param label the label
*/
public Label(String label) {
this.label = label;
}
/** {@inheritDoc} */
public void draw(GL gl, GLU glu) {
GLUT glut = new GLUT();
gl.glRasterPos2i(0, 0);
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, label);
}
/** {@inheritDoc} */
@Override
public int height() {
return 12;
}
/** {@inheritDoc} */
public int width() {
GLUT glut = new GLUT();
return glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, label);
}
/** {@inheritDoc} */
public Plane getPlane() {
// TODO Auto-generated method stub
return null;
}
/** {@inheritDoc} */
public Vertex intersection(Edge e) {
// TODO Auto-generated method stub
return null;
}
/**
* {@inheritDoc}
*/
public String toString() {
return label;
}
}
|