1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pygame
import jmenu
import sys
import txtlib
from applicationstate import *
from application import *
from ktextsurfacewriter import KTextSurfaceWriter
from pygame.locals import *
import pygame.font
class InfoState(ApplicationState):
def __init__(self, next_state, background = None, next_cookie = None):
ApplicationState.__init__(self, next_state, background, next_cookie)
self._images = []
self._ktexts = []
def clear_all(self):
self._images = []
self._ktexts = []
def add_text(self, text, color, pos, rectsize, fontsize, font = None):
textobj = txtlib.Text(rectsize, font, fontsize, text)
textobj.background_color = (255, 255, 255, 0)
textobj.update()
self.add_image( textobj.area, pos )
def add_htmltext(self, html_text, color, pos, rectsize, fontsize, font = None):
textobj = txtlib.Text(rectsize, font, fontsize)
textobj.background_color = (255, 255, 255, 0)
textobj.html(html_text)
textobj.update()
self.add_image( textobj.area, pos )
def add_text2(self, text, color, pos, rectsize, font = None):
text_rect = pygame.Rect( pos, rectsize )
fillcolor = (231,178,66,0)
textobj = KTextSurfaceWriter(text_rect, font, color, fillcolor)
textobj.text = (text)
textobj.invalidate()
self._ktexts.append(textobj)
def add_image(self, surface, pos):
info = {}
info["surface"] = surface
info["pos"] = pos
self._images.append(info)
def input(self, ms):
events = pygame.event.get()
if events:
for event in events:
if event.type == pygame.QUIT:
self.set_running( False )
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.set_running( False )
else:
self.go_to_next_state()
def render(self, ms):
for info in self._images:
self.screen().blit(info["surface"], info["pos"])
for info in self._ktexts:
info.draw(self.screen())
def entering_state(self, fromStack, cookie):
ApplicationState.entering_state(self, fromStack, cookie)
pygame.time.wait(500)
pygame.event.clear()
|