]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/xpm/xpm-ops.el
[xpm int] Make wip more visible; inhibit their distribution.
[gnu-emacs-elpa] / packages / xpm / xpm-ops.el
diff --git a/packages/xpm/xpm-ops.el b/packages/xpm/xpm-ops.el
new file mode 100644 (file)
index 0000000..67989ca
--- /dev/null
@@ -0,0 +1,63 @@
+;;; xpm-ops.el --- drawing operations        -*- lexical-binding: t -*-
+
+;; Copyright (C) 2014  Free Software Foundation, Inc.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'queue)
+
+(defun xpm-flood-fill (px x y)
+  (xpm--w/gg (cpp origin y-mult) (xpm--gate)
+    (let ((q (queue-create))
+          bye)
+      (cl-labels
+          ((pos (x y) (+ origin (* cpp x) (* y-mult y)))
+           (cur () (let ((p (point)))
+                     (buffer-substring-no-properties
+                      p (+ p cpp))))
+           (oldp () (string= bye (cur)))
+           (extent (coord)
+                   (let* ((x (car coord))
+                          (y (cdr coord))
+                          (p (goto-char (pos x y)))
+                          (beg x)
+                          (end x))
+                     (when (oldp)
+                       (loop while (oldp)
+                             do (backward-char cpp)
+                             do (decf beg)
+                             finally do (incf beg))
+                       (goto-char p)
+                       (loop while (oldp)
+                             do (forward-char cpp)
+                             do (incf end)
+                             finally do (decf end))
+                       (cons beg end)))))
+        (setq bye (let ((p (pos x y)))
+                    (buffer-substring-no-properties
+                     p (+ p cpp))))
+        (queue-enqueue q (cons x y))
+        (loop until (queue-empty q)
+              do (let* ((coord (queue-dequeue q))
+                        (ext (extent coord)))
+                   (when ext
+                     (xpm-put-points px ext y)
+                     ;; todo: expansion and queuing of y-1 and y+1
+                     )))))))
+
+;;; xpm-ops.el ends here