static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { int hours = tick_time->tm_hour; int mins = tick_time->tm_min; if(hours < 10) { digit_set_value(s_digits[0], 0); } else { digit_set_value(s_digits[0], hours / 10); } digit_set_value(s_digits[1], hours % 10); if(mins < 10) { digit_set_value(s_digits[2], 0); } else { digit_set_value(s_digits[2], mins / 10); } digit_set_value(s_digits[3], mins % 10); // Smooth transition if(data_get_animations()) { pge_resume(); } else { // Instant transition while(digits_are_animating()) { pge_logic(); } pge_manual_advance(); } }
static void click(int button_id, bool long_click) { switch(button_id) { case BUTTON_ID_UP: s_input_mode = (s_input_mode + 1) % 4; break; case BUTTON_ID_SELECT: switch(s_block_choice) { case BLOCK_GRASS: block_set_color(s_block_array[vec2i(s_cursor)], COLOR_GRASS); break; case BLOCK_SAND: block_set_color(s_block_array[vec2i(s_cursor)], COLOR_SAND); break; case BLOCK_WATER: block_set_color(s_block_array[vec2i(s_cursor)], COLOR_WATER); break; case BLOCK_RED: block_set_color(s_block_array[vec2i(s_cursor)], COLOR_RED); break; case BLOCK_STONE: block_set_color(s_block_array[vec2i(s_cursor)], COLOR_STONE); break; case BLOCK_DELETE: block_set_color(s_block_array[vec2i(s_cursor)], COLOR_INVISIBLE); break; } break; case BUTTON_ID_DOWN: switch(s_input_mode) { case MODE_X: s_cursor.x = (s_cursor.x + 1) % GRID_WIDTH; break; case MODE_Y: s_cursor.y = (s_cursor.y + 1) % GRID_HEIGHT; break; case MODE_Z: s_cursor.z = (s_cursor.z + 1) % GRID_DEPTH; break; case MODE_BLOCK_CHOICE: s_block_choice = (s_block_choice + 1) % NUM_BLOCK_TYPES; break; } break; } update_status_text(); pge_manual_advance(); }
void pge_init() { s_initd = false; data_init(); const int buffer_size = 64; comm_init(buffer_size, buffer_size); s_digits[0] = digit_create(GPoint(-HOURS_OFFSET, 0), 0); s_digits[1] = digit_create(GPoint(-HOURS_OFFSET + (5 * SEGMENT_SIZE.w), 0), 0); s_digits[2] = digit_create(GPoint(MINS_OFFSET, 7 * SEGMENT_SIZE.h), 0); s_digits[3] = digit_create(GPoint(MINS_OFFSET + (5 * SEGMENT_SIZE.w), 7 * SEGMENT_SIZE.h), 0); pge_isometric_set_projection_offset(PROJECTION_OFFSET); pge_set_framerate(FRAME_RATE_HIGH); pge_begin(pge_logic, pge_render, NULL); tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); time_t temp = time(NULL); struct tm *t = localtime(&temp); tick_handler(t, MINUTE_UNIT); main_reload_config(); // Fast forward - save power when lots of notifications while(digits_are_animating()) { pge_logic(); } app_focus_service_subscribe(focus_handler); // If no animations if(!data_get_animations()) { pge_manual_advance(); // Don't animate after this pge_pause(); } }
static void fix_handler(void *context) { // Render new state pge_manual_advance(); }