Mercurial > hg > forks > multipaint-js
comparison events.pde @ 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 | caefc3c9e78c |
children | 2d2e313882b4 |
comparison
equal
deleted
inserted
replaced
228:c9a77d87e380 | 229:4f26dc75c448 |
---|---|
925 } | 925 } |
926 | 926 |
927 restoreparameters(); | 927 restoreparameters(); |
928 } | 928 } |
929 | 929 |
930 if (g_data[int('e')] == 1) | |
931 g_data[int('e')] = 0; | |
932 | |
933 if (g_data[int('h')] == 1) | 930 if (g_data[int('h')] == 1) |
934 { | 931 { |
935 g_data[int('h')] = 0; | 932 g_data[int('h')] = 0; |
936 g_bsize--; | 933 g_bsize--; |
937 if (g_bsize < 0) g_bsize = 0; | 934 if (g_bsize < 0) g_bsize = 0; |
1014 message("SAVED"); | 1011 message("SAVED"); |
1015 else | 1012 else |
1016 message("ERROR!"); | 1013 message("ERROR!"); |
1017 } | 1014 } |
1018 | 1015 |
1016 if (g_data[int('e')] == 1) | |
1017 { | |
1018 g_data[int('e')] = 0; | |
1019 | |
1020 if (g_control) | |
1021 { | |
1022 message("PNG export|"+ (g_data[int('Q')] ? "w/border" : "w/o border")); | |
1023 | |
1024 String fname = filename +"_"+ (g_spare ? "spare" : "main") +".png"; | |
1025 PImage simg = mpRenderImage(g_data[int('Q')], 64, 32, 1); | |
1026 | |
1027 if (simg !== null) | |
1028 { | |
1029 simg.sourceImg.toBlob(function(idata){ mpSaveBinaryBlob(fname, idata); }, "image/png", 0.95); | |
1030 } | |
1031 } | |
1032 else | |
1033 { | |
1034 message("PNG/JPEG|import"); | |
1035 mpLoadFileSelector("PNG/JPEG image", ".png,.jpg,.jpeg,.gif", | |
1036 function (fh, fdata) | |
1037 { | |
1038 var fblob = new Blob([fdata], {'type': 'image/png'}) | |
1039 var furl = URL.createObjectURL(fblob); | |
1040 var fimg = new Image; | |
1041 fimg.onload = function() | |
1042 { | |
1043 PImage ftmpi = new PImage(fimg); | |
1044 if (ftmpi != null) | |
1045 { | |
1046 store_undo(); | |
1047 if (mpImportAnyImage(ftmpi)) | |
1048 { | |
1049 filename = fh.name; | |
1050 refresh(); | |
1051 } | |
1052 else | |
1053 { | |
1054 restore_undo(); | |
1055 message("COULD NOT IMPORT."); | |
1056 } | |
1057 } | |
1058 else | |
1059 message("COULD NOT LOAD."); | |
1060 } | |
1061 fimg.src = furl; | |
1062 }); | |
1063 } | |
1064 } | |
1065 | |
1019 if (g_data[int('E')] == 1) | 1066 if (g_data[int('E')] == 1) |
1020 { | 1067 { |
1021 g_data[int('E')] = 0; | 1068 g_data[int('E')] = 0; |
1022 | 1069 |
1023 // message("Export SRC|is disabled"); | 1070 // message("Export SRC|is disabled"); |
1067 | 1114 |
1068 if (g_data[int('W')] == 1) | 1115 if (g_data[int('W')] == 1) |
1069 { | 1116 { |
1070 g_data[int('W')] = 0; | 1117 g_data[int('W')] = 0; |
1071 | 1118 |
1072 if (g_alt) | |
1073 { | |
1074 message("PNG|export"); | |
1075 | |
1076 String fname = filename +"_"+ (g_spare ? "spare" : "main") +".png"; | |
1077 PImage simg = mpRenderImage(true, 64, 32, 1); | |
1078 | |
1079 if (simg !== null) | |
1080 { | |
1081 simg.sourceImg.toBlob(function(idata){ mpSaveBinaryBlob(fname, idata); }, "image/png", 0.95); | |
1082 } | |
1083 } | |
1084 else | |
1085 if (g_formatext != "") | 1119 if (g_formatext != "") |
1086 { | 1120 { |
1087 message("Format|export"); | 1121 message("Format|export"); |
1088 | 1122 |
1089 String fname = filename +"_"+ (g_spare ? "spare" : "main") +"."+ g_formatext; | 1123 String fname = filename +"_"+ (g_spare ? "spare" : "main") +"."+ g_formatext; |