Allow gray-scale icons color changing icons.

Change golden-ratio mode to be a color changing icon
This commit is contained in:
Matthew Fidler 2016-03-30 10:58:50 -05:00
parent ddb4e803d7
commit 6df89d5781

View file

@ -190,7 +190,7 @@ This was stole/modified from `c-save-buffer-state'"
("\\`Go\\'" "go" xpm) ("\\`Go\\'" "go" xpm)
("\\` Rbow\\'" "rainbow" xpm) ("\\` Rbow\\'" "rainbow" xpm)
("\\` ICY\\'" "icy" xpm) ;; http://www.clipartpal.com/clipart_pd/weather/ice_10206.html ("\\` ICY\\'" "icy" xpm) ;; http://www.clipartpal.com/clipart_pd/weather/ice_10206.html
("\\` Golden\\'" "golden" xpm) ;; Icon created by Arthur Shlain from Noun Project ("\\` Golden\\'" "golden" xpm-bw) ;; Icon created by Arthur Shlain from Noun Project
("\\`BibTeX\\'\\'" "bibtex" xpm) ("\\`BibTeX\\'\\'" "bibtex" xpm)
("\\`C[+][+]\\(/.*\\|\\)\\'" #xf10c font-mfizz) ("\\`C[+][+]\\(/.*\\|\\)\\'" #xf10c font-mfizz)
("\\`C[#]\\(/.*\\|\\)\\'" #xf10d font-mfizz) ("\\`C[#]\\(/.*\\|\\)\\'" #xf10d font-mfizz)
@ -280,15 +280,40 @@ without the extension. And the third being the type of icon."
(setq img (replace-regexp-in-string (regexp-quote (car c)) (cdr c) img t t))) (setq img (replace-regexp-in-string (regexp-quote (car c)) (cdr c) img t t)))
img)) img))
(defun mode-icons-interpolate (c1 c2 &optional factor)
"Interpolate between C1 and C2 by FACTOR.
If FACTOR is unspecified, use 0.5"
(let* ((factor (or factor 0.5))
(red (+ (* (nth 0 c1) factor) (* (nth 0 c2) (- 1.0 factor))))
(green (+ (* (nth 1 c1) factor) (* (nth 1 c2) (- 1.0 factor))))
(blue (+ (* (nth 2 c1) factor) (* (nth 2 c2) (- 1.0 factor)))))
(setq red (/ (round (* 256.0 red)) 256.0)
green (/ (round (* 256.0 green)) 256.0)
blue (/ (round (* 256.0 blue)) 256.0))
(color-rgb-to-hex red green blue)))
(defun mode-icons-interpolate-from-scale (foreground background)
"Interpolate black to FOREGROUND and white to BACKGROUND.
Grayscales are in between."
(let ((black '(0.0 0.0 0.0))
(white '(1.0 1.0 1.0))
lst tmp
(i 0))
(while (< i 256)
(setq tmp (/ i 255.0))
(push (cons (mode-icons-interpolate black white tmp)
(mode-icons-interpolate foreground background tmp)) lst)
(setq i (1+ i)))
lst))
(defun mode-icons-get-icon-display-xpm-bw-face (icon-path &optional face) (defun mode-icons-get-icon-display-xpm-bw-face (icon-path &optional face)
"Change xpm at ICON-PATH to match FACE." "Change xpm at ICON-PATH to match FACE.
(let ((background (color-name-to-rgb (face-background (or face 'mode-line)))) The white is changed to the background color.
(foreground (color-name-to-rgb (face-foreground (or face 'mode-line)))) The black is changed to the foreground color.
lst) Grayscale colors are aslo changed by `mode-icons-interpolate-from-scale'."
(setq foreground (color-rgb-to-hex (nth 0 foreground) (nth 1 foreground) (nth 2 foreground)) (let* ((background (color-name-to-rgb (face-background (or face 'mode-line))))
background (color-rgb-to-hex (nth 0 background) (nth 1 background) (nth 2 background))) (foreground (color-name-to-rgb (face-foreground (or face 'mode-line))))
(push (cons "#000000" foreground) lst) (lst (mode-icons-interpolate-from-scale foreground background)))
(push (cons "#ffffff" background) lst)
(mode-icons-get-icon-display-xpm-replace icon-path lst))) (mode-icons-get-icon-display-xpm-replace icon-path lst)))
(defun mode-icons-get-icon-display (icon type &optional face) (defun mode-icons-get-icon-display (icon type &optional face)