       (.addMouseMotionListener mouse-adapter))
     position-atom))
 
+(defn handle-arrow-pan [component position-atom]
+  (let [binder (fn [key axis step]
+                 (bind-key component key
+                           #(swap! position-atom update-in [axis] + step) true))]
+    (binder "UP" :y 50)
+    (binder "DOWN" :y -50)
+    (binder "RIGHT" :x -50)
+    (binder "LEFT" :x 50)))
+
 (defn handle-wheel [component z-atom]
   (.addMouseWheelListener component
     (proxy [MouseAdapter] []

    (.add (.getContentPane frame) panel)
    (setup-fullscreen frame)
    (handle-drags panel screen-state)
    (handle-wheel panel screen-state)
    (handle-resize panel screen-state)
    (handle-zoom frame screen-state)

                           RenderingHints/VALUE_ANTIALIAS_ON
                           RenderingHints/VALUE_ANTIALIAS_OFF)))))

(defn paint-tiles [^Graphics2D g available-tiles screen-state [tile-width tile-height]]
  (let [pixel-rect (Rectangle. (- (screen-state :x)) (- (screen-state :y))
                               (screen-state :width) (screen-state :height))]
    ;(println pixel-rect)
    (doseq [[nx ny] (tiles-in-pixel-rectangle pixel-rect [tile-width tile-height])]
      ;(println nx ny)
      (when-let [image (get-in available-tiles [(screen-state :zoom) {:nx nx :ny ny :nz (screen-state :z) :nt 0 :nc 0}])]
        (let [[x y] (tile-to-pixels [nx ny] [tile-width tile-height] 0)]
          (.drawImage g image x y nil))))))

(defn paint-screen [graphics screen-state available-tiles]
  (let [original-transform (.getTransform graphics)]
    (doto graphics
      (.setClip 0 0 (:width @screen-state) (:height @screen-state))
      (.translate (:x @screen-state)
                  (:y @screen-state))
      ;(.rotate @angle)
      enable-anti-aliasing
      (paint-tiles @available-tiles @screen-state [512 512])
      (.setColor Color/YELLOW)
      (.fillOval -30 -30
                 60 60)
