summaryrefslogtreecommitdiff
path: root/apps/plugins/clock/clock_draw_analog.c
diff options
context:
space:
mode:
authorKevin Ferrare <kevin@rockbox.org>2007-08-04 08:32:49 +0000
committerKevin Ferrare <kevin@rockbox.org>2007-08-04 08:32:49 +0000
commit721c897ad9b4377ebb3ed3e7bb9bdd5f4558d17e (patch)
treee09fb2be60212097371d3e13c7c12ec149cac655 /apps/plugins/clock/clock_draw_analog.c
parentdb6af4eeac61f7a4c999049fc49d0b51ac4b79ca (diff)
clock plugin : check wether it's necessary to save the settings, correct format for japanese dates on analog screen, code a little more clear
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14178 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/clock/clock_draw_analog.c')
-rw-r--r--apps/plugins/clock/clock_draw_analog.c163
1 files changed, 90 insertions, 73 deletions
diff --git a/apps/plugins/clock/clock_draw_analog.c b/apps/plugins/clock/clock_draw_analog.c
index 1fd98773f2..3cfb236db2 100644
--- a/apps/plugins/clock/clock_draw_analog.c
+++ b/apps/plugins/clock/clock_draw_analog.c
@@ -34,6 +34,7 @@
#define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10)
#define SECOND_ANGLE(second) (6 * (second))
+/* Note that the given angle's origin is midday and not 3 o'clock */
void polar_to_cartesian(int a, int r, int* x, int* y){
*x = (sin_int(a) * r) >> 14;
*y = (sin_int(a-90) * r) >> 14;
@@ -84,8 +85,7 @@ void draw_hand(struct screen* display, int angle,
int x1, y1; /* the longest */
int x2, y2, x3, y3; /* the base */
if(round){/* round clock */
- polar_to_cartesian_screen_centered(display, angle,
- radius, &x1, &y1);
+ polar_to_cartesian_screen_centered(display, angle, radius, &x1, &y1);
}else{/* fullscreen clock, hands describes square motions */
int square_width, square_height;
/* radius is defined smallest between width and height */
@@ -113,23 +113,78 @@ void draw_hands(struct screen* display, int hour, int minute, int second,
ANALOG_HOUR_RADIUS(display, round), thickness+2, round);
}
-/*******************
- * Analog clock mode
- ******************/
-void analog_clock_draw(struct screen* display, struct time* time,
- struct clock_settings* settings,
- struct counter* counter,
- int skin){
- int i;
+void draw_counter(struct screen* display, struct counter* counter){
+ char buffer[10];
+ int second_str_w, hour_str_w, str_h;
const struct picture* smalldigits_bitmaps =
- &(smalldigits[display->screen_type]);
+ &(smalldigits[display->screen_type]);
+ struct time counter_time;
+ counter_get_elapsed_time(counter, &counter_time);
+ rb->snprintf(buffer, 10, "%02d:%02d",
+ counter_time.hour, counter_time.minute);
+ getstringsize(smalldigits_bitmaps, buffer, &hour_str_w, &str_h);
+ draw_string(display, smalldigits_bitmaps, buffer,
+ display->width-hour_str_w,
+ display->height-2*str_h);
+
+ rb->snprintf(buffer, 10, "%02d", counter_time.second);
+ getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h);
+ draw_string(display, smalldigits_bitmaps, buffer,
+ display->width-(hour_str_w+second_str_w)/2,
+ display->height-str_h);
+}
+
+void draw_date(struct screen* display, struct time* time, int date_format){
+ char buffer[10];
+ int year_str_w, monthday_str_w, str_h;
+ int year_line=date_format==JAPANESE?1:2;
+ int monthday_line=date_format==JAPANESE?2:1;
+ const struct picture* smalldigits_bitmaps =
+ &(smalldigits[display->screen_type]);
+ if(date_format==ENGLISH || date_format==JAPANESE){
+ rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day);
+ }else{
+ rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month);
+ }
+ /* draws month and day */
+ getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h);
+ draw_string(display, smalldigits_bitmaps, buffer,
+ 0, display->height-year_line*str_h);
+ rb->snprintf(buffer, 10, "%04d", time->year);
+
+ /* draws year */
+ getstringsize(smalldigits_bitmaps, buffer, &year_str_w, &str_h);
+ draw_string(display, smalldigits_bitmaps, buffer,
+ (monthday_str_w-year_str_w)/2,
+ display->height-monthday_line*str_h);
+}
+
+void draw_border(struct screen* display, int skin){
+ /* Draws square dots every 5 minutes */
+ int i;
+ int x, y;
+ int size=display->height/50;/* size of the square dots */
+ if(size%2)/* a pair number */
+ size++;
+ for(i=0; i < 60; i+=5){
+ if(skin){
+ polar_to_cartesian_screen_centered(display, MINUTE_ANGLE(i, 0),
+ ANALOG_MINUTE_RADIUS(display, skin), &x, &y);
+ }else{
+ angle_to_square_screen_centered(
+ display, display->width/2-size/2, display->height/2-size/2,
+ MINUTE_ANGLE(i, 0), &x, &y);
+ }
+ display->fillrect(x-size/2, y-size/2, size, size);
+ }
+}
+
+void draw_hour(struct screen* display, struct time* time,
+ bool show_seconds, int skin){
int hour=time->hour;
if(hour >= 12)
hour -= 12;
- /* show_date */
- /* show_digital_time*/
-
/* Crappy fake antialiasing (color LCDs only)!
* how this works is we draw a large mid-gray hr/min/sec hand,
* then the actual (slightly smaller) hand on top of those.
@@ -137,69 +192,16 @@ void analog_clock_draw(struct screen* display, struct time* time,
#ifdef HAVE_LCD_COLOR
if(display->is_color){
display->set_foreground(LCD_RGBPACK(100,110,125));
- draw_hands(display, hour, time->minute, time->second, 2,
- skin, settings->analog.show_seconds);
+ draw_hands(display, hour, time->minute, time->second,
+ 2, skin, show_seconds);
display->set_foreground(LCD_BLACK);
}
#endif
- draw_hands(display, hour, time->minute, time->second, 0, skin,
- settings->analog.show_seconds);
-
- if(settings->analog.show_border){
- /* Draws square dots every 5 minutes */
- int x, y;
- int size=display->height/50;/* size of the square dots */
- if(size%2)/* a pair number */
- size++;
- for(i=0; i < 60; i+=5){
- if(skin){
- polar_to_cartesian_screen_centered(display, MINUTE_ANGLE(i, 0),
- ANALOG_MINUTE_RADIUS(display, skin), &x, &y);
- }else{
- angle_to_square_screen_centered(
- display, display->width/2-size/2, display->height/2-size/2,
- MINUTE_ANGLE(i, 0), &x, &y);
- }
- display->fillrect(x-size/2, y-size/2, size, size);
- }
- }
-
- if(counter){
- char buffer[10];
- int second_str_w, hour_str_w, str_h;
- struct time counter_time;
- counter_get_elapsed_time(counter, &counter_time);
- rb->snprintf(buffer, 10, "%02d:%02d",
- counter_time.hour, counter_time.minute);
- getstringsize(smalldigits_bitmaps, buffer, &hour_str_w, &str_h);
- draw_string(display, smalldigits_bitmaps, buffer,
- display->width-hour_str_w,
- display->height-2*str_h);
-
- rb->snprintf(buffer, 10, "%02d", counter_time.second);
- getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h);
- draw_string(display, smalldigits_bitmaps, buffer,
- display->width-(hour_str_w+second_str_w)/2,
- display->height-str_h);
- }
- if(settings->analog.show_date && settings->general.date_format!=NONE){
- char buffer[10];
- int year_str_w, monthday_str_w, str_h;
- if(settings->general.date_format==ENGLISH){
- rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day);
- }else{
- rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month);
- }
- getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h);
- draw_string(display, smalldigits_bitmaps, buffer,
- 0, display->height-2*str_h);
- rb->snprintf(buffer, 10, "%04d", time->year);
- getstringsize(smalldigits_bitmaps, buffer, &year_str_w, &str_h);
- draw_string(display, smalldigits_bitmaps, buffer,
- (monthday_str_w-year_str_w)/2, display->height-str_h);
- }
+ draw_hands(display, hour, time->minute, time->second,
+ 0, skin, show_seconds);
+}
- /* Draw the cover over the center */
+void draw_center_cover(struct screen* display){
display->drawline((display->width/2)-1, (display->height/2)+3,
(display->width/2)+1, (display->height/2)+3);
display->drawline((display->width/2)-3, (display->height/2)+2,
@@ -215,3 +217,18 @@ void analog_clock_draw(struct screen* display, struct time* time,
display->drawline((display->width/2)-1, (display->height/2)-3,
(display->width/2)+1, (display->height/2)-3);
}
+
+void analog_clock_draw(struct screen* display, struct time* time,
+ struct clock_settings* settings,
+ struct counter* counter,
+ int skin){
+
+ draw_hour(display, time, settings->analog.show_seconds, skin);
+ if(settings->analog.show_border)
+ draw_border(display, skin);
+ if(counter)
+ draw_counter(display, counter);
+ if(settings->analog.show_date && settings->general.date_format!=NONE)
+ draw_date(display, time, settings->general.date_format);
+ draw_center_cover(display);
+}