From d91dc97184708b958985e01ac068582aaf01b313 Mon Sep 17 00:00:00 2001 From: Daniel Johnson Date: Sat, 13 Jun 2015 14:09:55 -0700 Subject: [PATCH] Initial commit --- appinfo.json | 29 ++ resources/images/squared3_menu.png | Bin 0 -> 367 bytes src/squared.c | 476 +++++++++++++++++++++++++++++ wscript | 62 ++++ 4 files changed, 567 insertions(+) create mode 100644 appinfo.json create mode 100644 resources/images/squared3_menu.png create mode 100644 src/squared.c create mode 100644 wscript diff --git a/appinfo.json b/appinfo.json new file mode 100644 index 0000000..9fe287d --- /dev/null +++ b/appinfo.json @@ -0,0 +1,29 @@ +{ + "appKeys": {}, + "capabilities": [ + "" + ], + "companyName": "hexahedria", + "longName": "Squared 3.0", + "projectType": "native", + "resources": { + "media": [ + { + "file": "images/squared3_menu.png", + "menuIcon": true, + "name": "MENU_ICON", + "type": "png" + } + ] + }, + "sdkVersion": "3", + "shortName": "Squared 3.0", + "targetPlatforms": [ + "basalt" + ], + "uuid": "67142435-ff9a-431f-94ec-e1ac54a82d20", + "versionLabel": "1.0", + "watchapp": { + "watchface": true + } +} diff --git a/resources/images/squared3_menu.png b/resources/images/squared3_menu.png new file mode 100644 index 0000000000000000000000000000000000000000..967ed9dcd3affd457d13deeb681858d412d614ee GIT binary patch literal 367 zcmeAS@N?(olHy`uVBq!ia0vp^G9b*s1|*Ak?@s|zY)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~8?Pvns-fq;aKz-VTd`!~ zmqgVsiONe>@8%a56?z|ReD3380kuyN5k`zZ9ynD#Oxk(p;qMhXnT!lmqIUi22^Fu{ zeT)Cqualm0CkLfY;Njo6F6!$1>AIgag4~Y^m`3*;IpjVklJTa&{7BBtn~nBNuZ%O` zYRkGC`cTRKcz{jW!st{7p1p?cCz8+WDYRKv{i~Bo;9Gut^7g|8YUXK1XC%#>LZsiR zE;B0++;8ukxa5*wSootk$Mmj!{HFL__JoDCd)o1dVVt+Cf0uE@+*x^fucTPsrxO;} zrheR$s>XZf%Cm~kGD3&n`X2hbg4cXnUHGyO+c+iv@BAXkw|{$nLSvUx!z5rhFnGH9 KxvX + +Window *window; + +#define US_DATE true // true == MM/DD, false == DD/MM +#define NO_ZERO true // true == replaces leading Zero for hour, day, month with a "cycler" +#define TILE_SIZE 10 +#define NUMSLOTS 8 +#define SPACING_X TILE_SIZE +#define SPACING_Y TILE_SIZE +#define DIGIT_CHANGE_ANIM_DURATION 1700 +#define STARTDELAY 2000 + +#define NUMBER_BASE_COLOR_ARGB8 0b11001010 +#define ORNAMENT_BASE_COLOR_ARGB8 0b11100010 +#define ADD_VARIATION true // true == colors are randomly shifted + +#define FONT blocks // blocks or clean. clean == numbers with no ornaments + +typedef struct { + Layer *layer; + int prevDigit; + int curDigit; + int divider; + AnimationProgress normTime; + int slotIndex; +} digitSlot; + +digitSlot slot[NUMSLOTS]; + +AnimationImplementation animImpl; +Animation *anim; +bool splashEnded = false; + +unsigned char blocks[][5][5] = {{ + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,0,2,0,1}, + {1,0,0,0,1}, + {1,1,1,1,1} +}, { + {2,2,0,1,1}, + {0,0,0,0,1}, + {2,2,2,0,1}, + {0,0,0,0,1}, + {2,2,2,0,1} +}, { + {1,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1}, + {1,0,0,0,0}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {0,0,0,0,1}, + {0,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,0,2,0,1}, + {1,0,0,0,1}, + {1,1,1,1,1}, + {0,0,0,0,1}, + {2,2,2,0,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,0}, + {1,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,0}, + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {0,0,0,0,1}, + {2,0,2,0,1}, + {2,0,2,0,1}, + {2,0,2,0,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1} +}, { + {2,2,2,2,2}, + {0,0,0,0,0}, + {2,2,2,2,2}, + {0,0,0,0,0}, + {2,2,2,2,2} +}, { + {2,0,2,0,2}, + {2,0,2,0,2}, + {2,0,2,0,2}, + {2,0,2,0,2}, + {2,0,2,0,2} +}}; +unsigned char clean[][5][5] = {{ + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,0,0,0,1}, + {1,0,0,0,1}, + {1,1,1,1,1} +}, { + {0,0,0,1,1}, + {0,0,0,0,1}, + {0,0,0,0,1}, + {0,0,0,0,1}, + {0,0,0,0,1} +}, { + {1,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1}, + {1,0,0,0,0}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {0,0,0,0,1}, + {0,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,0,0,0,1}, + {1,0,0,0,1}, + {1,1,1,1,1}, + {0,0,0,0,1}, + {0,0,0,0,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,0}, + {1,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,0}, + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {0,0,0,0,1}, + {0,0,0,0,1}, + {0,0,0,0,1}, + {0,0,0,0,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1} +}, { + {1,1,1,1,1}, + {1,0,0,0,1}, + {1,1,1,1,1}, + {0,0,0,0,1}, + {1,1,1,1,1} +}, { + {2,2,2,2,2}, + {2,2,2,2,2}, + {2,2,2,2,2}, + {2,2,2,2,2}, + {2,2,2,2,2} +}, { + {2,2,2,2,2}, + {2,2,2,2,2}, + {2,2,2,2,2}, + {2,2,2,2,2}, + {2,2,2,2,2} +}}; + +int startDigit[NUMSLOTS] = { + 11,10,10,11,11,10,10,11 +}; + +unsigned char variation[] = { + 0b00000000, 0b00010000, 0b00000100, 0b00010000, 0b00000000, + 0b00010001, 0b00010000, 0b00000000, 0b00000101, 0b00010000, + 0b00000001, 0b00000000, 0b00000000, 0b00010100, 0b00010001, + 0b00000000, 0b00010001, 0b00000101, 0b00010001, 0b00010100, + 0b00000000, 0b00010001, 0b00000101, 0b00000000, 0b00000001, + 0b00000100, 0b00010100, 0b00010100, 0b00000001, 0b00010100, + 0b00010001, 0b00000001, 0b00010101, 0b00010101, 0b00010000, + 0b00000000, 0b00010100, 0b00010001, 0b00010100, 0b00000100, + 0b00010100, 0b00010101, 0b00010001, 0b00010001, 0b00010101, + 0b00010000, 0b00010000, 0b00000000, 0b00010000, 0b00000001, + 0b00000001, 0b00000000, 0b00010100, 0b00000000, 0b00010100, + 0b00010100, 0b00000001, 0b00000101, 0b00010000, 0b00010000, + 0b00000001, 0b00010000, 0b00000000, 0b00000001, 0b00000000, + 0b00010100, 0b00000100, 0b00000001, 0b00010000, 0b00010000, + 0b00000001, 0b00000001, 0b00000101, 0b00010101, 0b00000000, + 0b00010000, 0b00000001, 0b00000001, 0b00010000, 0b00000000, + 0b00000100, 0b00010000, 0b00010100, 0b00010000, 0b00010100, + 0b00000100, 0b00010101, 0b00010101, 0b00010000, 0b00010101, + 0b00000101, 0b00000001, 0b00010100, 0b00010100, 0b00000000, + 0b00000000, 0b00000001, 0b00010001, 0b00000101, 0b00010100 +}; + +#define FONT_HEIGHT_BLOCKS (sizeof *FONT / sizeof **FONT) +#define FONT_WIDTH_BLOCKS (sizeof **FONT) +#define TOTALBLOCKS FONT_HEIGHT_BLOCKS * FONT_WIDTH_BLOCKS +#define FONT_HEIGHT FONT_HEIGHT_BLOCKS*TILE_SIZE +#define FONT_WIDTH FONT_WIDTH_BLOCKS*TILE_SIZE + +#define SCREEN_WIDTH 144 + +#define TILES_X ( \ + FONT_WIDTH + SPACING_X + FONT_WIDTH) +#define TILES_Y ( \ + FONT_HEIGHT + SPACING_Y + FONT_HEIGHT) + +#define ORIGIN_X ((SCREEN_WIDTH - TILES_X)/2) +#define ORIGIN_Y TILE_SIZE*1.5 + +static GRect slotFrame(int i) { + int x, y, w, h; + if (i<4) { + w = FONT_WIDTH; + h = FONT_HEIGHT; + if (i%2) { + x = ORIGIN_X + FONT_WIDTH + SPACING_X; // i = 1 or 3 + } else { + x = ORIGIN_X; // i = 0 or 2 + } + + if (i<2) { + y = ORIGIN_Y; + } else { + y = ORIGIN_Y + FONT_HEIGHT + SPACING_Y; + } + } else { + w = FONT_WIDTH/2; + h = FONT_HEIGHT/2; + x = ORIGIN_X + (FONT_WIDTH + SPACING_X) * (i - 4) / 2; + y = ORIGIN_Y + (FONT_HEIGHT + SPACING_Y) * 2; + } + return GRect(x, y, w, h); +} + +static GColor8 getSlotColor(int x, int y, int digit, int pos) { + int argb; + if (FONT[digit][y][x] == 0) { + return GColorBlack; + } else if (FONT[digit][y][x] == 1) { + argb = NUMBER_BASE_COLOR_ARGB8; + } else { + argb = ORNAMENT_BASE_COLOR_ARGB8; + } + if (ADD_VARIATION) { + argb += variation[ ( y*5 + x + digit*17 + pos*19 )%sizeof(variation) ]; + } + GColor8 color = { .argb = argb }; + return color; +} + +static void updateSlot(Layer *layer, GContext *ctx) { + int t, tx, ty, w, offs, shift, total, tilesize, widthadjust; + total = TOTALBLOCKS; + widthadjust = 0; + digitSlot *slot = *(digitSlot**)layer_get_data(layer); + + if (slot->divider == 2) { + widthadjust = 1; + } + tilesize = TILE_SIZE/slot->divider; + uint32_t skewedNormTime = slot->normTime*3; + GRect r; + + graphics_context_set_fill_color(ctx, GColorBlack); + r = layer_get_bounds(slot->layer); + graphics_fill_rect(ctx, GRect(0, 0, r.size.w, r.size.h), 0, GCornerNone); + for (t=0; tprevDigit, slot->slotIndex); + GColor8 newColor = getSlotColor(tx, ty, slot->curDigit, slot->slotIndex); + + graphics_context_set_fill_color(ctx, oldColor); + graphics_fill_rect(ctx, GRect((tx*tilesize)-(tx*widthadjust), ty*tilesize-(ty*widthadjust), tilesize-widthadjust, tilesize-widthadjust), 0, GCornerNone); + + if(!gcolor_equal(oldColor, newColor)) { + w = (skewedNormTime*TILE_SIZE/ANIMATION_NORMALIZED_MAX)+shift-widthadjust; + if (w < 0) { + w = 0; + } else if (w > tilesize-widthadjust) { + w = tilesize-widthadjust; + } + graphics_context_set_fill_color(ctx, newColor); + graphics_fill_rect(ctx, GRect((tx*tilesize)-(tx*widthadjust), ty*tilesize-(ty*widthadjust), w, tilesize-widthadjust), 0, GCornerNone); + } + } +} + +static unsigned short get_display_hour(unsigned short hour) { + if (clock_is_24h_style()) { + return hour; + } + unsigned short display_hour = hour % 12; + return display_hour ? display_hour : 12; +} + +static void setupAnimation() { + anim = animation_create(); + animation_set_delay(anim, 0); + animation_set_duration(anim, DIGIT_CHANGE_ANIM_DURATION); + animation_set_implementation(anim, &animImpl); +} + +static void destroyAnimation() { + animation_destroy(anim); +} + +void handle_tick(struct tm *t, TimeUnits units_changed) { + int ho, mi, da, mo, i; + + if (splashEnded) { + if (animation_is_scheduled(anim)){ + animation_unschedule(anim); + animation_destroy(anim); + } + + ho = get_display_hour(t->tm_hour); + mi = t->tm_min; + da = t->tm_mday; + mo = t->tm_mon+1; + + for (i=0; islotIndex = i; + s->normTime = ANIMATION_NORMALIZED_MAX; + s->prevDigit = 0; + s->curDigit = startDigit[i]; + if (i<4) { + s->divider = 1; + } else { + s->divider = 2; + } + s->layer = layer_create_with_data(slotFrame(i), sizeof(digitSlot *)); + *(digitSlot **)layer_get_data(s->layer) = s; + + layer_set_update_proc(s->layer, updateSlot); + layer_add_child(parent, s->layer); +} + +static void deinitSlot(int i) { + layer_destroy(slot[i].layer); +} + +static void animateDigits(struct Animation *anim, const AnimationProgress normTime) { + int i; + for (i=0; i