1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | # |
---|
4 | # Puzzlebox - Brainstorms - Client Interface - Component |
---|
5 | # |
---|
6 | # Copyright Puzzlebox Productions, LLC (2010) |
---|
7 | # |
---|
8 | # This code is released under the GNU Pulic License (GPL) version 2 |
---|
9 | # For more information please refer to http://www.gnu.org/copyleft/gpl.html |
---|
10 | # |
---|
11 | # Last Update: 2010.02.01 |
---|
12 | # |
---|
13 | ##################################################################### |
---|
14 | |
---|
15 | ##################################################################### |
---|
16 | # Classes |
---|
17 | ##################################################################### |
---|
18 | |
---|
19 | class puzzlebox_brainstorms_client_interface_component: |
---|
20 | |
---|
21 | def __init__(self, DEBUG = 0): |
---|
22 | |
---|
23 | self.DEBUG = DEBUG |
---|
24 | |
---|
25 | |
---|
26 | ##################################################################### |
---|
27 | |
---|
28 | def load_image(self, image_file): |
---|
29 | |
---|
30 | try: |
---|
31 | #image = self.pygame.image.load(image_file) |
---|
32 | image = self.pygame.image.load(image_file).convert() |
---|
33 | #image = self.pygame.image.load(image_file).convert_alpha() |
---|
34 | except: |
---|
35 | if (self.DEBUG): |
---|
36 | print "Error loading image file: \n%s\n" % (image_file) |
---|
37 | sys.exit() |
---|
38 | |
---|
39 | return(image) |
---|
40 | |
---|
41 | |
---|
42 | ##################################################################### |
---|
43 | |
---|
44 | def draw_image(self, image_surface, \ |
---|
45 | display_position = None): |
---|
46 | |
---|
47 | if (display_position == None): |
---|
48 | display_position = image_surface.get_rect() |
---|
49 | |
---|
50 | self.screen.blit(image_surface, display_position) |
---|
51 | |
---|
52 | |
---|
53 | ##################################################################### |
---|
54 | |
---|
55 | def update_display(self): |
---|
56 | |
---|
57 | if (self.pygame.FLIP): |
---|
58 | self.pygame.display.flip() |
---|
59 | else: |
---|
60 | self.pygame.display.update() |
---|
61 | |
---|
62 | self.update_screen = 0 |
---|
63 | |
---|
64 | |
---|
65 | ##################################################################### |
---|
66 | |
---|
67 | def display_image(self, image_surface, \ |
---|
68 | display_position = None): |
---|
69 | |
---|
70 | self.draw_image(image_surface, display_position) |
---|
71 | self.update_screen() |
---|
72 | |
---|
73 | |
---|
74 | ##################################################################### |
---|
75 | |
---|
76 | def create_text(self, text, font=None, font_size=None, fg_color=(255,255,255)): |
---|
77 | |
---|
78 | if (font_size == None): |
---|
79 | font_size = self.display_window_y_dimension |
---|
80 | |
---|
81 | if ((os.name == 'nt') or (os.name == 'dos')): |
---|
82 | font_path = os.path.join(os.getcwd(), 'fonts') |
---|
83 | font_path = os.path.join(font_path, 'tahomabd.ttf') |
---|
84 | font_size = 36 |
---|
85 | font = self.pygame.font.Font(font_path, font_size) |
---|
86 | |
---|
87 | else: |
---|
88 | font = self.pygame.font.Font(font, font_size) |
---|
89 | |
---|
90 | # insert spaces |
---|
91 | text = " %s " % text |
---|
92 | |
---|
93 | #image = font.render(text, 0, fg_color) # antialias off |
---|
94 | image = font.render(text, 1, fg_color) # antialias on |
---|
95 | |
---|
96 | return(image) |
---|
97 | |
---|
98 | |
---|
99 | ##################################################################### |
---|
100 | # Functions |
---|
101 | ##################################################################### |
---|
102 | |
---|
103 | ##################################################################### |
---|
104 | # Main |
---|
105 | ##################################################################### |
---|
106 | |
---|
107 | if __name__ == '__main__': |
---|
108 | |
---|
109 | pass |
---|
110 | |
---|