diff options
| author | jmoenig <jens@moenig.org> | 2014-02-04 14:29:32 +0100 |
|---|---|---|
| committer | jmoenig <jens@moenig.org> | 2014-02-04 14:29:32 +0100 |
| commit | 1d8862c7af97408679aa431431a369197b2e47d1 (patch) | |
| tree | 3cef033f968a930478808d8d4f273f9135ea80e6 | |
| parent | 8654d9c3fc084fee3a460f8d64e53cfb58370936 (diff) | |
| download | snap-byow-1d8862c7af97408679aa431431a369197b2e47d1.tar.gz snap-byow-1d8862c7af97408679aa431431a369197b2e47d1.zip | |
Import costumes and backgrounds from the project menu
thanks, Brian, for the changeset!
| -rw-r--r-- | gui.js | 63 | ||||
| -rwxr-xr-x | history.txt | 4 |
2 files changed, 66 insertions, 1 deletions
@@ -68,7 +68,7 @@ sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2014-January-09'; +modules.gui = '2014-February-04'; // Declarations @@ -2233,6 +2233,8 @@ IDE_Morph.prototype.projectMenu = function () { myself = this, world = this.world(), pos = this.controlBar.projectButton.bottomLeft(), + graphicsName = this.currentSprite instanceof SpriteMorph ? + 'Costumes' : 'Backgrounds', shiftClicked = (world.currentKey === 16); menu = new MenuMorph(this); @@ -2380,9 +2382,68 @@ IDE_Morph.prototype.projectMenu = function () { 'Select categories of additional blocks to add to this project.' ); + menu.addItem( + localize(graphicsName) + '...', + function () { + var dir = graphicsName, + names = myself.getCostumesList(dir), + libMenu = new MenuMorph( + myself, + localize('Import') + ' ' + localize(dir) + ); + + function loadCostume(name) { + var url = dir + '/' + name, + img = new Image(); + img.onload = function () { + var canvas = newCanvas(new Point(img.width, img.height)); + canvas.getContext('2d').drawImage(img, 0, 0); + myself.droppedImage(canvas, name); + }; + img.src = url; + } + + names.forEach(function (line) { + if (line.length > 0) { + libMenu.addItem( + line, + function () {loadCostume(line); } + ); + } + }); + libMenu.popup(world, pos); + }, + 'Select a costume from the media library' + ); + menu.popup(world, pos); }; +IDE_Morph.prototype.getCostumesList = function (dirname) { + var dir, + costumes = []; + + dir = this.getURL(dirname); + dir.split('\n').forEach( + function (line) { + var startIdx = line.search(new RegExp('href="[^./?].*"')), + endIdx, + name; + + if (startIdx > 0) { + name = line.substring(startIdx + 6); + endIdx = name.search(new RegExp('"')); + name = name.substring(0, endIdx); + costumes.push(name); + } + } + ); + costumes.sort(function (x, y) { + return x < y ? -1 : 1; + }); + return costumes; +}; + // IDE_Morph menu actions IDE_Morph.prototype.aboutSnap = function () { diff --git a/history.txt b/history.txt index 8486b1a..d1fea7e 100755 --- a/history.txt +++ b/history.txt @@ -2075,3 +2075,7 @@ ______ ------ * Threads: Fixed #313. “Block of sprite” now works for interpolated (“timed”) blocks and for reporters (i.e. SAY FOR, THINK FOR, GLIDE, ASK etc.) * Morphic: replace deprecated DOM “body” references with “documentElement” + +140204 +------ +* GUI: Import costumes and background from the project menu, thanks, Brian, for the changeset! |
