forked from len0rd/rockbox
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:
parent
db6af4eeac
commit
721c897ad9
3 changed files with 102 additions and 75 deletions
|
@ -170,8 +170,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_EXIT:
|
case ACTION_EXIT:
|
||||||
/*clock_draw_restore_colors();
|
|
||||||
exit_clock=main_menu();*/
|
|
||||||
exit_clock=true;
|
exit_clock=true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10)
|
#define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10)
|
||||||
#define SECOND_ANGLE(second) (6 * (second))
|
#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){
|
void polar_to_cartesian(int a, int r, int* x, int* y){
|
||||||
*x = (sin_int(a) * r) >> 14;
|
*x = (sin_int(a) * r) >> 14;
|
||||||
*y = (sin_int(a-90) * 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 x1, y1; /* the longest */
|
||||||
int x2, y2, x3, y3; /* the base */
|
int x2, y2, x3, y3; /* the base */
|
||||||
if(round){/* round clock */
|
if(round){/* round clock */
|
||||||
polar_to_cartesian_screen_centered(display, angle,
|
polar_to_cartesian_screen_centered(display, angle, radius, &x1, &y1);
|
||||||
radius, &x1, &y1);
|
|
||||||
}else{/* fullscreen clock, hands describes square motions */
|
}else{/* fullscreen clock, hands describes square motions */
|
||||||
int square_width, square_height;
|
int square_width, square_height;
|
||||||
/* radius is defined smallest between width and height */
|
/* radius is defined smallest between width and height */
|
||||||
|
@ -113,40 +113,55 @@ void draw_hands(struct screen* display, int hour, int minute, int second,
|
||||||
ANALOG_HOUR_RADIUS(display, round), thickness+2, round);
|
ANALOG_HOUR_RADIUS(display, round), thickness+2, round);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************
|
void draw_counter(struct screen* display, struct counter* counter){
|
||||||
* Analog clock mode
|
char buffer[10];
|
||||||
******************/
|
int second_str_w, hour_str_w, str_h;
|
||||||
void analog_clock_draw(struct screen* display, struct time* time,
|
|
||||||
struct clock_settings* settings,
|
|
||||||
struct counter* counter,
|
|
||||||
int skin){
|
|
||||||
int i;
|
|
||||||
const struct picture* smalldigits_bitmaps =
|
const struct picture* smalldigits_bitmaps =
|
||||||
&(smalldigits[display->screen_type]);
|
&(smalldigits[display->screen_type]);
|
||||||
int hour=time->hour;
|
struct time counter_time;
|
||||||
if(hour >= 12)
|
counter_get_elapsed_time(counter, &counter_time);
|
||||||
hour -= 12;
|
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);
|
||||||
|
|
||||||
/* show_date */
|
rb->snprintf(buffer, 10, "%02d", counter_time.second);
|
||||||
/* show_digital_time*/
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/* Crappy fake antialiasing (color LCDs only)!
|
void draw_date(struct screen* display, struct time* time, int date_format){
|
||||||
* how this works is we draw a large mid-gray hr/min/sec hand,
|
char buffer[10];
|
||||||
* then the actual (slightly smaller) hand on top of those.
|
int year_str_w, monthday_str_w, str_h;
|
||||||
* End result: mid-gray edges to the black hands, smooths them out. */
|
int year_line=date_format==JAPANESE?1:2;
|
||||||
#ifdef HAVE_LCD_COLOR
|
int monthday_line=date_format==JAPANESE?2:1;
|
||||||
if(display->is_color){
|
const struct picture* smalldigits_bitmaps =
|
||||||
display->set_foreground(LCD_RGBPACK(100,110,125));
|
&(smalldigits[display->screen_type]);
|
||||||
draw_hands(display, hour, time->minute, time->second, 2,
|
if(date_format==ENGLISH || date_format==JAPANESE){
|
||||||
skin, settings->analog.show_seconds);
|
rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day);
|
||||||
display->set_foreground(LCD_BLACK);
|
}else{
|
||||||
|
rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month);
|
||||||
}
|
}
|
||||||
#endif
|
/* draws month and day */
|
||||||
draw_hands(display, hour, time->minute, time->second, 0, skin,
|
getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h);
|
||||||
settings->analog.show_seconds);
|
draw_string(display, smalldigits_bitmaps, buffer,
|
||||||
|
0, display->height-year_line*str_h);
|
||||||
|
rb->snprintf(buffer, 10, "%04d", time->year);
|
||||||
|
|
||||||
if(settings->analog.show_border){
|
/* 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 */
|
/* Draws square dots every 5 minutes */
|
||||||
|
int i;
|
||||||
int x, y;
|
int x, y;
|
||||||
int size=display->height/50;/* size of the square dots */
|
int size=display->height/50;/* size of the square dots */
|
||||||
if(size%2)/* a pair number */
|
if(size%2)/* a pair number */
|
||||||
|
@ -162,44 +177,31 @@ void analog_clock_draw(struct screen* display, struct time* time,
|
||||||
}
|
}
|
||||||
display->fillrect(x-size/2, y-size/2, size, size);
|
display->fillrect(x-size/2, y-size/2, size, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(counter){
|
void draw_hour(struct screen* display, struct time* time,
|
||||||
char buffer[10];
|
bool show_seconds, int skin){
|
||||||
int second_str_w, hour_str_w, str_h;
|
int hour=time->hour;
|
||||||
struct time counter_time;
|
if(hour >= 12)
|
||||||
counter_get_elapsed_time(counter, &counter_time);
|
hour -= 12;
|
||||||
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);
|
/* Crappy fake antialiasing (color LCDs only)!
|
||||||
getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h);
|
* how this works is we draw a large mid-gray hr/min/sec hand,
|
||||||
draw_string(display, smalldigits_bitmaps, buffer,
|
* then the actual (slightly smaller) hand on top of those.
|
||||||
display->width-(hour_str_w+second_str_w)/2,
|
* End result: mid-gray edges to the black hands, smooths them out. */
|
||||||
display->height-str_h);
|
#ifdef HAVE_LCD_COLOR
|
||||||
}
|
if(display->is_color){
|
||||||
if(settings->analog.show_date && settings->general.date_format!=NONE){
|
display->set_foreground(LCD_RGBPACK(100,110,125));
|
||||||
char buffer[10];
|
draw_hands(display, hour, time->minute, time->second,
|
||||||
int year_str_w, monthday_str_w, str_h;
|
2, skin, show_seconds);
|
||||||
if(settings->general.date_format==ENGLISH){
|
display->set_foreground(LCD_BLACK);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
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->drawline((display->width/2)-1, (display->height/2)+3,
|
||||||
(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,
|
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->drawline((display->width/2)-1, (display->height/2)-3,
|
||||||
(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);
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,14 @@ enum settings_file_status{
|
||||||
|
|
||||||
struct clock_settings clock_settings;
|
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){
|
void clock_settings_reset(struct clock_settings* settings){
|
||||||
settings->mode = ANALOG;
|
settings->mode = ANALOG;
|
||||||
int i;
|
int i;
|
||||||
|
@ -98,6 +106,7 @@ enum settings_file_status clock_settings_load(struct clock_settings* settings,
|
||||||
rb->read(fd, settings, sizeof(*settings));
|
rb->read(fd, settings, sizeof(*settings));
|
||||||
rb->close(fd);
|
rb->close(fd);
|
||||||
apply_backlight_setting(settings->general.backlight);
|
apply_backlight_setting(settings->general.backlight);
|
||||||
|
rb->memcpy(&hdd_clock_settings, settings, sizeof(*settings));
|
||||||
return(LOADED);
|
return(LOADED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,6 +180,9 @@ void load_settings(void){
|
||||||
void save_settings(void){
|
void save_settings(void){
|
||||||
int i;
|
int i;
|
||||||
struct screen* display;
|
struct screen* display;
|
||||||
|
if(!settings_needs_saving(&clock_settings))
|
||||||
|
return;
|
||||||
|
|
||||||
FOR_NB_SCREENS(i){
|
FOR_NB_SCREENS(i){
|
||||||
display=rb->screens[i];
|
display=rb->screens[i];
|
||||||
display->clear_display();
|
display->clear_display();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue