Added screenshot item to Stage's context menu

This commit is contained in:
Nathan Dinsmore 2014-05-10 20:03:54 -04:00
parent 9be7d2e86e
commit 4aeeda9f43

View file

@ -25,14 +25,17 @@
package scratch {
import flash.display.*;
import flash.external.ExternalInterface;
import flash.filters.GlowFilter;
import flash.geom.*;
import flash.filters.GlowFilter;
import flash.geom.*;
import flash.media.*;
import flash.events.*;
import flash.system.Capabilities;
import flash.utils.ByteArray;
import flash.net.FileReference;
import blocks.Block;
import filters.FilterPack;
import translation.Translator;
import uiwidgets.Menu;
import ui.media.MediaInfo;
import util.*;
import watchers.*;
@ -210,6 +213,22 @@ public class ScratchStage extends ScratchObj {
for each (var c:DisplayObject in toDelete) uiLayer.removeChild(c);
}
/* Menu */
public function menu(evt:MouseEvent):Menu {
var m:Menu = new Menu();
m.addItem('save picture of stage', saveScreenshot);
return m;
}
private function saveScreenshot():void {
var bitmapData:BitmapData = new BitmapData(480, 360, true, 0x0);
bitmapData.draw(this);
var pngData:ByteArray = PNG24Encoder.encode(bitmapData, PNGFilter.PAETH);
var file:FileReference = new FileReference();
file.save(pngData, 'stage.png');
}
/* Scrolling support */
public var xScroll:Number = 0;