예제 #1
0
void destroy_chrono_objects() {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "destroy_chrono_objects");

  layer_destroy(chrono_dial_layer);
  bwd_destroy(&chrono_dial_white);
  bwd_destroy(&chrono_dial_black);

  if (chrono_digital_window != NULL) {
    window_destroy(chrono_digital_window);
    chrono_digital_window = NULL;
  }

#ifdef ENABLE_CHRONO_MINUTE_HAND
  layer_destroy(chrono_minute_layer);
#endif
#ifdef ENABLE_CHRONO_SECOND_HAND
  layer_destroy(chrono_second_layer);
#endif
#ifdef ENABLE_CHRONO_TENTH_HAND
  layer_destroy(chrono_tenth_layer);
#endif
  hand_cache_destroy(&chrono_minute_cache);
  hand_cache_destroy(&chrono_second_cache);
  hand_cache_destroy(&chrono_tenth_cache);
}
예제 #2
0
void destroy_chrono_objects() {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "destroy_chrono_objects");

  if (chrono_digital_window != NULL) {
    window_destroy(chrono_digital_window);
    chrono_digital_window = NULL;
  }

  hand_cache_destroy(&chrono_minute_cache);
  hand_cache_destroy(&chrono_second_cache);
  hand_cache_destroy(&chrono_tenth_cache);

  bwd_destroy(&chrono_dial_white);
}
예제 #3
0
// Destroys the objects created by create_objects().
void destroy_objects() {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "destroy_objects");
  window_stack_pop_all(false);
  layer_destroy(clock_face_layer);
  clock_face_layer = NULL;
  bwd_destroy(&clock_face);
  face_index = -1;

#ifdef MAKE_CHRONOGRAPH
  destroy_chrono_objects();
#endif  // MAKE_CHRONOGRAPH

  deinit_battery_gauge();
  deinit_bluetooth_indicator();

  for (int i = 0; i < NUM_DATE_WINDOWS; ++i) {
    layer_destroy(date_window_layers[i]);
    date_window_layers[i] = NULL;
  }

  bwd_destroy(&date_window);
  bwd_destroy(&date_window_mask);

#ifdef SUPPORT_MOON
  bwd_destroy(&moon_bitmap);
#endif  // SUPPORT_MOON
  
  layer_destroy(minute_layer);
  layer_destroy(hour_layer);
  layer_destroy(second_layer);

  hand_cache_destroy(&hour_cache);
  hand_cache_destroy(&minute_cache);
  hand_cache_destroy(&second_cache);

  if (date_lang_font != NULL) {
    safe_unload_custom_font(&date_lang_font);
  }
  display_lang = -1;

  window_destroy(window);
  window = NULL;
}
예제 #4
0
// Draws a given hand on the face, using the bitmap structures.
void draw_bitmap_hand(struct HandCache *hand_cache, struct HandDef *hand_def, int hand_index, GContext *ctx) {
  if (hand_cache->bitmap_hand_index != hand_index) {
    // Force a new bitmap.
    if (hand_cache->image.bitmap != NULL) {
      bwd_destroy(&hand_cache->image);
    }
    if (hand_cache->mask.bitmap != NULL) {
      bwd_destroy(&hand_cache->mask);
    }
    hand_cache->bitmap_hand_index = hand_index;
  }

  struct BitmapHandTableRow *hand = &hand_def->bitmap_table[hand_index];
  int bitmap_index = hand->bitmap_index;
  struct BitmapHandCenterRow *lookup = &hand_def->bitmap_centers[bitmap_index];

  int hand_resource_id = hand_def->resource_id + bitmap_index;
  int hand_resource_mask_id = hand_def->resource_mask_id + bitmap_index;
 
  if (hand_def->resource_id == hand_def->resource_mask_id) {
    // The hand does not have a mask.  Draw the hand on top of the scene.
    if (hand_cache->image.bitmap == NULL) {
      if (hand_def->use_rle) {
	hand_cache->image = rle_bwd_create(hand_resource_id);
      } else {
	hand_cache->image = png_bwd_create(hand_resource_id);
      }
      if (hand_cache->image.bitmap == NULL) {
        hand_cache_destroy(hand_cache);
	trigger_memory_panic(__LINE__);
        return;
      }
      hand_cache->cx = lookup->cx;
      hand_cache->cy = lookup->cy;
    
      if (hand->flip_x) {
        // To minimize wasteful resource usage, if the hand is symmetric
        // we can store only the bitmaps for the right half of the clock
        // face, and flip them for the left half.
        flip_bitmap_x(hand_cache->image.bitmap, &hand_cache->cx);
      }
    
      if (hand->flip_y) {
        // We can also do this vertically.
        flip_bitmap_y(hand_cache->image.bitmap, &hand_cache->cy);
      }
    }
      
    // We make sure the dimensions of the GRect to draw into
    // are equal to the size of the bitmap--otherwise the image
    // will automatically tile.
    GRect destination = hand_cache->image.bitmap->bounds;
    
    // Place the hand's center point at place_x, place_y.
    destination.origin.x = hand_def->place_x - hand_cache->cx;
    destination.origin.y = hand_def->place_y - hand_cache->cy;
    
    // Specify a compositing mode to make the hands overlay on top of
    // each other, instead of the background parts of the bitmaps
    // blocking each other.

    if (hand_def->paint_black) {
      // Painting foreground ("white") pixels as black.
      graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_black);
    } else {
      // Painting foreground ("white") pixels as white.
      graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_white);
    }
      
    graphics_draw_bitmap_in_rect(ctx, hand_cache->image.bitmap, destination);
    
  } else {
    // The hand has a mask, so use it to draw the hand opaquely.
    if (hand_cache->image.bitmap == NULL) {
      if (hand_def->use_rle) {
	hand_cache->image = rle_bwd_create(hand_resource_id);
	hand_cache->mask = rle_bwd_create(hand_resource_mask_id);
      } else {
	hand_cache->image = png_bwd_create(hand_resource_id);
	hand_cache->mask = png_bwd_create(hand_resource_mask_id);
      }
      if (hand_cache->image.bitmap == NULL || hand_cache->mask.bitmap == NULL) {
        hand_cache_destroy(hand_cache);
	trigger_memory_panic(__LINE__);
        return;
      }
      hand_cache->cx = lookup->cx;
      hand_cache->cy = lookup->cy;
    
      if (hand->flip_x) {
        // To minimize wasteful resource usage, if the hand is symmetric
        // we can store only the bitmaps for the right half of the clock
        // face, and flip them for the left half.
        flip_bitmap_x(hand_cache->image.bitmap, &hand_cache->cx);
        flip_bitmap_x(hand_cache->mask.bitmap, NULL);
      }
    
      if (hand->flip_y) {
        // We can also do this vertically.
        flip_bitmap_y(hand_cache->image.bitmap, &hand_cache->cy);
        flip_bitmap_y(hand_cache->mask.bitmap, NULL);
      }
    }
    
    GRect destination = hand_cache->image.bitmap->bounds;
    
    destination.origin.x = hand_def->place_x - hand_cache->cx;
    destination.origin.y = hand_def->place_y - hand_cache->cy;

    graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_white);
    graphics_draw_bitmap_in_rect(ctx, hand_cache->mask.bitmap, destination);
    
    graphics_context_set_compositing_mode(ctx, draw_mode_table[config.draw_mode].paint_black);
    graphics_draw_bitmap_in_rect(ctx, hand_cache->image.bitmap, destination);
  }
}