Beispiel #1
0
static void main_window_load(Window *window) {
	//get root layer of window
	Layer *window_layer = window_get_root_layer(window);

	//get window dimensions
	GRect bounds = layer_get_bounds(window_layer);

	//add drawing layers
	s_clock_layer_outer = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_outer, draw_clock_layer_outer);
	layer_add_child(window_layer, s_clock_layer_outer);

	s_clock_layer_center = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_center, draw_clock_layer_center);
	layer_add_child(window_layer, s_clock_layer_center);

	s_clock_layer_inner = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_inner, draw_clock_layer_inner);
	layer_add_child(window_layer, s_clock_layer_inner);

	//init text time layer
	GSize max_size = graphics_text_layout_get_content_size(
		"00:00",
		fonts_get_system_font(FONT_KEY_GOTHIC_14),
		GRect(0, 0, bounds.size.w, bounds.size.h),
		GTextOverflowModeTrailingEllipsis,
		GTextAlignmentCenter
	);
	s_text_time = text_layer_create(GRect(
		(bounds.size.w / 2) - (max_size.w / 2),
		(bounds.size.h / 2) - (max_size.h / 2),
		max_size.w,
		max_size.h)
	);
	text_layer_set_background_color(s_text_time, GColorClear);
	text_layer_set_text_color(s_text_time, GColorBlack);
	text_layer_set_font(s_text_time, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_alignment(s_text_time, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(s_text_time));
	toggle_text_time();

	//init inverter layer
	s_layer_invert = inverter_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h));
	layer_add_child(window_layer, inverter_layer_get_layer(s_layer_invert));
	invert_face();

	//store clock layer bounds
	s_clock_bounds = layer_get_bounds(s_clock_layer_outer);
	s_clock_center = grect_center_point(&s_clock_bounds);

	//init hand paths
	s_hand_path_outer = gpath_create(&OUTER_HAND_POINTS);
	gpath_move_to(s_hand_path_outer, s_clock_center);

	s_hand_path_center = gpath_create(&CENTER_HAND_POINTS);
	gpath_move_to(s_hand_path_center, s_clock_center);

	s_hand_path_inner = gpath_create(&INNER_HAND_POINTS);
	gpath_move_to(s_hand_path_inner, s_clock_center);
}
// Draw the lizard by calling from the layer redraw proc
void draw_lizard(GContext* ctx) {
  GPath *lizard_path = gpath_create(&lizard_points);
  GPath *bug_path = gpath_create(&bug_points);

  //gpath_rotate_to(lizard_path, TRIG_MAX_ANGLE / 360 * 20);
  gpath_move_to(lizard_path, GPoint(10, 0));
    
  graphics_context_set_fill_color(ctx, GColorGreen);
  gpath_draw_filled(ctx, lizard_path);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  gpath_draw_outline(ctx, lizard_path);
  graphics_context_set_fill_color(ctx, GColorBlack);
  gpath_draw_filled(ctx, bug_path);
    
  GPoint center = {
      .x = 41,
      .y = 59
  };
  graphics_fill_circle(ctx, center, 3);
  graphics_draw_circle(ctx, center, 8);
  graphics_draw_line(ctx, GPoint(6, 73), GPoint(16, 72));
    
  graphics_context_set_text_color(ctx, GColorRed);
  graphics_draw_text(ctx,
	    		"Lizzy",
	    		fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
	    		GRect(0,120,144,140),
	    		GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    
}

// Only need to draw the lizard
static void drawing_layer_update_callback(Layer *me, GContext *ctx) { 
    draw_lizard(ctx);
}
static void init(void) {

  window = window_create();
  window_set_background_color(window, GColorBlack);
  window_stack_push(window, true);

  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  // Init the layer for the minute display
  minute_display_layer = layer_create(bounds);
  layer_set_update_proc(minute_display_layer, minute_display_layer_update_callback);
  layer_add_child(window_layer, minute_display_layer);


  // Init the minute segment path
  minute_segment_path = gpath_create(&MINUTE_SEGMENT_PATH_POINTS);
  gpath_move_to(minute_segment_path, grect_center_point(&bounds));


  // Init the layer for the hour display
  hour_display_layer = layer_create(bounds);
  layer_set_update_proc(hour_display_layer, hour_display_layer_update_callback);
  layer_add_child(window_layer, hour_display_layer);


  // Init the hour segment path
  hour_segment_path = gpath_create(&HOUR_SEGMENT_PATH_POINTS);
  gpath_move_to(hour_segment_path, grect_center_point(&bounds));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
}
Beispiel #4
0
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);
  
  fontRobotoCondensed19  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_19));
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  triangle_overlay_layer = layer_create(bounds);
	layer_set_update_proc(triangle_overlay_layer, triangle_display_layer_update_callback);
	layer_add_child(window_layer, triangle_overlay_layer);
	triangle_overlay_path = gpath_create(&TRIANGLE_OVERLAY_POINTS);
	gpath_move_to(triangle_overlay_path, grect_center_point(&bounds));
  
  // init hand paths
  minute_arrow_path = gpath_create(&MINUTE_HAND_POINTS);
  gpath_move_to(minute_arrow_path, grect_center_point(&bounds));
  
  hour_arrow_path = gpath_create(&HOUR_HAND_POINTS);
  gpath_move_to(hour_arrow_path, grect_center_point(&bounds));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  

  s_hands_layer = layer_create(bounds);

  layer_set_update_proc(s_hands_layer, hands_update_proc);
  layer_add_child(window_layer, s_hands_layer);
  
  // Battery Line Basalt
   #ifdef PBL_PLATFORM_BASALT
      GRect line_frame = GRect(22, 160, 104, 6);
      LineLayer = layer_create(line_frame);
      layer_set_update_proc(LineLayer, line_layer_update_callback);
      layer_add_child(window_layer, LineLayer);
   #else //Chalk
      GRect line_round_frame = GRect(1, 1, 180, 180);
      RoundBatteryLayer = layer_create(line_round_frame);
      layer_set_update_proc(RoundBatteryLayer, RoundBatteryLayer_update_callback);
      layer_add_child(window_layer,RoundBatteryLayer);
   #endif
     
  //Service subscribes:
  battery_state_service_subscribe(&handle_battery);
  
  handle_battery(battery_state_service_peek());
  
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
     
  app_focus_service_subscribe(&handle_appfocus);

}
Beispiel #5
0
/* Window handler */
static void main_window_load(Window *window) {
   // Get information about the Window
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  GPoint center = grect_center_point(&bounds);

  // init hand paths
  s_minute_arrow = gpath_create(&MINUTE_HAND_POINTS);
  s_hour_arrow = gpath_create(&HOUR_HAND_POINTS);
  gpath_move_to(s_minute_arrow, center);
  gpath_move_to(s_hour_arrow, center);


  // background all black
  s_bg_layer = layer_create(bounds);
  layer_set_update_proc(s_bg_layer, bg_update_proc);  
  layer_add_child(window_layer, s_bg_layer);
  
  s_draw_layer = layer_create(bounds);
  layer_set_update_proc(s_draw_layer, hands_update_proc);  
  
  s_time_layer = text_layer_create(PBL_IF_ROUND_ELSE(
    GRect(63, center.y / 2 - 15, 56, 20),
    GRect(46, center.y / 2 - 15, 56, 20)));  
  
  text_layer_set_background_color(s_time_layer, GColorBlack);
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  

  
  layer_add_child(window_layer, s_draw_layer);
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
  // register timetick handler
  tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
  //s_app_timer = app_timer_register(TIMER_INTERVALL,app_timer_handler,window);

  Layer *batteryLayer = init_battery_watcher(GRect(PBL_IF_ROUND_ELSE(30,1), PBL_IF_ROUND_ELSE(19,5), 35, 20));
  if (batteryLayer != NULL) {
    layer_add_child(window_layer, batteryLayer);
  }


  Layer *btLayer = init_bluetooth_layer(GRect(120, 5, 24,24));
  if (btLayer != NULL) {
    layer_add_child(window_layer, btLayer);  
  }
  

}
Beispiel #6
0
Datei: moo10.c Projekt: an-ox/bbc
static void shape(GContext *ctx,uint16_t ang,int16_t ox,int16_t oy,int16_t mx,int16_t my,GPathInfo *gp,int func)
{
  // draw 'shape' rotated to 'ang' and translated by 'ox' and 'oy'
  // use this instead of the library functions as they have shit precision
  
  GPoint *oldpoints=gp->points;
  gp->points=malloc(sizeof(GPoint)*gp->num_points);
  for(uint16_t i=0;i<gp->num_points;i++)
  {
    gp->points[i].x=((oldpoints[i].x*mx)>>FRACBITS)+ox;
    gp->points[i].y=((oldpoints[i].y*my)>>FRACBITS)+oy;
    rotate(ang,&gp->points[i]);
    gp->points[i].x=(gp->points[i].x>>FRACBITS)+CENTREX;
    gp->points[i].y=(gp->points[i].y>>FRACBITS)+CENTREY;
  }
  GPath *pptr=gpath_create(gp);
  switch(func)
  {
  case 0:  // std filled in  
    gpath_draw_outline(ctx,pptr);
    gpath_draw_filled(ctx,pptr);
  break;
  case 1: // open line draw
#ifdef PBL_COLOR
    gpath_draw_outline_open(ctx,pptr);
#else
    gpath_draw_outline(ctx,pptr);
#endif
  break;
  }
  gpath_destroy(pptr);
  free(gp->points);
  gp->points=oldpoints;
}
Beispiel #7
0
void paths_create() {
    for (int i = 0; i < NUM_WEDGES; i++) {
        if (s_paths[i]) {
            gpath_destroy(s_paths[i]);
        }

        GPathInfo path_info = (GPathInfo) {
            .num_points = 3,
             .points = s_points[i]
        };
        s_paths[i] = gpath_create(&path_info);
        gpath_move_to(s_paths[i], s_center);
    }
}

void paths_destroy() {
    for (int i = 0; i < NUM_WEDGES; i++) {
        gpath_destroy(s_paths[i]);
    }
}

Layer* forecast_create(GRect window_bounds) {
    s_center = grect_center_point(&window_bounds);
    init_points();
    paths_create();
    s_canvas_layer = layer_create(window_bounds);
    //layer_add_child(s_canvas_layer, textlayer_create());
    layer_set_update_proc(s_canvas_layer, draw_forecast);

    static Layer* icons_layer;
    icons_layer = forecast_icons_create(window_bounds);
    layer_add_child(s_canvas_layer, icons_layer);

    return s_canvas_layer;
}
Beispiel #8
0
// Draw the gray cover over part of the progress ring
static void prv_draw_progress_ring(GContext *ctx, GSize window_size, uint32_t angle) {
  graphics_context_set_fill_color(ctx, COLOR_BACKGROUND);
  // get step angle and exit if too small
  int32_t step = angle / 4;
  if (step < 1) {
    return;
  }
  // get properties
  GPoint center = GPoint(window_size.w / 2, window_size.h / 2);
  uint16_t radius = window_size.h + window_size.w / 2;
  // calculate points around outside of window to draw cover
  GPoint points[8];
  int8_t idx = 0;
  for (uint32_t t_angle = 0; t_angle < angle; t_angle += step){
    points[idx++] = prv_polar_to_rectangular(center, t_angle, radius);
  }
  // add point at hand position, and in center (to form pie wedge)
  points[idx++] = prv_polar_to_rectangular(center, angle, radius);
  points[idx++] = center;

  // fill the covering
  GPathInfo info = (GPathInfo) {
    .num_points = idx,
    .points = points
  };
  GPath *path = gpath_create(&info);
  gpath_draw_filled(ctx, path);
  gpath_destroy(path);
}
Layer * create_direction_layer(GRect bounds) {
  Layer *layer = layer_create_with_data(GRect(0, 20, bounds.size.w, 30), sizeof(Arrow));
  layer_set_update_proc(layer, redraw_direction_arrow);
  arrow_path = gpath_create(&ARROW_PATH_INFO);
  GRect layer_bounds = layer_get_bounds(layer);
  gpath_move_to(arrow_path, grect_center_point(&layer_bounds));
  return layer;
}
Beispiel #10
0
Layer* battery_init() {
  s_battery_layer = layer_create(GRect(5, 5, 20, 20));
  layer_set_update_proc(s_battery_layer, draw_battery);

  s_battery_path = gpath_create(&BATTERY_PATH_INFO);

  return s_battery_layer;
}
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);

	s_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
	layer_add_child(window_get_root_layer(window), s_layer);
	layer_set_update_proc(s_layer, draw_watchface);

	s_time_layer = text_layer_create(GRect(0, 0, 24, 24));
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
	text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

	if (persist_read_int(KEY_BACKGROUND_COLOR)) {
		background_color = GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR));
		window_set_background_color(window, GColorFromHEX(persist_read_int(KEY_BACKGROUND_COLOR)));
	} else {
		background_color = GColorWhite;
	}

	setup_blocks();

	if (persist_read_int(KEY_DEGREEOPTION)) {
		degreeOption = persist_read_int(KEY_DEGREEOPTION);
	} else {
		degreeOption = 0;
	}

	s_weather_layer = text_layer_create(GRect(0,152, 144, 14));
	text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_background_color(s_weather_layer, GColorClear);
	text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
	text_layer_set_text_alignment(s_weather_layer, GTextAlignmentRight);
	text_layer_set_text(s_weather_layer, "Loading...");
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));

	s_bluetooth_icon_layer = layer_create(GRect(0,0,30,30));
	layer_set_update_proc(s_bluetooth_icon_layer, bluetooth_update_proc);
	bluetooth_path = gpath_create(&BLUETOOTH_INFO);
	layer_add_child(window_get_root_layer(window), s_bluetooth_icon_layer);

	//show the correct state of the bluetooth connection from the start
#ifdef PBL_SDK_2
	bluetooth_callback(bluetooth_connection_service_peek());
#elif PBL_SDK_3
	bluetooth_callback(connection_service_peek_pebble_app_connection());
#endif

	s_date_layer = text_layer_create(GRect(0,0,144,14));
	text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_color(s_date_layer, gcolor_legible_over(background_color));
	text_layer_set_background_color(s_date_layer, GColorClear);
	text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));

}
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  s_minute_display_layer = layer_create(bounds);
  layer_set_update_proc(s_minute_display_layer, minute_display_update_proc);
  layer_add_child(window_layer, s_minute_display_layer);

  s_minute_segment_path = gpath_create(&MINUTE_SEGMENT_PATH_POINTS);
  gpath_move_to(s_minute_segment_path, grect_center_point(&bounds));

  s_hour_display_layer = layer_create(bounds);
  layer_set_update_proc(s_hour_display_layer, hour_display_update_proc);
  layer_add_child(window_layer, s_hour_display_layer);

  s_hour_segment_path = gpath_create(&HOUR_SEGMENT_PATH_POINTS);
  gpath_move_to(s_hour_segment_path, grect_center_point(&bounds));
}
Beispiel #13
0
Layer* bluetooth_init() {
  s_bt_layer = layer_create(GRect(25, 4, 20, 20));
  layer_set_update_proc(s_bt_layer, draw_bt);

  s_bt_path = gpath_create(&BT_PATH_INFO);

  bluetooth_connection_service_subscribe(on_bluetooth);
  return s_bt_layer;
}
Beispiel #14
0
ClockLayer* clock_layer_create(const GRect frame) {
    ClockLayer *clock_layer = layer_create(frame);
    layer_set_update_proc(clock_layer,clock_layer_update);

    //Create coordinate paths
    s_large_ticks = gpath_create(&LARGE_TICKS);
    s_small_ticks = gpath_create(&SMALL_TICKS);

    s_hour_hand = gpath_create(&HOUR_HAND);
    s_minute_hand = gpath_create(&MINUTE_HAND);

    // Center the coordinate paths
    GPoint center = grect_center_point(&frame);
    gpath_move_to(s_large_ticks, center);
    gpath_move_to(s_small_ticks, center);
    gpath_move_to(s_hour_hand, center);
    gpath_move_to(s_minute_hand, center);

    return clock_layer;
}
static void draw_shape(GContext* ctx, int shape, int32_t angle, bool hour) {
  if (shape < 3) {
    graphics_draw_circle(ctx, center_point, hour ? HOUR_RADIUS : MINUTE_RADIUS);
  } else {
    GPathInfo* path_info = (hour ? HOUR_SHAPES : MINUTE_SHAPES) + shape - 3;
    GPath* path = gpath_create(path_info);
    gpath_rotate_to(path, angle);
    gpath_move_to(path, center_point);
    gpath_draw_outline(ctx, path);
  }
}
static void init() {
  // Pass the corresponding GPathInfo to initialize a GPath
  s_house_path = gpath_create(&HOUSE_PATH_POINTS);
  s_infinity_path = gpath_create(&INFINITY_RECT_PATH_POINTS);

  // This demo allows you to cycle paths in an array
  // Try adding more GPaths to cycle through
  // You'll need to define another GPathInfo
  // Remember to update NUM_PATHS accordingly
  s_path_array[0] = s_house_path;
  s_path_array[1] = s_infinity_path;

  s_current_path = s_path_array[0];

  // Create Window
  s_main_window = window_create();
  window_set_background_color(s_main_window, GColorBlack);
  window_set_click_config_provider(s_main_window, config_provider);
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload,
  });
void analog_init(Window* window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  const GPoint center = grect_center_point(&bounds);

  analog_layer = layer_create(bounds);
  layer_set_update_proc(analog_layer, analog_update_proc);
  layer_add_child(window_layer, analog_layer);

  minute_arrow = gpath_create(&MINUTE_HAND_POINTS);
  minute_fill = gpath_create(&MINUTE_FILL_POINTS);
  hour_arrow = gpath_create(&HOUR_HAND_POINTS);
  hour_fill = gpath_create(&HOUR_FILL_POINTS);
  peg_fill = gpath_create(&PEG_POINTS);

  gpath_move_to(minute_arrow, center);
  gpath_move_to(minute_fill, center);
  gpath_move_to(hour_arrow, center);
  gpath_move_to(hour_fill, center);
  gpath_move_to(peg_fill, center);

  tick_init(window);
}
Beispiel #18
0
static void main_window_load(Window *window)
{	
	Layer *window_layer = window_get_root_layer(window);
	//arrow
	/*directionArrow = gbitmap_create_with_resource(RESOURCE_ID_COMPASS_BACKGROUND;
	arrow = bitmap_layer_create(GRect(0,0,144,138));
	bitmap_layer_set_bitmap(arrow,directionArrow);
	layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(arrow));
	*/
	GRect bounds = layer_get_frame(window_layer);
	s_bitmap_layer = bitmap_layer_create(bounds);
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_COMPASS_BACKGROUND);
  bitmap_layer_set_bitmap(s_bitmap_layer, s_background_bitmap);
	bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpAnd);
  layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer));
	

	
	// Create the layer in which we will draw the compass needles
  s_path_layer = layer_create(bounds);
  
  //  Define the draw callback to use for this layer
  layer_set_update_proc(s_path_layer, path_layer_update_callback);
  layer_add_child(window_layer, s_path_layer);
	
	s_needle_north = gpath_create(&NEEDLE_NORTH_POINTS);
	GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);
  gpath_move_to(s_needle_north, center);
	
  
	
	//distance
	
	distance = text_layer_create(GRect(0, 0, 144, 30));
	//text_layer_set_text(distance, "Distance is x m");
	static char s_heading_buf[16];
  snprintf(s_heading_buf, sizeof(s_heading_buf),
  "%i",(int)bering);
	text_layer_set_text(distance, s_heading_buf);
	text_layer_set_text_alignment(distance, GTextAlignmentCenter);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(distance));
	
	//est time
	timeTo = text_layer_create(GRect(0, 144, 144, 30));
	text_layer_set_text(timeTo, "It will take x min");
	text_layer_set_text_alignment(timeTo, GTextAlignmentCenter);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(timeTo));
	

}
Beispiel #19
0
static void draw_title_pane(Layer *layer, GContext *ctx) {
  graphics_context_set_fill_color(ctx, GColorBlack);
  GPoint selector[3];
  int xOff = 20; // kamotswolf - Needed for better arrow alignment
  int yOff = load_choice * 20;
  if(load_choice == 1) xOff = 24;
  if(load_choice == 2) xOff = 0;
  selector[0] = GPoint(xOff + 6, 61 + yOff);
  selector[1] = GPoint(xOff + 6, 69 + yOff);
  selector[2] = GPoint(xOff + 16, 65 + yOff);
  GPathInfo selector_path_info = { 3, selector };
  selector_path = gpath_create(&selector_path_info);
  gpath_draw_filled(ctx, selector_path);
}
Beispiel #20
0
void init_graph(Window *window) {
  // Create Graph Layer
  s_graph_layer = layer_create(GRect(2, 60, BOX_WIDTH, BOX_HEIGHT));
  layer_add_child(window_get_root_layer(window), s_graph_layer);
  layer_set_hidden(s_graph_layer, true);
  
  // Create Status Layer
  s_status_layer = layer_create(GRect(-120, 120, 120, 47));
  layer_add_child(window_get_root_layer(window), s_status_layer);
  snprintf(statusbuffer, 30, "Totalt: 0\nUser: 0"); 
  
  s_graph_path_ptr = gpath_create(&GRAPH_PATH_INFO);
  
  layer_set_update_proc(s_graph_layer, graph_layer_update_callback);
  layer_set_update_proc(s_status_layer, status_layer_update_callback);
}
Beispiel #21
0
// Draws a given hand on the face, using the vector structures.
void draw_vector_hand(struct HandCache *hand_cache, struct HandDef *hand_def, int hand_index, GContext *ctx) {
  struct VectorHand *vector_hand = hand_def->vector_hand;

  int gi;
  if (hand_cache->vector_hand_index != hand_index) {
    // Force a new path.
    for (gi = 0; gi < vector_hand->num_groups; ++gi) {
      if (hand_cache->path[gi] != NULL) {
        gpath_destroy(hand_cache->path[gi]);
        hand_cache->path[gi] = NULL;
      }
    }
    hand_cache->vector_hand_index = hand_index;
  }

  GPoint center = { hand_def->place_x, hand_def->place_y };
  int32_t angle = TRIG_MAX_ANGLE * hand_index / hand_def->num_steps;

  assert(vector_hand->num_groups <= HAND_CACHE_MAX_GROUPS);
  for (gi = 0; gi < vector_hand->num_groups; ++gi) {
    struct VectorHandGroup *group = &vector_hand->group[gi];

    if (hand_cache->path[gi] == NULL) {
      hand_cache->path[gi] = gpath_create(&group->path_info);
      if (hand_cache->path[gi] == NULL) {
	trigger_memory_panic(__LINE__);
	return;
      }

      gpath_rotate_to(hand_cache->path[gi], angle);
      gpath_move_to(hand_cache->path[gi], center);
    }

    if (group->fill != 0) {
      graphics_context_set_fill_color(ctx, draw_mode_table[config.draw_mode].colors[group->fill]);
      gpath_draw_filled(ctx, hand_cache->path[gi]);
    }
    if (group->outline != 0) {
      graphics_context_set_stroke_color(ctx, draw_mode_table[config.draw_mode].colors[group->outline]);
      gpath_draw_outline(ctx, hand_cache->path[gi]);
    }
  }
}
Beispiel #22
0
static void main_window_load(Window *window) {
	// Create ring layer
	Layer *window_layer = window_get_root_layer(s_window_main);
	GRect bounds = layer_get_bounds(window_layer);
	
	layer_ring = layer_create(bounds);
	layer_set_update_proc(layer_ring, layer_ring_update_callback);
	layer_add_child(window_layer, layer_ring);
	
	s_path_ring_segment = gpath_create(&PATH_POINTS_RING);
	gpath_move_to(s_path_ring_segment, grect_center_point(&bounds));

	// Create inner background
	layer_bg_in = layer_create(bounds);
	layer_set_update_proc(layer_bg_in, layer_bg_in_update_callback);
	layer_add_child(window_layer, layer_bg_in);
	
	// Create TextLayers
	s_layer_day = text_layer_create(GRect(0, 41, 144, 20));
	text_layer_set_background_color(s_layer_day, GColorClear);
	text_layer_set_font(s_layer_day, s_font_date);
	text_layer_set_text_color(s_layer_day, s_color_text);
	text_layer_set_text(s_layer_day, "");
	text_layer_set_text_alignment(s_layer_day, GTextAlignmentCenter);
	layer_add_child(layer_bg_in, text_layer_get_layer(s_layer_day));
	
	s_layer_time = text_layer_create(GRect(0, 59, 144, 50));
	text_layer_set_background_color(s_layer_time, GColorClear);
	text_layer_set_font(s_layer_time, s_font_time);
	text_layer_set_text_color(s_layer_time, s_color_text);
	text_layer_set_text(s_layer_time, "");
	text_layer_set_text_alignment(s_layer_time, GTextAlignmentCenter);
	layer_add_child(layer_bg_in, text_layer_get_layer(s_layer_time));
	
	s_layer_date = text_layer_create(GRect(0, 107, 144, 20));
	text_layer_set_background_color(s_layer_date, GColorClear);
	text_layer_set_font(s_layer_date, s_font_date);
	text_layer_set_text_color(s_layer_date, s_color_text);
	text_layer_set_text(s_layer_date, "");
	text_layer_set_text_alignment(s_layer_date, GTextAlignmentCenter);
	layer_add_child(layer_bg_in, text_layer_get_layer(s_layer_date));
}
Beispiel #23
0
static void window_load() {
    // APP_LOG(APP_LOG_LEVEL_DEBUG, "inside window_load()");
    settings_load(window);
    // screen size 144 x 168
    watchface_load(window);

    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);

    s_windshield_path = gpath_create(&WINDSHIELD_PATH_INFO);

    s_top_layer = layer_create(GRect(0, 0, bounds.size.w, 130));
    layer_set_update_proc(s_top_layer, windshield_proc);
    layer_add_child(window_layer,s_top_layer);

    s_grill_layer = layer_create(GRect(0, 57, bounds.size.w, 60));
    layer_set_update_proc(s_grill_layer, grill_proc);
    layer_add_child(window_layer,s_grill_layer);

    indicators_load(window);
}
Beispiel #24
0
void declare_drawing_layer(Window *window)
{
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);
    // Create GPath object
    s_task_color_path = gpath_create(&s_task_color_path_info);
    
    // Create Layer that the path will be drawn on
    s_task_color_layer = layer_create(bounds);
    s_weather_icon_layer = layer_create(bounds);
    s_calendar_background_layer = layer_create(bounds);
    
    taskColour = GColorRed;
    layer_set_update_proc(s_task_color_layer, task_background_color);
    layer_add_child(window_layer, s_task_color_layer);
    layer_add_child(window_layer, s_weather_icon_layer);
    layer_add_child(window_layer, s_calendar_background_layer);
    
    layer_set_update_proc(s_weather_icon_layer, set_weather_icon);
    layer_set_update_proc(s_calendar_background_layer, render_calendar_background);
}
Beispiel #25
0
void  twilight_path_render(TwilightPath *pTwilightPath, GContext *ctx,
                           GColor color, GRect frameDst)
{


   if ((pTwilightPath->fDawnTime == NO_RISE_SET_TIME) ||
       (pTwilightPath->fDuskTime == NO_RISE_SET_TIME))
   {
      //  sun either never sets or never rises at this location / time.
      //  For now, simply render nothing.
      return;
   }

   //  Recreate path each time.  Not sure if this is strictly necessary
   //  but it would probably not be good to apply gpath_move_to() more
   //  than once for the same path instance.
   if (pTwilightPath->pPath != NULL)
      gpath_destroy(pTwilightPath->pPath);

   pTwilightPath->pPath = gpath_create(&(pTwilightPath->pathInfo));
   if (pTwilightPath->pPath == NULL)
      return;
   gpath_move_to(pTwilightPath->pPath, grect_center_point(&frameDst));

   //  do rendering

   if (pTwilightPath->pBmpGrey != NULL)
   {
      graphics_context_set_compositing_mode(ctx, GCompOpAnd); 
      graphics_draw_bitmap_in_rect(ctx, pTwilightPath->pBmpGrey, frameDst);
   }

   graphics_context_set_fill_color(ctx, color);
   if ((pTwilightPath != NULL) && (pTwilightPath->pPath != NULL))
   {
      gpath_draw_filled(ctx, pTwilightPath->pPath); 
   }

}  /* end of twilight_path_render */
Beispiel #26
0
static void display_layer_update(Layer *layer, GContext *ctx) {
    time_t temp = time(NULL);
    struct tm *tick_time = localtime(&temp);

    // Second
    angle = TRIG_MAX_ANGLE * (tick_time->tm_sec / 60.0);
    path_info.points[0].x = centre.x + (sin_lookup(angle) * radius / TRIG_MAX_RATIO);
    path_info.points[0].y = centre.y - (cos_lookup(angle) * radius / TRIG_MAX_RATIO);
    
    // Minute
    angle = TRIG_MAX_ANGLE * (((tick_time->tm_min * 60) + tick_time->tm_sec) / 3600.0);
    path_info.points[1].x = centre.x + (sin_lookup(angle) * radius / TRIG_MAX_RATIO);
    path_info.points[1].y = centre.y - (cos_lookup(angle) * radius / TRIG_MAX_RATIO);

    // Hour
    angle = TRIG_MAX_ANGLE * ((((tick_time->tm_hour % 12) * 60) + tick_time->tm_min)  / 720.0);
    path_info.points[2].x = centre.x + (sin_lookup(angle) * radius / TRIG_MAX_RATIO);
    path_info.points[2].y = centre.y - (cos_lookup(angle) * radius / TRIG_MAX_RATIO);

    // Do some drawing
    graphics_context_set_stroke_color(ctx, GColorBlack);
    graphics_context_set_fill_color(ctx, GColorBlack);

    // Draw the poly
    path = gpath_create(&path_info);
    if(tick_time->tm_sec == tick_time->tm_min || tick_time->tm_sec == tick_time->tm_hour * 5) {
        // Make it easier to see
        gpath_draw_outline(ctx, path);
    } else {
        gpath_draw_filled(ctx, path);
    }
    gpath_destroy(path);

    // Draw some dots
    graphics_fill_circle(ctx, path_info.points[0], 1);
    graphics_fill_circle(ctx, path_info.points[1], 2);
    graphics_fill_circle(ctx, path_info.points[2], 3);
}
Beispiel #27
0
static void prv_draw_major_hands(GContext *ctx, const GPoint *center, int32_t hand_length,
                                 int32_t angle, GColor color) {
  GPoint points[] = {
    {-3, 0},
    {3, 0},
    {6, (int16_t)-(hand_length - 8)},
    {0, (int16_t)-hand_length},
    {-6, (int16_t)-(hand_length - 8)},
  };

  const GPathInfo path_info = (GPathInfo) {
    .num_points = ARRAY_LENGTH(points),
    .points = points,
  };

  GPath *path = gpath_create(&path_info);
  gpath_move_to(path, *center);
  gpath_rotate_to(path, angle);
  graphics_context_set_fill_color(ctx, color);
  gpath_draw_filled(ctx, path);

  gpath_destroy(path);
}
void screen_map_layer_init(Window* window) {

    for (int i = 0; i < NUM_POINTS; i++) {
        pts[i] = GPoint(0, 0);
    }

    s_data.page_map = layer_create(GRect(0,TOPBAR_HEIGHT,SCREEN_W,SCREEN_H-TOPBAR_HEIGHT));
    layer_add_child(window_get_root_layer(window), s_data.page_map);

    for(int i = 0; i < NUM_LIVE_FRIENDS; i++) {
        s_live.friends[i].name_frame = GRect(0, 15, 100, 15);
        s_live.friends[i].name_layer = text_layer_create(s_live.friends[i].name_frame);
        set_layer_attr_full(s_live.friends[i].name_layer, s_live.friends[i].name, font_12, GTextAlignmentLeft, GColorBlack, GColorWhite, s_data.page_map);
    }

    pathFrame = GRect(0, 0, MAP_VSIZE_X, MAP_VSIZE_Y);
    path_layer = layer_create(pathFrame);
    pathFrame.origin.x = -XINI + SCREEN_W/2;
    pathFrame.origin.y = -YINI + SCREEN_H/2;
    layer_set_frame(path_layer, pathFrame);
    layer_set_update_proc(path_layer, path_layer_update_callback);
    layer_add_child(s_data.page_map, path_layer);

    bearing_layer = layer_create(GRect(0, 0, SCREEN_W, SCREEN_H));
    layer_set_update_proc(bearing_layer, bearing_layer_update_callback);
    layer_add_child(s_data.page_map, bearing_layer);

    bearing_gpath = gpath_create(&BEARING_PATH_POINTS);
    gpath_move_to(bearing_gpath, GPoint(SCREEN_W/2, SCREEN_H/2));

    layer_set_hidden(s_data.page_map, true);


    s_gpsdata.xpos=0;
    s_gpsdata.ypos=0;
    s_gpsdata.nb_received=0;
}
Beispiel #29
0
// Draw the button onto the drawing context
void drawing_button_draw(Button *button, GContext *ctx, GSize window_size, uint8_t pose,
                         GBitmap *bmp) {
  // set fill color
  GColor fore_color = COLOR_PLAYING_FORE;
  if (pose == PoseWaitingForStart || pose == PoseDone) {
    fore_color = COLOR_PAUSED_FORE;
  } else if (pose == PoseResting) {
    fore_color = COLOR_RESTING_FORE;
  }
  graphics_context_set_fill_color(ctx, fore_color);
  // draw as path
  GPathInfo button_path = {
    .num_points = 4,
    .points = button->right,
  };
  GPath *path = gpath_create(&button_path);
  gpath_move_to(path, GPoint(window_size.w / 2, window_size.h / 2));
  gpath_draw_filled(ctx, path);
  gpath_destroy(path);
  button_path.points = button->left;
  path = gpath_create(&button_path);
  gpath_move_to(path, GPoint(window_size.w / 2, window_size.h / 2));
  gpath_draw_filled(ctx, path);
  gpath_destroy(path);
  // if aplite, cover with gray
#ifndef PBL_COLOR
  graphics_context_set_compositing_mode(ctx, GCompOpOr);
  graphics_draw_bitmap_in_rect(ctx, bmp, GRect(32, 42, 80, 80));
#endif
}


// Draw background in center of window
void drawing_background(GContext *ctx, GSize window_size, uint32_t angle, uint8_t pose,
                        GBitmap *bmp) {
#ifdef PBL_COLOR
  // draw background color of window
  // this is actually the color of the progress ring, which is then covered up to give
  // the appearance of progress
  GColor fore_color = COLOR_PLAYING_FORE;
  GColor back_color = COLOR_PLAYING_BACK;
  if (pose == PoseWaitingForStart || pose == PoseDone) {
    fore_color = COLOR_PAUSED_FORE;
    back_color = COLOR_PAUSED_BACK;
  }
  else if (pose == PoseResting) {
    fore_color = COLOR_RESTING_FORE;
    back_color = COLOR_RESTING_BACK;
  }
  graphics_context_set_fill_color(ctx, fore_color);
  graphics_fill_rect(ctx, GRect(0, 0, window_size.w, window_size.h), 1, GCornerNone);
#else
  GColor back_color = COLOR_PLAYING_BACK;
  graphics_draw_bitmap_in_rect(ctx, bmp, GRect(0, 0, window_size.w, window_size.h));
#endif
  // draw the cover for the progress ring
  prv_draw_progress_ring(ctx, window_size, angle);
  // draw the center circle
  graphics_context_set_fill_color(ctx, back_color);
  graphics_fill_circle(ctx, GPoint(window_size.w / 2, window_size.h / 2), CIRCLE_RADIUS);
}
Beispiel #30
0
void handle_init() {
  time_t clock = time(NULL);
  now = localtime(&clock);
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, BG_COLOR);

  date_layer = layer_create(GRect(0, EXTENT, EXTENT, 24));
  layer_set_update_proc(date_layer, &date_layer_update_callback);
  layer_add_child(window_get_root_layer(window), date_layer);

  background_layer = layer_create(GRect(0, 0, EXTENT, EXTENT));
  layer_set_update_proc(background_layer, &background_layer_update_callback);
  layer_add_child(window_get_root_layer(window), background_layer);

  logo = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO);
  gbitmap_set_palette(logo, bw_palette, false);
  GRect frame = gbitmap_get_bounds(logo);
  grect_align(&frame, &GRect(0, 0, EXTENT, CENTER_Y), GAlignCenter, false);
  logo_layer = bitmap_layer_create(frame);
  bitmap_layer_set_bitmap	(logo_layer, logo);
  layer_add_child(background_layer, bitmap_layer_get_layer(logo_layer));

  hands_layer = layer_create(layer_get_frame(background_layer));
  layer_set_update_proc(hands_layer, &hands_layer_update_callback);
  layer_add_child(background_layer, hands_layer);

  battery_layer = layer_create(GRect(EXTENT-22-3, 3, 22, 10));
  layer_set_update_proc(battery_layer, &battery_layer_update_callback);
  layer_add_child(window_get_root_layer(window), battery_layer);

  for (int i = 0; i < 2; i++) {
    bluetooth_images[i] = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLUETOOTH_OFF + i);  
    gbitmap_set_palette(bluetooth_images[i], bw_palette, false);
  }
  bluetooth_layer = bitmap_layer_create(GRect(CENTER_X - 6, CENTER_Y - DOTS_RADIUS - 4, 13, 13));
  layer_add_child(background_layer, bitmap_layer_get_layer(bluetooth_layer));

#if DEBUG
  debug_layer = text_layer_create(GRect(0, 0, 32, 16));
  strcpy(debug_buffer, "");
  text_layer_set_text(debug_layer, debug_buffer);
  text_layer_set_text_color(debug_layer, FG_COLOR);
  text_layer_set_background_color(debug_layer, BG_COLOR);
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(debug_layer));
#endif
  
  hour_path = gpath_create(&HOUR_POINTS);
  gpath_move_to(hour_path, GPoint(CENTER_X, CENTER_Y));
  min_path = gpath_create(&MIN_POINTS);
  gpath_move_to(min_path, GPoint(CENTER_X, CENTER_Y));
  sec_path = gpath_create(&SEC_POINTS);
  gpath_move_to(sec_path, GPoint(CENTER_X, CENTER_Y));
  battery_path = gpath_create(&BATTERY_POINTS);
  charge_path = gpath_create(&CHARGE_POINTS);

  startup_animation = animation_create();
  animation_set_curve(startup_animation, AnimationCurveEaseOut);
  animation_set_implementation(startup_animation, &startup_animation_implementation);
  startup_animation_init();
  app_focus_service_subscribe_handlers((AppFocusHandlers){
    .did_focus = handle_app_did_focus,
  });