]> gitweb.factorcode.org Git - factor.git/blob - extra/lcd/lcd.factor
0ac74a6f92c7a32d156c290bdb3aea323e3d439f
[factor.git] / extra / lcd / lcd.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar calendar.format fonts fry grouping
4 kernel math sequences timers ui ui.gadgets ui.gadgets.labels ;
5 IN: lcd
6
7 : lcd-digit ( digit row -- str )
8     [ dup CHAR: : = [ drop 10 ] [ CHAR: 0 - ] if ] dip {
9         "  _       _  _       _   _   _   _   _      "
10         " | |  |   _| _| |_| |_  |_    | |_| |_|  *  "
11         " |_|  |  |_  _|   |  _| |_|   | |_|   |  *  "
12         "                                            "
13     } nth 4 <groups> nth ;
14
15 : lcd-row ( row digit -- string )
16     '[ _ lcd-digit ] { } map-as concat ;
17
18 : lcd ( digit-str -- string )
19     4 <iota> [ lcd-row ] with map "\n" join ;
20
21 TUPLE: time-display < label timer ;
22
23 : <time-display> ( -- gadget )
24     "99:99:99" lcd time-display new-label
25         monospace-font >>font
26         dup '[ now timestamp>hms lcd _ string<< ]
27         f 1 seconds <timer> >>timer ;
28
29 M: time-display graft*
30     [ timer>> start-timer ] [ call-next-method ] bi ;
31
32 M: time-display ungraft*
33     [ timer>> stop-timer ] [ call-next-method ] bi ;
34
35 MAIN-WINDOW: time-window { { title "Time" } }
36     <time-display> >>gadgets ;