Exemple #1
0
void second_display_layer_update_callback(Layer *me, GContext* ctx) {
	(void) me;

	time_t now = time(NULL);
	struct tm *t = localtime(&now);

	int32_t second_angle = t->tm_sec * (0xffff / 60);
	int second_hand_length = 70;
	GPoint center = grect_center_point(&GRECT_FULL_WINDOW);
	GPoint second = GPoint(center.x, center.y - second_hand_length);

	if (init_anim < ANIM_SECONDS) {
		second = GPoint(center.x, center.y - 70);
	} else if (init_anim == ANIM_SECONDS) {
		second_angle_anim += 0xffff / 60;
		if (second_angle_anim >= second_angle) {
			init_anim = ANIM_DONE;
			second =
					GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
							center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
		} else {
			second =
					GPoint(center.x + second_hand_length * sin_lookup(second_angle_anim)/0xffff,
							center.y + (-second_hand_length) * cos_lookup(second_angle_anim)/0xffff);
		}
	} else {
		second =
				GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
						center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
	}

	graphics_context_set_stroke_color(ctx, GColorWhite);

	graphics_draw_line(ctx, center, second);
}
Exemple #2
0
void second_display_layer_update_callback(Layer *me, GContext* ctx) {
  (void)me;

  PblTm t;
  get_time(&t);

  int32_t second_angle = t.tm_sec * (0xffff/60);
  int32_t counter_second_angle = t.tm_sec * (0xffff/60);
  if(t.tm_sec<30)
  {
     counter_second_angle += 0xffff/2;
  }
  else
  {
     counter_second_angle -= 0xffff/2;
  }
  int second_hand_length = 60;
  int counter_second_hand_length = 15;

  graphics_context_set_fill_color(ctx, GColorWhite);

  GPoint center = grect_center_point(&me->frame);
  GPoint counter_second = GPoint(center.x + counter_second_hand_length * sin_lookup(counter_second_angle)/0xffff,
				center.y + (-counter_second_hand_length) * cos_lookup(counter_second_angle)/0xffff);
  GPoint second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
				center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);

  graphics_draw_line(ctx, counter_second, second);
}
Exemple #3
0
static void update_scale(Layer *layer, GContext *context) {
  GRect bounds = layer_get_bounds(layer);
  GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);

  graphics_context_set_stroke_color(context, GColorWhite);
  
  GPoint start;
  GPoint end;
  
  for( int i = 0; i < 12; ++i) {
    int32_t current_angle = TRIG_MAX_ANGLE * i / 12;
    
    // create an oval shape indicator start point
    start.x = (sin_lookup(current_angle) * 65 / TRIG_MAX_RATIO) + center.x;
    start.y = (-cos_lookup(current_angle) * 75 / TRIG_MAX_RATIO) + center.y;
    end.x = (sin_lookup(current_angle) * 100 / TRIG_MAX_RATIO) + center.x;
    end.y = (-cos_lookup(current_angle) * 100 / TRIG_MAX_RATIO) + center.y;

    if (i % 3  == 0) {
      // reached a quarter, draw bigger indicator
      graphics_context_set_stroke_width(context, 6);
    } else {
      graphics_context_set_stroke_width(context, 3);
    }

    graphics_draw_line(context, start, end);          
  }
}
Exemple #4
0
static void update_time() {
  // Get a tm structure
  time_t temp = time(NULL); 
  struct tm *t = localtime(&temp);
  srand((unsigned) time(&temp));
  static PropertyAnimation *s_min_animation, *s_hour_animation, *s_ufo_animation;
  static GRect min_from_frame, min_to_frame, hour_to_frame, hour_from_frame, ufo_to_frame, ufo_from_frame;
  static int x1ufo, x2ufo, y1ufo, y2ufo;
  
  int min_distance   = 64;
  int hour_distance  = 40;
  int32_t min_angle  = TRIG_MAX_ANGLE * t->tm_min/60;
  int32_t hour_angle = (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6);
  
  xmin = (int16_t)(sin_lookup(min_angle)    * min_distance  / TRIG_MAX_RATIO) + 72 - 16;
  ymin = (int16_t)(-cos_lookup(min_angle)   * min_distance  / TRIG_MAX_RATIO) + 86 - 16;
  xhour = (int16_t)(sin_lookup(hour_angle)  * hour_distance / TRIG_MAX_RATIO) + 72 - 14;
  yhour = (int16_t)(-cos_lookup(hour_angle) * hour_distance / TRIG_MAX_RATIO) + 86 - 14;
  
  min_from_frame  = GRect(oldxmin, oldymin, 32, 32);
  min_to_frame    = GRect(xmin, ymin, 32, 32);
  
  hour_from_frame = GRect(oldxhour, oldyhour, 28,28);
  hour_to_frame   = GRect(xhour, yhour, 28,28);
  
  s_min_animation = property_animation_create_layer_frame((Layer *)s_min_layer, &min_from_frame, &min_to_frame);
  animation_set_duration((Animation *)s_min_animation,1000);
  
  
  s_hour_animation = property_animation_create_layer_frame((Layer *)s_hour_layer, &hour_from_frame, &hour_to_frame);
  animation_set_duration((Animation *)s_hour_animation,1000);

  animation_set_handlers((Animation*) s_min_animation, (AnimationHandlers) {
    .stopped = (AnimationStoppedHandler) animation_sunmoon_stopped,
  }, NULL);
Exemple #5
0
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  const int16_t hourHandLength = bounds.size.w / 2 +20;
  const int16_t minuteHandLength = hourHandLength - 30;

  GPoint minuteHand;
  center.y +=20;

  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  for (int i=0;i<12;i++)
  {
    int16_t minute_angle = TRIG_MAX_ANGLE * (((59-t->tm_min)+i*5)%60) / 60;
    minuteHand.y = (int16_t)(-cos_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.y;
    minuteHand.x = (int16_t)(sin_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.x;

    GRect frame = layer_get_frame(text_layer_get_layer(num_layer[i]));
    frame.origin.x = minuteHand.x-frame.size.w/2;
    frame.origin.y = minuteHand.y-frame.size.h/2;
    layer_set_frame(text_layer_get_layer(num_layer[i]),frame);
    layer_set_hidden(text_layer_get_layer(num_layer[i]),false);
    
    int16_t hour_angle = (TRIG_MAX_ANGLE * (((24-t->tm_hour+i) % 12) * 6) +
                         ((TRIG_MAX_ANGLE * (60-t->tm_min)) / 10))     / (12 * 6);
    minuteHand.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.y;
    minuteHand.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.x;
    
    frame = layer_get_frame(text_layer_get_layer(hour_layer[i]));
    frame.origin.x = minuteHand.x-frame.size.w/2;
    frame.origin.y = minuteHand.y-frame.size.h/2;
    layer_set_frame(text_layer_get_layer(hour_layer[i]),frame);
    layer_set_hidden(text_layer_get_layer(hour_layer[i]),false);

  }
  
  // draw minute line
  if(getDrawline())
  {
    if(getInvert())
      graphics_context_set_stroke_color(ctx,GColorWhite);
    else
      graphics_context_set_stroke_color(ctx,GColorBlack);
    graphics_draw_line(ctx,GPoint(144/2,0),GPoint(144/2,167));
  }
  // draw background
  transbitmap_draw_in_rect(background_bitmap, ctx, bounds);
  
  // draw date
  if(draw_date)
  {
    graphics_context_set_fill_color(ctx,GColorBlack);
    graphics_fill_circle(ctx,GPoint(120,120),16);
    layer_set_hidden(text_layer_get_layer(date_layer),false);
  }
  else
    layer_set_hidden(text_layer_get_layer(date_layer),true);
}
Exemple #6
0
void rotate(uint16_t ang,GPoint *p)
{
  ang-=0x4000;
  int16_t ox=p->x;
  int16_t oy=p->y;
  
  p->x=(sin_lookup(ang)*ox/TRIG_MAX_RATIO)+(cos_lookup(ang)*oy/TRIG_MAX_RATIO);
  p->y=(-cos_lookup(ang)*ox/TRIG_MAX_RATIO)+(sin_lookup(ang)*oy/TRIG_MAX_RATIO);
  
}
Exemple #7
0
static void update_main_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(s_main_layer);
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, bounds, 0, GCornerNone);
  if(s_is_running) {
    show_round_meter(ctx, &bounds);
  }

  graphics_context_set_antialiased(ctx, ANTIALIASING);

  Time mode_time;
  srand(time(NULL));
  time_t t = time(NULL);
  struct tm *time_now = localtime(&t);
  mode_time.hours = time_now->tm_hour;
  mode_time.minutes = time_now->tm_min;
  
  // Adjust for minutes through the hour
  float minute_angle = TRIG_MAX_ANGLE * mode_time.minutes / 60;
  float hour_angle = TRIG_MAX_ANGLE * mode_time.hours / 12;

  hour_angle += (minute_angle / TRIG_MAX_ANGLE) * (TRIG_MAX_ANGLE / 12);

  // Plot hands
  GPoint minute_hand = (GPoint) {
    .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60 ) * (int32_t)(HAND_RADIUS - HAND_MARGIN) / TRIG_MAX_RATIO) + s_center.x,
    .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(HAND_RADIUS - HAND_MARGIN) / TRIG_MAX_RATIO) + s_center.y,
  };
  GPoint hour_hand = (GPoint) {
    .x = (int16_t)(sin_lookup(hour_angle) * (int32_t)(HAND_RADIUS - (2 * HAND_MARGIN)) / TRIG_MAX_RATIO) + s_center.x,
    .y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)(HAND_RADIUS - (2 * HAND_MARGIN)) / TRIG_MAX_RATIO) + s_center.y,
  };
  
  graphics_context_set_stroke_color(ctx, GColorWhite);
  graphics_context_set_stroke_width(ctx, 4);
  // Draw hands with positive length only
  if(HAND_RADIUS > 2 * HAND_MARGIN) {
    graphics_draw_line(ctx, s_center, hour_hand);
  }
  if(HAND_RADIUS > HAND_MARGIN) {
    graphics_draw_line(ctx, s_center, minute_hand);
  }
 
  // center dot
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_circle(ctx, s_center, 7);
}

static void main_select_click_handler(ClickRecognizerRef recognizer, void *context) {
  window_stack_push(s_menu_window, false);
}

static void main_click_config_provider(void *context) {
  window_single_click_subscribe(BUTTON_ID_SELECT, main_select_click_handler);
}
Exemple #8
0
void batteryLineArc(GContext *ctx, float start_angle, float end_angle, GPoint centre, int radius, int thickness){
	
	float minus_bit = radius - thickness/2 + 0.5;// + (user_battery_colour <= 1 ? 0.5 : 0); //add 0.5 for the int casting, later !!! dark colours like 1.0, light better with 0.5
	float add_bit = (radius + thickness/2 + 0.5); 
	
	graphics_context_set_stroke_width(ctx, 1);
	
	if (start_angle == 0) {
		start_angle = 2.5;	// for some reason, 0 seems to start too far to the left....at least for my purposes
	}
	
	for (float i = start_angle; i <= end_angle; i+=0.5) {
		
		GPoint inside_point = (GPoint) {
			.x = (int16_t)(sin_lookup(i * TRIG_MAX_ANGLE / 360) * minus_bit / TRIG_MAX_RATIO) + centre.x,
			.y = (int16_t)(-cos_lookup(i * TRIG_MAX_ANGLE / 360) * minus_bit / TRIG_MAX_RATIO) + centre.y,
		};

		GPoint outside_point = (GPoint) {
			.x = (int16_t)(sin_lookup(i * TRIG_MAX_ANGLE / 360) * add_bit / TRIG_MAX_RATIO) + centre.x,
			.y = (int16_t)(-cos_lookup(i * TRIG_MAX_ANGLE / 360) * add_bit / TRIG_MAX_RATIO) + centre.y,
		};
		
		graphics_draw_line(ctx, inside_point, outside_point);
	}
}


/*************************** AnimationImplementation **************************/

static void animation_started(Animation *anim, void *context) {
  s_animating = true;
}

static void animation_stopped(Animation *anim, bool stopped, void *context) {
  s_animating = false;
}

static void animate(int duration, int delay, AnimationImplementation *implementation, bool handlers) {
  Animation *anim = animation_create();
  animation_set_duration(anim, duration);
  animation_set_delay(anim, delay);
  animation_set_curve(anim, AnimationCurveEaseInOut);
  animation_set_implementation(anim, implementation);
  
	if(handlers) {
    animation_set_handlers(anim, (AnimationHandlers) {
      .started = animation_started,
      .stopped = animation_stopped
    }, NULL);
  }
  animation_schedule(anim);
}
Exemple #9
0
void Graphics_RenderCircle(u16 CentreX, u16 CentreY, u16 Radius, u16 colour, TFT *TftPtr){
	double x, y, old_x, old_y;
	int i = 0;
	x = (Radius*(cos_lookup(i))) + CentreX;
	y = (Radius*(sin_lookup(i))) + CentreY;
	for(i = SIN_DIV; i<=360; i = i+SIN_DIV){
		old_x = x;
		old_y = y;
		x = (Radius*(cos_lookup(i))) + CentreX;
		y = (Radius*(sin_lookup(i))) + CentreY;
		render_line(old_x, old_y, x, y, colour, TftPtr);
	}
}
Exemple #10
0
static void anim_update(Animation *animation, const AnimationProgress progress) {
    int max_angle = TRIG_MAX_ANGLE / 8;

    int angle_left = TRIG_MAX_ANGLE / 4 + (max_angle * progress) / ANIMATION_NORMALIZED_MAX;
    int angle_right = TRIG_MAX_ANGLE / 4 - (max_angle * progress) / ANIMATION_NORMALIZED_MAX;
    int length_left = (left_length * progress) / ANIMATION_NORMALIZED_MAX;
    int length_right = (right_length * progress) / ANIMATION_NORMALIZED_MAX;
    left_end = GPoint(left_start.x + (cos_lookup(angle_left) * length_left) / TRIG_MAX_RATIO,
                      left_start.y - (sin_lookup(angle_left) * length_left) / TRIG_MAX_RATIO);

    right_end = GPoint(right_start.x + (cos_lookup(angle_right) * length_right) / TRIG_MAX_RATIO,
                       right_start.y - (sin_lookup(angle_right) * length_right) / TRIG_MAX_RATIO);
    layer_mark_dirty(graphics_layer);
}
void draw_compass_face(void) {
  int32_t starx = 0;
  int32_t stary = 0;
  if (orientToHeading) {
    starx = center.x;
    stary = center.y-63;
  } else if (heading>=0) {
    starx = center.x + 63 * sin_lookup(TRIG_MAX_ANGLE * heading / 360 + orientation)/TRIG_MAX_RATIO;
    stary = center.y - 63 * cos_lookup(TRIG_MAX_ANGLE * heading / 360 + orientation)/TRIG_MAX_RATIO;
  }    
  layer_set_frame((Layer *) star_layer, GRect(starx - 14, stary - 18, 28, 28));
  int32_t nx = center.x + 63 * sin_lookup(orientation)/TRIG_MAX_RATIO;
  int32_t ny = center.y - 63 * cos_lookup(orientation)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
  if (orientToHeading && (abs(nx-starx)<10) && (abs(ny-stary)<10))
    text_layer_set_text(n_layer, "");
  else
#endif
    text_layer_set_text(n_layer, "N");
  layer_set_frame((Layer *) n_layer, GRect(nx - 14, ny - 18, 28, 28));
  int32_t ex = center.x + 63 * sin_lookup(orientation + TRIG_MAX_ANGLE/4)/TRIG_MAX_RATIO;
  int32_t ey = center.y - 63 * cos_lookup(orientation + TRIG_MAX_ANGLE/4)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
  if (orientToHeading && (abs(ex-starx)<10) && (abs(ey-stary)<10))
    text_layer_set_text(e_layer, "");
  else
#endif
    text_layer_set_text(e_layer, "E");
  layer_set_frame((Layer *) e_layer, GRect(ex - 14, ey - 18, 28, 28));
  int32_t sx = center.x + 63 * sin_lookup(orientation + TRIG_MAX_ANGLE/2)/TRIG_MAX_RATIO;
  int32_t sy = center.y - 63 * cos_lookup(orientation + TRIG_MAX_ANGLE/2)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
  if (orientToHeading && (abs(sx-starx)<10) &&  (abs(sy-stary)<10))
    text_layer_set_text(s_layer, "");
  else
#endif
    text_layer_set_text(s_layer, "S");
  layer_set_frame((Layer *) s_layer, GRect(sx - 14, sy - 18, 28, 28));
  int32_t wx = center.x + 63 * sin_lookup(orientation + TRIG_MAX_ANGLE*3/4)/TRIG_MAX_RATIO;
  int32_t wy = center.y - 63 * cos_lookup(orientation + TRIG_MAX_ANGLE*3/4)/TRIG_MAX_RATIO;
#ifndef PBL_COLOR
  if (orientToHeading && (abs(wx-starx)<10) &&  (abs(wy-stary)<10))
    text_layer_set_text(w_layer, "");
  else
#endif
    text_layer_set_text(w_layer, "W");
  layer_set_frame((Layer *) w_layer, GRect(wx - 14, wy - 18, 28, 28));
  layer_mark_dirty(head_layer);
}
Exemple #12
0
void set_hand_angle(RotBmpPairContainer *hand_image_container, unsigned int hand_angle, GPoint offset) {
  signed short x_fudge = 0;
  signed short y_fudge = 0;

  unsigned int pebble_angle = TRIG_MAX_ANGLE * hand_angle / 360;

  x_fudge += offset.x * cos_lookup(pebble_angle) / TRIG_MAX_RATIO - offset.y * sin_lookup(pebble_angle) / TRIG_MAX_RATIO;
  y_fudge += offset.x * sin_lookup(pebble_angle) / TRIG_MAX_RATIO + offset.y * cos_lookup(pebble_angle) / TRIG_MAX_RATIO;

  // (144 = screen width, 168 = screen height)
  hand_image_container->layer.layer.frame.origin.x = (144/2) - (hand_image_container->layer.layer.frame.size.w/2) + x_fudge;
  hand_image_container->layer.layer.frame.origin.y = (168/2) - (hand_image_container->layer.layer.frame.size.h/2) + y_fudge;

  layer_mark_dirty(&hand_image_container->layer.layer);
}
Exemple #13
0
void set_hand_text(TextLayer *text_layer, unsigned int hand_angle, char *text, GPoint offset, GSize size) {
  signed short x_fudge = (144/2);
  signed short y_fudge = (168/2);

  unsigned int pebble_angle = TRIG_MAX_ANGLE * hand_angle / 360;

  x_fudge += offset.x * cos_lookup(pebble_angle) / TRIG_MAX_RATIO - offset.y * sin_lookup(pebble_angle) / TRIG_MAX_RATIO;
  y_fudge += offset.x * sin_lookup(pebble_angle) / TRIG_MAX_RATIO + offset.y * cos_lookup(pebble_angle) / TRIG_MAX_RATIO;

  x_fudge -= size.w / 2;
  y_fudge -= size.h / 2;

  layer_set_frame(&text_layer->layer, GRect(x_fudge, y_fudge, size.w, size.h));
  text_layer_set_text(text_layer, text);
}
Exemple #14
0
void startup_animation_init() {
  update_angles();
  hour_delta = GPoint(
    DOTS_RADIUS * sin_lookup(hour_angle) / ONE,
    -DOTS_RADIUS * cos_lookup(hour_angle) / ONE);
  gpath_move_to(hour_path, GPoint(CENTER_X + hour_delta.x, CENTER_Y + hour_delta.y));
  min_delta = GPoint(
    DOTS_RADIUS * sin_lookup(min_angle) / ONE,
    -DOTS_RADIUS * cos_lookup(min_angle) / ONE);
  gpath_move_to(min_path, GPoint(CENTER_X + min_delta.x, CENTER_Y + min_delta.y));
  sec_delta = GPoint(
    DOTS_RADIUS * sin_lookup(sec_angle) / ONE,
    -DOTS_RADIUS * cos_lookup(sec_angle) / ONE);
  gpath_move_to(sec_path, GPoint(CENTER_X + sec_delta.x, CENTER_Y + sec_delta.y));
}
static void hands_update_proc(Layer* me, GContext* ctx) {
  const GPoint center = grect_center_point(&me->bounds);
  const int16_t secondHandLength = me->bounds.size.w / 2;

  GPoint secondHand;

  PblTm t;
  get_time(&t);

  int32_t second_angle = TRIG_MAX_ANGLE * t.tm_sec / 60;
  secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y;
  secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x;

  // second hand
  graphics_context_set_stroke_color(ctx, GColorWhite);
  graphics_draw_line(ctx, secondHand, center);

  // minute/hour hand
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_context_set_stroke_color(ctx, GColorBlack);

  gpath_rotate_to(&s_data.minute_arrow, TRIG_MAX_ANGLE * t.tm_min / 60);
  gpath_draw_filled(ctx, &s_data.minute_arrow);
  gpath_draw_outline(ctx, &s_data.minute_arrow);

  gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((t.tm_hour % 12) * 6) + (t.tm_min / 10))) / (12 * 6));
  gpath_draw_filled(ctx, &s_data.hour_arrow);
  gpath_draw_outline(ctx, &s_data.hour_arrow);

  // dot in the middle
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, GRect(me->bounds.size.w / 2-1, me->bounds.size.h / 2-1, 3, 3), 0, GCornerNone);
}
Exemple #16
0
/**
*
* Look up cos value from a table
*
* @param 	i, angle in degrees
*
******************************************************************************/
double cos_lookup(double i){
	if(i>270)
		i = i - 270;
	else
		i = i + 90;
	return sin_lookup(i);
}
Exemple #17
0
void gpath_draw_outline_antialiased(GContext* ctx, GPath *path, GColor8 stroke_color){
	if(path->num_points == 0)
		return;	

	GPoint offset = path->offset;
	int32_t rotation = path->rotation;
	GBitmap* bitmap = graphics_capture_frame_buffer(ctx);

  	int32_t s = sin_lookup(rotation);
  	int32_t c = cos_lookup(rotation);

	GPoint p = path->points[path->num_points-1];
	GPoint p1;
  	p1.x = (p.x * c - p.y * s) / TRIG_MAX_RATIO + offset.x;
  	p1.y = (p.x * s + p.y * c) / TRIG_MAX_RATIO + offset.y;

	for(uint32_t i=0; i<path->num_points; i++){
		GPoint p2;
		p2.x = (path->points[i].x * c - path->points[i].y * s) / TRIG_MAX_RATIO  + offset.x;
		p2.y = (path->points[i].x * s + path->points[i].y * c) / TRIG_MAX_RATIO  + offset.y;
		draw_line_antialias_(bitmap, p1.x, p1.y, p2.x, p2.y, stroke_color);
		p1 = p2;
	}

	graphics_release_frame_buffer(ctx, bitmap);
}
Exemple #18
0
static void update_triangle_proc(Layer *layer, GContext *ctx) {
  if(!s_spinning) {
    return;
  }
  
  // Move
  int32_t move_x = (int32_t)(sin_lookup(angle) * (RADIUS - 4) / TRIG_MAX_RATIO);
  int32_t move_y = (int32_t)(-cos_lookup(angle) * (RADIUS - 4) / TRIG_MAX_RATIO);
  gpath_move_to(s_spin_arrow_path, GPoint(s_spin_circle_center.x - move_x, s_spin_circle_center.y + move_y));
  
  if(TESTING){
    APP_LOG(APP_LOG_LEVEL_DEBUG, "move_x: %d", (int)move_x);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "move_y: %d", (int)move_y);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "angle: %d", (int)TRIGANGLE_TO_DEG(angle));
  }
  
  // Rotate
  gpath_rotate_to(s_spin_triangle_path, -angle);
  gpath_rotate_to(s_spin_arrow_path, -angle);
  
  // Fill the path:
  graphics_context_set_fill_color(ctx, GColorBlack);
  gpath_draw_filled(ctx, s_spin_triangle_path);
  graphics_context_set_fill_color(ctx, GColorWhite);
  gpath_draw_filled(ctx, s_spin_arrow_path);
}
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  const int16_t second_hand_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 19, bounds.size.w / 2);

  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  // minute/hour hand
  // 時
  graphics_context_set_stroke_color(ctx, s_backColor);

  graphics_context_set_fill_color(ctx, s_hourHandColor);
  gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
  gpath_draw_filled(ctx, s_hour_arrow);
  // 分
  graphics_context_set_fill_color(ctx, s_backColor);
  gpath_rotate_to(s_minute_arrow, (TRIG_MAX_ANGLE * (t->tm_min * 10 + (t->tm_sec/6)) / (60 * 10)));
  graphics_context_set_stroke_width(ctx, 2);
  graphics_context_set_stroke_color(ctx, s_minuteHandColor);
  gpath_draw_outline(ctx, s_minute_arrow);

  // 秒
  int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
  GPoint second_hand = {
    .x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
    .y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
  };
if (s_show_seconds_hand){
    // second hand
    graphics_context_set_stroke_width(ctx, 3);
    graphics_context_set_stroke_color(ctx, s_secondHandColor);
    graphics_draw_line(ctx, second_hand, center);
    graphics_context_set_stroke_width(ctx, 1);
    graphics_context_set_stroke_color(ctx, s_backColor);
    graphics_draw_line(ctx, second_hand, center);
  }
  // dot in the middle
  // 黒に設定
  graphics_context_set_fill_color(ctx, s_backColor);
  // 円を塗り潰し
  graphics_fill_circle(ctx, center, 7);
  // 線の色を白に設定
  graphics_context_set_stroke_color(ctx, s_secondHandColor);
  graphics_context_set_stroke_width(ctx, 1);
  graphics_draw_circle(ctx, center, 7);
  graphics_draw_circle(ctx, center, 1);
  
}

static void date_update_proc(Layer *layer, GContext *ctx) {
  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  strftime(s_day_buffer, sizeof(s_day_buffer), "%a", t);
  text_layer_set_text(s_day_label, s_day_buffer);

  strftime(s_num_buffer, sizeof(s_num_buffer), "%d", t);
  text_layer_set_text(s_num_label, s_num_buffer);
}
Exemple #20
0
static void minute_display_layer_update_callback(Layer *layer, GContext* ctx) {

  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  unsigned int angle = t->tm_min * 6;

  GRect bounds = layer_get_bounds(layer);
  GRect min_rect;
  GPoint center = grect_center_point(&bounds);
  
  GPoint min_center; // center of the minute circle
  min_center.x = sin_lookup((TRIG_MAX_ANGLE / 360) * angle)*54/TRIG_MAX_RATIO + center.x;
  min_center.y = -cos_lookup((TRIG_MAX_ANGLE / 360) * angle)*54/TRIG_MAX_RATIO + center.y;
  graphics_context_set_fill_color(ctx, FOREGROUND_COLOR);
  graphics_context_set_stroke_color(ctx, FOREGROUND_COLOR);
  graphics_fill_circle(ctx, min_center, 17);
  
  strftime(min_text,sizeof(hour_text),"%M",t);

  min_rect.origin.x = min_center.x - 15;
  min_rect.origin.y = min_center.y - 18;
  min_rect.size.w = 30;
  min_rect.size.h = 15;
  graphics_context_set_text_color(ctx,BACKGROUND_COLOR);
  graphics_draw_text(ctx,min_text,fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD),min_rect,GTextOverflowModeWordWrap,GTextAlignmentCenter,NULL);
}
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  const GPoint center = grect_center_point(&bounds);
  const int16_t secondHandLength = bounds.size.w / 2;

  GPoint secondHand;

  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
  secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y;
  secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x;

  // second hand
  graphics_context_set_stroke_color(ctx, GColorWhite);
  graphics_draw_line(ctx, secondHand, center);

  // minute/hour hand
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_context_set_stroke_color(ctx, GColorBlack);

  gpath_rotate_to(minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
  gpath_draw_filled(ctx, minute_arrow);
  gpath_draw_outline(ctx, minute_arrow);

  gpath_rotate_to(hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
  gpath_draw_filled(ctx, hour_arrow);
  gpath_draw_outline(ctx, hour_arrow);

  // dot in the middle
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone);
}
void sechand_update_proc(Layer *me, GContext *ctx)
// The second-hand is drawn as a simple line, rather than using image
// rotation.
{
    // The second-hand has a "counterbalance", so we actually start
    // the other side of the center.
    static GPoint endpoint1, endpoint2;

    graphics_context_set_stroke_color(ctx, GColorWhite);

    // We could probably precalc these calculations, but screw it.  The
    // length of the second-hand is the same as the radius of the
    // watchface, which is the same as watchface_center.x (as that's half
    // the width a.k.a. diameter)
    int32_t a = TRIG_MAX_ANGLE * pebble_time.tm_sec / 60;
    int16_t dy = (int16_t)(-cos_lookup(a) * (int32_t)watchface_center.x / TRIG_MAX_RATIO);
    int16_t dx = (int16_t)(sin_lookup(a) * (int32_t)watchface_center.x / TRIG_MAX_RATIO);

    // Draw a line _across_ the center to the edge of the face.
    endpoint1.x = watchface_center.x + dx;
    endpoint1.y = watchface_center.y + dy;
    endpoint2.x = watchface_center.x - dx/3;
    endpoint2.y = watchface_center.y - dy/3;

    graphics_draw_line(ctx, endpoint1, endpoint2);
}
Exemple #23
0
static void updateLayer(Layer *layer, GContext *ctx) {
	int angle;
	int cos, sin;
	GPoint a;
	static GRect r = { { 0, 0}, { 144, 168 } };
	
	angle = TRIG_MAX_ANGLE * (60*(now.tm_hour%12) + now.tm_min) / 720;
	cos = cos_lookup(angle);
	sin = sin_lookup(angle);
		
	center.x = 72 - 72*sin/TRIG_MAX_RATIO;
	center.y = 84 + 72*cos/TRIG_MAX_RATIO;

	r.origin.x = center.x - bgBitmap->bounds.size.w/2;
	r.origin.y = center.y - bgBitmap->bounds.size.h/2;
	r.size = bgBitmap->bounds.size;

	graphics_draw_bitmap_in_rect(ctx, bgBitmap, r);
		
	a.x = 72 + 72*sin/TRIG_MAX_RATIO;
	a.y = 84 - 72*cos/TRIG_MAX_RATIO;

	graphics_context_set_stroke_color(ctx, GColorBlack);
	graphics_draw_thick_line(ctx, a, center, 5);

	graphics_context_set_stroke_color(ctx, GColorWhite);
	graphics_draw_line(ctx, a, center);
}
Exemple #24
0
// Get a point from a center point, angle, and radius
static GPoint prv_polar_to_rectangular(GPoint center, uint32_t angle, uint16_t radius) {
  // get the point locations
  int32_t X = (-sin_lookup(angle) * radius / TRIG_MAX_RATIO) + center.x;
  int32_t Y = (-cos_lookup(angle) * radius / TRIG_MAX_RATIO) + center.y;
  // add them to the path
  return GPoint(X, Y);
}
Exemple #25
0
static inline FPoint clockToCartesian(FPoint center, fixed_t radius, int32_t angle) {
    FPoint pt;
    int32_t c = cos_lookup(angle);
    int32_t s = sin_lookup(angle);
    pt.x = center.x + s * radius / TRIG_MAX_RATIO;
    pt.y = center.y - c * radius / TRIG_MAX_RATIO;
    return pt;
}
Exemple #26
0
static void calculate_pointer_end(int16_t t, const int16_t length_from_center, GPoint *center, GPoint *point, long scale, long offset) {
  // rotate more if any other number than scale has to be on top 
  int32_t offset_angle = TRIG_MAX_ANGLE * offset / scale;
  long angle = TRIG_MAX_ANGLE * t / scale;
  
  point->y = (-cos_lookup(angle+offset_angle) * length_from_center / TRIG_MAX_RATIO) + center->y;
  point->x = (sin_lookup(angle+offset_angle) * length_from_center / TRIG_MAX_RATIO) + center->x;
}
static GPoint calculate_angled_point(int32_t angle, int radius) {
  GPoint pt;

  pt.y = 84 + (-cos_lookup(angle) * radius / TRIG_MAX_RATIO);
  pt.x = 72 + (sin_lookup(angle) * radius / TRIG_MAX_RATIO);

  return pt;
}
Exemple #28
0
static void draw_angle_line(GContext *aCtx, GPoint aCenter, int32_t aAngle,
        int32_t aRadiusFrom, int32_t aRadiusTo, LineWidth aLineWidth) {
    GPoint pt1;
    if (aRadiusFrom == 0) {
        pt1 = aCenter;
    } else {
        pt1.y = (-cos_lookup(aAngle) * aRadiusFrom / TRIG_MAX_RATIO) + aCenter.y;
        pt1.x = ( sin_lookup(aAngle) * aRadiusFrom / TRIG_MAX_RATIO) + aCenter.x;
    }
    GPoint pt2;
    if (aRadiusTo == 0) {
        pt2 = aCenter;
    } else {
        pt2.y = (-cos_lookup(aAngle) * aRadiusTo / TRIG_MAX_RATIO) + aCenter.y;
        pt2.x = ( sin_lookup(aAngle) * aRadiusTo / TRIG_MAX_RATIO) + aCenter.x;
    }
    draw_width_line(aCtx, pt1, pt2, aLineWidth);
}
Exemple #29
0
void draw_hand_layer(Layer* l, GContext* ctx)
{
	GColor foreground_color = gcolor_legible_over(s_background_color);
	GRect bounds = layer_get_frame(l);
	GPoint center = GPoint(bounds.size.w / 2, bounds.size.h / 2);

	graphics_context_set_antialiased(ctx, true);

	graphics_context_set_stroke_color(ctx, foreground_color);
	graphics_context_set_fill_color(ctx, foreground_color);
	graphics_context_set_stroke_width(ctx, 3);

	time_t ts = time(NULL);
	struct tm* now = localtime(&ts);

	GRect reduced_bounds = bounds;
	int arc_offset = PBL_IF_ROUND_ELSE(24, 18);
	reduced_bounds.origin.x += arc_offset;
	reduced_bounds.origin.y += arc_offset;
	reduced_bounds.size.w -= (arc_offset << 1);
	reduced_bounds.size.h -= (arc_offset << 1);

	// initially, angle is relative to top (wrong)
	int angle = TRIG_MAX_ANGLE * (now->tm_hour * 60 + now->tm_min) / 1440;
	// make 0 at the bottom
	angle = (angle + TRIG_MAX_ANGLE / 2) % TRIG_MAX_ANGLE;

	graphics_context_set_fill_color(ctx, s_complementary_color);

	int hand_length = MIN(reduced_bounds.size.h, reduced_bounds.size.w) / 2;
	int radial_inset = ((hand_length - 20) * inset_pct) / 100;

	if (angle < TRIG_MAX_ANGLE / 2) {
		// first draw the bottom half
		graphics_fill_radial(ctx, reduced_bounds, GOvalScaleModeFitCircle, radial_inset, TRIG_MAX_ANGLE / 2, TRIG_MAX_ANGLE);
		graphics_draw_arc(ctx, reduced_bounds, GOvalScaleModeFitCircle, TRIG_MAX_ANGLE / 2, TRIG_MAX_ANGLE);
		// then the rest
		graphics_fill_radial(ctx, reduced_bounds, GOvalScaleModeFitCircle, radial_inset, 0, angle);
		graphics_draw_arc(ctx, reduced_bounds, GOvalScaleModeFitCircle, 0, angle);
	} else {
		graphics_fill_radial(ctx, reduced_bounds, GOvalScaleModeFitCircle, radial_inset, TRIG_MAX_ANGLE / 2, angle);
		graphics_draw_arc(ctx, reduced_bounds, GOvalScaleModeFitCircle, TRIG_MAX_ANGLE / 2, angle);
	}

	graphics_context_set_stroke_width(ctx, 2);

	GPoint hand_end;
	hand_end.y = (-cos_lookup(angle) * hand_length / TRIG_MAX_RATIO) + center.y;
	hand_end.x = (sin_lookup(angle) * hand_length / TRIG_MAX_RATIO) + center.x;

	graphics_draw_line(ctx, center, hand_end);

	GPoint sm_end = GPoint(center.x, center.y + hand_length);
	GPoint sm_start = GPoint(center.x, sm_end.y - radial_inset);

	graphics_draw_line(ctx, sm_start, sm_end);
}
Exemple #30
0
void background_layer_update_callback(Layer *layer, GContext* ctx) {
	graphics_context_set_fill_color(ctx, GColorWhite);
  for (int32_t angle = 0; angle < THREESIXTY; angle += THREESIXTY / 12) {
    GPoint pos = GPoint(
      CENTER_X + DOTS_RADIUS * cos_lookup(angle) / ONE,
      CENTER_Y + DOTS_RADIUS * sin_lookup(angle) / ONE);
    graphics_fill_circle(ctx, pos, DOTS_SIZE);
  }
}