Created
December 23, 2011 23:22
-
-
Save anonymous/1515646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn make-map-console [gamemap] | |
"Makes a map console, which redraws the map every time it is repainted, | |
and has a default black background." | |
(doto (proxy [JPanel] [] | |
(paintComponent [g] | |
(proxy-super paintComponent g) | |
(doto g | |
(.setFont *font*) | |
(.setColor Color/white) | |
(.darwString "bla" 10 10)))) | |
(.setBackground Color/black))) | |
(defn make-main-window [] | |
"Makes the main window for the aplication. | |
Closing this window will end the game" | |
(doto (JFrame. *title*) | |
(.setSize *window-heigth* *window-width*) | |
;(.setResizable false) | |
(.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE) | |
(.setVisible true) | |
(.pack))) | |
(defn setup-UI [map] | |
"Creates the main window and the console on which the map is drawn, | |
then adds the console to the main window. | |
A watch is added to the map which makes the console redraw the map | |
every time it changes" | |
(let [main-window (make-main-window) | |
console (make-map-console map) | |
input (atom nil)] | |
(.add main-window console) | |
(add-watch map ::redraw-on-map-change (fn [_ _ _ _] (.repaint console))) | |
(set-key-bindings main-window input) | |
(.repaint console) | |
input)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment