diff options
Diffstat (limited to 'apps/plugins/clock')
-rw-r--r-- | apps/plugins/clock/clock.c | 2 | ||||
-rw-r--r-- | apps/plugins/clock/clock_draw_analog.c | 163 | ||||
-rw-r--r-- | apps/plugins/clock/clock_settings.c | 12 |
3 files changed, 102 insertions, 75 deletions
diff --git a/apps/plugins/clock/clock.c b/apps/plugins/clock/clock.c index 46d167ba54..d80f6dca03 100644 --- a/apps/plugins/clock/clock.c +++ b/apps/plugins/clock/clock.c | |||
@@ -170,8 +170,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ | |||
170 | break; | 170 | break; |
171 | 171 | ||
172 | case ACTION_EXIT: | 172 | case ACTION_EXIT: |
173 | /*clock_draw_restore_colors(); | ||
174 | exit_clock=main_menu();*/ | ||
175 | exit_clock=true; | 173 | exit_clock=true; |
176 | break; | 174 | break; |
177 | 175 | ||
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 @@ | |||
34 | #define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10) | 34 | #define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10) |
35 | #define SECOND_ANGLE(second) (6 * (second)) | 35 | #define SECOND_ANGLE(second) (6 * (second)) |
36 | 36 | ||
37 | /* Note that the given angle's origin is midday and not 3 o'clock */ | ||
37 | void polar_to_cartesian(int a, int r, int* x, int* y){ | 38 | void polar_to_cartesian(int a, int r, int* x, int* y){ |
38 | *x = (sin_int(a) * r) >> 14; | 39 | *x = (sin_int(a) * r) >> 14; |
39 | *y = (sin_int(a-90) * r) >> 14; | 40 | *y = (sin_int(a-90) * r) >> 14; |
@@ -84,8 +85,7 @@ void draw_hand(struct screen* display, int angle, | |||
84 | int x1, y1; /* the longest */ | 85 | int x1, y1; /* the longest */ |
85 | int x2, y2, x3, y3; /* the base */ | 86 | int x2, y2, x3, y3; /* the base */ |
86 | if(round){/* round clock */ | 87 | if(round){/* round clock */ |
87 | polar_to_cartesian_screen_centered(display, angle, | 88 | polar_to_cartesian_screen_centered(display, angle, radius, &x1, &y1); |
88 | radius, &x1, &y1); | ||
89 | }else{/* fullscreen clock, hands describes square motions */ | 89 | }else{/* fullscreen clock, hands describes square motions */ |
90 | int square_width, square_height; | 90 | int square_width, square_height; |
91 | /* radius is defined smallest between width and height */ | 91 | /* radius is defined smallest between width and height */ |
@@ -113,23 +113,78 @@ void draw_hands(struct screen* display, int hour, int minute, int second, | |||
113 | ANALOG_HOUR_RADIUS(display, round), thickness+2, round); | 113 | ANALOG_HOUR_RADIUS(display, round), thickness+2, round); |
114 | } | 114 | } |
115 | 115 | ||
116 | /******************* | 116 | void draw_counter(struct screen* display, struct counter* counter){ |
117 | * Analog clock mode | 117 | char buffer[10]; |
118 | ******************/ | 118 | int second_str_w, hour_str_w, str_h; |
119 | void analog_clock_draw(struct screen* display, struct time* time, | ||
120 | struct clock_settings* settings, | ||
121 | struct counter* counter, | ||
122 | int skin){ | ||
123 | int i; | ||
124 | const struct picture* smalldigits_bitmaps = | 119 | const struct picture* smalldigits_bitmaps = |
125 | &(smalldigits[display->screen_type]); | 120 | &(smalldigits[display->screen_type]); |
121 | struct time counter_time; | ||
122 | counter_get_elapsed_time(counter, &counter_time); | ||
123 | rb->snprintf(buffer, 10, "%02d:%02d", | ||
124 | counter_time.hour, counter_time.minute); | ||
125 | getstringsize(smalldigits_bitmaps, buffer, &hour_str_w, &str_h); | ||
126 | draw_string(display, smalldigits_bitmaps, buffer, | ||
127 | display->width-hour_str_w, | ||
128 | display->height-2*str_h); | ||
129 | |||
130 | rb->snprintf(buffer, 10, "%02d", counter_time.second); | ||
131 | getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h); | ||
132 | draw_string(display, smalldigits_bitmaps, buffer, | ||
133 | display->width-(hour_str_w+second_str_w)/2, | ||
134 | display->height-str_h); | ||
135 | } | ||
136 | |||
137 | void draw_date(struct screen* display, struct time* time, int date_format){ | ||
138 | char buffer[10]; | ||
139 | int year_str_w, monthday_str_w, str_h; | ||
140 | int year_line=date_format==JAPANESE?1:2; | ||
141 | int monthday_line=date_format==JAPANESE?2:1; | ||
142 | const struct picture* smalldigits_bitmaps = | ||
143 | &(smalldigits[display->screen_type]); | ||
144 | if(date_format==ENGLISH || date_format==JAPANESE){ | ||
145 | rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day); | ||
146 | }else{ | ||
147 | rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month); | ||
148 | } | ||
149 | /* draws month and day */ | ||
150 | getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h); | ||
151 | draw_string(display, smalldigits_bitmaps, buffer, | ||
152 | 0, display->height-year_line*str_h); | ||
153 | rb->snprintf(buffer, 10, "%04d", time->year); | ||
154 | |||
155 | /* draws year */ | ||
156 | getstringsize(smalldigits_bitmaps, buffer, &year_str_w, &str_h); | ||
157 | draw_string(display, smalldigits_bitmaps, buffer, | ||
158 | (monthday_str_w-year_str_w)/2, | ||
159 | display->height-monthday_line*str_h); | ||
160 | } | ||
161 | |||
162 | void draw_border(struct screen* display, int skin){ | ||
163 | /* Draws square dots every 5 minutes */ | ||
164 | int i; | ||
165 | int x, y; | ||
166 | int size=display->height/50;/* size of the square dots */ | ||
167 | if(size%2)/* a pair number */ | ||
168 | size++; | ||
169 | for(i=0; i < 60; i+=5){ | ||
170 | if(skin){ | ||
171 | polar_to_cartesian_screen_centered(display, MINUTE_ANGLE(i, 0), | ||
172 | ANALOG_MINUTE_RADIUS(display, skin), &x, &y); | ||
173 | }else{ | ||
174 | angle_to_square_screen_centered( | ||
175 | display, display->width/2-size/2, display->height/2-size/2, | ||
176 | MINUTE_ANGLE(i, 0), &x, &y); | ||
177 | } | ||
178 | display->fillrect(x-size/2, y-size/2, size, size); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | void draw_hour(struct screen* display, struct time* time, | ||
183 | bool show_seconds, int skin){ | ||
126 | int hour=time->hour; | 184 | int hour=time->hour; |
127 | if(hour >= 12) | 185 | if(hour >= 12) |
128 | hour -= 12; | 186 | hour -= 12; |
129 | 187 | ||
130 | /* show_date */ | ||
131 | /* show_digital_time*/ | ||
132 | |||
133 | /* Crappy fake antialiasing (color LCDs only)! | 188 | /* Crappy fake antialiasing (color LCDs only)! |
134 | * how this works is we draw a large mid-gray hr/min/sec hand, | 189 | * how this works is we draw a large mid-gray hr/min/sec hand, |
135 | * then the actual (slightly smaller) hand on top of those. | 190 | * then the actual (slightly smaller) hand on top of those. |
@@ -137,69 +192,16 @@ void analog_clock_draw(struct screen* display, struct time* time, | |||
137 | #ifdef HAVE_LCD_COLOR | 192 | #ifdef HAVE_LCD_COLOR |
138 | if(display->is_color){ | 193 | if(display->is_color){ |
139 | display->set_foreground(LCD_RGBPACK(100,110,125)); | 194 | display->set_foreground(LCD_RGBPACK(100,110,125)); |
140 | draw_hands(display, hour, time->minute, time->second, 2, | 195 | draw_hands(display, hour, time->minute, time->second, |
141 | skin, settings->analog.show_seconds); | 196 | 2, skin, show_seconds); |
142 | display->set_foreground(LCD_BLACK); | 197 | display->set_foreground(LCD_BLACK); |
143 | } | 198 | } |
144 | #endif | 199 | #endif |
145 | draw_hands(display, hour, time->minute, time->second, 0, skin, | 200 | draw_hands(display, hour, time->minute, time->second, |
146 | settings->analog.show_seconds); | 201 | 0, skin, show_seconds); |
147 | 202 | } | |
148 | if(settings->analog.show_border){ | ||
149 | /* Draws square dots every 5 minutes */ | ||
150 | int x, y; | ||
151 | int size=display->height/50;/* size of the square dots */ | ||
152 | if(size%2)/* a pair number */ | ||
153 | size++; | ||
154 | for(i=0; i < 60; i+=5){ | ||
155 | if(skin){ | ||
156 | polar_to_cartesian_screen_centered(display, MINUTE_ANGLE(i, 0), | ||
157 | ANALOG_MINUTE_RADIUS(display, skin), &x, &y); | ||
158 | }else{ | ||
159 | angle_to_square_screen_centered( | ||
160 | display, display->width/2-size/2, display->height/2-size/2, | ||
161 | MINUTE_ANGLE(i, 0), &x, &y); | ||
162 | } | ||
163 | display->fillrect(x-size/2, y-size/2, size, size); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | if(counter){ | ||
168 | char buffer[10]; | ||
169 | int second_str_w, hour_str_w, str_h; | ||
170 | struct time counter_time; | ||
171 | counter_get_elapsed_time(counter, &counter_time); | ||
172 | rb->snprintf(buffer, 10, "%02d:%02d", | ||
173 | counter_time.hour, counter_time.minute); | ||
174 | getstringsize(smalldigits_bitmaps, buffer, &hour_str_w, &str_h); | ||
175 | draw_string(display, smalldigits_bitmaps, buffer, | ||
176 | display->width-hour_str_w, | ||
177 | display->height-2*str_h); | ||
178 | |||
179 | rb->snprintf(buffer, 10, "%02d", counter_time.second); | ||
180 | getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h); | ||
181 | draw_string(display, smalldigits_bitmaps, buffer, | ||
182 | display->width-(hour_str_w+second_str_w)/2, | ||
183 | display->height-str_h); | ||
184 | } | ||
185 | if(settings->analog.show_date && settings->general.date_format!=NONE){ | ||
186 | char buffer[10]; | ||
187 | int year_str_w, monthday_str_w, str_h; | ||
188 | if(settings->general.date_format==ENGLISH){ | ||
189 | rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day); | ||
190 | }else{ | ||
191 | rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month); | ||
192 | } | ||
193 | getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h); | ||
194 | draw_string(display, smalldigits_bitmaps, buffer, | ||
195 | 0, display->height-2*str_h); | ||
196 | rb->snprintf(buffer, 10, "%04d", time->year); | ||
197 | getstringsize(smalldigits_bitmaps, buffer, &year_str_w, &str_h); | ||
198 | draw_string(display, smalldigits_bitmaps, buffer, | ||
199 | (monthday_str_w-year_str_w)/2, display->height-str_h); | ||
200 | } | ||
201 | 203 | ||
202 | /* Draw the cover over the center */ | 204 | void draw_center_cover(struct screen* display){ |
203 | display->drawline((display->width/2)-1, (display->height/2)+3, | 205 | display->drawline((display->width/2)-1, (display->height/2)+3, |
204 | (display->width/2)+1, (display->height/2)+3); | 206 | (display->width/2)+1, (display->height/2)+3); |
205 | display->drawline((display->width/2)-3, (display->height/2)+2, | 207 | display->drawline((display->width/2)-3, (display->height/2)+2, |
@@ -215,3 +217,18 @@ void analog_clock_draw(struct screen* display, struct time* time, | |||
215 | display->drawline((display->width/2)-1, (display->height/2)-3, | 217 | display->drawline((display->width/2)-1, (display->height/2)-3, |
216 | (display->width/2)+1, (display->height/2)-3); | 218 | (display->width/2)+1, (display->height/2)-3); |
217 | } | 219 | } |
220 | |||
221 | void analog_clock_draw(struct screen* display, struct time* time, | ||
222 | struct clock_settings* settings, | ||
223 | struct counter* counter, | ||
224 | int skin){ | ||
225 | |||
226 | draw_hour(display, time, settings->analog.show_seconds, skin); | ||
227 | if(settings->analog.show_border) | ||
228 | draw_border(display, skin); | ||
229 | if(counter) | ||
230 | draw_counter(display, counter); | ||
231 | if(settings->analog.show_date && settings->general.date_format!=NONE) | ||
232 | draw_date(display, time, settings->general.date_format); | ||
233 | draw_center_cover(display); | ||
234 | } | ||
diff --git a/apps/plugins/clock/clock_settings.c b/apps/plugins/clock/clock_settings.c index 9bd7c90d3b..b59a265a3b 100644 --- a/apps/plugins/clock/clock_settings.c +++ b/apps/plugins/clock/clock_settings.c | |||
@@ -45,6 +45,14 @@ enum settings_file_status{ | |||
45 | 45 | ||
46 | struct clock_settings clock_settings; | 46 | struct clock_settings clock_settings; |
47 | 47 | ||
48 | /* The settings as they exist on the hard disk, so that | ||
49 | * we can know at saving time if changes have been made */ | ||
50 | struct clock_settings hdd_clock_settings; | ||
51 | |||
52 | bool settings_needs_saving(struct clock_settings* settings){ | ||
53 | return(rb->memcmp(settings, &hdd_clock_settings, sizeof(*settings))); | ||
54 | } | ||
55 | |||
48 | void clock_settings_reset(struct clock_settings* settings){ | 56 | void clock_settings_reset(struct clock_settings* settings){ |
49 | settings->mode = ANALOG; | 57 | settings->mode = ANALOG; |
50 | int i; | 58 | int i; |
@@ -98,6 +106,7 @@ enum settings_file_status clock_settings_load(struct clock_settings* settings, | |||
98 | rb->read(fd, settings, sizeof(*settings)); | 106 | rb->read(fd, settings, sizeof(*settings)); |
99 | rb->close(fd); | 107 | rb->close(fd); |
100 | apply_backlight_setting(settings->general.backlight); | 108 | apply_backlight_setting(settings->general.backlight); |
109 | rb->memcpy(&hdd_clock_settings, settings, sizeof(*settings)); | ||
101 | return(LOADED); | 110 | return(LOADED); |
102 | } | 111 | } |
103 | } | 112 | } |
@@ -171,6 +180,9 @@ void load_settings(void){ | |||
171 | void save_settings(void){ | 180 | void save_settings(void){ |
172 | int i; | 181 | int i; |
173 | struct screen* display; | 182 | struct screen* display; |
183 | if(!settings_needs_saving(&clock_settings)) | ||
184 | return; | ||
185 | |||
174 | FOR_NB_SCREENS(i){ | 186 | FOR_NB_SCREENS(i){ |
175 | display=rb->screens[i]; | 187 | display=rb->screens[i]; |
176 | display->clear_display(); | 188 | display->clear_display(); |