Пример #1
0
static void window_load(Window *window) {
  SprinklesAppData *data = window_get_user_data(window);

  Layer *root_layer = window_get_root_layer(window);
  const GRect root_layer_bounds = layer_get_bounds(root_layer);

  data->homer_bitmap = gbitmap_create_with_resource(RESOURCE_ID_HOMER);

  GRect homer_bitmap_layer_frame = root_layer_bounds;
  homer_bitmap_layer_frame.size = gbitmap_get_bounds(data->homer_bitmap).size;
  grect_align(&homer_bitmap_layer_frame, &root_layer_bounds, GAlignBottom, true /* clip */);

  data->homer_layer = bitmap_layer_create(homer_bitmap_layer_frame);
  bitmap_layer_set_bitmap(data->homer_layer, data->homer_bitmap);
  bitmap_layer_set_compositing_mode(data->homer_layer, GCompOpSet);
  layer_add_child(root_layer, bitmap_layer_get_layer(data->homer_layer));

  const int16_t date_layer_width = PBL_IF_RECT_ELSE(41, 58);
  const int16_t date_layer_height = 17;
  GRect date_layer_frame = (GRect) { .size = GSize(date_layer_width, date_layer_height) };
  grect_align(&date_layer_frame, &root_layer_bounds, GAlignRight, true /* clip */);
  data->date_layer = layer_create(date_layer_frame);
  layer_set_update_proc(data->date_layer, prv_date_layer_update_proc);
  layer_add_child(root_layer, data->date_layer);

  data->homer_eyes_layer = layer_create(homer_bitmap_layer_frame);
  layer_set_update_proc(data->homer_eyes_layer, prv_homer_eyes_layer_update_proc);
  layer_add_child(root_layer, data->homer_eyes_layer);

  data->donut_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DONUT);

  data->hands_layer = layer_create(root_layer_bounds);
  layer_set_update_proc(data->hands_layer, prv_hands_layer_update_proc);
  layer_add_child(root_layer, data->hands_layer);

  const time_t current_time = time(NULL);
  struct tm *current_time_tm = localtime(&current_time);
  prv_tick_timer_service_handler(current_time_tm, SECOND_UNIT);
}

static void window_unload(Window *window) {
  SprinklesAppData *data = window_get_user_data(window);

  layer_destroy(data->hands_layer);
  layer_destroy(data->homer_eyes_layer);
  layer_destroy(data->date_layer);

  gbitmap_destroy(data->donut_bitmap);

  bitmap_layer_destroy(data->homer_layer);
  gbitmap_destroy(data->homer_bitmap);

  window_destroy(window);
}
Пример #2
0
static void main_window_load(Window *window) {
  // Grab user data 
  MainMenuData *data = window_get_user_data(window);
  
  // Icons for main menu
  data->icons[0] = gbitmap_create_with_resource(RESOURCE_ID_TELEVISION);
  data->icons[1] = gbitmap_create_with_resource (RESOURCE_ID_BOOK);
  
  // Categories for main menu
  data->categories[0] = "Anime";
  data->categories[1] = "Manga";
  
  // Setup main menu
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  data->layer = menu_layer_create(bounds);

  menu_layer_set_callbacks(data->layer, data, (MenuLayerCallbacks) {
    .get_num_rows = menu_layer_get_num_rows_callback,
    .get_num_sections = menu_layer_get_num_sections_callback,
    .get_header_height = menu_get_header_height_callback,
    .draw_header = menu_draw_header_callback,
    .draw_row = menu_layer_draw_row_callback,
    .get_cell_height = menu_layer_get_cell_height_callback,
    .select_click = menu_layer_select_click_callback
  });
Пример #3
0
// This initializes the menu upon window load
void replywindow_appear(Window *window) {
    
    ReplyWindow * rw = (ReplyWindow*)window_get_user_data(window);
    
    
    Layer * mainWindowLayer = window_get_root_layer(window);
    
    static char titleText[40];
#ifdef PBL_ROUND
    if ((rw->replyTo!=NULL) && (strlen(rw->replyTo) > 3)) {
        snprintf(titleText,40,"%s", rw->replyTo);
    } else {
        snprintf(titleText,40,"Reply %s", rw->replyTo);        
    }
#else
    snprintf(titleText,40,"Reply %s", rw->replyTo);
#endif
    rw->title_layer = title_layer_create(GRect(0,0,PEBBLE_WIDTH,TITLE_HEIGHT), titleText, ICON_CHAT);
    
    // Create the menu layer
#ifdef PBL_ROUND
    rw->menu_layer = menu_layer_create(GRect(0,0,PEBBLE_WIDTH,PEBBLE_HEIGHT));
#else
    rw->menu_layer = menu_layer_create(GRect(0,TITLE_HEIGHT,PEBBLE_WIDTH,PEBBLE_HEIGHT-TITLE_HEIGHT));
#endif
    // Set all the callbacks for the menu layer
    menu_layer_set_callbacks(rw->menu_layer, rw, (MenuLayerCallbacks){
        .get_num_sections = reply_get_num_sections_callback,
        .get_num_rows = reply_get_num_rows_callback,
        .draw_row = reply_draw_row_callback,
        .select_click = reply_select_callback,
        .get_cell_height = reply_get_cell_height_callback,
    });
Пример #4
0
void window_load(Window *window) {
    updates = 0;

    Menu* menu = window_get_user_data(window);

    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_frame(window_layer);

#ifdef PBL_SDK_3
    GRect menu_bounds = GRect(
            bounds.origin.x,
            bounds.origin.y + STATUS_BAR_LAYER_HEIGHT,
            bounds.size.w,
            bounds.size.h - STATUS_BAR_LAYER_HEIGHT
    );
    menu->layer = menu_layer_create(menu_bounds);
    menu->load_layer = bitmap_layer_create(menu_bounds);
#else
    menu->layer = menu_layer_create(bounds);
    menu->load_layer = bitmap_layer_create(bounds);
#endif

    menu_layer_set_callbacks(menu->layer, menu, (MenuLayerCallbacks){
            .get_num_sections = menu_get_num_sections_callback,
            .get_num_rows = menu_get_num_rows_callback,
            .get_header_height = menu_get_header_height_callback,
            .draw_header = menu_draw_header_callback,
            .draw_row = menu_draw_row_callback,
            .select_click = menu->callbacks.select_click,
            .selection_changed = selection_changed_callback,
    });
Пример #5
0
void calendar_unload(Window* wnd)
{
    RootData* data = window_get_user_data(wnd);
    if(data->graphicsLayer)
        layer_destroy(data->graphicsLayer);
    free(data);
}
Пример #6
0
static void time_window_unload(Window* window)
{
    TimeWindow* time_window = window_get_user_data(window);
    
    if (time_window)
    {
        time_window_destroy(time_window);
    }
}
Пример #7
0
void MenuDeinit(Window *window)
{
	MenuWindow *menuWindow = window_get_user_data(window);
	if(menuWindow)
	{
		menuWindow->inUse = false;
		menuWindow->menu = NULL;
	}
	window_destroy(window);
}
Пример #8
0
void layer_update_callback(Layer *layer, GContext *ctx) {
  SimplySplash *self = (SimplySplash*) window_get_user_data((Window*) layer);

  GRect frame = layer_get_frame(layer);

#if SPLASH_LOGO
  graphics_draw_bitmap_centered(ctx, self->image, frame);
#else
  graphics_draw_bitmap_in_rect(ctx, self->image, frame);
#endif
}
Пример #9
0
static SimplyWindow *get_top_simply_window(Simply *simply) {
  Window *base_window = window_stack_get_top_window();
  if (!base_window) {
    return NULL;
  }
  SimplyWindow *window = window_get_user_data(base_window);
  if (!window || (void*) window == simply->splash) {
    return NULL;
  }
  return window;
}
static void prv_window_unload(Window *window) {
  GoalStarConfigurationWindowData *data = window_get_user_data(window);

  if (data) {
    // TODO replace with SDK NumberWindow once it gets updated to support larger numbers
    goal_star_number_window_destroy(data->number_window);
    menu_layer_destroy(data->menu_layer);
    text_layer_destroy(data->title_layer);
    window_destroy(data->window);
  }

  free(data);
}
static void prv_window_unload(Window *window) {
  GoalStarGoalEventWindowData *data = window_get_user_data(window);

  if (data) {
    if (data->goal_reached_sequence_timer) {
      app_timer_cancel(data->goal_reached_sequence_timer);
    }
    layer_destroy(data->goal_reached_sequence_layer);
    gdraw_command_sequence_destroy(data->goal_reached_sequence);
    window_destroy(data->window);
  }

  free(data);
}
Пример #12
0
//appear interface
static void appear(Window *window) 
{
  // Get a tm structure and update time
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);
  update_time(tick_time);
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  
  //get data for player name
  PlayerScore * ps = (PlayerScore *)window_get_user_data(window);
  if(ps != NULL)
  {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "appear of stockScore PlayerScore=%p player=%d games=%d points=%d",
          ps, ps->p, ps->score.games, ps->score.points);
    
    if(ps->p == Player1)
    {
      score_p1.games = score_p1.games + ps->score.games; 
      score_p1.points = score_p1.points + ps->score.points;
      if(ps->score.games >= 1){
        score_p2.points = 0;
      }
      if(score_p1.points >= 3){
        score_p1.games = score_p1.games + (score_p1.points / 3);
        score_p1.points = score_p1.points % 3;
        score_p2.points = 0;
      }
    }
    else if(ps->p == Player2)
    {
      score_p2.games = score_p2.games + ps->score.games; 
      score_p2.points = score_p2.points + ps->score.points;
      if(ps->score.games >= 1){
        score_p1.points = 0;
      }
      if(score_p2.points >= 3){
        score_p2.games = score_p2.games + (score_p2.points / 3);
        score_p2.points = score_p2.points % 3;
        score_p1.points = 0;
      }
    }
    APP_LOG(APP_LOG_LEVEL_INFO, "new values Player1 games=%d points=%d Player2 games=%d points=%d",
          score_p1.games, score_p1.points, score_p2.games, score_p2.points);
  }  
  
  update_score();
}
Пример #13
0
void MenuAppear(Window *window)
{
	int i;
	bool setSelected = false;
		
	MenuWindow *menuWindow = window_get_user_data(window);
	if(menuWindow)
	{
		SetCurrentMenu(menuWindow->menu);
	}
	WindowAppear(window);
	if(!currentMenuDef)
	{
		HideAllMenuLayers();
		SetMenuDescription(NULL);
		return;
	}

	currentMenuDef->currentSelection = -1;
	for(i = 0; i < MAX_MENU_ENTRIES; ++i)
	{
		MenuEntry *entry = &currentMenuDef->menuEntries[i];
		if(MenuEntryIsActive(entry))
		{
			ShowMenuLayer(i, entry->text);
			if(setSelected)
			{
				SetMenuHighlight(i, false);
			}
			else
			{
				SetMenuHighlight(i, true);
				setSelected = true;
				currentMenuDef->currentSelection = i;
				SetMenuDescription(entry->description);
			}
		}
		else
		{
			HideMenuLayer(i);
		}
	}

	if(menuWindow && menuWindow->menu && menuWindow->menu->mainImageId != -1)
	{
		LoadMainBmpImage(window, menuWindow->menu->mainImageId, menuWindow->menu->useFloorImage ? menuWindow->menu->floorImageId : -1);
	}
}
static void prv_goal_reached_sequence_layer_update_proc(Layer *layer, GContext *ctx) {
  GoalStarGoalEventWindowData *data = window_get_user_data(layer_get_window(layer));
  const GRect layer_bounds = layer_get_bounds(layer);

  GRect sequence_frame = (GRect) {
    .size = gdraw_command_sequence_get_bounds_size(data->goal_reached_sequence),
  };
  grect_align(&sequence_frame, &layer_bounds, GAlignCenter, true /* clip */);
  sequence_frame.origin.y -= sequence_frame.origin.y / 4;

  GDrawCommandFrame *frame = gdraw_command_sequence_get_frame_by_index(
    data->goal_reached_sequence, data->goal_reached_sequence_frame_index);
  if (frame) {
    gdraw_command_frame_draw(ctx, data->goal_reached_sequence, frame, sequence_frame.origin);
  }

  const uint32_t num_frames = gdraw_command_sequence_get_num_frames(data->goal_reached_sequence);
  if (++data->goal_reached_sequence_frame_index >= num_frames) {
    app_timer_cancel(data->goal_reached_sequence_timer);
    const uint32_t timeout_ms = goal_star_configuration_get_goal_event_timeout_ms();
    if (timeout_ms) {
      data->goal_reached_sequence_timer = app_timer_register(timeout_ms,
                                                             prv_goal_reached_wait_timer_handler,
                                                             data);
    }
  }

  char text[GOAL_STAR_CONFIGURATION_STRING_BUFFER_LENGTH] = {0};
  goal_star_configuration_get_goal_summary_string(text);
  graphics_context_set_text_color(ctx, GColorBlack);
  const GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
  const int16_t font_height = 24;
  const GRect text_frame = GRect(0, sequence_frame.origin.y + sequence_frame.size.h,
                                 layer_bounds.size.w, font_height);
  graphics_draw_text(ctx, text, font, text_frame, GTextOverflowModeTrailingEllipsis,
                     GTextAlignmentCenter, NULL);
}

static void prv_goal_reached_sequence_timer_handler(void *context) {
  GoalStarGoalEventWindowData *data = context;
  if (data) {
    layer_mark_dirty(data->goal_reached_sequence_layer);
    data->goal_reached_sequence_timer = app_timer_register(ANIMATION_FRAME_INTERVAL_MS,
                                                           prv_goal_reached_sequence_timer_handler,
                                                           data);
  }
}
Пример #15
0
static void
text_entry_button_handler(struct widget *widget,
			  struct input *input, uint32_t time,
			  uint32_t button,
			  enum wl_pointer_button_state state, void *data)
{
	struct text_entry *entry = data;
	struct rectangle allocation;
	struct editor *editor;
	int32_t x, y;
	uint32_t result;

	widget_get_allocation(entry->widget, &allocation);
	input_get_position(input, &x, &y);

	x -= allocation.x + text_offset_left;
	y -= allocation.y + text_offset_left;

	editor = window_get_user_data(entry->window);

	if (button == BTN_LEFT) {
		entry->button_pressed = (state == WL_POINTER_BUTTON_STATE_PRESSED);

		if (state == WL_POINTER_BUTTON_STATE_PRESSED)
			input_grab(input, entry->widget, button);
		else
			input_ungrab(input);
	}

	if (text_entry_has_preedit(entry)) {
		result = text_entry_try_invoke_preedit_action(entry, x, y, button, state);

		if (result)
			return;
	}

	if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
		struct wl_seat *seat = input_get_seat(input);

		text_entry_activate(entry, seat);
		editor->active_entry = entry;

		text_entry_set_cursor_position(entry, x, y, true);
	}
}
Пример #16
0
// Load report window, expects a message (string buffer) to be attached via window_set_user_data()
void message_window_load(Window *window) {

  // Get information about the Window
  Layer *window_layer = window_get_root_layer(window);
  GRect window_bounds = layer_get_bounds(window_layer);

  message_text_layer = text_layer_create(
    GRect(0, (window_bounds.size.h/2)-20, window_bounds.size.w, window_bounds.size.h));

  text_layer_set_text_alignment(message_text_layer, GTextAlignmentCenter);
  text_layer_set_text_color(message_text_layer, GColorBlack);
  text_layer_set_background_color(message_text_layer, GColorWhite);
  text_layer_set_font(message_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(message_text_layer, GTextAlignmentCenter);
  text_layer_set_text(message_text_layer, window_get_user_data(window));

  layer_add_child(window_layer, text_layer_get_layer(message_text_layer));
}
static void prv_window_load(Window *window) {
  GoalStarConfigurationWindowData *data = window_get_user_data(window);
  if (!data) {
    return;
  }

  Layer *window_root_layer = window_get_root_layer(window);
  const GRect window_root_layer_bounds = layer_get_bounds(window_root_layer);

  const GRect title_layer_frame = (GRect) {
#if PBL_RECT
    // Adjust for font cap offset
    .origin = GPoint(0, -2),
#endif
    .size = GSize(window_root_layer_bounds.size.w, STATUS_BAR_LAYER_HEIGHT),
  };
  data->title_layer = text_layer_create(title_layer_frame);
  TextLayer *title_layer = data->title_layer;
  text_layer_set_text_alignment(title_layer, GTextAlignmentCenter);
  text_layer_set_overflow_mode(title_layer, GTextOverflowModeTrailingEllipsis);
  text_layer_set_background_color(title_layer, GColorClear);
  text_layer_set_text_color(title_layer, GColorBlack);
  text_layer_set_font(title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text(title_layer, PBL_IF_RECT_ELSE("Goal Star Configuration", "Config"));
  layer_add_child(window_root_layer, text_layer_get_layer(title_layer));

  const GEdgeInsets menu_layer_insets = PBL_IF_RECT_ELSE(GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0, 0),
                                                         GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0));
  const GRect menu_layer_frame = grect_inset(window_root_layer_bounds, menu_layer_insets);
  data->menu_layer = menu_layer_create(menu_layer_frame);
  MenuLayer *menu_layer = data->menu_layer;
  menu_layer_set_callbacks(menu_layer, data, (MenuLayerCallbacks) {
    .get_num_rows = prv_menu_layer_get_num_rows_callback,
    .draw_row = prv_menu_layer_draw_row_callback,
#if PBL_ROUND
    .get_cell_height = prv_menu_layer_get_cell_height,
#endif
    .select_click = prv_menu_layer_select_callback,
  });
  menu_layer_set_normal_colors(menu_layer, GColorWhite, GColorBlack);
  menu_layer_set_highlight_colors(menu_layer, GColorCobaltBlue, GColorWhite);
  menu_layer_set_click_config_onto_window(menu_layer, window);
  layer_add_child(window_root_layer, menu_layer_get_layer(menu_layer));
}
Пример #18
0
static void
text_entry_button_handler(struct widget *widget,
			  struct input *input, uint32_t time,
			  uint32_t button,
			  enum wl_pointer_button_state state, void *data)
{
	struct text_entry *entry = data;
	struct rectangle allocation;
	struct editor *editor;
	int32_t x, y;

	widget_get_allocation(entry->widget, &allocation);
	input_get_position(input, &x, &y);

	editor = window_get_user_data(entry->window);

	if (button != BTN_LEFT) {
		return;
	}

	text_entry_set_cursor_position(entry,
				       x - allocation.x - text_offset_left,
				       y - allocation.y - text_offset_left);

	if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
		struct wl_seat *seat = input_get_seat(input);

		text_entry_activate(entry, seat);
		editor->active_entry = entry;

		text_entry_set_anchor_position(entry,
					       x - allocation.x - text_offset_left,
					       y - allocation.y - text_offset_left);

		widget_set_motion_handler(entry->widget, text_entry_motion_handler);
	} else {
		widget_set_motion_handler(entry->widget, NULL);
	}
}
Пример #19
0
// Context in this case will be the window pointer.
void calendar_click_single(ClickRecognizerRef recogniser, void* context)
{
    ButtonId button = click_recognizer_get_button_id(recogniser);
    Window* wnd = (Window*)context;
    RootData* data = window_get_user_data(wnd);
    
    switch(button)
    {
    case BUTTON_ID_UP:
        data->curTime -= 7 * 86400;
        break;
    case BUTTON_ID_DOWN:
        data->curTime += 7 * 86400;
        break;
    case BUTTON_ID_SELECT:
        data->curTime += 86400;
        break;
    default:
        return; // Don't need to mark as dirty.
    }
    
    layer_mark_dirty(data->graphicsLayer);
}
Пример #20
0
//! Destroy layers, window data, and window.
//! @param window A pointer to the window the unload was called from
static void prv_window_unload_handler(Window *window) {
  // window properties
  WindowData *data = (WindowData*)window_get_user_data(window);
  // check user data
  if (data) {
    // unregister callbacks
    app_message_deregister_callbacks();
    // destroy images
    gbitmap_destroy(data->config_bmp);
    gbitmap_destroy(data->grid_1_bmp);
    gbitmap_destroy(data->grid_2_bmp);
    // free data
    stick_figure_destroy(data->stick_figure);
    drawing_button_destroy(data->button);
    layer_destroy(data->draw_layer);
    window_destroy(window);
    free(data);
    return;
  }

  // error handling
  window_destroy(window);
  APP_LOG(APP_LOG_LEVEL_ERROR, "Error: Tried to free NULL WindowData pointer.");
}
static void prv_window_load(Window *window) {
  GoalStarGoalEventWindowData *data = window_get_user_data(window);
  if (!data) {
    return;
  }

  Layer *window_root_layer = window_get_root_layer(window);
  const GRect window_root_layer_bounds = layer_get_bounds(window_root_layer);

  data->goal_reached_sequence =
    gdraw_command_sequence_create_with_resource(RESOURCE_ID_GOAL_REACHED);

  data->goal_reached_sequence_layer = layer_create(window_root_layer_bounds);
  Layer *goal_reached_sequence_layer = data->goal_reached_sequence_layer;
  layer_set_update_proc(goal_reached_sequence_layer, prv_goal_reached_sequence_layer_update_proc);
  layer_add_child(window_root_layer, goal_reached_sequence_layer);

  data->goal_reached_sequence_timer = app_timer_register(ANIMATION_FRAME_INTERVAL_MS,
                                                         prv_goal_reached_sequence_timer_handler,
                                                         data);

  prv_vibrate();
  light_enable_interaction();
}
Пример #22
0
static void pop_window(bool animated) {
  window_stack_pop(animated);
  set_current_window(window_get_user_data(window_stack_get_top_window()));
}
Пример #23
0
static void prv_window_load(Window *window) {
  GoalStarNumberWindow *number_window = window_get_user_data(window);
  if (!number_window) {
    return;
  }

  Layer *window_root_layer = window_get_root_layer(window);
  const GRect window_root_layer_bounds = layer_get_bounds(window_root_layer);

  number_window->checkmark_icon = gbitmap_create_with_resource(RESOURCE_ID_CHECKMARK);
  number_window->up_icon = gbitmap_create_with_resource(RESOURCE_ID_UP);
  number_window->down_icon = gbitmap_create_with_resource(RESOURCE_ID_DOWN);

  const GTextAlignment text_layer_alignment = GTextAlignmentRight;
  const GTextOverflowMode text_layer_overflow_mode = GTextOverflowModeTrailingEllipsis;

  const GFont label_text_font = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  const int16_t label_text_font_height = 14;

  const int16_t value_text_max_font_height = 36;

  const int16_t horizontal_padding = 5;
  GRect text_container_frame = grect_inset(window_root_layer_bounds,
                                           GEdgeInsets(0, ACTION_BAR_WIDTH + horizontal_padding,
                                                       0, horizontal_padding));
  text_container_frame.size.h = label_text_font_height + value_text_max_font_height;
  grect_align(&text_container_frame, &window_root_layer_bounds, GAlignLeft, true /* clip */);
  text_container_frame.origin.y -= gbitmap_get_bounds(number_window->checkmark_icon).size.h / 2;

  GRect label_text_layer_frame = (GRect) {
    .size = GSize(text_container_frame.size.w, label_text_font_height),
  };
  grect_align(&label_text_layer_frame, &text_container_frame, GAlignTop, true /* clip */);
  number_window->label_text_layer = text_layer_create(label_text_layer_frame);
  TextLayer *label_text_layer = number_window->label_text_layer;
  text_layer_set_text(label_text_layer, number_window->label);
  text_layer_set_text_color(label_text_layer, GColorBlack);
  text_layer_set_background_color(label_text_layer, GColorClear);
  text_layer_set_font(label_text_layer, label_text_font);
  text_layer_set_overflow_mode(label_text_layer, text_layer_overflow_mode);
  text_layer_set_text_alignment(label_text_layer, text_layer_alignment);
  layer_add_child(window_root_layer, text_layer_get_layer(label_text_layer));

  GRect value_text_layer_frame = (GRect) {
    .size = GSize(text_container_frame.size.w, value_text_max_font_height),
  };
  grect_align(&value_text_layer_frame, &text_container_frame, GAlignBottom, true /* clip */);
  number_window->value_text_layer = text_layer_create(value_text_layer_frame);
  TextLayer *value_text_layer = number_window->value_text_layer;
  prv_update_value_text_layer(number_window);
  text_layer_set_text_color(value_text_layer, GColorBlack);
  text_layer_set_background_color(value_text_layer, GColorClear);
  text_layer_set_overflow_mode(value_text_layer, text_layer_overflow_mode);
  text_layer_set_text_alignment(value_text_layer, text_layer_alignment);
  layer_add_child(window_root_layer, text_layer_get_layer(value_text_layer));

  number_window->action_bar_layer = action_bar_layer_create();
  ActionBarLayer *action_bar_layer = number_window->action_bar_layer;
  action_bar_layer_set_click_config_provider(action_bar_layer, prv_click_config_provider);
  action_bar_layer_set_context(action_bar_layer, number_window);
  action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_SELECT, number_window->checkmark_icon);
  action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_UP, number_window->up_icon);
  action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_DOWN, number_window->down_icon);
  action_bar_layer_add_to_window(action_bar_layer, window);
}

static void prv_window_unload(Window *window) {
  GoalStarNumberWindow *number_window = window_get_user_data(window);
  if (number_window) {
    text_layer_destroy(number_window->label_text_layer);
    text_layer_destroy(number_window->value_text_layer);
    action_bar_layer_destroy(number_window->action_bar_layer);
    gbitmap_destroy(number_window->checkmark_icon);
    gbitmap_destroy(number_window->up_icon);
    gbitmap_destroy(number_window->down_icon);
  }
}

static void prv_goal_star_number_window_init(GoalStarNumberWindow *number_window, const char *label,
                                             GoalStarNumberWindowCallbacks callbacks,
                                             void *callback_context) {
  if (!number_window) {
    return;
  }

  *number_window = (GoalStarNumberWindow) {
    .label = label,
    .value = 0,
    .min = GOAL_STAR_NUMBER_WINDOW_MIN,
    .max = GOAL_STAR_NUMBER_WINDOW_MAX,
    .step_size = 1,
    .callbacks = callbacks,
    .callback_context = callback_context,
  };

  number_window->window = window_create();
  Window *window = number_window->window;
  window_set_window_handlers(window, (WindowHandlers) {
    .load = prv_window_load,
    .unload = prv_window_unload,
  });
  window_set_background_color(window, GColorLightGray);
  window_set_user_data(window, number_window);
}

GoalStarNumberWindow *goal_star_number_window_create(const char *label,
                                                     GoalStarNumberWindowCallbacks callbacks,
                                                     void *callback_context) {
  GoalStarNumberWindow *number_window = calloc(1, sizeof(*number_window));
  prv_goal_star_number_window_init(number_window, label, callbacks, callback_context);
  return number_window;
}
Пример #24
0
static MyWindow *findMyWindow(Window *w) {
  MyWindow *mw = (MyWindow *)window_get_user_data(w);
  return mw;
}
Пример #25
0
void calendar_single_draw(Layer* layer, GContext* context, int16_t offset)
{    
    // Get the current date
    RootData* data = window_get_user_data(layer_get_window(layer));
    time_t t = data->curTime;
    struct tm* localTime = localtime(&t);
    char month[20];
    strftime(month, 20, "%B %Y", localTime);
    
    if(data->days_in_use_valid.month != (unsigned int)localTime->tm_mon+1 || data->days_in_use_valid.year != (unsigned int)(localTime->tm_year + 1900))
    {
        APP_LOG(APP_LOG_LEVEL_INFO, "Requesting new data. %d %d -> %d %d", data->days_in_use_valid.month, data->days_in_use_valid.year, localTime->tm_mon, localTime->tm_year);
        int rv = 0;
        rv = devinterface_get_days_used(localTime->tm_mon, localTime->tm_year, daysused_returned, data);
        if(rv != DEV_STAT_OK)
            APP_LOG(APP_LOG_LEVEL_WARNING, "devinterface_get_days_used failed %d", rv);
    }
        
    // Get the first day of the month (Mon-Sun)
    // Get the current day and day of week
    int curDay = localTime->tm_mday;
    int dow = localTime->tm_wday;
    
    // What's the offset into dow?
    // Ignoring weeks, this will give us the number of days
    // since the first of the month
    int curDowOffset = (curDay - 1 + WEEK_START_OFFSET) % 7;
    
    // We then subtract that from the current day of the week
    // which will yield the dow of the first day of the month.
    dow -= curDowOffset;
    if(dow < 0)
        dow += 7;
    
    // Get the number of days to draw
    int days_month = days_in_month(localTime->tm_mon + 1, localTime->tm_year + 1900);
    
    // How many weeks do we need to show?
    // How many days are there, including the leadin?
    int totalSlots = (days_month + dow);
    int lines = totalSlots / 7;
    
    // I'm not resorting to the FPU. Check if it had a fractional part
    if(lines * 7 != totalSlots)
        lines++;
    
    // Create the bounding box for the period
    GRect contextBound = layer_get_frame(layer);
    GRect textBounding = contextBound;
    textBounding.origin.y += offset + MONTHPANE_Y_OFFSET;
    textBounding.size.h = MONTHPANE_HEIGHT;
    
    // Put up the current period
    graphics_draw_text(context, month, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), textBounding, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL);
    
    // Compute the height of the calendar box
    int calHeight = contextBound.size.h - CALENDARPANE_TOP - CALENDARPANE_Y_MARGIN;
    int calWidth = contextBound.size.w - (CALENDARPANE_X_MARGIN*2);
    
    // Draw the calendar box
    // Top line
    graphics_draw_line(context, 
                       (GPoint){CALENDARPANE_X_MARGIN, CALENDARPANE_TOP + offset}, 
                       (GPoint){CALENDARPANE_X_MARGIN + calWidth, CALENDARPANE_TOP + offset});
    
    // Bottom line
    graphics_draw_line(context, 
                       (GPoint){CALENDARPANE_X_MARGIN, CALENDARPANE_TOP + calHeight + offset}, 
                       (GPoint){CALENDARPANE_X_MARGIN + calWidth, CALENDARPANE_TOP + calHeight + offset});
    
    // Left line
    graphics_draw_line(context,
                      (GPoint){CALENDARPANE_X_MARGIN, CALENDARPANE_TOP + offset},
                      (GPoint){CALENDARPANE_X_MARGIN, CALENDARPANE_TOP + offset + calHeight});
    
    // Right line
    graphics_draw_line(context,
                      (GPoint){CALENDARPANE_X_MARGIN + calWidth, CALENDARPANE_TOP + offset},
                      (GPoint){CALENDARPANE_X_MARGIN + calWidth, CALENDARPANE_TOP + offset + calHeight});
    
    // And now the vertical subdivisions. There needs to be 7.
    int vertSubDiv = calWidth / 7;
    for(int i = 1; i < 7; i++)
    {
        graphics_draw_line(context,
                          (GPoint){CALENDARPANE_X_MARGIN + vertSubDiv*i, CALENDARPANE_TOP + offset},
                          (GPoint){CALENDARPANE_X_MARGIN + vertSubDiv*i, CALENDARPANE_TOP + offset + calHeight});
    }
    
    // And now the horizontal subdivisions.
    int horizSubDiv = calHeight / lines;
    for(int i = 1; i < lines; i++)
    {
        graphics_draw_line(context,
                           (GPoint){CALENDARPANE_X_MARGIN, CALENDARPANE_TOP + offset + horizSubDiv*i},
                           (GPoint){CALENDARPANE_X_MARGIN + calWidth, CALENDARPANE_TOP + offset + horizSubDiv*i});
    }
    
    // Now draw the days
    for(int day = 1; day <= days_month; day++)
    {
        int x = (day-1+dow) % 7;
        int y = (day-1+dow) / 7;
        char dayStr[3];
        snprintf(dayStr, 3, "%d", day);
        
        // Is this the current day?
        if(day == localTime->tm_mday)
        {
            // Paint it white
            GRect dayRectFill;
            dayRectFill.origin.x = (x * vertSubDiv) + CALENDARPANE_X_MARGIN;
            dayRectFill.origin.y = (y * horizSubDiv) + CALENDARPANE_TOP + offset;
            dayRectFill.size.h = horizSubDiv;
            dayRectFill.size.w = vertSubDiv;
            graphics_context_set_fill_color(context, GColorWhite);
            graphics_context_set_text_color(context, GColorBlack);
            graphics_fill_rect(context, dayRectFill, 0, GCornerNone);
        }
        
        GRect dayRect;
        dayRect.origin.x = (x * vertSubDiv) + CALENDARPANE_X_MARGIN + CALENDARPANE_NUMBER_X_PAD;
        dayRect.origin.y = (y * horizSubDiv) + CALENDARPANE_TOP + offset;
        dayRect.size.h = horizSubDiv;
        dayRect.size.w = vertSubDiv;
        
        if(data->days_in_use_valid.month == (unsigned int)localTime->tm_mon+1 && data->days_in_use_valid.year == (unsigned int)(localTime->tm_year + 1900))
        {
            if(data->days_in_use & (1 << (day - 1)))
                graphics_draw_text(context, dayStr, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), dayRect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
            else
                graphics_draw_text(context, dayStr, fonts_get_system_font(FONT_KEY_GOTHIC_14), dayRect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        }
        else
        {
            graphics_draw_text(context, dayStr, fonts_get_system_font(FONT_KEY_GOTHIC_14), dayRect, GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL);
        }
            
        if(day == localTime->tm_mday)
        {
            graphics_context_set_fill_color(context, GColorBlack);
            graphics_context_set_text_color(context, GColorWhite);
        }
    }
}
Пример #26
0
static void window_load(Window *window) {
  SimplySplash *self = window_get_user_data(window);

  self->image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_LOGO_SPLASH);
}
Пример #27
0
static void window_disappear(Window *window) {
  SimplySplash *self = window_get_user_data(window);
  bool animated = false;
  window_stack_remove(self->window, animated);
  simply_splash_destroy(self);
}