pebble / pebblekit

Pebble's app development toolkit for the Pebble smartwatch, Android and iOS
199 stars 13 forks source link

graphics_fill_circle fills a rectangle instead of a circle #29

Closed arimwilson closed 11 years ago

arimwilson commented 11 years ago

Exactly what the summary says. I get an 8x8 rectangle instead of a circle with the following code:

const int kCircleRadius = 8; void circle_update_proc(Circle* circle, GContext* ctx) { graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle( ctx, GPoint(kCircleRadius / 2, kCircleRadius / 2), kCircleRadius); }

void handle_init(GContext* ctx) { ... window_init(&window, "Falldown"); window_set_background_color(&window, GColorBlack); window_stack_push(&window, true /* Animated */); ... }

Full source: https://code.google.com/p/ariwilson/source/browse/Falldown/src/falldown.c

Meiguro commented 11 years ago

Hey, thanks for filing an issue. I checked out your game and it looks like you're accidentally mixing up diameter and radius. The layer you made for the circle can only fit a quarter of the circle if the radius is 8, but I think you meant that the diameter is 8. If so, then you'll want to change:

graphics_fill_circle(
    ctx, GPoint(kCircleRadius / 2, kCircleRadius / 2), kCircleRadius);

to

graphics_fill_circle(
    ctx, GPoint(kCircleRadius / 2, kCircleRadius / 2), (kCircleRadius-1) / 2);

The negative one in this case is to keep the circle from being too big for the layer. You could remove the negative one and +1 the layer size instead (both circle_init and the layer_set_frame to the circle layer). That is, the layer needs the diameter, and fill circle needs the radius. Of course, after you sort out what it really means, you'll want to rename the variable accordingly :)

Also, for circle_update_proc, PebbleKit passes the current layer as the first parameter. If you change:

void circle_update_proc(Circle* circle, GContext* ctx) {

to

void circle_update_proc(Layer* layer, GContext* ctx) {

You'll be able to use the first parameter without surprises. You'll also no longer need the function type cast when setting it as the layer update proc because now it is the right function type.

arimwilson commented 11 years ago

Great, thanks for the help! Yeah I was definitely thinking of diameter :).