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
This commit is contained in:
Kevin Ferrare 2007-08-04 08:32:49 +00:00
parent db6af4eeac
commit 721c897ad9
3 changed files with 102 additions and 75 deletions

View file

@ -170,8 +170,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
break;
case ACTION_EXIT:
/*clock_draw_restore_colors();
exit_clock=main_menu();*/
exit_clock=true;
break;

View file

@ -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);
draw_hands(display, hour, time->minute, time->second,
0, skin, 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 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);
}

View file

@ -45,6 +45,14 @@ enum settings_file_status{
struct clock_settings clock_settings;
/* The settings as they exist on the hard disk, so that
* we can know at saving time if changes have been made */
struct clock_settings hdd_clock_settings;
bool settings_needs_saving(struct clock_settings* settings){
return(rb->memcmp(settings, &hdd_clock_settings, sizeof(*settings)));
}
void clock_settings_reset(struct clock_settings* settings){
settings->mode = ANALOG;
int i;
@ -98,6 +106,7 @@ enum settings_file_status clock_settings_load(struct clock_settings* settings,
rb->read(fd, settings, sizeof(*settings));
rb->close(fd);
apply_backlight_setting(settings->general.backlight);
rb->memcpy(&hdd_clock_settings, settings, sizeof(*settings));
return(LOADED);
}
}
@ -171,6 +180,9 @@ void load_settings(void){
void save_settings(void){
int i;
struct screen* display;
if(!settings_needs_saving(&clock_settings))
return;
FOR_NB_SCREENS(i){
display=rb->screens[i];
display->clear_display();