~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to release/scripts/console.py

  • Committer: Dietrich Bollmann
  • Date: 2009-04-26 06:25:14 UTC
  • mfrom: (184.1.520)
  • Revision ID: diresu@web.de-20090426062514-ly27wepl1t5d7p8s
Update to state of blender repository from 2009-04-26 revision 19927.

Show diffs side-by-side

added added

removed removed

Lines of Context:
708
708
        # Fixed margin. use a margin since 0 margin can be hard to seewhen close to a crt's edge.
709
709
        margin = 4
710
710
        
 
711
        # Convenience
 
712
        FNT_NAME, FNT_HEIGHT = __FONT_SIZES__[__FONT_SIZE__]
 
713
        
711
714
        # Draw cursor location colour
712
715
        if __CONSOLE_LINE_OFFSET__ == 0:
713
 
                cmd2curWidth = Draw.GetStringWidth(cmdBuffer[-1].cmd[:cursor], __FONT_SIZES__[__FONT_SIZE__][0])
 
716
                cmd2curWidth = Draw.GetStringWidth(cmdBuffer[-1].cmd[:cursor], FNT_NAME)
714
717
                BGL.glColor3f(0.8, 0.2, 0.2)
715
718
                if cmd2curWidth == 0:
716
 
                        BGL.glRecti(margin,2,margin+2, __FONT_SIZES__[__FONT_SIZE__][1]+2)
 
719
                        BGL.glRecti(margin,2,margin+2, FNT_HEIGHT+2)
717
720
                else:
718
 
                        BGL.glRecti(margin + cmd2curWidth-2,2, margin+cmd2curWidth, __FONT_SIZES__[__FONT_SIZE__][1]+2)
 
721
                        BGL.glRecti(margin + cmd2curWidth-2,2, margin+cmd2curWidth, FNT_HEIGHT+2)
719
722
        
720
723
        BGL.glColor3f(1,1,1)
721
724
        # Draw the set of cammands to the buffer
722
725
        consoleLineIdx = __CONSOLE_LINE_OFFSET__ + 1
723
726
        wrapLineIndex = 0
724
 
        while consoleLineIdx < len(cmdBuffer) and  __CONSOLE_RECT__[3] > (consoleLineIdx - __CONSOLE_LINE_OFFSET__) * __FONT_SIZES__[__FONT_SIZE__][1]:
 
727
        while consoleLineIdx < len(cmdBuffer) and  __CONSOLE_RECT__[3] > (consoleLineIdx - __CONSOLE_LINE_OFFSET__) * FNT_HEIGHT:
725
728
                if cmdBuffer[-consoleLineIdx].type == 0:
726
729
                        BGL.glColor3f(1, 1, 1)
727
730
                elif cmdBuffer[-consoleLineIdx].type == 1:
734
737
                        BGL.glColor3f(1, 1, 0)
735
738
                
736
739
                if consoleLineIdx == 1: # user input
737
 
                        BGL.glRasterPos2i(margin, (__FONT_SIZES__[__FONT_SIZE__][1] * (consoleLineIdx-__CONSOLE_LINE_OFFSET__)) - 8)
738
 
                        Draw.Text(cmdBuffer[-consoleLineIdx].cmd, __FONT_SIZES__[__FONT_SIZE__][0])             
739
 
                else:
740
 
                        BGL.glRasterPos2i(margin, (__FONT_SIZES__[__FONT_SIZE__][1] * ((consoleLineIdx-__CONSOLE_LINE_OFFSET__)+wrapLineIndex)) - 8)
741
 
                        Draw.Text(cmdBuffer[-consoleLineIdx].cmd, __FONT_SIZES__[__FONT_SIZE__][0])
742
 
 
743
 
                # Wrapping is totally slow, can even hang blender - dont do it!
744
 
                '''
745
 
                if consoleLineIdx == 1: # NEVER WRAP THE USER INPUT
746
 
                        BGL.glRasterPos2i(margin, (__FONT_SIZES__[__FONT_SIZE__][1] * (consoleLineIdx-__CONSOLE_LINE_OFFSET__)) - 8)
747
 
                        # BUG, LARGE TEXT DOSENT DISPLAY
748
 
                        Draw.Text(cmdBuffer[-consoleLineIdx].cmd, __FONT_SIZES__[__FONT_SIZE__][0])
749
 
                        
750
 
                
751
 
                else: # WRAP?
752
 
                        # LINE WRAP
753
 
                        if Draw.GetStringWidth(cmdBuffer[-consoleLineIdx].cmd, __FONT_SIZES__[__FONT_SIZE__][0]) >  __CONSOLE_RECT__[2]:
 
740
                        BGL.glRasterPos2i(margin, (FNT_HEIGHT * (consoleLineIdx-__CONSOLE_LINE_OFFSET__)) - 8)
 
741
                        Draw.Text(cmdBuffer[-consoleLineIdx].cmd, FNT_NAME)             
 
742
                else: # WRAP
 
743
                        lwid = Draw.GetStringWidth(cmdBuffer[-consoleLineIdx].cmd, FNT_NAME)
 
744
                        if margin + lwid >  __CONSOLE_RECT__[2]:
754
745
                                wrapLineList = []
755
 
                                copyCmd = [cmdBuffer[-consoleLineIdx].cmd, '']
756
 
                                while copyCmd != ['','']:
757
 
                                        while margin + Draw.GetStringWidth(copyCmd[0], __FONT_SIZES__[__FONT_SIZE__][0]) > __CONSOLE_RECT__[2]:
758
 
                                                #print copyCmd
759
 
                                                copyCmd[1] = '%s%s'% (copyCmd[0][-1], copyCmd[1]) # Add the char on the end
760
 
                                                copyCmd[0] = copyCmd[0][:-1]# remove last chat
761
 
                                        
762
 
                                        # Now we have copyCmd[0] at a good length we can print it.                                      
763
 
                                        if copyCmd[0] != '':
764
 
                                                wrapLineList.append(copyCmd[0])
765
 
                                        
766
 
                                        copyCmd[0]=''
767
 
                                        copyCmd = [copyCmd[1], copyCmd[0]]
768
 
                                
 
746
                                wtext = cmdBuffer[-consoleLineIdx].cmd
 
747
                                wlimit = len(wtext)
 
748
                                chunksz = int(( __CONSOLE_RECT__[2] - margin ) / (lwid / len(wtext)))
 
749
                                lstart = 0
 
750
                                fsize = FNT_NAME
 
751
                                while lstart < wlimit:
 
752
                                        lend = min(lstart+chunksz,wlimit)
 
753
                                        ttext = wtext[lstart:lend]
 
754
                                        while lend < wlimit and Draw.GetStringWidth(ttext, fsize) + margin < __CONSOLE_RECT__[2]:
 
755
                                                lend += 1
 
756
                                                ttext = wtext[lstart:lend]
 
757
                                        while lend > lstart+1 and Draw.GetStringWidth(ttext, fsize) + margin > __CONSOLE_RECT__[2]:
 
758
                                                lend -= 1
 
759
                                                ttext = wtext[lstart:lend]
 
760
                                        wrapLineList.append(ttext)
 
761
                                        lstart = lend 
769
762
                                # Now we have a list of lines, draw them (OpenGLs reverse ordering requires this odd change)
770
763
                                wrapLineList.reverse()
771
764
                                for wline in wrapLineList:
772
 
                                        BGL.glRasterPos2i(margin, (__FONT_SIZES__[__FONT_SIZE__][1]*((consoleLineIdx-__CONSOLE_LINE_OFFSET__) + wrapLineIndex)) - 8)
773
 
                                        Draw.Text(wline, __FONT_SIZES__[__FONT_SIZE__][0])
 
765
                                        BGL.glRasterPos2i(margin, (FNT_HEIGHT*((consoleLineIdx-__CONSOLE_LINE_OFFSET__) + wrapLineIndex)) - 8)
 
766
                                        Draw.Text(wline, FNT_NAME)
774
767
                                        wrapLineIndex += 1
775
 
                                wrapLineIndex-=1 # otherwise we get a silly extra line.
 
768
                                wrapLineIndex-=1 # otherwise we get a silly extra line. 
776
769
                                
777
770
                        else: # no wrapping.
778
771
                                
779
 
                                BGL.glRasterPos2i(margin, (__FONT_SIZES__[__FONT_SIZE__][1] * ((consoleLineIdx-__CONSOLE_LINE_OFFSET__)+wrapLineIndex)) - 8)
780
 
                                Draw.Text(cmdBuffer[-consoleLineIdx].cmd, __FONT_SIZES__[__FONT_SIZE__][0])
781
 
                '''
 
772
                                BGL.glRasterPos2i(margin, (FNT_HEIGHT * ((consoleLineIdx-__CONSOLE_LINE_OFFSET__)+wrapLineIndex)) - 8)
 
773
                                Draw.Text(cmdBuffer[-consoleLineIdx].cmd, FNT_NAME)
782
774
                consoleLineIdx += 1
783
 
                        
784
775
 
785
776
# This recieves the event index, call a function from here depending on the event.
786
777
def handle_button_event(evt):