blob: d5c37ad8dcb0270f6ac595014e541c545d7fd56e [file] [log] [blame]
Kevin Ferrare93b2f9f2007-08-04 03:01:46 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $
9 *
Nicolas Pennequin357ffb32008-05-05 10:32:46 +000010 * Copyright (C) 2007 Copyright Kévin Ferrare
Kevin Ferrare93b2f9f2007-08-04 03:01:46 +000011 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Kevin Ferrare93b2f9f2007-08-04 03:01:46 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "clock.h"
23#include "clock_draw_digital.h"
24#include "clock_bitmap_strings.h"
25#include "clock_bitmaps.h"
26#include "picture.h"
27
28const struct picture* digits_skin[]={digits,segments};
29const struct picture* smalldigits_skin[]={smalldigits,smallsegments};
30
31#define buffer_printf(buffer, buffer_pos, ... ) \
32 buffer_pos+=rb->snprintf(&buffer[buffer_pos], sizeof(buffer)-buffer_pos, __VA_ARGS__);
33
34void digital_clock_draw(struct screen* display,
35 struct time* time,
36 struct clock_settings* settings,
37 struct counter* counter,
38 int skin){
39 bool display_colon;
40 const struct picture* digits_bitmaps = &(digits_skin[skin][display->screen_type]);
41 const struct picture* smalldigits_bitmaps = &(smalldigits_skin[skin][display->screen_type]);
42 int hour=time->hour;
43 int str_w, str_h;
44 char buffer[20];
45 int buffer_pos=0;
46
47 if(settings->digital.blinkcolon){
48 display_colon=(time->second%2==0);
49 }
50 else
51 display_colon=true;
52
Kevin Ferrare14d27612007-08-04 14:50:28 +000053 if(settings->general.hour_format==H12 && time->hour>12)/* AM/PM format */
54 hour -= 12;
55
Kevin Ferrare93b2f9f2007-08-04 03:01:46 +000056 buffer_printf(buffer, buffer_pos, "%02d", hour);
57 buffer_printf(buffer, buffer_pos, "%c", display_colon?':':' ');
58 buffer_printf(buffer, buffer_pos, "%02d", time->minute);
Kevin Ferrare14d27612007-08-04 14:50:28 +000059 if(settings->general.hour_format==H12){
Nils Wallménius48406822008-05-15 20:16:38 +000060 if(time->hour>=12){
Kevin Ferrare14d27612007-08-04 14:50:28 +000061 buffer_printf(buffer, buffer_pos, "P");/* PM */
62 }else{
63 buffer_printf(buffer, buffer_pos, "A");/* AM */
64 }
65 }
Kevin Ferrare93b2f9f2007-08-04 03:01:46 +000066 getstringsize(digits_bitmaps, buffer, &str_w, &str_h);
67 draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, 0);
68 if(settings->digital.show_seconds){
69 buffer_pos=0;
70 buffer_printf(buffer, buffer_pos, "%02d", time->second);
71 getstringsize(digits_bitmaps, buffer, &str_w, &str_h);
72 draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2,
73 digits_bitmaps->height);
74 }
75 if(settings->general.date_format!=NONE){
76 format_date(buffer, time, settings->general.date_format);
77 getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h);
78 draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2,
79 display->height-smalldigits_bitmaps->height*2);
80 }
81 if(counter){
82 struct time counter_time;
83 counter_get_elapsed_time(counter, &counter_time);
84 rb->snprintf(buffer, 20, "%02d:%02d:%02d",
85 counter_time.hour, counter_time.minute, counter_time.second);
86 getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h);
87 draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2,
88 display->height-str_h);
89 }
90}