Skip to content
This repository has been archived by the owner on Aug 9, 2019. It is now read-only.

Commit

Permalink
refactored L5/slide and reduce calling repaint.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Jan 7, 2011
1 parent f68b67c commit fe86285
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/L5/context.clj
Expand Up @@ -17,8 +17,7 @@
(defn dispatch-event [context keyCode]
(let [actions (get @(:actions context) keyCode)]
(when (not (empty? actions))
(doseq [act actions] (act))
(.repaint @(:frame context)))))
(doseq [act actions] (act)))))

(defn build-context [raw-context-params & slides]
(let [params (merge default raw-context-params)
Expand Down Expand Up @@ -84,8 +83,7 @@
(dosync
(ref-set zoom scale)
(ref-set x (/ width-diff 2 scale))
(ref-set y (/ height-diff 2 scale))))
(slide/current-slide context)))]
(ref-set y (/ height-diff 2 scale))))))]
(doto panel
(.setFocusable true)
(.setForeground (:color context))
Expand Down
22 changes: 9 additions & 13 deletions src/L5/slide.clj
Expand Up @@ -179,27 +179,23 @@
(ref-set y elem-y))))))))

(defn current-slide [context]
(let [idx @(:current context)]
(let [idx @(:current context)
slides @(:slides context)]
(println
(format "%d / %d %s"
(+ 1 idx) (count slides) (:body (first (get slides idx)))))
(draw-slide context idx)))

(defn next-slide [context]
(let [slides @(:slides context)
idx (+ @(:current context) 1)]
(when (> (count slides) idx)
;; TODO: this indicator is dup with below
(println
(format "%d / %d %s"
(+ 1 idx) (count slides) (:body (first (get slides idx)))))
(draw-slide context idx)
(dosync (alter (:current context) inc)))))
(dosync (alter (:current context) inc))
(current-slide context))))

(defn prev-slide [context]
(let [slides @(:slides context)
idx (- @(:current context) 1)]
(when (>= idx 0)
;; TODO: this indicator is dup with above
(println
(format "%d / %d %s"
(+ 1 idx) (count @(:slides context)) (:body (first (get slides idx)))))
(draw-slide context idx)
(dosync (alter (:current context) dec)))))
(dosync (alter (:current context) dec))
(current-slide context))))

0 comments on commit fe86285

Please sign in to comment.