diff options
Diffstat (limited to 'apps/plugins/clock/clock_draw_digital.c')
-rw-r--r-- | apps/plugins/clock/clock_draw_digital.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/apps/plugins/clock/clock_draw_digital.c b/apps/plugins/clock/clock_draw_digital.c new file mode 100644 index 0000000000..9fff47c520 --- /dev/null +++ b/apps/plugins/clock/clock_draw_digital.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock.h" | ||
21 | #include "clock_draw_digital.h" | ||
22 | #include "clock_bitmap_strings.h" | ||
23 | #include "clock_bitmaps.h" | ||
24 | #include "picture.h" | ||
25 | |||
26 | const struct picture* digits_skin[]={digits,segments}; | ||
27 | const struct picture* smalldigits_skin[]={smalldigits,smallsegments}; | ||
28 | |||
29 | #define buffer_printf(buffer, buffer_pos, ... ) \ | ||
30 | buffer_pos+=rb->snprintf(&buffer[buffer_pos], sizeof(buffer)-buffer_pos, __VA_ARGS__); | ||
31 | |||
32 | void digital_clock_draw(struct screen* display, | ||
33 | struct time* time, | ||
34 | struct clock_settings* settings, | ||
35 | struct counter* counter, | ||
36 | int skin){ | ||
37 | bool display_colon; | ||
38 | const struct picture* digits_bitmaps = &(digits_skin[skin][display->screen_type]); | ||
39 | const struct picture* smalldigits_bitmaps = &(smalldigits_skin[skin][display->screen_type]); | ||
40 | int hour=time->hour; | ||
41 | int str_w, str_h; | ||
42 | char buffer[20]; | ||
43 | int buffer_pos=0; | ||
44 | |||
45 | if(settings->digital.blinkcolon){ | ||
46 | display_colon=(time->second%2==0); | ||
47 | } | ||
48 | else | ||
49 | display_colon=true; | ||
50 | |||
51 | if(settings->general.hour_format==H12){/* AM/PM format */ | ||
52 | if(hour>12){ | ||
53 | buffer_printf(buffer, buffer_pos, "P");/* AM */ | ||
54 | /* readjust the hour to 12-hour format | ||
55 | * ( 13:00+ -> 1:00+ ) */ | ||
56 | hour -= 12; | ||
57 | }else | ||
58 | buffer_printf(buffer, buffer_pos, "A");/* AM */ | ||
59 | } | ||
60 | buffer_printf(buffer, buffer_pos, "%02d", hour); | ||
61 | buffer_printf(buffer, buffer_pos, "%c", display_colon?':':' '); | ||
62 | buffer_printf(buffer, buffer_pos, "%02d", time->minute); | ||
63 | getstringsize(digits_bitmaps, buffer, &str_w, &str_h); | ||
64 | draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, 0); | ||
65 | if(settings->digital.show_seconds){ | ||
66 | buffer_pos=0; | ||
67 | buffer_printf(buffer, buffer_pos, "%02d", time->second); | ||
68 | getstringsize(digits_bitmaps, buffer, &str_w, &str_h); | ||
69 | draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, | ||
70 | digits_bitmaps->height); | ||
71 | } | ||
72 | if(settings->general.date_format!=NONE){ | ||
73 | format_date(buffer, time, settings->general.date_format); | ||
74 | getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h); | ||
75 | draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2, | ||
76 | display->height-smalldigits_bitmaps->height*2); | ||
77 | } | ||
78 | if(counter){ | ||
79 | struct time counter_time; | ||
80 | counter_get_elapsed_time(counter, &counter_time); | ||
81 | rb->snprintf(buffer, 20, "%02d:%02d:%02d", | ||
82 | counter_time.hour, counter_time.minute, counter_time.second); | ||
83 | getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h); | ||
84 | draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2, | ||
85 | display->height-str_h); | ||
86 | } | ||
87 | } | ||