# HG changeset patch # User Matti Hamalainen # Date 1530891611 -10800 # Node ID a0d0994e9bace744438f64bc3780a904d9fe628a # Parent 044e3371d44b03eefae8a8b6049447baf5f6c556 Move file operations from draw function to events handling. diff -r 044e3371d44b -r a0d0994e9bac events.pde --- a/events.pde Fri Jul 06 18:20:28 2018 +0300 +++ b/events.pde Fri Jul 06 18:40:11 2018 +0300 @@ -565,15 +565,6 @@ message("Set 2nd|back color"); } } - if (g_data[int('W')] == 1) { - g_data[int('W')] = 0; - if (g_formatext != "") { - exportfmt = true; - message("Format|export"); - } else { - message("None for|" + g_name); - } - } if (g_data[int('N')] == 1) { g_data[int('N')] = 0; if (++g_animspeed > 3) @@ -718,20 +709,7 @@ makecolor(259, g_r[g_map[0]], g_g[g_map[0]], g_b[g_map[0]]); g_boxreconstruct = 2; } - if (g_data[int('E')] == 1) { - g_data[int('E')] = 0; - message("Source|export"); - exportsrc = true; - } - if (g_data[int('A')] == 1) { - g_data[int('A')] = 0; - message("Executable|export"); - exportemu = true; - } - if (g_data[int('w')] == 1) { - g_data[int('w')] = 0; - importfmt = true; - } + if (g_data[int('O')] == 1) { g_data[int('O')] = 0; store_undo(); @@ -804,7 +782,6 @@ refresh(); } - if (machine == SPECTRUM) { if (g_data[int('i')] == 1) { g_data[int('i')] = 0; @@ -825,11 +802,99 @@ } if (g_data[int('l')] == 1) { g_data[int('l')] = 0; - fileselect = true; + + mpLoadFileSelector("Multipaint image", ".mp", + function (fh, fdata) + { + int err = mpSetNativeImage(fdata); + if (err == 0) + { + mpSetTitle(fh.name); + if (g_spare) + sfilename = fh.name; + else + filename = fh.name; + + message("Image loaded"); + refresh(); + } + else + if (err == -2) + message("Wrong|machine!"); + else + message("ERROR!"); + }); } if (g_data[int('s')] == 1) { g_data[int('s')] = 0; - saveas = true; + + String fname = filename +"_"+ (g_spare ? "spare" : "main") +".mp"; + if (mpSaveBinaryFile(fname, mpGetNativeImage())) + message("SAVED"); + else + message("ERROR!"); + } + + if (g_data[int('E')] == 1) { + g_data[int('E')] = 0; + message("Export SRC|is disabled"); +/* + message("Source|export"); + String fname = (g_spare ? sfilename : filename) +"_"+ (g_spare ? "spare" : "main") +".asm"; + byte[] fdata = mpExportMachinePRG(true); + if (fdata != null && mpSaveBinaryFile(fname, fdata)) + message("EXPORTED"); + else + message("COULD NOT|EXPORT"); +*/ + } + + if (g_data[int('A')] == 1) { + g_data[int('A')] = 0; + message("Executable|export"); + + String fname = (g_spare ? sfilename : filename) +"_"+ (g_spare ? "spare" : "main") +"."+ g_exportext; + byte[] fdata = mpExportMachinePRG(false); + if (fdata != null && mpSaveBinaryFile(fname, fdata)) + message("EXPORTED"); + else + message("COULD NOT|EXPORT"); + } + + if (g_data[int('w')] == 1) { + g_data[int('w')] = 0; + + if (g_formatext != "") { + message("Format|import"); + mpLoadFileSelector(g_formatname, g_formatext, + function (fh, fdata) + { + store_undo(); + filename = fh.name; + mpImportFormat(fdata); + refresh(); + }); + } + else + message("None for|"+ g_name); + } + + if (g_data[int('W')] == 1) + { + g_data[int('W')] = 0; + if (g_formatext != "") { + message("Format|export"); + + byte[] fdata = mpExportFormat(0); // XXX TODO + String fname = filename +"_"+ (g_spare ? "spare" : "main") +"."+ g_formatext; + + if (fdata != null && mpSaveBinaryFile(fname, fdata)) + message("EXPORTED"); + else + message("COULD NOT|EXPORT"); + } else { + message("None for|"+ g_name); + } } if (g_data[int('S')] == 1) @@ -853,7 +918,8 @@ message("Lstorage is not available"); } - if (g_data[int('L')] == 1) { + if (g_data[int('L')] == 1) + { g_data[int('L')] = 0; if (mpHaveLocalStorage()) { diff -r 044e3371d44b -r a0d0994e9bac multipaint.pde --- a/multipaint.pde Fri Jul 06 18:20:28 2018 +0300 +++ b/multipaint.pde Fri Jul 06 18:40:11 2018 +0300 @@ -24,9 +24,7 @@ int g_animx, g_animy, g_animframes, g_animno, g_animtime, g_animspeed; int g_omag, g_bordh, g_bordv, g_keymacpos, g_dirty; -boolean g_control = false, g_shift = false, - fileselect = false, saveas = false, exportsrc = false, - importfmt = false, exportemu = false, exportfmt = false; +boolean g_control = false, g_shift = false; String filename = "", sfilename = "", g_name, g_exportext = "", g_exportname = "", g_keymacro = ""; @@ -499,111 +497,6 @@ if (g_msgctr > 0) g_msgctr--; - // UI file operations - if (fileselect) // Fileselect "event" for Load - { - mpLoadFileSelector("Multipaint image", ".mp", - function (fh, fdata) - { - int err = mpSetNativeImage(fdata); - if (err == 0) - { - mpSetTitle(fh.name); - if (g_spare) - sfilename = fh.name; - else - filename = fh.name; - - message("Image loaded"); - refresh(); - } - else - if (err == -2) - message("Wrong|machine!"); - else - message("ERROR!"); - }); - - fileselect = false; - g_shift = false; - g_control = false; - } - - if (saveas) // Fileselect "event" for Save as - { - String fname = filename +"_"+ (g_spare ? "spare" : "main") +".mp"; - if (mpSaveBinaryFile(fname, mpGetNativeImage())) - message("SAVED"); - else - message("ERROR!"); - - saveas = false; - g_shift = false; - g_control = false; - } - - if (exportsrc) - { - message("Export SRC|is disabled"); -/* - String fname = (g_spare ? sfilename : filename) +"_"+ (g_spare ? "spare" : "main") +".asm"; - byte[] fdata = mpExportMachinePRG(true); - if (fdata != null && mpSaveBinaryFile(fname, fdata)) - message("EXPORTED"); - else - message("COULD NOT|EXPORT"); -*/ - - exportsrc = false; - g_shift = false; - g_control = false; - } - - if (exportemu) - { - String fname = (g_spare ? sfilename : filename) +"_"+ (g_spare ? "spare" : "main") +"."+ g_exportext; - byte[] fdata = mpExportMachinePRG(false); - if (fdata != null && mpSaveBinaryFile(fname, fdata)) - message("EXPORTED"); - else - message("COULD NOT|EXPORT"); - - exportemu = false; - g_shift = false; - g_control = false; - } - - if (importfmt) - { - mpLoadFileSelector(g_formatname, g_formatext, - function (fh, fdata) - { - store_undo(); - filename = fh.name; - mpImportFormat(fdata); - refresh(); - }); - - importfmt = false; - g_shift = false; - g_control = false; - } - - if (exportfmt) - { - byte[] fdata = mpExportFormat(0); // XXX TODO - String fname = filename +"_"+ (g_spare ? "spare" : "main") +"."+ g_formatext; - - if (fdata != null && mpSaveBinaryFile(fname, fdata)) - message("EXPORTED"); - else - message("COULD NOT|EXPORT"); - - exportfmt = false; - g_shift = false; - g_control = false; - } - if (g_keymacro.length() > g_keymacpos) { macro_command(g_keymacro.charAt(g_keymacpos)); g_keymacpos++;