Permalink
Browse files

add GWTCanvas demo

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1628 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
1 parent a730bc1 commit e74e4a65fd1a698b6e1983ea19fe15745a0a4367 lkcl committed Sep 1, 2009
@@ -78,7 +78,7 @@ def onModuleLoad(self):
if self.currentDemo.getControls() is not None:
self.layout.add(self.currentDemo.getControls())
- RootPanel.get().add(self.layout)
+ RootPanel().add(self.layout)
self.currentDemo.drawDemo()
def onChange(self, listBox):
@@ -19,6 +19,7 @@
from pyjamas.ui.Composite import Composite
from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.Canvas import Color
from SimpleCanvasDemo import SimpleCanvasDemo
@@ -27,7 +28,7 @@
# Even if they don't have any :).
class StaticDemoControls(Composite):
def __init__(self):
- self.initWidget(VerticalPanel())
+ Composite.__init__(self, VerticalPanel())
"""*
* Demo that showcases most of the GWTCanvas drawing Api,
@@ -31,7 +31,7 @@ def addColorStop(self, offset, color):
self.addNativeColorStop(offset,color.toString())
def getObject(self):
- return nativeGradient
+ return self.nativeGradient
def addNativeColorStop(self, offset, color):
self.nativeGradient.addColorStop(offset,color);
@@ -19,209 +19,202 @@
from pyjamas import DOM
+from pyjamas.Canvas.Color import Color
"""*
* Deferred binding implementation of GWTCanvas.
"""
class GWTCanvasImplDefault:
-
+
def __init__(self):
self.canvasContext = None
-
+
def arc(self, x, y, radius, startAngle, endAngle, antiClockwise):
self.canvasContext.arc(x,y,radius,startAngle,endAngle,antiClockwise)
-
-
+
+
def beginPath(self):
self.canvasContext.beginPath()
-
-
+
+
def clear(self, width, height):
clearRect(0,0,width,height)
-
-
+
+
def closePath(self):
self.canvasContext.closePath()
-
-
+
+
def createElement(self):
e = DOM.createElement("CANVAS")
self.setCanvasContext(e.getContext('2d'))
return e
-
-
+
+
def cubicCurveTo(self, cp1x, cp1y, cp2x, cp2y, x, y):
self.canvasContext.bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y)
-
-
+
+
def drawImage(self, img, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight):
-
+
self.canvasContext.drawImage(img,sourceX,sourceY,sourceWidth,sourceHeight,destX,destY,destWidth,destHeight)
-
-
-
+
+
+
def fill(self):
self.canvasContext.fill()
-
-
+
+
def fillRect(self, startX, startY, width, height):
self.canvasContext.fillRect(startX,startY,width,height)
-
-
+
+
def getGlobalAlpha(self):
return self.canvasContext.globalAlpha
-
-
+
+
def getGlobalCompositeOperation(self):
return self.canvasContext.globalCompositeOperation
-
-
+
+
def getHeight(self, elem):
return DOM.getElementPropertyInt(elem, "height")
-
-
+
+
def getLineCap(self):
return self.canvasContext.lineCap
-
-
+
+
def getLineJoin(self):
return self.canvasContext.lineJoin
-
-
+
+
def getLineWidth(self):
return self.canvasContext.lineWidth
-
-
+
+
def getMiterLimit(self):
return self.canvasContext.miterLimit
-
-
+
+
def getWidth(self, elem):
return DOM.getElementPropertyInt(elem, "width")
-
-
+
+
def lineTo(self, x, y):
self.canvasContext.lineTo(x,y)
-
-
+
+
def moveTo(self, x, y):
self.canvasContext.moveTo(x,y)
-
-
+
+
def quadraticCurveTo(self, cpx, cpy, x, y):
self.canvasContext.quadraticCurveTo(cpx,cpy,x,y)
-
-
+
+
def rect(self, x, y, width, height):
self.canvasContext.rect(x,y,width,height)
-
-
+
+
def restoreContext(self):
self.canvasContext.restore()
-
-
+
+
def rotate(self, angle):
self.canvasContext.rotate(angle)
-
-
+
+
def saveContext(self):
self.canvasContext.save()
-
-
+
+
def scale(self, x, y):
self.canvasContext.scale(x,y)
-
-
+
+
def setBackgroundColor(self, element, color):
DOM.setStyleAttribute(element, "backgroundColor", color)
-
-
+
+
def setCoordHeight(self, elem, height):
DOM.setElemAttribute(elem, "height", str(height))
-
-
+
+
def setCoordWidth(self, elem, width):
DOM.setElemAttribute(elem,"width", str(width))
-
-
+
+
+ def setStrokeStyle(self, gradient):
+ if isinstance(gradient, Color): # is it a colorString?
+ gradient = gradient.toString()
+ elif not isinstance(gradient, str): # is it a colorString?
+ gradient = gradient.getObject() # it's a gradient object
+ self.canvasContext.strokeStyle = gradient
+
+
def setFillStyle(self, gradient):
- setFillStyle( gradient)
-
-
- def setFillStyle(self, colorStr):
- self.canvasContext.fillStyle = colorStr
-
-
+ if isinstance(gradient, Color): # is it a colorString?
+ gradient = gradient.toString()
+ elif not isinstance(gradient, str): # is it a colorString?
+ gradient = gradient.getObject() # it's a gradient object
+ self.canvasContext.fillStyle = gradient
+
def setGlobalAlpha(self, alpha):
self.canvasContext.globalAlpha = alpha
-
-
+
+
def setGlobalCompositeOperation(self, globalCompositeOperation):
self.canvasContext.globalCompositeOperation = globalCompositeOperation
-
-
+
+
def setLineCap(self, lineCap):
self.canvasContext.lineCap = lineCap
-
-
+
+
def setLineJoin(self, lineJoin):
self.canvasContext.lineJoin = lineJoin
-
-
+
+
def setLineWidth(self, width):
self.canvasContext.lineWidth = width
-
-
+
+
def setMiterLimit(self, miterLimit):
self.canvasContext.miterLimit = miterLimit
-
-
+
+
def setPixelHeight(self, elem, height):
DOM.setStyleAttribute(elem, "height", "%dpx" % height)
-
-
+
+
def setPixelWidth(self, elem, width):
DOM.setStyleAttribute(elem, "width", "%dpx" % width)
-
-
- def setStrokeStyle(self, gradient):
- setStrokeStyle(gradient)
-
-
- def setStrokeStyle(self, colorStr):
- self.canvasContext.strokeStyle = colorStr
-
-
+
+
def stroke(self):
self.canvasContext.stroke()
-
-
+
+
def strokeRect(self, startX, startY, width, height):
self.canvasContext.strokeRect(startX,startY,width,height)
-
+
def transform(self, m11, m12, m21, m22, dx, dy):
self.canvasContext.transform(m11,m12,m21,m22,dx,dy)
-
-
+
+
def translate(self, x, y):
self.canvasContext.translate(x,y)
-
-
+
+
def clearRect(self, startX, startY, width, height):
self.canvasContext.clearRect(startX,startY,width,height)
-
-
+
+
def setCanvasContext(self, ctx):
self.canvasContext = ctx
-
-
- def setFillStyle(self, gradient):
- self.canvasContext.fillStyle = getObject()
-
-
- def setStrokeStyle(self, gradient):
- self.canvasContext.strokeStyle = gradient.getObject()
-
+
+

0 comments on commit e74e4a6

Please sign in to comment.