/usr/lib/games/solarwolf/gfx.py is in solarwolf 1.5-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | """graphics class, helps everyone to draw"""
import sys, pygame, pygame.image
from pygame.locals import *
import game, stars
#the accessable screen surface and size
surface = None
rect = Rect(0, 0, 0, 0)
#the accessable dirty rectangles
dirtyrects = []
starobj = None
wantscreentoggle = 0
def initialize(size, fullscreen):
global surface, rect, starobj
try:
flags = 0
if fullscreen:
flags |= FULLSCREEN
#depth = pygame.display.mode_ok(size, flags, 16)
surface = pygame.display.set_mode(size, flags)#, depth)
rect = surface.get_rect()
pygame.mouse.set_visible(0)
if surface.get_bytesize() == 1:
loadpalette()
except pygame.error, msg:
raise pygame.error, 'Cannot Initialize Graphics'
starobj = stars.Stars()
def switchfullscreen():
oldfull = surface.get_flags() & FULLSCREEN == FULLSCREEN
newfull = game.display == 1
if newfull == oldfull:
return
global wantscreentoggle
wantscreentoggle = 1
def dirty(rect):
dirtyrects.append(rect)
def dirty2(rect1, rect2):
if not rect2:
dirtyrects.append(rect1)
elif rect.colliderect(rect2):
dirtyrects.append(rect1.union(rect2))
else:
dirtyrects.append(rect1)
dirtyrects.append(rect2)
def updatestars(bgd, gfx):
starobj.erase_tick_draw(bgd, gfx)
def update():
global dirtyrects
pygame.display.update(dirtyrects)
#dirtyrects = []
del dirtyrects[:]
global wantscreentoggle
if wantscreentoggle:
wantscreentoggle = 0
if game.handler:
starobj.eraseall(game.handler.background, sys.modules[__name__])
screencapture = pygame.Surface(surface.get_size())
screencapture.blit(surface, (0,0))
clipcapture = surface.get_clip()
initialize(surface.get_size(), game.display)
# if game.handler:
# game.handler.background(rect)
surface.blit(screencapture, (0,0))
pygame.display.update()
surface.set_clip(clipcapture)
def optimize(img):
#~ if surface.get_alpha():
#~ img.set_alpha()
#~ if surface.get_flags() & HWSURFACE:
#~ img.set_colorkey(0)
#~ else:
#~ img.set_colorkey(0, RLEACCEL)
#~ elif not surface.get_flags() & HWSURFACE:
if not surface.get_flags() & HWSURFACE:
clear = img.get_colorkey()
if clear:
img.set_colorkey(clear, RLEACCEL)
return img.convert()
def load(name):
img = load_raw(name)
#use rle acceleration if no hardware accel
return optimize(img)
def load_raw(name):
file = game.get_resource(name)
img = pygame.image.load(file)
return img
def loadpalette():
file = open(game.get_resource('solarwolf.pal'))
pal = []
for line in file.readlines()[3:]:
vals = [int(x) for x in line.split()]
pal.append(vals)
surface.set_palette(pal)
#thanks to MU
def drawvertdashline(dstsurf, startpos, endpos, color, dashsize, offset):
"""drawvertdashline
dstsurf = surface on which line is drawn
startpos, endpos = (x0, y0), (x0, y1) of line
color = RGB(A) of line; between dashes is nothing
dashsize = pixel length of on, and of off sections
offset = where to start"""
x, y0 = startpos
x, y1 = endpos
if y1 < y0:
y0, y1 = y1, y0
period = 2*dashsize
offset = offset % period
starts = [ max(y,y0)
for y in range(y0-period+offset, y1+period, 2*dashsize)
if y0-dashsize < y < y1 ]
stops = [ min(y-1,y1)
for y in range(y0-dashsize+offset, y1+period, 2*dashsize)
if y0 < y < y1+dashsize ]
for b,e in zip(starts, stops):
#pygame.draw.line(dstsurf, color, (x,b), (x,e))
dstsurf.fill(color, (x,b,1,e-b+1))
def drawhorzdashline(dstsurf, startpos, endpos, color, dashsize, offset):
"""drawhorzdashline
dstsurf = surface on which line is drawn
startpos, endpos = (x0, y0), (x0, y1) of line
color = RGB(A) of line; between dashes is nothing
dashsize = pixel length of on, and of off sections
offset = where to start"""
x0, y = startpos
x1, y = endpos
if x1 < x0:
x0, x1 = x1, x0
period = 2*dashsize
offset = offset % period
starts = [ max(x,x0)
for x in range(x0-period+offset, x1+period, 2*dashsize)
if x0-dashsize < x < x1 ]
stops = [ min(x-1,x1)
for x in range(x0-dashsize+offset, x1+period, 2*dashsize)
if x0 < x < x1+dashsize ]
for b,e in zip(starts, stops):
#pygame.draw.line(dstsurf, color, (x,b), (x,e))
dstsurf.fill(color, (b,y,e-b+1,1))
def animstrip(img, width=0):
if not width:
width = img.get_height()
size = width, img.get_height()
images = []
origalpha = img.get_alpha()
origckey = img.get_colorkey()
img.set_colorkey(None)
img.set_alpha(None)
for x in range(0, img.get_width(), width):
i = pygame.Surface(size)
i.blit(img, (0, 0), ((x, 0), size))
if origalpha:
i.set_colorkey((0,0,0))
elif origckey:
i.set_colorkey(origckey)
images.append(optimize(i))
img.set_alpha(origalpha)
img.set_colorkey(origckey)
return images
|