Improve buffer viewer display:

Buffer views no longer go off screen except when there are way too many buffers (since the min buffer frame size is now 5 pixels).
Fix a case where too many buffers being displayed results in a divide by zero.
This commit is contained in:
aignacio_sf 2008-09-10 02:08:16 +00:00
parent dc3173c1fb
commit 615d92440f

View File

@ -343,8 +343,9 @@ class BufferViewer(DirectObject):
# an 800x600 display. Then, it double checks that the
# readout will fit on the screen, and if not, it shrinks it.
if (float(self.sizex)==0.0) and (float(self.sizey)==0.0):
bordersize = 4.0
if (float(self.sizex)==0.0) and (float(self.sizey)==0.0):
sizey = int(0.4266666667 * base.win.getYSize())
sizex = (sizey * aspectx) / aspecty
v_sizey = (base.win.getYSize() - (rows-1) - (rows*2)) / rows
@ -352,23 +353,27 @@ class BufferViewer(DirectObject):
if (v_sizey < sizey) or (v_sizex < sizex):
sizey = v_sizey
sizex = v_sizex
h_sizex = (base.win.getXSize() - (cols-1) - (cols*2)) / cols
adjustment = 2
h_sizex = float (base.win.getXSize() - adjustment) / float (cols)
h_sizex -= bordersize
if (h_sizex < 1.0):
h_sizex = 1.0
h_sizey = (h_sizex * aspecty) / aspectx
if (h_sizey < sizey) or (h_sizex < sizex):
sizey = h_sizey
sizex = h_sizex
else:
sizex = int(self.sizex * 0.5 * base.win.getXSize())
sizey = int(self.sizey * 0.5 * base.win.getYSize())
if (sizex == 0): sizex = (sizey*aspectx) / aspecty
if (sizey == 0): sizey = (sizex*aspecty) / aspectx
# Convert from pixels to render2d-units.
fsizex = (2.0*sizex) / float(base.win.getXSize())
fsizey = (2.0*sizey) / float(base.win.getYSize())
fsizex = (2.0 * sizex) / float(base.win.getXSize())
fsizey = (2.0 * sizey) / float(base.win.getYSize())
fpixelx = 2.0 / float(base.win.getXSize())
fpixely = 2.0 / float(base.win.getYSize())
@ -399,8 +404,9 @@ class BufferViewer(DirectObject):
index = c + r*cols
if (index < ncards):
index = (index + self.cardindex) % len(cards)
posx = dirx * (1.0 - fsizex*0.5 - 3*fpixelx - (c*(fsizex+6*fpixelx)))
posy = diry * (1.0 - fsizey*0.5 - 3*fpixely - (r*(fsizey+6*fpixely)))
posx = dirx * (1.0 - ((c + 0.5) * (fsizex + fpixelx * bordersize))) - (fpixelx * dirx)
posy = diry * (1.0 - ((r + 0.5) * (fsizey + fpixely * bordersize))) - (fpixely * diry)
placer = NodePath("card-structure")
placer.setPos(posx, 0, posy)
placer.setScale(fsizex*0.5, 1.0, fsizey*0.5)