class AbilityImage(View): def handle_event(self, event): if event.kind == 'mouse_up': if self.position[0] <= event.position[0] <= self.position[0] + 40 and \ self.position[1] <= event.position[1] <= self.position[1] + 40: self.container.imageClicked(event.position) elif event.kind == 'mouse_move': self.container.mouseOverImage() def setupComponents(self): path = os.path.join("Data", "Pics", "Abilities", "Frame.png") self.border = Image(file=path) self.image = None def clearImage(self): self.image = None def setImage(self, imagePath): if imagePath: path = os.path.join("Data", "Pics", "Abilities", imagePath + ".png") self.image = Image(file=path) else: self.image = None def draw(self, c, r): main_image_pos = self.position src_rect = (0, 0, 40, 40) dst_rect = (main_image_pos[0], main_image_pos[1], main_image_pos[0] + 40, main_image_pos[1] + 40) if self.image: self.image.draw(c, src_rect, dst_rect) if self.border: self.border.draw(c, src_rect, dst_rect)
class AbilityImage(View): def handle_event(self, event): if event.kind == 'mouse_up': if self.position[0] <= event.position[0] <= self.position[0] + 40 and \ self.position[1] <= event.position[1] <= self.position[1] + 40: self.container.imageClicked(event.position) elif event.kind == 'mouse_move': self.container.mouseOverImage() def setupComponents(self): path = os.path.join("Data", "Pics", "Abilities", "Frame.png") self.border = Image(file = path) self.image = None def clearImage(self): self.image = None def setImage(self, imagePath): if imagePath: path = os.path.join("Data", "Pics", "Abilities", imagePath + ".png") self.image = Image(file = path) else: self.image = None def draw(self, c, r): main_image_pos = self.position src_rect = (0, 0, 40, 40) dst_rect = (main_image_pos[0], main_image_pos[1], main_image_pos[0] + 40, main_image_pos[1] + 40) if self.image: self.image.draw(c, src_rect, dst_rect) if self.border: self.border.draw(c, src_rect, dst_rect)
def draw(self, c, r): here = sys.path[0] image_path = os.path.join(here, "test.png") image = Image(file=image_path) c.backcolor = yellow c.erase_rect(r) main_image_pos = (30, btn1.bottom + 30) src_rect = (0, 0, 571, 416) #say("Image bounds =", src_rect) dst_rect = offset_rect(src_rect, main_image_pos) #say("Drawing", src_rect, "in", dst_rect) image.draw(c, src_rect, dst_rect)
class CharacterImage(View): def setupComponents(self): self.image = None def clearImage(self): self.image = None def setImage(self, imagePath): path = os.path.join("Data", "Pics", "Actors", imagePath + ".png") self.image = Image(file=path) def draw(self, c, r): if self.image: main_image_pos = self.position src_rect = (39, 0, 39 * 2, 39) dst_rect = (main_image_pos[0], main_image_pos[1], main_image_pos[0] + src_rect[2] - src_rect[0], main_image_pos[1] + src_rect[3] - src_rect[1]) self.image.draw(c, src_rect, dst_rect)
class CharacterImage(View): def setupComponents(self): self.image = None def clearImage(self): self.image = None def setImage(self, imagePath): path = os.path.join("Data", "Pics", "Actors", imagePath + ".png") self.image = Image(file = path) def draw(self, c, r): if self.image: main_image_pos = self.position src_rect = (39, 0, 39*2, 39) dst_rect = (main_image_pos[0], main_image_pos[1], main_image_pos[0] + src_rect[2] - src_rect[0], main_image_pos[1] + src_rect[3] - src_rect[1]) self.image.draw(c, src_rect, dst_rect)
def draw(self, c, r): c.backcolor = view_backcolor c.erase_rect(r) # Background image image_pos = ((player_name_label.left - player_background.width)/2, 5) src_rect = player_background.bounds dst_rect = Geometry.offset_rect(src_rect, image_pos) player_background.draw(c, src_rect, dst_rect) # Lines between summary stats c.forecolor = stat_line_color c.fill_rect((dst_rect[0]+22, dst_rect[1]+stat_line_y, dst_rect[2]-22, dst_rect[1]+stat_line_y+1)) c.fill_rect((dst_rect[0]+22, dst_rect[1]+stat_line_y+stat_line_spacing, dst_rect[2]-22, dst_rect[1]+stat_line_y+stat_line_spacing+1)) # Headshot image_pos = (image_pos[0]+player_headshot_pos[0], player_headshot_pos[1]) src_rect = player_headshot.bounds headshot_dst_rect = Geometry.offset_rect(src_rect, image_pos) player_headshot.draw(c, src_rect, headshot_dst_rect) # Club if 'normal' in player['club']['imageUrls']: image_url = player['club']['imageUrls']['normal']['large'] # FIFA 15 compatibility elif 'dark' in player['club']['imageUrls']: image_url = player['club']['imageUrls']['dark']['large'] ratio = 0.75 image_file_name = 'club_' + str(player['club']['id']) + '_' + str(ratio) image_file_name = save_small_image(image_url, image_file_name, ratio) club_image = Image(file=image_file_name) club_image_pos = club_pos club_rect = club_image.bounds club_dst_rect = Geometry.offset_rect(club_rect, club_image_pos) club_image.draw(c, club_rect, club_dst_rect) # Nation if 'imageUrls' in player['nation']: image_url = player['nation']['imageUrls']['large'] # FIFA 15 compatibility elif 'imageUrl' in player['nation']: image_url = player['nation']['imgUrl'] ratio = 0.75 image_file_name = 'nation_' + str(player['nation']['id']) + '_' + str(ratio) image_file_name = save_small_image(image_url, image_file_name, ratio) nation_image = Image(file=image_file_name) nation_image_pos = (club_image_pos[0], club_image_pos[1]+club_image.size[1]+nation_spacing) nation_rect = nation_image.bounds nation_dst_rect = Geometry.offset_rect(nation_rect, nation_image_pos) nation_image.draw(c, nation_rect, nation_dst_rect) # Coins symbol image_file_name = 'Images/coins.png' coins_image = Image(file=image_file_name) coins_image_pos = coins_pos coins_rect = coins_image.bounds coins_dst_rect = Geometry.offset_rect(coins_rect, coins_image_pos) coins_image.draw(c, coins_rect, coins_dst_rect)
from GUI import View, Button, Image
from GUI import View, Button, Image