Added movie clips

This commit is contained in:
Skyler Lehmkuhl 2012-01-13 16:45:55 -05:00
parent 0d0f6c66a2
commit 75f3402103
2 changed files with 99 additions and 15 deletions

View File

@ -3,6 +3,8 @@
# © 2012 Skyler Lehmkuhl # © 2012 Skyler Lehmkuhl
# Released under the GPLv3. For more information, see gpl.txt. # Released under the GPLv3. For more information, see gpl.txt.
import os
#SVLGUI - my custom GUI wrapper to abstract the GUI #SVLGUI - my custom GUI wrapper to abstract the GUI
import svlgui import svlgui
@ -51,6 +53,8 @@ def onKeyDownFrame(self, key):
misc_funcs.update_tooloptions() misc_funcs.update_tooloptions()
elif key=="F6": elif key=="F6":
add_keyframe() add_keyframe()
elif key=="F8":
convert_to_symbol()
MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions MainWindow.scriptwindow.text = root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions
def onMouseDownGroup(self, x, y): def onMouseDownGroup(self, x, y):
self.activelayer.frames[self.activelayer.currentframe].actions = MainWindow.scriptwindow.text self.activelayer.frames[self.activelayer.currentframe].actions = MainWindow.scriptwindow.text
@ -130,7 +134,8 @@ def onKeyDownGroup(self, key):
misc_funcs.update_tooloptions() misc_funcs.update_tooloptions()
elif key=="F6": elif key=="F6":
add_keyframe() add_keyframe()
print "Added keyframe." elif key=="F8":
convert_to_symbol()
def onKeyDownObj(self, key): def onKeyDownObj(self, key):
if key in ("delete", "backspace"): if key in ("delete", "backspace"):
del self.parent[self.parent.index(self)] # Need to clean up deletion del self.parent[self.parent.index(self)] # Need to clean up deletion
@ -141,10 +146,14 @@ def onKeyDownObj(self, key):
misc_funcs.update_tooloptions() misc_funcs.update_tooloptions()
elif key=="F6": elif key=="F6":
add_keyframe() add_keyframe()
elif key=="F8":
convert_to_symbol()
def create_sc(root): def create_sc(root):
#retval = ".flash bbox="+str(svlgui.WIDTH)+"x"+str(svlgui.HEIGHT)+" background=#ffffff \
#fps="+str(svlgui.FRAMERATE)+"\n"+root.print_sc()+".end"
retval = ".flash bbox="+str(svlgui.WIDTH)+"x"+str(svlgui.HEIGHT)+" background=#ffffff \ retval = ".flash bbox="+str(svlgui.WIDTH)+"x"+str(svlgui.HEIGHT)+" background=#ffffff \
fps="+str(svlgui.FRAMERATE)+"\n"+root.print_sc()+".end" fps="+str(svlgui.FRAMERATE)+"\n"+"".join([i.print_sc() for i in svlgui.Library])+root.print_sc()+".end"
return retval return retval
def run_file(self=None): def run_file(self=None):
global root global root
@ -152,7 +161,8 @@ def run_file(self=None):
root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text
open("test.sc", "w").write(create_sc(root)) open("test.sc", "w").write(create_sc(root))
svlgui.execute("swfc/swfc_"+svlgui.PLATFORM+" test.sc -o test.swf") svlgui.execute("swfc/swfc_"+svlgui.PLATFORM+" test.sc -o test.swf")
logloc = "/Users/skyler/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt" #TODO: Make this cross-platform compatible
logloc = os.getenv('HOME')+"/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt"
try: try:
logfile.close() logfile.close()
except: except:
@ -205,7 +215,7 @@ def run_html(self=None):
global root global root
print "RUNNING" print "RUNNING"
root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text root.descendItem().activelayer.frames[root.descendItem().activelayer.currentframe].actions = MainWindow.scriptwindow.text
open("SDFGHJK.html", "w").write(create_html5(root)) open("test.html", "w").write(create_html5(root))
@ -370,6 +380,14 @@ def bring_to_front(widget=None):
rac.append(a) rac.append(a)
MainWindow.stage.draw() MainWindow.stage.draw()
def convert_to_symbol(widget=None):
if not root.descendItem().activelayer.currentselect:
svlgui.alert("No object selected!")
return
else:
svlgui.ConvertToSymbolWindow(root)
MainWindow.stage.draw()
def about(widget=None): def about(widget=None):
svlgui.alert("Lightningbeam v1.0-alpha1\nLast Updated: "+update_date()+ svlgui.alert("Lightningbeam v1.0-alpha1\nLast Updated: "+update_date()+
"\nCreated by: Skyler Lehmkuhl\nBased on SWIFT") "\nCreated by: Skyler Lehmkuhl\nBased on SWIFT")
@ -395,7 +413,7 @@ svlgui.menufuncs([["File",
"Delete", "Delete",
("Preferences",preferences,"")], ("Preferences",preferences,"")],
["Timeline", ["Timeline",
("Add Keyframe",add_keyframe,"F5"), ("Add Keyframe",add_keyframe,"F6"),
"Add Blank Keyframe", "Add Blank Keyframe",
("Add Layer",add_layer,"<Shift><Control>N"), ("Add Layer",add_layer,"<Shift><Control>N"),
("Delete Layer",delete_layer,"<Shift><Control>Delete")], ("Delete Layer",delete_layer,"<Shift><Control>Delete")],
@ -416,7 +434,7 @@ svlgui.menufuncs([["File",
("Execute as HTML5",run_html,"/\\")], ("Execute as HTML5",run_html,"/\\")],
["Modify", ["Modify",
"Document", "Document",
"Convert to Symbol", ("Convert to Symbol",convert_to_symbol,"F8"),
("Send to Back",send_to_back,"<Shift><Control>Down"), ("Send to Back",send_to_back,"<Shift><Control>Down"),
("Send Backwards",send_backward,"<Control>Down"), ("Send Backwards",send_backward,"<Control>Down"),
("Bring Forwards",bring_forward,"<Control>Up"), ("Bring Forwards",bring_forward,"<Control>Up"),

View File

@ -234,6 +234,7 @@ if SYSTEM=="osx":
m.send_to_back.enabled = 1 m.send_to_back.enabled = 1
m.import_to_stage.enabled = 1 m.import_to_stage.enabled = 1
m.import_to_library.enabled = 1 m.import_to_library.enabled = 1
m.convert_to_symbol.enabled = 1
m.preferences_cmd.enabled = 1 m.preferences_cmd.enabled = 1
#def create_sc(self): #def create_sc(self):
@ -999,6 +1000,8 @@ class Image(object):
pass pass
def onKeyUp(self, self1, key): def onKeyUp(self, self1, key):
pass pass
def print_sc(self):
return ".png "+self.name+" \""+self.path+"\"\n"
class Shape (object): class Shape (object):
def __init__(self,x=0,y=0,rotation=0,fillcolor=None,linecolor=None): def __init__(self,x=0,y=0,rotation=0,fillcolor=None,linecolor=None):
@ -1207,6 +1210,15 @@ class Shape (object):
miny = property(getminy) miny = property(getminy)
maxx = property(getmaxx) maxx = property(getmaxx)
maxy = property(getmaxy) maxy = property(getmaxy)
def print_sc(self):
retval = ""
retval+=".outline "+self.name+"outline:\n"
retval+=" ".join([" ".join([str(x) for x in a]) for a in self.shapedata])+"\n.end\n"
if self.filled:
retval+=".filled "+self.name+" outline="+self.name+"outline fill="+self.fillcolor.rgb+" color="+self.linecolor.rgb+"\n"
else:
retval+=".filled "+self.name+" outline="+self.name+"outline fill=#00000000 color="+self.linecolor.rgb+"\n"
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"
retval += self.name+".fill = \""+self.fillcolor.rgb+"\";\n"+self.name+".line = \""+self.linecolor.rgb+"\";\n" retval += self.name+".fill = \""+self.fillcolor.rgb+"\";\n"+self.name+".line = \""+self.linecolor.rgb+"\";\n"
@ -1224,6 +1236,7 @@ class framewrapper (object):
self.scaley = obj.scaley = scaley self.scaley = obj.scaley = scaley
self.level = False # don't try to descend into a framewrapper self.level = False # don't try to descend into a framewrapper
self.type = obj.__class__.__name__ self.type = obj.__class__.__name__
if obj.__class__.__name__=="Shape":
self.filled = obj.filled self.filled = obj.filled
self.linecolor = obj.linecolor self.linecolor = obj.linecolor
self.fillcolor = obj.fillcolor self.fillcolor = obj.fillcolor
@ -1239,6 +1252,7 @@ class framewrapper (object):
self.obj.rot = self.rot self.obj.rot = self.rot
self.obj.scalex = self.scalex self.obj.scalex = self.scalex
self.obj.scaley = self.scaley self.obj.scaley = self.scaley
if self.type=="Shape":
self.obj.filled = self.filled self.obj.filled = self.filled
self.obj.linecolor = self.linecolor self.obj.linecolor = self.linecolor
self.obj.fillcolor = self.fillcolor self.obj.fillcolor = self.fillcolor
@ -1440,6 +1454,12 @@ class Layer:
self.frames[self.currentframe].add(obj, obj.x, obj.y, obj.rotation,0,0) self.frames[self.currentframe].add(obj, obj.x, obj.y, obj.rotation,0,0)
self.objs.append(obj) self.objs.append(obj)
[parse_obj(obj) for obj in args] [parse_obj(obj) for obj in args]
def delete(self,*args):
for i in args:
print "#>>",i
for j in self.frames[self.currentframe].objs:
if j == i:
del self.currentFrame()[self.currentFrame().index(j)]
def add_frame(self,populate): def add_frame(self,populate):
if self.activeframe>len(self.frames): if self.activeframe>len(self.frames):
lastframe = len(self.frames) lastframe = len(self.frames)
@ -1535,7 +1555,7 @@ class Layer:
if defs: if defs:
for i in self.objs: for i in self.objs:
if i.type=="Group": if i.type=="Group":
retval+=".sprite "+i.name+"\n"+i.print_sc retval+=".sprite "+i.name+"\n"+i.print_sc()+".end\n"
elif i.type=="Shape": elif i.type=="Shape":
retval+=".outline "+i.name+"outline:\n" retval+=".outline "+i.name+"outline:\n"
retval+=" ".join([" ".join([str(x) for x in a]) for a in i.shapedata])+"\n.end\n" retval+=" ".join([" ".join([str(x) for x in a]) for a in i.shapedata])+"\n.end\n"
@ -1619,6 +1639,7 @@ class Group (object):
self.rotation = 0 self.rotation = 0
self.xscale = 1 self.xscale = 1
self.yscale = 1 self.yscale = 1
self.type = "Group"
if "onload" in kwargs: if "onload" in kwargs:
kwargs["onload"](self) kwargs["onload"](self)
def draw(self,cr=None,transform=None,rect=None): def draw(self,cr=None,transform=None,rect=None):
@ -1736,16 +1757,22 @@ class Group (object):
return frame return frame
def print_sc(self): def print_sc(self):
retval = "" retval = ""
for i in self.layers: #for i in self.layers:
retval+=i.print_sc(True, False) # retval+=i.print_sc(True, False)
if not self.name=="_root":
retval+=".sprite "+self.name+"\n"
for i in xrange(self.maxframe()): for i in xrange(self.maxframe()):
for j in self.layers: for j in self.layers:
if j.frames[i]: if j.frames[i]:
retval+=".frame "+str(i+1)+"\n" retval+=".frame "+str(i+1)+"\n"
retval+=j.frames[i].print_sc() retval+=j.frames[i].print_sc()
if not self.name=="_root":
retval+=".end\n"
return retval return retval
def print_html(self): def print_html(self):
retval = "" retval = ""
if not self.name=="_root":
retval = retval + "var "+self.name+" = new MovieClip();\n"
for i in self.layers: for i in self.layers:
pass pass
#retval+=i.print_html(True,False) #retval+=i.print_html(True,False)
@ -1984,6 +2011,7 @@ class PreferencesWindow:
def __init__(self): def __init__(self):
if SYSTEM=="osx": if SYSTEM=="osx":
win = ModalDialog(closable=True,width=500,height=500) win = ModalDialog(closable=True,width=500,height=500)
self.win.title = "Preferences"
frame = Frame() frame = Frame()
win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew") win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew")
label = Label("Path to Flash Debugger: ") label = Label("Path to Flash Debugger: ")
@ -1996,6 +2024,7 @@ class SizeWindow:
self.width = WIDTH self.width = WIDTH
self.height = HEIGHT self.height = HEIGHT
self.win = ModalDialog(closable=True,width=160,height=70) self.win = ModalDialog(closable=True,width=160,height=70)
self.win.title = "Dimensions"
frame = Frame() frame = Frame()
self.win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew") self.win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew")
wlabel = Label("Width: ") wlabel = Label("Width: ")
@ -2027,6 +2056,7 @@ class PublishSettingsWindow:
def __init__(self): def __init__(self):
if SYSTEM=="osx": if SYSTEM=="osx":
self.win = ModalDialog(closable=True,width=400,height=300) self.win = ModalDialog(closable=True,width=400,height=300)
self.win.title = "Publish Settings"
frame = Frame() frame = Frame()
self.win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew") self.win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew")
plabel = Label("Settings-publish") plabel = Label("Settings-publish")
@ -2069,6 +2099,42 @@ class PublishSettingsWindow:
"fallback":self.c4.value,"pack":self.impack.value} "fallback":self.c4.value,"pack":self.impack.value}
self.win.ok() self.win.ok()
class ConvertToSymbolWindow:
def __init__(self,root):
self.root = root
if SYSTEM=="osx":
self.win = ModalDialog(closable=True,width=400,height=150)
self.win.title = "Convert to symbol"
frame = Frame()
self.win.place(frame._int(), left=0, top=0, right=0, bottom=0, sticky="nsew")
nlabel = Label("Name: ")
self.ntry = TextEntry("Symbol 1") #TODO: dynamically generate this
self.ntry.set_action(self.confirm)
tlabel = Label("Type: ")
tgroup = RadioGroup("Movie Clip", "Button", "Group")
b1 = DefaultButton()
b1.action = self.confirm
b2 = CancelButton()
frame.layout_self( [nlabel,5,None,5,None,"nw",""],
[self.ntry, nlabel._int()+5,-5,5,None,'new','h'],
[tlabel,5,None,self.ntry._int(),None,'nw',''],
[tgroup[0],32,None,tlabel._int(),None,'nw',''],
[tgroup[1],32,None,tgroup[0]._int(),None,'nw',''],
[tgroup[2],32,None,tgroup[1]._int(),None,'nw',''],
[Widget(b2),5,None,None,-5,'nw',''],
[Widget(b1),None,-5,None,-5,'nw',''])
self.win.present()
def settype(self,tgroup):
self.type = tgroup.value
def confirm(self):
symbol = Group()
symbol.add(self.root.descendItem().activelayer.currentselect.obj)
symbol.name = self.ntry.text
self.root.descendItem().activelayer.delete(self.root.descendItem().activelayer.currentselect)
print self.root.descendItem().activelayer.currentFrame()
self.root.descendItem().activelayer.add(symbol)
self.win.ok()
class FramesCanvas(Canvas): class FramesCanvas(Canvas):
def __init__(self,w,h): def __init__(self,w,h):
Canvas.__init__(self,w,h) Canvas.__init__(self,w,h)