5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/com/adobe/utils/macro/UnaryExpression.as:
--------------------------------------------------------------------------------
1 | package com.adobe.utils.macro
2 | {
3 | internal class UnaryExpression extends Expression
4 | {
5 | public function UnaryExpression() {}
6 |
7 | public var right:Expression;
8 | override public function print( depth:int ):void {
9 | if ( AGALPreAssembler.TRACE_VM ) {
10 | trace( spaces( depth ) + "not" );
11 | }
12 | right.print( depth+1 );
13 | }
14 | override public function exec( vm:VM ):void {
15 | right.exec( vm );
16 |
17 | var varRight:Number = vm.stack.pop();
18 | var value:Number = (varRight == 0) ? 1 : 0;
19 |
20 | if ( AGALPreAssembler.TRACE_VM ) {
21 | trace( "::NotExpression push " + value );
22 | }
23 | if ( isNaN( varRight ) ) throw new Error( "UnaryExpression NaN" );
24 | vm.stack.push( value );
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/leelib/util/flvEncoder/ByteableByteArray.as:
--------------------------------------------------------------------------------
1 | package leelib.util.flvEncoder
2 | {
3 | import flash.utils.ByteArray;
4 |
5 | public class ByteableByteArray extends ByteArray implements IByteable
6 | {
7 | public function ByteableByteArray()
8 | {
9 | super();
10 | }
11 |
12 | public function get canPosition():Boolean
13 | {
14 | return true;
15 | }
16 |
17 | public function get pos():Number
18 | {
19 | return this.position;
20 | }
21 | public function set pos($pos:Number):void
22 | {
23 | this.position = uint($pos);
24 | }
25 |
26 | public function get len():Number
27 | {
28 | return this.length;
29 | }
30 | public function set len($len:Number):void
31 | {
32 | this.length = uint($len);
33 | }
34 |
35 | public function kill():void
36 | {
37 | this.length = 0;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/filters/fisheye.pbk:
--------------------------------------------------------------------------------
1 |
2 |
3 | kernel Fisheye
4 | < vendor : "MIT Media Laboratory";
5 | namespace : "filters";
6 | version : 1;
7 | description : "Scratch Fisheye";
8 | >
9 | {
10 | parameter float scaledPower
11 | <
12 | minValue:float(0);
13 | maxValue:float(10);
14 | defaultValue:float(1);
15 | >;
16 | parameter float2 center
17 | <
18 | minValue:float2(0, 0);
19 | maxValue:float2(1000, 1000);
20 | defaultValue:float2(100, 100);
21 | >;
22 |
23 | input image4 src;
24 | output float4 dst;
25 |
26 | void evaluatePixel() {
27 | float2 p = outCoord();
28 | float2 vec = (p - center) / center;
29 | float r = pow(length(vec), scaledPower);
30 | float angle = atan(vec[1], vec[0]);
31 |
32 | p = center + (r * float2(cos(angle), sin(angle)) * center);
33 | if (r > 1.0) p = outCoord();
34 | dst = sample(src, p);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/leelib/util/flvEncoder/IByteable.as:
--------------------------------------------------------------------------------
1 | package leelib.util.flvEncoder
2 | {
3 | import flash.utils.IDataInput;
4 | import flash.utils.IDataOutput;
5 |
6 | /**
7 | * IBytes allows FlvEncoder to do byte operations on either a ByteArray or a FileStream instance,
8 | * without explicitly typing to either.
9 | *
10 | * But must be used with an instance of "ByteArrayWrapper" or "FileStreamWrapper" rather than
11 | * ByteArray or FileStream directly.
12 | *
13 | * "position" has a different signature in ByteArray versus FileStream (uint versus Number),
14 | * so it gets wrapped with the getter/setter "pos"
15 | *
16 | * "length" also needs to values > 2^32 so same treatment applies
17 | */
18 | public interface IByteable extends IDataInput, IDataOutput
19 | {
20 | function get pos():Number;
21 | function set pos($n:Number):void;
22 |
23 | function get len():Number;
24 |
25 | function kill():void;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "type": "swf",
9 | "request": "launch",
10 | "name": "Launch SWF built by IDE",
11 | "program": "${workspaceFolder}/build/ide/Scratch.swf"
12 | },
13 | {
14 | "type": "swf",
15 | "request": "launch",
16 | "name": "Launch Flash 11.6 SWF built by Gradle",
17 | "program": "${workspaceFolder}/build/11.6/Scratch.swf"
18 | },
19 | {
20 | "type": "swf",
21 | "request": "launch",
22 | "name": "Launch Flash 10.2 SWF built by Gradle",
23 | "program": "${workspaceFolder}/build/10.2/ScratchFor10.2.swf"
24 | },
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/src/com/adobe/utils/macro/AGALVar.as:
--------------------------------------------------------------------------------
1 | package com.adobe.utils.macro
2 | {
3 | /**
4 | * Class to record information about all the aliases in an AGAL
5 | * shader. Typically a program is interested in making sure all
6 | * the needed constants are set in the constant pool. If isConstant()
7 | * return true, then the x,y,z,w members contain the values required
8 | * for the shader to run correctly.
9 | */
10 | public class AGALVar
11 | {
12 | public var name:String; // transform
13 | public var target:String; // "vc3", "va2.x"
14 | public var x:Number = Number.NaN;
15 | public var y:Number = Number.NaN;
16 | public var z:Number = Number.NaN;
17 | public var w:Number = Number.NaN;
18 |
19 | public function isConstant():Boolean { return !isNaN( x ); }
20 | public function toString():String {
21 | if ( this.isConstant() )
22 | return "alias " + target + ", " + name + "( " + x + ", " + y + ", " + z + ", " + w + " )";
23 | else
24 | return "alias " + target + ", " + name;
25 | }
26 |
27 | }
28 | }
--------------------------------------------------------------------------------
/src/util/DragClient.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package util {
21 | import flash.events.MouseEvent;
22 |
23 | public interface DragClient {
24 | function dragBegin(evt:MouseEvent):void;
25 | function dragMove(evt:MouseEvent):void;
26 | function dragEnd(evt:MouseEvent):void;
27 | }}
28 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/PathDrawContext.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.objs
21 | {
22 | import flash.geom.Point;
23 |
24 | public class PathDrawContext
25 | {
26 | public var cmds:Array;
27 | public var acurve:Boolean;
28 | public var lastcxy:Point;
29 | public var adjust:Boolean;
30 | function PathDrawContext() {
31 | cmds = new Array();
32 | acurve = false;
33 | adjust = false;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/adobe/utils/macro/VM.as:
--------------------------------------------------------------------------------
1 | package com.adobe.utils.macro
2 | {
3 | import flash.utils.Dictionary;
4 |
5 | public class VM
6 | {
7 | public var vars:flash.utils.Dictionary = new flash.utils.Dictionary();
8 | public var stack:Array = new Array();
9 |
10 | public function pushIf():void
11 | {
12 | m_ifIsTrue.push( false );
13 | m_ifWasTrue.push( false );
14 | }
15 |
16 | public function popEndif():void
17 | {
18 | m_ifIsTrue.pop();
19 | m_ifWasTrue.pop();
20 | }
21 |
22 | public function setIf( value:Number ):void
23 | {
24 | m_ifIsTrue[ m_ifIsTrue.length-1 ] = (value != 0);
25 | m_ifWasTrue[ m_ifIsTrue.length-1 ] = (value != 0);
26 | }
27 |
28 | public function ifWasTrue():Boolean
29 | {
30 | return m_ifWasTrue[ m_ifIsTrue.length-1 ];
31 | }
32 |
33 | public function ifIsTrue():Boolean
34 | {
35 | if ( m_ifIsTrue.length == 0 )
36 | return true;
37 |
38 | // All ifs on the stack must be true for current true.
39 | for( var i:int=0; i = new Vector.();
48 | private var m_ifWasTrue:Vector. = new Vector.();
49 | }
50 | }
--------------------------------------------------------------------------------
/src/scratch/ReadyLabel.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package scratch {
21 | public class ReadyLabel {
22 | //indicates that recording is not happening or preparing to happening
23 | public static const NOT_READY:int = -1;
24 |
25 | //indicates that countdown is happening
26 | public static const COUNTDOWN:int = 0;
27 |
28 | //indicates that recording is ready to happen or happening
29 | public static const READY:int = 1;
30 | }
31 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: groovy
2 | cache:
3 | directories:
4 | - $HOME/.gradle/caches/
5 | - $HOME/.gradle/wrapper/dists/
6 | before_install:
7 | - mkdir -p /home/travis/.gradle/gradleFx/sdks/77b6510675e9bf47142422c374af153591fe4734/in/ && wget http://sourceforge.net/projects/osmf.adobe/files/OSMF%201.0%20%28final%20source%2C%20ASDocs%2C%20PDF%20guides%2C%20and%20release%20notes%29/OSMF_1.0.zip/download -O /home/travis/.gradle/gradleFx/sdks/77b6510675e9bf47142422c374af153591fe4734/in/OSMF_1.0.zip
8 | install:
9 | - ./gradlew build -Ptarget=11.6
10 | - ./gradlew build -Ptarget=10.2
11 | script:
12 | - ./gradlew check -Ptarget=11.6
13 | - ./gradlew check -Ptarget=10.2
14 | notifications:
15 | slack:
16 | secure: TFnMix3WLFecQLMgmSIsUrnZUV7s5U7mJlzkfLrGU02u0uztjLcJr9qekg65I0wFtqGuMGAOfPAZo4hf0l5djzJTSUobLdlTpEunIEWd53IUZlljKCJQsVT8hfJtbjpIXMraLRLyTzDkXcRO3v2xthU30vsSI75sxQYufBx5/sU=
17 | format: text
18 | hipchat:
19 | rooms:
20 | secure: RP6i3+3IPgwkCj78UAjISXCv67RIU8u84OOAAcLT64pRoJ2aZvNo4ITlU28AVnRojO8V9JoXo/UBiTSTnNZsiL6LIqh1BScIE8lfIHLZ4pEqrvrjSmx56jT9jf3kttjjp00qaQ2QlpV7v9Dyg4GOvLRfOYTOhTSQTKgfWN+/dJA=
21 | template:
22 | - '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}
23 | (Details/Change view)'
24 | format: html
25 |
--------------------------------------------------------------------------------
/src/render3d/StageUIContainer.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package render3d {
21 | import flash.display.Sprite;
22 |
23 | public class StageUIContainer extends Sprite
24 | {
25 | public function step(runtime:Object):void {
26 | for (var i:int = 0; i < numChildren; i++) {
27 | var c:Object = getChildAt(i);
28 | if (c.visible == true && c.hasOwnProperty('step')) {
29 | if ('listName' in c) c.step();
30 | else c.step(runtime);
31 | }
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/util/StringUtils.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 | package util {
20 | import flash.utils.Dictionary;
21 |
22 | public class StringUtils {
23 | // format('My {animal} is named {name}.', {animal:'goat',name:'Eric'}) => 'My goat is named Eric.'
24 | // Tokens not contained in the dictionary will not be modified.
25 | public static function substitute(s:String, context:Dictionary):String {
26 | for (var token:String in context) {
27 | s = s.replace('{'+token+'}', context[token]);
28 | }
29 | return s;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/ISVGEditable.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.objs
21 | {
22 | import svgutils.SVGElement;
23 | public interface ISVGEditable
24 | {
25 | // Returns the SVGElement for this object
26 | function getElement():SVGElement;
27 |
28 | // Redraws the element
29 | function redraw(forHitTest:Boolean = false):void;
30 |
31 | // Returns a copy of the current element
32 | function clone():ISVGEditable;
33 |
34 | // Fixes up the transform and element specific position data
35 | //function normalize():void;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/filters/whirl.pbk:
--------------------------------------------------------------------------------
1 |
2 |
3 | kernel Whirl
4 | < vendor : "MIT Media Laboratory";
5 | namespace : "filters";
6 | version : 1;
7 | description : "Scratch Whirl";
8 | >
9 | {
10 | parameter float whirlRadians
11 | <
12 | minValue: float(-100.0);
13 | maxValue: float(100.0);
14 | defaultValue: float(0);
15 | >;
16 | parameter float2 center
17 | <
18 | minValue:float2(0, 0);
19 | maxValue:float2(1000, 1000);
20 | defaultValue:float2(100, 100);
21 | >;
22 | parameter float radius
23 | <
24 | minValue: float(0);
25 | maxValue: float(500);
26 | defaultValue: float(100);
27 | >;
28 | parameter float2 scale
29 | <
30 | minValue:float2(0, 0);
31 | maxValue:float2(10, 10);
32 | defaultValue:float2(1, 1);
33 | >;
34 |
35 | input image4 src;
36 | output float4 dst;
37 |
38 | void evaluatePixel() {
39 | float2 vec = scale * (outCoord() - center);
40 | float d = length(vec);
41 | float factor = 1.0 - (d / radius);
42 | float a = whirlRadians * (factor * factor);
43 | // matrix to rotate the vector from the center
44 | float sinAngle = sin(a);
45 | float cosAngle = cos(a);
46 | float2x2 rotationMat = float2x2(
47 | cosAngle, -sinAngle,
48 | sinAngle, cosAngle
49 | );
50 | // rotate, unscale, and compute source point
51 | float2 p = ((rotationMat * vec) / scale) + center;
52 | dst = sampleNearest(src, p);
53 | if (d > radius) dst = sampleNearest(src, outCoord());
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/assets/cursors/videoCursor.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
--------------------------------------------------------------------------------
/src/render3d/SpriteStamp.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package render3d {
21 | import flash.display.BitmapData;
22 |
23 | public class SpriteStamp extends BitmapData {
24 | private var fx:Object;
25 | public function SpriteStamp(width:int, height:int, fx:Object) {
26 | super(width, height, true, 0);
27 | effects = fx;
28 | }
29 |
30 | public function set effects(o:Object):void {
31 | fx = null;
32 |
33 | if(o) {
34 | fx = {};
35 | for(var prop:String in o)
36 | fx[prop] = o[prop];
37 | }
38 | }
39 |
40 | public function get effects():Object {
41 | return fx;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/interpreter/Variable.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // Variable.as
21 | // John Maloney, February 2010
22 | //
23 | // A variable is a name-value pair.
24 |
25 | package interpreter {
26 | import util.JSON;
27 |
28 | public class Variable {
29 |
30 | public var name:String;
31 | public var value:*;
32 | public var watcher:*;
33 | public var isPersistent:Boolean;
34 |
35 | public function Variable(vName:String, initialValue:*) {
36 | name = vName;
37 | value = initialValue;
38 | }
39 |
40 | public function writeJSON(json:util.JSON):void {
41 | json.writeKeyValue('name', name);
42 | json.writeKeyValue('value', value);
43 | json.writeKeyValue('isPersistent', isPersistent);
44 | }
45 |
46 | }}
47 |
--------------------------------------------------------------------------------
/src/logging/LogLevel.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2015 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package logging {
21 |
22 | public class LogLevel {
23 | // Use this for problems that should be in our control
24 | static public const ERROR:String = "err";
25 |
26 | // Use this for unexpected conditions and problems outside our control (network, user data, etc.)
27 | static public const WARNING:String = "wrn";
28 |
29 | // These events will be communicated to JS so they can be handled by web UI, sent to GA, etc.
30 | static public const TRACK:String = "trk";
31 |
32 | // Use this to report status information
33 | static public const INFO:String = "inf";
34 |
35 | // Use this to report information useful for debugging
36 | static public const DEBUG:String = "dbg";
37 |
38 | static public const LEVEL:Array = [
39 | ERROR, WARNING, TRACK, INFO, DEBUG
40 | ];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/util/DebugUtils.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package util {
21 |
22 | import flash.utils.getQualifiedClassName;
23 | import flash.display.DisplayObjectContainer;
24 | import flash.display.DisplayObject;
25 |
26 | public class DebugUtils {
27 |
28 | public static function printTree(top:DisplayObject):String {
29 | var result:String = '';
30 | printSubtree(top, 0, result);
31 | return result;
32 | }
33 |
34 | private static function printSubtree(t:DisplayObject, indent:int, out:String):void {
35 | var tabs:String = '';
36 | for (var i:int = 0; i < indent; i++) tabs += '\t';
37 | out += tabs + getQualifiedClassName(t) + '\n';
38 | var container:DisplayObjectContainer = t as DisplayObjectContainer;
39 | if (container == null) return;
40 | for (i = 0; i < container.numChildren; i++) {
41 | printSubtree(container.getChildAt(i), indent + 1, out);
42 | }
43 | }
44 |
45 | }}
46 |
--------------------------------------------------------------------------------
/src/util/IServer.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // IServer.as
21 | // Shane Clements, March 2014
22 | //
23 | // Interface to the Scratch website API's
24 | //
25 | // Note: All operations call the callback function with the result
26 | // if the operation succeeded or null if it failed.
27 |
28 | package util {
29 | import flash.net.URLLoader;
30 |
31 | public interface IServer {
32 | // -----------------------------
33 | // Asset API
34 | //------------------------------
35 | function getAsset(md5:String, callback:Function):URLLoader;
36 | function getMediaLibrary(type:String, callback:Function):URLLoader;
37 | function getThumbnail(md5:String, w:int, h:int, callback:Function):URLLoader;
38 |
39 | // -----------------------------
40 | // Translation Support
41 | //------------------------------
42 | function getLanguageList(callback:Function):void;
43 | function getPOFile(lang:String, callback:Function):void;
44 | function getSelectedLang(callback:Function):void;
45 | function setSelectedLang(lang:String):void;
46 | }}
47 |
--------------------------------------------------------------------------------
/src/uiwidgets/VariableTextField.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 | package uiwidgets {
20 | import flash.text.TextField;
21 | import flash.text.TextFormat;
22 | import flash.utils.Dictionary;
23 |
24 | import util.StringUtils;
25 |
26 | public class VariableTextField extends TextField {
27 | private var originalText:String;
28 |
29 | override public function set text(value:String):void {
30 | throw Error('Call setText() instead');
31 | }
32 |
33 | public function setText(t: String, context:Dictionary = null):void {
34 | originalText = t;
35 | applyContext(context);
36 | }
37 |
38 | // Re-substitutes values from this new context into the original text.
39 | // This context must be a complete context, not just the fields that have changed.
40 | public function applyContext(context: Dictionary):void {
41 | // Assume that the whole text field uses the same format since there's no guarantee how indices will map.
42 | var oldFormat:TextFormat = this.getTextFormat();
43 | super.text = context ? StringUtils.substitute(originalText, context) : originalText;
44 | setTextFormat(oldFormat);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/uiwidgets/IndicatorLight.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // IndicatorLight.as
21 | // John Maloney, September 2013
22 | //
23 | // A simple indicator light with a color and a tooltip. Used to show extension state.
24 |
25 | package uiwidgets {
26 | import flash.display.*;
27 | import uiwidgets.SimpleTooltips;
28 |
29 | public class IndicatorLight extends Sprite {
30 |
31 | public var target:*;
32 |
33 | private var color:int;
34 | private var msg:String = '';
35 |
36 | public function IndicatorLight(target:* = null) {
37 | this.target = target;
38 | redraw();
39 | }
40 |
41 | public function setColorAndMsg(color:int, msg:String):void {
42 | if ((color == this.color) && (msg == this.msg)) return; // no change
43 | this.color = color;
44 | this.msg = msg;
45 | SimpleTooltips.add(this, {text: msg, direction: 'bottom'});
46 | redraw();
47 | }
48 |
49 | private function redraw():void {
50 | const borderColor:int = 0x505050;
51 | var g:Graphics = graphics;
52 | g.clear();
53 | g.lineStyle(1, borderColor);
54 | g.beginFill(color);
55 | g.drawCircle(7, 7, 6);
56 | g.endFill();
57 | }
58 |
59 | }}
60 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/SVGBitmap.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.objs
21 | {
22 | import flash.display.Bitmap;
23 | import flash.display.BitmapData;
24 | import flash.display.DisplayObject;
25 | import flash.events.Event;
26 |
27 | import svgeditor.objs.ISVGEditable;
28 |
29 | import svgutils.SVGDisplayRender;
30 | import svgutils.SVGElement;
31 |
32 | public class SVGBitmap extends Bitmap implements ISVGEditable
33 | {
34 | private var element:SVGElement;
35 |
36 | public function SVGBitmap(elem:SVGElement, bitmapData:BitmapData=null)
37 | {
38 | element = elem;
39 | super(bitmapData);
40 | }
41 |
42 | public function getElement():SVGElement {
43 | element.transform = transform.matrix;
44 | return element;
45 | }
46 |
47 | public function redraw(forHitTest:Boolean = false):void {
48 | element.renderImageOn(this);
49 | }
50 |
51 | public function clone():ISVGEditable {
52 | var copy:ISVGEditable = new SVGBitmap(element.clone(), bitmapData);
53 | (copy as DisplayObject).transform.matrix = transform.matrix.clone();
54 | copy.redraw();
55 | return copy;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/FlasccConsole.as:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Mallory on 11/30/15.
3 | */
4 | package svgeditor.objs {
5 | import flash.display.Sprite;
6 | import flash.text.TextField;
7 | import flash.events.Event;
8 |
9 | import grabcut.CModule;
10 | import grabcut.vfs.ISpecialFile;
11 |
12 | public class FlasccConsole extends Sprite implements ISpecialFile {
13 |
14 | private var tf:TextField;
15 |
16 | public function SampleApplication():void {
17 | addEventListener(Event.ADDED_TO_STAGE, initCode);
18 | }
19 |
20 | private function initCode(e:Event):void {
21 | tf = new TextField();
22 | addChild(tf);
23 | tf.appendText("SWC Output:\n");
24 |
25 |
26 |
27 | // call a C++ function that calls printf
28 | var func:int = CModule.getPublicSymbol("test")
29 | var result:int = CModule.callI(func, new Vector.());
30 | }
31 |
32 | /**
33 | * The PlayerKernel implementation will use this function to handle
34 | * C IO write requests to the file "/dev/tty" (e.g. output from
35 | * printf will pass through this function). See the ISpecialFile
36 | * documentation for more information about the arguments and return value.
37 | */
38 | public function write(fd:int, bufPtr:int, nbyte:int, errnoPtr:int):int
39 | {
40 | var str:String = CModule.readString(bufPtr, nbyte);
41 | tf.appendText(str);
42 | trace(str);
43 | return nbyte;
44 | }
45 |
46 | /** See ISpecialFile */
47 | public function read(fd:int, bufPtr:int, nbyte:int, errnoPtr:int):int { return 0; }
48 | public function fcntl(fd:int, com:int, data:int, errnoPtr:int):int { return 0; }
49 | public function ioctl(fd:int, com:int, data:int, errnoPtr:int):int { return 0; }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/villekoskela/utils/SortableSize.as:
--------------------------------------------------------------------------------
1 | /**
2 | * Sortable size
3 | *
4 | * Copyright 2012 Ville Koskela. All rights reserved.
5 | *
6 | * Email: ville@villekoskela.org
7 | * Blog: http://villekoskela.org
8 | * Twitter: @villekoskelaorg
9 | *
10 | * You may redistribute, use and/or modify this source code freely
11 | * but this copyright statement must not be removed from the source files.
12 | *
13 | * The package structure of the source code must remain unchanged.
14 | * Mentioning the author in the binary distributions is highly appreciated.
15 | *
16 | * If you use this utility it would be nice to hear about it so feel free to drop
17 | * an email.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
29 | *
30 | */
31 | package org.villekoskela.utils
32 | {
33 | /**
34 | * Class used for sorting the inserted rectangles based on the dimensions
35 | */
36 | public class SortableSize
37 | {
38 | public var width:int;
39 | public var height:int;
40 | public var id:int;
41 |
42 | public function SortableSize(width:int, height:int, id:int)
43 | {
44 | this.width = width;
45 | this.height = height;
46 | this.id = id;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/util/DrawPath.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package util {
21 | import flash.display.Graphics;
22 |
23 | public class DrawPath {
24 |
25 | static public function drawPath(path:Array, g:Graphics):void {
26 | var startx:Number = 0, starty:Number = 0;
27 | var pathx:Number = 0, pathy:Number = 0;
28 | for each (var item:Array in path) {
29 | switch (item[0].toLowerCase()) {
30 | case 'm':
31 | startx = item[1];
32 | starty = item[2];
33 | g.moveTo(pathx = startx, pathy = starty);
34 | break;
35 | case 'l': g.lineTo(pathx += item[1], pathy += item[2]); break;
36 | case 'h': g.lineTo(pathx += item[1], pathy); break;
37 | case 'v': g.lineTo(pathx, pathy += item[1]); break;
38 | case 'c':
39 | var cx:Number = pathx + item[1];
40 | var cy:Number = pathy + item[2];
41 | var px:Number = pathx + item[3];
42 | var py:Number = pathy + item[4];
43 | g.curveTo(cx, cy, px, py);
44 | pathx += item[3];
45 | pathy += item[4];
46 | break;
47 | case 'z':
48 | g.lineTo(pathx = startx, pathy = starty);
49 | break;
50 | default:
51 | trace('DrawPath command not implemented' , item[0]);
52 | }
53 | }
54 | }
55 |
56 | }}
57 |
--------------------------------------------------------------------------------
/src/util/CachedTimer.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2018 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package util {
21 | import flash.utils.getTimer;
22 |
23 | /**
24 | * Calling getTimer() is much more expensive in Flash 30 than in previous versions.
25 | * This class is meant to reduce the number of actual calls to getTimer() with minimal changes to existing code.
26 | */
27 | public class CachedTimer {
28 | private static var dirty:Boolean = true;
29 | private static var cachedTimer:int;
30 |
31 | /**
32 | * @return the last cached value of getTimer(). May return a fresh value if the cache has been invalidated.
33 | */
34 | public static function getCachedTimer():int {
35 | return dirty ? getFreshTimer() : cachedTimer;
36 | }
37 |
38 | /**
39 | * Clear the timer cache, forcing getCachedTimer() to get a fresh value next time. Use this at the top of a frame.
40 | */
41 | public static function clearCachedTimer():void {
42 | dirty = true;
43 | }
44 |
45 | /**
46 | * @return and cache the current value of getTimer().
47 | * Use this if you need an accurate timer value in the middle of a frame.
48 | */
49 | public static function getFreshTimer():int {
50 | cachedTimer = getTimer();
51 | dirty = false;
52 | return cachedTimer;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/filters/hsv.pbk:
--------------------------------------------------------------------------------
1 |
2 |
3 | kernel HSV
4 | < vendor : "MIT Media Laboratory";
5 | namespace : "filters";
6 | version : 1;
7 | description : "Scratch HSV";
8 | >
9 | {
10 | parameter float hueShift
11 | <
12 | minValue: float(-500.0);
13 | maxValue: float(500.0);
14 | defaultValue: float(0);
15 | >;
16 | parameter float brightnessShift
17 | <
18 | minValue: float(-100.0);
19 | maxValue: float(100.0);
20 | defaultValue: float(0);
21 | >;
22 |
23 | input image4 src;
24 | output float4 dst;
25 |
26 | void evaluatePixel() {
27 | dst = sampleNearest(src, outCoord());
28 | float r = dst.r;
29 | float g = dst.g;
30 | float b = dst.b;
31 | // compute h, s, v
32 | float h, s;
33 | float v = max(r, max(g, b));
34 | float span = v - min(r, min(g, b));
35 | if (span == 0.0) {
36 | h = s = 0.0; // grayscale
37 | } else {
38 | if (r == v) h = 60.0 * ((g - b) / span);
39 | else if (g == v) h = 120.0 + (60.0 * ((b - r) / span));
40 | else if (b == v) h = 240.0 + (60.0 * ((r - g) / span));
41 | s = span / v;
42 | }
43 |
44 | if (hueShift != 0.0) {
45 | // this code forces grayscale values to be slightly saturated
46 | // so that some slight change of hue will be visible
47 | if (v < 0.11) { v = 0.11; s = 1.0; } // force black to dark gray, fully-saturated
48 | if (s < 0.09) s = 0.09; // make saturation at least 0.09
49 | if ((v == 0.11) || (s == 0.09)) h = 0.0; // use same tint for all grays
50 | }
51 |
52 | // apply h, s, v shifts
53 | h = mod(h + hueShift, 360.0);
54 | if (h < 0.0) h += 360.0;
55 | s = max(0.0, min(s, 1.0));
56 | v = max(0.0, min(v + (brightnessShift / 100.0), 1.0));
57 |
58 | // convert hsv to rgb and save pixel
59 | int i = int(floor(h / 60.0));
60 | float f = (h / 60.0) - float(i);
61 | float p = v * (1.0 - s);
62 | float q = v * (1.0 - (s * f));
63 | float t = v * (1.0 - (s * (1.0 - f)));
64 |
65 | if ((i == 0) || (i == 6)) dst.rgb = float3(v, t, p);
66 | else if (i == 1) dst.rgb = float3(q, v, p);
67 | else if (i == 2) dst.rgb = float3(p, v, t);
68 | else if (i == 3) dst.rgb = float3(p, q, v);
69 | else if (i == 4) dst.rgb = float3(t, p, v);
70 | else if (i == 5) dst.rgb = float3(v, p, q);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/uiwidgets/ZoomWidget.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package uiwidgets {
21 | import flash.display.Sprite;
22 |
23 | public class ZoomWidget extends Sprite {
24 |
25 | private var scriptsPane:ScriptsPane;
26 | private var zoom:int;
27 |
28 | private var smaller:IconButton;
29 | private var normal:IconButton;
30 | private var bigger:IconButton;
31 |
32 | public function ZoomWidget(scriptsPane:ScriptsPane) {
33 | this.scriptsPane = scriptsPane;
34 | addChild(smaller = new IconButton(zoomOut, 'zoomOut'));
35 | addChild(normal = new IconButton(noZoom, 'noZoom'));
36 | addChild(bigger = new IconButton(zoomIn, 'zoomIn'));
37 | smaller.x = 0;
38 | normal.x = 24;
39 | bigger.x = 48;
40 | smaller.isMomentary = true;
41 | normal.isMomentary = true;
42 | bigger.isMomentary = true;
43 | }
44 |
45 | private function zoomOut(b:IconButton):void { changeZoomBy(-1) }
46 | private function noZoom(b:IconButton):void { zoom = 0; changeZoomBy(0) }
47 | private function zoomIn(b:IconButton):void { changeZoomBy(1) }
48 |
49 | private function changeZoomBy(delta:int):void {
50 | const scaleFactors:Array = [25, 50, 75, 100, 125, 150, 200];
51 | zoom += delta;
52 | zoom = Math.max(-3, Math.min(zoom, 3));
53 | smaller.setDisabled(zoom < -2, 0.5);
54 | bigger.setDisabled(zoom > 2, 0.5);
55 | scriptsPane.setScale(scaleFactors[3 + zoom] / 100);
56 | }
57 |
58 | }}
59 |
--------------------------------------------------------------------------------
/src/leelib/util/flvEncoder/README.TXT:
--------------------------------------------------------------------------------
1 | FlvEncoder (leelib.util.flvEncoder.*)
2 | Lee Felarca
3 | http://www.zeropointnine.com/blog
4 | 3-29-2011
5 | Package version: v0.9b
6 |
7 | Creates uncompressed FLV's with video and audio without server-side dependency.
8 |
9 | See http://www.zeropointnine.com/blog/updated-flv-encoder-alchemy for more info.
10 |
11 | FLV spec is described here: http://www.adobe.com/devnet/f4v.html
12 |
13 |
14 | Example usage:
15 |
16 | [1] ByteArrayFlvEncoder:
17 |
18 | var baFlvEncoder:ByteArrayFlvEncoder = new ByteArrayFlvEncoder(myFrameRate);
19 |
20 | baFlvEncoder.setVideoProperties(myWidth, myHeight, VideoPayloadMakerAlchemy);
21 | // (Omit the 3rd argument to NOT use the Alchemy encoding routine)
22 | baFlvEncoder.setAudioProperties(BaseFlvEncoder.SAMPLERATE_44KHZ, true, false, true);
23 |
24 | baFlvEncoder.start();
25 |
26 | baFlvEncoder.addFrame(myBitmapData, myAudioByteArray);
27 | baFlvEncoder.addFrame(myBitmapData, myAudioByteArray); // etc.
28 |
29 | baFlvEncoder.updateDurationMetadata();
30 |
31 | saveOutMyFileUsingFileReference( baFlvEncoder.byteArray );
32 |
33 | baFlvEncoder.kill(); // for garbage collection
34 |
35 | [2] FileStreamFlvEncoder (using Adobe AIR)
36 |
37 | var myFile:File = File.documentsDirectory.resolvePath("video.flv");
38 | var fsFlvEncoder:FileStreamFlvEncoder = new FileStreamFlvEncoder(myFile, myFrameRate);
39 | fsFlvEncoder.fileStream.openAsync(myFile, FileMode.UPDATE);
40 |
41 | fsFlvEncoder.setVideoProperties(myWidth, myHeight, VideoPayloadMakerAlchemy);
42 | // (Omit the 3rd argument to NOT use the Alchemy encoding routine)
43 | fsFlvEncoder.setAudioProperties(BaseFlvEncoder.SAMPLERATE_44KHZ, true, false, true);
44 |
45 | fsFlvEncoder.start();
46 |
47 | fsFlvEncoder.addFrame(myBitmapData, myAudioByteArray);
48 | fsFlvEncoder.addFrame(myBitmapData, myAudioByteArray); // etc.
49 |
50 | fsFlvEncoder.updateDurationMetadata();
51 |
52 | fsFlvEncoder.fileStream.close();
53 |
54 | fsFlvEncoder.kill();
55 |
56 | *** To use the Alchemy version, add a SWC folder reference to leelib/util/flvEncoder/alchemy
57 |
58 |
59 | Source code licensed under a Creative Commons Attribution 3.0 License.
60 | http://creativecommons.org/licenses/by/3.0/
61 | Some Rights Reserved.
62 |
--------------------------------------------------------------------------------
/src/logging/LogEntry.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2015 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package logging {
21 | import util.CachedTimer;
22 |
23 | public class LogEntry {
24 | public var timeStamp:Number;
25 | public var severity:int;
26 | public var messageKey:String;
27 | public var extraData:Object;
28 |
29 | public function LogEntry(severity:String, messageKey:String, extraData:Object = null) {
30 | setAll(severity, messageKey, extraData);
31 | }
32 |
33 | // Set all fields of this event
34 | public function setAll(severity:String, messageKey:String, extraData:Object = null):void {
35 | this.timeStamp = getCurrentTime();
36 | this.severity = LogLevel.LEVEL.indexOf(severity);
37 | this.messageKey = messageKey;
38 | this.extraData = extraData;
39 | }
40 |
41 | private static const tempDate:Date = new Date();
42 | private function makeTimeStampString():String {
43 | tempDate.time = timeStamp;
44 | return tempDate.toLocaleTimeString();
45 | }
46 |
47 | // Generate a string representing this event. Does not include extraData.
48 | public function toString():String {
49 | return [makeTimeStampString(), LogLevel.LEVEL[severity], messageKey].join(' | ');
50 | }
51 |
52 | private static const timerOffset:Number = new Date().time - CachedTimer.getFreshTimer();
53 |
54 | // Returns approximately the same value as "new Date().time" without GC impact
55 | public static function getCurrentTime():Number {
56 | return CachedTimer.getCachedTimer() + timerOffset;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/org/villekoskela/utils/IntegerRectangle.as:
--------------------------------------------------------------------------------
1 | /**
2 | * Integer rectangle
3 | *
4 | * Copyright 2012 Ville Koskela. All rights reserved.
5 | *
6 | * Email: ville@villekoskela.org
7 | * Blog: http://villekoskela.org
8 | * Twitter: @villekoskelaorg
9 | *
10 | * You may redistribute, use and/or modify this source code freely
11 | * but this copyright statement must not be removed from the source files.
12 | *
13 | * The package structure of the source code must remain unchanged.
14 | * Mentioning the author in the binary distributions is highly appreciated.
15 | *
16 | * If you use this utility it would be nice to hear about it so feel free to drop
17 | * an email.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
29 | *
30 | */
31 | package org.villekoskela.utils
32 | {
33 | /**
34 | * Class used to store rectangles values inside rectangle packer
35 | * ID parameter needed to connect rectangle with the originally inserted rectangle
36 | */
37 | public class IntegerRectangle
38 | {
39 | public var x:int;
40 | public var y:int;
41 | public var width:int;
42 | public var height:int;
43 | public var right:int;
44 | public var bottom:int;
45 | public var id:int;
46 |
47 | public function IntegerRectangle(x:int = 0, y:int = 0, width:int = 0, height:int = 0)
48 | {
49 | this.x = x;
50 | this.y = y;
51 | this.width = width;
52 | this.height = height;
53 | this.right = x + width;
54 | this.bottom = y + height;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/ui/CameraDialog.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package ui {
21 | import flash.display.*;
22 | import flash.media.*;
23 | import translation.Translator;
24 | import uiwidgets.*;
25 |
26 | public class CameraDialog extends DialogBox {
27 |
28 | private var saveFunc:Function;
29 | private var picture:Bitmap;
30 | private var video:Video;
31 |
32 | public static function strings():Array {
33 | return ['Camera', 'Save', 'Close'];
34 | }
35 |
36 | public function CameraDialog(saveFunc:Function) {
37 | super();
38 | this.saveFunc = saveFunc;
39 |
40 | addTitle(Translator.map('Camera'));
41 |
42 | var container:Sprite = new Sprite();
43 | addWidget(container);
44 |
45 | picture = new Bitmap();
46 | picture.bitmapData = new BitmapData(320, 240, true);
47 | picture.visible = false;
48 | container.addChild(picture);
49 |
50 | video = new Video(320, 240);
51 | video.smoothing = true;
52 | video.attachCamera(Camera.getCamera());
53 | container.addChild(video);
54 |
55 | var b:Button;
56 | addChild(b = new Button(Translator.map('Save'), savePicture));
57 | buttons.push(b);
58 | addChild(b = new Button(Translator.map('Close'), closeDialog));
59 | buttons.push(b);
60 | }
61 |
62 | private function savePicture():void {
63 | picture.bitmapData.draw(video);
64 | if (saveFunc != null) (saveFunc(picture.bitmapData.clone()));
65 | }
66 |
67 | public function closeDialog():void {
68 | if (video) video.attachCamera(null);
69 | if (parent) parent.removeChild(this);
70 | }
71 |
72 | }}
73 |
--------------------------------------------------------------------------------
/src/com/adobe/utils/macro/BinaryExpression.as:
--------------------------------------------------------------------------------
1 | package com.adobe.utils.macro
2 | {
3 | internal class BinaryExpression extends com.adobe.utils.macro.Expression
4 | {
5 | public var op:String;
6 | public var left:Expression;
7 | public var right:Expression;
8 | override public function print( depth:int ):void {
9 | if ( AGALPreAssembler.TRACE_VM ) {
10 | trace( spaces( depth ) + "binary op " + op );
11 | }
12 | left.print( depth+1 );
13 | right.print( depth+1 );
14 | }
15 |
16 | override public function exec( vm:VM ):void {
17 | var varLeft:Number = Number.NaN;
18 | var varRight:Number = Number.NaN;
19 |
20 | left.exec( vm );
21 | varLeft = vm.stack.pop();
22 | right.exec( vm );
23 | varRight = vm.stack.pop();
24 |
25 | if ( isNaN( varLeft ) ) throw new Error( "Left side of binary expression (" + op + ") is NaN" );
26 | if ( isNaN( varRight ) ) throw new Error( "Right side of binary expression (" + op + ") is NaN" );
27 |
28 | switch( op ) {
29 | case "*":
30 | vm.stack.push( varLeft * varRight );
31 | break;
32 | case "/":
33 | vm.stack.push( varLeft / varRight );
34 | break;
35 | case "+":
36 | vm.stack.push( varLeft + varRight );
37 | break;
38 | case "-":
39 | vm.stack.push( varLeft - varRight );
40 | break;
41 | case ">":
42 | vm.stack.push( (varLeft > varRight) ? 1 : 0 );
43 | break;
44 | case "<":
45 | vm.stack.push( (varLeft < varRight) ? 1 : 0 );
46 | break;
47 | case ">=":
48 | vm.stack.push( (varLeft >= varRight) ? 1 : 0 );
49 | break;
50 | case ">=":
51 | vm.stack.push( (varLeft <= varRight) ? 1 : 0 );
52 | break;
53 | case "==":
54 | vm.stack.push( (varLeft==varRight) ? 1 : 0 );
55 | break;
56 | case "!=":
57 | vm.stack.push( (varLeft!=varRight) ? 1 : 0 );
58 | break;
59 | case "&&":
60 | vm.stack.push( (Boolean(varLeft) && Boolean(varRight)) ? 1 : 0 );
61 | break;
62 | case "||":
63 | vm.stack.push( (Boolean(varLeft) || Boolean(varRight)) ? 1 : 0 );
64 | break;
65 |
66 | default:
67 | throw new Error( "unimplemented BinaryExpression exec" );
68 | break;
69 | }
70 | if ( AGALPreAssembler.TRACE_VM ) {
71 | trace( "::BinaryExpression op" + op + " left=" + varLeft + " right=" +varRight + " push " + vm.stack[vm.stack.length-1] );
72 | }
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/src/soundedit/SoundLevelMeter.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // SoundLevelMeter.as
21 | // John Maloney, March 2012
22 |
23 | package soundedit {
24 | import flash.display.*;
25 | import flash.text.TextFormat;
26 | import assets.Resources;
27 |
28 | public class SoundLevelMeter extends Sprite {
29 |
30 | private var w:int, h:int;
31 | private var bar:Shape;
32 | private var recentMax:Number = 0;
33 |
34 | public function SoundLevelMeter(barWidth:int, barHeight:int) {
35 | w = barWidth;
36 | h = barHeight;
37 |
38 | // frame
39 | graphics.lineStyle(1, CSS.borderColor, 1, true);
40 | graphics.drawRoundRect(0, 0, w, h, 7, 7);
41 |
42 | // meter bar
43 | addChild(bar = new Shape());
44 | }
45 |
46 | public function clear():void {
47 | recentMax = 0;
48 | setLevel(0);
49 | }
50 |
51 | public function setLevel(percent:Number):void {
52 | recentMax *= 0.85;
53 | recentMax = Math.max(percent, recentMax);
54 | drawBar(recentMax);
55 | }
56 |
57 | private function drawBar(percent:Number):void {
58 | const red:int = 0xFF0000;
59 | const yellow:int = 0xFFFF00;
60 | const green:int = 0xFF00;
61 | const r:int = 3;
62 |
63 | var g:Graphics = bar.graphics;
64 | g.clear();
65 |
66 | g.beginFill(red);
67 | var barH:int = (h - 1) * Math.min(percent, 100) / 100;
68 | g.drawRoundRect(1, h - barH, w - 1, barH, r, r);
69 |
70 | g.beginFill(yellow);
71 | barH = h * Math.min(percent, 95) / 100;
72 | g.drawRoundRect(1, h - barH, w - 1, barH, r, r);
73 |
74 | g.beginFill(green);
75 | barH = h * Math.min(percent, 70) / 100;
76 | g.drawRoundRect(1, h - barH, w - 1, barH, r, r);
77 | }
78 |
79 | }}
80 |
--------------------------------------------------------------------------------
/src/uiwidgets/StretchyBitmap.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package uiwidgets {
21 | import flash.display.*;
22 | import flash.geom.*;
23 |
24 | public class StretchyBitmap extends Sprite {
25 |
26 | private var srcBM:BitmapData;
27 | private var cachedBM:Bitmap;
28 |
29 | public function StretchyBitmap(bm:BitmapData = null, w:int = 100, h:int = 75) {
30 | srcBM = bm;
31 | if (srcBM == null) srcBM = new BitmapData(1, 1, false, 0x808080);
32 | cachedBM = new Bitmap(srcBM);
33 | addChild(cachedBM);
34 | setWidthHeight(w, h);
35 | }
36 |
37 | public function setWidthHeight(w:int, h:int):void {
38 | var srcW:int = srcBM.width;
39 | var srcH:int = srcBM.height;
40 | w = Math.max(w, srcW);
41 | h = Math.max(h, srcH);
42 | var halfSrc:int;
43 |
44 | // adjust width
45 | var newBM:BitmapData = new BitmapData(w, h, true, 0xFF000000);
46 | halfSrc = srcW / 2;
47 | newBM.copyPixels(srcBM, new Rectangle(0, 0, halfSrc, srcH), new Point(0, 0));
48 | newBM.copyPixels(srcBM, new Rectangle(srcW - halfSrc, 0, halfSrc, srcH), new Point(w - halfSrc, 0));
49 | for (var dstX:int = halfSrc; dstX < (w - halfSrc); dstX++) {
50 | newBM.copyPixels(srcBM, new Rectangle(halfSrc, 0, 1, srcH), new Point(dstX, 0));
51 | }
52 |
53 | // adjust height
54 | halfSrc = srcH / 2;
55 | newBM.copyPixels(newBM, new Rectangle(0, (srcH - halfSrc), w, halfSrc), new Point(0, h - halfSrc));
56 | for (var dstY:int = halfSrc + 1; dstY < (h - halfSrc); dstY++) {
57 | newBM.copyPixels(newBM, new Rectangle(0, halfSrc, w, 1), new Point(0, dstY));
58 | }
59 |
60 | // install new bitmap
61 | cachedBM.bitmapData = newBM;
62 | }
63 |
64 | }}
65 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/SegmentationState.as:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by Mallory on 10/22/15.
3 | */
4 | package svgeditor.objs {
5 | import flash.display.BitmapData;
6 | import flash.geom.Rectangle;
7 |
8 | import svgeditor.BitmapEdit;
9 |
10 | public class SegmentationState {
11 | public var scribbleBitmap:BitmapData;
12 | public var unmarkedBitmap:BitmapData;
13 | public var costumeRect:Rectangle;
14 | public var lastMask:BitmapData;
15 |
16 | public var next:SegmentationState = null;
17 | public var prev:SegmentationState = null;
18 |
19 | public var xMin:int;
20 | public var yMin:int;
21 | public var xMax:int;
22 | public var yMax:int;
23 |
24 | public function SegmentationState() {
25 | reset();
26 | }
27 |
28 | public function clone():SegmentationState{
29 | var clone:SegmentationState = new SegmentationState();
30 | //Scribble, mask, and bounding rect must be cloned as a snapshot of the current state.
31 | //We can get away with storing a reference to unmarked bitmap and only updating
32 | //on mask commits
33 | if(scribbleBitmap)
34 | clone.scribbleBitmap = scribbleBitmap.clone();
35 | if(unmarkedBitmap)
36 | clone.unmarkedBitmap = unmarkedBitmap;
37 | if(costumeRect)
38 | clone.costumeRect = costumeRect.clone();
39 | if(lastMask)
40 | clone.lastMask = lastMask.clone();
41 | clone.next = next;
42 | clone.prev = prev;
43 | clone.xMax = xMax;
44 | clone.xMin = xMin;
45 | clone.yMax = yMax;
46 | clone.yMin = yMin;
47 | return clone
48 | }
49 |
50 | public function recordForUndo():void{
51 | next = clone();
52 | next.next = null;
53 | next.prev = this;
54 | }
55 |
56 | public function canUndo():Boolean{
57 | return prev != null;
58 | }
59 |
60 | public function canRedo():Boolean{
61 | return next != null;
62 | }
63 |
64 | public function reset():void{
65 | scribbleBitmap = null;
66 | lastMask = null;
67 | next = null;
68 | xMin = -1;
69 | yMin = -1;
70 | xMax = 0;
71 | yMax = 0;
72 | }
73 |
74 | public function eraseUndoHistory():void{
75 | prev = next = null;
76 | }
77 |
78 | public function flip(vertical:Boolean):void{
79 | scribbleBitmap = BitmapEdit.flipBitmap(vertical, scribbleBitmap);
80 | lastMask = BitmapEdit.flipBitmap(vertical, lastMask);
81 | unmarkedBitmap = BitmapEdit.flipBitmap(vertical, unmarkedBitmap);
82 | costumeRect.x = unmarkedBitmap.width - costumeRect.x - costumeRect.width;
83 | costumeRect.y = unmarkedBitmap.height - costumeRect.y - costumeRect.height;
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/svgeditor/Renderer.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor
21 | {
22 | import flash.display.*;
23 | import flash.text.*;
24 | import svgutils.*;
25 | import svgeditor.objs.SVGBitmap;
26 | import svgeditor.objs.SVGGroup;
27 | import svgeditor.objs.SVGShape;
28 | import svgeditor.objs.SVGTextField;
29 |
30 | public class Renderer
31 | {
32 |
33 | static public function renderToSprite(spr:Sprite, rootSVG:SVGElement):void {
34 | // Populate the given sprite with DisplayObjects (e.g. SVGBitmap) for the subelements of rootSVG.
35 | if (!rootSVG) return;
36 | for each (var el:SVGElement in rootSVG.subElements) {
37 | appendElementToSprite(el, spr);
38 | }
39 | }
40 |
41 | static private function appendElementToSprite(el:SVGElement, spr:Sprite):void {
42 | // Append a DisplayObject for the given element to the given sprite.
43 | if ('g' == el.tag) {
44 | var groupSprite:SVGGroup = new SVGGroup(el);
45 | renderToSprite(groupSprite, el);
46 | if (el.transform) groupSprite.transform.matrix = el.transform;
47 | spr.addChild(groupSprite);
48 | } else if ('image' == el.tag) {
49 | var bmp:SVGBitmap = new SVGBitmap(el);
50 | bmp.redraw();
51 | if (el.transform) bmp.transform.matrix = el.transform;
52 | spr.addChild(bmp);
53 | } else if ('text' == el.tag) {
54 | var tf:SVGTextField = new SVGTextField(el);
55 | tf.selectable = false;
56 | el.renderTextOn(tf);
57 | if (el.transform) tf.transform.matrix = el.transform;
58 | spr.addChild(tf);
59 | } else if (el.path) {
60 | var shape:SVGShape = new SVGShape(el);
61 | shape.redraw();
62 | if (el.transform) shape.transform.matrix = el.transform;
63 | spr.addChild(shape);
64 | }
65 | }
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/ui/BlockPalette.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // BlockPalette.as
21 | // John Maloney, August 2009
22 | //
23 | // A BlockPalette holds the blocks for the selected category.
24 | // The mouse handling code detects when a Block's parent is a BlocksPalette and
25 | // creates a copy of that block when it is dragged out of the palette.
26 |
27 | package ui {
28 | import flash.geom.*;
29 | import blocks.Block;
30 | import interpreter.Interpreter;
31 | import uiwidgets.*;
32 | import scratch.ScratchObj;
33 | import scratch.ScratchComment;
34 |
35 | public class BlockPalette extends ScrollFrameContents {
36 |
37 | public const isBlockPalette:Boolean = true;
38 |
39 | public function BlockPalette():void {
40 | super();
41 | this.color = 0xE0E0E0;
42 | }
43 |
44 | override public function clear(scrollToOrigin:Boolean = true):void {
45 | var interp:Interpreter = Scratch.app.interp;
46 | var targetObj:ScratchObj = Scratch.app.viewedObj();
47 | while (numChildren > 0) {
48 | var b:Block = getChildAt(0) as Block;
49 | if (interp.isRunning(b, targetObj)) interp.toggleThread(b, targetObj);
50 | removeChildAt(0);
51 | }
52 | if (scrollToOrigin) x = y = 0;
53 | }
54 |
55 | public function handleDrop(obj:*):Boolean {
56 | // Delete blocks and stacks dropped onto the palette.
57 | var c:ScratchComment = obj as ScratchComment;
58 | if (c) {
59 | c.x = c.y = 20; // position for undelete
60 | c.deleteComment();
61 | return true;
62 | }
63 | var b:Block = obj as Block;
64 | if (b) {
65 | return b.deleteStack();
66 | }
67 | return false;
68 | }
69 |
70 | public static function strings():Array {
71 | return ['Cannot Delete', 'To delete a block definition, first remove all uses of the block.'];
72 | }
73 |
74 | }}
75 |
--------------------------------------------------------------------------------
/scratch.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath group: 'org.gradlefx', name: 'gradlefx', version: '1.2.0'
7 | }
8 | }
9 |
10 | repositories {
11 | ivy {
12 | name 'Apache Flex'
13 | artifactPattern 'http://archive.apache.org/dist/flex/[revision]/binaries/[module]-[revision]-bin.[ext]'
14 | }
15 | ivy {
16 | name 'Player Globals'
17 | artifactPattern 'http://fpdownload.macromedia.com/get/flashplayer/installers/archive/[module]/[module][revision].[ext]'
18 | }
19 | }
20 |
21 | apply plugin: org.gradlefx.plugins.GradleFxPlugin
22 |
23 | ext.getCommitID = { repository ->
24 | def dirty = "git status --porcelain --ignore-submodules=dirty".execute(null, file(repository)).text.trim() ? "-dirty" : ""
25 | def revision = "git rev-parse --short HEAD".execute(null, file(repository)).text.trim()
26 | return revision ? revision + dirty : 'unknown'
27 | }
28 |
29 | def commonDir = ext.commonDir
30 | def target = hasProperty('target') ? target : '11.6'
31 | println "Target is: $target"
32 | def config = new ConfigSlurper(target).parse(file("${commonDir}/config.groovy").toURL())
33 |
34 | type = 'mobile'
35 | version = '1.0-SNAPSHOT'
36 | frameworkLinkage = 'none'
37 | buildDir = "${buildDir}/${target}" // GradleFX does an out-of-date check on the whole build dir
38 | output = config.get('output')
39 | playerVersion = config.get('playerVersion')
40 |
41 | def scratchFlashCommitID = getCommitID(commonDir)
42 | println "Commit ID for scratch-flash is: ${scratchFlashCommitID}"
43 |
44 | dependencies {
45 | flexSDK group: 'org.apache', name: 'apache-flex-sdk', version: '4.15.0', ext: 'zip'
46 | external group: 'macromedia.com', name: 'playerglobal', version: playerVersion.replace('.', '_'), ext: 'swc'
47 | merged files(
48 | "${commonDir}/libs/as3corelib.swc",
49 | "${commonDir}/libs/blooddy_crypto.swc",
50 | "${commonDir}/libs/grabcut.swc"
51 |
52 | )
53 | }
54 |
55 | sdkAutoInstall {
56 | showPrompts = false
57 | }
58 |
59 | additionalCompilerOptions = [
60 | "-library-path+=libs/framework.swc", // in the SDK's frameworks directory
61 | "-library-path+=libs/osmf.swc", // in the SDK's frameworks directory
62 | "-target-player=${playerVersion}",
63 | "-default-size=800,600",
64 | "-define+=SCRATCH::revision,'${scratchFlashCommitID}'",
65 | "-advanced-telemetry",
66 | ]
67 | additionalCompilerOptions += config.get('additionalCompilerOptions')
68 |
69 | task wrapper(type: Wrapper) {
70 | gradleVersion = '2.5'
71 | }
72 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/SVGTextField.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.objs
21 | {
22 | import flash.display.DisplayObject;
23 | import flash.display.Shape;
24 | import flash.events.Event;
25 | import flash.events.FocusEvent;
26 | import flash.events.KeyboardEvent;
27 | import flash.text.AntiAliasType;
28 | import flash.text.TextField;
29 | import flash.text.TextFieldAutoSize;
30 | import flash.text.TextFieldType;
31 |
32 | import svgeditor.objs.ISVGEditable;
33 |
34 | import svgutils.SVGDisplayRender;
35 | import svgutils.SVGElement;
36 |
37 | public class SVGTextField extends TextField implements ISVGEditable
38 | {
39 | private var element:SVGElement;
40 | private var _editable:Boolean;
41 |
42 | public function SVGTextField(elem:SVGElement) {
43 | element = elem;
44 | if (element.text == null) element.text = '';
45 | _editable = false;
46 | antiAliasType = AntiAliasType.ADVANCED;
47 | cacheAsBitmap = true;
48 | embedFonts = true;
49 | backgroundColor = 0xFFFFFF;
50 | multiline = true;
51 | }
52 |
53 | public function getElement():SVGElement {
54 | element.transform = transform.matrix.clone();
55 | return element;
56 | }
57 |
58 | public function redraw(forHitTest:Boolean = false):void {
59 | var fixup:Boolean = (type == TextFieldType.INPUT && element.text.length < 4);
60 | var origText:String = element.text;
61 | if(element.text == "") element.text = " ";
62 | element.renderTextOn(this);
63 | element.text = origText;
64 | if(fixup) width += 25;
65 | }
66 |
67 | public function clone():ISVGEditable {
68 | var copy:SVGTextField = new SVGTextField(element.clone());
69 | copy.transform.matrix = transform.matrix.clone();
70 | copy.selectable = false;
71 | copy.redraw();
72 | return copy as ISVGEditable;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/svgeditor/DrawProperties.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor {
21 | public class DrawProperties {
22 |
23 | // colors
24 | public var rawColor:uint = 0xFF000000;
25 | public var rawSecondColor:uint = 0xFFFFFFFF;
26 |
27 | public function set color(c:uint):void { rawColor = c }
28 | public function get color():uint { return rawColor & 0xFFFFFF }
29 | public function get alpha():Number { return ((rawColor >> 24) & 0xFF) / 0xFF }
30 |
31 | public function set secondColor(c:uint):void { rawSecondColor = c }
32 | public function get secondColor():uint { return rawSecondColor & 0xFFFFFF }
33 | public function get secondAlpha():Number { return ((rawSecondColor >> 24) & 0xFF) / 0xFF }
34 |
35 | // stroke
36 | public var smoothness:Number = 1;
37 | private var rawStrokeWidth:Number = 1;
38 | private var rawEraserWidth:Number = 4;
39 |
40 | public function set strokeWidth(w:int):void { rawStrokeWidth = w }
41 | public function set eraserWidth(w:int):void { rawEraserWidth = w }
42 |
43 | public function get strokeWidth():int {
44 | return adjustWidth(rawStrokeWidth);
45 | }
46 |
47 | public function get eraserWidth():int {
48 | return adjustWidth(rawEraserWidth);
49 | }
50 |
51 | private static function adjustWidth(raw:int):int {
52 | if (Scratch.app.imagesPart && (Scratch.app.imagesPart.editor is SVGEdit)) return raw;
53 |
54 | // above 10, use Squeak brush sizes
55 | const n:Number = Math.max(1, Math.round(raw));
56 | switch(n) {
57 | case 11: return 13;
58 | case 12: return 19;
59 | case 13: return 29;
60 | case 14: return 47;
61 | case 15: return 75;
62 | default: return n;
63 | }
64 | }
65 |
66 | // fill
67 | public var fillType:String = 'solid'; // solid, linearHorizontal, linearVertical, radial
68 | public var filledShape:Boolean = false;
69 |
70 | // font
71 | public var fontName:String = 'Helvetica';
72 |
73 | }}
74 |
--------------------------------------------------------------------------------
/src/svgeditor/objs/SVGGroup.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.objs
21 | {
22 | import flash.display.DisplayObject;
23 | import flash.display.Sprite;
24 |
25 | import svgeditor.objs.ISVGEditable;
26 |
27 | import svgutils.SVGElement;
28 |
29 | public class SVGGroup extends Sprite implements ISVGEditable
30 | {
31 | private var element:SVGElement;
32 |
33 | public function SVGGroup(elem:SVGElement) {
34 | super();
35 | element = elem;
36 | }
37 |
38 | public function getElement():SVGElement {
39 | element.subElements = getSubElements();
40 | element.transform = transform.matrix;
41 | return element;
42 | }
43 |
44 | public function redraw(forHitTest:Boolean = false):void {
45 | if(element.transform) transform.matrix = element.transform;
46 |
47 | // Redraw the sub elements
48 | for(var i:uint = 0; i < numChildren; ++i) {
49 | var child:DisplayObject = getChildAt(i);
50 | if(child is ISVGEditable) {
51 | (child as ISVGEditable).redraw();
52 | }
53 | }
54 | }
55 |
56 | private function getSubElements():Array {
57 | var elements:Array = [];
58 | for(var i:uint = 0; i < numChildren; ++i) {
59 | var child:DisplayObject = getChildAt(i);
60 | if(child is ISVGEditable) {
61 | elements.push((child as ISVGEditable).getElement());
62 | }
63 | }
64 | return elements;
65 | }
66 |
67 | public function clone():ISVGEditable {
68 | var copy:SVGGroup = new SVGGroup(element.clone());
69 | (copy as DisplayObject).transform.matrix = transform.matrix.clone();
70 |
71 | var elements:Array = [];
72 | for(var i:uint = 0; i < numChildren; ++i) {
73 | var child:DisplayObject = getChildAt(i);
74 | if(child is ISVGEditable) {
75 | copy.addChild((child as ISVGEditable).clone() as DisplayObject);
76 | }
77 | }
78 |
79 | copy.redraw();
80 | return copy;
81 | }
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/watchers/WatcherReadout.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package watchers {
21 | import flash.display.Sprite;
22 | import flash.text.*;
23 | import uiwidgets.ResizeableFrame;
24 |
25 | public class WatcherReadout extends Sprite {
26 |
27 | private var smallFont:TextFormat = new TextFormat(CSS.font, 10, 0xFFFFFF, true);
28 | private var largeFont:TextFormat = new TextFormat(CSS.font, 15, 0xFFFFFF, true);
29 |
30 | private var frame:ResizeableFrame;
31 | private var tf:TextField;
32 | private var isLarge:Boolean;
33 |
34 | public function WatcherReadout() {
35 | frame = new ResizeableFrame(0xFFFFFF, Specs.variableColor, 8, true);
36 | addChild(frame);
37 | addTextField();
38 | beLarge(false);
39 | }
40 |
41 | public function getColor():int { return frame.getColor() }
42 | public function setColor(color:int):void { frame.setColor(color) }
43 |
44 | public function get contents():String { return tf.text }
45 |
46 | public function setContents(s:String):void {
47 | if (s == tf.text) return; // no change
48 | tf.text = s;
49 | fixLayout();
50 | }
51 |
52 | public function beLarge(newValue:Boolean):void {
53 | isLarge = newValue;
54 | var fmt:TextFormat = isLarge ? largeFont : smallFont;
55 | fmt.align = TextFormatAlign.CENTER;
56 | tf.defaultTextFormat = fmt;
57 | tf.setTextFormat(fmt); // force font change
58 | fixLayout();
59 | }
60 |
61 | private function fixLayout():void {
62 | var w:int = isLarge ? 48 : 40;
63 | var h:int = isLarge ? 20 : 14;
64 | var hPad:int = isLarge ? 12 : 5;
65 | w = Math.max(w, tf.textWidth + hPad);
66 | tf.width = w;
67 | tf.height = h;
68 | tf.y = isLarge ? 0 : -1;
69 | if ((w != frame.w) || (h != frame.h)) frame.setWidthHeight(w, h);
70 | }
71 |
72 | private function addTextField():void {
73 | tf = new TextField();
74 | tf.type = "dynamic";
75 | tf.selectable = false;
76 | addChild(tf);
77 | }
78 |
79 | }}
80 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/src/svgeditor/tools/PathEndPoint.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.tools
21 | {
22 | import flash.display.DisplayObject;
23 | import flash.display.Graphics;
24 | import flash.display.Sprite;
25 | import flash.events.MouseEvent;
26 | import flash.geom.Point;
27 |
28 | import svgeditor.ImageEdit;
29 | import svgeditor.tools.PathEndPointManager;
30 | import svgeditor.objs.ISVGEditable;
31 | import svgeditor.objs.SVGShape;
32 |
33 | public class PathEndPoint extends Sprite
34 | {
35 | private var editor:ImageEdit;
36 | private var shape:SVGShape;
37 | private var strokeWidth:Number;
38 | public function PathEndPoint(ed:ImageEdit, a:SVGShape, p:Point) {
39 | editor = ed;
40 | shape = a;
41 | x = p.x;
42 | y = p.y;
43 |
44 | addEventListener(MouseEvent.MOUSE_OVER, toggleHighlight, false, 0 , true);
45 | addEventListener(MouseEvent.MOUSE_OUT, toggleHighlight, false, 0 , true);
46 | addEventListener(MouseEvent.MOUSE_DOWN, proxyEvent, false, 0 , true);
47 | addEventListener(MouseEvent.MOUSE_MOVE, showOrb, false, 0 , true);
48 |
49 | graphics.clear();
50 | graphics.beginFill(0, 0);
51 | graphics.drawCircle(0, 0, 10);
52 | graphics.endFill();
53 | }
54 |
55 | private function toggleHighlight(e:MouseEvent):void {
56 | PathEndPointManager.toggleEndPoint(e.type == MouseEvent.MOUSE_OVER, new Point(x, y));
57 | editor.getWorkArea().dispatchEvent(e);
58 |
59 | if(e.type == MouseEvent.MOUSE_OVER) {
60 | strokeWidth = editor.getShapeProps().strokeWidth;
61 | }
62 | }
63 |
64 | private function proxyEvent(e:MouseEvent):void {
65 | editor.getCanvasLayer().dispatchEvent(e);
66 | e.stopImmediatePropagation();
67 | }
68 |
69 | private function showOrb(e:MouseEvent):void {
70 | var w:Number = (strokeWidth + shape.getElement().getAttribute('stroke-width', 1)) / 4;
71 | PathEndPointManager.updateOrb((new Point(mouseX, mouseY)).length < w);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/svgeditor/tools/RectangleTool.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.tools
21 | {
22 | import flash.display.DisplayObject;
23 | import flash.geom.Point;
24 |
25 | import svgeditor.ImageEdit;
26 | import svgeditor.DrawProperties;
27 | import svgeditor.objs.SVGShape;
28 |
29 | import svgutils.SVGElement;
30 |
31 | public final class RectangleTool extends SVGCreateTool
32 | {
33 | private var createOrigin:Point;
34 | private var newElement:SVGElement;
35 |
36 | public function RectangleTool(svgEditor:ImageEdit) {
37 | super(svgEditor);
38 | }
39 |
40 | override protected function mouseDown(p:Point):void {
41 | // If we're trying to draw with invisible settings then bail
42 | var props:DrawProperties = editor.getShapeProps();
43 | if(props.alpha == 0)
44 | return;
45 |
46 | createOrigin = p;
47 |
48 | newElement = new SVGElement('rect', null);
49 | if(props.filledShape) {
50 | newElement.setShapeFill(props);
51 | newElement.setAttribute('stroke', 'none');
52 | }
53 | else {
54 | newElement.setShapeStroke(props);
55 | newElement.setAttribute('fill', 'none');
56 | }
57 |
58 | newObject = new SVGShape(newElement);
59 | contentLayer.addChild(newObject as DisplayObject);
60 | }
61 |
62 | override protected function mouseMove(p:Point):void {
63 | if(!createOrigin) return;
64 |
65 | var ofs:Point = createOrigin.subtract(p);
66 | var w:Number = Math.abs(ofs.x);
67 | var h:Number = Math.abs(ofs.y);
68 |
69 | // Shift key makes a square
70 | if(currentEvent.shiftKey) {
71 | w = h = Math.max(w, h);
72 | p.x = createOrigin.x + (ofs.x < 0 ? w : -w);
73 | p.y = createOrigin.y + (ofs.y < 0 ? h : -h);
74 | }
75 |
76 | newElement.setAttribute('x', Math.min(p.x, createOrigin.x));
77 | newElement.setAttribute('y', Math.min(p.y, createOrigin.y));
78 | newElement.setAttribute('width', w);
79 | newElement.setAttribute('height', h);
80 | //newElement.setAttribute('scratch-type', 'backdrop-fill');
81 | newElement.updatePath();
82 | newObject.redraw();
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/uiwidgets/TextPane.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package uiwidgets {
21 | import flash.display.Sprite;
22 | import flash.events.Event;
23 | import flash.text.TextField;
24 | import flash.text.TextFieldType;
25 | import flash.text.TextFormat;
26 |
27 | public class TextPane extends Sprite {
28 |
29 | private static var scrollbarWidth:int = 10;
30 |
31 | public var textField:TextField;
32 | public var scrollbar:Scrollbar;
33 |
34 | public function TextPane() {
35 | addTextField();
36 | scrollbar = new Scrollbar(scrollbarWidth, textField.height, scrollTextField);
37 | setWidthHeight(400, 500);
38 | addChild(scrollbar);
39 | addEventListener(Event.ENTER_FRAME, updateScrollbar);
40 | }
41 |
42 | public function setWidthHeight(w:int, h:int):void {
43 | textField.width = w - scrollbar.width;
44 | textField.height = h;
45 | scrollbar.x = textField.width;
46 | scrollbar.setWidthHeight(scrollbarWidth, h);
47 | }
48 |
49 | public function append(s:String):void {
50 | textField.appendText(s);
51 | textField.scrollV = textField.maxScrollV - 1;
52 | updateScrollbar(null);
53 | }
54 |
55 | public function clear():void {
56 | textField.text = "";
57 | textField.scrollV = 0;
58 | updateScrollbar(null);
59 | }
60 |
61 | public function setText(s:String):void {
62 | textField.text = s;
63 | textField.scrollV = textField.maxScrollV - 1;
64 | updateScrollbar(null);
65 | }
66 |
67 | private function scrollTextField(scrollFraction:Number):void {
68 | textField.scrollV = scrollFraction * textField.maxScrollV;
69 | }
70 |
71 | private function updateScrollbar(evt:Event):void {
72 | var scroll:Number = textField.scrollV / textField.maxScrollV;
73 | var visible:Number = textField.height / textField.textHeight;
74 | scrollbar.update(scroll, visible);
75 | }
76 |
77 | private function addTextField():void {
78 | textField = new TextField();
79 | textField.background = true;
80 | textField.type = TextFieldType.INPUT;
81 | textField.defaultTextFormat = new TextFormat(CSS.font, 14);
82 | textField.multiline = true;
83 | textField.wordWrap = true;
84 | addChild(textField);
85 | }
86 |
87 | }}
88 |
--------------------------------------------------------------------------------
/src/leelib/util/flvEncoder/VideoPayloadMaker.as:
--------------------------------------------------------------------------------
1 | package leelib.util.flvEncoder
2 | {
3 | import flash.display.BitmapData;
4 | import flash.system.System;
5 | import flash.utils.ByteArray;
6 | import flash.utils.Endian;
7 |
8 | /**
9 | * AS-3 only algorithm.
10 | * No SWC dependencies, no Flash 10 requirement
11 | */
12 | public class VideoPayloadMaker implements IVideoPayload
13 | {
14 | public function make($bitmapData:BitmapData):ByteArray
15 | {
16 | var w:int = $bitmapData.width;
17 | var h:int = $bitmapData.height;
18 |
19 | var ba:ByteArray = new ByteArray();
20 |
21 | // VIDEODATA 'header' - frametype (1) + codecid (3)
22 | ba.writeByte(0x13);
23 |
24 | // SCREENVIDEOPACKET 'header'
25 | FlvEncoder.writeUI4_12(ba, int(FlvEncoder.BLOCK_WIDTH/16) - 1, w); // blockwidth/16-1 (4bits) + imagewidth (12bits)
26 | FlvEncoder.writeUI4_12(ba, int(FlvEncoder.BLOCK_HEIGHT/16) - 1, h); // blockheight/16-1 (4bits) + imageheight (12bits)
27 |
28 | // IMAGEBLOCKS
29 |
30 | var rowMax:int = int(h/FlvEncoder.BLOCK_HEIGHT);
31 | var rowRemainder:int = h % FlvEncoder.BLOCK_HEIGHT;
32 | if (rowRemainder > 0) rowMax += 1;
33 |
34 | var colMax:int = int(w/FlvEncoder.BLOCK_WIDTH);
35 | var colRemainder:int = w % FlvEncoder.BLOCK_WIDTH;
36 | if (colRemainder > 0) colMax += 1;
37 |
38 | var block:ByteArray = new ByteArray();
39 | block.endian = Endian.LITTLE_ENDIAN;
40 |
41 | for (var row:int = 0; row < rowMax; row++)
42 | {
43 | for (var col:int = 0; col < colMax; col++)
44 | {
45 | var xStart:uint = col * FlvEncoder.BLOCK_WIDTH;
46 | var xLimit:int = (colRemainder > 0 && col + 1 == colMax) ? colRemainder : FlvEncoder.BLOCK_WIDTH;
47 | var xEnd:int = xStart + xLimit;
48 |
49 | var yStart:uint = h - (row * FlvEncoder.BLOCK_HEIGHT); // * goes from bottom to top
50 | var yLimit:int = (rowRemainder > 0 && row + 1 == rowMax) ? rowRemainder : FlvEncoder.BLOCK_HEIGHT;
51 | var yEnd:int = yStart - yLimit;
52 |
53 | // re-use ByteArray
54 | block.length = 0;
55 |
56 | for (var y:int = yStart-1; y >= yEnd; y--) // (flv's store image data from bottom to top)
57 | {
58 | for (var x:int = xStart; x < xEnd; x++)
59 | {
60 | var p:uint = $bitmapData.getPixel(x, y);
61 | block.writeByte( p & 0xff );
62 | block.writeShort(p >> 8);
63 | // ... this is the equivalent of writing the B, G, and R bytes in sequence
64 | }
65 | }
66 |
67 | block.compress();
68 |
69 | FlvEncoder.writeUI16(ba, block.length); // write block length (UI16)
70 | ba.writeBytes( block ); // write block
71 | }
72 | }
73 |
74 | block.length = 0;
75 | block = null;
76 |
77 | return ba;
78 | }
79 |
80 | public function init($width:int, $height:int):void
81 | {
82 | // (no particular need in AS3 version)
83 | }
84 |
85 | public function kill():void
86 | {
87 | // (no particular need in AS3 version)
88 | }
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/src/svgeditor/tools/EllipseTool.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.tools
21 | {
22 | import flash.display.DisplayObject;
23 | import flash.geom.Point;
24 |
25 | import svgeditor.DrawProperties;
26 | import svgeditor.ImageEdit;
27 | import svgeditor.objs.SVGShape;
28 |
29 | import svgutils.SVGElement;
30 |
31 | public final class EllipseTool extends SVGCreateTool
32 | {
33 | private var createOrigin:Point;
34 | private var newElement:SVGElement;
35 |
36 | public function EllipseTool(svgEditor:ImageEdit) {
37 | super(svgEditor);
38 | createOrigin = null;
39 | newElement = null;
40 | }
41 |
42 | override protected function mouseDown(p:Point):void {
43 | // If we're trying to draw with invisible settings then bail
44 | var props:DrawProperties = editor.getShapeProps();
45 | if(props.alpha == 0)
46 | return;
47 |
48 | createOrigin = p;
49 |
50 | newElement = new SVGElement('ellipse', null);
51 | newElement.setAttribute('cx', contentLayer.mouseX);
52 | newElement.setAttribute('cy', contentLayer.mouseY);
53 | if(props.filledShape) {
54 | newElement.setShapeFill(props);
55 | newElement.setAttribute('stroke', 'none');
56 | }
57 | else {
58 | newElement.setShapeStroke(props);
59 | newElement.setAttribute('fill', 'none');
60 | }
61 |
62 | newObject = new SVGShape(newElement);
63 | contentLayer.addChild(newObject as DisplayObject);
64 | }
65 |
66 | override protected function mouseMove(p:Point):void {
67 | if(!createOrigin) return;
68 |
69 | var ofs:Point = createOrigin.subtract(p);
70 | var w:Number = Math.abs(ofs.x);
71 | var h:Number = Math.abs(ofs.y);
72 |
73 | // Shift key makes a circle
74 | if(currentEvent.shiftKey) {
75 | w = h = Math.max(w, h);
76 | p.x = createOrigin.x + (ofs.x < 0 ? w : -w);
77 | p.y = createOrigin.y + (ofs.y < 0 ? h : -h);
78 | }
79 |
80 | var rx:Number = w/2;
81 | var ry:Number = h/2;
82 | newElement.setAttribute('cx', Math.min(p.x, createOrigin.x) + rx);
83 | newElement.setAttribute('cy', Math.min(p.y, createOrigin.y) + ry);
84 | newElement.setAttribute('rx', rx);
85 | newElement.setAttribute('ry', ry);
86 | newElement.updatePath();
87 | newObject.redraw();
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/ui/PaletteSelectorItem.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // PaletteSelectorItem.as
21 | // John Maloney, August 2009
22 | //
23 | // A PaletteSelectorItem is a text button for a named category in a PaletteSelector.
24 | // It handles mouse over, out, and up events and changes its appearance when selected.
25 |
26 | package ui {
27 | import flash.display.*;
28 | import flash.events.MouseEvent;
29 | import flash.text.*;
30 |
31 | public class PaletteSelectorItem extends Sprite {
32 |
33 | public var categoryID:int;
34 | public var label:TextField;
35 | public var isSelected:Boolean;
36 |
37 | private var color:uint;
38 |
39 | public function PaletteSelectorItem(id: int, s:String, c:uint) {
40 | categoryID = id;
41 | addLabel(s);
42 | color = c;
43 | setSelected(false);
44 | addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
45 | addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
46 | addEventListener(MouseEvent.CLICK, mouseUp);
47 | }
48 |
49 | private function addLabel(s:String):void {
50 | label = new TextField();
51 | label.autoSize = TextFieldAutoSize.LEFT;
52 | label.selectable = false;
53 | label.text = s;
54 | addChild(label);
55 | }
56 |
57 | public function setSelected(flag:Boolean):void {
58 | var w:int = 100;
59 | var h:int = label.height + 2;
60 | var tabInset:int = 8;
61 | var tabW:int = 7;
62 | isSelected = flag;
63 | var fmt:TextFormat = new TextFormat(CSS.font, 12, (isSelected ? CSS.white : CSS.offColor), isSelected);
64 | label.setTextFormat(fmt);
65 | label.x = 17;
66 | label.y = 1;
67 | var g:Graphics = this.graphics;
68 | g.clear();
69 | g.beginFill(0xFF00, 0); // invisible, but mouse sensitive
70 | g.drawRect(0, 0, w, h);
71 | g.endFill();
72 | g.beginFill(color);
73 | g.drawRect(tabInset, 1, isSelected ? w - tabInset - 1 : tabW, h - 2);
74 | g.endFill();
75 | }
76 |
77 | private function mouseOver(event:MouseEvent):void {
78 | label.textColor = isSelected ? CSS.white : CSS.buttonLabelOverColor;
79 | }
80 |
81 | private function mouseOut(event:MouseEvent):void {
82 | label.textColor = isSelected ? CSS.white : CSS.offColor;
83 | }
84 |
85 | private function mouseUp(event:MouseEvent):void {
86 | if (parent is PaletteSelector) {
87 | PaletteSelector(parent).select(categoryID, event.shiftKey);
88 | }
89 | }
90 |
91 | }}
92 |
--------------------------------------------------------------------------------
/src/CSS.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | // CSS.as
21 | // Paula Bonta, November 2011
22 | //
23 | // Styles for Scratch Editor based on the Upstatement design.
24 |
25 | package {
26 | import flash.text.*;
27 | import assets.Resources;
28 |
29 | public class CSS {
30 |
31 | public static function topBarColor():int { return Scratch.app.isExtensionDevMode ? topBarColor_ScratchX : topBarColor_default; }
32 | public static function backgroundColor():int { return Scratch.app.isExtensionDevMode ? backgroundColor_ScratchX : backgroundColor_default; }
33 |
34 | // ScratchX
35 | public static const topBarColor_ScratchX:int = 0x30485f;
36 | public static const backgroundColor_ScratchX:int = 0x3f5975;
37 |
38 | // Colors
39 | public static const white:int = 0xFFFFFF;
40 | public static const backgroundColor_default:int = white;
41 | public static const topBarColor_default:int = 0x9C9EA2;
42 | public static const tabColor:int = 0xE6E8E8;
43 | public static const panelColor:int = 0xF2F2F2;
44 | public static const itemSelectedColor:int = 0xD0D0D0;
45 | public static const borderColor:int = 0xD0D1D2;
46 | public static const textColor:int = 0x5C5D5F; // 0x6C6D6F
47 | public static const buttonLabelColor:int = textColor;
48 | public static const buttonLabelOverColor:int = 0xFBA939;
49 | public static const offColor:int = 0x8F9193; // 0x9FA1A3
50 | public static const onColor:int = textColor; // 0x4C4D4F
51 | public static const overColor:int = 0x179FD7;
52 | public static const arrowColor:int = 0xA6A8AC;
53 |
54 | // Fonts
55 | public static const font:String = Resources.chooseFont(['Arial', 'Verdana', 'DejaVu Sans']);
56 | public static const menuFontSize:int = 12;
57 | public static const normalTextFormat:TextFormat = new TextFormat(font, 12, textColor);
58 | public static const topBarButtonFormat:TextFormat = new TextFormat(font, 12, white, true);
59 | public static const titleFormat:TextFormat = new TextFormat(font, 14, textColor);
60 | public static const thumbnailFormat:TextFormat = new TextFormat(font, 11, textColor);
61 | public static const thumbnailExtraInfoFormat:TextFormat = new TextFormat(font, 9, textColor);
62 | public static const projectTitleFormat:TextFormat = new TextFormat(font, 13, textColor);
63 | public static const projectInfoFormat:TextFormat = new TextFormat(font, 12, textColor);
64 |
65 | // Section title bars
66 | public static const titleBarColors:Array = [white, tabColor];
67 | public static const titleBarH:int = 30;
68 |
69 | }}
70 |
--------------------------------------------------------------------------------
/src/ui/LoadProgress.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package ui {
21 | import flash.display.*;
22 | import flash.filters.DropShadowFilter;
23 | import flash.text.*;
24 | import assets.Resources;
25 | import translation.Translator;
26 |
27 | public class LoadProgress extends Sprite {
28 |
29 | private const titleFormat:TextFormat = new TextFormat(CSS.font, 18, CSS.textColor);
30 | private const infoFormat:TextFormat = new TextFormat(CSS.font, 12, CSS.textColor);
31 | private const grooveColor:int = 0xB9BBBD;
32 |
33 | private var bkg:Shape;
34 | private var titleField:TextField;
35 | private var infoField:TextField;
36 | private var groove:Shape;
37 | private var progressBar:Shape;
38 |
39 | public function LoadProgress():void {
40 | addBackground(310, 120);
41 | addChild(titleField = Resources.makeLabel('', titleFormat, 20, bkg.height - 61));
42 | addChild(infoField = Resources.makeLabel('', infoFormat, 20, bkg.height - 35));
43 |
44 | addChild(groove = new Shape());
45 | addChild(progressBar = new Shape());
46 | groove.x = progressBar.x = 30;
47 | groove.y = progressBar.y = 25;
48 |
49 | drawBar(groove.graphics, grooveColor, 250, 22)
50 | }
51 |
52 | public function getTitle():String { return titleField.text }
53 |
54 | public function setTitle(s:String):void {
55 | titleField.text = Translator.map(s);
56 | titleField.x = (bkg.width - titleField.textWidth) / 2;
57 | infoField.text = ''; // clear old info when title changes
58 | }
59 |
60 | public function setInfo(s:String):void {
61 | infoField.text = Translator.map(s);
62 | infoField.x = (bkg.width - infoField.textWidth) / 2;
63 | }
64 |
65 | public function setProgress(p:Number):void {
66 | drawBar(progressBar.graphics, CSS.overColor, Math.floor(groove.width * p), groove.height);
67 | }
68 |
69 | private function addBackground(w:int, h:int):void {
70 | addChild(bkg = new Shape());
71 |
72 | var g:Graphics = bkg.graphics;
73 | g.clear();
74 | g.lineStyle(1, CSS.borderColor, 1, true);
75 | g.beginFill(0xFFFFFF);
76 | g.drawRoundRect(0, 0, w, h, 24, 24);
77 | g.endFill();
78 |
79 | var f:DropShadowFilter = new DropShadowFilter();
80 | f.blurX = f.blurY = 8;
81 | f.distance = 5;
82 | f.alpha = 0.75;
83 | f.color = 0x333333;
84 | bkg.filters = [f];
85 | }
86 |
87 | private function drawBar(g:Graphics, c:uint, w:int, h:int):void {
88 | var radius:int = h / 2;
89 | g.clear();
90 | g.beginFill(c);
91 | g.drawRoundRect(0, 0, w, h, radius, radius);
92 | g.endFill();
93 | }
94 |
95 | }}
96 |
--------------------------------------------------------------------------------
/src/svgeditor/tools/SVGEditTool.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Scratch Project Editor and Player
3 | * Copyright (C) 2014 Massachusetts Institute of Technology
4 | *
5 | * This program is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU General Public License
7 | * as published by the Free Software Foundation; either version 2
8 | * of the License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program; if not, write to the Free Software
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 | */
19 |
20 | package svgeditor.tools
21 | {
22 | import flash.display.DisplayObject;
23 | import flash.display.Sprite;
24 | import flash.events.Event;
25 | import flash.events.MouseEvent;
26 | import flash.filters.GlowFilter;
27 | import flash.geom.Point;
28 |
29 | import svgeditor.ImageEdit;
30 | import svgeditor.Selection;
31 | import svgeditor.objs.ISVGEditable;
32 |
33 | public class SVGEditTool extends SVGTool
34 | {
35 | protected var object:ISVGEditable;
36 | private var editTag:Array;
37 |
38 | public function SVGEditTool(ed:ImageEdit, tag:* = null) {
39 | super(ed);
40 | touchesContent = true;
41 | object = null;
42 | editTag = (tag is String) ? [tag] : tag;
43 | }
44 |
45 | public function editSelection(s:Selection):void {
46 | if(s && s.getObjs().length == 1)
47 | setObject(s.getObjs()[0] as ISVGEditable);
48 | }
49 |
50 | public function setObject(obj:ISVGEditable):void {
51 | edit(obj, null);
52 | }
53 |
54 | public function getObject():ISVGEditable {
55 | return object;
56 | }
57 |
58 | // When overriding this method, usually an event handler will be added with a higher priority
59 | // so that the mouseDown method below is overridden
60 | protected function edit(obj:ISVGEditable, event:MouseEvent):void {
61 | if(obj == object) return;
62 |
63 | if(object) {
64 | //(object as DisplayObject).filters = [];
65 | }
66 |
67 | if(obj && (!editTag || editTag.indexOf(obj.getElement().tag) > -1)) {
68 | object = obj;
69 |
70 | if(object) {
71 | //(object as DisplayObject).filters = [new GlowFilter(0x28A5DA)];
72 | }
73 | } else {
74 | object = null;
75 | }
76 | dispatchEvent(new Event('select'));
77 | }
78 |
79 | override protected function init():void {
80 | super.init();
81 | editor.getContentLayer().addEventListener(MouseEvent.MOUSE_DOWN, mouseDown, false, 0, true);
82 | }
83 |
84 | override protected function shutdown():void {
85 | editor.getContentLayer().removeEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
86 | super.shutdown();
87 |
88 | if(object) {
89 | setObject(null);
90 | }
91 | }
92 |
93 | public function mouseDown(event:MouseEvent):void {
94 | var obj:ISVGEditable = getEditableUnderMouse(!(this is PathEditTool));
95 | currentEvent = event;
96 | edit(obj, event);
97 | currentEvent = null;
98 |
99 | event.stopPropagation();
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------