Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28252/src/net/sourceforge/bprocessor/gl/view
Modified Files:
View.java
Log Message:
Added drag selection with the left mousebutton, and fixed the selectionBuffer so that if the selection were too big to fit in the selectionBuffer the size will double and it will try again, that will keep going forever, so some kind of valve have to be added if GL starts to redisplay all the time
Index: View.java
===================================================================
RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/view/View.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -C2 -d -r1.60 -r1.61
*** View.java 11 Feb 2006 18:00:00 -0000 1.60
--- View.java 14 Feb 2006 11:56:21 -0000 1.61
***************
*** 209,212 ****
--- 209,218 ----
protected IntBuffer selectBuffer;
+ /** The size of the selection buffer */
+ protected int selectionLength = 256;
+
+ /** The size of the selection box */
+ protected int[] selectionSize = new int[]{6, 6};
+
/** The objectTable used for assigning unique ID's during selection */
protected ArrayList objectTable;
***************
*** 449,456 ****
View.width = width;
if (picking > 0) {
! //notice 512 is just some magic number for the size of the selectbuffer
! // TODO Catch overflow in select buffer
! selectBuffer = BufferUtils.newIntBuffer(512);
! gl.glSelectBuffer(512, selectBuffer);
gl.glRenderMode(GL.GL_SELECT);
hitdetection = true;
--- 455,460 ----
View.width = width;
if (picking > 0) {
! selectBuffer = BufferUtils.newIntBuffer(selectionLength);
! gl.glSelectBuffer(selectionLength, selectBuffer);
gl.glRenderMode(GL.GL_SELECT);
hitdetection = true;
***************
*** 518,521 ****
--- 522,534 ----
gl.glFlush();
hits = gl.glRenderMode(GL.GL_RENDER);
+ if (hits < 0) {
+ // There were overflow in the selctionBuffer double the buffer and try again
+ selectionLength *= 2;
+ picking = 10;
+ glv.repaint(true);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Hits: " + hits);
+ }
} else {
gld.swapBuffers();
***************
*** 1794,1797 ****
--- 1807,1864 ----
/**
+ * find all geometry affected by the selection
+ * @return All geometry in the selection
+ */
+ private List getAllGeometryInSelection() {
+ List selection = new ArrayList();
+ int bufferOffset = 0;
+ int names = 0;
+
+ for (int i = 0; i < hits; i++) {
+ names = selectBuffer.get(bufferOffset);
+ bufferOffset += 3;
+ if (names > 0) {
+ int tar = selectBuffer.get(bufferOffset);
+ Object current = getName(tar);
+ selection.add(current);
+ bufferOffset += names;
+ }
+ }
+ return selection;
+ }
+
+ /**
+ * Gets id of the objects in a given area with corner x1,y1 and opposite corner x2,y2
+ * @param x1 the x coordinate in the first corner
+ * @param y1 the y coordinate in the first corner
+ * @param x2 the x coordinate in the second corner
+ * @param y2 the y coordinate in the second corner
+ * @return The objects in the area
+ */
+ public List getObjectInArea(double x1, double y1, double x2, double y2) {
+ double x = (x1 - x2);
+ double y = (y1 - y2);
+ // save default selection box
+ int[] tempsize = selectionSize;
+ // set new selection size
+ selectionSize = new int[] {(int)Math.abs(x) < 6 ? 6 : (int)Math.abs(x),
+ (int)Math.abs(y) < 6 ? 6 : (int)Math.abs(y)};
+
+ // Do selection on vertices
+ this.x = x1 - (x / 2);
+ this.y = y1 - (y / 2);
+ picking = 10;
+ selectMode = ALL;
+ int lengthTemp = selectionLength;
+ selectionLength = 2056;
+ glv.repaint(true);
+ List selection = getAllGeometryInSelection();
+ selectionLength = lengthTemp;
+ //restore default selection box
+ selectionSize = tempsize;
+ return selection;
+ }
+
+ /**
* Gets id of any Edges under a point. For use in selection.
* @param x the x coordinate of the point in mouse coordinates
***************
*** 2109,2113 ****
if (picking > 0) {
int[] viewport = new int[] {0, 0, (int)width, (int)height};
! glu.gluPickMatrix(x, viewport[3] - y, 6, 6, viewport);
}
--- 2176,2180 ----
if (picking > 0) {
int[] viewport = new int[] {0, 0, (int)width, (int)height};
! glu.gluPickMatrix(x, viewport[3] - y, selectionSize[0], selectionSize[1], viewport);
}
|