Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text cz #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PebbleTextWatch
===============

Pebble Text Watch implementation with animation
![Screenshot](http://c.wip.ro/image/2O1i1j1k2J0N/photo.JPG)
Binary file added resources/src/fonts/gotham_bold_36.ttf
Binary file not shown.
Binary file added resources/src/fonts/gotham_light_31.ttf
Binary file not shown.
15 changes: 10 additions & 5 deletions resources/src/resource_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
{"friendlyVersion": "0.1",
"versionDefName": "APP_RESOURCES",
"media": [
{
"type":"raw",
"defName":"DUMMY",
"file":"resource_map.json"
}
{
"type": "font",
"defName": "FONT_GOTHAM_LIGHT_31",
"file": "fonts/gotham_light_31.ttf"
},
{
"type": "font",
"defName": "FONT_GOTHAM_BOLD_36",
"file": "fonts/gotham_bold_36.ttf"
}
]
}
52 changes: 28 additions & 24 deletions src/TextWatch.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#include "resource_ids.auto.h"

#include "num2words-en.h"
#include "num2words-cz.h"

#define DEBUG 0
#define BUFFER_SIZE 44
Expand Down Expand Up @@ -33,13 +34,13 @@ Line line2;
Line line3;

PblTm t;
GFont lightFont;
GFont boldFont;

static char line1Str[2][BUFFER_SIZE];
static char line2Str[2][BUFFER_SIZE];
static char line3Str[2][BUFFER_SIZE];

static bool textInitialized = false;

// Animation handler
void animationStoppedHandler(struct Animation *animation, bool finished, void *context)
{
Expand Down Expand Up @@ -143,25 +144,6 @@ void display_initial_time(PblTm *t)
}


// Configure the first line of text
void configureBoldLayer(TextLayer *textlayer)
{
text_layer_set_font(textlayer, fonts_get_system_font(FONT_KEY_GOTHAM_42_BOLD));
text_layer_set_text_color(textlayer, GColorWhite);
text_layer_set_background_color(textlayer, GColorClear);
text_layer_set_text_alignment(textlayer, GTextAlignmentLeft);
}

// Configure for the 2nd and 3rd lines
void configureLightLayer(TextLayer *textlayer)
{
text_layer_set_font(textlayer, fonts_get_system_font(FONT_KEY_GOTHAM_42_LIGHT));
text_layer_set_text_color(textlayer, GColorWhite);
text_layer_set_background_color(textlayer, GColorClear);
text_layer_set_text_alignment(textlayer, GTextAlignmentLeft);
}


/**
* Debug methods. For quickly debugging enable debug macro on top to transform the watchface into
* a standard app and you will be able to change the time with the up and down buttons
Expand Down Expand Up @@ -209,6 +191,24 @@ void click_config_provider(ClickConfig **config, Window *window) {

#endif

// Configure the first line of text
void configureBoldLayer(TextLayer *textlayer)
{
text_layer_set_font(textlayer, boldFont);
text_layer_set_text_color(textlayer, GColorWhite);
text_layer_set_background_color(textlayer, GColorClear);
text_layer_set_text_alignment(textlayer, GTextAlignmentLeft);
}

// Configure for the 2nd and 3rd lines
void configureLightLayer(TextLayer *textlayer)
{
text_layer_set_font(textlayer, lightFont);
text_layer_set_text_color(textlayer, GColorWhite);
text_layer_set_background_color(textlayer, GColorClear);
text_layer_set_text_alignment(textlayer, GTextAlignmentLeft);
}

void handle_init(AppContextRef ctx) {
(void)ctx;

Expand All @@ -219,6 +219,10 @@ void handle_init(AppContextRef ctx) {
// Init resources
resource_init_current_app(&APP_RESOURCES);

// Custom fonts
lightFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GOTHAM_LIGHT_31));
boldFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GOTHAM_BOLD_36));

// 1st line layers
text_layer_init(&line1.currentLayer, GRect(0, 18, 144, 50));
text_layer_init(&line1.nextLayer, GRect(144, 18, 144, 50));
Expand All @@ -232,8 +236,8 @@ void handle_init(AppContextRef ctx) {
configureLightLayer(&line2.nextLayer);

// 3rd layers
text_layer_init(&line3.currentLayer, GRect(0, 92, 144, 50));
text_layer_init(&line3.nextLayer, GRect(144, 92, 144, 50));
text_layer_init(&line3.currentLayer, GRect(0, 85, 144, 50));
text_layer_init(&line3.nextLayer, GRect(144, 85, 144, 50));
configureLightLayer(&line3.currentLayer);
configureLightLayer(&line3.nextLayer);

Expand Down
89 changes: 53 additions & 36 deletions src/num2words-en.c → src/num2words-cz.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
#include "num2words-en.h"
#include "num2words-cz.h"
#include "string.h"

static const char* const ONES[] = {
"o'clock",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine"
"hodin",
"jedna",
"dva",
"tři",
"čtyři",
"pět",
"šest",
"sedm",
"osm",
"devět"
};

static const char* const TEENS[] ={
"",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eightteen",
"nineteen"
"jedenáct",
"dvanáct",
"třináct",
"čtrnáct",
"patnáct",
"šestnáct",
"sedmnáct",
"osmnáct",
"devatenáct"
};

static const char* const TENS[] = {
"",
"ten",
"twenty",
"thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
"deset",
"dvacet",
"třicet",
"čtyřicet",
"padesát",
"šedesát",
"sedmdesát",
"osmdesát",
"devadesát"
};

static size_t append_number(char* words, int num) {
Expand Down Expand Up @@ -98,7 +98,7 @@ void time_to_3words(int hours, int minutes, char *line1, char *line2, char *line
memset(line1, 0, length);
memset(line2, 0, length);
memset(line3, 0, length);

char *start = value;
char *pch = strstr (start, " ");
while (pch != NULL) {
Expand All @@ -114,11 +114,28 @@ void time_to_3words(int hours, int minutes, char *line1, char *line2, char *line
}

// Truncate long teen values
if (strlen(line2) > 7) {
char *pch = strstr(line2, "teen");
if (pch) {
memcpy(line3, pch, 4);
pch[0] = 0;
pch = strstr(line2, "náct");
if (pch) {
memcpy(line3, pch, 8);
pch[0] = 0;
} else if (strlen(line3) != 0) {
// Changing "doua" to "doi"
if (memcmp(line3, "doua", 4) == 0) {
memset(line3, 0, strlen(line3));
memcpy(line3, "doi", 3);
}

memmove(line3+3, line3, strlen(line3));
memcpy(line3, "si ", 3);
}

if (memcmp(line1, "unsprezece", 10) == 0) {
memset(line1, 0, strlen(line1));
memcpy(line1, "unspe", 5);
}
}

if (memcmp(line1, "doispre", 7) == 0) {
memset(line1, 0, strlen(line1));
memcpy(line1, "doispe", 6);
}
}
File renamed without changes.