Remove plugin-specific defines from the pdbox makefile, and add them to m_pd.h, which...
[kugel-rb.git] / apps / plugins / clock / clock_draw_digital.c
blob7218b2c7b87b0824e9582a2fe8447152b8bdc76c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Copyright Kévin Ferrare
12 * 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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "clock.h"
23 #include "clock_draw_digital.h"
24 #include "clock_bitmap_strings.h"
25 #include "clock_bitmaps.h"
26 #include "lib/picture.h"
28 const struct picture* digits_skin[]={digits,segments};
29 const struct picture* smalldigits_skin[]={smalldigits,smallsegments};
31 #define buffer_printf(buffer, buffer_pos, ... ) \
32 buffer_pos+=rb->snprintf(&buffer[buffer_pos], sizeof(buffer)-buffer_pos, __VA_ARGS__);
34 void 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;
47 if(settings->digital.blinkcolon){
48 display_colon=(time->second%2==0);
50 else
51 display_colon=true;
53 if(settings->general.hour_format==H12 && time->hour>12)/* AM/PM format */
54 hour -= 12;
56 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);
59 if(settings->general.hour_format==H12){
60 if(time->hour>=12){
61 buffer_printf(buffer, buffer_pos, "P");/* PM */
62 }else{
63 buffer_printf(buffer, buffer_pos, "A");/* AM */
66 getstringsize(digits_bitmaps, buffer, &str_w, &str_h);
67 draw_string(display, digits_bitmaps, buffer,
68 (display->getwidth()-str_w)/2, 0);
69 if(settings->digital.show_seconds){
70 buffer_pos=0;
71 buffer_printf(buffer, buffer_pos, "%02d", time->second);
72 getstringsize(digits_bitmaps, buffer, &str_w, &str_h);
73 draw_string(display, digits_bitmaps, buffer,
74 (display->getwidth()-str_w)/2,
75 digits_bitmaps->slide_height);
77 if(settings->general.date_format!=NONE){
78 format_date(buffer, time, settings->general.date_format);
79 getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h);
80 draw_string(display, smalldigits_bitmaps, buffer,
81 (display->getwidth()-str_w)/2,
82 display->getheight()-smalldigits_bitmaps->slide_height*2);
84 if(counter){
85 struct time counter_time;
86 counter_get_elapsed_time(counter, &counter_time);
87 rb->snprintf(buffer, 20, "%02d:%02d:%02d",
88 counter_time.hour, counter_time.minute, counter_time.second);
89 getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h);
90 draw_string(display, smalldigits_bitmaps, buffer,
91 (display->getwidth()-str_w)/2, display->getheight()-str_h);