Jump to content

Need help with some code (C)

XTankSlayerX

Well, I think this is C... Must be confusing the name with other languages.

 

Anyways.

 

I've been coding a pebble watchface, and im pretty much done except the colon on the time dosnt show up right...

 

Any ideas? I really want to use the WAN Show font (8Bit Wonders)

 

16813398656_b1ca0df58a_o.png

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

From the looks of it that font doesn't have a colon character. Could you split it into 3 strings using the font you want for the numbers and a different font for just the colon?

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Show some code, but you may have to escape the character by placing a backslash in front of it depending on which language it's actually in.

Link to comment
Share on other sites

Link to post
Share on other sites

Show some code, but you may have to escape the character by placing a backslash in front of it.

Here

 

 

EDIT: First thing I've coded, its more of a mod to a tutorial rather than 100% my own code.

#include <pebble.h>  static Window *s_main_window;static TextLayer *s_time_layer;static GFont s_time_font;static BitmapLayer *s_background_layer;static GBitmap *s_background_bitmap;static void update_time() {  // Get a tm structure  time_t temp = time(NULL);   struct tm *tick_time = localtime(&temp);  // Create a long-lived buffer  static char buffer[] = "00:00";  // Write the current hours and minutes into the buffer  if(clock_is_24h_style() == true) {    //Use 2h hour format    strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);  } else {    //Use 12 hour format    strftime(buffer, sizeof("00:00"), "%I:%M", tick_time);  }  // Display this time on the TextLayer  text_layer_set_text(s_time_layer, buffer);}static void main_window_load(Window *window) {  //Create GBitmap, then set to created BitmapLayer  s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));    // Create time TextLayer  s_time_layer = text_layer_create(GRect(5, 52, 139, 50));  text_layer_set_background_color(s_time_layer, GColorClear);  text_layer_set_text_color(s_time_layer, GColorBlack);  text_layer_set_text(s_time_layer, "00:00");    //Create GFont  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_PERFECT_DOS_48));  //Apply to TextLayer  text_layer_set_font(s_time_layer, s_time_font);  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);  // Add it as a child layer to the Window's root layer  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));    // Make sure the time is displayed from the start  update_time();}static void main_window_unload(Window *window) {  //Unload GFont  fonts_unload_custom_font(s_time_font);    //Destroy GBitmap  gbitmap_destroy(s_background_bitmap);  //Destroy BitmapLayer  bitmap_layer_destroy(s_background_layer);    // Destroy TextLayer  text_layer_destroy(s_time_layer);}static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {  update_time();}  static void init() {  // Create main Window element and assign to pointer  s_main_window = window_create();  // Set handlers to manage the elements inside the Window  window_set_window_handlers(s_main_window, (WindowHandlers) {    .load = main_window_load,    .unload = main_window_unload  });  // Show the Window on the watch, with animated=true  window_stack_push(s_main_window, true);    // Register with TickTimerService  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);}static void deinit() {  // Destroy Window  window_destroy(s_main_window);}int main(void) {  init();  app_event_loop();  deinit();}

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×