def __init__(self, text, back1, back2, padA=10, padB=2, fontA=ubuntu_bold_graph_pre, fontB=ubuntu_bold_graph_initial): self.text = text textlon = fontA.render(text, 0, (0, 0, 0)) textlon2 = fontB.render(text, 0, (0, 0, 0)) image1 = pygame.surface.Surface((textlon.get_size()[0] + padA * 2, textlon.get_size()[1] + padB * 2)) image1.fill(back1) image2 = pygame.surface.Surface((textlon.get_size()[0] + padA * 2, textlon.get_size()[1] + padB * 2)) image2.fill(back2) add_border.add_border(image1) add_border.add_border(image2) image1.blit(textlon, (padA, padB)) image2.blit( textlon2, ((image2.get_size()[0] - textlon2.get_size()[0]) / 2, (textlon.get_size()[1] + padB * 2 - textlon2.get_size()[1]) / 2)) self.button = button(image1, image2)
def graphic_update(self, SCREEN): surface = pygame.surface.Surface((self.W, self.H), pygame.SRCALPHA, 32) surface.convert_alpha() background = pygame.surface.Surface((self.W, self.H)) background.fill((50, 50, 255)) background.set_alpha(200) for x in range(len(self.elements)): self.elements[x].graphic_update(surface) add_border.add_border(surface) SCREEN.blit(background, (self.X, self.Y)) SCREEN.blit(surface, (self.X, self.Y))
def graphic_update(self,SCREEN): self.surface.fill((100,100,255)) add_border.add_border(self.surface) surfaceServers = pygame.surface.Surface((450,20+24*len(self.options))) surfaceServers.fill((100,100,255)) for x in range(len(self.options)): self.options[x].graphic_update(surfaceServers) self.rooms_area.set_surface(surfaceServers) self.rooms_area.graphic_update(self.surface) pygame.draw.line(self.surface,(0,0,0),(0,400),(600,400)) surfaceButtons = pygame.surface.Surface((600,30)) surfaceButtons.fill((255,255,100)) add_border.add_border(surfaceButtons) self.room_info.graphic_update(self.surface) self.surface.blit(surfaceButtons,(0,400)) self.buttonConnect.graphic_update(self.surface) self.buttonRefresh.graphic_update(self.surface) add_border.add_border(self.surface) SCREEN.blit(self.surface,(self.X,self.Y))
def logic_update(self,EVENTS): mouse = EVENTS.get_mouse() mx,my = mouse.get_position() pressed = mouse.get_pressed() surface = pygame.surface.Surface((self.W,self.H)) clicked = False if (mx > self.X and mx < self.X+self.W and my > self.Y and my < self.Y+self.H): if (pressed[0]): clicked = True self.clicked = True status_cur.set_pointer() font = ubuntu_bold_graph_initial surface.fill((150,255,150)) else: font = ubuntu_bold_graph_pre surface.fill((100,255,100)) self.clicked = clicked if (self.selected): surface.fill((255,100,100)) add_border.add_border(surface) text_name = font.render(self.name,0,(0,0,0)) text_players = font.render(str(self.room_players)+"/"+str(self.room_max_players),0,(0,0,0)) server_color = pygame.surface.Surface((16,16)) server_color.fill(self.room_color) surface.blit(text_name,(5,(self.H-text_name.get_size()[1])/2)) surface.blit(text_players,(250,(self.H-text_name.get_size()[1])/2)) surface.blit(server_color,(self.W-18,2)) self.surface = surface
def logic_update(self, EVENTS): mouse = EVENTS.get_mouse() #creating the surface surface = pygame.surface.Surface((self.W, self.H)) surface.fill(self.background) selection = pygame.surface.Surface((self.W, self.H * self.scale)) selection.fill(self.bar_background) surface.blit(selection, (0, self.position * self.H)) pressed = mouse.get_pressed()[0] if (self.foc(EVENTS)): if (pressed): self.moving = True if (not (pressed)): self.moving = False if (self.moving): self.update_bar_position(EVENTS) surface = add_border.add_border(surface, (0, 0, 0)) self.surface = surface self.pressed_aux = pressed
def graphic_update(self, Pantalla): self.Render_boton = self.Font.render("Aceptar", 1, (0, 0, 0)) self.Tboton = [ self.Render_boton.get_size()[0] + 40, self.Render_boton.get_size()[1] + 10 ] self.Boton = pygame.Surface((self.Tboton[0] + 4, self.Tboton[1] + 4)) self.Surface_boton = pygame.Surface(self.Tboton) self.Surface_boton.fill(self.Color_boton) self.Boton.blit(self.Surface_boton, (2, 2)) self.Boton.blit(self.Render_boton, (self.Boton.get_size()[0] / 2 - self.Render_boton.get_size()[0] / 2, self.Boton.get_size()[1] / 2 - self.Render_boton.get_size()[1] / 2)) self.Talert = [300, 10] lineas = [] palabras = [] palabra = "" for q in self.Text: if q == " ": palabras.append(palabra) palabra = "" else: palabra += q if palabra != "": palabras.append(palabra) end = False while not end: for q in range(len(palabras)): test = "" for w in range(q): test += palabras[w] + " " test2 = "" for w in range(q + 1): test2 += palabras[w] + " " n1 = self.Font.render(test, 1, (0, 0, 0)) n2 = self.Font.render(test2, 1, (0, 0, 0)) if n1.get_size()[0] < self.Talert[0] and n2.get_size( )[0] >= self.Talert[0]: lineas.append(test) for w in range(q): del palabras[0] break if q == len(palabras) - 1: if len(palabras) > 0: test = "" for w in palabras: test += w + " " lineas.append(test) end = True for q in range(len(lineas)): self.Talert[1] += self.Font.render(lineas[q], 1, (0, 0, 0)).get_size()[1] + 10 if lineas[q][len(lineas[q]) - 1] == " ": lineas[q] = lineas[q][:len(lineas[q]) - 1] self.Talert[1] += self.Tboton[1] + 10 self.Position = [ Pantalla.get_size()[0] / 2 - self.Talert[0] / 2, Pantalla.get_size()[1] / 2 - self.Talert[1] / 2 ] self.Alert = pygame.Surface(self.Talert) self.Alert.fill((255, 255, 255)) self.Alert = add_border.add_border(self.Alert, (0, 0, 0), 2, 2, 2, 2) pos_y = 10 for q in range(len(lineas)): rendered = self.Font.render(lineas[q], 1, (0, 0, 0)) self.Alert.blit( rendered, (self.Talert[0] / 2 - rendered.get_size()[0] / 2, pos_y)) pos_y += rendered.get_size()[1] + 10 pos_boton = (self.Talert[0] / 2 - self.Tboton[0] / 2, pos_y) self.Position_boton = (self.Position[0] + pos_boton[0], self.Position[1] + pos_boton[1]) self.Alert.blit(self.Boton, pos_boton) Pantalla.blit(self.Alert, self.Position)
def logic_update(self, events): if (self.initial): font = self.initial_font color = self.initial_color else: font = self.font color = self.color #getting all events mouse = events.get_mouse() keys = events.get_keyboard() mx, my = mouse.get_position() pressed = mouse.get_pressed()[0] self.getLettersLens() #updating key events if (self.pressed == True): self.update_writting(keys) #getting particular letters surfaces lens = self.getLettersLens() #mouse events if (mx > self.X and mx < self.X + self.W and my > self.Y and my < self.Y + self.H): if (pressed): #we calculate the position of the tile when we press netaX = mx - self.margin - self.X netaV = 0 anetaV = 0 for x in range(len(lens)): netaV += lens[x] #until we have passed the letter distance if (netaV > netaX): #calculating if we go forward or backforward if (netaX - anetaV) < lens[x] / 2: self.letter = x break else: self.letter = x + 1 break #last value anetaV = netaV if (x == len(lens) - 1): self.letter = x + 1 #selection area if (self.pressed_aux == False): self.start_select = self.letter - 1 self.end_select = self.letter - 1 else: self.end_select = self.letter self.pressed_aux = True self.pressed = True if (self.initial): self.text = "" self.letters = [] self.initial = False self.letter = 0 else: self.pressed_aux = False else: if (self.pressed_aux2 == False and pressed): self.pressed = False self.pressed_aux = False self.pressed_aux2 = pressed alpha = self.alpha if (self.pressed == False): alpha = self.alpha2 #getting neta position neta_position = 0 for x in range(self.letter): neta_position += lens[x] text = font.render(self.text, 0, self.color) w, h = text.get_size() distance = (self.H - h) / 2 #the final surface surface_final = pygame.surface.Surface((self.W, self.H)) #creating surface and border background = pygame.surface.Surface((self.W, self.H)) background.set_alpha(alpha) background.fill(self.background) border_background = add_border.add_border(background, self.border_color) #bliting the final surface surface_final.blit(border_background, (0, 0)) #bliting text add = 0 for x in range(len(self.letters)): surface_letter = font.render(self.letters[x], 0, color) #handling the selected colors toFill = pygame.surface.Surface(surface_letter.get_size()) toFill.fill(self.selection_color) if (x > self.start_select and x < self.end_select): toFill.set_alpha(170) elif (x - 1 < self.start_select and x + 1 > self.end_select): toFill.set_alpha(170) else: toFill.set_alpha(0) surface_final.blit(toFill, (self.margin + add, distance)) surface_final.blit(surface_letter, (self.margin + add, distance)) add += surface_letter.get_size()[0] #blitting tile if (self.loops % self.intensity > self.intensity / 8.0 * 3.0 and self.pressed): tile = pygame.surface.Surface((1, h)) surface_final.blit(tile, (neta_position + self.margin, distance)) #updating surface self.surface = surface_final #updating variable self.loops += 1