Mercurial > hg > forks > multipaint-js
changeset 229:4f26dc75c448
Implement freeform image import, key ctrl+e. PNG export is now 'e'.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 05 Sep 2018 22:32:45 +0300 |
parents | c9a77d87e380 |
children | 2d2e313882b4 |
files | events.pde mpui.js |
diffstat | 2 files changed, 51 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/events.pde Wed Sep 05 22:28:15 2018 +0300 +++ b/events.pde Wed Sep 05 22:32:45 2018 +0300 @@ -927,9 +927,6 @@ restoreparameters(); } - if (g_data[int('e')] == 1) - g_data[int('e')] = 0; - if (g_data[int('h')] == 1) { g_data[int('h')] = 0; @@ -1016,6 +1013,56 @@ message("ERROR!"); } + if (g_data[int('e')] == 1) + { + g_data[int('e')] = 0; + + if (g_control) + { + message("PNG export|"+ (g_data[int('Q')] ? "w/border" : "w/o border")); + + String fname = filename +"_"+ (g_spare ? "spare" : "main") +".png"; + PImage simg = mpRenderImage(g_data[int('Q')], 64, 32, 1); + + if (simg !== null) + { + simg.sourceImg.toBlob(function(idata){ mpSaveBinaryBlob(fname, idata); }, "image/png", 0.95); + } + } + else + { + message("PNG/JPEG|import"); + mpLoadFileSelector("PNG/JPEG image", ".png,.jpg,.jpeg,.gif", + function (fh, fdata) + { + var fblob = new Blob([fdata], {'type': 'image/png'}) + var furl = URL.createObjectURL(fblob); + var fimg = new Image; + fimg.onload = function() + { + PImage ftmpi = new PImage(fimg); + if (ftmpi != null) + { + store_undo(); + if (mpImportAnyImage(ftmpi)) + { + filename = fh.name; + refresh(); + } + else + { + restore_undo(); + message("COULD NOT IMPORT."); + } + } + else + message("COULD NOT LOAD."); + } + fimg.src = furl; + }); + } + } + if (g_data[int('E')] == 1) { g_data[int('E')] = 0; @@ -1069,19 +1116,6 @@ { g_data[int('W')] = 0; - if (g_alt) - { - message("PNG|export"); - - String fname = filename +"_"+ (g_spare ? "spare" : "main") +".png"; - PImage simg = mpRenderImage(true, 64, 32, 1); - - if (simg !== null) - { - simg.sourceImg.toBlob(function(idata){ mpSaveBinaryBlob(fname, idata); }, "image/png", 0.95); - } - } - else if (g_formatext != "") { message("Format|export");
--- a/mpui.js Wed Sep 05 22:28:15 2018 +0300 +++ b/mpui.js Wed Sep 05 22:32:45 2018 +0300 @@ -241,11 +241,11 @@ "<li>Save as ('s') and Load from ('l') export and import Multipaint workfiles.</li>"+ "<li>When loading/importing, you click on the load icon (or press key) and a HTML file selector button will appear "+ "ON THE BOTTOM. You need to click that, too. Sorry, that can't be automated because of pop-up blocking etc.</li>"+ + "<li>PNG/JPEG/GIF import is key 'e'. PNG export is ctrl+e.</li>"+ "</ul>"+ "<p><b>Existing problems:</b></p>"+ "<ul>"+ "<li>Source code export is not guaranteed to work (it is enabled now, though.)</li>"+ - "<li>PNG/JPEG <b>import</b> does not work. <b>PNG export works now (alt+shift+W or alt+click on format export icon.)</b></li>"+ "<li>The 'magnify' tool works oddly, though I think this issue may exist in the original as well.</li>"+ "<li>The preview window seems to be buggy for wide-pixel (e.g. c64 multicolor) bitmaps.</li>"+ "<li>There may be other bugs .. though I've also fixed few bugs that exist in original Multipaint.</li>"+