static void maze_layer_update(Layer *me, GContext *ctx) {
  GRect cell;
  // Draw the maze
  
  // [Put your maze drawing code here]
  
  // Draw the start entrance
  graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorLightGray, GColorRed));
  cell = GRect(start_x * CELL_SIZE, start_y * CELL_SIZE, CELL_SIZE, CELL_SIZE);
  graphics_fill_rect(ctx, cell, 0, GCornerNone);
  
  // Draw the finish exit
  graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorLightGray, GColorRed));
  cell = GRect(finish_x * CELL_SIZE, finish_y * CELL_SIZE, CELL_SIZE, CELL_SIZE);
  graphics_fill_rect(ctx, cell, 0, GCornerNone);
}
// ------------------------------------------------------------------------ //
//  Drawing Functions
// ------------------------------------------------------------------------ //
static void solution_layer_update(Layer *me, GContext *ctx) {
  // Draw the solution
  graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorLightGray, GColorRed));

  // [Put your maze solution drawing code here]
  
}
Exemple #3
0
static void battery_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);

  // Find the width of the bar
  float percent = ((float)s_battery_level / 100.0F);
  int width = (int)(float)(percent * bounds.size.w);

  // Draw the background
  
  GColor bgcolor = GColorFromHEX(persist_read_int(MESSAGE_KEY_BackgroundColor));
  GColor batterycolor;
  
  //graphics_context_set_fill_color(ctx, GColorClear);
  //graphics_fill_rect(ctx, bounds, 0, GCornerNone);

  // Draw the bar
  int g = (255 * percent);
  int r = (255 * (1 - percent));
  int b = 0;
  int rgb = createRGB(r, g, b);

  if (s_battery_level == 100) {
    r = 85;
    g = 255;
  }
  if (s_battery_level == 50) {
    rgb = 0xFFAA00;
  }
  int x = persist_read_int(MESSAGE_KEY_Battery);
  APP_LOG(APP_LOG_LEVEL_INFO, "Battery Preference: %d", x);
  if (persist_read_int(MESSAGE_KEY_Battery) != 102) {
    APP_LOG(APP_LOG_LEVEL_INFO, "RGB");
    batterycolor = GColorFromHEX(rgb);
  } else {
    batterycolor = gcolor_legible_over(bgcolor);
  }

  PBL_IF_BW_ELSE(graphics_context_set_fill_color(ctx, batterycolor), graphics_context_set_fill_color(ctx, batterycolor));
  //APP_LOG(APP_LOG_LEVEL_INFO, GColorFromHEX(rgb));
  
  /*
  if (s_battery_level <= 20) {
    graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorRed));
  } else if (s_battery_level == 100) {
    graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorBrightGreen));
  }
  */
  
  GRect frame = grect_inset(bounds, GEdgeInsets(10));
  
  //graphics_context_set_fill_color(ctx, GColorBlack);
  
  PBL_IF_ROUND_ELSE(graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, 5,
                       DEG_TO_TRIGANGLE(125+((1-percent)*110)), DEG_TO_TRIGANGLE(235)), 
                    graphics_fill_rect(ctx, GRect(0, 0, width, bounds.size.h), 0, GCornerNone));
  
}
Exemple #4
0
static void update_time() {
  // Get a tm structure
  time_t temp = time(NULL);
  struct tm *tick_time = localtime(&temp);

  // Write the current hours and minutes into a buffer
  static char s_buffer[8];
  APP_LOG(APP_LOG_LEVEL_INFO, "24 hour time: %d", persist_read_bool(MESSAGE_KEY_Twenty_Four_Hour_Format));
  if (persist_read_bool(MESSAGE_KEY_Twenty_Four_Hour_Format) == 1) {
    APP_LOG(APP_LOG_LEVEL_INFO, "24h:");
    strftime(s_buffer, sizeof("00:00"), "%H:%M", tick_time);
  } else {
  APP_LOG(APP_LOG_LEVEL_INFO, "12h:");
  strftime(s_buffer, sizeof(s_buffer), "%I:%M", tick_time);
  }
  // Display this time on the TextLayer
  if('0' == s_buffer[0]) {
    text_layer_set_text(s_time_layer, s_buffer+1);
  } else
  {
  text_layer_set_text(s_time_layer, s_buffer);
  }
  APP_LOG(APP_LOG_LEVEL_INFO, "getting date");
  // Copy date into buffer from tm structure
  static char date_buffer[16];
  strftime(date_buffer, sizeof(date_buffer), PBL_IF_BW_ELSE("%a  %b %d", PBL_IF_ROUND_ELSE("%a  %b %d", "%a %n %b %d")), tick_time);
  APP_LOG(APP_LOG_LEVEL_INFO, "date calculations");
  // Show the date
  int x;
  PBL_IF_BW_ELSE(x = 9, x = 10);
  PBL_IF_ROUND_ELSE(x = 9, x = 10);
  if(date_buffer[x]=='0') {
  date_buffer[x]=date_buffer[x+1]; // copy the second digit on top of the first one
  date_buffer[x+1]=0; // shorten the string by one character
}
  APP_LOG(APP_LOG_LEVEL_INFO, "set date text:");
  text_layer_set_text(s_date_layer, date_buffer);
  APP_LOG(APP_LOG_LEVEL_INFO, "returning from updatetime");
}
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  
  //Bitmap Layyer + GBitmap
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ROBOSTANGS_LOGO);
  s_background_layer = bitmap_layer_create(bounds);
  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  bitmap_layer_set_alignment(s_background_layer, GAlignTop);
  layer_add_child(window_layer, bitmap_layer_get_layer(s_background_layer));
  
  //Time layer
  s_time_layer = text_layer_create(GRect(0, 125, bounds.size.w, 50));
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BANK_GOTHIC_30));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, PBL_IF_BW_ELSE(GColorWhite, GColorChromeYellow));
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
}
/***Handle Window***/
static void main_window_load(Window *window) {
	//Get information about the window
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);
	
	//Use platform specific background image
	s_bitmap = gbitmap_create_with_resource(
		PBL_IF_BW_ELSE(RESOURCE_ID_IMAGE_BACKGROUND_BW, RESOURCE_ID_IMAGE_BACKGROUND_COLOR));
	s_bitmap_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); //size of image
	bitmap_layer_set_compositing_mode(s_bitmap_layer, GCompOpSet);
	bitmap_layer_set_bitmap(s_bitmap_layer, s_bitmap);
	window_set_background_color(s_main_window, GColorBlack);
	layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_layer));
	
	//Add custom font
	s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MONACO_14));	
		
	//Time layer
	s_time_layer = text_layer_create(GRect(5, 30, bounds.size.w, 40));
	text_layer_set_background_color(s_time_layer, GColorClear);
	text_layer_set_text_color(s_time_layer, GColorWhite);
	text_layer_set_font(s_time_layer, s_font);
	layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
	
	//Battery layer
	s_battery_layer = text_layer_create(GRect(5, 70, bounds.size.w, 50));
	text_layer_set_background_color(s_battery_layer, GColorClear);
	text_layer_set_text_color(s_battery_layer, GColorWhite);
	text_layer_set_font(s_battery_layer, s_font);
	layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
	
	//Connection layer
	s_connection_layer = text_layer_create(GRect(5, 100, bounds.size.w, 20));
	text_layer_set_background_color(s_connection_layer, GColorClear);
	text_layer_set_text_color(s_connection_layer, GColorWhite);
	text_layer_set_font(s_connection_layer, s_font);
	handle_bluetooth(connection_service_peek_pebble_app_connection());
	layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
	
	//Other text layer
	s_text_layer = text_layer_create(GRect(5, 125, bounds.size.w, 20));
	text_layer_set_background_color(s_text_layer, GColorClear);
	text_layer_set_text_color(s_text_layer, GColorWhite);
	text_layer_set_font(s_text_layer, s_font);
	text_layer_set_text(s_text_layer, "root@PC:/$");
	layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
	
	//Platform-specific cursor animation
	//Stationary cursor for Aplite
	#if defined (PBL_BW)
	s_bitmap_cursor = gbitmap_create_with_resource(RESOURCE_ID_STATIC_CURSOR);
	//Blinking cursor for Basalt
	#elif defined (PBL_COLOR)
	s_sequence = gbitmap_sequence_create_with_resource(RESOURCE_ID_BLINKING_CURSOR);
	GSize frame_size = gbitmap_sequence_get_bitmap_size(s_sequence);
	s_bitmap_cursor = gbitmap_create_blank(frame_size, GBitmapFormat8Bit);
	//Start the animation
	uint32_t first_delay_ms = 1000;
	app_timer_register(first_delay_ms, timer_handler, NULL);
	#endif
	
	s_bitmap_cursor_layer = bitmap_layer_create(GRect(90, 125, 10, 15));
	bitmap_layer_set_compositing_mode(s_bitmap_cursor_layer, GCompOpSet);
	bitmap_layer_set_bitmap(s_bitmap_cursor_layer, s_bitmap_cursor);
	layer_add_child(window_layer, bitmap_layer_get_layer(s_bitmap_cursor_layer));
}
Exemple #7
0
static void main_window_load(Window *window) {
  // Get information about the Window
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  

  APP_LOG(APP_LOG_LEVEL_INFO, "Main window loading");
  
  APP_LOG(APP_LOG_LEVEL_INFO, "battery time");

  s_battery_layer = layer_create(GRect(PBL_IF_ROUND_ELSE(0, 20), PBL_IF_ROUND_ELSE(0, 154), PBL_IF_ROUND_ELSE(180, 104), PBL_IF_ROUND_ELSE(180, 2)));
  s_weather_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(117, 120), bounds.size.w, 55));
  s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(52, 46), bounds.size.w, 80));
  s_date_layer = PBL_IF_BW_ELSE(text_layer_create(GRect(1, 2, bounds.size.w, 50)), text_layer_create(GRect(PBL_IF_ROUND_ELSE(42, 1), PBL_IF_ROUND_ELSE(15, 1), PBL_IF_ROUND_ELSE(97, 65), 55)));
  s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30)));
  
  
  int textcolor = persist_read_int(MESSAGE_KEY_TextColor);
  int background = persist_read_int(MESSAGE_KEY_BackgroundColor);
  GColor bg_color = GColorFromHEX(background);
  GColor text_color = GColorFromHEX(textcolor);
  window_set_background_color(s_main_window, bg_color);
  APP_LOG(APP_LOG_LEVEL_INFO, "Text Color is: %d", textcolor);
  APP_LOG(APP_LOG_LEVEL_INFO, "Background Color is: %d", background);
  
  
  // Battery Layer
  layer_set_update_proc(s_battery_layer, battery_update_proc);

  // Add Battery Layer to Window
  layer_add_child(window_get_root_layer(window), s_battery_layer);
  
  

  
  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: celsius");
  
  if (persist_read_bool(MESSAGE_KEY_Celsius)) {
    celsius = persist_read_int(MESSAGE_KEY_Celsius);
  }
  
  /*
  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: customLocation");
  if (persist_read_string(KEY_CUSTOM_LOCATION)) {
    customLocation = persist_read_string(KEY_CUSTOM_LOCATION);
  }*/
  
  APP_LOG(APP_LOG_LEVEL_INFO, "weather time");
  
  
  
  // Weather Layer
  text_layer_set_background_color(s_weather_layer, GColorClear);
  text_layer_set_text_color(s_weather_layer, text_color);
  //text_layer_set_text_color(s_weather_layer, GColorBlack);
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  PBL_IF_BW_ELSE(text_layer_set_text(s_weather_layer, ""), text_layer_set_text(s_weather_layer, "Loading..."));
  s_weather_font = PBL_IF_ROUND_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20)));
  text_layer_set_font(s_weather_layer, s_weather_font);
  
  // Add Weather Layer to Window
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer));

  APP_LOG(APP_LOG_LEVEL_INFO, "time layer");
  
 
  
  
  // Time Layer
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_53));
  text_layer_set_font(s_time_layer, s_time_font);
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, text_color);
  
  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: invert");

  APP_LOG(APP_LOG_LEVEL_INFO, "reading key: 24h");
  

  
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

  // Add Time Layer to Window
  layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
  
  APP_LOG(APP_LOG_LEVEL_INFO, "date time");

  // Date Layer
  s_date_font = PBL_IF_BW_ELSE(fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_20)), fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)));
	text_layer_set_text_color(s_date_layer, text_color);
  //text_layer_set_text_color(s_date_layer, GColorBlack);
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  text_layer_set_font(s_date_layer, s_date_font);

  APP_LOG(APP_LOG_LEVEL_INFO, "updating time");
  
  
  // Add Date Layer to Window
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer));
  
  
  // Create the Bluetooth icon GBitmap
  APP_LOG(APP_LOG_LEVEL_INFO, "Reading Bluetooth color: %d", persist_read_bool(MESSAGE_KEY_Bluetooth));
  if (persist_read_int(MESSAGE_KEY_Bluetooth) == 102) {
    s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON);
  } else {
    s_bt_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ICON_BLACK);
  }
  // Create the BitmapLayer to display the GBitmap
  s_bt_icon_layer = PBL_IF_BW_ELSE(layer_create(GRect(60, 115, 30, 30)), layer_create(GRect(PBL_IF_ROUND_ELSE(75, 62), PBL_IF_ROUND_ELSE(135, 8), 30, 30)));
  layer_set_update_proc(s_bt_icon_layer, layer_update_proc);
  //bitmap_layer_set_bitmap(s_bt_icon_layer, s_bt_icon_bitmap);
  layer_add_child(window_layer, s_bt_icon_layer);
  
  APP_LOG(APP_LOG_LEVEL_INFO, "steps time");

  // Steps Layer
  
  // subscribe to health events
  int goal_num = persist_read_int(MESSAGE_KEY_Step_Goal);
  int steps = persist_read_int(MESSAGE_KEY_Goal_Color);
  GColor steps_color = GColorFromHEX(steps);
  s_num_label = text_layer_create(GRect(PBL_IF_ROUND_ELSE(67, 90), PBL_IF_ROUND_ELSE(37, 1), 50, 45));
  text_layer_set_background_color(s_num_label, GColorClear);
  text_layer_set_text_color(s_num_label, text_color);
  int s_step_count = (int)health_service_sum_today(HealthMetricStepCount);
  if (goal_num == 0 || s_step_count < goal_num) {
    int textcolor = persist_read_int(MESSAGE_KEY_TextColor);
    GColor text_color = GColorFromHEX(textcolor);
    text_layer_set_text_color(s_num_label, text_color);
  }
  else {
    text_layer_set_text_color(s_num_label, steps_color);
  }
  //text_layer_set_text_color(s_num_label, GColorBlack);
  text_layer_set_text_alignment(s_num_label, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentRight));
  text_layer_set_font(s_num_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SF_17)));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_num_label));
  
  if(health_service_events_subscribe(health_handler, NULL)) {
    // force initial steps display
    health_handler(HealthEventMovementUpdate, NULL);
  } else {
    APP_LOG(APP_LOG_LEVEL_ERROR, "Health not available!");
  }
  
 
	
  
  // Show the correct state of the BT connection from the start
  bluetooth_callback(connection_service_peek_pebble_app_connection());


  APP_LOG(APP_LOG_LEVEL_INFO, "Main window loaded");
  
  update_time();
}
Exemple #8
0
static void boardUpdateProc(Layer* this_layer, GContext *ctx) {
  GRect b = layer_get_bounds(this_layer);
  graphics_context_set_antialiased(ctx, 0);

  // Fill grey back (white on BW)
  graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorLightGray, GColorWhite));
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, b, 0, GCornersAll);

  // Frame highlight around currently selected square colours is gray w white highlight, BW is wite w black highight
  graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorDarkGray, GColorWhite));
  graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorWhite, GColorBlack));
  GRect highlightR = GRect(s_cursor.x*PIECE_PIXELS, s_cursor.y*PIECE_PIXELS, PIECE_PIXELS+1, PIECE_PIXELS+1);
  graphics_fill_rect(ctx, highlightR, 0, GCornersAll);
  graphics_draw_rect(ctx, highlightR);

  // Draw all board shapes
  for (int x = 0; x < BOARD_PIECES_X; ++x) {
    for (int y = 0; y < BOARD_PIECES_Y; ++y) {
      int xy = XY(x,y);
      if (s_gameState == kFlashRemoved && (s_pieces[xy].match != kUnmatched || s_pieces[XY(x,y)].exploded == true)) {
        // Highlight squares which have just been matched
        GColor highlight = COLOR_FALLBACK(GColorRed, GColorBlack);
        if (s_pieces[xy].match == kMatchedTwice) highlight = COLOR_FALLBACK(GColorDarkCandyAppleRed, GColorBlack);
        graphics_context_set_fill_color(ctx, highlight);
        graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorBlack, GColorLightGray));
        highlightR = GRect((s_pieces[xy].loc.x/SUB_PIXEL), (s_pieces[xy].loc.y/SUB_PIXEL), PIECE_PIXELS+1, PIECE_PIXELS+1);
        graphics_fill_rect(ctx, highlightR, 0, GCornersAll);
        graphics_draw_rect(ctx, highlightR);
      }
      // Draw the shape itself
      graphics_context_set_fill_color(ctx, COLOURS[ s_pieces[xy].colour ]);
      if (getShape( s_pieces[xy].colour ) != NULL) {
        static const bool bw = PBL_IF_BW_ELSE(true,false);
        if (bw == false && s_pieces[xy].colour == kBlack ) {
          graphics_context_set_stroke_color(ctx, GColorWhite);
        } else if (bw == true
          && (s_pieces[xy].match != kUnmatched || s_pieces[XY(x,y)].exploded == true)
          && COLOURS[ s_pieces[xy].colour ].argb != GColorWhite.argb ) {
          graphics_context_set_stroke_color(ctx, GColorWhite);
        } else {
          graphics_context_set_stroke_color(ctx, GColorBlack);
        }
        gpath_move_to(getShape( s_pieces[xy].colour ), GPoint(s_pieces[xy].loc.x/SUB_PIXEL, s_pieces[xy].loc.y/SUB_PIXEL));
        gpath_draw_filled(ctx, getShape( s_pieces[xy].colour ));
        gpath_draw_outline(ctx, getShape( s_pieces[xy].colour ));
      } else {
        // White rectangle of debug - we should not have the case where we render a NULL square
        graphics_fill_rect(ctx, GRect((s_pieces[xy].loc.x/SUB_PIXEL)+2, (s_pieces[xy].loc.y/SUB_PIXEL)+2, PIECE_PIXELS-3, PIECE_PIXELS-3), 2, GCornersAll);
      }
    }
  }

  // Move Arrows
  if (s_flashArrows == true && s_gameState == kAwaitingDirection) {
    graphics_context_set_fill_color(ctx, GColorWhite);
    for (int d = 0; d < N_CARDINAL; ++d) {
      gpath_move_to(getArrow(d), GPoint(s_cursor.x * PIECE_PIXELS, s_cursor.y * PIECE_PIXELS));
      gpath_draw_filled(ctx, getArrow(d));
      gpath_draw_outline(ctx, getArrow(d));
    }
  }

  // Cursor
  if (s_tiltMode > 0) {
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_context_set_stroke_color(ctx, GColorBlack);
    graphics_fill_circle(ctx, GPoint(s_motionCursor.x/SUB_PIXEL,s_motionCursor.y/SUB_PIXEL), 3);
    graphics_draw_circle(ctx, GPoint(s_motionCursor.x/SUB_PIXEL,s_motionCursor.y/SUB_PIXEL), 3);
  }

  // Next move
  if (s_hintOn && s_availableMove.x != -1 && s_gameState == kIdle && s_hintStatus == true) {
    graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorDarkCandyAppleRed,GColorBlack) );
    graphics_context_set_stroke_width(ctx, 3);
    graphics_draw_circle(ctx, GPoint(s_availableMove.x*PIECE_PIXELS + PIECE_PIXELS/2, s_availableMove.y*PIECE_PIXELS + PIECE_PIXELS/2), PIECE_PIXELS);
    graphics_context_set_stroke_width(ctx, 1);
  }

  // Redo border
  graphics_context_set_stroke_color(ctx, GColorBlack);
  graphics_draw_rect(ctx, b);

}