Merge branch 'master' of github.com:skykooler/Lightningbeam

This commit is contained in:
Skyler Lehmkuhl 2012-03-30 14:29:39 -04:00
commit c3ef57dee3
3 changed files with 426 additions and 156 deletions

View File

@ -308,14 +308,14 @@ root.onMouseUp = onMouseUpGroup
root.onMouseMove = onMouseMoveGroup root.onMouseMove = onMouseMoveGroup
root.onMouseDrag = onMouseDragGroup root.onMouseDrag = onMouseDragGroup
root.onKeyDown = onKeyDownGroup root.onKeyDown = onKeyDownGroup
'''
e=ellipse(100,100,10,10,None) e=ellipse(100,100,100,50,None)
e.onMouseDown = onMouseDownObj e.onMouseDown = onMouseDownObj
e.onMouseMove = onMouseMoveObj e.onMouseMove = onMouseMoveObj
e.onMouseDrag = onMouseDragObj e.onMouseDrag = onMouseDragObj
e.onMouseUp = onMouseUpObj e.onMouseUp = onMouseUpObj
e.onKeyDown = onKeyDownObj e.onKeyDown = onKeyDownObj
root.add(e)''' root.add(e)

View File

@ -59,6 +59,12 @@ def update_tooloptions():
else: else:
i.setvisible(False) i.setvisible(False)
def ave(x, y, fac):
"""Weighted average.
fac is the weight - 0.5 gives a standard average"""
return y - fac*(y-x)
def box(x, y, width, height, fill): def box(x, y, width, height, fill):
global objects global objects
box = svlgui.Shape(x, y) box = svlgui.Shape(x, y)

558
svlgui.py
View File

@ -44,6 +44,9 @@ FRAMERATE=50
#Width and height are the width and height of the document #Width and height are the width and height of the document
WIDTH, HEIGHT = 500, 500 WIDTH, HEIGHT = 500, 500
#Whether we are using OpenGL for rendering.
USING_GL = True
#Object which has the keyboard focus. #Object which has the keyboard focus.
FOCUS = None FOCUS = None
@ -170,6 +173,14 @@ if sys.platform=="linux2":
from GUI.StdMenus import basic_menus, file_cmds, print_cmds from GUI.StdMenus import basic_menus, file_cmds, print_cmds
from GUI.StdButtons import DefaultButton, CancelButton from GUI.StdButtons import DefaultButton, CancelButton
from GUI.Files import FileType from GUI.Files import FileType
if USING_GL:
from OpenGL.GL import *
from OpenGL.GLU import *
from GUI import GL
try:
from PIL import Image as PILImage
except ImportError as err:
import Image as PILImage
from GUI.Geometry import offset_rect, rect_sized from GUI.Geometry import offset_rect, rect_sized
#If we can import this, we are in the install directory. Mangle media paths accordingly. #If we can import this, we are in the install directory. Mangle media paths accordingly.
@ -246,6 +257,7 @@ elif sys.platform=="darwin":
FONT = u'Times New Roman' FONT = u'Times New Roman'
media_path = "" media_path = ""
#app = GUI.application() #app = GUI.application()
SYSTEM="osx"
TEMPDIR="/tmp" TEMPDIR="/tmp"
sep = "/" sep = "/"
@ -581,7 +593,8 @@ class Label(Widget):
elif SYSTEM=="pyglet": elif SYSTEM=="pyglet":
self.label = pyglet.text.Label(text) self.label = pyglet.text.Label(text)
def _int(self): def _int(self):
return self.label if SYSTEM=="osx":
return self.label
def disable(self): def disable(self):
if SYSTEM=="osx": if SYSTEM=="osx":
self.label.enabled = False self.label.enabled = False
@ -831,6 +844,76 @@ class CheckBox(Widget):
self.box.value = value self.box.value = value
value = property(get_value, set_value) value = property(get_value, set_value)
class _CR(object):
"""Internal use only. This is a class that only exists for GLViews
to pass window dimensions on to their children."""
def __init__(self):
self.x = 0
self.y = 0
self.stack = []
def save(self):
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix()
self.stack.append((self.x, self.y))
def restore(self):
self.x, self.y = self.stack.pop()
glPopMatrix()
glPopAttrib()
def translate(self, x, y):
glTranslatef(x, y, 0);
def rotate(self, r):
pass
def scale(self, sx, sy):
pass
def drawCurve(self, points, precision=20):
npoints = []
ave = misc_funcs.ave
s = range(0, len(points)-2, 2)
for i in s:
for j in range(precision):
k=1.0*(precision-j)
x=ave( ave(ave(self.x,
points[i][0],
k/precision),
ave(points[i][0],
points[i+1][0],
k/precision),
k/precision),
ave(ave(points[i][0],
points[i+1][0],
k/precision),
ave(points[i+1][0],
points[i+2][0],
k/precision),
k/precision),
k/precision)
y=ave( ave(ave(self.y,
points[i][1],
k/precision),
ave(points[i][1],
points[i+1][1],
k/precision),
k/precision),
ave(ave(points[i][1],
points[i+1][1],
k/precision),
ave(points[i+1][1],
points[i+2][1],
k/precision),
k/precision),
k/precision)
npoints.append((x, y))
glVertex2f(self.x, self.y)
glVertex2f(npoints[0][0], npoints[0][1])
for i in range(len(npoints)-1):
#drawLine(gc, drawable, npoints[i][0], npoints[i][1], npoints[i+1][0], npoints[i+1][1])
print npoints[i][0],npoints[i][1],npoints[i+1][0],npoints[i+1][1]
glVertex2f(npoints[i][0], npoints[i][1])
glVertex2f(npoints[i+1][0], npoints[i+1][1])
glVertex2f(npoints[-1][0],npoints[-1][1])
glVertex2f(*points[2])
class Canvas(Widget): class Canvas(Widget):
def __init__(self,width=False,height=False): def __init__(self,width=False,height=False):
@ -863,59 +946,83 @@ class Canvas(Widget):
self.canvas.connect("button-release-event", onMouseUp) self.canvas.connect("button-release-event", onMouseUp)
self.canvas.connect("motion_notify_event", onMouseMove) self.canvas.connect("motion_notify_event", onMouseMove)
elif SYSTEM=="osx": elif SYSTEM=="osx":
class OSXCanvas (ScrollableView): if USING_GL:
def draw(self, canvas, update_rect): class OSXCanvas(GL.GLView):
canvas.erase_rect(update_rect) def init_context(self):
for i in self.objs: glClearColor(0.75,0.75,0.75,0.0)
i.draw(canvas) def init_projection(self):
glViewport(0, 0, width, height);
def mouse_down(self, event): glEnable( GL_TEXTURE_2D );
self.become_target() glEnable (GL_BLEND);
x, y = event.position #glDisable( GL_LIGHTING)
try: glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
def render(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluOrtho2D(0, width, 0, height); #TODO: width, height
glMatrixMode(GL_MODELVIEW);
cr = _CR()
cr.width = self.width
cr.height = self.height
for i in self.objs: for i in self.objs:
i._onMouseDown(x, y) i.draw(cr)
except ObjectDeletedError:
return
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
def mouse_drag(self, event): self.canvas = OSXCanvas()
x, y = event.position self.canvas.update()
for i in self.objs: else:
i._onMouseDrag(x, y) class OSXCanvas (ScrollableView):
self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) def draw(self, canvas, update_rect):
canvas.erase_rect(update_rect)
for i in self.objs:
i.draw(canvas)
def mouse_move(self, event): def mouse_down(self, event):
x, y = event.position self.become_target()
for i in self.objs: x, y = event.position
i._onMouseMove(x, y) try:
self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) for i in self.objs:
i._onMouseDown(x, y)
except ObjectDeletedError:
return
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
def mouse_up(self, event): def mouse_drag(self, event):
x, y = event.position x, y = event.position
for i in self.objs: for i in self.objs:
i._onMouseUp(x, y) i._onMouseDrag(x, y)
self.invalidate_rect([0,0,self.extent[0],self.extent[1]]) self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
def key_down(self, event): def mouse_move(self, event):
keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow", x, y = event.position
63235:"right_arrow",63234:"left_arrow",13:"enter",9:"tab", for i in self.objs:
63236:"F1",63237:"F2",63238:"F3",63239:"F4",63240:"F5", i._onMouseMove(x, y)
63241:"F6",63242:"F7",63243:"F8",27:"escape"} self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
if not event.unichars=='':
if ord(event.unichars) in keydict: def mouse_up(self, event):
key = keydict[ord(event.unichars)] x, y = event.position
for i in self.objs:
i._onMouseUp(x, y)
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
def key_down(self, event):
keydict = {127:"backspace",63272:"delete",63232:"up_arrow",63233:"down_arrow",
63235:"right_arrow",63234:"left_arrow",13:"enter",9:"tab",
63236:"F1",63237:"F2",63238:"F3",63239:"F4",63240:"F5",
63241:"F6",63242:"F7",63243:"F8",27:"escape"}
if not event.unichars=='':
if ord(event.unichars) in keydict:
key = keydict[ord(event.unichars)]
else:
key = event.unichars
else: else:
key = event.unichars key = event.key.upper()
else: for i in self.objs:
key = event.key.upper() i._onKeyDown(key)
for i in self.objs: self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
i._onKeyDown(key)
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])
def key_up(self, event): def key_up(self, event):
pass pass
self.canvas = OSXCanvas(extent = (width, height), scrolling = 'hv') self.canvas = OSXCanvas(extent = (width, height), scrolling = 'hv')
self.canvas.objs = self.objs self.canvas.objs = self.objs
elif SYSTEM=="html": elif SYSTEM=="html":
global ids global ids
@ -1060,6 +1167,10 @@ class Image(object):
self.path = image self.path = image
self.pilimage = PILimage.open(image) self.pilimage = PILimage.open(image)
self.type="Image" self.type="Image"
if USING_GL:
# This is an OpenGL texture ID.
self.gltexture = self.loadGLImage(file = image)
if animated: if animated:
self.animated = True self.animated = True
self.htiles = htiles self.htiles = htiles
@ -1101,43 +1212,97 @@ class Image(object):
if SYSTEM=="android": if SYSTEM=="android":
pass pass
elif SYSTEM=="osx": elif SYSTEM=="osx":
cr.gsave() if USING_GL:
if sep=="\\": pass
# Very ugly hack for Windows. :( glEnable(GL_TEXTURE_2D);
# Windows doesn't respect coordinate transformations glColor3f(0.5,0.5,0.5);
# with respect to translation, so we have to do this #self.gltexture.bind()
# bit ourselves. #self.gltexture.gl_tex_image_2d(self.image, with_mipmaps=True)
# Rotation in radians glBindTexture(GL_TEXTURE_2D, self.gltexture)
radrot = parent.group.rotation*math.pi/180
# Coordinate transform: multiplication by a rotation matrix if self.animated:
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot)) src_rect = [(1.0/self.htiles)*(self.pointer%self.htiles),
(1.0/self.vtiles)*(self.pointer/self.htiles),
(1.0/self.htiles)*(self.pointer%self.htiles+1),
(1.0/self.vtiles)*(self.pointer/self.htiles+1)]
width = self.image.bounds[2]/self.htiles
height = self.image.bounds[3]/self.vtiles
else:
src_rect = [0.0, 0.0, 1.0, 1.0]
width, height = self.image.bounds
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
#glTexCoord2f(src_rect[0], src_rect[1]);
glVertex2f( self.x, cr.height-(self.y));
glTexCoord2f(1.0, 0.0);
#glTexCoord2f(src_rect[2], src_rect[1]);
glVertex2f(width+self.x, cr.height-(self.y));
glTexCoord2f(1.0, 1.0);
#glTexCoord2f(src_rect[2], src_rect[3]);
glVertex2f( width+self.x, cr.height-(height+self.y));
glTexCoord2f(0.0, 1.0);
#glTexCoord2f(src_rect[0], src_rect[3]);
glVertex2f( self.x, cr.height-(height+self.y));
print src_rect
glEnd();
else: else:
cr.translate(self.x,self.y) cr.gsave()
cr.rotate(self.rotation) if sep=="\\":
cr.scale(self.xscale*1.0, self.yscale*1.0) # Very ugly hack for Windows. :(
if self.animated: # Windows doesn't respect coordinate transformations
src_rect = self.image.bounds # with respect to translation, so we have to do this
# (i%4)%6, i/4 # bit ourselves.
src_rect = [(src_rect[2]/self.htiles)*(self.pointer%self.htiles),
(src_rect[3]/self.vtiles)*(self.pointer/self.htiles), # Rotation in radians
(src_rect[2]/self.htiles)*(self.pointer%self.htiles+1), radrot = parent.group.rotation*math.pi/180
(src_rect[3]/self.vtiles)*(self.pointer/self.htiles+1)] # Coordinate transform: multiplication by a rotation matrix
#src_rect = [16*self.pointer,0,16+16*self.pointer,32] cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
#print [self.x, self.y, self.x+self.image.bounds[2]/self.htiles, self.y+self.image.bounds[3]/self.vtiles] else:
dst_rect = [self.x, self.y, self.image.bounds[2]/self.htiles+self.x, self.image.bounds[3]/self.vtiles+self.y] cr.translate(self.x,self.y)
self.image.draw(cr, src_rect, dst_rect) cr.rotate(self.rotation)
else: cr.scale(self.xscale*1.0, self.yscale*1.0)
src_rect = self.image.bounds if self.animated:
dst_rect = [self.x,self.y,self.x+src_rect[2],self.y+src_rect[3]] src_rect = self.image.bounds
self.image.draw(cr, src_rect, dst_rect) # (i%4)%6, i/4
cr.grestore() src_rect = [(src_rect[2]/self.htiles)*(self.pointer%self.htiles),
(src_rect[3]/self.vtiles)*(self.pointer/self.htiles),
(src_rect[2]/self.htiles)*(self.pointer%self.htiles+1),
(src_rect[3]/self.vtiles)*(self.pointer/self.htiles+1)]
#src_rect = [16*self.pointer,0,16+16*self.pointer,32]
#print [self.x, self.y, self.x+self.image.bounds[2]/self.htiles, self.y+self.image.bounds[3]/self.vtiles]
dst_rect = [self.x, self.y, self.image.bounds[2]/self.htiles+self.x, self.image.bounds[3]/self.vtiles+self.y]
self.image.draw(cr, src_rect, dst_rect)
else:
src_rect = self.image.bounds
dst_rect = [self.x,self.y,self.x+src_rect[2],self.y+src_rect[3]]
self.image.draw(cr, src_rect, dst_rect)
cr.grestore()
elif SYSTEM=="html": elif SYSTEM=="html":
cr.save() cr.save()
pass pass
def set_image(self,img): def set_image(self,img):
if SYSTEM=="osx": if SYSTEM=="osx":
self.image = GUI.Image(file = img) self.image = GUI.Image(file = img)
if USING_GL:
self.gltexture = self.loadGLImage(file = img)
def loadGLImage(self, file = None ):
"""Load an image file as a 2D texture using PIL"""
if not file:
file = self.path
im = PILImage.open(file)
try:
ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1)
except SystemError:
ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1)
ID = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, ID)
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glTexImage2D(
GL_TEXTURE_2D, 0, 3, ix, iy, 0,
GL_RGBA, GL_UNSIGNED_BYTE, image
)
return ID
def hitTest(self,x,y): def hitTest(self,x,y):
hits = False hits = False
# points "a" and "b" forms the anchored segment. # points "a" and "b" forms the anchored segment.
@ -1187,6 +1352,7 @@ class Shape (object):
self.yscale = 1 self.yscale = 1
self.linecolor = linecolor if linecolor else LINECOLOR self.linecolor = linecolor if linecolor else LINECOLOR
self.fillcolor = fillcolor if fillcolor else FILLCOLOR self.fillcolor = fillcolor if fillcolor else FILLCOLOR
self.linewidth = 2
self.shapedata=[] self.shapedata=[]
self.filled=False self.filled=False
self.type="Shape" self.type="Shape"
@ -1202,6 +1368,7 @@ class Shape (object):
cr.rotate(self.rotation*math.pi/180) cr.rotate(self.rotation*math.pi/180)
cr.scale(self.xscale*1.0, self.yscale*1.0) cr.scale(self.xscale*1.0, self.yscale*1.0)
cr.set_source(self.linecolor.cairo) cr.set_source(self.linecolor.cairo)
cr.set_line_width(max(self.linewidth,1))
for i in self.shapedata: for i in self.shapedata:
if i[0]=="M": if i[0]=="M":
cr.move_to(i[1],i[2]) cr.move_to(i[1],i[2])
@ -1222,6 +1389,7 @@ class Shape (object):
tb+="cr.translate("+str(self.x)+","+str(self.y)+")\n" tb+="cr.translate("+str(self.x)+","+str(self.y)+")\n"
tb+="cr.rotate("+str(self.rotation*math.pi/180)+")\n" tb+="cr.rotate("+str(self.rotation*math.pi/180)+")\n"
tb+="cr.scale("+str(self.xscale)+"*1.0, "+str(self.yscale)+"*1.0)\n" tb+="cr.scale("+str(self.xscale)+"*1.0, "+str(self.yscale)+"*1.0)\n"
tb+="cr.lineWidth = "+str(max(self.linewidth,1))+"\n"
if type(self.fill)==type([]): if type(self.fill)==type([]):
tb+="cr.fillStyle = \""+rgb2hex(self.fill[0],self.fill[1],self.fill[2])+"\"\n" tb+="cr.fillStyle = \""+rgb2hex(self.fill[0],self.fill[1],self.fill[2])+"\"\n"
for i in self.shapedata: for i in self.shapedata:
@ -1238,49 +1406,123 @@ class Shape (object):
tb+="cr.stroke()\n" tb+="cr.stroke()\n"
tb+="cr.restore()\n" tb+="cr.restore()\n"
elif SYSTEM=="osx": elif SYSTEM=="osx":
cr.gsave()
if sep=="\\":
# Very ugly hack for Windows. :(
# Windows doesn't respect coordinate transformations
# with respect to translation, so we have to do this
# bit ourselves.
# Rotation in radians if USING_GL:
radrot = parent.group.rotation*math.pi/180 cr.save()
# Coordinate transform: multiplication by a rotation matrix cr.translate(self.x, cr.height-self.y)
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot)) cr.rotate(self.rotation)
cr.scale(self.xscale*1.0, self.yscale*1.0)
#pencolor, fillcolor, pensize
#Temporary.
glColor3f(1.0,0.0,0.0)
glBegin(GL_LINES)
for i in self.shapedata:
if i[0]=="M":
point = (i[1], i[2])
#glVertex2f(point[0], cr.height-point[1])
cr.x, cr.y = point
elif i[0]=="L":
point = (i[1], i[2])
#glVertex2f(point[0], cr.height-point[1])
glVertex2f(cr.x, -cr.y)
glVertex2f(point[0], -point[1])
cr.x, cr.y = point
elif i[0]=="C":
pointa = (i[1], i[2])
pointb = (i[3], i[4])
pointc = (i[5], i[6])
#TODO: curve
#glVertex2f(pointc[0], -pointc[1])
#glVertex2f(pointc[0], -pointc[1])
cr.drawCurve([ pointa, pointb, pointc])
cr.x, cr.y = pointc
glEnd()
cr.restore()
else: else:
cr.translate(self.x,self.y) cr.gsave()
cr.rotate(self.rotation) if sep=="\\":
cr.scale(self.xscale*1.0, self.yscale*1.0) # Very ugly hack for Windows. :(
cr.newpath() # Windows doesn't respect coordinate transformations
cr.pencolor = self.linecolor.pygui # with respect to translation, so we have to do this
cr.fillcolor = self.fillcolor.pygui # bit ourselves.
for i in self.shapedata:
if i[0]=="M": # Rotation in radians
point = (i[1], i[2]) radrot = parent.group.rotation*math.pi/180
cr.moveto(point[0],point[1]) # Coordinate transform: multiplication by a rotation matrix
elif i[0]=="L": cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
point = (i[1], i[2]) else:
cr.lineto(point[0],point[1]) cr.translate(self.x,self.y)
elif i[0]=="C": cr.rotate(self.rotation)
pointa = (i[1], i[2]) cr.scale(self.xscale*1.0, self.yscale*1.0)
pointb = (i[3], i[4]) cr.newpath()
pointc = (i[5], i[6]) cr.pencolor = self.linecolor.pygui
### Mac OSX needs custom PyGUI for this to work ### cr.fillcolor = self.fillcolor.pygui
cr.curveto((pointa[0],pointa[1]),(pointb[0],pointb[1]),(pointc[0],pointc[1])) cr.pensize = max(self.linewidth,1)
if self.filled: for i in self.shapedata:
cr.closepath() if i[0]=="M":
cr.fill_stroke() point = (i[1], i[2])
else: cr.moveto(point[0],point[1])
cr.stroke() elif i[0]=="L":
cr.grestore() point = (i[1], i[2])
cr.lineto(point[0],point[1])
elif i[0]=="C":
pointa = (i[1], i[2])
pointb = (i[3], i[4])
pointc = (i[5], i[6])
### Mac OSX needs custom PyGUI for this to work ###
cr.curveto((pointa[0],pointa[1]),(pointb[0],pointb[1]),(pointc[0],pointc[1]))
if self.filled:
cr.closepath()
cr.fill_stroke()
else:
cr.gsave()
if sep=="\\":
# Very ugly hack for Windows. :(
# Windows doesn't respect coordinate transformations
# with respect to translation, so we have to do this
# bit ourselves.
# Rotation in radians
radrot = parent.group.rotation*math.pi/180
# Coordinate transform: multiplication by a rotation matrix
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
else:
cr.translate(self.x,self.y)
cr.rotate(self.rotation)
cr.scale(self.xscale*1.0, self.yscale*1.0)
cr.newpath()
cr.pencolor = self.linecolor.pygui
cr.fillcolor = self.fillcolor.pygui
for i in self.shapedata:
if i[0]=="M":
point = (i[1], i[2])
cr.moveto(point[0],point[1])
elif i[0]=="L":
point = (i[1], i[2])
cr.lineto(point[0],point[1])
elif i[0]=="C":
pointa = (i[1], i[2])
pointb = (i[3], i[4])
pointc = (i[5], i[6])
### Mac OSX needs custom PyGUI for this to work ###
cr.curveto((pointa[0],pointa[1]),(pointb[0],pointb[1]),(pointc[0],pointc[1]))
if self.filled:
cr.closepath()
cr.fill_stroke()
else:
cr.stroke()
cr.grestore()
elif SYSTEM=="html": elif SYSTEM=="html":
tb = "" tb = ""
tb+="cr.save()\n" tb+="cr.save()\n"
tb+="cr.translate("+str(self.x)+","+str(self.y)+")\n" tb+="cr.translate("+str(self.x)+","+str(self.y)+")\n"
tb+="cr.rotate("+str(self.rotation*math.pi/180)+")\n" tb+="cr.rotate("+str(self.rotation*math.pi/180)+")\n"
tb+="cr.scale("+str(self.xscale)+"*1.0, "+str(self.yscale)+"*1.0)\n" tb+="cr.scale("+str(self.xscale)+"*1.0, "+str(self.yscale)+"*1.0)\n"
tb+="cr.lineWidth = "+str(max(self.linewidth,1))+"\n"
if type(self.fill)==type([]): if type(self.fill)==type([]):
tb+="cr.fillStyle = \""+rgb2hex(self.fill[0],self.fill[1],self.fill[2])+"\"\n" tb+="cr.fillStyle = \""+rgb2hex(self.fill[0],self.fill[1],self.fill[2])+"\"\n"
for i in self.shapedata: for i in self.shapedata:
@ -1388,9 +1630,9 @@ class Shape (object):
retval+=".outline "+self.name+"outline:\n" retval+=".outline "+self.name+"outline:\n"
retval+=" ".join([" ".join([str(x) for x in a]) for a in self.shapedata])+"\n.end\n" retval+=" ".join([" ".join([str(x) for x in a]) for a in self.shapedata])+"\n.end\n"
if self.filled: if self.filled:
retval+=".filled "+self.name+" outline="+self.name+"outline fill="+self.fillcolor.rgb+" color="+self.linecolor.rgb+"\n" retval+=".filled "+self.name+" outline="+self.name+"outline fill="+self.fillcolor.rgb+" color="+self.linecolor.rgb+" line="+str(self.linewidth)+"\n"
else: else:
retval+=".filled "+self.name+" outline="+self.name+"outline fill=#00000000 color="+self.linecolor.rgb+"\n" retval+=".filled "+self.name+" outline="+self.name+"outline fill=#00000000 color="+self.linecolor.rgb+" line="+str(self.linewidth)+"\n"
return retval return retval
def print_html(self): def print_html(self):
retval = "var "+self.name+" = new Shape();\n"+self.name+"._shapedata = "+str(self.shapedata)+";\n" retval = "var "+self.name+" = new Shape();\n"+self.name+"._shapedata = "+str(self.shapedata)+";\n"
@ -1429,26 +1671,29 @@ class Text (object):
SITER+=1 SITER+=1
def draw(self,cr=None,parent=None,rect=None): def draw(self,cr=None,parent=None,rect=None):
if SYSTEM=="osx": if SYSTEM=="osx":
cr.font = self.font if USING_GL:
cr.textcolor = self.fill.pygui pass
cr.gsave()
#cr.moveto(self.x,self.y)
if sep=="\\":
# Very ugly hack for Windows. :(
# Windows doesn't respect coordinate transformations
# with respect to translation, so we have to do this
# bit ourselves.
# Rotation in radians
radrot = parent.group.rotation*math.pi/180
# Coordinate transform: multiplication by a rotation matrix
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
else: else:
cr.translate(self.x,self.y) cr.font = self.font
cr.newpath() cr.textcolor = self.fill.pygui
cr.moveto(0,0) cr.gsave()
cr.show_text(self.text) #cr.moveto(self.x,self.y)
cr.grestore() if sep=="\\":
# Very ugly hack for Windows. :(
# Windows doesn't respect coordinate transformations
# with respect to translation, so we have to do this
# bit ourselves.
# Rotation in radians
radrot = parent.group.rotation*math.pi/180
# Coordinate transform: multiplication by a rotation matrix
cr.translate(self.x*math.cos(radrot)-self.y*math.sin(radrot), self.x*math.sin(radrot)+self.y*math.cos(radrot))
else:
cr.translate(self.x,self.y)
cr.newpath()
cr.moveto(0,0)
cr.show_text(self.text)
cr.grestore()
def hitTest(self, x, y): def hitTest(self, x, y):
self.width = self.font.width(self.text) self.width = self.font.width(self.text)
self.height = self.font.height self.height = self.font.height
@ -1629,23 +1874,42 @@ class frame:
tb+="cr.restore()\n" tb+="cr.restore()\n"
elif SYSTEM=="osx": elif SYSTEM=="osx":
self.group = group self.group = group
cr.gsave() if USING_GL:
cr.rotate(group.rotation) #cr.gsave()
cr.translate(group.x,group.y) #cr.rotate(group.rotation)
cr.scale(group.xscale,group.yscale) #cr.translate(group.x,group.y)
def dodraw(obj, cr): #cr.scale(group.xscale,group.yscale)
obj.draw(cr, self) def dodraw(obj, cr):
result = [dodraw(obj, cr) for obj in self.objs] obj.draw(cr, self)
if currentselect: result = [dodraw(obj, cr) for obj in self.objs]
#if currentselect:
#cr.gsave()
#cr.newpath()
#cr.pencolor = Colors.rgb(0,0,1)
#cr.rect([currentselect.minx-1,currentselect.miny-1,
# currentselect.maxx+currentselect.x+2,
# currentselect.maxy+currentselect.y+2])
#cr.stroke()
#cr.grestore()
#cr.grestore()
else:
cr.gsave() cr.gsave()
cr.newpath() cr.rotate(group.rotation)
cr.pencolor = Colors.rgb(0,0,1) cr.translate(group.x,group.y)
cr.rect([currentselect.minx-1,currentselect.miny-1, cr.scale(group.xscale,group.yscale)
currentselect.maxx+currentselect.x+2, def dodraw(obj, cr):
currentselect.maxy+currentselect.y+2]) obj.draw(cr, self)
cr.stroke() result = [dodraw(obj, cr) for obj in self.objs]
if currentselect:
cr.gsave()
cr.newpath()
cr.pencolor = Colors.rgb(0,0,1)
cr.rect([currentselect.minx-1,currentselect.miny-1,
currentselect.maxx+currentselect.x+2,
currentselect.maxy+currentselect.y+2])
cr.stroke()
cr.grestore()
cr.grestore() cr.grestore()
cr.grestore()
elif SYSTEM=="html": elif SYSTEM=="html":
tb = "" tb = ""
tb+="cr.save()\n" tb+="cr.save()\n"