diff options
| author | Michael Ball <cycomachead@gmail.com> | 2014-06-21 11:37:25 -0700 |
|---|---|---|
| committer | Michael Ball <cycomachead@gmail.com> | 2014-06-21 11:37:25 -0700 |
| commit | ec8b14a3758acfc852a6f02010394bd5814d7272 (patch) | |
| tree | 2589fd29d40516c3a5c171a5aca6fcff80b7cff9 | |
| parent | bf03185eb083ea4171121d25ffda3041d91be8e7 (diff) | |
| parent | 7f8d5a3d1eacdc78f61da8e82ac481bbbb825938 (diff) | |
| download | snap-yow-ec8b14a3758acfc852a6f02010394bd5814d7272.tar.gz snap-yow-ec8b14a3758acfc852a6f02010394bd5814d7272.zip | |
Merge pull request #34 from jmoenig/master
updating cs10 branch from jmoenig 0614
| -rw-r--r-- | blocks.js | 52 | ||||
| -rw-r--r-- | byob.js | 86 | ||||
| -rw-r--r-- | cloud.js | 15 | ||||
| -rw-r--r-- | gui.js | 76 | ||||
| -rwxr-xr-x | history.txt | 33 | ||||
| -rw-r--r-- | lang-de.js | 10 | ||||
| -rwxr-xr-x | lang-pt.js | 86 | ||||
| -rw-r--r-- | lists.js | 4 | ||||
| -rw-r--r-- | locale.js | 6 | ||||
| -rw-r--r-- | objects.js | 225 | ||||
| -rw-r--r-- | paint.js | 59 | ||||
| -rw-r--r-- | store.js | 4 | ||||
| -rw-r--r-- | threads.js | 4 |
13 files changed, 601 insertions, 59 deletions
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph, Costume*/ // Global stuff //////////////////////////////////////////////////////// -modules.blocks = '2014-May-02'; +modules.blocks = '2014-June-06'; var SyntaxElementMorph; @@ -913,17 +913,13 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { part = new InputSlotMorph( null, false, - { - /* - color : 'color', - fisheye : 'fisheye', - whirl : 'whirl', - pixelate : 'pixelate', - mosaic : 'mosaic', - brightness : 'brightness', - */ - ghost : ['ghost'] - }, + { brightness : ['brightness'], + ghost : ['ghost'], + negative : ['negative'], + comic: ['comic'], + duplicate: ['duplicate'], + confetti: ['confetti'] + }, true ); part.setContents(['ghost']); @@ -2013,6 +2009,7 @@ BlockMorph.prototype.userMenu = function () { var menu = new MenuMorph(this), world = this.world(), myself = this, + alternatives, blck; menu.addItem( @@ -2070,6 +2067,14 @@ BlockMorph.prototype.userMenu = function () { ); } ); + } else if (this.definition && this.alternatives) { // custom block + alternatives = this.alternatives(); + if (alternatives.length > 0) { + menu.addItem( + 'relabel...', + function () {myself.relabel(alternatives); } + ); + } } menu.addItem( @@ -2268,6 +2273,7 @@ BlockMorph.prototype.relabel = function (alternativeSelectors) { alternativeSelectors.forEach(function (sel) { var block = SpriteMorph.prototype.blockForSelector(sel); block.restoreInputs(oldInputs); + block.fixBlockColor(null, true); block.addShadow(new Point(3, 3)); menu.addItem( block, @@ -2287,7 +2293,7 @@ BlockMorph.prototype.setSelector = function (aSelector) { var oldInputs = this.inputs(), info; info = SpriteMorph.prototype.blocks[aSelector]; - this.category = info.category; + this.setCategory(info.category); this.selector = aSelector; this.setSpec(localize(info.spec)); this.restoreInputs(oldInputs); @@ -2299,6 +2305,7 @@ BlockMorph.prototype.restoreInputs = function (oldInputs) { // try to restore my previous inputs when my spec has been changed var i = 0, old, + nb, myself = this; this.inputs().forEach(function (inp) { @@ -2309,7 +2316,14 @@ BlockMorph.prototype.restoreInputs = function (oldInputs) { // original - turns empty numberslots to 0: // inp.setContents(old.evaluate()); // "fix" may be wrong b/c constants - inp.setContents(old.contents().text); + if (old.contents) { + inp.setContents(old.contents().text); + } + } else if (old instanceof CSlotMorph && inp instanceof CSlotMorph) { + nb = old.nestedBlock(); + if (nb) { + inp.nestedBlock(nb.fullCopy()); + } } i += 1; }); @@ -4957,6 +4971,14 @@ ScriptsMorph.prototype.cleanUp = function () { }; ScriptsMorph.prototype.exportScriptsPicture = function () { + var pic = this.scriptsPicture(); + if (pic) { + window.open(pic.toDataURL()); + } +}; + +ScriptsMorph.prototype.scriptsPicture = function () { + // private - answer a canvas containing the pictures of all scripts var boundingBox, pic, ctx; if (this.children.length === 0) {return; } boundingBox = this.children[0].fullBounds(); @@ -4977,7 +4999,7 @@ ScriptsMorph.prototype.exportScriptsPicture = function () { ); } }); - window.open(pic.toDataURL()); + return pic; }; ScriptsMorph.prototype.addComment = function () { @@ -106,7 +106,7 @@ SymbolMorph, isNil*/ // Global stuff //////////////////////////////////////////////////////// -modules.byob = '2014-May-02'; +modules.byob = '2014-Jun-06'; // Declarations @@ -336,6 +336,43 @@ CustomBlockDefinition.prototype.parseSpec = function (spec) { return parts; }; +// CustomBlockDefinition picturing + +CustomBlockDefinition.prototype.scriptsPicture = function () { + var scripts, proto, block, comment; + + scripts = new ScriptsMorph(); + scripts.cleanUpMargin = 10; + proto = new PrototypeHatBlockMorph(this); + proto.setPosition(scripts.position().add(10)); + if (this.comment !== null) { + comment = this.comment.fullCopy(); + proto.comment = comment; + comment.block = proto; + } + if (this.body !== null) { + proto.nextBlock(this.body.expression.fullCopy()); + } + scripts.add(proto); + proto.fixBlockColor(null, true); + this.scripts.forEach(function (element) { + block = element.fullCopy(); + block.setPosition(scripts.position().add(element.position())); + scripts.add(block); + if (block instanceof BlockMorph) { + block.allComments().forEach(function (comment) { + comment.align(block); + }); + } + }); + proto.allComments().forEach(function (comment) { + comment.align(proto); + }); + proto.children[0].fixLayout(); + scripts.fixMultiArgs(); + return scripts.scriptsPicture(); +}; + // CustomCommandBlockMorph ///////////////////////////////////////////// // CustomCommandBlockMorph inherits from CommandBlockMorph: @@ -708,6 +745,7 @@ CustomCommandBlockMorph.prototype.userMenu = function () { } else { menu.addLine(); } + // menu.addItem("export definition...", 'exportBlockDefinition'); menu.addItem("delete block definition...", 'deleteBlockDefinition'); } @@ -809,6 +847,44 @@ CustomCommandBlockMorph.prototype.popUpbubbleHelp = function ( ).popUp(this.world(), this.rightCenter().add(new Point(-8, 0))); }; +// CustomCommandBlockMorph relabelling + +CustomCommandBlockMorph.prototype.relabel = function (alternatives) { + var menu = new MenuMorph(this), + oldInputs = this.inputs().map( + function (each) {return each.fullCopy(); } + ), + myself = this; + alternatives.forEach(function (def) { + var block = def.blockInstance(); + block.restoreInputs(oldInputs); + block.fixBlockColor(null, true); + block.addShadow(new Point(3, 3)); + menu.addItem( + block, + function () { + myself.definition = def; + myself.refresh(); + } + ); + }); + menu.popup(this.world(), this.bottomLeft().subtract(new Point( + 8, + this instanceof CommandBlockMorph ? this.corner : 0 + ))); +}; + +CustomCommandBlockMorph.prototype.alternatives = function () { + var rcvr = this.receiver(), + stage = rcvr.parentThatIsA(StageMorph), + allDefs = rcvr.customBlocks.concat(stage.globalBlocks), + myself = this; + return allDefs.filter(function (each) { + return each !== myself.definition && + each.type === myself.definition.type; + }); +}; + // CustomReporterBlockMorph //////////////////////////////////////////// // CustomReporterBlockMorph inherits from ReporterBlockMorph: @@ -924,6 +1000,14 @@ CustomReporterBlockMorph.prototype.bubbleHelp CustomReporterBlockMorph.prototype.popUpbubbleHelp = CustomCommandBlockMorph.prototype.popUpbubbleHelp; +// CustomReporterBlockMorph relabelling + +CustomReporterBlockMorph.prototype.relabel + = CustomCommandBlockMorph.prototype.relabel; + +CustomReporterBlockMorph.prototype.alternatives + = CustomCommandBlockMorph.prototype.alternatives; + // JaggedBlockMorph //////////////////////////////////////////////////// /* @@ -27,9 +27,10 @@ // Global settings ///////////////////////////////////////////////////// -/*global modules, IDE_Morph, SnapSerializer, hex_sha512, alert, nop*/ +/*global modules, IDE_Morph, SnapSerializer, hex_sha512, alert, nop, +localize*/ -modules.cloud = '2014-January-09'; +modules.cloud = '2014-May-26'; // Global stuff @@ -107,7 +108,7 @@ Cloud.prototype.signup = function ( errorCall.call( null, myself.url + 'SignUp', - 'could not connect to:' + localize('could not connect to:') ); } } @@ -164,7 +165,7 @@ Cloud.prototype.getPublicProject = function ( errorCall.call( null, myself.url + 'Public', - 'could not connect to:' + localize('could not connect to:') ); } } @@ -217,7 +218,7 @@ Cloud.prototype.resetPassword = function ( errorCall.call( null, myself.url + 'ResetPW', - 'could not connect to:' + localize('could not connect to:') ); } } @@ -264,7 +265,7 @@ Cloud.prototype.connect = function ( errorCall.call( null, myself.url, - 'could not connect to:' + localize('could not connect to:') ); } } @@ -533,7 +534,7 @@ Cloud.prototype.callService = function ( errorCall.call( this, request.responseText, - 'Service: ' + serviceName + localize('Service:') + ' ' + localize(serviceName) ); return; } @@ -64,11 +64,12 @@ 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, Audio*/ +sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph, Audio, +SpeechBubbleMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2014-May-20'; +modules.gui = '2014-Jun-04'; // Declarations @@ -2349,6 +2350,15 @@ IDE_Morph.prototype.projectMenu = function () { 'show global custom block definitions as XML\nin a new browser window' ); + if (shiftClicked) { + menu.addItem( + 'Export all scripts as pic...', + function () {myself.exportScriptsPicture(); }, + 'show a picture of all scripts\nand block definitions', + new Color(100, 0, 0) + ); + } + menu.addLine(); menu.addItem( 'Import tools', @@ -2525,6 +2535,7 @@ IDE_Morph.prototype.aboutSnap = function () { + '\n\nNathan Dinsmore: Saving/Loading, Snap-Logo Design, ' + 'countless bugfixes' + '\nKartik Chandra: Paint Editor' + + '\nYuan Yuan: Graphic Effects' + '\nIan Reynolds: UI Design, Event Bindings, ' + 'Sound primitives' + '\nIvan Motyashov: Initial Squeak Porting' @@ -2846,6 +2857,56 @@ IDE_Morph.prototype.exportSprite = function (sprite) { + '</sprites>'); }; +IDE_Morph.prototype.exportScriptsPicture = function () { + var pics = [], + pic, + padding = 20, + w = 0, + h = 0, + y = 0, + ctx; + + // collect all script pics + this.sprites.asArray().forEach(function (sprite) { + pics.push(sprite.image); + pics.push(sprite.scripts.scriptsPicture()); + sprite.customBlocks.forEach(function (def) { + pics.push(def.scriptsPicture()); + }); + }); + pics.push(this.stage.image); + pics.push(this.stage.scripts.scriptsPicture()); + this.stage.customBlocks.forEach(function (def) { + pics.push(def.scriptsPicture()); + }); + + // collect global block pics + this.stage.globalBlocks.forEach(function (def) { + pics.push(def.scriptsPicture()); + }); + + pics = pics.filter(function (each) {return !isNil(each); }); + + // determine dimensions of composite + pics.forEach(function (each) { + w = Math.max(w, each.width); + h += (each.height); + h += padding; + }); + h -= padding; + pic = newCanvas(new Point(w, h)); + ctx = pic.getContext('2d'); + + // draw all parts + pics.forEach(function (each) { + ctx.drawImage(each, 0, y); + y += padding; + y += each.height; + }); + + window.open(pic.toDataURL()); +}; + IDE_Morph.prototype.openProjectString = function (str) { var msg, myself = this; @@ -4533,6 +4594,17 @@ ProjectDialogMorph.prototype.installCloudProjectList = function (pl) { myself.preview.texture = item.Thumbnail || null; myself.preview.cachedTexture = null; myself.preview.drawNew(); + (new SpeechBubbleMorph(new TextMorph( + localize('last changed') + '\n' + item.Updated, + null, + null, + null, + null, + 'center' + ))).popUp( + myself.world(), + myself.preview.rightCenter().add(new Point(2, 0)) + ); } if (item.Public === 'true') { myself.shareButton.hide(); diff --git a/history.txt b/history.txt index 126c11c..02fc2a0 100755 --- a/history.txt +++ b/history.txt @@ -2133,3 +2133,36 @@ ______ * Threads: new Variable data structure, for refactoring upvar references, not yet used anywhere * Objects, GUI: Search Blocks, feature. Thanks, Kyle, for architecting and designing this!!! * Objects, GUI: Keyboard-shortcuts for opening (cmd-o), saving (cmd-s) projects and for finding blocks (cmd-f) + +140526 +------ +* Objects: Fixed #445 (minor search + zoom issues) +* Localization additions and Portuguese translation update, thanks, Manuel! +* GUI, cloud: Show last-changed-timestamp when opening cloud projects + +140604 +------ +* Blocks: refactor “script pics” feature +* BYOB: new scriptsPicture() method for custom block definitions +* GUI: new (hidden) feature: “Export all scripts as pic” (including custom block refs) +* Graphic effects!!! Yay, thanks, Yuan! +* Bug fixes from Nathan, yay, thanks, Nathan!! +* German translation update +* Paint Editor transforms, yay, thanks, Kartik!! + +140605 +------ +* Objects: stop replacing the empty string with the number zero in watchers +* Threads: initialize new variables with zero (instead of null) +* Objects: fixed #465 +* Objects: fixed #457 + +140605 +------ +* Objects: gracefully hide & show the stage, fixed #281 +* Objects: add hide and show blocks to the stage’s “looks” category +* Objects: added more relabelling options to SAY and THINK variants +* Blocks, objects: enable relabelling blocks with C-Slots +* Blocks: enable relabelling blocks across categories +* Objects: more relabelling options for SAY, THINK, ASK +* BYOB, Blocks: relabelling custom blocks (experimental) @@ -185,7 +185,7 @@ SnapTranslator.dict.de = { 'translator_e-mail': 'jens@moenig.org', // optional 'last_changed': - '2014-02-13', // this, too, will appear in the Translators tab + '2014-06-04', // this, too, will appear in the Translators tab // GUI // control bar: @@ -1122,8 +1122,16 @@ SnapTranslator.dict.de = { 'Leer', // graphical effects + 'brightness': + 'Helligeit', 'ghost': 'Durchsichtigkeit', + 'negative': + 'Farbumkehr', + 'comic': + 'Moire', + 'confetti': + 'Farbverschiebung', // keys 'space': @@ -185,7 +185,7 @@ SnapTranslator.dict.pt = { 'translator_e-mail': 'mmsequeira@gmail.com', 'last_changed': - '2014-01-12', + '2014-05-26', // GUI // control bar: @@ -685,6 +685,16 @@ SnapTranslator.dict.pt = { 'Língua…', 'Zoom blocks...': 'Ampliação dos blocos…', + 'Stage size...': + 'Tamanho do palco…', + 'Stage size': + 'Tamanho do palco', + 'Stage width': + 'Largura do palco', + 'Stage height': + 'Altura do palco', + 'Default': + 'Normal', 'Blurred shadows': 'Sombras desfocadas', 'uncheck to use solid drop\nshadows and highlights': @@ -767,6 +777,12 @@ SnapTranslator.dict.pt = { 'Desassinalar para aumentar a velocidade\npermitindo ritmos variáveis das tramas.', 'check for smooth, predictable\nanimations across computers': 'Assinalar para obter animações mais suaves\ne previsíveis de computador para computador.', + 'Flat line ends': + 'Extremos das linhas planos', + 'check for flat ends of lines': + 'Assinalar para que os extremos das linhas\ndesenhadas pela caneta sejam planos.', + 'uncheck for round ends of lines': + 'Desassinalar para que os extremos das linhas\ndesenhadas pela caneta sejam redondos.', // entradas 'with inputs': @@ -1106,8 +1122,16 @@ SnapTranslator.dict.pt = { 'vazio', // efeitos gráficos + 'brightness': + 'brilho', 'ghost': 'fantasma', + 'negative': + 'negativo', + 'comic': + 'ondeado', + 'confetti': + 'cor', // teclas 'space': @@ -1254,20 +1278,74 @@ SnapTranslator.dict.pt = { 'um item ao acaso', // em falta no ficheiro lang-de.js + 'grow': + 'aumentar', + 'shrink': + 'reduzir', + 'flip ↔': + 'inverter ↔', + 'flip ↕': + 'inverter ↕', + 'Export all scripts as pic...': + 'Exportar todos os guiões como fotografia…', + 'show a picture of all scripts\nand block definitions': + 'Mostra uma imagem com todos\nos guiões e definições de blocos', + 'current %dates': + '%dates corrente', + 'year': + 'ano', + 'month': + 'mês', + 'date': + 'dia', + 'day of week': + 'dia da semana', + 'hour': + 'hora', + 'minute': + 'minuto', + 'second': + 'segundo', + 'time in milliseconds': + 'tempo (em milisegundos)', + 'find blocks...': + 'procurar blocos…', 'costume name': 'o nome do traje', 'Open': 'Abrir', 'Share': 'Partilhar', + 'Snap!Cloud': + 'Snap!Nuvem', 'Cloud': 'Nuvem', + 'could not connect to:': + 'Não foi possível ligar a:', + 'Service:': + 'Serviço:', + 'login': + 'autenticação', + 'ERROR: INVALID PASSWORD': + 'ERRO: PALAVRA-PASSE INVÁLIDA', 'Browser': 'Navegador', 'Sign up': 'Registar nova conta', + 'Signup': + 'Registo de nova conta', 'Sign in': 'Entrar', + 'Logout': + 'Sair', + 'Change Password...': + 'Alterar palavra-passe…', + 'Change Password': + 'Alterar palavra-passe', + 'Account created.': + 'Conta criada.', + 'An e-mail with your password\nhas been sent to the address provided': + 'Foi enviada uma mensagem para\no endereço disponibilizado\ncontendo a sua palavra-passe.', 'now connected.': 'entrou.', 'disconnected.': @@ -1280,6 +1358,12 @@ SnapTranslator.dict.pt = { 'Nome de utilizador:', 'Password:': 'Palavra-passe:', + 'Old password:': + 'Palavra-passe actual:', + 'New password:': + 'Nova palavra-passe:', + 'Repeat new password:': + 'Repita a nova palavra-passe:', 'Birth date:': 'Data de nascimento:', 'January': @@ -61,7 +61,7 @@ PushButtonMorph, SyntaxElementMorph, Color, Point, WatcherMorph, StringMorph, SpriteMorph, ScrollFrameMorph, CellMorph, ArrowMorph, MenuMorph, snapEquals, Morph, isNil, localize, MorphicPreferences*/ -modules.lists = '2014-January-09'; +modules.lists = '2014-Jun-04'; var List; var ListWatcherMorph; @@ -305,7 +305,7 @@ List.prototype.equalTo = function (other) { if (this.length() !== other.length()) { return false; } - for (i = 0; i < this.length(); i += 1) { + for (i = 1; i <= this.length(); i += 1) { if (!snapEquals(this.at(i), other.at(i))) { return false; } @@ -42,7 +42,7 @@ /*global modules, contains*/ -modules.locale = '2014-May-02'; +modules.locale = '2014-Jun-04'; // Global stuff @@ -149,7 +149,7 @@ SnapTranslator.dict.de = { 'translator_e-mail': 'jens@moenig.org', 'last_changed': - '2014-02-13' + '2014-06-04' }; SnapTranslator.dict.it = { @@ -209,7 +209,7 @@ SnapTranslator.dict.pt = { 'translator_e-mail': 'mmsequeira@gmail.com', 'last_changed': - '2014-01-12' + '2014-05-26' }; SnapTranslator.dict.cs = { @@ -61,6 +61,7 @@ sound handling Achal Dave contributed research and prototyping for creating music using the Web Audio API + Yuan Yuan contributed graphic effects for costumes */ @@ -124,7 +125,7 @@ PrototypeHatBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.objects = '2014-May-20'; +modules.objects = '2014-Jun-06'; var SpriteMorph; var StageMorph; @@ -1198,10 +1199,10 @@ SpriteMorph.prototype.blockAlternatives = { yPosition: ['xPosition'], // looks: - doSayFor: ['doThinkFor'], - doThinkFor: ['doSayFor'], - bubble: ['doThink'], - doThink: ['bubble'], + doSayFor: ['doThinkFor', 'bubble', 'doThink', 'doAsk'], + doThinkFor: ['doSayFor', 'doThink', 'bubble', 'doAsk'], + bubble: ['doThink', 'doAsk', 'doSayFor', 'doThinkFor'], + doThink: ['bubble', 'doAsk', 'doSayFor', 'doThinkFor'], show: ['hide'], hide: ['show'], changeEffect: ['setEffect'], @@ -1232,8 +1233,13 @@ SpriteMorph.prototype.blockAlternatives = { receiveClick: ['receiveGo'], doBroadcast: ['doBroadcastAndWait'], doBroadcastAndWait: ['doBroadcast'], + doIf: ['doIfElse', 'doUntil'], + doIfElse: ['doIf', 'doUntil'], + doRepeat: ['doUntil'], + doUntil: ['doRepeat', 'doIf'], // sensing: + doAsk: ['bubble', 'doThink', 'doSayFor', 'doThinkFor'], getLastAnswer: ['getTimer'], getTimer: ['getLastAnswer'], reportMouseX: ['reportMouseY'], @@ -1292,6 +1298,18 @@ SpriteMorph.prototype.init = function (globals) { this.idx = 0; // not to be serialized (!) - used for de-serialization this.wasWarped = false; // not to be serialized, used for fast-tracking + this.graphicsValues = { 'negative': 0, + 'fisheye': 0, + 'whirl': 0, + 'pixelate': 0, + 'mosaic': 0, + 'brightness': 0, + 'color': 0, + 'comic': 0, + 'duplicate': 0, + 'confetti': 0 + }; + SpriteMorph.uber.init.call(this); this.isDraggable = true; @@ -1421,6 +1439,9 @@ SpriteMorph.prototype.drawNew = function () { ctx.rotate(radians(facing - 90)); ctx.drawImage(pic.contents, 0, 0); + // apply graphics effects to image + this.image = this.applyGraphicsEffects(this.image); + // adjust my position to the rotation this.setCenter(currentCenter, true); // just me @@ -1443,6 +1464,7 @@ SpriteMorph.prototype.drawNew = function () { this.setCenter(currentCenter, true); // just me SpriteMorph.uber.drawNew.call(this, facing); this.rotationOffset = this.extent().divideBy(2); + this.image = this.applyGraphicsEffects(this.image); if (isLoadingCostume) { // retry until costume is done loading cst = this.costume; handle = setInterval( @@ -2348,13 +2370,11 @@ SpriteMorph.prototype.searchBlocks = function () { } searchPane.owner = this; - searchPane.padding = unit / 2; searchPane.color = myself.paletteColor; searchPane.contents.color = myself.paletteColor; - searchPane.growth = new Point(0, MorphicPreferences.scrollBarSize); searchPane.addContents(searchBar); searchBar.drawNew(); - searchBar.setWidth(ide.logo.width() - 20); + searchBar.setWidth(ide.logo.width() - 30); searchBar.contrast = 90; searchBar.setPosition( searchPane.contents.topLeft().add(new Point(10, 10)) @@ -2833,14 +2853,132 @@ SpriteMorph.prototype.changeScale = function (delta) { this.setScale(this.getScale() + (+delta || 0)); }; -// SpriteMorph graphic effects +// Spritemorph graphic effects + +SpriteMorph.prototype.graphicsChanged = function () { + var myself = this; + return Object.keys(this.graphicsValues).some( + function (any) { + return myself.graphicsValues[any] < 0 || + myself.graphicsValues[any] > 0; + } + ); +}; + +SpriteMorph.prototype.applyGraphicsEffects = function (canvas) { +// For every effect: apply transform of that effect(canvas, stored value) +// The future: write more effects here + var ctx, imagedata, pixels, newimagedata; + + function transform_negative(p, value) { + var i, rcom, gcom, bcom; + if (value !== 0) { + for (i = 0; i < p.length; i += 4) { + rcom = 255 - p[i]; + gcom = 255 - p[i + 1]; + bcom = 255 - p[i + 2]; + + if (p[i] < rcom) { //compare to the complement + p[i] += value; + } else if (p[i] > rcom) { + p[i] -= value; + } + if (p[i + 1] < gcom) { + p[i + 1] += value; + } else if (p[i + 1] > gcom) { + p[i + 1] -= value; + } + if (p[i + 2] < bcom) { + p[i + 2] += value; + } else if (p[i + 2] > bcom) { + p[i + 2] -= value; + } + } + } + return p; + } + + function transform_brightness(p, value) { + var i; + if (value !== 0) { + for (i = 0; i < p.length; i += 4) { + p[i] += value; //255 = 100% of this color + p[i + 1] += value; + p[i + 2] += value; + } + } + return p; + } + + function transform_comic(p, value) { + var i; + if (value !== 0) { + for (i = 0; i < p.length; i += 4) { + p[i] += Math.sin(i * value) * 127 + 128; + p[i + 1] += Math.sin(i * value) * 127 + 128; + p[i + 2] += Math.sin(i * value) * 127 + 128; + } + } + return p; + } + + function transform_duplicate(p, value) { + var i; + if (value !== 0) { + for (i = 0; i < p.length; i += 4) { + p[i] = p[i * value]; + p[i + 1] = p[i * value + 1]; + p[i + 2] = p[i * value + 2]; + p[i + 3] = p[i * value + 3]; + } + } + return p; + } + + function transform_confetti(p, value) { + var i; + if (value !== 0) { + for (i = 0; i < p.length; i += 1) { + p[i] = Math.sin(value * p[i]) * 127 + p[i]; + } + } + return p; + } + + if (this.graphicsChanged()) { + ctx = canvas.getContext("2d"); + imagedata = ctx.getImageData(0, 0, canvas.width, canvas.height); + pixels = imagedata.data; + + //A sprite should wear all 7 effects at once + /*pixels = transform_whirl(pixels, this.graphicsValues.whirl);*/ + pixels = transform_negative(pixels, this.graphicsValues.negative); + pixels = transform_brightness(pixels, this.graphicsValues.brightness); + pixels = transform_comic(pixels, this.graphicsValues.comic); + /*pixels = transform_pixelate(pixels, this.graphicsValues.pixelate);*/ + pixels = transform_duplicate(pixels, this.graphicsValues.duplicate); + /*pixels = transform_color(pixels, this.graphicsValues.color);*/ + /*pixels = transform_fisheye(pixels, this.graphicsValues.fisheye);*/ + pixels = transform_confetti(pixels, this.graphicsValues.confetti); + + //the last object will have all the transformations done on it + newimagedata = ctx.createImageData(imagedata); //make imgdata object + newimagedata.data.set(pixels); //add transformed pixels + ctx.putImageData(newimagedata, 0, 0); + } + + return canvas; +}; SpriteMorph.prototype.setEffect = function (effect, value) { var eff = effect instanceof Array ? effect[0] : null; if (eff === 'ghost') { this.alpha = 1 - Math.min(Math.max(+value || 0, 0), 100) / 100; - this.changed(); + } else { + this.graphicsValues[eff] = value; } + this.drawNew(); + this.changed(); }; SpriteMorph.prototype.getGhostEffect = function () { @@ -2851,10 +2989,18 @@ SpriteMorph.prototype.changeEffect = function (effect, value) { var eff = effect instanceof Array ? effect[0] : null; if (eff === 'ghost') { this.setEffect(effect, this.getGhostEffect() + (+value || 0)); + } else { + this.setEffect(effect, this.graphicsValues[eff] + value); } }; SpriteMorph.prototype.clearEffects = function () { + var effect; + for (effect in this.graphicsValues) { + if (this.graphicsValues.hasOwnProperty(effect)) { + this.setEffect([effect], 0); + } + } this.setEffect(['ghost'], 0); }; @@ -3063,11 +3209,12 @@ SpriteMorph.prototype.forward = function (steps) { SpriteMorph.prototype.setHeading = function (degrees) { var x = this.xPosition(), y = this.yPosition(), - turn = degrees - this.heading; + dir = (+degrees || 0), + turn = dir - this.heading; // apply to myself this.changed(); - SpriteMorph.uber.setHeading.call(this, degrees); + SpriteMorph.uber.setHeading.call(this, dir); this.silentGotoXY(x, y, true); // just me this.positionTalkBubble(); @@ -4002,12 +4149,24 @@ StageMorph.prototype.init = function (globals) { this.keysPressed = {}; // for handling keyboard events, do not persist this.blocksCache = {}; // not to be serialized (!) this.paletteCache = {}; // not to be serialized (!) - this.lastAnswer = null; // last user input, do not persist + this.lastAnswer = ''; // last user input, do not persist this.activeSounds = []; // do not persist this.trailsCanvas = null; this.isThreadSafe = false; + this.graphicsValues = { 'negative': 0, + 'fisheye': 0, + 'whirl': 0, + 'pixelate': 0, + 'mosaic': 0, + 'brightness': 0, + 'color': 0, + 'comic': 0, + 'duplicate': 0, + 'confetti': 0 + }; + StageMorph.uber.init.call(this); this.acceptsDrops = false; @@ -4072,6 +4231,7 @@ StageMorph.prototype.drawNew = function () { (this.width() / this.scale - this.costume.width()) / 2, (this.height() / this.scale - this.costume.height()) / 2 ); + this.image = this.applyGraphicsEffects(this.image); } }; @@ -4397,7 +4557,7 @@ StageMorph.prototype.processKeyEvent = function (event, action) { default: keyName = String.fromCharCode(event.keyCode || event.charCode); if (event.ctrlKey || event.metaKey) { - keyName = 'ctrl ' + keyName; + keyName = 'ctrl ' + (event.shiftKey ? 'shift ' : '') + keyName; } } action.call(this, keyName); @@ -4422,6 +4582,9 @@ StageMorph.prototype.fireKeyEvent = function (key) { if (evt === 'ctrl s') { return this.parentThatIsA(IDE_Morph).save(); } + if (evt === 'ctrl shift s') { + return this.parentThatIsA(IDE_Morph).saveProjectsBrowser(); + } if (evt === 'esc') { return this.fireStopAllEvent(); } @@ -4581,6 +4744,9 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('changeEffect')); blocks.push(block('setEffect')); blocks.push(block('clearEffects')); + blocks.push('-'); + blocks.push(block('show')); + blocks.push(block('hide')); // for debugging: /////////////// @@ -5033,6 +5199,23 @@ StageMorph.prototype.thumbnail = function (extentPoint, excludedSprite) { return trg; }; +// StageMorph hiding and showing: + +/* + override the inherited behavior to recursively hide/show all + children. +*/ + +StageMorph.prototype.hide = function () { + this.isVisible = false; + this.changed(); +}; + +StageMorph.prototype.show = function () { + this.isVisible = true; + this.changed(); +}; + // StageMorph cloning overrice StageMorph.prototype.createClone = nop; @@ -5095,6 +5278,12 @@ StageMorph.prototype.reportCostumes // StageMorph graphic effects +StageMorph.prototype.graphicsChanged + = SpriteMorph.prototype.graphicsChanged; + +StageMorph.prototype.applyGraphicsEffects + = SpriteMorph.prototype.applyGraphicsEffects; + StageMorph.prototype.setEffect = SpriteMorph.prototype.setEffect; @@ -6428,9 +6617,11 @@ WatcherMorph.prototype.update = function () { } else { newValue = this.target[this.getter](); } - num = +newValue; - if (typeof newValue !== 'boolean' && !isNaN(num)) { - newValue = Math.round(newValue * 1000000000) / 1000000000; + if (newValue !== '' && !isNil(newValue)) { + num = +newValue; + if (typeof newValue !== 'boolean' && !isNaN(num)) { + newValue = Math.round(newValue * 1000000000) / 1000000000; + } } if (newValue !== this.currentValue) { this.changed(); @@ -3,12 +3,12 @@ a paint editor for Snap! inspired by the Scratch paint editor. - + written by Kartik Chandra Copyright (C) 2014 by Kartik Chandra - + This file is part of Snap!. - + Snap! is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of @@ -53,6 +53,8 @@ Jan 08 - mouse leave dragging fix (Kartik) Feb 11 - dynamically adjust to stage dimensions (Jens) Apr 30 - localizations (Manuel) + June 3 - transformations (Kartik) + June 4 - tweaks (Jens) */ @@ -66,7 +68,7 @@ // Global stuff //////////////////////////////////////////////////////// -modules.paint = '2014-May-02'; +modules.paint = '2014-June-4'; // Declarations @@ -111,10 +113,10 @@ PaintEditorMorph.prototype.buildContents = function () { this.paper.setExtent(StageMorph.prototype.dimensions); this.addBody(new AlignmentMorph('row', this.padding)); - this.controls = new AlignmentMorph('column', this.padding); + this.controls = new AlignmentMorph('column', this.padding / 2); this.controls.alignment = 'left'; - this.edits = new AlignmentMorph('row', this.padding); + this.edits = new AlignmentMorph('row', this.padding / 2); this.buildEdits(); this.controls.add(this.edits); @@ -133,6 +135,10 @@ PaintEditorMorph.prototype.buildContents = function () { this.buildToolbox(); this.controls.add(this.toolbox); + this.scaleBox = new AlignmentMorph('row', this.padding / 2); + this.buildScaleBox(); + this.controls.add(this.scaleBox); + this.propertiesControls = { colorpicker: null, penSizeSlider: null, @@ -218,6 +224,27 @@ PaintEditorMorph.prototype.buildEdits = function () { this.edits.fixLayout(); }; +PaintEditorMorph.prototype.buildScaleBox = function () { + var paper = this.paper; + this.scaleBox.add(this.pushButton( + "grow", + function () {paper.scale(0.05, 0.05); } + )); + this.scaleBox.add(this.pushButton( + "shrink", + function () {paper.scale(-0.05, -0.05); } + )); + this.scaleBox.add(this.pushButton( + "flip ↔", + function () {paper.scale(-2, 0); } + )); + this.scaleBox.add(this.pushButton( + "flip ↕", + function () {paper.scale(0, -2); } + )); + this.scaleBox.fixLayout(); +}; + PaintEditorMorph.prototype.openIn = function (world, oldim, oldrc, callback) { // Open the editor in a world with an optional image to edit this.oldim = oldim; @@ -558,6 +585,26 @@ PaintCanvasMorph.prototype.init = function (shift) { this.buildContents(); }; +PaintCanvasMorph.prototype.scale = function (x, y) { + this.mask = newCanvas(this.extent()); + var c = newCanvas(this.extent()); + c.getContext("2d").save(); + c.getContext("2d").translate( + this.rotationCenter.x, + this.rotationCenter.y + ); + c.getContext("2d").scale(1 + x, 1 + y); + c.getContext("2d").drawImage( + this.paper, + -this.rotationCenter.x, + -this.rotationCenter.y + ); + c.getContext("2d").restore(); + this.paper = c; + this.drawNew(); + this.changed(); +}; + PaintCanvasMorph.prototype.cacheUndo = function () { var cachecan = newCanvas(this.extent()); this.merge(this.paper, cachecan); @@ -61,7 +61,7 @@ SyntaxElementMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.store = '2014-May-02'; +modules.store = '2014-Jun-04'; // XML_Serializer /////////////////////////////////////////////////////// @@ -1032,7 +1032,7 @@ SnapSerializer.prototype.loadInput = function (model, input, block) { input.setColor(this.loadColor(model.contents)); } else { val = this.loadValue(model); - if (val) { + if (!isNil(val) && input.setContents) { input.setContents(this.loadValue(model)); } } @@ -83,7 +83,7 @@ ArgLabelMorph, localize, XML_Element, hex_sha512*/ // Global stuff //////////////////////////////////////////////////////// -modules.threads = '2014-May-20'; +modules.threads = '2014-Jun-05'; var ThreadManager; var Process; @@ -3054,7 +3054,7 @@ VariableFrame.prototype.getVar = function (name, upvars) { VariableFrame.prototype.addVar = function (name, value) { this.vars[name] = (value === 0 ? 0 : value === false ? false - : value === '' ? '' : value || null); + : value === '' ? '' : value || 0); }; VariableFrame.prototype.deleteVar = function (name) { |
