# HG changeset patch # User Mikhail Kryshen <mikhail@kryshen.net> # Date 1282789770 -14400 # Node ID 702a4939312d0554796c633a7424e6c5cee0cdad # Parent 2d74abee0c9389d8768ac159cd8b79a213f0a377 New mechanism for layers to trigger repaints (beginning). diff -r 2d74abee0c93 -r 702a4939312d src/net/kryshen/indyvon/core.clj --- a/src/net/kryshen/indyvon/core.clj Thu Aug 26 03:45:52 2010 +0400 +++ b/src/net/kryshen/indyvon/core.clj Thu Aug 26 06:29:30 2010 +0400 @@ -102,6 +102,47 @@ :center (/ (:height size) 2) :bottom (:height size))))))) +(defn- assoc-cons [m key val] + (->> (get m key) (cons val) (assoc m key))) + +(defn- assoc-in-cons [m keys val] + (->> (get-in m keys) (cons val) (assoc-in m keys))) + +;; +;; Observers +;; + +(def observers (atom nil)) + +(defn add-observer + ([target f] + (add-observer target f :default)) + ([target f group-id] + (swap! observers assoc-in-cons [group-id target] f) + nil)) + +(defn remove-group + "Remove group of observers." + [group-id] + (swap! observers dissoc group-id) + nil) + +(defn- change-group-id* + [observers old-id new-id] + (let [group (get observers old-id)] + (assoc (dissoc observers old-id) + new-id group))) + +(defn- change-group-id + [old-id new-id] + (swap! observers change-group-id* old-id new-id)) + +(defn update + "Notify observers." + [target & args] + (doseq [f (reduce #(concat %1 (get %2 target)) nil (vals @observers))] + (apply f target args))) + ;; ;; Rendering ;; @@ -242,6 +283,12 @@ ([layer x y width height] (with-bounds* x y width height render! layer))) +;; TODO: объект-Ñцена вмеÑто context-draw! +;; Сцена уÑтанавливает контекÑÑ‚ и риÑует Ñлой. Сцена - Ñлой? +;; Сцена идентифицирует группу Ð¾Ð±Ð¾Ð·Ñ€ÐµÐ²Ð°Ñ‚ÐµÐ»Ñ Ñлоев. +;; ÐžÐ±Ð½Ð¾Ð²Ð»ÐµÐ½Ð¸Ñ Ð»ÑŽÐ±Ð¾Ð³Ð¾ ÑлоÑ, изображенного в Ñцене, вызывает обновление Ñцены. +;; Обозреватель Ñцены вызывает repaint(). + (defn context-draw! "Sets up layer context, draws layer and commits event dispatcher." ([layer graphics event-dispatcher update-fn width height] @@ -309,9 +356,6 @@ (inverse-relative-transform) (get-thread-bindings))) -(defn- assoc-cons [m key val] - (assoc m key (cons val (get m key)))) - (defn- add-node [tree node] (assoc-cons tree (:parent node) node))