diff options
Diffstat (limited to 'apps/plugins/clock/clock_draw_analog.c')
-rw-r--r-- | apps/plugins/clock/clock_draw_analog.c | 163 |
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 @@ | |||
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 | } | ||