Exemplo n.º 1
0
    def drawString(self,string,col="yellow"):
        glPushMatrix()

        for l in range(0,len(string)):
            
            if string[l].upper()=="#":
                if len(string[l:])>2:
                    if string[l:l+3]=="###": break
            
            glPushMatrix()
            glTranslate(0,0,0.5)
            glColor(colours["black"])
            glLineWidth(3.0)
            if lists.has_key(string[l].upper()): glCallList(lists[string[l].upper()])
            else:  glCallList(lists[" "])
            glPopMatrix()
            
            glPushMatrix()
            glTranslate(0,0,0)
            glColor(colours[col])
            glLineWidth(0.5)
            if lists.has_key(string[l].upper()): glCallList(lists[string[l].upper()])
            else:  glCallList(lists[" "])
            glPopMatrix()
            glTranslate(14,0,0)

        glPopMatrix()
Exemplo n.º 2
0
    def draw(self):

        if self.lock==True: return

        try:



            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluPerspective(60.0,self.WIDTH/self.HEIGHT,1.,50.)
            glMatrixMode(GL_MODELVIEW)
            glLoadIdentity()
                      
            glEnable(GL_DEPTH_TEST)  

            glPushMatrix()

            #tweaks to set up and a white wired cube for 1,1,1 scale help
            glTranslate(0,0,0-self.zoom)
            glTranslate(0,0,3)
            glRotate(-self.yRot*2,1,0,0)
            glRotate(-self.xRot*2,0,1,0)
            glMaterialfv(GL_FRONT,GL_DIFFUSE,colours["white"])
            glutWireCube(1)

            ##axes
            glBegin(GL_LINES)

            glMaterialfv(GL_FRONT,GL_DIFFUSE,colours["red"])
            for xxx in range(1,10):
                glVertex3f(0.5*(xxx-1), 0, 0)
                glVertex3f(0.5*(xxx), 0, 0)

            glMaterialfv(GL_FRONT,GL_DIFFUSE,colours["green"])
            for xxx in range(1,10):
                glVertex3f(0,0.5*(xxx-1), 0)
                glVertex3f(0,0.5*(xxx), 0)

            glMaterialfv(GL_FRONT,GL_DIFFUSE,colours["blue"])
            for xxx in range(1,10):
                glVertex3f(0,0,0.5*(xxx-1))
                glVertex3f(0,0,0.5*(xxx))

            glEnd()

            ##set colour to white
            glMaterialfv(GL_FRONT,GL_DIFFUSE,colours["white"])

            try:
                ERROR_MESSAGE=""
                ##danger code! - literally dump python script into scene
                offset=0
                for t in self.temp:
                    if t=="glPopMatrix()": offset-=1
                    exec(t)
                    if t=="glPushMatrix()": offset+=1
                
            except Exception as e:                    
                ERROR_MESSAGE=str(e).upper()
                #print ERROR_MESSAGE
                while offset>0:
                    glPopMatrix()
                    offset-=1
                    
                
            
            glPopMatrix()
            
            
            

            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            gluOrtho2D(0,self.WIDTH,0,self.HEIGHT)
            glMatrixMode(GL_MODELVIEW)            
            glLoadIdentity()
            
            glDisable(GL_DEPTH_TEST)  
            
            #glScale(self.WIDTH/640.0,self.WIDTH/640.0,1)
            
            textOn=True
            #if self.X %2 == 0: textOn=False
            
            if textOn==True:

                #disable lights for the text etc
                glDisable(GL_LIGHTING)

                #for xxx in range(0,5): #int(self.WIDTH),10):
                #    for yyy in range(0,5): #int(self.HEIGHT),10):                
                #        glPushMatrix()
                #        glTranslate(xxx,yyy,0)
                #        #glutWireCube(.5)
                #        self.drawString("*")
                #        glPopMatrix()

                #glPushMatrix()
                #glTranslate(-0.7,0,0)
                #glScale(0.0028,0.003,0.003)
                #glTranslate(0,0,1255)

                #glTranslate(-100,0,0)


                #draw the editor state word top left
                glPushMatrix()
                glTranslate(20,self.HEIGHT-20,0)   
                self.drawString(self.state.upper())
                
                if not ERROR_MESSAGE=="":
                    #print "argrgrg"
                    glTranslate(0,-30,0)   
                    self.drawString(ERROR_MESSAGE,"red")
                
                glPopMatrix()

                mn=0


                glTranslate(20,self.HEIGHT/2,0)



                glTranslate(0,-15,0)
                if len(self.menu)>0: self.drawString("*")
                        
                glTranslate(0,15,0)

                
                ##shift everything so the cursor is always at the centre screen
                glTranslate(0,14*self.menuindex,0)


                temponly=False







                ##check to see if menu has anything in it - overwrite temporarily if so
                if self.state=="browse":
                    if len(self.menu)==0:
                        self.menu=["NO ITEMS"]
                        temponly=True
                    else:
                        self.menu=self.temp







                #this block is to compile or draw menu
                
                
                '''            
                lists["menu"] = glGenLists(1) 
                glNewList(lists["menu"],GL_COMPILE) 
                    #....
                glEndList()
                '''
                
                '''                
                if lists.has_key("menu"): glCallList(lists["menu"])
                '''



                
                if self.lastMenu==self.menu:
                    if lists.has_key("menu"): glCallList(lists["menu"])
                    #print("menu called")
                else:
                    #print("menu generated") 
                    
                    lists["menu"] = glGenLists(1) 
                    glNewList(lists["menu"],GL_COMPILE) 


                    ##draw the menu
                    ##push offset
                    offset=0

                    for mi in self.menu:

                        if mi=="glPopMatrix()": offset-=1

                        string=""
                        offsetspaces=""
                        for oo in range(0,offset):
                            offsetspaces+=" "

                        
                        #print mi
                        if mn==self.menuindex:
                            #print "yo!"
                            string=" "+offsetspaces+mi
                        else:
                            string=" "+offsetspaces+mi
                        
        
                        #glTranslate(10,0,0)
                        glTranslate(0,-14,0)
                        self.drawString(string)
                        mn+=1

                        if mi=="glPushMatrix()": offset+=1


                    glEndList()






                self.lastMenu=self.menu


                ##put back normal menu
                if temponly==True: self.menu=[]

                #glPopMatrix()

                glEnable(GL_LIGHTING)

        except Exception as e:

            print str(traceback.print_exc(file=sys.stdout))

            print "Bollocks! Dumping\n----------------------------\n\n"
            for f in self.temp:
                print f

            print "\n----------------------------\nBollocks! Dumped!\n\n"
            sys.exit(0)

        finally:
            pass