aboutsummaryrefslogtreecommitdiff
path: root/pixelcore/Screen.py
diff options
context:
space:
mode:
Diffstat (limited to 'pixelcore/Screen.py')
-rw-r--r--pixelcore/Screen.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/pixelcore/Screen.py b/pixelcore/Screen.py
index 6b5c737..71b9b0b 100644
--- a/pixelcore/Screen.py
+++ b/pixelcore/Screen.py
@@ -7,11 +7,24 @@ class Screen:
def __init__(self):
self.responseQueue = []
self.pixelStrips = []
+ self.xSortedPixels = []
+ self.xPixelLocs = []
sizeValid = False
def addStrip(self, lS):
self.pixelStrips.append(lS)
self.sizeValid = False #keep track of whether or not our screen size has
#been invalidated by adding more pixels
+ self.computeXSortedPixels()
+ #Returns (pixelIndex, pixel). Does a binary search.
+ def pixelsInRange(self, minX, maxX):
+ minIndex = Util.find_ge(self.xPixelLocs, minX)
+ maxIndex = Util.find_le(self.xPixelLocs, maxX)+1
+ return self.xSortedPixels[minIndex:maxIndex]
+ def computeXSortedPixels(self):
+ for pixel in self:
+ self.xSortedPixels.append((pixel.location[0], pixel))
+ self.xSortedPixels.sort()
+ self.xPixelLocs = [p[0] for p in self.xSortedPixels]
def render(self, surface):
[lS.render(surface) for lS in self.pixelStrips]
def setMapper(self, mapper):
@@ -29,6 +42,7 @@ class Screen:
self.responseQueue = []
for response in tempQueue:
self.processResponse(response)
+ [p.invalidateState() for p in self]
#public
def respond(self, responseInfo):
self.responseQueue.append(responseInfo)
@@ -53,7 +67,8 @@ class Screen:
#each to prevent interference
#[strip.respond(dict(responseInfo)) for strip in self.pixelStrips]
if type(responseInfo) != type(dict()):
- pdb.set_trace()
+ pass
+ #pdb.set_trace()
pixelWeightList = self.mapper.mapEvent(responseInfo['Location'], self)
Util.addPixelEventIfMissing(responseInfo)
for (pixel, weight) in pixelWeightList: