def __init__(self, pos, width, fontsize, nblines, fontname=None, bg=(250, 250, 250), fgcolor=None, hlcolor=(180, 180, 200), curscolor=(0xff0000), maxlen=0, menu=[], label=''): Form.__init__(self, pos, width, fontsize, height=None, font=fontname, bg=bg, fgcolor=fgcolor, hlcolor=hlcolor, curscolor=curscolor, maxlen=maxlen, maxlines=1) self.OUTPUT = label self._index = len(label) self.scr = pygame.display.get_surface() self.box = Lister(menu, self.bottomleft, (self.width, self._h * nblines), fontsize, font=fontname) self.openbox = 0 self.just_now = 0
class MenuForm(Form): def __init__(self,pos,width,fontsize,nblines,fontname=None,bg=(250,250,250),fgcolor=None,hlcolor=(180,180,200),curscolor=(0xff0000),maxlen=0,menu=[],label=''): Form.__init__(self,pos,width,fontsize,height=None,font=fontname,bg=bg,fgcolor=fgcolor,hlcolor=hlcolor,curscolor=curscolor,maxlen=maxlen,maxlines=1) self.OUTPUT = label self._index = len(label) self.scr = pygame.display.get_surface() self.box = Lister(menu,self.bottomleft,(self.width,self._h*nblines),fontsize,font=fontname) self.openbox = 0 self.just_now = 0 def update(self,ev): self.just_now = 0 ret = super(MenuForm,self).update(ev) if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1: if self.openbox and not self.box.collidepoint(ev.pos): self.openbox = 0 self.just_now = 1 return True elif self.collidepoint(ev.pos): self.openbox = 1 self.just_now = 1 return True if self.openbox: if self.box.update(ev): self.OUTPUT = self.box.LINE[1:] self.INDEX = 0,len(self.OUTPUT) ret = True if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1 and self.box.collidepoint(ev.pos): self.openbox = 0 self.just_now = 1 ret = True return ret def close(self): self.openbox = 0 self.just_now = 1 def screen(self): super(MenuForm,self).screen() if self.openbox: if self.just_now: self._bg = self.scr.subsurface(self.box).copy() self.box.screen() pygame.draw.rect(self.scr,(0,0,0),self.box,1) elif self.just_now: self.scr.blit(self._bg,self.box) def show(self): self.screen() if self.openbox or self.just_now: pygame.display.update((self,self.box)) else: pygame.display.update(self)
def __init__(self,pos,width,fontsize,nblines,fontname=None,bg=(250,250,250),fgcolor=None,hlcolor=(180,180,200),curscolor=(0xff0000),maxlen=0,menu=[],label=''): Form.__init__(self,pos,width,fontsize,height=None,font=fontname,bg=bg,fgcolor=fgcolor,hlcolor=hlcolor,curscolor=curscolor,maxlen=maxlen,maxlines=1) self.OUTPUT = label self._index = len(label) self.scr = pygame.display.get_surface() self.box = Lister(menu,self.bottomleft,(self.width,self._h*nblines),fontsize,font=fontname) self.openbox = 0 self.just_now = 0
class MenuForm(Form): def __init__(self, pos, width, fontsize, nblines, fontname=None, bg=(250, 250, 250), fgcolor=None, hlcolor=(180, 180, 200), curscolor=(0xff0000), maxlen=0, menu=[], label=''): Form.__init__(self, pos, width, fontsize, height=None, font=fontname, bg=bg, fgcolor=fgcolor, hlcolor=hlcolor, curscolor=curscolor, maxlen=maxlen, maxlines=1) self.OUTPUT = label self._index = len(label) self.scr = pygame.display.get_surface() self.box = Lister(menu, self.bottomleft, (self.width, self._h * nblines), fontsize, font=fontname) self.openbox = 0 self.just_now = 0 def update(self, ev): self.just_now = 0 ret = super(MenuForm, self).update(ev) if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1: if self.openbox and not self.box.collidepoint(ev.pos): self.openbox = 0 self.just_now = 1 return True elif self.collidepoint(ev.pos): self.openbox = 1 self.just_now = 1 return True if self.openbox: if self.box.update(ev): self.OUTPUT = self.box.LINE[1:] self.INDEX = 0, len(self.OUTPUT) ret = True if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1 and self.box.collidepoint( ev.pos): self.openbox = 0 self.just_now = 1 ret = True return ret def close(self): self.openbox = 0 self.just_now = 1 def screen(self): super(MenuForm, self).screen() if self.openbox: if self.just_now: self._bg = self.scr.subsurface(self.box).copy() self.box.screen() pygame.draw.rect(self.scr, (0, 0, 0), self.box, 1) elif self.just_now: self.scr.blit(self._bg, self.box) def show(self): self.screen() if self.openbox or self.just_now: pygame.display.update((self, self.box)) else: pygame.display.update(self)