Exemple #1
0
// Handles tick of the system clock.
static void handle_tick(struct tm *tick_time, TimeUnits units_changed) {
    if(units_changed & SECOND_UNIT) {

      // Update control block.
      control_block_tick();
    
      // Redraw the timer.
      draw_timer();
    
      // Update UI.
      if (control_block_is_program_over()){
          // Vibrate with different pattern at the end of the program.
          vibes_double_pulse();
    
          // And update the screen with a final message.
          layer_set_hidden((Layer *)tw_tl_time, true);
          layer_set_hidden((Layer *)tw_tl_interval, true);
    
          text_layer_set_text(tw_tl_type, "Done!");
          layer_mark_dirty((Layer *)tw_tl_type);
    
          return;
      } else if (control_block_is_interval_over()){
        vibes_long_pulse();
      }
    }  
}
Exemple #2
0
void on_time_changed(signed long total_seconds)
{
    int seconds = 0, minutes = 0, hours = 0, rest = 0;

    rest    = total_seconds;
    hours   = rest / 3600;
    rest    = rest - (hours * 3600);
    minutes = rest / 60;
    rest    = rest - (minutes * 60);
    seconds = rest;

    draw_timer(hours, minutes, seconds);
}
Exemple #3
0
// This callback will initialize the timer and starts the count down.
static void program_menu_callback(int index, void *ctx) {
  
  if (selected_program_menu -> program_menu == interval_menu){
    control_block_init(((selected_program_menu -> program_menu[index])).intervals, ((selected_program_menu -> program_menu[index])).title, ((selected_program_menu -> program_menu[index])).intervals_cnt, true);
  } else {
    control_block_init(((selected_program_menu -> program_menu[index])).intervals, ((selected_program_menu -> program_menu[index])).title, ((selected_program_menu -> program_menu[index])).intervals_cnt, false);
  }

  // Add the timer window to the stack.
  window_stack_push(timer_window, true);

  // Log the status of the control block.
  control_block_log_status();

  // Set up timer screen.  
  draw_timer();

  // Start ticking.
  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);
 
}
Exemple #4
0
static void
draw_score_and_ships(void)
{
	/* gc.score */
	glPushMatrix();
        glTranslatef(4, 23, 0.f);
	draw_score();

	/* gc.multiplier */
	if (gc.multiplier > 1) {
		glColor3f(1, .8, 0.f);
		glTranslatef(viewport_width/2 - 30, 0, 0);
		render_string(font_medium, 0, 0, 1.f, "x");
		glTranslatef(32, 2, 0);
		render_string(font_medium, 0, 0, 1.5f, "%d", gc.multiplier);
	}

	glPopMatrix();

	/* time */
	draw_timer();

	glPushMatrix();

	glColor3f(1, 1, 1);

	glTranslatef(8, 34, 0);

	if (gc.ships_left > 3) {
		/* ship icon */

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, gl_texture_id(ship_outline_texture_id));

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		draw_ship_icon();

		glDisable(GL_BLEND);
		glDisable(GL_TEXTURE_2D);

		/* # of ships left */

		glTranslatef(.8*29, .8*15, 0);
		render_string(font_medium, 0, 0, .9*.4, "x");

		glTranslatef(.8*17, .8*1.5, 0);
		render_string(font_medium, 0, 0, .8*.8, "%d", gc.ships_left);
	} else {
		int i;

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, gl_texture_id(ship_outline_texture_id));

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		for (i = 0; i < gc.ships_left; i++) {
			draw_ship_icon();
			glTranslatef(SHIP_ICON_SIZE, 0, 0);
		}

		glDisable(GL_BLEND);
		glDisable(GL_TEXTURE_2D);
	}

        glPopMatrix();
}
Exemple #5
0
int main()
{
#ifdef __MIPSEL__
    create_app_dir(BASE_PATH);
#endif

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        log(FATAL, "Cannot init SDL.");
    }

    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF)))
    {
        SDL_Quit();
        log(FATAL, "Cannot SetVideoMode.");
    }

    SDL_ShowCursor(SDL_DISABLE);

    if (TTF_Init() < 0)
    {
        SDL_Quit();
        log(FATAL, "Unable to start the TTF.");
    }

    int img_flags = IMG_INIT_PNG;

    if(!(IMG_Init(img_flags) & img_flags))
    {
        TTF_Quit();
        SDL_Quit();
        log(FATAL, "SDL_image could not initialize. %s.", IMG_GetError());
    }

    pconfig = new Config();
    pconfig->load();

    pmixer = new Mixer();
    current_volume = pmixer->get_speaker_volume();
    pmixer->set_speaker_volume(current_volume);

    load_resources();
    draw_buttons();
    draw_timer(0, 0, 0);
    draw_volume();
    draw_vu(1, -1);
    draw_vu(1, 1);

    pmic = new Mic();
    pmic->set_on_terminate_event(on_terminate_exec);
    pmic->set_on_vu_change_event(on_vu_changed);

    main_loop();

    delete pmic;
    delete pmixer;
    delete pconfig;

    TTF_CloseFont(font_10);
    TTF_CloseFont(font_28);

    IMG_Quit();
    TTF_Quit();
    SDL_Quit();

    return 0;
}