diff options
Diffstat (limited to 'gui.js')
| -rw-r--r-- | gui.js | 173 |
1 files changed, 170 insertions, 3 deletions
@@ -64,11 +64,11 @@ standardSettings, Sound, BlockMorph, ToggleMorph, InputSlotDialogMorph, ScriptsMorph, isNil, SymbolMorph, BlockExportDialogMorph, BlockImportDialogMorph, SnapTranslator, localize, List, InputSlotMorph, SnapCloud, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512, -sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph*/ +sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph, Audio*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2014-January-09'; +modules.gui = '2014-February-13'; // Declarations @@ -1447,7 +1447,8 @@ IDE_Morph.prototype.setProjectName = function (string) { // IDE_Morph resizing IDE_Morph.prototype.setExtent = function (point) { - var minExt, + var padding = new Point(430, 110), + minExt, ext; // determine the minimum dimensions making sense for the current mode @@ -1463,7 +1464,12 @@ IDE_Morph.prototype.setExtent = function (point) { } */ minExt = this.isSmallStage ? + padding.add(StageMorph.prototype.dimensions.divideBy(2)) + : padding.add(StageMorph.prototype.dimensions); +/* + minExt = this.isSmallStage ? new Point(700, 350) : new Point(910, 490); +*/ } ext = point.max(minExt); IDE_Morph.uber.setExtent.call(this, ext); @@ -2061,6 +2067,10 @@ IDE_Morph.prototype.settingsMenu = function () { 'Zoom blocks...', 'userSetBlocksScale' ); + menu.addItem( + 'Stage size...', + 'userSetStageSize' + ); menu.addLine(); addPreference( 'Blurred shadows', @@ -2212,6 +2222,16 @@ IDE_Morph.prototype.settingsMenu = function () { 'check for smooth, predictable\nanimations across computers' ); addPreference( + 'Flat line ends', + function () { + SpriteMorph.prototype.useFlatLineEnds = + !SpriteMorph.prototype.useFlatLineEnds; + }, + SpriteMorph.prototype.useFlatLineEnds, + 'uncheck for round ends of lines', + 'check for flat ends of lines' + ); + addPreference( 'Codification support', function () { StageMorph.prototype.enableCodeMapping = @@ -2233,6 +2253,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 +2402,94 @@ 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.addItem( + localize('Sounds') + '...', + function () { + var names = this.getCostumesList('Sounds'), + libMenu = new MenuMorph(this, 'Import sound'); + + function loadSound(name) { + var url = 'Sounds/' + name, + audio = new Audio(); + audio.src = url; + audio.load(); + myself.droppedAudio(audio, name); + } + + names.forEach(function (line) { + if (line.length > 0) { + libMenu.addItem( + line, + function () {loadSound(line); } + ); + } + }); + libMenu.popup(world, pos); + }, + 'Select a sound 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 () { @@ -2598,10 +2705,12 @@ IDE_Morph.prototype.newProject = function () { this.globalVariables = new VariableFrame(); this.currentSprite = new SpriteMorph(this.globalVariables); this.sprites = new List([this.currentSprite]); + StageMorph.prototype.dimensions = new Point(480, 360); StageMorph.prototype.hiddenPrimitives = {}; StageMorph.prototype.codeMappings = {}; StageMorph.prototype.codeHeaders = {}; StageMorph.prototype.enableCodeMapping = false; + SpriteMorph.prototype.useFlatLineEnds = false; this.setProjectName(''); this.projectNotes = ''; this.createStage(); @@ -3366,6 +3475,64 @@ IDE_Morph.prototype.setBlocksScale = function (num) { this.saveSetting('zoom', num); }; +// IDE_Morph stage size manipulation + +IDE_Morph.prototype.userSetStageSize = function () { + new DialogBoxMorph( + this, + this.setStageExtent, + this + ).promptVector( + "Stage size", + StageMorph.prototype.dimensions, + new Point(480, 360), + 'Stage width', + 'Stage height', + this.world(), + null, // pic + null // msg + ); +}; + +IDE_Morph.prototype.setStageExtent = function (aPoint) { + var myself = this, + world = this.world(), + ext = aPoint.max(new Point(480, 180)); + + function zoom() { + myself.step = function () { + var delta = ext.subtract( + StageMorph.prototype.dimensions + ).divideBy(2); + if (delta.abs().lt(new Point(5, 5))) { + StageMorph.prototype.dimensions = ext; + delete myself.step; + } else { + StageMorph.prototype.dimensions = + StageMorph.prototype.dimensions.add(delta); + } + myself.stage.setExtent(StageMorph.prototype.dimensions); + myself.stage.clearPenTrails(); + myself.fixLayout(); + this.setExtent(world.extent()); + }; + } + + this.stageRatio = 1; + this.isSmallStage = false; + this.controlBar.stageSizeButton.refresh(); + this.setExtent(world.extent()); + if (this.isAnimating) { + zoom(); + } else { + StageMorph.prototype.dimensions = ext; + this.stage.setExtent(StageMorph.prototype.dimensions); + this.stage.clearPenTrails(); + this.fixLayout(); + this.setExtent(world.extent()); + } +}; + // IDE_Morph cloud interface IDE_Morph.prototype.initializeCloud = function () { |
