Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pebble.h>
- #define row_four_blocks 4
- #define row_eleven_blocks 11
- #define outline_four_row_width 30
- #define outline_four_row_next 31
- #define outline_four_row_height 17
- #define outline_four_row_offset 10
- #define ball_radius 21
- #define ball_x 70
- #define ball_y 41
- #define outline_eleven_row_width 11
- #define outline_eleven_row_height 12
- #define outline_eleven_row_next 12
- #define outline_first_row_y 67
- #define outline_second_row_y 91
- #define outline_third_row_y 114
- #define outline_fourth_row_y 134
- #define fill_four_row_offset 12
- #define fill_first_row_y 69
- #define fill_second_row_y 93
- #define fill_third_row_y 116
- #define fill_fourth_row_y 136
- #define fill_four_row_width 27
- #define fill_four_row_height 13
- #define fill_eleven_row_width 8
- #define fill_eleven_row_height 8
- #define ball_fill_radius 18
- static Window *s_main_window;
- static Layer *s_outline_layer;
- static Layer *s_fill_layer;
- struct BerlinClock {
- // Might be a good idea to try and object-orient this thing.
- // bool initializied;
- GRect first_row[row_four_blocks];
- GRect second_row[row_four_blocks];
- GRect third_row[row_eleven_blocks];
- GRect fourth_row[row_four_blocks];
- };
- struct BerlinClock watch;
- int odd( int number ){
- return (number%2);
- }
- static void outline_update_procedure( Layer *this_layer, GContext *context ){
- graphics_context_set_stroke_color( context, GColorWhite );
- graphics_context_set_fill_color( context, GColorWhite );
- for ( int i = 0; i < row_four_blocks; i++ ){
- graphics_draw_rect( context, GRect( i*outline_four_row_width + outline_four_row_offset, outline_first_row_y, outline_four_row_next, outline_four_row_height ) );
- graphics_draw_rect( context, GRect( i*outline_four_row_width + outline_four_row_offset, outline_second_row_y, outline_four_row_next, outline_four_row_height ) );
- graphics_draw_rect( context, GRect( i*outline_four_row_width + outline_four_row_offset, outline_fourth_row_y, outline_four_row_next, outline_four_row_height ) );
- }
- for ( int i = 0; i < row_eleven_blocks; i++ ){
- graphics_draw_rect( context, GRect( i*outline_eleven_row_width + outline_four_row_offset, outline_third_row_y, outline_eleven_row_next, outline_eleven_row_height ) );
- }
- graphics_draw_circle( context, GPoint( ball_x, ball_y ), ball_radius );
- }
- static void fill_update_procedure( Layer *this_layer, GContext *context ){
- time_t temp = time(NULL);
- struct tm *ttime = localtime( &temp );
- if ( odd( ttime->tm_sec ) ){
- graphics_context_set_fill_color( context, GColorWhite );
- graphics_fill_circle( context, GPoint( ball_x, ball_y ), ball_fill_radius );
- }else{
- graphics_context_set_fill_color( context, GColorBlack );
- graphics_fill_circle( context, GPoint( ball_x, ball_y ), ball_fill_radius );
- }
- int first_row = (int)(ttime->tm_hour / 5);
- int second_row = (ttime->tm_hour % 5);
- int third_row = (int)(ttime->tm_min / 5);
- int fourth_row = (ttime->tm_min % 5);
- graphics_context_set_fill_color( context, GColorWhite );
- for ( int i = 0; i < first_row; i++ ){
- graphics_fill_rect( context, watch.first_row[i], 0, GCornerNone );
- }
- for ( int i = 0; i < second_row; i++ ){
- graphics_fill_rect( context, watch.second_row[i], 0, GCornerNone );
- }
- for ( int i = 0; i < third_row; i++ ){
- graphics_fill_rect( context, watch.third_row[i], 0, GCornerNone );
- }
- for ( int i = 0; i < fourth_row; i++ ){
- graphics_fill_rect( context, watch.fourth_row[i], 0, GCornerNone );
- }
- }
- static void tick_handler( struct tm *tick_time, TimeUnits units_changed ){
- layer_mark_dirty( s_fill_layer );
- /*
- Marks the complete layer as "dirty", awaiting to be asked by the
- system to redraw itself. Typically, this function is called whenever state
- has changed that affects what the layer is displaying. The layer's
- .update_proc will not be called before this function returns, but will be
- called asynchronously, shortly.
- */
- }
- static void main_window_load( Window *window ){
- Layer *window_layer = window_get_root_layer( window );
- GRect window_bounds = layer_get_bounds( window_layer );
- s_outline_layer = layer_create( GRect( 0, 0, window_bounds.size.w, window_bounds.size.h ) );
- s_fill_layer = layer_create( GRect( 0, 0, window_bounds.size.w, window_bounds.size.h ) );
- layer_add_child( window_layer, s_outline_layer );
- layer_add_child( s_outline_layer, s_fill_layer );
- layer_set_update_proc( s_outline_layer, outline_update_procedure );
- layer_set_update_proc( s_fill_layer, fill_update_procedure );
- for ( int i = 0; i < row_four_blocks; i++ ){
- watch.first_row[i] = GRect( i*outline_four_row_width + fill_four_row_offset, fill_first_row_y, fill_four_row_width, fill_four_row_height );
- watch.second_row[i] = GRect( i*outline_four_row_width + fill_four_row_offset, fill_second_row_y, fill_four_row_width, fill_four_row_height );
- watch.fourth_row[i] = GRect( i*outline_four_row_width + fill_four_row_offset, fill_fourth_row_y, fill_four_row_width, fill_four_row_height );
- }
- for ( int i = 0; i < row_eleven_blocks; i++ ){
- watch.third_row[i] = GRect( i*outline_eleven_row_width + fill_four_row_offset, fill_third_row_y, fill_eleven_row_width, fill_eleven_row_height );
- }
- }
- static void main_window_unload( Window *window ){
- layer_destroy( s_outline_layer );
- layer_destroy( s_fill_layer );
- }
- static void init(){
- s_main_window = window_create();
- window_set_background_color( s_main_window, GColorBlack );
- window_set_window_handlers( s_main_window, (WindowHandlers){
- .load = main_window_load,
- .unload = main_window_unload,
- } );
- window_stack_push( s_main_window, true );
- tick_timer_service_subscribe( SECOND_UNIT, tick_handler );
- }
- static void deinit(){
- window_destroy( s_main_window );
- }
- int main( void ){
- init();
- app_event_loop();
- deinit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement