📄 interactionbox.java
字号:
package AccordionDrawer;import gl4java.*;import java.awt.*;/** * Draw and cache information about an onscreen rubberband box. * Because we need to draw exactly this box again to erase it in XOR * mode, we must cache the corner points instead of looking them up * dynamically. * @see GridCell * @author Tamara Munzner */public class InteractionBox { static final int X=AccordionDrawer.X; static final int Y=AccordionDrawer.Y; float linewidth = 3.0f; Color col; float plane; public int moveLine[] = new int[2]; // store where the interaction box drag starts/ends in the interaction box public int dragStart[] = new int[2]; public int dragEnd[] = new int[2]; public int oldDragEnd[] = new int[2]; public int originalMovePixelPosition[] = new int[2]; // store the location of the stuck positions set when starting drag, position zero for X, one for Y public int stuckLineIndex[] = new int[2]; // location of movable lines set when starting drag, position zero for X, one for Y public int moveLineIndex[] = new int[2]; // store the bounding box, later reassigned to stuckLine and moveLine when drag starts private int[] minLineIndex = new int[2], maxLineIndex = new int[2]; public CellGeom item; AccordionDrawer d; public InteractionBox(int minSplit[], int maxSplit[], CellGeom item, AccordionDrawer d) { this.minLineIndex[X] = minSplit[X]; this.minLineIndex[Y] = minSplit[Y]; this.maxLineIndex[X] = maxSplit[X]; this.maxLineIndex[Y] = maxSplit[Y]; this.d = d; this.dragStart[X] = this.dragStart[Y] = -1; // init this.item = item; } public void setDragPoints(int[] dragStart, int[] dragEnd) { int frameNum = d.getFrameNum(); for (int xy = X; xy <= Y; xy++) { if (this.dragStart[xy] == -1) // initialized but not set the first time { this.dragStart[xy] = dragStart[xy]; if (isMinLineMoving(dragStart[xy], xy)) { moveLineIndex[xy] = minLineIndex[xy]; stuckLineIndex[xy] = maxLineIndex[xy]; originalMovePixelPosition[xy] = d.w2s(d.splitLine[xy].getAbsoluteValue(moveLineIndex[xy], frameNum), xy); } else { moveLineIndex[xy] = maxLineIndex[xy]; stuckLineIndex[xy] = minLineIndex[xy]; originalMovePixelPosition[xy] = d.w2s(d.splitLine[xy].getAbsoluteValue(moveLineIndex[xy], frameNum), xy); } } this.dragEnd[xy] = dragEnd[xy]; } } public void updateDrag(int[] dragEnd) { for (int xy = X; xy <= Y; xy++) { oldDragEnd[xy] = this.dragEnd[xy]; this.dragEnd[xy] = dragEnd[xy]; } } // set moveLine[xy] to 0 if dragEnd is closer to minimum (or 1 if closer to maximum) public boolean isMinLineMoving(int dragEnd, int xy) { return (getMax(xy) + getMin(xy))/2 >= dragEnd; // midpoint of box is bigger than dragEnd } public void draw(Color col, float linewidth, float plane) { this.col = col; //System.out.println("new interaction box: " + col); this.linewidth = linewidth; this.plane = plane; drawRubberband(); } public void undraw(){ drawRubberband(); } public double getMinAbs(int xy) { return d.splitLine[xy].getAbsoluteValue(minLineIndex[xy], d.getFrameNum()); } public int getMinLine(int xy) { return minLineIndex[xy]; } public int getMaxLine(int xy) { return maxLineIndex[xy]; } // get min pixel in direction xy public int getMin(int xy) {// d.splitLine[xy].computePlaceThisFrame(minLineIndex[xy]); return d.w2s(d.splitLine[xy].getAbsoluteValue(minLineIndex[xy], d.getFrameNum()), xy); } public double getMaxAbs(int xy) { return d.splitLine[xy].getAbsoluteValue(maxLineIndex[xy], d.getFrameNum()); } // get max pixel in direction xy public int getMax(int xy) {// d.splitLine[xy].computePlaceThisFrame(maxLineIndex[xy]); return d.w2s(d.splitLine[xy].getAbsoluteValue(maxLineIndex[xy], d.getFrameNum()), xy); } public double getCenterAbs(int xy) { return (getMinAbs(xy) + getMaxAbs(xy))/2; } public void drawRubberband() { int x = 0, y = 1; GLFunc gl = d.gl; GLCapabilities glc = d.glc; // set rendering in frontbuffer if you are // still in doublebuffer mode // don't set it to backbuffer // this is only for the startframe //gl.glDrawBuffer(GLEnum.GL_FRONT); //glc.setDoubleBuffered(false); // enable all your states boolean doubleBufferOriginal = d.getDoubleBuffer(); d.setDoubleBuffer(false, false); gl.glEnable(GLEnum.GL_COLOR_LOGIC_OP); gl.glLogicOp(GLEnum.GL_XOR); int min[] = new int[2]; int max[] = new int[2]; int center[] = new int[2]; for (int xy = X; xy <= Y; xy++) { min[xy] = getMin(xy); max[xy] = getMax(xy); center[xy] = (int)((max[xy]-min[xy])/2.0 + min[xy]); } float thecol[] = new float[3]; col.getRGBColorComponents(thecol); gl.glColor3f(thecol[0], thecol[1], thecol[2]); gl.glLineWidth(linewidth);// if(d.drawDirection == AccordionDrawer.LEFT) { gl.glBegin(GLEnum.GL_LINE_LOOP); gl.glVertex3d(d.s2w(min[x],x), d.s2w(max[y],y), plane); gl.glVertex3d(d.s2w(max[x],x), d.s2w(max[y],y), plane); gl.glVertex3d(d.s2w(max[x],x), d.s2w(min[y],y), plane); gl.glVertex3d(d.s2w(min[x],x), d.s2w(min[y],y), plane); gl.glEnd(); //System.out.println("band" + d.s2w(min[x],x) +" " + d.s2w(min[y],y) +" " + d.s2w(max[y],y) + " " + d.s2w(max[x],x)); gl.glPointSize(linewidth+2f); gl.glBegin(GLEnum.GL_POINTS); gl.glVertex3d(d.s2w(center[x],x), d.s2w(center[y],y), plane); gl.glEnd(); }// else if(d.drawDirection == AccordionDrawer.RIGHT)// {// gl.glBegin(GLEnum.GL_LINE_LOOP);// gl.glVertex3d(d.s2w(d.getWinsize(x)-min[x],x), d.s2w(max[y],y), plane);// gl.glVertex3d(d.s2w(d.getWinsize(x)-max[x],x), d.s2w(max[y],y), plane);// gl.glVertex3d(d.s2w(d.getWinsize(x)-max[x],x), d.s2w(min[y],y), plane);// gl.glVertex3d(d.s2w(d.getWinsize(x)-min[x],x), d.s2w(min[y],y), plane);// gl.glEnd();// //System.out.println("band" + d.s2w(min[x],x) +" " + d.s2w(min[y],y) +" " + d.s2w(max[y],y) + " " + d.s2w(max[x],x));// gl.glPointSize(linewidth+2f);// gl.glBegin(GLEnum.GL_POINTS);// gl.glVertex3d(d.s2w(d.getWinsize(x)-center[x],x), d.s2w(center[y],y), plane);// gl.glEnd();// }// else if(d.drawDirection == AccordionDrawer.UP)// {// gl.glBegin(GLEnum.GL_LINE_LOOP);// gl.glVertex3d(d.s2w(max[y],y), 1-d.s2w(min[x],x), plane);// gl.glVertex3d(d.s2w(max[y],y), 1-d.s2w(max[x],x), plane);// gl.glVertex3d( d.s2w(min[y],y),1-d.s2w(max[x],x), plane);// gl.glVertex3d( d.s2w(min[y],y), 1-d.s2w(min[x],x),plane); gl.glEnd();// //System.out.println("band" + d.s2w(min[x],x) +" " + d.s2w(min[y],y) +" " + d.s2w(max[y],y) + " " + d.s2w(max[x],x));// gl.glPointSize(linewidth+2f);// gl.glBegin(GLEnum.GL_POINTS);// gl.glVertex3d(d.s2w(center[y],y), 1-d.s2w(center[x],x), plane);// gl.glEnd();// }// else if(d.drawDirection == AccordionDrawer.DOWN)// {// gl.glBegin(GLEnum.GL_LINE_LOOP);// gl.glVertex3d(1-d.s2w(max[y],y), d.s2w(min[x],x), plane);// gl.glVertex3d(1-d.s2w(max[y],y), d.s2w(max[x],x), plane);// gl.glVertex3d(1- d.s2w(min[y],y),d.s2w(max[x],x), plane);// gl.glVertex3d(1- d.s2w(min[y],y), d.s2w(min[x],x),plane); gl.glEnd();// //System.out.println("band" + d.s2w(min[x],x) +" " + d.s2w(min[y],y) +" " + d.s2w(max[y],y) + " " + d.s2w(max[x],x));// gl.glPointSize(linewidth+2f);// gl.glBegin(GLEnum.GL_POINTS);// gl.glVertex3d(1-d.s2w(center[y],y), d.s2w(center[x],x), plane);// gl.glEnd();// } // disable states gl.glDisable(GLEnum.GL_COLOR_LOGIC_OP); d.setDoubleBuffer(doubleBufferOriginal, false); // no redraw, !start and !continue so third arg doesn't matter// gl.glDisable(GLEnum.GL_DEPTH_TEST); } public String toString() { return getMinAbs(X) + " " + getMaxAbs(X) + " " + getMinAbs(Y) + " " + getMaxAbs(Y);// return minLineIndex[X] + " " + maxLineIndex[X] + " " + minLineIndex[Y] + " " + maxLineIndex[Y]; } public boolean moveStuck() { return minLineIndex[X] == maxLineIndex[X] || minLineIndex[Y] == maxLineIndex[Y]; } /** * @return */ public AccordionDrawer getDrawer() { return d; }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -