# HG changeset patch # User Matti Hamalainen # Date 1536175965 -10800 # Node ID 4f26dc75c4485ec80755be982b14a9d6a0d8c677 # Parent c9a77d87e38008bbc6951154de596b96b71959f1 Implement freeform image import, key ctrl+e. PNG export is now 'e'. diff -r c9a77d87e380 -r 4f26dc75c448 events.pde --- 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"); diff -r c9a77d87e380 -r 4f26dc75c448 mpui.js --- 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 @@ "
  • Save as ('s') and Load from ('l') export and import Multipaint workfiles.
  • "+ "
  • 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.
  • "+ + "
  • PNG/JPEG/GIF import is key 'e'. PNG export is ctrl+e.
  • "+ ""+ "

    Existing problems:

    "+ "