[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/svg-clock 03ea7e3 01/18: New package svg-clock.
From: |
Stefan Monnier |
Subject: |
[elpa] externals/svg-clock 03ea7e3 01/18: New package svg-clock. |
Date: |
Tue, 1 Dec 2020 17:26:01 -0500 (EST) |
branch: externals/svg-clock
commit 03ea7e3497c2c1bef3d3a4d7123296c9bf2db668
Author: Ulf Jasper <ulf.jasper@web.de>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
New package svg-clock.
---
svg-clock.el | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 209 insertions(+)
diff --git a/svg-clock.el b/svg-clock.el
new file mode 100644
index 0000000..68a1d1e
--- /dev/null
+++ b/svg-clock.el
@@ -0,0 +1,209 @@
+;;; svg-clock.el --- Analog clock using Scalable Vector Graphics
+
+;; Copyright (C) 2011 Free Software Foundation, Inc.
+
+;; Author: Ulf Jasper <ulf.jasper@web.de>
+;; Created: 22. Sep. 2011
+;; Keywords: demo
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; svg-clock provides a scalable analog clock. Rendering is done by
+;; means of svg (Scalable Vector Graphics). Works only with Emacsen
+;; which were built with svg support -- (image-type-available-p 'svg)
+;; must return t. Call `svg-clock' to start/stop the clock.
+;; Set `svg-clock-size' to change its size.
+
+;; Installation
+;; ------------
+
+;; Add the following lines to your Emacs startup file (`~/.emacs').
+;; (add-to-list 'load-path "/path/to/svg-clock.el")
+;; (autoload 'svg-clock "svg-clock" "Start/stop svg-clock" t)
+
+;; ======================================================================
+
+;;; History:
+
+;; 0.1 (2011-09-22)
+;; - Initial release.
+
+;;; Code:
+(defconst svg-clock-version "0.1" "Version number of `svg-clock'.")
+
+(require 'image-mode)
+
+(defgroup svg-clock nil
+ "svg-clock"
+ :group 'applications)
+
+(defcustom svg-clock-size 250
+ "Size (width and height) of the clock, in pixels."
+ :type 'integer
+ :group 'svg-clock)
+
+(defvar svg-clock-timer nil)
+
+(defconst svg-clock-template
+ "<?xml version=\"1.0\"?>
+<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"
+\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">
+<svg xmlns=\"http://www.w3.org/2000/svg\"
+ width=\"%SIZE%\" height=\"%SIZE%\" >
+ <defs>
+ <symbol id=\"tick\">
+ <line x1=\"50\" y1=\"2\" x2=\"50\" y2=\"4\"
+ style=\"stroke:%FG%;stroke-width:1\"/>
+ </symbol>
+ <symbol id=\"ticklong\">
+ <line x1=\"50\" y1=\"2\" x2=\"50\" y2=\"9\"
+ style=\"stroke:%FG%;stroke-width:2\"/>
+ </symbol>
+ <symbol id=\"hand-hour\">
+ <line x1=\"50\" y1=\"22\" x2=\"50\" y2=\"54\"
+ style=\"stroke:%FG%;stroke-width:3\"/>
+ </symbol>
+ <symbol id=\"hand-minute\">
+ <line x1=\"50\" y1=\"12\" x2=\"50\" y2=\"55\"
+ style=\"stroke:%FG%;stroke-width:3\"/>
+ </symbol>
+ <symbol id=\"hand-second\">
+ <line x1=\"50\" y1=\"10\" x2=\"50\" y2=\"59\"
+ style=\"stroke:%FG%;stroke-width:0.5\"/>
+ </symbol>
+ <g id=\"minute-ticks-a\">
+ <use xlink:href=\"#tick\"
+ transform=\"rotate(6, 50, 50)\" />
+ <use xlink:href=\"#tick\"
+ transform=\"rotate(12, 50, 50)\" />
+ <use xlink:href=\"#tick\"
+ transform=\"rotate(18, 50, 50)\" />
+ <use xlink:href=\"#tick\"
+ transform=\"rotate(24, 50, 50)\" />
+ </g>
+ <g id=\"minute-ticks-b\">
+ <use xlink:href=\"#minute-ticks-a\"
+ transform=\"rotate(0, 50, 50)\" />
+ <use xlink:href=\"#minute-ticks-a\"
+ transform=\"rotate(30, 50, 50)\" />
+ <use xlink:href=\"#minute-ticks-a\"
+ transform=\"rotate(60, 50, 50)\" />
+ <use xlink:href=\"#minute-ticks-a\"
+ transform=\"rotate(90, 50, 50)\" />
+ <use xlink:href=\"#minute-ticks-a\"
+ transform=\"rotate(120, 50, 50)\" />
+ <use xlink:href=\"#minute-ticks-a\"
+ transform=\"rotate(150, 50, 50)\" />
+ </g>
+
+ <g id=\"5-minute-ticks\">
+ <use xlink:href=\"#ticklong\" />
+ <use xlink:href=\"#ticklong\" transform=\"rotate(30, 50, 50)\" />
+ <use xlink:href=\"#ticklong\" transform=\"rotate(60, 50, 50)\" />
+ </g>
+
+ <g id=\"clock\">
+ <use xlink:href=\"#5-minute-ticks\"
+ transform=\"rotate(0, 50, 50)\" />
+ <use xlink:href=\"#5-minute-ticks\"
+ transform=\"rotate(90, 50, 50)\" />
+ <use xlink:href=\"#5-minute-ticks\"
+ transform=\"rotate(180, 50, 50)\" />
+ <use xlink:href=\"#5-minute-ticks\"
+ transform=\"rotate(270, 50, 50)\" />
+
+ <use xlink:href=\"#minute-ticks-b\"
+ transform=\"rotate(0, 50, 50)\" />
+ <use xlink:href=\"#minute-ticks-b\"
+ transform=\"rotate(180, 50, 50)\" />
+
+
+ <use xlink:href=\"#hand-second\"
+ transform=\"rotate(%SECOND%, 50, 50)\">
+ </use>
+ <use xlink:href=\"#hand-minute\"
+ transform=\"rotate(%MINUTE%, 50, 50)\">
+ </use>
+ <use xlink:href=\"#hand-hour\"
+ transform=\"rotate(%HOUR%, 50, 50)\">
+ </use>
+
+
+ <circle cx=\"50\" cy=\"50\" r=\"3\" fill=\"%FG%\"/>
+ </g>
+ </defs>
+ <use xlink:href=\"#clock\"
+ transform=\"scale(%SCALE%, %SCALE%)\"/>
+</svg>"
+ "The template for drawing the `svg-clock'.")
+
+(defun svg-clock-color-to-hex (colour)
+ "Return hex representation of COLOUR."
+ (let ((values (color-values colour)))
+ (format "#%04x%04x%04x" (nth 0 values) (nth 1 values) (nth 2 values))))
+
+(defun svg-clock-replace (from to)
+ "Replace all occurrences of FROM with TO."
+ (goto-char (point-min))
+ (while (re-search-forward from nil t)
+ (replace-match to)))
+
+(defun svg-clock-do-update (time)
+ "Make the clock display TIME.
+TIME must have the form (SECOND MINUTE HOUR ...), as returned by
`decode-time'."
+ (with-current-buffer (get-buffer-create "*clock*")
+ (let* ((inhibit-read-only t)
+ (seconds (nth 0 time))
+ (minutes (nth 1 time))
+ (hours (nth 2 time))
+ (bg-colour (svg-clock-color-to-hex (face-background 'default)))
+ (fg-colour (svg-clock-color-to-hex (face-foreground 'default))))
+ (erase-buffer)
+ (insert svg-clock-template)
+
+ (svg-clock-replace "%BG%" bg-colour)
+ (svg-clock-replace "%FG%" fg-colour)
+ (svg-clock-replace "%HOUR%" (format "%f" (+ (* hours 30) (/ minutes
2.0))))
+ (svg-clock-replace "%MINUTE%" (format "%f" (+ (* minutes 6)
+ (/ seconds 10.0))))
+ (svg-clock-replace "%SECOND%" (format "%f" (* seconds 6)))
+ (svg-clock-replace "%SIZE%" (format "%d" svg-clock-size))
+ (svg-clock-replace "%SCALE%" (format "%f" (/ svg-clock-size 100.0)))
+ (image-toggle-display-image))))
+
+(defun svg-clock-update ()
+ "Update the clock."
+ (svg-clock-do-update (decode-time (current-time))))
+
+;;;###autoload
+(defun svg-clock ()
+ "Start/stop the svg clock."
+ (interactive)
+ (if svg-clock-timer
+ (progn
+ (cancel-timer svg-clock-timer)
+ (setq svg-clock-timer nil)
+ (message "Clock stopped"))
+ (switch-to-buffer (get-buffer-create "*clock*"))
+ (setq svg-clock-timer
+ (run-with-timer 0 1 'svg-clock-update))
+ (message "Clock started")))
+
+(provide 'svg-clock)
+
+;;; svg-clock.el ends here
- [elpa] branch externals/svg-clock created (now 039aac6), Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock ba6878a 03/18: Added Version to svg-clock.el, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 039aac6 18/18: * .gitignore: New file, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock d1aeadd 11/18: There's no longer an svg-def function in svg.el, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock ba28d97 09/18: Bump version number to 1.0 and make changes public, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 284d123 14/18: Fix requirements and version numbers, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock ea9302b 07/18: * packages/svg-clock/svg-clock.el (svg-clock-do-update, svg-clock-start): Don't, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 3d9cd0e 15/18: Copy svg--def to manipulate the DOM directly from svg-clock.el, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 534946a 06/18: Fixed image-mode issue. Changed version to 0.5., Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 03ea7e3 01/18: New package svg-clock.,
Stefan Monnier <=
- [elpa] externals/svg-clock 48454df 04/18: svg-clock: Disable buffer undo, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock dc73e08 13/18: Allow controlling whether to show the seconds and the face, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 99c291f 02/18: 2011-09-26 Ulf Jasper <address@hidden>, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 5e4e62e 08/18: svg-clock.el: Refactoring. Use 'svg.el' and 'dom.el'., Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 9f4be3e 05/18: 2012-01-29 Ulf Jasper <address@hidden>, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 1c04475 16/18: Bump version after last fix, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 301259c 10/18: Fix some quoting problems in doc strings, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock c8fc54f 12/18: Pick the right size when on a scaled display, Stefan Monnier, 2020/12/01
- [elpa] externals/svg-clock 55d2f18 17/18: Revert "Copy svg--def to manipulate the DOM directly from svg-clock.el", Stefan Monnier, 2020/12/01