Mercurial > MadButterfly
changeset 1124:b5ff72dbc910
merge
author | wycc |
---|---|
date | Thu, 09 Dec 2010 07:48:46 +0800 |
parents | aad659b6b625 (diff) 17cbb862a8c6 (current diff) |
children | 5b2394f67ad0 |
files | |
diffstat | 5 files changed, 434 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/filebrowser.c Thu Dec 09 00:33:41 2010 +0800 +++ b/examples/menu/filebrowser.c Thu Dec 09 07:48:46 2010 +0800 @@ -191,7 +191,8 @@ dir = opendir(curdir); while(e = readdir(dir)) { if (strcmp(e->d_name,".")==0) continue; - if (e->d_type == DT_REG) { + printf("e->d_type=%d %d name=%s\n",e->d_type,DT_REG,e->d_name); + if (e->d_type == DT_REG || e->d_type == DT_LNK) { if (data->nFiles < MAX_ENTRY) { f = fileinfo_new(); data->files[data->nFiles] = f;
--- a/nodejs/examples/mce/epg.js Thu Dec 09 00:33:41 2010 +0800 +++ b/nodejs/examples/mce/epg.js Thu Dec 09 07:48:46 2010 +0800 @@ -28,7 +28,12 @@ js = js + data; }); res.on('end', function () { - res = JSON.parse(js); + try { + res = JSON.parse(js); + } catch(e) { + sys.puts(e); + sys.puts(js); + } sys.puts("parsed"); self.onLoad(res); @@ -119,7 +124,7 @@ fs.close(f); var fields = cachepath.split('.'); var ext = fields.pop(); - if (ext != "png") { + if (ext != "png" && ext != 'jpg') { fields.push("png"); newf = fields.join("."); sys.puts("cachepath="+cachepath+" newf="+newf);
--- a/pyink/MBScene.py Thu Dec 09 00:33:41 2010 +0800 +++ b/pyink/MBScene.py Thu Dec 09 07:48:46 2010 +0800 @@ -48,10 +48,11 @@ pass class Scene: - def __init__(self, node, start,end): + def __init__(self, node, start,end,typ): self.node = node self.start = int(start) self.end = int(end) + self.type = typ pass pass @@ -168,10 +169,15 @@ except: end = start pass + try: + typ = s.repr.attribute('type') + if typ == None: + typ = 'normal' + except: + traceback.print_exc() + typ = 'normal' link = s.repr.attribute("ref") - self.scenemap[link] = [int(start),int(end)] - print "scene %d to %d" % (self.scenemap[link][0], - self.scenemap[link][1]) + self.scenemap[link] = [int(start),int(end),typ] if cur >= start and cur <= end: self.currentscene = link pass @@ -234,7 +240,7 @@ lyobj.current_scene.append(scene) continue - lyobj.scenes.append(Scene(scene,scmap[0],scmap[1])) + lyobj.scenes.append(Scene(scene,scmap[0],scmap[1],scmap[2])) pass else: lyobj.current_scene.append(scene) @@ -423,9 +429,35 @@ def setCurrentScene(self,nth): + """ + Update the scene group according to the curretn scene data. There are a couple of cases. + 1. If the type of the scene is normal, we display it when it contains the current + frame. Otherwise hide it. + 2. If the type of the scene is relocate or scale, we need to duplicate the scene group + and then modify its transform matrix according to the definition of the scene. Then, + hide the original scenr group and display the duplciate scene group. In addition, + we may need to delete the old duplicated scene group as well. + + For each layer, we will always use the duplicated scene group whose name as dup. + We will put the duplicated scene group inside it. We will create this group if it is not + available. + """ self.current = nth for layer in self._framelines: i=0 + + # Check the duplicated scene group and create it if it is not available + try: + if layer.duplicateGroup: + layer.duplicateGroup.parent().removeChild(layer.duplicateGroup) + layer.duplicateGroup = None + except: + traceback.print_exc() + pass + # Create a new group + layer.duplicateGroup = None + + while i < len(layer._keys): s = layer._keys[i] print s.ref.attribute("id"),s.idx,s.left_tween,s.right_tween @@ -436,15 +468,131 @@ s.ref.setAttribute("style","display:none",True) i = i + 1 continue - - if nth >= (s.idx+1) and nth <= (layer._keys[i+1].idx+1): + if nth == s.idx + 1: s.ref.setAttribute("style","",True) else: - s.ref.setAttribute("style","display:none",True) + if nth > (s.idx+1) and nth <= (layer._keys[i+1].idx+1): + if i+2 < len(layer._keys): + layer.duplicateGroup = self.desktop.doc().rdoc.createElement("svg:g") + layer.duplicateGroup.setAttribute("inkscape:label","dup",True) + s.ref.setAttribute("style","display:none",True) + s.ref.parent().appendChild(layer.duplicateGroup) + self.updateTweenContent(layer.duplicateGroup, layer.get_tween_type(s.idx),s, layer._keys[i+2], nth) + else: + s.ref.setAttribute("style","display:none",True) i = i + 2 pass pass pass + def updateTweenContent(self,obj, typ, source,dest,cur): + """ + Update the content of the duplicate scene group. We will use the (start,end) and cur to calculate the percentage of + the tween motion effect and then use it to update the transform matrix of the duplicated scene group. + """ + start = source.idx + end = dest.idx + print cur,start,end + percent = (cur-start)*1.0/(end-start) + i = 0 + s = source.ref.firstChild() + d = dest.ref.firstChild() + sources={} + dests={} + # Collect all objects + while d: + try: + label = d.attribute("inkscape:label") + except: + d = d.next() + continue + dests[label.value()] = d + d = d.next() + # Check if the object in the source exists in the destination + s = source.ref.firstChild() + d = dest.ref.firstChild() + while s: + print s,d + try: + label = s.attribute("inkscape:label") + # Use i8nkscape:label to identidy the equipvalent objects + if label: + if dests.hasattr(label.value()): + self.updateTweenObject(obj,typ,s,dests[label.value()],percent) + s = s.next() + continue + except: + pass + # Search obejcts in the destination + while d: + try: + d.attribute("inkscape:label") + d = d.next() + continue + except: + pass + if s.name() == d.name(): + self.updateTweenObject(obj,typ,s,d,percent) + d = d.next() + break + d = d.next() + s = s.next() + def parseTransform(self,obj): + """ + Return the transform matrix of an object + """ + try: + t = obj.attribute("transform") + print t + if t[0:9] == 'translate': + print "translate" + fields = t[10:].split(',') + x = float(fields[0]) + fields = fields[1].split(')') + y = float(fields[0]) + return [1,0,x,0,1,y] + elif t[0:6] == 'matrix': + print "matrix" + fields=t[7:].split(')') + fields = fields[0].split(',') + return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] + except: + traceback.print_exc() + return [1,0,0,0,1,0] + + + def updateTweenObject(self,obj,typ,s,d,p): + """ + Generate tweened object in the @obj by using s and d in the @p percent + """ + print 'compare',s,d + if typ == 'relocate': + print "percent",p + newobj = s.duplicate(self.desktop.doc().rdoc) + top = self.desktop.doc().rdoc.createElement("svg:g") + top.appendChild(newobj) + obj.appendChild(top) + print s.name() + if s.name() == 'svg:g': + # Parse the translate or matrix + sm = self.parseTransform(s) + dm = self.parseTransform(d) + print "g", (dm[2]-sm[2])*p,(dm[5]-sm[5])*p + top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p),True) + else: + try: + sx = float(s.attribute("x")) + sy = float(s.attribute("y")) + dx = float(d.attribute("x")) + dy = float(d.attribute("y")) + tx = (dx-sx)*p + ty = (dy-sy)*p + print tx,ty + top.setAttribute("transform","translate(%g,%g)" % (tx,ty),True) + except: + traceback.print_exc() + pass + pass + pass def enterGroup(self,obj): for l in self.layers: for s in l.node.childList(): @@ -458,6 +606,7 @@ if s.right_tween is False: if nth == s.idx+1: self.enterGroup(s.ref) + self.setTweenType(frameline.get_tween_type(s.idx)) return else: pass @@ -466,12 +615,20 @@ if nth >= (s.idx+1) and nth <= (frameline._keys[i+1].idx+1): self.enterGroup(s.ref) + self.setTweenType(frameline.get_tween_type(s.idx)) return else: pass i = i + 2 pass pass + def setTweenType(self,typ): + if typ == 'normal': + self.tweenTypeSelector.set_active(0) + elif typ == 'relocate': + self.tweenTypeSelector.set_active(1) + elif typ == 'scale': + self.tweenTypeSelector.set_active(2) @@ -558,7 +715,7 @@ frameline.add_keyframe(scene.start-1,scene.node.repr) if scene.start != scene.end: frameline.add_keyframe(scene.end-1,scene.node.repr) - frameline.tween(scene.start-1) + frameline.tween(scene.start-1,scene.type) pass pass pass @@ -662,7 +819,52 @@ btn.connect('clicked', self.doDuplicateKeyScene) hbox.pack_start(btn,expand=False,fill=False) self.addNameEditor(hbox) + self.addTweenTypeSelector(hbox) pass + def onTweenTypeChange(self,w): + n = self.tweenTypeSelector.get_active() + if self.last_line == None: + return + frameline = self.last_line + i = 0 + found = -1 + while i < len(frameline._keys): + s = frameline._keys[i] + if s.right_tween is False: + if self.last_frame == s.idx: + found = s.idx + break + else: + pass + i = i + 1 + continue + + if self.last_frame >= s.idx and self.last_frame <= frameline._keys[i+1].idx: + found = s.idx + break + else: + pass + i = i + 2 + pass + pass + if found == -1: return + self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text()) + self.last_line.update() + self.update() + + def addTweenTypeSelector(self,hbox): + tweenbox = gtk.HBox() + label = gtk.Label('Tween Type') + tweenbox.pack_start(label) + + self.tweenTypeSelector = gtk.combo_box_new_text() + self.tweenTypeSelector.append_text('normal') + self.tweenTypeSelector.append_text('relocate') + self.tweenTypeSelector.append_text('scale') + self.tweenTypeSelector.set_active(0) + tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False) + hbox.pack_start(tweenbox,expand=False,fill=False) + self.tweenTypeSelector.connect('changed', self.onTweenTypeChange) def onQuit(self, event): self.OK = False
--- a/pyink/frameline.py Thu Dec 09 00:33:41 2010 +0800 +++ b/pyink/frameline.py Thu Dec 09 07:48:46 2010 +0800 @@ -116,7 +116,7 @@ _key_mark_color = 0x000000 # color of marks for key frames. _key_mark_sz = 4 # width and height of a key frame mark _tween_color = 0x808080 # color of tween line - _tween_bgcolors = [0x80ff80, 0xff8080] # bg colors of tween frames + _tween_bgcolors = [0x80ff80, 0xff8080,0xffff80] # bg colors of tween frames # Colors for normal frames _normal_bgcolors = [0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xcccccc] _normal_border = 0xaaaaaa # border color of normal frames. @@ -124,7 +124,8 @@ _hover_border_color = 0xa0a0a0 # border when the pointer over a frame # tween types _tween_type_none=0 - _tween_type_shape=3 + _tween_type_move=1 + _tween_type_shape=2 FRAME_BUT_PRESS = 'frame-button-press' @@ -464,6 +465,24 @@ pass pass pass + def set_tween_type(self,frame_idx,typ): + found=False + for i in range(0,len(self._keys)): + if self._keys[i].idx == frame_idx: + idx = i + found = True + break + if not found: return + key = self._keys[idx] + if typ == 'normal': + type = self._tween_type_none + elif typ == 'relocate': + type = self._tween_type_move + elif typ == 'scale': + type = self._tween_type_shape + if key.left_tween is False and key.right_tween is True: + key.right_tween_type = type + ## \brief Show a mark for the pointer for a frame. # @@ -573,7 +592,7 @@ ## Tween the key frame specified by an index and the key frame at right. # # \see http://www.entheosweb.com/Flash/shape_tween.asp - def tween(self, idx, _type=0): + def tween(self, idx, _type='normal'): key_indic = [key.idx for key in self._keys] pos = key_indic.index(idx) key = self._keys[pos] @@ -585,8 +604,25 @@ key.right_tween = True right_key.left_tween = True - key.right_tween_type = _type + if _type == 'normal': + key.right_tween_type = self._tween_type_none + elif _type == 'relocate': + key.right_tween_type = self._tween_type_move + elif _type == 'scale': + key.right_tween_type = self._tween_type_shape pass + def get_tween_type(self,idx): + for i in range(0,len(self._keys)): + key = self._keys[i] + if key.left_tween is True: continue + if key.idx == idx: + if key.right_tween_type == self._tween_type_none: + return 'normal' + elif key.right_tween_type == self._tween_type_move: + return 'relocate' + elif key.right_tween_type == self._tween_type_shape: + return 'scale' + ## Set active frame # @@ -626,11 +662,18 @@ ss.setAttribute("start", str(key.idx+1),True) ss.setAttribute("ref",key.ref.attribute("id"),True) ss.setAttribute("end", str(self._keys[i+1].idx+1),True) + if self._keys[i].right_tween_type == self._tween_type_none: + ss.setAttribute("type", "normal", True) + elif self._keys[i].right_tween_type == self._tween_type_move: + ss.setAttribute("type", "relocate", True) + elif self._keys[i].right_tween_type == self._tween_type_scale: + ss.setAttribute("type", "scale", True) else: ss = rdoc.createElement("ns0:scene") node.appendChild(ss) ss.setAttribute("start", str(key.idx+1),True) ss.setAttribute("ref",key.ref.attribute("id"),True) + ss.setAttribute("type", "normal", True) ## \brief Start future drawing actions
--- a/pyink/mbtest.svg Thu Dec 09 00:33:41 2010 +0800 +++ b/pyink/mbtest.svg Thu Dec 09 07:48:46 2010 +0800 @@ -15,7 +15,7 @@ height="480px" id="svg2383" sodipodi:version="0.32" - inkscape:version="0.48+devel r9764 custom" + inkscape:version="0.48+devel r9773 custom" sodipodi:docname="mbtest.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.1"> @@ -27,13 +27,13 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="1.6029106" - inkscape:cx="69.206233" + inkscape:cx="238.58561" inkscape:cy="290.40921" inkscape:current-layer="layer2" inkscape:document-units="px" showgrid="false" inkscape:window-width="1400" - inkscape:window-height="974" + inkscape:window-height="973" inkscape:window-x="271" inkscape:window-y="25" inkscape:window-maximized="0" /> @@ -180,6 +180,45 @@ y1="28.009714" x2="104.68548" y2="28.009714" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3211-0-5-5" + id="linearGradient3316-4-8-2" + gradientUnits="userSpaceOnUse" + x1="31.940987" + y1="28.009714" + x2="104.68548" + y2="28.009714" /> + <linearGradient + inkscape:collect="always" + id="linearGradient3211-0-5-5"> + <stop + style="stop-color:#001dff;stop-opacity:1;" + offset="0" + id="stop3213-3-8-8" /> + <stop + style="stop-color:#001dff;stop-opacity:0;" + offset="1" + id="stop3215-9-4-6" /> + </linearGradient> + <filter + color-interpolation-filters="sRGB" + inkscape:collect="always" + id="filter3295-1-3-2"> + <feGaussianBlur + inkscape:collect="always" + stdDeviation="0.67110109" + id="feGaussianBlur3297-9-7-8" /> + </filter> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3211-0-5-5" + id="linearGradient3909" + gradientUnits="userSpaceOnUse" + x1="31.940987" + y1="28.009714" + x2="104.68548" + y2="28.009714" /> </defs> <metadata id="metadata2388"> @@ -194,21 +233,30 @@ <ns0:scenes> <ns0:scene start="1" - ref="g3189" - end="15" /> - <ns0:scene - start="1" - ref="s4427" /> + ref="s4427" + type="normal" /> <ns0:scene start="2" - ref="s4159" /> + ref="s4159" + type="normal" /> <ns0:scene start="5" ref="s9524" - end="10" /> + end="10" + type="normal" /> <ns0:scene start="15" - ref="s6546" /> + ref="s6546" + type="normal" /> + <ns0:scene + start="1" + ref="g3303" + end="15" + type="relocate" /> + <ns0:scene + start="16" + ref="Backgrounds4326" + type="normal" /> </ns0:scenes> </metadata> <g @@ -217,58 +265,58 @@ inkscape:label="Background" style="display:inline"> <g - id="g3189" - style=""> - <rect - style="fill:#00ffff;fill-opacity:1;stroke:#000000;stroke-opacity:1;display:inline" - id="rect2437" - width="641.95721" - height="481.62387" - x="0.93578684" - y="-10.98185" /> + style="display:none" + transform="translate(-15.128732,2.0275737)" + id="g3303" + inkscape:label="action1"> + <g + id="g3189"> + <rect + style="fill:#00ffff;fill-opacity:1;stroke:#000000;stroke-opacity:1;display:inline" + id="rect2437" + width="641.95721" + height="481.62387" + x="0.93578684" + y="-10.98185" /> + <rect + style="fill:#ffcc1d;fill-opacity:1;stroke:none" + id="rect3698" + width="624.48901" + height="46.789886" + x="6.8625164" + y="5.8625031" + rx="10" + ry="10" /> + </g> <rect - style="fill:#ffcc1d;fill-opacity:1;stroke:none" - id="rect3698" - width="624.48901" - height="46.789886" - x="6.8625164" - y="5.8625031" - rx="10" - ry="10" /> - <g - style="display:inline" - transform="translate(-11.385541,2.6514388)" - id="g3303"> - <rect - y="15.22048" - x="32.440987" - height="25.57847" - width="71.744492" - id="rect2439" - style="fill:url(#linearGradient3237);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3)" /> - <text - id="text3299" + y="15.22048" + x="32.440987" + height="25.57847" + width="71.744492" + id="rect2439" + style="fill:url(#linearGradient3237);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3)" /> + <text + id="text3299" + y="33.312569" + x="39.927368" + style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" + xml:space="preserve"><tspan + style="font-size:16px" y="33.312569" x="39.927368" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan - style="font-size:16px" - y="33.312569" - x="39.927368" - id="tspan3301" - sodipodi:role="line">Action</tspan></text> - </g> + id="tspan3301" + sodipodi:role="line">Action</tspan></text> <g style="display:inline" id="g3308" - transform="translate(76.891374,2.9633707)"> + transform="translate(75.331712,-0.46789912)"> <rect y="15.22048" x="32.440987" height="25.57847" width="71.744492" id="rect3310" - style="fill:url(#linearGradient3316-4-8);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3)" /> + style="fill:url(#linearGradient3316-4-8-2);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3-2)" /> <text id="text3312" y="33.312569" @@ -283,14 +331,78 @@ </g> </g> <g - id="s4393" - style="" /> + inkscape:label="action1" + id="Backgrounds4326" + transform="translate(-15.128732,2.0275737)" + style="" + inkscape:groupmode="layer"> + <g + id="g3889"> + <rect + y="-10.98185" + x="0.93578684" + height="481.62387" + width="641.95721" + id="rect3891" + style="fill:#00ffff;fill-opacity:1;stroke:#000000;stroke-opacity:1;display:inline" /> + <rect + ry="10" + rx="10" + y="5.8625031" + x="6.8625164" + height="46.789886" + width="624.48901" + id="rect3893" + style="fill:#ffcc1d;fill-opacity:1;stroke:none" /> + </g> + <rect + style="fill:url(#linearGradient3237);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3)" + id="rect3895" + width="71.744492" + height="25.57847" + x="32.440987" + y="15.22048" /> + <text + xml:space="preserve" + style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" + x="39.927368" + y="33.312569" + id="text3897"><tspan + sodipodi:role="line" + id="tspan3899" + x="39.927368" + y="33.312569" + style="font-size:16px">Action</tspan></text> + <g + transform="translate(170.78307,-0.46789912)" + id="g3901" + style="display:inline"> + <rect + style="fill:url(#linearGradient3909);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3-2)" + id="rect3903" + width="71.744492" + height="25.57847" + x="32.440987" + y="15.22048" /> + <text + xml:space="preserve" + style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" + x="39.927368" + y="33.312569" + id="text3905"><tspan + sodipodi:role="line" + id="tspan3907" + x="39.927368" + y="33.312569" + style="font-size:16px">Select</tspan></text> + </g> + </g> </g> <g inkscape:groupmode="layer" id="layer3" inkscape:label="Buton" - style="display:inline"> + style="display:none"> <g id="s4427" style="display:none" /> @@ -362,7 +474,6 @@ y="0" width="100" height="100" - style="fill:#ff00" id="rect3116" /> </g> </g> @@ -370,5 +481,5 @@ id="layer1" inkscape:label="Layer 1" inkscape:groupmode="layer" - style="display:inline" /> + style="display:none" /> </svg>