Mercurial > sypikslang
annotate gamelib/main.py @ 51:ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 07 May 2012 21:51:36 +0200 |
parents | a2980cc9a060 |
children | 1d3d20bdc8b9 |
rev | line source |
---|---|
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
1 '''Game main module. |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
2 |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
3 Contains the entry point used by the run_game.py script. |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
4 |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
5 Feel free to put all your game code here, or in other modules in this "gamelib" |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
6 package. |
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
7 ''' |
37 | 8 import pygame |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
9 from pygame.locals import (MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION, QUIT, |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
10 USEREVENT) |
37 | 11 from pygame.time import Clock |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
12 |
39
d82d3e54a4ef
fixed more pep8 issues
Rizmari Versfeld <rizziepit@gmail.com>
parents:
38
diff
changeset
|
13 from gamelib.gui_base import Window |
d82d3e54a4ef
fixed more pep8 issues
Rizmari Versfeld <rizziepit@gmail.com>
parents:
38
diff
changeset
|
14 from gamelib.gui import BigButton |
48
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
15 from gamelib.constants import WIDTH, HEIGHT, SCREEN, FPS |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
16 |
1
c90a6586cd66
PEP8-ify skellington (because)
Neil Muller <drnlmuller@gmail.com>
parents:
0
diff
changeset
|
17 |
37 | 18 pygame.init() |
19 | |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
20 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
21 class UserEvent(object): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
22 # Handy event wrapper |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
23 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
24 TYPE = "unknown" |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
25 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
26 @classmethod |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
27 def post(cls, **kw): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
28 event = pygame.event.Event(USEREVENT, utype=cls.TYPE, **kw) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
29 pygame.event.post(event) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
30 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
31 @classmethod |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
32 def matches(cls, event): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
33 return event.type == USEREVENT and event.utype == cls.TYPE |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
34 |
37 | 35 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
36 class AddWindow(UserEvent): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
37 # Add the given window to the top of the window stack |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
38 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
39 TYPE = "ADD_WINDOW" |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
40 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
41 @classmethod |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
42 def post(cls, window): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
43 super(AddWindow, cls).post(window=window) |
37 | 44 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
45 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
46 class PopWindow(UserEvent): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
47 # Pop a window off the top of the window stack |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
48 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
49 TYPE = "POP_WINDOW" |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
50 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
51 @classmethod |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
52 def post(cls): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
53 super(PopWindow, cls).post() |
38 | 54 |
55 | |
43
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
56 class ExitGameButton(BigButton): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
57 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
58 def __init__(self): |
48
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
59 super(ExitGameButton, self).__init__(((WIDTH - 128), 10), 'Exit') |
43
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
60 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
61 def on_click(self): |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
62 PopWindow.post() |
43
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
63 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
64 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
65 class GameWindow(Window): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
66 """Main window for the game""" |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
67 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
68 def __init__(self, screen): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
69 super(GameWindow, self).__init__(screen) |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
70 exit = ExitGameButton() |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
71 self.add_child(exit) |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
72 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
73 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
74 class StartButton(BigButton): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
75 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
76 def __init__(self, screen): |
48
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
77 super(StartButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2), |
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
78 'Start') |
43
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
79 self.screen = screen |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
80 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
81 def on_click(self): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
82 game_window = GameWindow(self.screen) |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
83 AddWindow.post(game_window) |
43
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
84 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
85 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
86 class QuitButton(BigButton): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
87 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
88 def __init__(self): |
48
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
89 super(QuitButton, self).__init__(((WIDTH - 128) / 2, |
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
90 HEIGHT / 2 + 100), 'Quit') |
43
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
91 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
92 def on_click(self): |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
93 pygame.event.post(pygame.event.Event(pygame.QUIT)) |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
94 |
2bdac178ec6f
Play with the gui stuff a bit
Neil Muller <drnlmuller@gmail.com>
parents:
39
diff
changeset
|
95 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
96 class MainMenu(Window): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
97 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
98 def __init__(self, screen): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
99 super(MainMenu, self).__init__(screen) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
100 self.background_colour = (0, 0, 0) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
101 button1 = StartButton(screen) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
102 self.add_child(button1) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
103 button2 = QuitButton() |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
104 self.add_child(button2) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
105 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
106 |
0
d0de8832774b
Import skellington-1.9 into the repo
Neil Muller <drnlmuller+bitbucket@gmail.com>
parents:
diff
changeset
|
107 def main(): |
48
a2980cc9a060
Factor out some constants
Neil Muller <drnlmuller@gmail.com>
parents:
44
diff
changeset
|
108 screen = pygame.display.set_mode(SCREEN) |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
109 engine = Engine(screen) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
110 window = MainMenu(screen) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
111 engine.run(window) |
37 | 112 |
38 | 113 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
114 class Engine(object): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
115 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
116 def __init__(self, screen): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
117 self._window_stack = [] |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
118 self._running = False |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
119 self._mouse_down = False |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
120 self._screen = screen |
38 | 121 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
122 def run(self, window): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
123 clock = Clock() |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
124 self._window_stack.append(window) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
125 self._running = True |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
126 self._mouse_down = False |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
127 while self._running: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
128 self.process_input() |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
129 self.draw() |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
130 clock.tick(FPS) |
38 | 131 |
51
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
132 def draw(self): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
133 for view in self._window_stack: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
134 view.draw(self._screen) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
135 pygame.display.flip() |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
136 |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
137 def process_input(self): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
138 for event in pygame.event.get(): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
139 if self._mouse_down: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
140 if event.type == MOUSEBUTTONUP: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
141 self._mouse_down = False |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
142 self._window_stack[-1].on_mouse_up(event.pos) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
143 elif event.type == MOUSEMOTION: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
144 self._window_stack[-1].on_mouse_move(event.pos) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
145 elif not self._mouse_down and event.type == MOUSEBUTTONDOWN: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
146 self._mouse_down = True |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
147 self._window_stack[-1].on_mouse_down(event.pos) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
148 elif event.type == QUIT: |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
149 self._running = False |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
150 elif AddWindow.matches(event): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
151 self._window_stack.append(event.window) |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
152 elif PopWindow.matches(event): |
ac637e84f8f8
Consilidate engine stuff and eventify window stack manipulation
Neil Muller <drnlmuller@gmail.com>
parents:
48
diff
changeset
|
153 self._window_stack.pop() |