[shpy-commit] r2859 - shpy/trunk/dist/shpy
mwh@codespeak.net
mwh@codespeak.net
Tue, 20 Jan 2004 16:44:02 +0100 (MET)
Author: mwh
Date: Tue Jan 20 16:44:02 2004
New Revision: 2859
Modified:
shpy/trunk/dist/shpy/ui_pygame.py
Log:
Only draw lines that need drawing.
Scrolling is still very inefficient...
Modified: shpy/trunk/dist/shpy/ui_pygame.py
==============================================================================
--- shpy/trunk/dist/shpy/ui_pygame.py (original)
+++ shpy/trunk/dist/shpy/ui_pygame.py Tue Jan 20 16:44:02 2004
@@ -40,6 +40,7 @@
pygame.key.set_repeat(500,30)
pygame.display.set_mode(RESOLUTION, RESIZABLE)
self.font = pygame.font.Font(FONT, HEIGHT)
+ self.fontheight = self.font.size('X')[1]
self.root = self.servergateway.registerclient()
username = info.getusername()
try:
@@ -59,16 +60,27 @@
pygame.display.flip()
def drawcell(self, screen, cell):
- ypos = self.vscroll
- yposlist = []
- for line in cell.lines:
- yposlist.append(ypos)
+ start = -self.vscroll//self.fontheight
+ stop = (-self.vscroll + screen.get_size()[1])//self.fontheight + 1
+ ypos = self.vscroll + start*self.fontheight
+ for line in cell.lines[start:stop]:
lineimage = self.font.render(line or ' ', 1, (0,0,0))
screen.blit(lineimage, (0, ypos))
- ypos += lineimage.get_size()[1]
- self.drawcursors(screen, yposlist)
+ ypos += self.fontheight
+ self.drawcursors(screen, cell)
- def drawcursors(self, screen, yposlist):
+ def char_pos(self, cell, x, y):
+ line = cell.lines[y]
+ return (self.font.size(line[:x])[0],
+ y*self.fontheight + self.vscroll)
+
+ def char_rect(self, cell, x, y):
+ c = cell.lines[y][x:x+1]
+ if not c:
+ c = ' '
+ return Rect(self.char_pos(x, y), self.font.size(c))
+
+ def drawcursors(self, screen, cell):
othercursors = self.root.users.__dict__.values()
try:
othercursors.remove(self.cursor)
@@ -78,14 +90,14 @@
for cursor in othercursors:
x = cursor.x
y = cursor.y
- if y >= len(yposlist):
- y = len(yposlist)-1
- line = self.cell.lines[y]
- xpos = self.font.size(line[:x])[0]
- ypos = yposlist[y]
- char = line[x:x+1] or ' '
+ if y >= len(cell.lines):
+ y = len(cell.lines)-1
+ char = cell.lines[y][x:x+1]
+ if not char:
+ char = ' '
charimage = self.font.render(char, 1, (255,255,255), cursor.color)
- screen.blit(charimage, (xpos, ypos))
+ screen.blit(charimage, self.char_pos(cell, x, y))
+ ypos = self.vscroll + y * self.fontheight
if ypos < 0:
screen.fill((255, 255, 255))
self.vscroll -= ypos