annotate multipaint.pde @ 111:044e3371d44b

Do store_undo() in mpSetNativeImage() when supposedly successfully loading an image, instead of out of the function.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Jul 2018 18:20:28 +0300
parents ae324b1a020f
children a0d0994e9bac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
eb9157c6a067 Update author blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
1 //
eb9157c6a067 Update author blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
2 // Multipaint Metal Edition 22.5.2017
eb9157c6a067 Update author blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
3 // Tero Heikkinen (Dr. TerrorZ)
eb9157c6a067 Update author blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
4 // ProcessingJS port and changes by Matti Hämäläinen (ccr/TNSP)
eb9157c6a067 Update author blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
5 // processing setup draw and file things here
eb9157c6a067 Update author blurb.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
6 //
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
7
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
8 final int C64 = 0, MSX = 5, SPECTRUM = 6, C64M = 10, PLUS4 = 9, PLUS4M = 19, CPC = 2; // supported
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
9 final int TIMEX = 7, JR200 = 8, AMIGA = 11; // experimental or incomplete
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
10 final int C64FLI = 20, C64FLIM = 21; // experimental
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
11 final int PICO8 = 88;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
12 final int FAKEX = 32; // Commodore 64 without attribute limitations
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
13 final int UNIA = 33;
16
f356d9c176a6 ProcessingJS does not provide "platform" variables, we need to define them ourselves.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
14 final int PEESEE = 0, MACOSX = 1, PSJS = 2;
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
15
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
16 //-1 & -1 for normal operation
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
17 int machine = -1; // change this to autoselect
16
f356d9c176a6 ProcessingJS does not provide "platform" variables, we need to define them ourselves.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
18 int platform = PSJS;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
19
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
20 final int COMMAND = 157; // Marq's cmd/ctrl solution
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
21
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
22 int g_active, g_tooltrigger, g_prevtool;
93
aadcd5f7e9dc Misc. cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
23 int g_rband, g_rbang, g_boxreconstruct, g_charlimit;
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
24 int g_animx, g_animy, g_animframes, g_animno, g_animtime, g_animspeed;
72
5e7553e9aee0 Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
25 int g_omag, g_bordh, g_bordv, g_keymacpos, g_dirty;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
26
110
ae324b1a020f Remove some unused globals.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
27 boolean g_control = false, g_shift = false,
ae324b1a020f Remove some unused globals.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
28 fileselect = false, saveas = false, exportsrc = false,
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
29 importfmt = false, exportemu = false, exportfmt = false;
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
30
110
ae324b1a020f Remove some unused globals.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
31 String filename = "", sfilename = "", g_name, g_exportext = "",
ae324b1a020f Remove some unused globals.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
32 g_exportname = "", g_keymacro = "";
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
33
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
34
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
35 int[] g_r = new int[266];
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
36 int[] g_g = new int[266];
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37 int[] g_b = new int[266];
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
38 int[] g_rgb = new int[266];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
39
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
40 byte[] g_map = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
41 byte[] g_fillmap = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
42 byte[] g_sparepage = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
43 byte[] g_swappage = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
44 byte[] g_rmap = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
45 byte[] g_icons = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
46 byte[] g_brush = new byte[88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
47 byte[][] g_undob = new byte[11][88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
48 byte[][] g_undobs = new byte[11][88000];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
49 byte[] g_template = new byte[16384];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
50 byte[] g_redo = new byte[1024];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
51 byte[] g_remdo = new byte[1024];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
52 int[] g_chaup = new int[64];
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
53 byte[] g_data = new byte[1024];
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
54 int[] g_uindex = new int[8];
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
55 int[] g_ubottom = new int[8];
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56 int[] g_utop = new int[8];
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
57 int[] g_magpix = new int[64];
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
58 int[] g_magpiy = new int[64];
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
59
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
60 byte g_realfront, g_realback;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
61
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
62
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
63 //dimensions
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
64 int X, Y, MX, MY;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
65 //generic mouse
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
66 int g_ofx, g_ofy, g_button, g_realbutton, g_klikkeri, g_mx, g_my, g_orx, g_ory, g_msx, g_msy;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
67 //rubberband,mouse
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
68 int g_phase, g_rx, g_ry, g_rx2, g_ry2, g_rubbermode;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
69 int g_prex, g_prey, g_storedcoordx, g_storedcoordy;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
70 //window positioning
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71 int g_windowx, g_windowy, g_maglocx, g_maglocy;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
72 int g_hedge, g_vedge, g_uizoom, g_wzoom;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
73 //icons & gui stuff
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
74 int g_iconx, g_icony, g_piconx, g_picony, g_iconmode;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
75 int g_gridx, g_gridy, g_spare;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
76 int g_farge, g_backg, g_ofarge, g_repanel, g_msgctr;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
77 //machine related color properties
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
78 int g_attrimode, g_britemode, g_multic, g_backmode, g_maxcolors, g_hzoomer;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
79 float g_palsteps;
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
80 //brush, tool parameters
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81 int g_bsourcex, g_bsourcey, g_bsourcex2, g_bsourcey2;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
82 int g_bsize, g_btype;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
83
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
84
83
6524e83c3ba7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
85 void setup()
6524e83c3ba7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
86 {
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
87 g_magpix[0] = 3;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
88 g_magpix[1] = 8;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
89 g_magpix[2] = 16;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
90 g_magpix[10] = 2;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91 g_magpix[11] = 6;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
92 g_magpix[12] = 16;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
93 g_magpix[20] = 4;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
94 g_magpix[21] = 16;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
95 g_magpix[22] = 32;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
96
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
97 g_magpiy[0] = 3;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
98 g_magpiy[1] = 8;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
99 g_magpiy[2] = 16;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
100 g_magpiy[10] = 2;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
101 g_magpiy[11] = 6;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
102 g_magpiy[12] = 16;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
103 g_magpiy[20] = 4;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
104 g_magpiy[21] = 16;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
105 g_magpiy[22] = 32;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
106
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
107 g_omag = 1;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
108 g_bordh = 64;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
109 g_bordv = 32;
25
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
110
36
a39b3c9e5c3b Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
111 // Set up UI
25
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
112 g_uizoom = 2;
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
113 g_animspeed = 1;
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
114
36
a39b3c9e5c3b Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
115 // Get machine from Javascript runner, or default to C64
25
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
116 if (mpMachine)
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
117 machine = mpMachine;
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
118 else
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
119 machine = C64;
13dda1c3ae88 As we launch from a browser now, include the HTML and necessary Javascript
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
120
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
121 switch (g_uizoom) {
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
122 case 1:
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
123 g_wzoom = 2;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
124 size(700, 468);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
125 break;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
126 case 2:
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
127 g_wzoom = 3;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
128 size(1058, 708);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
129 break;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
130 case 3:
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
131 g_wzoom = 4;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
132 size(1460, 950);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
133 break;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
134 }
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
135
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
136 g_hedge = 32 * g_uizoom;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
137 g_vedge = 32 * g_uizoom;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
138
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
139 g_uindex[0] = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
140 g_utop[0] = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
141 g_ubottom[0] = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
142 g_uindex[1] = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
143 g_utop[1] = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
144 g_ubottom[1] = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
145 g_spare = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
146 g_bsize = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
147 g_btype = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
148 g_phase = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
149 g_button = LEFT;
4
a1261cd4c676 Int-ize byte array index references when using character, e.g. arr['A'] -> arr[int('A')]
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
150 g_data[int('f')] = 1;
a1261cd4c676 Int-ize byte array index references when using character, e.g. arr['A'] -> arr[int('A')]
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
151 g_data[int('g')] = 1;
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
152 g_icons = mpLoadBinaryFile("icons.bin");
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
153 set_tool(3);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
154
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
155 g_gridx = 8;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
156 g_gridy = 8;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
157 g_multic = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
158 g_repanel = -2;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
159
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
160 //UI colors
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
161 makecolor(256, 0xff, 0, 0xff);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
162 makecolor(257, 180, 180, 180);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
163 g_rgb[257] = 0xff808080;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
164 makecolor(258, 0, 0, 0);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
165 makecolor(259, 48, 48, 48);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
166 //R,G,B
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 makecolor(260, 255, 0, 0);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
168 makecolor(261, 0, 255, 0);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
169 makecolor(262, 0, 0, 255);
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
170
81
7ee5e0c590bd Clean set_machine() and rename to mpSetupMachine()
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
171 mpSetupMachine(machine);
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
172 g_windowx = width - (g_hedge) - (g_wzoom * X);
7
c848a6133cfc Fix many calculations (divisions) that assume integer variable division
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
173 g_windowx = int(g_windowx / 2);
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
174 g_windowy = height - (g_vedge) - (g_wzoom * Y);
7
c848a6133cfc Fix many calculations (divisions) that assume integer variable division
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
175 g_windowy = int(g_windowy / 2);
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
176
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
177 switcher(3);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
178
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
179 g_map[4] = byte(g_maxcolors - 1);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
180 g_ofarge = g_farge;
7
c848a6133cfc Fix many calculations (divisions) that assume integer variable division
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
181 MX = int(X / 8);
c848a6133cfc Fix many calculations (divisions) that assume integer variable division
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
182 MY = int(Y / 8);
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
183 g_realfront = byte(g_farge);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
184 g_realback = byte(g_backg);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
185
83
6524e83c3ba7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
186 for (int y = 0; y < Y; y++)
6524e83c3ba7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
187 for (int x = 0; x < X; x++)
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
188 absolute_clearpoint(x, y);
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
189
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
190 switcher(2);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
191 noStroke();
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
192 background(g_r[259], g_g[259], g_b[259]);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
193 sussborder();
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
194 setup_raster();
83
6524e83c3ba7 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
195
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
196 message("Multipaint|Metal|v22.5.2017");
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
197 message("*");
89
09c1a4aba305 Set dirty flag on setup.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
198 g_dirty = true;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
199 }
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
200
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
201
101
e5c147a7bf98 Remove fexists(), it's not in use.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
202 void mpSetTitle(String str)
e5c147a7bf98 Remove fexists(), it's not in use.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
203 {
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
204 console.log("TITLE: '" + str + "'");
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
205 }
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
206
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
207
102
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
208 bool mpHaveLocalStorage()
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
209 {
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
210 var test = 'mpLSTest';
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
211 try {
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
212 localStorage.setItem(test, test);
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
213 if (localStorage.getItem(test) == test)
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
214 {
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
215 localStorage.removeItem(test);
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
216 return true;
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
217 }
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
218 }
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
219 catch (e) {
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
220 return false;
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
221 }
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
222 return false;
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
223 }
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
224
287892b5eff8 Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
225
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
226 function mpLoadFileSelector(fmtname, fmtexts, fcallback)
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
227 {
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
228 var mpUI = stGE("mpUI");
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
229 if (mpUI)
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
230 {
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
231 stClearChildren(mpUI);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
232 mpUI.style.background = "red";
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
233 mpUI.style.padding = "0.5em";
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
234
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
235 mobj = stCE("input", "mpFileSelector");
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
236 mobj.type = "file";
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
237 mobj.name = "name";
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
238 mobj.multiple = false;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
239
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
240 if (fmtexts != null)
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
241 mobj.accept = fmtexts;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
242
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
243 stAddEventOb(mobj.name, mobj, "change",
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
244 function(evt)
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
245 {
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
246 var files = evt.target.files;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
247 if (files.length > 0)
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
248 {
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
249 var freader = new FileReader();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
250
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
251 freader.onloadend = (function(theFile) {
58
8c47708f0196 Oops, forgot to commit this.
Matti Hamalainen <ccr@tnsp.org>
parents: 56
diff changeset
252 fcallback(theFile, new Uint8Array(freader.result));
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
253 });
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
254
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
255 freader.readAsArrayBuffer(files[0]);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
256 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
257 stClearChildren(mpUI);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
258 mpUI.style.background = null;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
259 });
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
260
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
261 mpUI.appendChild(mobj);
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
262
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
263 mobj = stCE("span", "mpFileInfo");
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
264 mobj.innerHTML = "Load / import an '<b>"+ fmtname +"</b>' file.";
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
265 mpUI.appendChild(mobj);
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
266 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
267 else
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
268 return null;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
269 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
270
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
271
52
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
272 //
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
273 // Basically the same as Processing loadBytes(), but it seems
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
274 // that Processing.JS's loadBytes() is broken at least in v1.4.8
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
275 // and does not return byte-clean data. So roll a replacement of
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
276 // our own design. --ccr
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
277 //
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
278 byte[] mpLoadBinaryFile(String url)
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
279 {
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
280 var xhr = new XMLHttpRequest();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
281 xhr.open("GET", url, false);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
282 xhr.overrideMimeType("text/plain; charset=x-user-defined");
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
283 xhr.setRequestHeader("If-Modified-Since", "Fri, 01 Jan 1960 00:00:00 GMT");
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
284 xhr.send(null);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
285
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
286 if (xhr.status !== 200 && xhr.status !== 0)
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
287 return null;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
288
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
289 var string = xhr.responseText;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
290 byte[] ret = new byte[string.length];
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
291
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
292 for (var i = 0; i < string.length; i++)
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
293 {
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
294 ret[i] = string.charCodeAt(i) & 0xff;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
295 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
296
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
297 return ret;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
298 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
299
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
300
103
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
301 Blob mpMakeBinaryBlob(byte[] data)
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
302 {
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
303 var blob = null;
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
304 if (data == null)
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
305 return null;
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
306
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
307 if (typeof(data) == "string")
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
308 blob = new Blob([data], {type: "application/octet-stream"});
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
309 else
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
310 if (typeof(data) == "object")
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
311 blob = new Blob([new Uint8Array(data)], {type: "application/octet-stream"});
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
312
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
313 return blob;
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
314 }
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
315
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
316
52
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
317 //
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
318 // "Save" a byte array to file. Basically creates a blob URI
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
319 // and dumps it in the DOM, giving user a download.
4f998eb1700a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
320 //
96
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
321 bool mpSaveBinaryFile(String name, byte[] data)
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
322 {
103
7a889d59b405 Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
323 var blob = mpMakeBinaryBlob(data);
96
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
324 if (blob == null)
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
325 {
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
326 console.log("Could not create BLOB from data.");
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
327 return false;
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
328 }
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
329
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
330 var url = window.URL.createObjectURL(blob);
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
331 if (url == null)
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
332 {
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
333 console.log("Could not create URL from BLOB object.");
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
334 return false;
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
335 }
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
336
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
337 var alink = stCE("a");
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
338 var mpUI = stGE("mpUI");
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
339 stClearChildren(mpUI);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
340 mpUI.appendChild(alink);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
341
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
342 alink.style = "display: none";
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
343 alink.href = url;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
344 alink.download = name;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
345 alink.click();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
346
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
347 window.URL.revokeObjectURL(url);
96
2d4b56e4d966 Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
348 return true;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
349 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
350
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
351
94
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
352 void mpSavePNGImage(String name, int fmt, bool border)
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
353 {
94
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
354 PImage simg = mpRenderImage(border);
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
355 // if (g_data[int('Q')] == 0)
88
03823fa2cb01 Refactor export_image() and export_image_sans_border() to use common code,
Matti Hamalainen <ccr@tnsp.org>
parents: 84
diff changeset
356
94
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
357 if (simg !== null)
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
358 {
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
359 // XXX TODO .. actually save the image, something like ..
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
360 //simg.canvas.toBlob(function(idata){ mpSaveBinaryFile(name, idata); }, "image/png", 0.95);
6e74d45ea620 More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
361 }
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
362 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
363
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
364
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
365 int mpLoadPNGImage(String name)
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
366 {
92
4161d798cb64 Clean up/refactor image (jpeg/png) importing a bit and rename function.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
367 PImage simg = null;
4161d798cb64 Clean up/refactor image (jpeg/png) importing a bit and rename function.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
368 if (simg == null)
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
369 return -1;
92
4161d798cb64 Clean up/refactor image (jpeg/png) importing a bit and rename function.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
370
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
371 int lefth = g_farge;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
372 int righth = g_backg;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
373 storeparameters();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
374
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
375 g_data[int('d')] = 0;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
376 g_data[int('t')] = 0;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
377 g_data[int('b')] = 1; //old IQ
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
378
92
4161d798cb64 Clean up/refactor image (jpeg/png) importing a bit and rename function.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
379 if (!mpImportFromImage(simg))
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
380 return -2;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
381
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
382 restoreparameters();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
383 refreshpalette();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
384 refresh();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
385 g_boxreconstruct = 2;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
386 message("Image|loaded");
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
387 selectcolor(0, lefth);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
388 selectcolor(1, righth);
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
389 return 0;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
390 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
391
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
392
104
73a8773466ae Change mpSaveNativeImage() to mpGetNativeImage().
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
393 byte[] mpGetNativeImage()
53
c551029a7086 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
394 {
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
395 //save the picture page g_map[], make sure some essential parameters are correct
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
396 g_map[3] = byte(machine);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
397 g_map[5] = byte(MX);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
398 g_map[7] = byte(MY);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
399
104
73a8773466ae Change mpSaveNativeImage() to mpGetNativeImage().
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
400 return g_map;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
401 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
402
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
403
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
404 int mpSetNativeImage(byte[] data, bool noError)
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
405 {
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
406 if (data == null)
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
407 return -1;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
408
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
409 if (data[3] != machine && !noError)
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
410 return -2;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
411
111
044e3371d44b Do store_undo() in mpSetNativeImage() when supposedly successfully loading
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
412 store_undo();
044e3371d44b Do store_undo() in mpSetNativeImage() when supposedly successfully loading
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
413
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
414 g_map = data;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
415
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
416 refreshpalette();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
417 consistency();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
418 g_farge = int(g_realfront);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
419 g_ofarge = g_farge;
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
420 g_backg = int(g_realback);
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
421 sussborder();
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
422
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
423 return 0;
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
424 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
425
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
426
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
427 int mpLoadNativeImage(String name, bool noError)
55
7194cdcc9dab Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
428 {
7194cdcc9dab Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
429 return mpSetNativeImage(
7194cdcc9dab Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
430 mpLoadBinaryFile(name), noError);
28
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
431 }
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
432
edcf9039552b Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
433
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
434 void draw()
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
435 {
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
436 if (!focused) {
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
437 g_control = false;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
438 g_shift = false;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
439 }
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
440
72
5e7553e9aee0 Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
441 // If there should be no update, do not update.
73
d2a89e88f958 When in rubberband mode, do not delay screen updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
442 if (!g_dirty && !g_rubbermode)
72
5e7553e9aee0 Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
443 return;
5e7553e9aee0 Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
444 g_dirty = false;
5e7553e9aee0 Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
445
5e7553e9aee0 Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
446 // Animate animbrush
4
a1261cd4c676 Int-ize byte array index references when using character, e.g. arr['A'] -> arr[int('A')]
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
447 if (g_data[int('n')] == 1) {
69
3d40683b367a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
448 if (++g_animtime > 8 - g_animspeed * 2) {
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
449 animbrush_do();
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
450 g_animtime = 0;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
451 }
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
452 }
9
dfdc18b62fab Change the help() function and its usage to have more than one parameter to
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
453
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
454
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
455 // Update some mouse variables
4
a1261cd4c676 Int-ize byte array index references when using character, e.g. arr['A'] -> arr[int('A')]
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
456 if (g_data[int('m')] == 0 && g_data[int('M')] == 0) {
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
457 g_mx = g_msx - g_windowx;
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
458 g_my = g_msy - g_windowy;
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
459 } else {
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
460 g_mx = mouseX;
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
461 g_my = mouseY;
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
462 }
11
c1667eb54808 Cosmetics and indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
463
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
464 g_msx = mouseX;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
465 g_msy = mouseY;
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
466
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
467 // Actual tool drawing
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
468 if (g_tooltrigger == 1) { // comes from mousepressed, or mousedragged
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
469 if (g_mx <= width - g_hedge && g_my <= height - g_vedge)
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
470 do_tool(g_mx, g_my, g_button);
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
471 }
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
472
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
473 switcher(0);
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
474
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
475 for (int i = 0; i < 1024; i++) {
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
476 g_remdo[i] = 0;
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
477 }
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
478
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
479 // Tool drawing for shows
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
480 int lipo = g_button;
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
481 if (tool() != 5) {
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
482 if (g_phase == 0)
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
483 g_button = LEFT;
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
484 do_tool(g_mx, g_my, LEFT);
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
485 }
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
486 if (tool() == 6) doline(g_rx, g_ry, g_rx2, g_ry2, 0);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
487 if (tool() == 7) docircle(g_rx, g_ry, g_rx2, g_ry2);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
488 if (tool() == 8) rectangle(g_rx, g_ry, g_rx2, g_ry2);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
489 g_button = lipo;
39
5e0306ac3575 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
490
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
491 // Screen update stuff
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
492 loadPixels();
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
493 viewport();
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
494 //magport();
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
495 switcher(1);
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
496 update_ui();
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
497 updatePixels();
11
c1667eb54808 Cosmetics and indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
498
40
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
499 if (g_msgctr > 0)
8d2362b6ac12 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
500 g_msgctr--;
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
501
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
502 // UI file operations
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
503 if (fileselect) // Fileselect "event" for Load
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
504 {
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
505 mpLoadFileSelector("Multipaint image", ".mp",
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
506 function (fh, fdata)
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
507 {
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
508 int err = mpSetNativeImage(fdata);
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
509 if (err == 0)
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
510 {
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
511 mpSetTitle(fh.name);
43
df6eecdf1cd4 Clean up g_spare related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
512 if (g_spare)
df6eecdf1cd4 Clean up g_spare related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
513 sfilename = fh.name;
df6eecdf1cd4 Clean up g_spare related things.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
514 else
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
515 filename = fh.name;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
516
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
517 message("Image loaded");
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
518 refresh();
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
519 }
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
520 else
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
521 if (err == -2)
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
522 message("Wrong|machine!");
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
523 else
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
524 message("ERROR!");
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
525 });
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
526
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
527 fileselect = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
528 g_shift = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
529 g_control = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
530 }
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
531
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
532 if (saveas) // Fileselect "event" for Save as
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
533 {
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
534 String fname = filename +"_"+ (g_spare ? "spare" : "main") +".mp";
104
73a8773466ae Change mpSaveNativeImage() to mpGetNativeImage().
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
535 if (mpSaveBinaryFile(fname, mpGetNativeImage()))
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
536 message("SAVED");
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
537 else
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
538 message("ERROR!");
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
539
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
540 saveas = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
541 g_shift = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
542 g_control = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
543 }
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
544
82
d982486e0a85 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
545 if (exportsrc)
56
4eb9ebde8c20 Some more interface cleanupping.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
546 {
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
547 message("Export SRC|is disabled");
59
1628649831cc Disable the TXT and EMU export functionality as they are not working yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
548 /*
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
549 String fname = (g_spare ? sfilename : filename) +"_"+ (g_spare ? "spare" : "main") +".asm";
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
550 byte[] fdata = mpExportMachinePRG(true);
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
551 if (fdata != null && mpSaveBinaryFile(fname, fdata))
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
552 message("EXPORTED");
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
553 else
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
554 message("COULD NOT|EXPORT");
59
1628649831cc Disable the TXT and EMU export functionality as they are not working yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
555 */
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
556
82
d982486e0a85 Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
557 exportsrc = false;
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
558 g_shift = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
559 g_control = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
560 }
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
561
56
4eb9ebde8c20 Some more interface cleanupping.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
562 if (exportemu)
4eb9ebde8c20 Some more interface cleanupping.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
563 {
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
564 String fname = (g_spare ? sfilename : filename) +"_"+ (g_spare ? "spare" : "main") +"."+ g_exportext;
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
565 byte[] fdata = mpExportMachinePRG(false);
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
566 if (fdata != null && mpSaveBinaryFile(fname, fdata))
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
567 message("EXPORTED");
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
568 else
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
569 message("COULD NOT|EXPORT");
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
570
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
571 exportemu = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
572 g_shift = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
573 g_control = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
574 }
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
575
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
576 if (importfmt)
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
577 {
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
578 mpLoadFileSelector(g_formatname, g_formatext,
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
579 function (fh, fdata)
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
580 {
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
581 store_undo();
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
582 filename = fh.name;
84
025efefd1704 Rename few functions and a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
583 mpImportFormat(fdata);
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
584 refresh();
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
585 });
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
586
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
587 importfmt = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
588 g_shift = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
589 g_control = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
590 }
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
591
54
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
592 if (exportfmt)
dee55b8f97a6 Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
593 {
97
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
594 byte[] fdata = mpExportFormat(0); // XXX TODO
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
595 String fname = filename +"_"+ (g_spare ? "spare" : "main") +"."+ g_formatext;
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
596
65e6cacd068c Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
597 if (fdata != null && mpSaveBinaryFile(fname, fdata))
90
dffafe05d520 Refactor mpExportFormat() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
598 message("EXPORTED");
dffafe05d520 Refactor mpExportFormat() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
599 else
dffafe05d520 Refactor mpExportFormat() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
600 message("COULD NOT|EXPORT");
29
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
601
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
602 exportfmt = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
603 g_shift = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
604 g_control = false;
249c4f5742f3 Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
605 }
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
606
2
5eb3559e1778 Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
607 if (g_keymacro.length() > g_keymacpos) {
0
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
608 macro_command(g_keymacro.charAt(g_keymacpos));
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
609 g_keymacpos++;
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
610 }
ebd5689e2985 Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff changeset
611 }