\name {doodle} \class {vpane} \children {doodle.ctrl doodle.canvas} \width {400} \height {400} \gapH {2} \gapV {2} \border {3} \script { switch (arg[0]) { case "yP": return 0; break; case "display": case "show": case "VIEW_ON": case "VIEW_OFF": return; break; } usual(); } \ \class {hpane} \name {doodle.ctrl} \parent {doodle} \children {doodle.ctrl.ops doodle.ctrl.brush doodle.ctrl.color} \maxHeight {20} \gapH {4} \gapV {4} \border {3} \ \class {menu} \name {doodle.ctrl.ops} \parent {doodle.ctrl} \menuConfig { . {backup} {send("doodle.canvas", "backup");} . {redraw} {send("doodle.canvas", "redraw");} . {record on} {send("doodle.canvas", "record on");} . {record off} {send("doodle.canvas", "record off");} . {dump} {send("doodle.canvas", "dump");} . {clear stroke list} {send("doodle.canvas", "clear");} . {clearWindow} {send("doodle.canvas", "clearWindow");} . {save} {send("doodle.canvas", "save");} . {effect A, x10} {send("doodle.canvas", "effect A", 10);} . {effect A, x100} {send("doodle.canvas", "effect A", 100);} . {effect A, x200} {send("doodle.canvas", "effect A", 200);} . {effect B} {send("doodle.canvas", "effect B");} . {effect C} {send("doodle.canvas", "effect C");} . {effect D} {send("doodle.canvas", "effect D");} . {effect E wave} {send("doodle.canvas", "effect E");} } \label {Operation} \maxWidth {100} \gapH {2} \gapV {2} \ \class {menu} \name {doodle.ctrl.brush} \parent {doodle.ctrl} \menuConfig { . {line} {send("doodle.canvas", "setBrush", 0);} . {point} {send("doodle.canvas", "setBrush", 1);} . {larger point} {send("doodle.canvas", "setBrush", 2);} . {even larger point} {send("doodle.canvas", "setBrush", 3);} . {very large point} {send("doodle.canvas", "setBrush", 4);} . {monster point} {send("doodle.canvas", "setBrush", 5);} . {textual 1} {send("doodle.canvas", "setBrush", 6);} . {textual 3} {send("doodle.canvas", "setBrush", 7);} } \label {Brushes} \maxWidth {100} \gapH {2} \gapV {2} \ \class {menu} \name {doodle.ctrl.color} \parent {doodle.ctrl} \menuConfig { . {black} {send("doodle.canvas", "setColor", "black");} . {white} {send("doodle.canvas", "setColor", "white");} . {red} {send("doodle.canvas", "setColor", "red");} . {blue} {send("doodle.canvas", "setColor", "blue");} . {green} {send("doodle.canvas", "setColor", "green");} \label {Colors} \maxWidth {100} \gapH {2} \gapV {2} \ \class {field} \name {doodle.canvas} \parent {doodle} \script { switch (arg[0]) { case "mouseMove": if (penDownP) { x0 = x1; y0 = y1; x1 = arg[1]; y1 = arg[2]; if (brush == 0) { drawLine(x0, y0, x1, y1); if (record == 1) { stroke[count] = concat("drawLine(", x0, ",", y0, ",", x1, ",", y1, ");"); count = count + 1; } } else if (brush == 1) { drawLine(x1, y1, x1, y1); if (record == 1) { stroke[count] = concat("drawLine(", x1, ",", y1, ",", x1, ",", y1, ");"); count = count + 1; } } else if (brush == 2) { drawFillRect(x1, y1, x1 + 2, y1 + 2); if (record == 1) { stroke[count] = concat("drawFillRect(", x1, ",", y1, ",", x1 + 2, ",", y1 + 2, ");"); count = count + 1; } } else if (brush == 3) { drawFillRect(x1, y1, x1 + 5, y1 + 5); if (record == 1) { stroke[count] = concat("drawFillRect(", x1, ",", y1, ",", x1 + 5, ",", y1 + 5, ");"); count = count + 1; } } else if (brush == 4) { drawFillRect(x1, y1, x1 + 10, y1 + 10); if (record == 1) { stroke[count] = concat("drawFillRect(", x1, ",", y1, ",", x1 + 10, ",", y1 + 10, ");"); count = count + 1; } } else if (brush == 5) { drawFillRect(x1, y1, x1 + 100, y1 + 100); if (record == 1) { stroke[count] = concat("drawFillRect(", x1, ",", y1, ",", x1 + 100, ",", y1 + 100, ");"); count = count + 1; } } else if (brush == 6) { c = nthChar(brushText, idx); drawText(x1, y1, 1, c); idx = idx + 1; if (record == 1) { stroke[count] = concat("drawText(", x1, ",", y1, ",", "1, ", c, ");"); count = count + 1; } } else if (brush == 7) { c = nthChar(brushText, idx); drawText(x1, y1, 3, c); idx = idx + 1; if (record == 1) { stroke[count] = concat("drawText(", x1, ",", y1, ",", "3, ", c, ");"); count = count + 1; } } return; } break; case "buttonPress": penDownP = 1; x0 = mouseX(); y0 = mouseY(); x1 = x0; y1 = y0; break; case "buttonRelease": penDownP = 0; break; case "setColor": set("FGColor", arg[1]); break; case "setBrush": brush = arg[1]; if (brush == 6) { idx = 0; /* brushText = loadFile("~/aliceInWonderland.txt"); brushText = loadFile("/usr/work/viola/apps/doodle.v"); */ brushText = loadFile("/usr/dict/words"); } else if (brush == 7) { idx = 0; brushText = loadFile("/usr/dict/words"); } break; case "clear": count = 0; clearWindow(); return; break; case "clearWindow": clearWindow(); return; break; case "save": tt = ""; for (i = 0; i < count; i++) { tt = concat(tt, stroke[i], "\n"); } print("Saving to doodle.out\n"); saveFile("/usr/tmp/doodle.out", tt); return; break; case "dump": for (i = 0; i < count; i++) { print(i, "\t", stroke[i], "\n"); } return; break; case "backup": count = count - 1; return; break; case "redraw": tt = ""; for (i = 0; i < count; i++) { tt = concat(tt, stroke[i]); } clearWindow(); interpret(tt); return; break; case "record on": record = 1; return; break; case "record off": record = 0; return; break; case "effect A": if (count <= 0) return; n = arg[1]; for (i = 0; i < n; i++) { /* idx = random(1) % count; print("idx=", idx, "\n"); print("> ", idx, "\t", stroke[idx], "\n"); hue = (random(0) % 50) * 2; set("FGColor", concat(hue, " ",hue, " ",hue)); */ set("FGColor", "grey90"); idx = random(1) % count; interpret(stroke[idx]); set("FGColor", "grey80"); idx = random(1) % count; interpret(stroke[idx]); set("FGColor", "grey70"); idx = random(1) % count; interpret(stroke[idx]); } return; break; case "effect B": if (count <= 0) return; for (i = 0; i < count;) { set("FGColor", "blue"); interpret(stroke[i]); i++; set("FGColor", "green"); interpret(stroke[i]); i++; } return; break; case "effect C": if (count <= 0) return; for (i = 0; i < count;) { set("FGColor", "blue"); interpret(stroke[i]); i++; set("FGColor", "grey"); interpret(stroke[i]); i++; } return; break; case "effect D": if (count <= 0) return; for (i = 0; i < count;) { set("FGColor", "grey80"); interpret(stroke[i]); i++; set("FGColor", "grey70"); interpret(stroke[i]); i++; set("FGColor", "grey60"); interpret(stroke[i]); i++; } return; break; case "effect E": if (count <= 0) return; for (i = 2; i < count;) { set("FGColor", "grey80"); interpret(stroke[i + 1]); set("FGColor", "grey50"); interpret(stroke[i]); set("FGColor", "grey80"); interpret(stroke[i - 1]); set("FGColor", "white"); interpret(stroke[i - 2]); i++; } return; break; case "init": usual(); record = 1; penDownP = 0; return; break; } usual(); } \gapH {4} \gapV {4} \border {6} \