Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Change angleStart, angleEnd to angle, angle2 to match Line's position…
Browse files Browse the repository at this point in the history
…, position2
  • Loading branch information
Meiguro committed Feb 28, 2016
1 parent 4db6cd0 commit 327dc6e
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ main.on('click', 'select', function(e) {
var radial = new UI.Radial({
position: new Vector2(2, 14),
size: new Vector2(140, 140),
angleStart: 0,
angleEnd: 300,
angle: 0,
angle2: 300,
radius: 20,
backgroundColor: 'cyan',
borderColor: 'celeste',
Expand Down
2 changes: 1 addition & 1 deletion src/js/lib/safe.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ safe.dumpError = function(err, intro, level) {
safe.warn = function(message, level, name) {
var err = new Error(message);
err.name = name || 'Warning';
safe.dumpError(err, 'Warning:', 1);
safe.dumpError(err, 'Warning:', level);
};

/* Takes a function and return a new function with a call to it wrapped in a try/catch statement */
Expand Down
2 changes: 1 addition & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Pebble.addEventListener('ready', function(e) {
return function() {
if (safe.warnGlobalMoment !== false) {
safe.warn("You've accessed moment globally. Pleae use `var moment = require('moment')` instead.\n\t" +
'moment will not be automatically loaded as a global in future versions.', 5);
'moment will not be automatically loaded as a global in future versions.', 1);
safe.warnGlobalMoment = false;
}
return (methodName ? moment[methodName] : moment).apply(this, arguments);
Expand Down
28 changes: 24 additions & 4 deletions src/js/ui/radial.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
var util2 = require('util2');
var myutil = require('myutil');
var safe = require('safe');
var Propable = require('ui/propable');
var StageElement = require('ui/element');

var accessorProps = [
'radius',
'angleStart',
'angleEnd',
'angle',
'angle2',
];

var defaults = {
backgroundColor: 'white',
borderColor: 'clear',
borderWidth: 1,
radius: 0,
angleStart: 0,
angleEnd: 360,
angle: 0,
angle2: 360,
};

var checkProps = function(def) {
if ('angleStart' in def && safe.warnAngleStart !== false) {
safe.warn('`angleStart` has been deprecated in favor of `angle` in order to match\n\t' +
"Line's `position` and `position2`. Please use `angle` intead.", 2);
safe.warnAngleStart = false;
}
if ('angleEnd' in def && safe.warnAngleEnd !== false) {
safe.warn('`angleEnd` has been deprecated in favor of `angle2` in order to match\n\t' +
"Line's `position` and `position2`. Please use `angle2` intead.", 2);
safe.warnAngleEnd = false;
}
};

var Radial = function(elementDef) {
checkProps(elementDef);
StageElement.call(this, myutil.shadow(defaults, elementDef || {}));
this.state.type = StageElement.RadialType;
};
Expand All @@ -27,4 +42,9 @@ util2.inherit(Radial, StageElement);

Propable.makeAccessors(accessorProps, Radial.prototype);

Radial.prototype._prop = function(def) {
checkProps(def);
StageElement.prototype._prop.call(this, def);
};

module.exports = Radial;
36 changes: 18 additions & 18 deletions src/js/ui/simply-pebble.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,16 +763,16 @@ var ElementRadiusPacket = new struct([
['uint16', 'radius', EnumerableType],
]);

var ElementAngleStartPacket = new struct([
var ElementAnglePacket = new struct([
[Packet, 'packet'],
['uint32', 'id'],
['uint16', 'angleStart', EnumerableType],
['uint16', 'angle', EnumerableType],
]);

var ElementAngleEndPacket = new struct([
var ElementAngle2Packet = new struct([
[Packet, 'packet'],
['uint32', 'id'],
['uint16', 'angleEnd', EnumerableType],
['uint16', 'angle2', EnumerableType],
]);

var ElementTextPacket = new struct([
Expand Down Expand Up @@ -875,8 +875,8 @@ var CommandPackets = [
ElementRemovePacket,
ElementCommonPacket,
ElementRadiusPacket,
ElementAngleStartPacket,
ElementAngleEndPacket,
ElementAnglePacket,
ElementAngle2Packet,
ElementTextPacket,
ElementTextStylePacket,
ElementImagePacket,
Expand Down Expand Up @@ -1346,16 +1346,16 @@ SimplyPebble.elementCommon = function(id, def) {
SimplyPebble.sendPacket(ElementCommonPacket);
};

SimplyPebble.elementRadius = function(id, radius) {
SimplyPebble.sendPacket(ElementRadiusPacket.id(id).radius(radius));
SimplyPebble.elementRadius = function(id, def) {
SimplyPebble.sendPacket(ElementRadiusPacket.id(id).radius(def.radius));
};

SimplyPebble.elementAngleStart = function(id, angleStart) {
SimplyPebble.sendPacket(ElementAngleStartPacket.id(id).angleStart(angleStart));
SimplyPebble.elementAngle = function(id, def) {
SimplyPebble.sendPacket(ElementAnglePacket.id(id).angle(def.angleStart || def.angle));
};

SimplyPebble.elementAngleEnd = function(id, angleEnd) {
SimplyPebble.sendPacket(ElementAngleEndPacket.id(id).angleEnd(angleEnd));
SimplyPebble.elementAngle2 = function(id, def) {
SimplyPebble.sendPacket(ElementAngle2Packet.id(id).angle2(def.angleEnd || def.angle2));
};

SimplyPebble.elementText = function(id, text, timeUnits) {
Expand Down Expand Up @@ -1398,20 +1398,20 @@ SimplyPebble.stageElement = function(id, type, def, index) {
switch (type) {
case StageElement.RectType:
case StageElement.CircleType:
SimplyPebble.elementRadius(id, def.radius);
SimplyPebble.elementRadius(id, def);
break;
case StageElement.RadialType:
SimplyPebble.elementRadius(id, def.radius);
SimplyPebble.elementAngleStart(id, def.angleStart);
SimplyPebble.elementAngleEnd(id, def.angleEnd);
SimplyPebble.elementRadius(id, def);
SimplyPebble.elementAngle(id, def);
SimplyPebble.elementAngle2(id, def);
break;
case StageElement.TextType:
SimplyPebble.elementRadius(id, def.radius);
SimplyPebble.elementRadius(id, def);
SimplyPebble.elementTextStyle(id, def);
SimplyPebble.elementText(id, def.text, def.updateTimeUnits);
break;
case StageElement.ImageType:
SimplyPebble.elementRadius(id, def.radius);
SimplyPebble.elementRadius(id, def);
SimplyPebble.elementImage(id, def.image, def.compositing);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/simply/simply_msg_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ enum Command {
CommandElementRemove,
CommandElementCommon,
CommandElementRadius,
CommandElementAngleStart,
CommandElementAngleEnd,
CommandElementAngle,
CommandElementAngle2,
CommandElementText,
CommandElementTextStyle,
CommandElementImage,
Expand Down
54 changes: 25 additions & 29 deletions src/simply/simply_stage.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,15 @@ struct __attribute__((__packed__)) ElementRadiusPacket {
uint16_t radius;
};

typedef struct CommandElementAngleStartPacket CommandElementAngleStartPacket;
typedef struct ElementAnglePacket ElementAnglePacket;

struct __attribute__((__packed__)) CommandElementAngleStartPacket {
struct __attribute__((__packed__)) ElementAnglePacket {
Packet packet;
uint32_t id;
uint16_t angle_start;
uint16_t angle;
};

typedef struct CommandElementAngleEndPacket CommandElementAngleEndPacket;

struct __attribute__((__packed__)) CommandElementAngleEndPacket {
Packet packet;
uint32_t id;
uint16_t angle_end;
};
typedef struct ElementAnglePacket ElementAngle2Packet;

typedef struct ElementTextPacket ElementTextPacket;

Expand Down Expand Up @@ -239,20 +233,20 @@ static void prv_draw_line_polar(GContext *ctx, const GRect *outer_frame, const G

static void radial_element_draw(GContext *ctx, SimplyStage *self, SimplyElementRadial *element) {
const GOvalScaleMode scale_mode = GOvalScaleModeFitCircle;
const int32_t angle_start = DEG_TO_TRIGANGLE(element->angle_start);
const int32_t angle_end = DEG_TO_TRIGANGLE(element->angle_end);
const int32_t angle = DEG_TO_TRIGANGLE(element->angle);
const int32_t angle2 = DEG_TO_TRIGANGLE(element->angle2);
const GRect *frame = &element->rect.common.frame;
if (element->rect.common.background_color.a) {
graphics_fill_radial(ctx, *frame, scale_mode, element->rect.radius, angle_start, angle_end);
graphics_fill_radial(ctx, *frame, scale_mode, element->rect.radius, angle, angle2);
}
if (element->rect.common.border_color.a && element->rect.common.border_width) {
graphics_draw_arc(ctx, *frame, scale_mode, angle_start, angle_end);
graphics_draw_arc(ctx, *frame, scale_mode, angle, angle2);
if (element->rect.radius) {
GRect inner_frame = grect_inset(*frame, GEdgeInsets(element->rect.radius));
if (inner_frame.size.w) {
prv_draw_line_polar(ctx, frame, &inner_frame, scale_mode, angle_start);
prv_draw_line_polar(ctx, frame, &inner_frame, scale_mode, angle_end);
graphics_draw_arc(ctx, inner_frame, GOvalScaleModeFitCircle, angle_start, angle_end);
prv_draw_line_polar(ctx, frame, &inner_frame, scale_mode, angle);
prv_draw_line_polar(ctx, frame, &inner_frame, scale_mode, angle2);
graphics_draw_arc(ctx, inner_frame, GOvalScaleModeFitCircle, angle, angle2);
}
}
}
Expand Down Expand Up @@ -622,23 +616,25 @@ static void handle_element_radius_packet(Simply *simply, Packet *data) {
simply_stage_update(simply->stage);
};

static void handle_element_angle_start_packet(Simply *simply, Packet *data) {
CommandElementAngleStartPacket *packet = (CommandElementAngleStartPacket*) data;
SimplyElementRadial *element = (SimplyElementRadial*) simply_stage_get_element(simply->stage, packet->id);
static void handle_element_angle_packet(Simply *simply, Packet *data) {
ElementAnglePacket *packet = (ElementAnglePacket *)data;
SimplyElementRadial *element =
(SimplyElementRadial *)simply_stage_get_element(simply->stage, packet->id);
if (!element) {
return;
}
element->angle_start = packet->angle_start;
element->angle = packet->angle;
simply_stage_update(simply->stage);
};

static void handle_element_angle_end_packet(Simply *simply, Packet *data) {
CommandElementAngleEndPacket *packet = (CommandElementAngleEndPacket*) data;
SimplyElementRadial *element = (SimplyElementRadial*) simply_stage_get_element(simply->stage, packet->id);
static void handle_element_angle2_packet(Simply *simply, Packet *data) {
ElementAngle2Packet *packet = (ElementAngle2Packet *)data;
SimplyElementRadial *element =
(SimplyElementRadial *)simply_stage_get_element(simply->stage, packet->id);
if (!element) {
return;
}
element->angle_end = packet->angle_end;
element->angle2 = packet->angle;
simply_stage_update(simply->stage);
};

Expand Down Expand Up @@ -718,11 +714,11 @@ bool simply_stage_handle_packet(Simply *simply, Packet *packet) {
case CommandElementRadius:
handle_element_radius_packet(simply, packet);
return true;
case CommandElementAngleStart:
handle_element_angle_start_packet(simply, packet);
case CommandElementAngle:
handle_element_angle_packet(simply, packet);
return true;
case CommandElementAngleEnd:
handle_element_angle_end_packet(simply, packet);
case CommandElementAngle2:
handle_element_angle2_packet(simply, packet);
return true;
case CommandElementText:
handle_element_text_packet(simply, packet);
Expand Down
4 changes: 2 additions & 2 deletions src/simply/simply_stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ typedef struct SimplyElementRadial SimplyElementRadial;

struct SimplyElementRadial {
SimplyElementRect rect;
uint16_t angle_start;
uint16_t angle_end;
uint16_t angle;
uint16_t angle2;
};

typedef struct SimplyElementText SimplyElementText;
Expand Down

0 comments on commit 327dc6e

Please sign in to comment.