Mercurial > hg > forks > multipaint-js
annotate multipaint.pde @ 188:6fba2c255319
More work on the MP.JS launcher.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 23 Aug 2018 16:32:10 +0300 |
parents | 74e1616ca38e |
children | b36cfb497223 |
rev | line source |
---|---|
35 | 1 // |
159 | 2 // Multipaint.JS 1.8.2018 |
35 | 3 // Tero Heikkinen (Dr. TerrorZ) |
4 // ProcessingJS port and changes by Matti Hämäläinen (ccr/TNSP) | |
5 // processing setup draw and file things here | |
6 // | |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
7 |
148 | 8 // Supported |
176 | 9 final int C64 = 0, MSX = 5, SPECTRUM = 6, C64M = 10, |
10 PLUS4 = 9, PLUS4M = 19, CPC = 2; | |
148 | 11 |
12 // Experimental or incomplete | |
13 final int C64NOLIMIT = 32; // Commodore 64 without attribute limitations | |
14 final int C64FLI = 20, C64FLIM = 21; // incomplete FLI & AFLI modes | |
15 final int TIMEX = 7, JR200 = 8, AMIGA = 11, ATARIST = 12; | |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
16 final int PICO8 = 88; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
17 final int UNIA = 33; |
148 | 18 final int COCO3 = 34; |
19 final int BK0010 = 99; | |
20 final int QLLOW = 66; | |
21 | |
22 // Reserved but completely unimplemented | |
23 final int VIC = 22; // VIC-20 | |
24 final int CGA = 23; // 320 x 200 PC CGA screen with black, white, cyan, magenta | |
25 final int CGAX = 24; // 320 x 200 PC CGA screen with black, yellow, green, red-ish | |
26 final int EGA = 200; // 320 x 200 PC EGA screen, 16 colors of 64 | |
27 final int VGA = 255; // 320 x 200 PC VGA screen, 256 colors of 65536 | |
28 final int NES = 90; // 8-bit NES | |
29 final int SEGAM = 91; // 8-bit Sega Master System | |
30 | |
176 | 31 final int GRIDMODE_OLD = 0; |
32 final int GRIDMODE_NEW = 1; | |
33 final int AR_FLAT = 1; | |
34 final int AR_SQUARE = 0; | |
35 | |
16
f356d9c176a6
ProcessingJS does not provide "platform" variables, we need to define them ourselves.
Matti Hamalainen <ccr@tnsp.org>
parents:
15
diff
changeset
|
36 final int PEESEE = 0, MACOSX = 1, PSJS = 2; |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
37 final int COMMAND = 157; // Marq's cmd/ctrl solution |
69 | 38 |
179
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
39 int g_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
|
40 int platform = PSJS; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
41 |
133
f5c32f6470d0
Begin integrating more changes from Multipaint 1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
42 int[] g_grids = new int[16]; |
f5c32f6470d0
Begin integrating more changes from Multipaint 1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
43 |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
44 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
|
45 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
|
46 int[] g_b = new int[266]; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
47 int[] g_rgb = new int[266]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
48 |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
49 byte[] g_map = new byte[88000]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
50 byte[] g_fillmap = new byte[88000]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
51 byte[] g_rmap = new byte[88000]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
52 byte[] g_icons = new byte[88000]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
53 byte[] g_brush = new byte[88000]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
54 byte[] g_template = new byte[16384]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
55 byte[] g_redo = new byte[1024]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
56 byte[] g_remdo = new byte[1024]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
57 int[] g_chaup = new int[64]; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
58 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
|
59 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
|
60 int[] g_magpiy = new int[64]; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
61 |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
62 byte g_realfront, g_realback; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
63 |
176 | 64 int g_tooltrigger, g_prevtool, g_rband, g_rbang, g_boxreconstruct, |
65 g_charlimit, g_animx, g_animy, g_animframes, g_animno, g_animtime, | |
182
55a3fee48fe1
Implement UI resolution changer.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
66 g_animspeed, g_keymacpos, g_forced_width, g_forced_height, |
55a3fee48fe1
Implement UI resolution changer.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
67 g_hadjust, g_vadjust; |
176 | 68 |
69 int g_wheelup = int(':'), g_wheeldown = int(';'), g_middlebutton = int(','); | |
70 int g_gridmode = GRIDMODE_OLD; | |
71 int g_pixelw = 1; | |
72 int g_aspect = AR_SQUARE; | |
73 | |
74 boolean g_control = false, g_shift = false, | |
75 g_dirty, g_inhibit_aspect = false; | |
76 | |
77 String g_formatname, g_formatext, | |
78 filename = "", sfilename = "", | |
79 g_name, g_exportext = "", | |
80 g_exportname = "", g_keymacro = "", | |
81 g_forced_palette = ""; | |
82 | |
69 | 83 |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
84 //dimensions |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
85 int X, Y, MX, MY; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
86 //generic mouse |
154 | 87 boolean g_klikkeri, g_iconmode = false; |
143 | 88 int g_ofx, g_ofy, g_button, g_realbutton, 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
|
89 //rubberband,mouse |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 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
|
91 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
|
92 //window positioning |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
93 int g_windowx, g_windowy, g_maglocx, g_maglocy; |
183
1cb7ecd73554
Rename global variable g_uizoom to g_uiscale and mpUIZoom -> mpUIScale.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
94 int g_hedge, g_vedge, g_uiscale, g_wzoom; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
95 //icons & gui stuff |
154 | 96 int g_iconx, g_icony, g_piconx, g_picony; |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
97 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
|
98 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
|
99 //machine related color properties |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
100 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
|
101 float g_palsteps; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
102 //brush, tool parameters |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
103 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
|
104 int g_bsize, g_btype; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
105 |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
106 |
83 | 107 void setup() |
108 { | |
176 | 109 // Get settings from Javascript runner, or use defaults |
179
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
110 g_machine = (mpMachine >= 0) ? mpMachine : C64; |
183
1cb7ecd73554
Rename global variable g_uizoom to g_uiscale and mpUIZoom -> mpUIScale.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
111 g_uiscale = (mpUIScale >= 1 && mpUIScale <= 3) ? mpUIScale : 2; |
188
6fba2c255319
More work on the MP.JS launcher.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
112 g_forced_width = mpUIForcedWidth > 0 ? mpUIForcedWidth : 0; |
6fba2c255319
More work on the MP.JS launcher.
Matti Hamalainen <ccr@tnsp.org>
parents:
186
diff
changeset
|
113 g_forced_height = mpUIForcedHeight > 0 ? mpUIForcedHeight : 0; |
176 | 114 g_animspeed = 1; |
115 | |
148 | 116 //normi |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
117 g_magpix[0] = 3; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
118 g_magpix[1] = 8; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
119 g_magpix[2] = 16; |
148 | 120 g_magpiy[0] = 3; |
121 g_magpiy[1] = 8; | |
122 g_magpiy[2] = 16; | |
123 | |
124 //mini | |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
125 g_magpix[10] = 2; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
126 g_magpix[11] = 6; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
127 g_magpix[12] = 16; |
148 | 128 g_magpiy[10] = 2; |
129 g_magpiy[11] = 6; | |
130 g_magpiy[12] = 16; | |
131 | |
132 //maxi | |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
133 g_magpix[20] = 4; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
134 g_magpix[21] = 16; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
135 g_magpix[22] = 32; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
136 g_magpiy[20] = 4; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
137 g_magpiy[21] = 16; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
138 g_magpiy[22] = 32; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
139 |
148 | 140 //FLAT normi |
141 g_magpix[100] = 3; | |
142 g_magpix[101] = 9; | |
143 g_magpix[102] = 12; | |
144 g_magpiy[100] = 2; | |
145 g_magpiy[101] = 6; | |
146 g_magpiy[102] = 8; | |
147 | |
148 //FLAT mini | |
149 g_magpix[110] = 3; | |
150 g_magpix[111] = 9; | |
151 g_magpix[112] = 12; | |
152 g_magpiy[110] = 2; | |
153 g_magpiy[111] = 6; | |
154 g_magpiy[112] = 8; | |
155 | |
156 //FLAT maxi | |
157 g_magpix[120] = 6; | |
158 g_magpix[121] = 12; | |
159 g_magpix[122] = 21; | |
160 g_magpiy[120] = 4; | |
161 g_magpiy[121] = 8; | |
162 g_magpiy[122] = 14; | |
163 | |
176 | 164 // Setup other stuff |
183
1cb7ecd73554
Rename global variable g_uizoom to g_uiscale and mpUIZoom -> mpUIScale.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
165 if (g_uiscale >= 1 && g_uiscale <= 3) |
1cb7ecd73554
Rename global variable g_uizoom to g_uiscale and mpUIZoom -> mpUIScale.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
166 g_wzoom = g_uiscale + 1; |
148 | 167 |
183
1cb7ecd73554
Rename global variable g_uizoom to g_uiscale and mpUIZoom -> mpUIScale.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
168 g_hedge = 32 * g_uiscale; |
1cb7ecd73554
Rename global variable g_uizoom to g_uiscale and mpUIZoom -> mpUIScale.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
169 g_vedge = 32 * g_uiscale; |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
170 |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
171 g_spare = 0; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
172 g_bsize = 0; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
173 g_btype = 0; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
174 g_phase = 0; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
175 g_button = LEFT; |
148 | 176 |
177 g_data[int('f')] = 1; // fill on | |
178 g_data[int('g')] = 1; // grid on | |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
179 g_data[int('m')] = 0; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
180 g_data[int('M')] = 0; // mags off |
148 | 181 |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
182 set_tool(3); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
183 |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
184 g_gridx = 8; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
185 g_gridy = 8; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
186 g_multic = 0; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
187 g_repanel = -2; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
188 |
179
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
189 mpSetupMachine(g_machine); |
162 | 190 mpSetUIColors(); |
179
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
191 |
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
192 g_icons = mpLoadBinaryFile("icons.bin"); |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
193 |
176 | 194 if (g_forced_palette.length() > 3) |
195 mpLoadPalette(g_forced_palette); | |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
196 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
197 int truwinsizex = X * g_magpix[magmode()]; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
198 int truwinsizey = Y * g_magpiy[magmode()]; |
176 | 199 |
200 if (g_forced_width == 0 || g_forced_height == 0) | |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
201 { |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
202 g_hadjust = 0; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
203 g_vadjust = 0; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
204 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
205 int hsize = truwinsizex + g_hedge + (22) * g_wzoom; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
206 int vsize = truwinsizey + g_vedge + (14) * g_wzoom; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
207 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
208 while (vsize - g_vedge < (12 * 16) * g_wzoom) |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
209 vsize += 2; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
210 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
211 while (hsize - g_hedge < (17 * 16) * g_wzoom) |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
212 hsize += 2; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
213 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
214 size(hsize, vsize); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
215 } |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
216 |
176 | 217 if (g_forced_width > 800 && g_forced_height > 600) |
218 size(g_forced_width, g_forced_height); | |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
219 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
220 if (g_inhibit_aspect) |
172
e77a726a587e
Rename FLATRATIO/SQUARERATIO and gridmode OLD/NEW constants to something more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
221 g_aspect = AR_SQUARE; |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
222 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
223 int paspect = g_wzoom; |
172
e77a726a587e
Rename FLATRATIO/SQUARERATIO and gridmode OLD/NEW constants to something more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
224 if (g_aspect == AR_FLAT) |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
225 { |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
226 if (g_wzoom == 2) paspect = 1; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
227 if (g_wzoom == 3) paspect = 2; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
228 if (g_wzoom == 4) paspect = 3; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
229 } |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
230 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
231 g_windowx = width - (g_hedge) - (truwinsizex); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
232 g_windowx = g_windowx / 2; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
233 g_windowy = height - (g_vedge) - (truwinsizey); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
234 g_windowy = g_windowy / 2; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
235 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
236 if (g_hadjust > 0) |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
237 g_windowx = width - (g_hedge) - (g_wzoom * X) - g_hadjust; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
238 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
239 if (g_vadjust > 0) |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
240 g_windowy = height - (g_vedge) - (paspect * Y) - g_vadjust; |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
241 |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
242 switcher(3); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
243 |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
244 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
|
245 g_ofarge = g_farge; |
7
c848a6133cfc
Fix many calculations (divisions) that assume integer variable division
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
246 MX = int(X / 8); |
c848a6133cfc
Fix many calculations (divisions) that assume integer variable division
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
247 MY = int(Y / 8); |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
248 g_realfront = byte(g_farge); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
249 g_realback = byte(g_backg); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
250 |
83 | 251 for (int y = 0; y < Y; y++) |
252 for (int x = 0; x < X; x++) | |
69 | 253 absolute_clearpoint(x, y); |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
254 |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
255 switcher(2); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
256 noStroke(); |
150 | 257 background(g_r[263], g_g[263], g_b[263]); |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
258 sussborder(); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
259 setup_raster(); |
83 | 260 |
159 | 261 message(" Multipaint| - 2018 -||v1.8.2018.JS"); |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
262 message("*"); |
89 | 263 g_dirty = true; |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
264 } |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
265 |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
266 |
162 | 267 void mpSetUIColors() |
268 { | |
269 // UI colors | |
270 makecolor(256, 0xff, 0, 0xff); | |
271 makecolor(257, 180, 180, 180); | |
272 // g_rgb[257] = 0xff808080; | |
273 makecolor(258, 0, 0, 0); | |
274 makecolor(259, 48, 48, 48); | |
275 | |
276 // R,G and B for the palette sliders | |
277 makecolor(260, 255, 0, 0); | |
278 makecolor(261, 0, 255, 0); | |
279 makecolor(262, 0, 0, 255); | |
280 makecolor(263, 48, 48, 48); //backest UI background | |
281 | |
282 } | |
283 | |
101
e5c147a7bf98
Remove fexists(), it's not in use.
Matti Hamalainen <ccr@tnsp.org>
parents:
97
diff
changeset
|
284 void mpSetTitle(String str) |
e5c147a7bf98
Remove fexists(), it's not in use.
Matti Hamalainen <ccr@tnsp.org>
parents:
97
diff
changeset
|
285 { |
29
249c4f5742f3
Refactor the import/export stuff a bit and the GUI bits for JS.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
286 console.log("TITLE: '" + str + "'"); |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
287 } |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
288 |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
289 |
117
44a07b1c620d
Rename 'bool' -> 'boolean'.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
290 boolean mpHaveLocalStorage() |
102
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
291 { |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
292 var test = 'mpLSTest'; |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
293 try { |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
294 localStorage.setItem(test, test); |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
295 if (localStorage.getItem(test) == test) |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
296 { |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
297 localStorage.removeItem(test); |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
298 return true; |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
299 } |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
300 } |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
301 catch (e) { |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
302 return false; |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
303 } |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
304 return false; |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
305 } |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
306 |
287892b5eff8
Add function for checking availability of browser local storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
307 |
54
dee55b8f97a6
Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
308 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
|
309 { |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
310 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
|
311 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
|
312 { |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 |
54
dee55b8f97a6
Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 |
54
dee55b8f97a6
Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
322 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
|
323 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
|
324 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
325 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
|
326 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
|
327 { |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
328 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
|
329 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
|
330 { |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
331 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
|
332 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
333 freader.onloadend = (function(theFile) { |
58
8c47708f0196
Oops, forgot to commit this.
Matti Hamalainen <ccr@tnsp.org>
parents:
56
diff
changeset
|
334 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
|
335 }); |
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 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
|
338 } |
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.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
|
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 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
343 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
|
344 |
dee55b8f97a6
Use defined format extensions in the file selector. Also display format name
Matti Hamalainen <ccr@tnsp.org>
parents:
53
diff
changeset
|
345 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
|
346 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
|
347 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
|
348 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
349 else |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
350 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
|
351 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
352 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
353 |
52 | 354 // |
355 // Basically the same as Processing loadBytes(), but it seems | |
356 // that Processing.JS's loadBytes() is broken at least in v1.4.8 | |
357 // and does not return byte-clean data. So roll a replacement of | |
358 // our own design. --ccr | |
359 // | |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
360 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
|
361 { |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
368 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
|
369 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
|
370 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
371 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
|
372 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
|
373 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
374 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
|
375 { |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
376 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
|
377 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
378 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
379 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
|
380 } |
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 |
103
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
383 Blob mpMakeBinaryBlob(byte[] data) |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
384 { |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
385 var blob = null; |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
386 if (data == null) |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
387 return null; |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
388 |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
389 if (typeof(data) == "string") |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
390 blob = new Blob([data], {type: "application/octet-stream"}); |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
391 else |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
392 if (typeof(data) == "object") |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
393 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
|
394 |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
395 return blob; |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
396 } |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
397 |
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
398 |
52 | 399 // |
400 // "Save" a byte array to file. Basically creates a blob URI | |
401 // and dumps it in the DOM, giving user a download. | |
402 // | |
117
44a07b1c620d
Rename 'bool' -> 'boolean'.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
403 boolean 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
|
404 { |
103
7a889d59b405
Split Blob creation to mpMakeBinaryBlob().
Matti Hamalainen <ccr@tnsp.org>
parents:
102
diff
changeset
|
405 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
|
406 if (blob == null) |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
407 { |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
408 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
|
409 return false; |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
410 } |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
411 |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
412 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
|
413 if (url == null) |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
414 { |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
415 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
|
416 return false; |
2d4b56e4d966
Improve mpSaveBinaryFile() to also handle string format data. Also improve
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
417 } |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
418 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
419 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
|
420 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
|
421 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
|
422 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
|
423 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
424 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
|
425 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
|
426 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
|
427 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
|
428 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
429 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
|
430 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
|
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 |
175
3ddf4d799fe6
Get rid of globals g_omag, g_bordh and g_bordv which set PNG/JPEG image
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
434 // bordh/v = 64, 32, omag = 1 |
3ddf4d799fe6
Get rid of globals g_omag, g_bordh and g_bordv which set PNG/JPEG image
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
435 void mpSavePNGImage(String name, int fmt, boolean border, int bordh, int bordv, int omag) |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
436 { |
175
3ddf4d799fe6
Get rid of globals g_omag, g_bordh and g_bordv which set PNG/JPEG image
Matti Hamalainen <ccr@tnsp.org>
parents:
172
diff
changeset
|
437 PImage simg = mpRenderImage(border, bordh, bordv, omag); |
94
6e74d45ea620
More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
438 // 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
|
439 |
94
6e74d45ea620
More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
440 if (simg !== null) |
6e74d45ea620
More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
441 { |
6e74d45ea620
More work towards jpeg/png image export/import.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
442 // 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
|
443 //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
|
444 } |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
445 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
446 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
447 |
97
65e6cacd068c
Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
448 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
|
449 { |
92
4161d798cb64
Clean up/refactor image (jpeg/png) importing a bit and rename function.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
450 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
|
451 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
|
452 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
|
453 |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
454 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
|
455 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
|
456 storeparameters(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
457 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
458 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
|
459 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
|
460 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
|
461 |
92
4161d798cb64
Clean up/refactor image (jpeg/png) importing a bit and rename function.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
462 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
|
463 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
|
464 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
465 restoreparameters(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
466 refreshpalette(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
467 refresh(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
468 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
|
469 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
|
470 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
|
471 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
|
472 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
473 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
474 |
104
73a8773466ae
Change mpSaveNativeImage() to mpGetNativeImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
475 byte[] mpGetNativeImage() |
53 | 476 { |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
477 //save the picture page g_map[], make sure some essential parameters are correct |
179
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
478 g_map[3] = byte(g_machine); |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
479 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
|
480 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
|
481 |
104
73a8773466ae
Change mpSaveNativeImage() to mpGetNativeImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
103
diff
changeset
|
482 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
|
483 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
484 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
485 |
117
44a07b1c620d
Rename 'bool' -> 'boolean'.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
486 int mpSetNativeImage(byte[] data, boolean 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
|
487 { |
97
65e6cacd068c
Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
488 if (data == null) |
65e6cacd068c
Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
489 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
|
490 |
179
934934bb1fbb
Rename global variable s/machine/g_machine/g
Matti Hamalainen <ccr@tnsp.org>
parents:
178
diff
changeset
|
491 if (data[3] != g_machine && !noError) |
97
65e6cacd068c
Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
492 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
|
493 |
111
044e3371d44b
Do store_undo() in mpSetNativeImage() when supposedly successfully loading
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
494 store_undo(); |
044e3371d44b
Do store_undo() in mpSetNativeImage() when supposedly successfully loading
Matti Hamalainen <ccr@tnsp.org>
parents:
110
diff
changeset
|
495 |
28
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
496 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
|
497 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
498 refreshpalette(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
499 consistency(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
500 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
|
501 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
|
502 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
|
503 sussborder(); |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
504 |
97
65e6cacd068c
Make PRG export work. Also some improvements in overall error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
505 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
|
506 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
507 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
508 |
117
44a07b1c620d
Rename 'bool' -> 'boolean'.
Matti Hamalainen <ccr@tnsp.org>
parents:
114
diff
changeset
|
509 int mpLoadNativeImage(String name, boolean noError) |
55 | 510 { |
511 return mpSetNativeImage( | |
512 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
|
513 } |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
514 |
edcf9039552b
Add several new helper functions for loading and saving formats using Javascript facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
515 |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
516 boolean mpLoadPalette(String fname) |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
517 { |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
518 if (g_map[13] != C64) |
162 | 519 { |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
520 return false; |
162 | 521 } |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
522 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
523 byte fdata[] = mpLoadbinaryFile(fname); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
524 if (fdata == null || |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
525 fdata.length != 772 || |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
526 fdata[0x301] != byte(0x10) || |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
527 fdata[0x302] != byte(0xff) || |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
528 fdata[0x303] != byte(0xff)) |
162 | 529 { |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
530 return false; |
162 | 531 } |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
532 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
533 for (int n = 0; n < 16; n++) |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
534 { |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
535 makecolor(n, |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
536 int(fdata[n * 3]), |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
537 int(fdata[n * 3 + 1]), |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
538 int(fdata[n * 3 + 2])); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
539 } |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
540 |
162 | 541 mpSetUIColors(); |
153
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
542 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
543 sussborder(); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
544 refresh_all(); |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
545 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
546 return true; |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
547 } |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
548 |
9f4e6f888120
Integrate more changes from v1.8.2018.
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
549 |
69 | 550 void draw() |
551 { | |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
552 if (!focused) |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
553 { |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
554 g_control = false; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
555 g_shift = false; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
556 } |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
557 |
72
5e7553e9aee0
Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
558 // 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
|
559 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
|
560 return; |
5e7553e9aee0
Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
561 g_dirty = false; |
5e7553e9aee0
Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
562 |
5e7553e9aee0
Improve 'dirty' flag for only updating canvas when something changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
563 // Animate animbrush |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
564 if (g_data[int('n')] == 1) |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
565 { |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
566 if (++g_animtime > 8 - g_animspeed * 2) |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
567 { |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
568 animbrush_do(); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
569 g_animtime = 0; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
570 } |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
571 } |
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
|
572 |
40 | 573 // Update some mouse variables |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
574 if (g_data[int('m')] == 0 && g_data[int('M')] == 0) |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
575 { |
39 | 576 g_mx = g_msx - g_windowx; |
577 g_my = g_msy - g_windowy; | |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
578 } |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
579 else |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
580 { |
39 | 581 g_mx = mouseX; |
582 g_my = mouseY; | |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
583 } |
11 | 584 |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
585 g_msx = mouseX; |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
586 g_msy = mouseY; |
39 | 587 |
40 | 588 // Actual tool drawing |
145
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
589 if (g_tooltrigger == 1 && |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
590 g_mx <= width - g_hedge && |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
591 g_my <= height - g_vedge) |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
592 do_tool(g_mx, g_my, g_button); |
39 | 593 |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
594 switcher(0); |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
595 |
142 | 596 for (int i = 0; i < 1024; i++) |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
597 g_remdo[i] = 0; |
39 | 598 |
40 | 599 // Tool drawing for shows |
135 | 600 int savebut = g_button; |
186 | 601 int tt = tool(); |
602 if (tt != 5) | |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
603 { |
40 | 604 if (g_phase == 0) |
605 g_button = LEFT; | |
39 | 606 do_tool(g_mx, g_my, LEFT); |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
607 } |
148 | 608 else |
609 storecoords(g_mx, g_my); | |
610 | |
186 | 611 if (tt == 6) do_line(g_rx, g_ry, g_rx2, g_ry2, 0); |
612 if (tt == 7) do_circle(g_rx, g_ry, g_rx2, g_ry2); | |
613 if (tt == 8) do_rectangle(g_rx, g_ry, g_rx2, g_ry2); | |
135 | 614 g_button = savebut; |
39 | 615 |
40 | 616 // Screen update stuff |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
617 loadPixels(); |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
618 viewport(); |
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
619 switcher(1); |
145
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
620 |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
621 if (g_pgrab) |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
622 preview_box_drag(); |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
623 |
5af8b5ddf349
Merge and clean up changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
143
diff
changeset
|
624 preview_window(); |
136
12cf30907f26
More work on integrating changes from v1.8.2018
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
625 update_ui(false); |
40 | 626 updatePixels(); |
11 | 627 |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
628 // Message control |
40 | 629 if (g_msgctr > 0) |
630 g_msgctr--; | |
2
5eb3559e1778
Run everything through JS-beautifier and remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
631 |
113
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
632 // Macro handling |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
633 if (g_keymacro.length() > g_keymacpos) |
f87c6577e696
Cleanups and few comments added.
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
634 { |
0
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
635 macro_command(g_keymacro.charAt(g_keymacpos)); |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
636 g_keymacpos++; |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
637 } |
ebd5689e2985
Initial import of Multipaint sketch version 22.5.2017.
Tero Heikkinen
parents:
diff
changeset
|
638 } |