def __init__(self, file , pos): "Sets up the image widget" GuiWidget.__init__(self) self.screen_size=Constants.SCREEN.get_size() self.image=pygame.image.load(file) self.image.convert() #for blitting more faster self.rect = self.image.get_rect() self.x = pos[0] self.y = pos[1] self.rect.center = (self.screen_size[0]*self.x,self.screen_size[1]*self.y)
def __init__(self, file, pos): "Sets up the image widget" GuiWidget.__init__(self) self.screen_size = Constants.SCREEN.get_size() self.image = pygame.image.load(file) self.image.convert() #for blitting more faster self.rect = self.image.get_rect() self.x = pos[0] self.y = pos[1] self.rect.center = (self.screen_size[0] * self.x, self.screen_size[1] * self.y)
def __init__(self, title , pos , color): "Sets up the label widget" GuiWidget.__init__(self) self.screen_size=Constants.SCREEN.get_size() self.font = pygame.font.Font(os.path.join("fonts","freesansbold.ttf"), 24) self.title = title self.color = color self.image = self.font.render(self.title, 1, color) self.rect = self.image.get_rect() self.rect = self.image.get_rect() self.x = pos[0] self.y = pos[1] self.rect.center = (self.screen_size[0]*self.x,self.screen_size[1]*self.y)
def __init__(self, title , pos, color): "Sets up the button widget" GuiWidget.__init__(self) self.screen_size=Constants.SCREEN.get_size() self.font = pygame.font.Font(os.path.join("fonts","freesansbold.ttf"), 24) self.title = title self.color = color self.color_normal = color self.color_hover = (255,255,0) self.image = self.font.render(self.title, 1, (255, 255, 255)) self.rect = self.image.get_rect() self.x = pos[0] self.y = pos[1] self.rect.center = (self.screen_size[0]*self.x,self.screen_size[1]*self.y) self.eventhandlers['onmouseclick']=self.onmouseclick self.eventhandlers['onmouseclickup']=self.onmouseclickup
def __init__(self, title, pos, color): "Sets up the label widget" GuiWidget.__init__(self) self.screen_size = Constants.SCREEN.get_size() self.font = pygame.font.Font(os.path.join("fonts", "freesansbold.ttf"), 24) self.title = title self.color = color self.image = self.font.render(self.title, 1, color) self.rect = self.image.get_rect() self.rect = self.image.get_rect() self.x = pos[0] self.y = pos[1] self.rect.center = (self.screen_size[0] * self.x, self.screen_size[1] * self.y)
def __init__(self, pos, fontsize, width, defaultName="DEFAULT"): "Sets up the text input box type widget" GuiWidget.__init__(self) self.set_click_state = 0 self.font = pygame.font.Font(os.path.join("fonts", "freesansbold.ttf"), fontsize) self.linesize = self.font.get_linesize() self.screen_size = Constants.SCREEN.get_size( ) # self.background.get_size() self.x = pos[0] self.y = pos[1] self.rect = pygame.Rect( (0, 0, width * self.screen_size[0], self.linesize + 4)) self.boxImg = pygame.Surface(self.rect.size).convert_alpha() self.boxImg.fill((128, 128, 128)) self.color = (255, 255, 255) pygame.draw.rect(self.boxImg, self.color, self.rect, 2) self.emptyImg = self.boxImg.convert_alpha() self.image = self.boxImg self.text = defaultName self.textPos = (5, 0) self.textColor = (255, 255, 255) self.textColor_clicked = (255, 255, 0) self.textImg = self.font.render(self.text, 1, self.textColor) self.image.blit(self.emptyImg, (0, 0)) self.image.blit(self.textImg, self.textPos) self.rect.center = (self.screen_size[0] * self.x, self.screen_size[1] * self.y) self.flick_time = 500 self.eventhandlers['onkeydown'] = self.onkeydown
def __init__(self, pos , fontsize, width, defaultName="DEFAULT"): "Sets up the text input box type widget" GuiWidget.__init__(self) self.set_click_state=0 self.font = pygame.font.Font(os.path.join("fonts","freesansbold.ttf"), fontsize) self.linesize = self.font.get_linesize() self.screen_size=Constants.SCREEN.get_size() # self.background.get_size() self.x = pos[0] self.y = pos[1] self.rect = pygame.Rect( (0,0,width*self.screen_size[0], self.linesize +4) ) self.boxImg = pygame.Surface( self.rect.size ).convert_alpha() self.boxImg.fill((128,128,128)) self.color = (255,255,255) pygame.draw.rect( self.boxImg, self.color, self.rect, 2 ) self.emptyImg = self.boxImg.convert_alpha() self.image = self.boxImg self.text = defaultName self.textPos = (5, 0) self.textColor = (255,255,255) self.textColor_clicked = (255,255,0) self.textImg = self.font.render( self.text, 1, self.textColor ) self.image.blit( self.emptyImg, (0,0) ) self.image.blit( self.textImg, self.textPos ) self.rect.center = (self.screen_size[0]*self.x,self.screen_size[1]*self.y) self.flick_time=500 self.eventhandlers['onkeydown']=self.onkeydown