Changeset 111

Show
Ignore:
Timestamp:
03/03/2012 02:39:20 AM (2 years ago)
Author:
ecoughlan
Message:

Centering text

Location:
src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • src/alert.py

    r69 r111  
    2929            okay = WindowEntry(Response(self.optionResponse,[],True,False)) 
    3030            okay.addRectangle(Rectangle((378,120),56,25,GRAY)) 
    31             okay.addText(Text((386,125),'OKAY',24,FAKEBLACK)) 
     31            okay.addText(Text((378,125),'OKAY',24,FAKEBLACK,378+56,True,378)) 
    3232            alertWindow.addEntry(okay) 
    3333            cancel = WindowEntry(Response('windows',[],True,False)) 
    3434            cancel.addRectangle(Rectangle((438,120),56,25,GRAY)) 
    35             cancel.addText(Text((442,125),'CANCEL',24,FAKEBLACK)) 
     35            cancel.addText(Text((438,125),'CANCEL',24,FAKEBLACK,438+56,True,438)) 
    3636            alertWindow.addEntry(cancel) 
    3737        else: 
    3838            close = WindowEntry(Response('windows',[],True,False)) 
    39             close.addRectangle(Rectangle((440,120),55,25,GRAY)) 
    40             close.addText(Text((445,125),'CLOSE',24,FAKEBLACK)) 
     39            close.addRectangle(Rectangle((440,120),56,25,GRAY)) 
     40            close.addText(Text((440,125),'CLOSE',24,FAKEBLACK,440+56,True,440)) 
    4141            alertWindow.addEntry(close) 
    4242        return alertWindow 
  • src/spinner.py

    r107 r111  
    3131 
    3232        cancelButton = WindowEntry(Response('spinner',[],True,False,'cancel')) 
    33         cancelButton.addRectangle(Rectangle((295,75),80,20,GRAY)) 
    34         cancelButton.addText(Text((300,76),'CANCEL',24,FAKEBLACK)) 
     33        cancelButton.addRectangle(Rectangle((285,75),80,20,GRAY)) 
     34        cancelButton.addText(Text((285,76),'CANCEL',24,FAKEBLACK,285+80,True,285)) 
    3535        researchWindow.addEntry(cancelButton) 
    3636         
    3737        researchButton = WindowEntry(Response('spinner',[],True,False,'research')) 
    3838        researchButton.addRectangle(Rectangle((195,75),80,20,GRAY)) 
    39         researchButton.addText(Text((200,76),'RESEARCH',24,FAKEBLACK)) 
     39        researchButton.addText(Text((195,76),'RESEARCH',24,FAKEBLACK,195+80,True,195)) 
    4040        researchWindow.addEntry(researchButton) 
    4141         
    4242        incrementButton = WindowEntry(Response('spinner',[],False,False,'increment')) 
    43         incrementButton.addRectangle(Rectangle((300,6),20,30,YELLOW)) 
    44         incrementButton.addText(Text((300,5),'^',72,FAKEBLACK)) 
     43        incrementButton.addRectangle(Rectangle((300,6),25,30,YELLOW)) 
     44        incrementButton.addText(Text((300,2),'^',72,FAKEBLACK,300+25,True,300)) 
    4545        researchWindow.addEntry(incrementButton) 
    4646         
    4747        decrementButton = WindowEntry(Response('spinner',[],False,False,'decrement')) 
    48         decrementButton.addRectangle(Rectangle((300,40),20,25,YELLOW)) 
    49         decrementButton.addText(Text((300,30),'v',72,FAKEBLACK)) 
     48        decrementButton.addRectangle(Rectangle((300,40),25,30,YELLOW)) 
     49        decrementButton.addText(Text((300,28),'v',72,FAKEBLACK,300+25,True,300)) 
    5050        researchWindow.addEntry(decrementButton) 
    5151         
  • src/staticWindows.py

    r109 r111  
    4646buildIcon.addImage(Image((5,5),IMG_SM,IMG_SM,buildArt,)) 
    4747buildIcon.addRectangle(Rectangle((0,0),BUTTON_W,BUTTON_H,BLUE)) 
    48 buildIcon.addText(Text((65,17),"BUILD",BUTTON_TEXT,WHITE)) 
     48buildIcon.addText(Text((0,17),"BUILD",BUTTON_TEXT,WHITE,BUTTON_W,True,0)) 
    4949buttons.addEntry(buildIcon) 
    5050 
     
    5454researchIcon.addImage(Image((5+BUTTON_SHIFT,5),IMG_SM,IMG_SM,buildArt)) 
    5555researchIcon.addRectangle(Rectangle((BUTTON_SHIFT,0),BUTTON_W,BUTTON_H,BLUE)) 
    56 researchIcon.addText(Text((45+BUTTON_SHIFT,17),"RESEARCH",BUTTON_TEXT,WHITE)) 
     56researchIcon.addText(Text((BUTTON_SHIFT,17),"RESEARCH",BUTTON_TEXT,WHITE,BUTTON_W+BUTTON_SHIFT,True,BUTTON_SHIFT)) 
    5757buttons.addEntry(researchIcon) 
    5858 
     
    6060endTurnButton = WindowEntry(Response('endTurn',[],False,False)) 
    6161endTurnButton.addRectangle(Rectangle((BUTTON_SHIFT*2,0),BUTTON_W,BUTTON_H,BLUE)) 
    62 endTurnButton.addText(Text((32+BUTTON_SHIFT*2,17),"END TURN",BUTTON_TEXT,WHITE)) 
     62endTurnButton.addText(Text((BUTTON_SHIFT*2,17),"END TURN",BUTTON_TEXT,WHITE,BUTTON_W+BUTTON_SHIFT*2,True,BUTTON_SHIFT*2)) 
    6363buttons.addEntry(endTurnButton) 
    6464 
     
    7272mainMenuButton = WindowEntry(Response('mainMenu',[],False,False)) 
    7373mainMenuButton.addRectangle(Rectangle((0,0),BUTTON_W,BUTTON_H,BLUE)) 
    74 mainMenuButton.addText(Text((32,17),"MAIN MENU",BUTTON_TEXT,WHITE)) 
     74mainMenuButton.addText(Text((0,17),"MAIN MENU",BUTTON_TEXT,WHITE,BUTTON_W,True,0)) 
    7575mainButtons.addEntry(mainMenuButton) 
    7676 
    7777undoTurnButton = WindowEntry(Response('windows',['undoAlert'],False,False)) 
    7878undoTurnButton.addRectangle(Rectangle((BUTTON_SHIFT,0),BUTTON_W,BUTTON_H,BLUE)) 
    79 undoTurnButton.addText(Text((32+BUTTON_SHIFT,17),"UNDO TURN",BUTTON_TEXT,WHITE)) 
     79undoTurnButton.addText(Text((BUTTON_SHIFT,17),"UNDO TURN",BUTTON_TEXT,WHITE,BUTTON_SHIFT+BUTTON_W,True,BUTTON_SHIFT)) 
    8080mainButtons.addEntry(undoTurnButton) 
    8181 
     
    9696researchIcon.addImage(Image((345,10),40,40,researchArt,)) 
    9797researchIcon.addRectangle(Rectangle((0,0),MENU_W,MENU_H,BLUE)) 
    98 researchIcon.addText(Text((175,17),"RESEARCH",42,WHITE)) 
     98researchIcon.addText(Text((0,17),"RESEARCH",42,WHITE,MENU_W,True,0)) 
    9999researchMenu.addEntry(researchIcon) 
    100100 
     
    115115researchIcon.addRectangle(Rectangle((20,220),460,100,CYAN)) 
    116116researchIcon.addText(Text((25,230),"TRANSPORT",32,WHITE)) 
    117 researchIcon.addText(Text((25,260),"This is where the text would go.",24,WHITE)) 
     117researchIcon.addText(Text((25,260),"This is where the text would go. It is going to be on multiple lines because Erin is curious.",24,WHITE,300)) 
    118118researchMenu.addEntry(researchIcon) 
    119119 
     
    123123researchIcon.addRectangle(Rectangle((20,340),460,100,CYAN)) 
    124124researchIcon.addText(Text((25,350),"MATERIAL",32,WHITE)) 
    125 researchIcon.addText(Text((25,380),"This is where the text would go.",24,WHITE)) 
     125researchIcon.addText(Text((25,380),"This is where the text would go. This text is centered and line wrapped.",24,WHITE,300,True,25)) 
    126126researchMenu.addEntry(researchIcon) 
    127127windowsDict['researchMenu'] = researchMenu 
     
    134134mainIcon = WindowEntry(Response('windows',[],False,False)) 
    135135mainIcon.addRectangle(Rectangle((0,0),MAIN_MENU_W,MAIN_MENU_H,GRAY)) 
    136 mainIcon.addText(Text((45,15),"TECHTREK",72,FAKEBLACK)) 
     136mainIcon.addText(Text((0,15),"TECHTREK",72,FAKEBLACK,MAIN_MENU_W,True,0)) 
    137137mainMenu.addEntry(mainIcon) 
    138138 
     
    143143    menuButton = WindowEntry(Response(names[i][1],['introScene_1'],True,False)) 
    144144    menuButton.addRectangle(Rectangle((50,70+MAIN_SHIFT*i),200,70,BLUE)) 
    145     menuButton.addText(Text((100,85+MAIN_SHIFT*i),names[i][0],48,WHITE)) 
     145    menuButton.addText(Text((50,85+MAIN_SHIFT*i),names[i][0],48,WHITE,250,True,50)) 
    146146    mainMenu.addEntry(menuButton) 
    147147     
     
    155155buildIcon.addImage(Image((345,10),40,40,buildArt)) 
    156156buildIcon.addRectangle(Rectangle((0,0),MENU_W,MENU_H,BLUE)) 
    157 buildIcon.addText(Text((210,17),"BUILD",42,WHITE)) 
     157buildIcon.addText(Text((0,17),"BUILD",42,WHITE,MENU_W,True,0)) 
    158158buildMenu1.addEntry(buildIcon) 
    159159 
  • src/text.py

    r92 r111  
    1212class Text: 
    1313    """ class that contains information necessary to render text in pygame """ 
    14     def __init__(self, pos, text, size, color, width=SCREEN_W-20): 
     14    def __init__(self, pos, text, size, color, width = SCREEN_W-20, center = False, shift = 0): 
     15        """  
     16            Shift is the amount the text should always be shifted from the edge of the window 
     17            since width is in the relative coordinate and may not start where the text 
     18            starts. 
     19        """ 
    1520        self.text = text 
    1621        self.size = size 
     
    2227        self.maxWidth = width 
    2328        self.origMaxWidth = width 
     29        self.center = center 
     30        self.shift = shift 
    2431         
    2532    def render(self,surface): 
    2633        """ draw text to surface by wrapping line """ 
    2734        wrapped = self.wrapMultiLine() 
    28         for i in range(len(wrapped)): 
    29             surface.blit(self.font.render(wrapped[i], True, self.color), 
    30                          pygame.Rect(self.left, self.top+(self.size)*i,0,0)) 
     35        if self.center: 
     36            for i in range(len(wrapped)): 
     37                text = self.font.render(wrapped[i], True, self.color) 
     38                textRect = text.get_rect(centerx = (self.maxWidth-self.shift)/2) 
     39                surface.blit(text, pygame.Rect(textRect.x+self.shift, self.top+(self.size)*i,0,0)) 
     40        else: 
     41            for i in range(len(wrapped)): 
     42                surface.blit(self.font.render(wrapped[i], True, self.color), 
     43                             pygame.Rect(self.left, self.top+(self.size)*i,0,0)) 
    3144         
    3245    def resize(self,size): 
  • src/turnMenu.py

    r107 r111  
    2626        buildIcon.addImage(Image((345,10),40,40,buildArt)) 
    2727        buildIcon.addRectangle(Rectangle((0,0),MENU_W,MENU_H,BLUE)) 
    28         buildIcon.addText(Text((210,17),typesLUT[researchType].upper(),42,WHITE)) 
     28        buildIcon.addText(Text((0,17),typesLUT[researchType].upper(),42,WHITE,MENU_W,True,0)) 
    2929        buildMenu.addEntry(buildIcon) 
    3030        buildables = self.calculateBuildables(state)