Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/p5_button.py
diff options
context:
space:
mode:
authorerikb <erikb@574bc980-5f2d-0410-acbc-c8f9f0eb14e0>2007-06-20 22:12:14 (GMT)
committer erikb <erikb@574bc980-5f2d-0410-acbc-c8f9f0eb14e0>2007-06-20 22:12:14 (GMT)
commit0a4db4aa9d53e17b60c42f1ee3b6a238ed741a83 (patch)
tree2ec84f646aa33af20c9f98b98d2ea2765fda4912 /p5_button.py
parentb2dc1cbdffc307e723ac09ca54e8d5811cc8c87f (diff)
ui overhaul continues
git-svn-id: http://mediamods.com/public-svn/camera-activity/Camera.activity@102 574bc980-5f2d-0410-acbc-c8f9f0eb14e0
Diffstat (limited to 'p5_button.py')
-rwxr-xr-xp5_button.py146
1 files changed, 86 insertions, 60 deletions
diff --git a/p5_button.py b/p5_button.py
index fc0cf0a..ee869c2 100755
--- a/p5_button.py
+++ b/p5_button.py
@@ -1,39 +1,15 @@
-import datetime
-import time
from p5 import P5
-from color import Color
-from button import Button
class P5Button(P5):
def __init__(self):
P5.__init__(self)
self.noloop()
-
self._butts = []
-
- self._colPressed = Color( 172, 168, 153, 200 )
- self._colHighlight = Color( 255, 255, 255, 255 )
- self._colDarkShadow = Color( 113, 111, 100, 255 )
- self._colShadow = Color( 172, 168, 153, 255 )
- self._colBackground = Color( 236, 233, 216, 0 )
-
- self._pressDownTime = -1
self._buttonPressed = False
- def getButtonPressTime():
- now = datetime.datetime.now()
- nowTime = time.mktime( now.timetuple() )
- diff = nowTime - self._pressDownTime
- return diff
-
-
- def fireButton(self, actionCommand):
- pass
-
-
def button_press(self, widget, event):
P5.button_press(self, widget, event)
@@ -44,8 +20,6 @@ class P5Button(P5):
contains = self._butts[i].contains(event.x, event.y)
self._butts[i]._pressed = contains
if (contains):
- now = datetime.datetime.now()
- self._pressDownTime = time.mktime( now.timetuple() )
bp = True
self._buttonPressed = bp
@@ -75,46 +49,98 @@ class P5Button(P5):
self.redraw()
- def drawButton(self, ctx, butt):
- pass
+class Polygon:
+
+ def __init__( self, xs, ys ):
+ self.setPoints( xs, ys )
+
+
+ def setPoints( self, xs, ys ):
+ self._xs = xs
+ self._ys = ys
+
+ self._boundingX = self._xs[0]
+ self._boundingY = self._ys[0]
+ self._boundingW = self._xs[0]
+ self._boundingH = self._ys[0]
+
+ for i in range ( 1, len(self._xs) ):
+ if (self._xs[i] > self._boundingW):
+ self._boundingW = self._xs[i]
+ if (self._ys[i] > self._boundingH):
+ self._boundingH = self._ys[i]
+ if (self._xs[i] < self._boundingX):
+ self._boundingX = self._xs[i]
+ if (self._ys[i] < self._boundingY):
+ self._boundingY = self._ys[i]
+
+
+ def contains( self, mx, my ):
+ if (not self.bbox_contains(mx, my)):
+ return False
+
+ #insert simple path tracing check on the polygon here
+
+ return True
+
+
+ def bbox_contains( self, mx, my ):
+ if ( not((mx>=self._boundingX) and (my>=self._boundingY) and (mx<self._boundingW) and (my<self._boundingH)) ):
+ return False
+ else:
+ return True
+
+
+class Button:
+
+ def __init__(self, poly, offX, offY):
+ self._poly = poly
+ self._offX = offX
+ self._offY = offY
+
+ self._enabled = True
+ self._pressed = False
+ self._toggle = False
+
+ self._listeners = []
+
+ self._actionCommand = None
+
+ self._img = None
+
+
+ def addActionListener(self, listen):
+ self._listeners.append(listen)
+
+
+ def removeActionListener(self, listen):
+ self._listeners.remove(listen)
+
+
+ def setActionCommand(self, command):
+ self._actionCommand = command
+
+
+ def getActionCommand(self):
+ return self._actionCommand
- def drawButtonOld(self, ctx, butt):
- ctx.scale (1, 1)
- ctx.translate( butt._offX, butt._offY )
-
- #!enabled?
- #do stuff, return
- if (not butt._enabled):
- #if(butt.isImg()):
- # ctx.set_source_surface(butt._img, 0, 0)
- # ctx.paint()
+ def setImage(self, img):
+ self._img = img
- #self.fillShape( ctx, butt._poly, self._colPressed )
- #ctx.translate( -butt._offX, -butt._offY )
- return
- #set highlightColor
- #draw highlightShape
- ctx.translate( 1, 1 )
- #self.drawShape( ctx, butt._poly, self._colHighlight )
- ctx.translate( -1, -1 )
+ def contains( self, mx, my ):
+ x = mx - self._offX
+ y = my - self._offY
- #draw image
- if (butt.isImg()):
- ctx.set_source_surface(butt._img, 0, 0)
- ctx.paint()
+ contains = self._poly.contains( x, y )
+ return contains
- if (butt._pressed):
- self.fillShape( ctx, butt._poly, self._colPressed )
- #self.drawShape( ctx, butt._poly, self._colDarkShadow )
+ def doPressed( self ):
+ for i in range ( 0, len(self._listeners) ):
+ self._listeners[i].fireButton( self._actionCommand )
- #if not pressed, setColor buttonHighlightColor
- #if not pressed, draw HighlightShape
- if (not butt._pressed):
- ctx.translate( 1, 1 )
- #self.drawShape( ctx, butt._poly, self._colHighlight )
- ctx.translate( -1, -1 )
- ctx.translate( -butt._offX, -butt._offY )
+ def isImg( self ):
+ return self._img != None \ No newline at end of file