!7 sbool showHelpOnStart; static JFrame mainFrame; static LL gridComponents; static JComponent mainGrid; static JCheckBoxMenuItem miShowLocations; static Color lightBlue = colorFromHex("4169e1"); static int gridRows = 8, gridCols = 8; sbool showLocations = true; static int smartyX, smartyY; static Rect selection; sS locationLetters = charRange('A', 'Z') + "[\\]^_`" + charRange('a', 'z') + "{|}~?€"; sS smartyUnicode = basicUnicodeSmiley(); static int smartyFontSize = 40; sS windowsFontID = #1400468; sclass JCell > JComponent { int x, y; char letter; bool obstacle; *(int *x, int *y) {} public void paint(Graphics _g) { Graphics2D g = cast _g; int w = getWidth(), h = getHeight(); Color color = Color.white; if (obstacle) color = Color.black; else if (selection.contains(x, y)) color = lightBlue; fillRect(g, 0, 0, w, h, color); if (showLocations && !obstacle) { temp tempSetFont(g, loadFont_cached(windowsFontID)); drawTextWithTopLeftCornerAt(g, str(letter), Pt(2, 0), Color.black); } if (smartyX == x && smartyY == y) { temp tempSetFontSize(g, smartyFontSize); drawCenteredText(g, smartyUnicode, 0, 0, w, h, Color.black); } } { addMouseListener(new MouseAdapter { public void mousePressed(MouseEvent e) { if (!isLeftButton(e)) ret; setSelection(new Rect(x, y, 1, 1)); } }); addMouseMotionListener(new MouseMotionAdapter { public void mouseDragged(MouseEvent e) { _print("Drag in " + x + "/" + y + ": " + e.getPoint()); Component dest = componentAtScreenLocationInWindow(mainFrame, e); if (dest cast JCell) { _print("Target: " + dest); setSelection(new Rect(x, y, max(dest.x+1-x, 1), max(dest.y+1-y, 1))); } } }); } toString { ret x + "/" + y; } } static JCell getCell(int x, int y) { ret gridComponents.get(y).get(x); } svoid rearrangeLetters { int iLetter = 0; for y to gridRows: for x to gridCols: { JCell cell = getCell(x, y); if (cell.obstacle) cell.letter = ' '; else cell.letter = locationLetters.charAt(iLetter++); } } svoid setSelection(Rect r) { if (eq(selection, r)) ret; selection = r; repaint(mainGrid); } p { autoRestart(5.0); loadLibrary(windowsFontID); mainFrame = showFrame("Smarty"); addMenu(mainFrame, "Worlds", "New... (Ctrl+N)", r {}, "Retrieve... (Ctrl+R)", r {}, "Save... (Ctrl+S)", r {}, "---", "Exit", rThread killVM); registerCtrlKey(mainFrame, KeyEvent.VK_N, "New world", r { print("new") }); registerCtrlKey(mainFrame, KeyEvent.VK_R, "Retrieve world", r {}); registerCtrlKey(mainFrame, KeyEvent.VK_S, "Save world", r {}); addMenu(mainFrame, "View", miShowLocations = jCheckBoxMenuItem("Locations (Ctrl+L)", showLocations, b -> { showLocations = b; repaint(mainGrid); })); registerCtrlKey(mainFrame, KeyEvent.VK_L, "Locations", r { showLocations = !showLocations; setChecked(miShowLocations, showLocations); repaint(mainGrid); }); JMenuBar menuBar = getMenuBar(mainFrame); JMenuItem helpItem = jMenuItem("Help F1", rThread showHelp); /*print(minSize := getMinimumSize(helpItem)); print(preferredSize := getPreferredSize(helpItem));*/ addMenuItem(menuBar, jPreferredWidthToMaxWidth(helpItem)); addAndRevalidate(menuBar, jHorizontalGlue()); // spacer registerFunctionKey(mainFrame, 1, rThread showHelp); selection = new Rect(1, 1, 1, 1); gridComponents = map(iotaZeroList(gridRows), y -> map(iotaZeroList(gridCols), x -> new JCell(x, y))); //gridComponents = repF_2d(8, 8, lambda0 newSingleComponentPanel); second(second(gridComponents)).obstacle = true; //first(first(gridComponents)).setComponent(fontSize(50, jcenteredlabel(basicUnicodeSmiley()))); rearrangeLetters(); mainGrid = setBackground(Color.black, hvgrid(gridComponents, 1)); setFrameContents(mainFrame, westAndCenter( jvstack(jFixedSize(500, mainGrid)), jCenteredLabel("TODO"))); centerPackFrame(mainFrame); if (showHelpOnStart) showHelp(); //hideConsole(); } svoid showHelp() { S text = loadSnippet(#1031105); S heading = firstLine(text); trim(dropFirstLine(text)); showFrame(heading, fontSizePlus(4, makeUneditableWithTextColor(Color.black, wordWrapTextArea(text)))); }