def drawMarquee(self, x0, y0, x1, y1): GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GLU.gluOrtho2D(0.0, self.width, 0.0, self.height) # (0,0) at bottom-left GL.glLineStipple(1, 0x5555) GL.glLineWidth(1.0) GL.glEnable(GL.GL_LINE_STIPPLE) GL.glEnable(GL.GL_COLOR_LOGIC_OP) GL.glLogicOp(GL.GL_INVERT) GL.glTranslatef(0.375, 0.375, 0.0) GL.glColor3f(1,1,1) GL.glBegin(GL.GL_LINE_LOOP) GL.glVertex2i(x0,y0) GL.glVertex2i(x1,y0) GL.glVertex2i(x1,y1) GL.glVertex2i(x0,y1) GL.glEnd() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPopMatrix() GL.glDisable(GL.GL_LINE_STIPPLE) GL.glDisable(GL.GL_COLOR_LOGIC_OP)
def display(self): """(Re)display all the actors in the scene. This should e.g. be used when actors are added to the scene, or after changing camera position/orientation or lens. """ #GD.debugt("UPDATING CURRENT OPENGL CANVAS") self.makeCurrent() self.clear() self.glLight(self.lighting) # Draw Scene Actors self.camera.loadProjection() self.camera.loadMatrix() if self.alphablend: opaque = [ a for a in self.actors if not a.trans ] transp = [ a for a in self.actors if a.trans ] for actor in opaque: actor.draw(mode=self.rendermode) GL.glEnable (GL.GL_BLEND) GL.glDepthMask (GL.GL_FALSE) GL.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) for actor in transp: actor.draw(mode=self.rendermode) GL.glDepthMask (GL.GL_TRUE) GL.glDisable (GL.GL_BLEND) else: for actor in self.actors: self.setDefaults() actor.draw(mode=self.rendermode) # draw the highlighted actors if self.highlights: print "highlighting actors" GL.glDepthMask (GL.GL_FALSE) GL.glEnable(GL.GL_COLOR_LOGIC_OP) GL.glLogicOp(GL.GL_INVERT) for actor in self.highlights: actor.draw(mode=self.rendermode) GL.glDisable(GL.GL_COLOR_LOGIC_OP) GL.glDepthMask (GL.GL_TRUE) # annotations are drawn in 3D space for actor in self.annotations: self.setDefaults() actor.draw(mode=self.rendermode) # decorations are drawn in 2D mode self.begin_2D_drawing() for actor in self.decorations: self.setDefaults() actor.draw(mode=self.rendermode) self.end_2D_drawing() # make sure canvas is updated GL.glFlush()
def mouse_rectangle_zoom(self,x,y,action): """Process mouse events during interactive rectangle zooming. On PRESS, record the mouse position. On MOVE, create a rectangular zoom window. On RELEASE, zoom to the picked rectangle. """ if action == PRESS: self.makeCurrent() self.update() if self.trackfunc: print "PRESS",self.trackfunc,pf.canvas.camera.ctr pf.canvas.camera.setTracking(True) x,y,z = pf.canvas.camera.ctr self.zplane = pf.canvas.project(x,y,z,True)[2] print 'ZPLANE',self.zplane self.trackfunc(x,y,self.zplane) self.begin_2D_drawing() GL.glEnable(GL.GL_COLOR_LOGIC_OP) # An alternative is GL_XOR # GL.glLogicOp(GL.GL_INVERT) # Draw rectangle self.draw_state_rect(x,y) self.swapBuffers() elif action == MOVE: if self.trackfunc: print "MOVE",self.trackfunc print 'ZPLANE',self.zplane self.trackfunc(x,y,self.zplane) # Remove old rectangle self.swapBuffers() self.draw_state_rect(*self.state) # Draw new rectangle self.draw_state_rect(x,y) self.swapBuffers() elif action == RELEASE: GL.glDisable(GL.GL_COLOR_LOGIC_OP) self.end_2D_drawing() x0 = min(self.statex,x) y0 = min(self.statey,y) x1 = max(self.statex,x) y1 = max(self.statey,y) self.zoomRectangle(x0,y0,x1,y1) self.finish_rectangle_zoom()
def mouse_pick(self,x,y,action): """Process mouse events during interactive picking. On PRESS, record the mouse position. On MOVE, create a rectangular picking window. On RELEASE, pick the objects inside the rectangle. """ if action == PRESS: self.makeCurrent() self.update() self.begin_2D_drawing() #self.swapBuffers() GL.glEnable(GL.GL_COLOR_LOGIC_OP) # An alternative is GL_XOR # GL.glLogicOp(GL.GL_INVERT) # Draw rectangle self.draw_state_rect(x,y) self.swapBuffers() elif action == MOVE: # Remove old rectangle self.swapBuffers() self.draw_state_rect(*self.state) # Draw new rectangle self.draw_state_rect(x,y) self.swapBuffers() elif action == RELEASE: GL.glDisable(GL.GL_COLOR_LOGIC_OP) self.swapBuffers() self.end_2D_drawing() x,y = (x+self.statex)/2., (y+self.statey)/2. w,h = abs(x-self.statex)*2., abs(y-self.statey)*2. if w <= 0 or h <= 0: w,h = pf.cfg.get('pick/size',(20,20)) vp = GL.glGetIntegerv(GL.GL_VIEWPORT) self.pick_window = (x,y,w,h,vp) self.selection_busy = False
def mouse_rectangle_zoom(self,x,y,action): """Process mouse events during interactive picking. On PRESS, record the mouse position. On MOVE, create a rectangular picking window. On RELEASE, pick the objects inside the rectangle. """ if action == PRESS: self.makeCurrent() self.update() self.begin_2D_drawing() #self.swapBuffers() GL.glEnable(GL.GL_COLOR_LOGIC_OP) # An alternative is GL_XOR # GL.glLogicOp(GL.GL_INVERT) # Draw rectangle self.draw_state_rect(x,y) self.swapBuffers() elif action == MOVE: # Remove old rectangle self.swapBuffers() self.draw_state_rect(*self.state) # Draw new rectangle self.draw_state_rect(x,y) self.swapBuffers() elif action == RELEASE: GL.glDisable(GL.GL_COLOR_LOGIC_OP) #self.swapBuffers() self.end_2D_drawing() x0 = min(self.statex,x) y0 = min(self.statey,y) x1 = max(self.statex,x) y1 = max(self.statey,y) self.zoomRectangle(x0,y0,x1,y1) self.finish_rectangle_zoom()
def mouse_draw_line(self,x,y,action): """Process mouse events during interactive drawing. On PRESS, record the mouse position. On MOVE, draw a line. On RELEASE, add the line to the drawing. """ if action == PRESS: self.makeCurrent() self.update() self.begin_2D_drawing() self.swapBuffers() GL.glEnable(GL.GL_COLOR_LOGIC_OP) # An alternative is GL_XOR # GL.glLogicOp(GL.GL_INVERT) # Draw rectangle if self.drawing.size != 0: self.statex,self.statey = self.drawing[-1,-1] self.draw_state_line(x,y) self.swapBuffers() elif action == MOVE: # Remove old rectangle self.swapBuffers() self.draw_state_line(*self.state) # Draw new rectangle self.draw_state_line(x,y) self.swapBuffers() elif action == RELEASE: GL.glDisable(GL.GL_COLOR_LOGIC_OP) #self.swapBuffers() self.end_2D_drawing() self.drawn = asarray([[self.statex,self.statey],[x,y]]) self.drawing_busy = False