static void paint_clock(ClockIcon *aIcon, GContext *aCtx, GRect r, GPoint aCenter, int32_t aRadius, bool aAnimating, bool aZoomedIn) { // background if (aAnimating) { graphics_context_set_stroke_color(aCtx, GColorWhite); for (int32_t i = 0; i < 60; ++i) { int32_t len1 = aRadius; int32_t len2 = (i % 5 == 0) ? CLOCK_HOUR_MARK_START_LENGTH(aRadius) : CLOCK_MIN_MARK_START_LENGTH(aRadius); int32_t angle = TRIG_MAX_ANGLE * i / 60.f; draw_angle_line(aCtx, aCenter, angle, len1, len2, (i % 5 == 0) ? LineWidth2 : LineWidth1); } graphics_context_set_fill_color(aCtx, GColorWhite); graphics_context_set_stroke_color(aCtx, GColorWhite); } else { graphics_context_set_fill_color(aCtx, GColorWhite); graphics_fill_circle(aCtx, aCenter, aRadius); graphics_context_set_fill_color(aCtx, GColorBlack); graphics_context_set_stroke_color(aCtx, GColorBlack); } clock_icon_data *data = layer_get_data(aIcon); int32_t h = data->h; int32_t m = data->m; int32_t s = data->s; // hour hand draw_clock_hand(aCtx, aCenter, aRadius, aZoomedIn, CLOCK_HOUR_HAND_LENGTH(aRadius), TRIG_MAX_ANGLE * (h + m / 60.f) / 12.f); // minutes hand draw_clock_hand(aCtx, aCenter, aRadius, aZoomedIn, CLOCK_MIN_HAND_LENGTH(aRadius), TRIG_MAX_ANGLE * (m + s / 60.f) / 60.f); if (aZoomedIn) { graphics_draw_circle(aCtx, aCenter, CLOCK_CENTER_RADIUS - 1); } if (!aAnimating && !aZoomedIn && !clock_icon_shows_second_hand()) { // don't draw second hand if preffed off. return; } // seconds hand int32_t secLength = CLOCK_SEC_HAND_LENGTH(aRadius); int32_t secAngle = TRIG_MAX_ANGLE * s / 60.f; #ifdef PBL_COLOR graphics_context_set_stroke_color(aCtx, GColorChromeYellow); #endif if (aZoomedIn) { draw_angle_line(aCtx, aCenter, secAngle, CLOCK_CENTER_RADIUS, secLength, LineWidth1); } else { draw_angle_line(aCtx, aCenter, secAngle, 0, secLength, LineWidth1); } }
// canvas::draw overridable virtual void draw( HELEMENT he, graphics& gx, UINT width, UINT height ) { SYSTEMTIME st; GetLocalTime(&st); //Use GetSystemTime(&st); - if you need clocks in UTC or other TZ //you may use something like get_attribute("timezone") const wchar_t* caption = dom::element(he).get_attribute("caption"); if( caption ) draw_caption( he, gx, width, height, aux::chars_of(caption) ); draw_clock_hand(he, gx,width,height, (st.wHour * 360.0) / 12.0 + st.wMinute / 2.0, 0); draw_clock_hand(he, gx,width,height, (st.wMinute * 360.0) / 60.0, 1); draw_clock_hand(he, gx,width,height, (st.wSecond * 360.0) / 60.0, 2); }
virtual BOOL on_draw (HELEMENT he, UINT draw_type, HDC hdc, const RECT& rc ) { if( draw_type != DRAW_CONTENT ) return FALSE; /*do default draw*/ // we can get color settings from attributes but for simplicity lets use // default values SYSTEMTIME st; GetLocalTime(&st); //Use GetSystemTime(&st); - if you need clocks in UTC or other TZ //you may use something like get_attribute("timezone") draw_clock_hand(hdc,rc, (st.wHour * 360.0) / 12.0 + st.wMinute / 2.0, 0); draw_clock_hand(hdc,rc, (st.wMinute * 360.0) / 60.0, 1); draw_clock_hand(hdc,rc, (st.wSecond * 360.0) / 60.0, 2); return TRUE; /*skip default draw as we did it already*/ }