static void update_time() { time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); static char s_buffer_h[3]; strftime(s_buffer_h, sizeof(s_buffer_h), clock_is_24h_style() ? "%H" : "%I", tick_time); text_layer_set_text(s_timehours_layer, s_buffer_h); static char s_buffer_m[3]; strftime(s_buffer_m, sizeof(s_buffer_m), "%M", tick_time); text_layer_set_text(s_timemins_layer, s_buffer_m); static char s_buffer_ampm[3]; strftime(s_buffer_ampm, sizeof(s_buffer_ampm), clock_is_24h_style() ? "": "%p", tick_time); text_layer_set_text(s_time_ampm_layer, s_buffer_ampm); // Resize to ceneter GSize hoursSize = text_layer_get_content_size(s_timehours_layer); GSize minSize = text_layer_get_content_size(s_timemins_layer); GSize ampmSize = text_layer_get_content_size(s_time_ampm_layer); int combinedWidth = hoursSize.w + minSize.w; int halfWidth = combinedWidth / 2; text_layer_set_size(s_timehours_layer, GSize(xHalf + halfWidth - minSize.w, 90)); text_layer_set_size(s_timemins_layer, GSize(xHalf + halfWidth, 68)); text_layer_set_size(s_time_ampm_layer, GSize(xHalf + halfWidth - (minSize.w - ampmSize.w) + 2, 68)); }
void storyview_init(char *title, char *summary) { window = window_create(); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GRect max_text_bounds = GRect(2, 0, bounds.size.w - 4, 2000); scroll_layer = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(scroll_layer, window); title_layer = text_layer_create(max_text_bounds); text_layer_set_font(title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text(title_layer, title); GSize title_max_size = text_layer_get_content_size(title_layer); text_layer_set_size(title_layer, GSize(title_max_size.w, title_max_size.h + 14)); summary_layer = text_layer_create(GRect(2, title_max_size.h + 14, max_text_bounds.size.w, max_text_bounds.size.h - (title_max_size.h + 14))); text_layer_set_font(summary_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text(summary_layer, summary); GSize summary_max_size = text_layer_get_content_size(summary_layer); text_layer_set_size(summary_layer, GSize(summary_max_size.w, summary_max_size.h + 14)); scroll_layer_set_content_size(scroll_layer, GSize(bounds.size.w, title_max_size.h + 14 + summary_max_size.h + 8)); scroll_layer_add_child(scroll_layer, text_layer_get_layer(title_layer)); scroll_layer_add_child(scroll_layer, text_layer_get_layer(summary_layer)); layer_add_child(window_layer, scroll_layer_get_layer(scroll_layer)); }
void update_rings() { PblTm t; get_time(&t); int hourAngle = ((t.tm_hour % 12) * 30) + (t.tm_min / 2); int minAngle = t.tm_min * 6; static char hour_str[] = "00"; static char minute_str[] = "00"; char *hour_format; if (clock_is_24h_style()) { hour_format = "%k"; } else { hour_format = "%l"; } string_format_time(hour_str, sizeof(hour_str), hour_format, &t); string_format_time(minute_str, sizeof(minute_str), "%M", &t); set_hand_text(&hourText, hourAngle, hour_str, GPoint(0,-55), GSize(26,26)); set_hand_text(&minuteText, minAngle, minute_str, GPoint(0,-24), GSize(18,18)); set_hand_angle(&hourImage, hourAngle, GPoint(0, -55)); set_hand_angle(&minuteImage, minAngle, GPoint(0, -24)); }
void thread_window_load(Window *window) { struct ThreadData *thread = GetSelectedThread(); thread_scroll_layer = scroll_layer_create(window_frame); scroll_layer_set_shadow_hidden(thread_scroll_layer, true); scroll_layer_set_click_config_onto_window(thread_scroll_layer, window); scroll_layer_set_content_size(thread_scroll_layer, GSize(window_frame.size.w, 0)); scroll_layer_set_content_offset(thread_scroll_layer, GPoint(0, 0), false); ScrollLayerCallbacks scrollOverride = { .click_config_provider = &thread_click_config, .content_offset_changed_handler = &thread_offset_changed_handler }; scroll_layer_set_callbacks(thread_scroll_layer, scrollOverride); thread_title_layer = layer_create(GRect(0, 0, window_frame.size.w, 22)); layer_set_update_proc(thread_title_layer, thread_title_layer_update_proc); scroll_layer_add_child(thread_scroll_layer, thread_title_layer); layer_add_child(window_get_root_layer(window), scroll_layer_get_layer(thread_scroll_layer)); thread_view_comments_layer = text_layer_create(GRect(0, 0, window_frame.size.w, LOAD_COMMENTS_HEIGHT)); text_layer_set_text(thread_view_comments_layer, "View Comments"); text_layer_set_font(thread_view_comments_layer, GetBiggerFont()); text_layer_set_text_alignment(thread_view_comments_layer, GTextAlignmentCenter); scroll_layer_add_child(thread_scroll_layer, text_layer_get_layer(thread_view_comments_layer)); thread_inverter_hidden = true; thread_inverter_layer = inverter_layer_create(GRect(0, 0, window_frame.size.w, LOAD_COMMENTS_HEIGHT)); layer_set_hidden(inverter_layer_get_layer(thread_inverter_layer), true); scroll_layer_add_child(thread_scroll_layer, inverter_layer_get_layer(thread_inverter_layer)); if(thread->type == 1) { // we are an image thread_body_layer = NULL; thread_bitmap_layer = bitmap_layer_create(GRect(0, 22, window_frame.size.w, window_frame.size.h)); scroll_layer_add_child(thread_scroll_layer, bitmap_layer_get_layer(thread_bitmap_layer)); scroll_layer_set_content_size(thread_scroll_layer, GSize(window_frame.size.w, 22 + window_frame.size.h + 10)); thread_update_comments_position(); } else { //current_thread.image = NULL; thread_bitmap_layer = NULL; thread_body_layer = text_layer_create(GRect(0, 22, window_frame.size.w, 10000)); text_layer_set_font(thread_body_layer, GetFont()); scroll_layer_add_child(thread_scroll_layer, text_layer_get_layer(thread_body_layer)); } }
static void update_sleep_bar_buffer() { HealthMetric sleep_metric = HealthMetricSleepSeconds; HealthMetric deep_sleep_metric = HealthMetricSleepRestfulSeconds; static double seconds_in_8_hours = 28000; static double pebble_time_pixel_width = 144; double s_sleep_pixel_length = (double)health_service_sum_today(sleep_metric) / seconds_in_8_hours * pebble_time_pixel_width; double s_deep_sleep_pixel_length = (double)health_service_sum_today(deep_sleep_metric) / seconds_in_8_hours * pebble_time_pixel_width; text_layer_set_size(s_sleep_bar_layer, GSize(s_sleep_pixel_length, 6)); text_layer_set_size(s_deep_sleep_bar_layer, GSize(s_deep_sleep_pixel_length, 6)); }
void set_layout(Window *window, Layout *layout) { Layer *root_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(root_layer); GPoint center = grect_center_point(&window_bounds); GSize layer_size = PBL_IF_ROUND_ELSE(GSize(24, 130), GSize(35,160)); int layer_y_pos = center.y - (layer_size.h / 2); layout->hour_tens = cylinder_layer_new(root_layer, GPoint(center.x - (layer_size.w * 2), layer_y_pos), layer_size); layout->hour_ones = cylinder_layer_new(root_layer, GPoint(center.x - layer_size.w, layer_y_pos), layer_size); layout->minute_tens = cylinder_layer_new(root_layer, GPoint(center.x, layer_y_pos), layer_size); layout->minute_ones = cylinder_layer_new(root_layer, GPoint(center.x + layer_size.w, layer_y_pos), layer_size); }
void update_round_light_layer(Layer *layer, GContext *ctx) { // set metrics const GSize digit = {24, 26}; const uint8_t col_pad = 25, row_pad = 33, start_col = 81; const uint8_t col1 = 1, col2 = col1 + col_pad, col3 = col2 + col_pad, col4 = col3 + col_pad + 3, col5 = col4 + col_pad, col6 = col5 + col_pad + 1, col7 = col6 + col_pad; const int16_t row0 = 9, row1 = row0 - row_pad, row2 = row1 - row_pad, row3 = row2 - row_pad, row4 = row3 - row_pad, row5 = row4 - row_pad, row6 = row5 - row_pad, row7 = row6 - row_pad, row8 = row7 - row_pad, row9 = row8 - row_pad, row10 = row9 - row_pad, row11 = row10 - row_pad, row12 = row11 - row_pad; const GSize hour_plate = GSize(80, 524); const GSize min_plate = GSize(100, 524); const GRect hour_mark = (GRect) {{col3, 77}, .size = digit};
void rot_bitmap_layer_update_func (Layer* l,GContext* ctx) { ROT_BITMAP_GET; GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,l->frame.size.w,l->frame.size.h); SDL_Surface* sur=createSurface(rotbitmap->bitmap->bounds.size.w,rotbitmap->bitmap->bounds.size.h); SDL_FillRect(sur,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,rotbitmap->bitmap,rect,sur); double angle=(double)rotbitmap->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(sur,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(sur); GPoint offset=getPivotRotationOffset(rotbitmap->bitmap->bounds.size,GSize(rotated->w,rotated->h),rotbitmap->src_ic,angle); rotbitmap->dest_ic.x=l->frame.size.w/2; //TODO: Verify this rotbitmap->dest_ic.y=l->frame.size.h/2; setTopOffset(topOffset); if (rotbitmap->corner_clip_color!=GColorClear) { graphics_context_set_fill_color(ctx,rotbitmap->corner_clip_color); graphics_fill_rect(ctx,GRect(0,0,l->frame.size.w,l->frame.size.h),0,0); } graphics_context_set_compositing_mode (ctx,rotbitmap->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(rotbitmap->dest_ic.x-offset.x,rotbitmap->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
/** * Initializates the GUI Elements */ void about_window_load (Window *window) { GRect windowBounds = layer_get_frame(ui.windowLayer); GRect titleBounds = GRect(0, 0, windowBounds.size.w, 30); ui.titleLayer = text_layer_create(titleBounds); text_layer_set_text_color(ui.titleLayer, GColorWhite); text_layer_set_background_color(ui.titleLayer, GColorBlack); text_layer_set_text(ui.titleLayer, "About"); text_layer_set_font(ui.titleLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_text_alignment(ui.titleLayer, GTextAlignmentCenter); layer_add_child(ui.windowLayer, text_layer_get_layer(ui.titleLayer)); // Creates the Scroll GRect scrollBounds = GRect(0, 30, windowBounds.size.w, (windowBounds.size.h - 30)); ui.scroll = scroll_layer_create(scrollBounds); scroll_layer_set_click_config_onto_window(ui.scroll, ui.window); layer_add_child(ui.windowLayer, scroll_layer_get_layer(ui.scroll)); GRect textBounds = GRect(0, 0, scrollBounds.size.w, 2000); ui.textLayer = text_layer_create(textBounds); text_layer_set_text_color(ui.textLayer, GColorBlack); text_layer_set_background_color(ui.textLayer, GColorClear); text_layer_set_text(ui.textLayer, "Developer:\nYago Carballo ([email protected])\n\nGame By...\nameiga 2014\n\n"); text_layer_set_font(ui.textLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(ui.textLayer, GTextAlignmentCenter); GSize max_size = text_layer_get_content_size(ui.textLayer); text_layer_set_size(ui.textLayer, max_size); scroll_layer_set_content_size(ui.scroll, GSize(windowBounds.size.w, max_size.h + 5)); scroll_layer_add_child(ui.scroll, text_layer_get_layer(ui.textLayer)); }
// Setup the scroll layer on window load // We do this here in order to be able to get the max used text size static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 2000); // Initialize the scroll layer scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(scroll_layer, window); // Initialize the text layer text_layer = text_layer_create(max_text_bounds); text_layer_set_text(text_layer, scroll_text); // Change the font to a nice readable one // This is system font; you can inspect pebble_fonts.h for all system fonts // or you can take a look at feature_custom_font to add your own font text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(text_layer); text_layer_set_size(text_layer, max_size); scroll_layer_set_content_size(scroll_layer, GSize(bounds.size.w, max_size.h + vert_scroll_text_padding)); // Add the layers for display scroll_layer_add_child(scroll_layer, text_layer_get_layer(text_layer)); // The inverter layer will highlight some text inverter_layer = inverter_layer_create(GRect(0, 28, bounds.size.w, 28)); scroll_layer_add_child(scroll_layer, inverter_layer_get_layer(inverter_layer)); layer_add_child(window_layer, scroll_layer_get_layer(scroll_layer)); }
static void ring_layer_update(Layer *layer, GContext *ctx) { if (data_loaded) { const GRect entire_screen = GRect(0, 0, 180, 180); draw_circle(ctx, entire_screen, GColorWhite, 20, 360); graphics_context_set_stroke_color(ctx, GColorOxfordBlue); graphics_context_set_stroke_width(ctx, 10); const GRect time_orbit = GRect(10, 10, 160, 160); int degree_icon = degreeify(hour, minute); int degree_rise = degreeify(hour_rise, minute_rise); int degree_set = degreeify(hour_set, minute_set); GBitmap *icon = degree_icon >= degree_set && degree_icon <= degree_rise ? moon : sun; const GRect icon_space = grect_centered_from_polar( time_orbit, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(degree_icon), GSize(18, 18) ); graphics_context_set_compositing_mode(ctx, GCompOpSet); graphics_draw_bitmap_in_rect(ctx, icon, icon_space); } }
void scroll_text_layer_set_text(ScrollTextLayer* layer, char* text) { if (NULL == layer) { return; } text_layer_set_size(layer->text_layer, GSize(layer_get_bounds(scroll_layer_get_layer(layer->scroll_layer)).size.w - (PADDING_X * 2), MAX_HEIGHT)); text_layer_set_text(layer->text_layer, text); scroll_text_layer_update(layer); }
void setup_message_layer() { int header_height = get_header_height(); int text_height = get_text_height(); setup_header(header_height); layer_set_frame(text_layer_get_layer(messagetext_layer), GRect(0, header_height, 144, text_height)); scroll_layer_set_content_offset(message_layer, GPoint(0, 0), false); scroll_layer_set_content_size(message_layer, GSize(144, header_height + text_height)); layer_set_hidden(scroll_layer_get_layer(message_layer), false); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_title_layer = stats_window_common_create_title(bounds, "SETS DURATION"); s_scroll_layer = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(s_scroll_layer, window); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, bounds.size.h * 1.7)); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_title_layer)); MatchStatistics score_detail= match_statistics_get(); // score_detail.set_duration[0] = 45* 60; // score_detail.set_duration[1] = 53 * 60; // score_detail.set_duration[2] = 33 * 60; // score_detail.set_duration[3] = 62 * 60; // score_detail.set_duration[4] = 39 * 60; int start_from_y =PBL_IF_ROUND_ELSE(40, 30); int box_h = 40; float every_y = box_h +2; for (int i = 0; i < 5; ++i) { int hours = score_detail.set_duration[i] / 3600; int minutes = (score_detail.set_duration[i] / 60) % 60; int seconds = score_detail.set_duration[i] % 60; snprintf(buffer_sets_time[i], sizeof(buffer_sets_time[i]), "%.2d:%.2d:%.2d\n", hours, minutes, seconds); APP_LOG(APP_LOG_LEVEL_DEBUG, "*** window_load *** set %d lasted %d seconds", i, (int)score_detail.set_duration[i]); int padding = PBL_IF_ROUND_ELSE(64, 28); int box_x = padding / 2 ; int box_w = bounds.size.w - padding; s_sets_time_layer[i] = stats_window_common_create_layer( GRect( box_x, start_from_y + (i * every_y), box_w, box_h), buffer_sets_time[i]); int num_x = PBL_IF_ROUND_ELSE(18, 2);; int num_y = start_from_y + (i * every_y) + (box_h / 4); snprintf(buffer_sets_num[i], sizeof(buffer_sets_num[i]), "%d\n", i + 1); s_sets_num_layer[i] =create_set_num_layer(GRect(num_x, num_y, 13, 20), buffer_sets_num[i]); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_sets_time_layer[i])); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_sets_num_layer[i])); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); } }
void scroll_text_layer_set_text(ScrollTextLayer* layer, char* text) { if (layer == NULL) { return; } text_layer_set_text(layer->text_layer, text); GSize max_size = text_layer_get_content_size(layer->text_layer); text_layer_set_size(layer->text_layer, max_size); GRect bounds = layer_get_bounds(scroll_layer_get_layer(layer->scroll_layer)); scroll_layer_set_content_size(layer->scroll_layer, GSize(bounds.size.w, max_size.h + (PADDING_Y * 3))); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); s_icon_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ICONO_PRINCIPAL); GRect bitmap_bounds = gbitmap_get_bounds(s_icon_bitmap); s_fondo_layer = bitmap_layer_create(GRect(0, 0, 144, 40)); bitmap_layer_set_background_color(s_fondo_layer, COLOR_CABECERA); layer_add_child(window_layer, bitmap_layer_get_layer(s_fondo_layer)); s_scroll_layer = scroll_layer_create(GRect(10, 10 + bitmap_bounds.size.h + 5, 124, 168 - (10 + bitmap_bounds.size.h + 10))); scroll_layer_set_click_config_onto_window(s_scroll_layer, window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, 120, 2000); s_label_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_label_layer, i_lineas); text_layer_set_text_color(s_label_layer, COLOR_TEXTO_CUERPO); text_layer_set_background_color(s_label_layer, GColorClear); if (i_total_lineas> 3) text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); else text_layer_set_font(s_label_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); //layer_add_child(window_layer, text_layer_get_layer(s_label_layer)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_label_layer); text_layer_set_size(s_label_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); scroll_layer_set_shadow_hidden(s_scroll_layer, true); scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_label_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); // CAPA DE LA PARADA s_titulo_layer = text_layer_create(GRect(38, 0 , 101, 40)); text_layer_set_text(s_titulo_layer, string_parada); text_layer_set_background_color(s_titulo_layer, GColorClear ); text_layer_set_text_color(s_titulo_layer, COLOR_TEXTO_CABECERA ); text_layer_set_text_alignment(s_titulo_layer, GTextAlignmentCenter); text_layer_set_font(s_titulo_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_titulo_layer)); // FIN DE CAPA DE LA PARADA // CAPA DEL ICONO DEL BUS s_icon_layer = bitmap_layer_create(GRect(5, 5, bitmap_bounds.size.w, bitmap_bounds.size.h)); bitmap_layer_set_bitmap(s_icon_layer, s_icon_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_icon_layer)); // FIN DE LA CAPA }
// Setup the scroll layer on window load // We do this here in order to be able to get the max used text size static void traveltime_details_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(10, 90, bounds.size.w - 20, 60); GRect from_text_bounds = GRect(10, 10, bounds.size.w - 20, 30); GRect name_text_bounds = GRect(10, 30, bounds.size.w - 20, 40); GRect bkg_text_bounds = GRect(0, 70, bounds.size.w, bounds.size.h); // Initialize the scroll layer traveltime_details_scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(traveltime_details_scroll_layer, window); // Initialize the text layers traveltime_from_text_layer = text_layer_create(from_text_bounds); text_layer_set_text(traveltime_from_text_layer, "Depuis"); text_layer_set_font(traveltime_from_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); traveltime_name_text_layer = text_layer_create(name_text_bounds); text_layer_set_text(traveltime_name_text_layer, traveltimes_menu_items[current_traveltime_idx].title); text_layer_set_font(traveltime_name_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); traveltime_details_text_layer = text_layer_create(max_text_bounds); text_layer_set_text(traveltime_details_text_layer, traveltimes_menu_items[current_traveltime_idx].subtitle); text_layer_set_font(traveltime_details_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(traveltime_details_text_layer); //text_layer_set_size(traveltime_details_text_layer, max_size); scroll_layer_set_content_size(traveltime_details_scroll_layer, GSize(bounds.size.w, max_size.h + 104)); traveltime_bkg_text_layer = text_layer_create(bkg_text_bounds); #ifdef PBL_COLOR text_layer_set_background_color(traveltime_bkg_text_layer, GColorBlack); text_layer_set_background_color(traveltime_from_text_layer, GColorIslamicGreen); text_layer_set_background_color(traveltime_name_text_layer, GColorIslamicGreen); text_layer_set_background_color(traveltime_details_text_layer, GColorBlack); text_layer_set_text_color(traveltime_from_text_layer, GColorWhite); text_layer_set_text_color(traveltime_name_text_layer, GColorWhite); text_layer_set_text_color(traveltime_details_text_layer, GColorYellow); #endif // Add the layers for display scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_bkg_text_layer)); scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_from_text_layer)); scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_name_text_layer)); scroll_layer_add_child(traveltime_details_scroll_layer, text_layer_get_layer(traveltime_details_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(traveltime_details_scroll_layer)); }
void prv_draw_pupil(GContext *ctx, const GRect *eye_rect, const GPoint *perimeter_point) { const int16_t pupil_radius = 3; const GSize pupil_size = GSize(pupil_radius * 2, pupil_radius * 2); const GRect pupil_container_rect = grect_inset((*eye_rect), GEdgeInsets(2 * pupil_radius)); const GPoint pupil_center = grect_center_point(&pupil_container_rect); const int32_t pupil_angle = atan2_lookup(perimeter_point->y - pupil_center.y, perimeter_point->x - pupil_center.x) + DEG_TO_TRIGANGLE(90); const GRect pupil_rect = grect_centered_from_polar(pupil_container_rect, GOvalScaleModeFitCircle, pupil_angle, pupil_size); graphics_fill_radial(ctx, pupil_rect, GOvalScaleModeFitCircle, pupil_radius, 0, TRIG_MAX_ANGLE); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 2000); // Initialize the scroll layer s_scroll_layer = scroll_layer_create(GRect(0, 55, bounds.size.w, 98)); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(s_scroll_layer, window); // Initialize the social messages scrolling text layer s_text_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_text_layer, s_scroll_text); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_text_layer); text_layer_set_size(s_text_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); // Add the layers for display scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); // Set the text of the application name layer text_layer_app_name = text_layer_create(GRect(0, 0, bounds.size.w, 20)); text_layer_set_text(text_layer_app_name, "UbiSwim.org"); text_layer_set_text_alignment(text_layer_app_name, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer_app_name)); // Set the text of the social likes layer text_layer_likes = text_layer_create(GRect(0, 20, bounds.size.w, 40)); text_layer_set_font(text_layer_likes, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text(text_layer_likes, "Likes:"); text_layer_set_text_alignment(text_layer_likes, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer_likes)); // Set the text of the info layer text_layer_msg = text_layer_create(GRect(0, 150, bounds.size.w, 30)); text_layer_set_text(text_layer_msg, "U:Prev M:Like D:Next"); text_layer_set_text_alignment(text_layer_msg, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(text_layer_msg)); // Set the click config provider for the scrolling text layer scroll_layer_set_callbacks(s_scroll_layer, (ScrollLayerCallbacks) { .click_config_provider = &click_config_provider_updown });
static void detail_window_load(Window *window) { #ifdef PBL_COLOR window_colorize(window); #endif // set up text layer Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); int16_t content_width = bounds.size.w-10; // Initialize the text layers GRect max_title_bounds = GRect(5, 0, content_width, 2000); s_detail_title_text_layer = detail_text_layer_create(max_title_bounds, s_detail_title, true); GSize title_size = text_layer_get_content_size(s_detail_title_text_layer); title_size.w = content_width; GRect max_text_bounds = GRect(5, title_size.h+2, content_width, 2000); s_detail_text_layer = detail_text_layer_create(max_text_bounds, s_detail_text, false); // Initialize the scroll layer s_detail_scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(s_detail_scroll_layer, window); // Add the layers for display scroll_layer_add_child(s_detail_scroll_layer, text_layer_get_layer(s_detail_text_layer)); scroll_layer_add_child(s_detail_scroll_layer, text_layer_get_layer(s_detail_title_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_detail_scroll_layer)); // Trim text layer and scroll content to fit text box // GSize title_size = text_layer_get_content_size(s_detail_title_text_layer); title_size.w = content_width; title_size.h += 5; GSize text_size = text_layer_get_content_size(s_detail_text_layer); text_size.h += title_size.h; text_size.w = content_width; text_layer_set_size(s_detail_title_text_layer, title_size); text_layer_set_size(s_detail_text_layer, text_size); scroll_layer_set_content_size(s_detail_scroll_layer, GSize(bounds.size.w, title_size.h + text_size.h)); }
static void history_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); history_scroller = scroll_layer_create(bounds); scroll_layer_set_click_config_onto_window(history_scroller, window); int items = current_history_batch * HISTORY_BATCH_SIZE + history[current_history_batch].last_event + 1; int width = 142; int margin = (bounds.size.w - width)/2; GSize max_size = GSize(bounds.size.w, (items + 9) * 19); // font size is 18, 5 newlines before and 4 after history_layer = text_layer_create(GRect(margin, 0, width, max_size.h)); if ((current_history_batch == 0) && (history[0].last_event < 0)) { strcpy(history_text, "No history recorded."); } else { // int history_events = current_history_batch * HISTORY_BATCH_SIZE + history[current_history_batch].last_event + 1; // APP_LOG(APP_LOG_LEVEL_DEBUG, "%d history events", history_events); strcpy(history_text, "\n\n\n\n\n"); for (int b=current_history_batch; b>=0; b--) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "Processing batch %d", b); for (int e=history[b].last_event; e>=0; e--) { // APP_LOG(APP_LOG_LEVEL_DEBUG, "Feeling %d at %d (%d/%d)", history[b].mood[e], (int) history[b].event_time[e], e, b); struct tm *lt = localtime(&history[b].event_time[e]); strftime(timestr, sizeof(timestr), "%V %a %k:%M", lt); snprintf(event_text, sizeof(event_text), "%s %s\n", timestr, Moods[history[b].mood[e]]); strncat(history_text, event_text, sizeof(event_text)); } } } strncat(history_text, "\n\n\n\n", 5); text_layer_set_text(history_layer, history_text); text_layer_set_font(history_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18)); text_layer_set_overflow_mode(history_layer, GTextOverflowModeWordWrap); text_layer_set_text_color(history_layer, GColorBlack); text_layer_set_background_color(history_layer, GColorWhite); max_size = text_layer_get_content_size(history_layer); max_size.w = bounds.size.w; text_layer_set_size(history_layer, max_size); scroll_layer_set_content_size(history_scroller, max_size); scroll_layer_add_child(history_scroller, text_layer_get_layer(history_layer)); scroll_layer_set_content_offset(history_scroller, GPoint(0, 40), true); layer_add_child(window_layer, scroll_layer_get_layer(history_scroller)); }
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)); }
static void render(GContext *ctx) { #ifdef BENCHMARK uint16_t start = time_ms(NULL, NULL); #endif pge_isometric_begin(ctx); // Tiles for(int z = 0; z < GRID_DEPTH; z++) { for(int y = 0; y < GRID_HEIGHT; y++) { for(int x = 0; x < GRID_WIDTH; x++) { block_render(s_block_array[vec2i(Vec3(x, y, z))]); } } } for(int i = 0; i < MAX_CLOUDS; i++) { cloud_render(s_cloud_array[i]); } // Selection switch(s_input_mode) { case MODE_X: pge_isometric_draw_rect(Vec3(0, s_cursor.y * BLOCK_SIZE, (s_cursor.z + 1) * BLOCK_SIZE), GSize(GRID_WIDTH * BLOCK_SIZE, BLOCK_SIZE), GColorWhite); break; case MODE_Y: pge_isometric_draw_rect(Vec3(s_cursor.x * BLOCK_SIZE, 0, (s_cursor.z + 1) * BLOCK_SIZE), GSize(BLOCK_SIZE, GRID_HEIGHT * BLOCK_SIZE), GColorWhite); break; case MODE_Z: pge_isometric_draw_box(Vec3(s_cursor.x * BLOCK_SIZE, s_cursor.y * BLOCK_SIZE, BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), (GRID_DEPTH - 1) * BLOCK_SIZE, GColorWhite); break; } pge_isometric_draw_box(Vec3(s_cursor.x * BLOCK_SIZE, s_cursor.y * BLOCK_SIZE, s_cursor.z * BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), BLOCK_SIZE, GColorRed); // Box pge_isometric_draw_box(Vec3(0, 0, 0), GSize(BLOCK_SIZE * GRID_WIDTH, BLOCK_SIZE * GRID_HEIGHT), SKY_HEIGHT, GColorLightGray); pge_isometric_finish(ctx); #ifdef BENCHMARK uint16_t finish = time_ms(NULL, NULL); APP_LOG(APP_LOG_LEVEL_INFO, "Frame time: %d ms", (int)finish - start); #endif }
static void inbox_received_callback(DictionaryIterator *iterator, void *context) { Tuple *tuple = dict_find(iterator, 0); if (!tuple) { APP_LOG(APP_LOG_LEVEL_ERROR, "The tuple was missing!"); return; } s_speaking_enabled = true; APP_LOG(APP_LOG_LEVEL_INFO, "Got message: %s", tuple->value->cstring); snprintf(s_defn_buffer, sizeof(s_defn_buffer), "%s", tuple->value->cstring); //where the word and def show up GSize size = graphics_text_layout_get_content_size(s_defn_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(0, 0, 134, 1000), GTextOverflowModeWordWrap, GTextAlignmentCenter); layer_set_frame((Layer *)s_def_layer, GRect(5, 40, 134, size.h)); scroll_layer_set_content_size(s_scroll_layer, GSize(144, 50 + size.h)); text_layer_set_text(s_word_layer, s_last_text_buffer); text_layer_set_text(s_def_layer, s_defn_buffer); window_stack_push(s_def_window, true); }
void rotbmp_layer_update_func (Layer* me,GContext* ctx) { GPoint topOffset=getTopOffset (); setTopOffset(GPoint(0,0)); GRect rect=GRect(0,0,me->frame.size.w,me->frame.size.h); RotBitmapLayer* bitmapLayer=(RotBitmapLayer*)me; SDL_Surface* bitmap=createSurface(bitmapLayer->bitmap->bounds.size.w,bitmapLayer->bitmap->bounds.size.h); SDL_FillRect(bitmap,0,0); graphics_context_set_compositing_mode (ctx,GCompOpAssign); graphics_draw_bitmap_in_rect_to (ctx,bitmapLayer->bitmap,rect,bitmap); double angle=(double)bitmapLayer->rotation/TRIG_MAX_ANGLE*360.0; SDL_Surface* rotated=rotozoomSurface(bitmap,-angle,1.0,SMOOTHING_OFF); SDL_FreeSurface(bitmap); GPoint offset=getPivotRotationOffset(bitmapLayer->bitmap->bounds.size,GSize(rotated->w,rotated->h),bitmapLayer->src_ic,angle); setTopOffset(topOffset); graphics_context_set_compositing_mode (ctx,bitmapLayer->compositing_mode); graphics_draw_surface_in_rect (ctx,rotated,GRect(bitmapLayer->dest_ic.x-offset.x,bitmapLayer->dest_ic.y-offset.y,rotated->w,rotated->h)); SDL_FreeSurface(rotated); }
void set_new_stat_text(void) { const holomesh_tag_t* tag = &g_holomesh->tags.ptr[ (++g_current_stat) % g_holomesh->tags.size ]; const char* stat = g_holomesh->string_table.ptr[tag->name_string].str.ptr; GRect currentFrame = layer_get_bounds(text_layer_get_layer(infoTextLayer)); currentFrame.size = GSize(c_viewportWidth, c_viewportHeight); currentFrame.size = graphics_text_layout_get_content_size( stat, g_font_info, currentFrame, 0, GTextAlignmentLeft); layer_set_bounds(text_layer_get_layer(infoTextLayer), currentFrame); text_layer_set_text(infoTextLayer, stat); }
static void battery_handler(BatteryChargeState charge_state) { int16_t value = 0; value = (122*charge_state.charge_percent)/100+10; layer_set_hidden(bitmap_layer_get_layer(s_battery_layer), !charge_state.is_charging || charge_state.charge_percent == 100); #ifdef PBL_COLOR if(charge_state.charge_percent<=25){ s_connection_bar_color = GColorDarkCandyAppleRed; text_layer_set_background_color(s_connection_bg_layer, GColorBulgarianRose); }else{ if(!charge_state.is_charging){ s_connection_bar_color = GColorCyan; text_layer_set_background_color(s_connection_bg_layer, GColorTiffanyBlue); }else{ s_connection_bar_color = GColorChromeYellow; text_layer_set_background_color(s_connection_bg_layer, GColorWindsorTan); } } #endif text_layer_set_size(s_connection_layer, GSize(value, 18)); }
static void parseStringIntoArray(char *passedString, char a_delim[]) { char *tmp = passedString; //char a_delim[] = ","; // Find the number of delimiters int delimNum = 1; // Increment from 1 for the trailing string while (*tmp) { if (*a_delim == *tmp) { delimNum++; } tmp++; } //dispVal(delimNum, "Number of unique strings:"); if (delimNum > CHECKLIST_MAX_ITEMS) { delimNum = CHECKLIST_MAX_ITEMS; // Reset the number of items to show only the maximum amount } numItems = delimNum; //APP_LOG(APP_LOG_LEVEL_INFO, "Parsing string, heap usage: %d", (int)heap_bytes_used()); //checklistItems = iso_realloc(checklistItems, delimNum * sizeof(char*) * MAXIMUM_LIST_ITEM_SIZE); if (checklistItems == NULL) { APP_LOG(APP_LOG_LEVEL_ERROR, "The reallocation of memory for checklistItems failed, most probably a lack of available heap."); } // Reallocate enough memory for the checklist item array, returns null if failed and will error out. //memset(checklistItems, 0, sizeof(checklistItems)); // Reset all bytes in checklist items array to zero value tmp = passedString; int i = 0; for (int j = 0; j < delimNum; j++) { i = 0; while (*a_delim != *tmp && *tmp) { memcpy(&checklistItems[j][i], tmp, sizeof(char*)); // The address of the checklist item array increments by row every maximum list size (in characters) i++; tmp++; } tmp++; // Increment to get passed the delimiter that stopped the while loop checklistItems[j][i] = 0; //APP_LOG(APP_LOG_LEVEL_INFO, "%s", checklistItems[j]); } sizeOfContent = CHECK_ICON_START + ((numItems + PBL_IF_RECT_ELSE(0,2)) * CHECK_ICON_HEIGHT); // Add two extra items when using a round face to create an infinite scroll scroll_layer_set_content_size(s_checklist_scroll, GSize(144, sizeOfContent)); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect max_text_bounds = GRect(0, 0, bounds.size.w, 2000); // Initialize the scroll layer s_scroll_layer = scroll_layer_create(bounds); // This binds the scroll layer to the window so that up and down map to scrolling // You may use scroll_layer_set_callbacks to add or override interactivity scroll_layer_set_click_config_onto_window(s_scroll_layer, window); // Initialize the text layer s_text_layer = text_layer_create(max_text_bounds); text_layer_set_text(s_text_layer, s_scroll_text); // Change the font to a nice readable one // This is system font; you can inspect pebble_fonts.h for all system fonts // or you can take a look at feature_custom_font to add your own font text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_background_color(s_text_layer, GColorClear); #if defined(PBL_PLATFORM_APLITE) text_layer_set_text_color(s_text_layer, GColorBlack); #else text_layer_set_text_color(s_text_layer, GColorWhite); #endif // Trim text layer and scroll content to fit text box GSize max_size = text_layer_get_content_size(s_text_layer); text_layer_set_size(s_text_layer, max_size); scroll_layer_set_content_size(s_scroll_layer, GSize(bounds.size.w, max_size.h + 4)); // Add the layers for display scroll_layer_add_child(s_scroll_layer, text_layer_get_layer(s_text_layer)); layer_add_child(window_layer, scroll_layer_get_layer(s_scroll_layer)); }
void instruction_window_load(Window *window) { // set size variables for instructions short size = get_instruction_size(instruction_type); short height = get_instruction_height(instruction_type); ResHandle rh = get_resource_handle(instruction_type); // allocate text holder and load resource instruction_text_ptr = malloc(size*sizeof(char)); reset_text(); resource_load(rh, (uint8_t *)instruction_text_ptr, size*sizeof(char)); // get bounds of the window and set bounds of text Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); GRect text_bounds = GRect(0, 0, bounds.size.w, height); // create layers s_instruction_scroll_layer = scroll_layer_create(bounds); s_instruction_text_layer = text_layer_create(text_bounds); // setup scroll view scroll_layer_set_content_size(s_instruction_scroll_layer, GSize(SCROLL_WIDTH,height)); scroll_layer_set_click_config_onto_window(s_instruction_scroll_layer, s_instruction_window); // setup text view text_layer_set_text(s_instruction_text_layer, instruction_text_ptr); text_layer_set_text_alignment(s_instruction_text_layer, GTextAlignmentCenter); // add children layer_add_child(window_get_root_layer(s_instruction_window), scroll_layer_get_layer(s_instruction_scroll_layer)); scroll_layer_add_child(s_instruction_scroll_layer, text_layer_get_layer(s_instruction_text_layer)); scroll_layer_set_content_offset(s_instruction_scroll_layer, GPoint(0,0), false); // free memory free(instruction_text_ptr); }