Esempio n. 1
0
void handle_init(void) {

  // WINDOW //
  mWindow = window_create();
  if (mWindow == NULL) {
      return;
  }
  window_stack_push(mWindow, true /* Animated */);
  mWindowLayer = window_get_root_layer(mWindow);
  window_set_background_color(mWindow, GColorWhite);
  
  // BACKGROUND //
  mBackgroundLayer = layer_create(layer_get_frame(mWindowLayer));
  layer_add_child(mWindowLayer, mBackgroundLayer);
  layer_set_update_proc(mBackgroundLayer, update_background_callback);
	
	
	
  //BATTERY_ICONS
  battery_image = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_100);
  GRect frame4 = (GRect) {
    .origin = { .x = 50, .y = 82 },
    .size = battery_image->bounds.size
  };

  battery_image_layer = bitmap_layer_create(frame4);
  bitmap_layer_set_bitmap(battery_image_layer, battery_image);
  layer_add_child(mWindowLayer, bitmap_layer_get_layer(battery_image_layer));

  // FONTS //
	//ResHandle res_d = resource_get_handle(RESOURCE_ID_SMALL_26);
	ResHandle res_t = resource_get_handle(RESOURCE_ID_BIG_52);
	ResHandle res_temp = resource_get_handle(RESOURCE_ID_MEDIUM_34);
	//ResHandle res_hl = resource_get_handle(RESOURCE_ID_SMALL_22);
  
	//mDateFont = fonts_load_custom_font(res_d);
	mTimeFont = fonts_load_custom_font(res_t);
	mTemperatureFont = fonts_load_custom_font(res_temp);
	//mHighLowFont = fonts_load_custom_font(res_hl);
  
  // TIME LAYER //  
  mTimeLayer = layer_create(layer_get_frame(mWindowLayer));
  layer_add_child(mWindowLayer, mTimeLayer);
  
  // TIME HOUR LAYER //
  mTimeHourLayer = text_layer_create(TIME_HOUR_FRAME);  
	text_layer_set_background_color(mTimeHourLayer, GColorClear);
  text_layer_set_text_color(mTimeHourLayer, GColorBlack);
	text_layer_set_font(mTimeHourLayer, mTimeFont);
	text_layer_set_text_alignment(mTimeHourLayer, GTextAlignmentRight);
	layer_add_child(mTimeLayer, text_layer_get_layer(mTimeHourLayer));
  
  // TIME SEPARATOR LAYER //
  mTimeSeparatorLayer = text_layer_create(TIME_SEP_FRAME);  
	text_layer_set_background_color(mTimeSeparatorLayer, GColorClear);
  text_layer_set_text_color(mTimeSeparatorLayer, GColorBlack);
	text_layer_set_font(mTimeSeparatorLayer, mTimeFont);
	text_layer_set_text_alignment(mTimeSeparatorLayer, GTextAlignmentCenter);
  text_layer_set_text(mTimeSeparatorLayer, ":");
	layer_add_child(mTimeLayer, text_layer_get_layer(mTimeSeparatorLayer));
  
  // TIME MINUTES LAYER //
  mTimeMinutesLayer = text_layer_create(TIME_MIN_FRAME);  
	text_layer_set_background_color(mTimeMinutesLayer, GColorClear);
  text_layer_set_text_color(mTimeMinutesLayer, GColorBlack);
	text_layer_set_font(mTimeMinutesLayer, mTimeFont);
	text_layer_set_text_alignment(mTimeMinutesLayer, GTextAlignmentLeft);
	layer_add_child(mTimeLayer, text_layer_get_layer(mTimeMinutesLayer));  

	// DATE LAYER //
	mDateLayer = text_layer_create(DATE_FRAME);  
	text_layer_set_background_color(mDateLayer, GColorClear);
	text_layer_set_text_color(mDateLayer, GColorBlack);
	text_layer_set_font(mDateLayer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));//mDateFont);
	text_layer_set_text_alignment(mDateLayer, GTextAlignmentCenter);
	layer_add_child(mWindowLayer, text_layer_get_layer(mDateLayer)); 
  	
  // WEATHER ICON //
  mWeatherIconLayer = bitmap_layer_create(WEATHER_ICON_FRAME);
  layer_add_child(mWindowLayer, bitmap_layer_get_layer(mWeatherIconLayer));
  
	// TEMPERATURE //
  mTemperatureLayer = text_layer_create(WEATHER_TEMP_FRAME);  
	text_layer_set_background_color(mTemperatureLayer, GColorClear);
  text_layer_set_text_color(mTemperatureLayer, GColorBlack);
	text_layer_set_font(mTemperatureLayer, mTemperatureFont); //fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); //
	text_layer_set_text_alignment(mTemperatureLayer, GTextAlignmentCenter);
	layer_add_child(mWindowLayer, text_layer_get_layer(mTemperatureLayer));

	// HIGHLOW //
  mHighLowLayer = text_layer_create(WEATHER_HL_FRAME);  
	text_layer_set_background_color(mHighLowLayer, GColorClear);
  text_layer_set_text_color(mHighLowLayer, GColorBlack);
	text_layer_set_font(mHighLowLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); //mHighLowFont);
	text_layer_set_text_alignment(mHighLowLayer, GTextAlignmentCenter);
	layer_add_child(mWindowLayer, text_layer_get_layer(mHighLowLayer));

	weather_set_loading();

  app_message_init();

  time_t now = time(NULL);
  struct tm *tick_time = localtime(&now);  

  mInitialMinute = (tick_time->tm_min % FREQUENCY_MINUTES);

  handle_tick(tick_time, DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT);
  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);
  
  bluetooth_connection_service_subscribe(bluetooth_connection_callback);
	
  update_battery(battery_state_service_peek());
  battery_state_service_subscribe(&update_battery);
}
static void window_load(Window *window) {
   
  /*
  //Setup BT Layer
  bt_layer = text_layer_create(GRect(5, 5, 144, 30));
  text_layer_set_font(bt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  if(bluetooth_connection_service_peek() == true)
  {
    text_layer_set_text(bt_layer, "BT: CONNECTED");
  }
  else
  {
    text_layer_set_text(bt_layer, "BT: DISCONNECTED");
  }
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(bt_layer));*/

  
  
        // Although we already defined NUM_FIRST_MENU_ITEMS, you can define
        // an int as such to easily change the order of menu items later
        int num_a_items = 0;

        // This is an example of how you'd set a simple menu item
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        // You should give each menu item a title and callback
        .title = "Chambre",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };
        // The menu items appear in the order saved in the menu items array
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        .title = "Cuisine",
        // You can also give menu items a subtitle
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        .title = "Bureau",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        // This is how you would give a menu item an icon
        //  .icon = menu_icon_image,
        };
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        // You should give each menu item a title and callback
        .title = "Salle de bain",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };
        first_menu_items[num_a_items++] = (SimpleMenuItem){
        // You should give each menu item a title and callback
        .title = "TV",
        .subtitle = "Sélection",
        .callback = menu_select_callback,
        };

        // This initializes the second section
        second_menu_items[0] = (SimpleMenuItem){
        .title = "Retour",
        // You can use different callbacks for your menu items
        .callback = special_select_callback,
        };

        // Bind the menu items to the corresponding menu sections
        menu_sections[0] = (SimpleMenuSection){
        .title = "Sélection des pièces",
        .num_items = NUM_FIRST_MENU_ITEMS,
        .items = first_menu_items,
        };
        menu_sections[1] = (SimpleMenuSection){
        // Menu sections can also have titles as well
        .title = "Fin de la sélection",
        .num_items = NUM_SECOND_MENU_ITEMS,
        .items = second_menu_items,
        };

// INITIALISATION WINDOW, MENU LAYER,...



        // Now we prepare to initialize the simple menu layer
        // We need the bounds to specify the simple menu layer's viewport size
        // In this case, it'll be the same as the window's
        Layer *window_layer = window_get_root_layer(window);
        GRect bounds = layer_get_frame(window_layer);

        // Initialize the simple menu layer
        simple_menu_layer = simple_menu_layer_create(bounds, window, menu_sections, NUM_MENU_SECTIONS, NULL);

        // Add it to the window for display
        layer_add_child(window_layer, simple_menu_layer_get_layer(simple_menu_layer));
        }

// Deinitialize resources on window unload that were initialized on window load
        void window_unload(Window *window) {
        simple_menu_layer_destroy(simple_menu_layer);
         // text_layer_destroy(bt_layer);
        }


void init(void) {
	window = window_create();
  
  // Setup the window handlers
        window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
        });

	window_stack_push(window, true);
  

	
	// Register AppMessage handlers
	app_message_register_inbox_received(in_received_handler); 
	app_message_register_inbox_dropped(in_dropped_handler); 
	app_message_register_outbox_failed(out_failed_handler);
		
	app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

}

void deinit(void) {
	app_message_deregister_callbacks();
	window_destroy(window);
}

int main( void ) {
	init();
	app_event_loop();
	deinit();
}
Esempio n. 3
0
	  Window* w;
	  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);
	
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "Creating GPS window");
	  w = window_create();
      window_set_background_color(w, GColorBlack);
      window_set_fullscreen(w, true);
      window_set_window_handlers(w, (WindowHandlers) {
        .load = gps_window_load,
        .unload = gps_window_unload
      });
	  window_set_click_config_provider(w, config_provider);
	  view_windows[SCREEN_GPS_KEY] = w;
	
	  //APP_LOG(APP_LOG_LEVEL_DEBUG, "Creating sailing window");  
	  w = window_create();
      window_set_background_color(w, GColorBlack);
      window_set_fullscreen(w, true);
      window_set_window_handlers(w, (WindowHandlers) {
        .load = sailing_window_load,
        .unload = sailing_window_unload
      });
	  window_set_click_config_provider(w, config_provider);
	  view_windows[SCREEN_SAILING_KEY] = w;
	
	  w = window_create();
      window_set_background_color(w, GColorBlack);
      window_set_fullscreen(w, true);
      window_set_window_handlers(w, (WindowHandlers) {
        .load = navigation_window_load,
        .unload = navigation_window_unload
Esempio n. 4
0
void init_settings_window()
{
  window_set_background_color(window, GColorWhite);
  int i = 0, s = 0;

  // Section "Actions"
  i = 0;
  menu_section0_items[i++] = (SimpleMenuItem) {
    .title = (s_data.state == STATE_STOP) ? _("Start GPS") : _("Stop GPS"),
    .callback = &menu_start_stop_data_callback,
  };
  menu_section0_items[i++] = (SimpleMenuItem) {
    .title = _("Reset data"),
    .subtitle = _("distance, time, ascent..."),
    .callback = &menu_reset_data_callback,
  };
  if (s_data.page_number == PAGE_DATA || s_data.page_number == PAGE_ALTITUDE) {
    menu_section0_items[i++] = (SimpleMenuItem) {
      .title = _("Configure screen"),
      .subtitle = _("Change fields"),
      .callback = &menu_configure_screen,
    };
  }
  // Header
  menu_sections[s++] = (SimpleMenuSection) {
    .title = _("Actions"),
    .items = menu_section0_items,
    .num_items = i
  };

#ifdef ENABLE_ORUXMAPS
    // Section "Orux"
    i = 0;
    menu_section_orux_items[i++] = (SimpleMenuItem) {
      .title = _("Start OruxMaps"),
      .subtitle = _("Continue previous track"),
      .callback = &menu_orux_callback,
    };
    menu_section_orux_items[i++] = (SimpleMenuItem) {
      .title = _("Stop OruxMaps"),
      .callback = &menu_orux_callback,
    };
    menu_section_orux_items[i++] = (SimpleMenuItem) {
      .title = _("Add waypoint"),
      .callback = &menu_orux_callback,
    };
    // Header
    menu_sections[s++] = (SimpleMenuSection) {
      .title = _("OruxMaps Integration"),
      .items = menu_section_orux_items,
      .num_items = ARRAY_LENGTH(menu_section_orux_items)
    };
#endif
#ifdef ENABLE_MENU_HEART_ZONES
  // Section "Heart rate zones"
  if (heartrate_max > 0) {
    i = 0;
    char buffer_duration[10];
    for (int j = 1; j <= NB_HR_ZONES; j++) {
      snprintf(heartzones_titles[j], sizeof(heartzones_titles[j]), "%d - %s", j, heartrate_zones_name[j]);
      if (heartrate_zones_duration[j] < 60) {
        snprintf(buffer_duration, sizeof(buffer_duration), "%02d\"", heartrate_zones_duration[j]);
      } else {
        snprintf(buffer_duration, sizeof(buffer_duration), "%d'%02d\"", heartrate_zones_duration[j] / 60, heartrate_zones_duration[j] % 60);
      }
      snprintf(heartzones_subtitles[j], sizeof(heartzones_subtitles[j]), "[%d-%d] : %s", j == 1 ? 0 : heartrate_zones_min_hr(j), j == NB_HR_ZONES ? heartrate_max : heartrate_zones_min_hr(j+1), buffer_duration);
      //LOG_INFO("%d %s %s", j, heartzones_titles[j], heartzones_subtitles[j]);
      menu_section_heartzones_items[i++] = (SimpleMenuItem) {
        .title = heartzones_titles[j],
        .subtitle = heartzones_subtitles[j],
      };
    }
    // Header
    menu_sections[s++] = (SimpleMenuSection) {
      .title = _("Heart rate zones"),
      .items = menu_section_heartzones_items,
      .num_items = ARRAY_LENGTH(menu_section_heartzones_items)
    };
  }
#endif
#if MENU_HELP_BUTTONS
    // Section "Buttons"
    i = 0;
    menu_section1_items[i++] = (SimpleMenuItem) {
      .title = _("Up"),
      .subtitle = _("Start/stop GPS"),
    };
    menu_section1_items[i++] = (SimpleMenuItem) {
      .title = _("Middle"),
      .subtitle = _("Change screen"),
    };
    menu_section1_items[i++] = (SimpleMenuItem) {
      .title = _("Down"),
      .subtitle = _("Menu / Zoom map"),
    };
    menu_section1_items[i++] = (SimpleMenuItem) {
      .title = _("Back"),
      .subtitle = _("Double click to exit"),
    };
    // Header
    menu_sections[s++] = (SimpleMenuSection) {
      .title = _("Buttons"),
      .items = menu_section1_items,
      .num_items = ARRAY_LENGTH(menu_section1_items)
    };
#endif


  // Section "About"
  i = 0;
  menu_section2_items[i++] = (SimpleMenuItem) {
    .title = "Ventoo",
    .subtitle = VERSION_TEXT,
  };
  menu_section2_items[i++] = (SimpleMenuItem) {
    .title = _("Authors"),
    .subtitle = APP_COMPANY,
  };
  menu_section2_items[i++] = (SimpleMenuItem) {
    .title = _("More info"),
    .subtitle = "http://pebblebike.com",
  };

  BatteryChargeState charge_state = battery_state_service_peek();
  snprintf(pebble_battery_level, sizeof(pebble_battery_level), "%d %%", charge_state.charge_percent);
  menu_section2_items[i++] = (SimpleMenuItem) {
    .title = _("Pebble battery"),
    .subtitle = pebble_battery_level,
  };
  //APP_LOG(APP_LOG_LEVEL_DEBUG, "phone_battery_level:%ld", s_data.phone_battery_level);
  if (s_data.phone_battery_level > 0) {
    snprintf(phone_battery_level, sizeof(phone_battery_level), "%ld %%", s_data.phone_battery_level);
  } else {
    snprintf(phone_battery_level, sizeof(phone_battery_level), "-");
  }
  menu_section2_items[i++] = (SimpleMenuItem) {
    .title = _("Phone battery"),
    .subtitle = phone_battery_level,
  };
  // Header
  menu_sections[s++] = (SimpleMenuSection) {
    .title = _("About"),
    .items = menu_section2_items,
    .num_items = ARRAY_LENGTH(menu_section2_items)
  };

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

  // Initialize the simple menu layer
  menu_layer = simple_menu_layer_create(bounds, window, menu_sections, ARRAY_LENGTH(menu_sections), NULL);

  // Add it to the window for display
  layer_add_child(window_layer, simple_menu_layer_get_layer(menu_layer));  
}


/**
 * Public functions
 */

void menu_show()
{
  init_settings_window();

  window_stack_push(window, true);
}

void window_disappear(Window *window) {
  simple_menu_layer_destroy(menu_layer);
}

void menu_init() {
  window = window_create();
#ifdef PBL_SDK_2
  window_set_fullscreen(window, true);
#endif

  window_set_window_handlers(window, (WindowHandlers) {
    .appear = (WindowHandler)handle_appear,
    .disappear = window_disappear,
  });
  
}
void menu_deinit() {
  window_destroy(window);
}
Esempio n. 5
0
int
main(int argc, char *argv[])
{
	struct editor editor;
	int i;
	uint32_t click_to_show = 0;
	const char *preferred_language = NULL;

	for (i = 1; i < argc; i++) {
		if (strcmp("--click-to-show", argv[i]) == 0)
			click_to_show = 1;
		else if (strcmp("--preferred-language", argv[i]) == 0) {
			if (i + 1 < argc) {
				preferred_language = argv[i + 1];
				i++;
			}
		}
	}

	memset(&editor, 0, sizeof editor);

#ifdef HAVE_PANGO
	g_type_init();
#endif

	editor.display = display_create(&argc, argv);
	if (editor.display == NULL) {
		fprintf(stderr, "failed to create display: %m\n");
		return -1;
	}

	display_set_user_data(editor.display, &editor);
	display_set_global_handler(editor.display, global_handler);

	editor.window = window_create(editor.display);
	editor.widget = frame_create(editor.window, &editor);

	editor.entry = text_entry_create(&editor, "Entry");
	editor.entry->click_to_show = click_to_show;
	if (preferred_language)
		editor.entry->preferred_language = strdup(preferred_language);
	editor.editor = text_entry_create(&editor, "Numeric");
	editor.editor->content_purpose = WL_TEXT_INPUT_CONTENT_PURPOSE_NUMBER;
	editor.editor->click_to_show = click_to_show;

	window_set_title(editor.window, "Text Editor");
	window_set_key_handler(editor.window, key_handler);
	window_set_user_data(editor.window, &editor);

	widget_set_redraw_handler(editor.widget, redraw_handler);
	widget_set_resize_handler(editor.widget, resize_handler);
	widget_set_button_handler(editor.widget, editor_button_handler);

	window_schedule_resize(editor.window, 500, 400);

	display_run(editor.display);

	text_entry_destroy(editor.entry);
	text_entry_destroy(editor.editor);

	return 0;
}
Esempio n. 6
0
    .did_focus = app_focus_changed
  });
  #endif

  
  
  #ifdef PBL_COLOR
    hand_color = GColorRed;
  #else
    hand_color = GColorWhite;
    aplite_visited = malloc(168*20);
  #endif   
  shadow_color = GColorWhite;
  
  
  window = window_create();
  window_set_background_color(window, GColorBlack);
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
  window_stack_push(window, true);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_second_tick);
}

static void deinit() {
  
  

  #ifndef PBL_SDK_2
Esempio n. 7
0
static void initialise_ui(void) {
  s_window = window_create();
  #ifndef PBL_SDK_3
    window_set_fullscreen(s_window, true);
  #endif
  
  s_res_gothic_18_bold = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
  s_res_gothic_14 = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  s_res_gothic_24_bold = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
  // txt_train_origin
  txt_train_origin = text_layer_create(GRect(5, 0, 134, 21));
  text_layer_set_text(txt_train_origin, "Firenze SMN");
  text_layer_set_font(txt_train_origin, s_res_gothic_18_bold);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_train_origin);
  
  // txt_train_code
  txt_train_code = text_layer_create(GRect(5, 20, 125, 16));
  text_layer_set_text(txt_train_code, "1234");
  text_layer_set_font(txt_train_code, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_train_code);
  
  // txt_update
  txt_update = text_layer_create(GRect(111, 149, 30, 15));
  text_layer_set_text_alignment(txt_update, GTextAlignmentRight);
  text_layer_set_font(txt_update, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_update);
  
  // txt_last_stop
  txt_last_stop = text_layer_create(GRect(22, 64, 104, 16));
  text_layer_set_text(txt_last_stop, "-");
  text_layer_set_font(txt_last_stop, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_last_stop);
  
  // txt_next_stop_dt
  txt_next_stop_dt = text_layer_create(GRect(22, 121, 38, 20));
  text_layer_set_text(txt_next_stop_dt, "--:--");
  text_layer_set_font(txt_next_stop_dt, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_next_stop_dt);
  
  // txt_next_stop
  txt_next_stop = text_layer_create(GRect(21, 104, 112, 18));
  text_layer_set_text(txt_next_stop, "-");
  text_layer_set_font(txt_next_stop, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_next_stop);
  
  // s_textlayer_1
  s_textlayer_1 = text_layer_create(GRect(57, 149, 55, 18));
  text_layer_set_text(s_textlayer_1, "upd @");
  text_layer_set_text_alignment(s_textlayer_1, GTextAlignmentRight);
  text_layer_set_font(s_textlayer_1, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_1);
  
  // txt_next_stop_pf
  txt_next_stop_pf = text_layer_create(GRect(86, 121, 42, 20));
  text_layer_set_text(txt_next_stop_pf, "-");
  text_layer_set_text_alignment(txt_next_stop_pf, GTextAlignmentRight);
  text_layer_set_font(txt_next_stop_pf, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_next_stop_pf);
  
  // txt_last_stop_dt
  txt_last_stop_dt = text_layer_create(GRect(23, 81, 44, 20));
  text_layer_set_text(txt_last_stop_dt, "--:--");
  text_layer_set_font(txt_last_stop_dt, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_last_stop_dt);
  
  // txt_last_stop_pf
  txt_last_stop_pf = text_layer_create(GRect(99, 81, 29, 20));
  text_layer_set_text(txt_last_stop_pf, "-");
  text_layer_set_text_alignment(txt_last_stop_pf, GTextAlignmentRight);
  text_layer_set_font(txt_last_stop_pf, s_res_gothic_14);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_last_stop_pf);
  
  // s_textlayer_2
  s_textlayer_2 = text_layer_create(GRect(5, 99, 9, 24));
  text_layer_set_text(s_textlayer_2, ">");
  text_layer_set_text_alignment(s_textlayer_2, GTextAlignmentCenter);
  text_layer_set_font(s_textlayer_2, s_res_gothic_24_bold);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_2);
  
  // s_textlayer_3
  s_textlayer_3 = text_layer_create(GRect(2, 60, 13, 24));
  text_layer_set_text(s_textlayer_3, "<");
  text_layer_set_text_alignment(s_textlayer_3, GTextAlignmentCenter);
  text_layer_set_font(s_textlayer_3, s_res_gothic_24_bold);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_3);
  
  // txt_train_delay
  txt_train_delay = text_layer_create(GRect(22, 39, 100, 20));
  text_layer_set_text(txt_train_delay, "Text layer");
  text_layer_set_text_alignment(txt_train_delay, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(s_window), (Layer *)txt_train_delay);
}
Esempio n. 8
0
Window *initEating() {
	Window *window = window_create();
	window_set_window_handlers(window, (WindowHandlers) {
	  .load = load,
	  .unload = unload,
	});
Esempio n. 9
0
static void init() {

  window = window_create();
  window_stack_push(window, true);
  window_set_background_color(window, GColorBlack);
  
  // Custom fonts
  GFont timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TEXT_TIME_30));
  GFont amFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TEXT_AM_18));
	
  //  AM / PM Layer
  amLayer = text_layer_create(GRect(10, 60, 144-20, 24));
  text_layer_set_text(amLayer, "");
  text_layer_set_font(amLayer, amFont);
  text_layer_set_text_color(amLayer, GColorWhite);
  text_layer_set_background_color(amLayer, GColorClear);
  text_layer_set_text_alignment(amLayer, GTextAlignmentLeft);

  // Hour layer
  hourLayer = text_layer_create(GRect(0, 75, 144-70, 50));
  text_layer_set_font(hourLayer, timeFont);
  text_layer_set_text_color(hourLayer, GColorWhite);
  text_layer_set_background_color(hourLayer, GColorClear);
  text_layer_set_text_alignment(hourLayer, GTextAlignmentRight);

  // Separator layer
  GRect rect = layer_get_frame(text_layer_get_layer(hourLayer));
  rect.origin.x = rect.size.w;
  rect.size.w = 20;
  dotsLayer = text_layer_create(rect);
  text_layer_set_text(dotsLayer, ":");
  text_layer_set_font(dotsLayer, timeFont);
  text_layer_set_text_color(dotsLayer, GColorWhite);
  text_layer_set_background_color(dotsLayer, GColorClear);
  text_layer_set_text_alignment(dotsLayer, GTextAlignmentCenter);
  
  // Minutes layer
  rect = layer_get_frame(text_layer_get_layer(dotsLayer));
  rect.origin.x += rect.size.w;
  rect.size.w = 144-rect.origin.x;
  minuteLayer = text_layer_create(rect);
  text_layer_set_font(minuteLayer, timeFont);
  text_layer_set_text_color(minuteLayer, GColorWhite);
  text_layer_set_background_color(minuteLayer, GColorClear);
  text_layer_set_text_alignment(minuteLayer, GTextAlignmentLeft);
  
  // Configure time on init
	// Configure time on init
  time_t now = time(NULL);
  struct tm *t = localtime(&now);
	display_time(t);

	// Load layers
	Layer *window_layer = window_get_root_layer(window);
  layer_add_child(window_layer, text_layer_get_layer(amLayer));
  layer_add_child(window_layer, text_layer_get_layer(hourLayer));
  layer_add_child(window_layer, text_layer_get_layer(dotsLayer));
  layer_add_child(window_layer, text_layer_get_layer(minuteLayer));
	
	// Handle minute tick
	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
}
Esempio n. 10
0
// Creates all of the objects needed for the watch.  Normally called
// only by handle_init(), but might be invoked midstream in a
// memory-panic situation.
void create_objects() {
  app_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "create_objects");
  window = window_create();
  assert(window != NULL);

  struct WindowHandlers window_handlers;
  memset(&window_handlers, 0, sizeof(window_handlers));
  window_handlers.load = window_load_handler;
  window_handlers.appear = window_appear_handler;
  window_handlers.disappear = window_disappear_handler;
  window_handlers.unload = window_unload_handler;
  window_set_window_handlers(window, window_handlers);

  window_set_fullscreen(window, true);
  window_stack_push(window, false);

  hand_cache_init(&hour_cache);
  hand_cache_init(&minute_cache);
  hand_cache_init(&second_cache);

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

  clock_face_layer = layer_create(window_frame);
  assert(clock_face_layer != NULL);
  layer_set_update_proc(clock_face_layer, &clock_face_layer_update_callback);
  layer_add_child(window_layer, clock_face_layer);

  {
    const struct IndicatorTable *window = &battery_table[config.face_index];
    init_battery_gauge(window_layer, window->x, window->y, window->invert, window->opaque);
  }
  {
    const struct IndicatorTable *window = &bluetooth_table[config.face_index];
    init_bluetooth_indicator(window_layer, window->x, window->y, window->invert, window->opaque);
  }

  for (int i = 0; i < NUM_DATE_WINDOWS; ++i) {
    const struct IndicatorTable *window = &date_windows[i][config.face_index];
    Layer *layer = layer_create_with_data(GRect(window->x - 19, window->y - 8, 39, 19), sizeof(DateWindowData));
    assert(layer != NULL);
    date_window_layers[i] = layer;
    DateWindowData *data = (DateWindowData *)layer_get_data(layer);
    data->date_window_index = i;

    layer_set_update_proc(layer, &date_window_layer_update_callback);
    layer_add_child(window_layer, layer);
  }

#ifdef MAKE_CHRONOGRAPH
  create_chrono_objects();
#endif  // MAKE_CHRONOGRAPH

  // Init all of the hands, taking care to arrange them in the correct
  // stacking order.
  int i;
  for (i = 0; stacking_order[i] != STACKING_ORDER_DONE; ++i) {
    switch (stacking_order[i]) {
    case STACKING_ORDER_HOUR:
      hour_layer = layer_create(window_frame);
      assert(hour_layer != NULL);
      layer_set_update_proc(hour_layer, &hour_layer_update_callback);
      layer_add_child(window_layer, hour_layer);
      break;

    case STACKING_ORDER_MINUTE:
      minute_layer = layer_create(window_frame);
      assert(minute_layer != NULL);
      layer_set_update_proc(minute_layer, &minute_layer_update_callback);
      layer_add_child(window_layer, minute_layer);
      break;

    case STACKING_ORDER_SECOND:
      second_layer = layer_create(window_frame);
      assert(second_layer != NULL);
      layer_set_update_proc(second_layer, &second_layer_update_callback);
      layer_add_child(window_layer, second_layer);
      break;

    case STACKING_ORDER_CHRONO_MINUTE:
#if defined(ENABLE_CHRONO_MINUTE_HAND) && defined(MAKE_CHRONOGRAPH)
      chrono_minute_layer = layer_create(window_frame);
      assert(chrono_minute_layer != NULL);
      layer_set_update_proc(chrono_minute_layer, &chrono_minute_layer_update_callback);
      layer_add_child(window_layer, chrono_minute_layer);
#endif  // ENABLE_CHRONO_MINUTE_HAND
      break;

    case STACKING_ORDER_CHRONO_SECOND:
#if defined(ENABLE_CHRONO_SECOND_HAND) && defined(MAKE_CHRONOGRAPH)
      chrono_second_layer = layer_create(window_frame);
      assert(chrono_second_layer != NULL);
      layer_set_update_proc(chrono_second_layer, &chrono_second_layer_update_callback);
      layer_add_child(window_layer, chrono_second_layer);
#endif  // ENABLE_CHRONO_SECOND_HAND
      break;

    case STACKING_ORDER_CHRONO_TENTH:
#if defined(ENABLE_CHRONO_TENTH_HAND) && defined(MAKE_CHRONOGRAPH)
      chrono_tenth_layer = layer_create(window_frame);
      assert(chrono_tenth_layer != NULL);
      layer_set_update_proc(chrono_tenth_layer, &chrono_tenth_layer_update_callback);
      layer_add_child(window_layer, chrono_tenth_layer);
#endif  // ENABLE_CHRONO_TENTH_HAND
      break;
    }
  }
}
Esempio n. 11
0
PinWindow* pin_window_create(PinWindowCallbacks callbacks) {
  PinWindow *pin_window = (PinWindow*)malloc(sizeof(PinWindow));
  if (pin_window) {
    pin_window->window = window_create();
    pin_window->callbacks = callbacks;
    if (pin_window->window) {
      pin_window->field_selection = 0;
      for(int i = 0; i < NUM_CELLS; i++) {
        pin_window->pin.digits[i] = 0;
      }
      
      // Get window parameters
      Layer *window_layer = window_get_root_layer(pin_window->window);
      GRect bounds = layer_get_bounds(window_layer);
      
      // Main TextLayer
#ifdef PBL_SDK_3
      pin_window->main_text = text_layer_create(GRect(0, 30, bounds.size.w, 40));
#else
      pin_window->main_text = text_layer_create(GRect(0, 15, bounds.size.w, 40));
#endif
      text_layer_set_text(pin_window->main_text, "How many?");
      text_layer_set_font(pin_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
      text_layer_set_text_alignment(pin_window->main_text, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(pin_window->main_text));
      
      // Sub TextLayer
#ifdef PBL_SDK_3
      pin_window->sub_text = text_layer_create(GRect(1, 125, bounds.size.w, 40));
#else
      pin_window->sub_text = text_layer_create(GRect(1, 110, bounds.size.w, 40));
#endif

      // Create selection layer
#ifdef PBL_SDK_3
      pin_window->selection = selection_layer_create(GRect(8, 75, 128, 34), NUM_CELLS);
#else
      pin_window->selection = selection_layer_create(GRect(8, 60, 128, 34), NUM_CELLS);
#endif
      for (int i = 0; i < NUM_CELLS; i++) {
        selection_layer_set_cell_width(pin_window->selection, i, 40);
      }
      selection_layer_set_cell_padding(pin_window->selection, 4);
#ifdef PBL_COLOR
      selection_layer_set_active_bg_color(pin_window->selection, GColorRed);
      selection_layer_set_inactive_bg_color(pin_window->selection, GColorDarkGray);
#endif
      selection_layer_set_click_config_onto_window(pin_window->selection, pin_window->window);
      selection_layer_set_callbacks(pin_window->selection, pin_window, (SelectionLayerCallbacks) {
        .get_cell_text = selection_handle_get_text,
        .complete = selection_handle_complete,
        .increment = selection_handle_inc,
        .decrement = selection_handle_dec,
      });
      layer_add_child(window_get_root_layer(pin_window->window), pin_window->selection);

#ifdef PBL_SDK_3

#endif
      return pin_window;
    }
Esempio n. 12
0
//Hippo Command, I put my pants on backwards!
void handle_init(void) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "INIT MEMORY: %u bytes used, %u bytes free", (unsigned) heap_bytes_used(), (unsigned) heap_bytes_free());
    
    // TODO: restore this once done profiling
#ifndef LOCK_SHIP
    srand(time(NULL));
    load_holomesh(rand() % c_craft_info_count);
#else
    load_holomesh(LOCK_SHIP);
#endif
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "UI MEMORY: %u bytes used, %u bytes free", (unsigned) heap_bytes_used(), (unsigned) heap_bytes_free());

    my_window = window_create();
    window_set_background_color(my_window, GColorBlack);

    GRect logoRect = GRect(0, 12, c_viewportWidth, c_viewportWidth);
    logoLayer = bitmap_layer_create(logoRect);
    bitmap_layer_set_bitmap(logoLayer, logoBitmap);
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(logoLayer));

    // Fonts    
    g_font_sw = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_14));
    g_font_sw_symbol = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_SYMBOL_14));
    g_font_time = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
    g_font_info = fonts_get_system_font(FONT_KEY_GOTHIC_14);
    
    // Paint layer
    frameBufferLayer = bitmap_layer_create(GRect(0, 0, c_viewportWidth, c_viewportHeight));
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(frameBufferLayer));
    
    frameBufferBitmap = gbitmap_create_blank_with_palette(
        GSize(c_viewportWidth, c_viewportHeight),
        GBitmapFormat2BitPalette,
        c_palette,
        false);
    bitmap_layer_set_bitmap(frameBufferLayer, frameBufferBitmap);
    bitmap_layer_set_compositing_mode(frameBufferLayer, GCompOpSet);
    
    paint();

    GRect layerSize = GRect(0, 0, c_viewportWidth, c_viewportHeight);

    // Two small text layers
    textLayer = text_layer_create(layerSize);
    text_layer_set_background_color(textLayer, GColorClear);
    text_layer_set_text_color(textLayer, GColorYellow);
    text_layer_set_font(textLayer, g_font_sw);
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(textLayer));

    //Jet Force Push-up, you silly-billy.   
    textLayerSym = text_layer_create(layerSize);
    text_layer_set_background_color(textLayerSym, GColorClear);
    text_layer_set_text_color(textLayerSym, GColorYellow);
    text_layer_set_font(textLayerSym, g_font_sw_symbol);
    layer_set_hidden(text_layer_get_layer(textLayerSym), true);
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(textLayerSym));

    //Hippo Command, I also put my watch on backwards!

    // Info text layer
    infoTextLayer = text_layer_create(layerSize);
    text_layer_set_background_color(infoTextLayer, GColorClear);
    text_layer_set_text_color(infoTextLayer, GColorYellow);
    text_layer_set_font(infoTextLayer, g_font_info);
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(infoTextLayer));
    
    // Time
    GSize timeSize = graphics_text_layout_get_content_size(
        "00:00 AM",
        g_font_time,
        layerSize,
        0,
        GTextAlignmentLeft);
    GRect timeRect = { GPoint(DT_EDGE_PAD, c_viewportHeight - timeSize.h), GSize(c_viewportWidth, timeSize.h) };
    timeLayer = text_layer_create(timeRect);
    text_layer_set_background_color(timeLayer, GColorClear);
    text_layer_set_text_color(timeLayer, GColorYellow);
    text_layer_set_font(timeLayer, g_font_time);
    //text_layer_set_text(timeLayer, "23:45 AM");
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(timeLayer));
    
    // Date
    dateLayer = text_layer_create(layerSize);
    text_layer_set_background_color(dateLayer, GColorClear);
    text_layer_set_text_color(dateLayer, GColorYellow);
    text_layer_set_font(dateLayer, g_font_info);
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(dateLayer));
    


    time_t t = time(NULL);
    update_time_display(localtime(&t));
    update_date_display(localtime(&t));
    update_title_and_info();
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "FINAL MEMORY: %u bytes used, %u bytes free", (unsigned) heap_bytes_used(), (unsigned) heap_bytes_free());
    
    window_stack_push(my_window, true);
    tick_timer_service_subscribe(SECOND_UNIT | MINUTE_UNIT, tick_handler);
    
    g_timer = app_timer_register(c_refreshTimer, animation_timer_trigger, NULL);
    
    accel_data_service_subscribe(c_accelSampleCount, accel_data_handler);
    accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
}
Esempio n. 13
0
static void initialise_ui(void) {
  LOG_FUNC();
  s_window = window_create();
  window_set_background_color(s_window, GColorClear);
  
  s_res_image_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  s_res_image_bt_active = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_ACTIVE);
  s_res_image_bt_passive = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BT_PASSIVE);
  s_res_image_battery = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY);
  s_res_image_outbound = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_OUTBOUND);
  s_res_image_inbound = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_INBOUND);

  s_res_roboto_condensed_21 = fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21);
  s_res_bitham_42_medium_numbers = fonts_get_system_font(FONT_KEY_BITHAM_42_MEDIUM_NUMBERS);
  s_res_gothic_18 = fonts_get_system_font(FONT_KEY_GOTHIC_24);

  // s_bitmaplayer_bg
  s_bitmaplayer_bg = bitmap_layer_create(GRect(0, 0, 144, 168));
  bitmap_layer_set_bitmap(s_bitmaplayer_bg, s_res_image_background);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_bg);
  
  // s_timelayer
  s_timelayer = text_layer_create(GRect(5, 13, 134, 50));
  text_layer_set_background_color(s_timelayer, GColorClear);
  text_layer_set_text_color(s_timelayer, GColorWhite);
  text_layer_set_text(s_timelayer, "00:00");
  text_layer_set_text_alignment(s_timelayer, GTextAlignmentCenter);
  text_layer_set_font(s_timelayer, s_res_bitham_42_medium_numbers);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_timelayer);
  
  // s_daylayer
  s_daylayer = text_layer_create(GRect(5, 64, 134, 26));
  text_layer_set_background_color(s_daylayer, GColorClear);
  text_layer_set_text_color(s_daylayer, GColorWhite);
  text_layer_set_text(s_daylayer, "Mon");
  text_layer_set_text_alignment(s_daylayer, GTextAlignmentCenter);
  text_layer_set_font(s_daylayer, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_daylayer);
  layer_set_hidden(text_layer_get_layer(s_daylayer), true);
  
  // s_datelayer
  s_datelayer = text_layer_create(GRect(5, 64, 134, 26));
  text_layer_set_background_color(s_datelayer, GColorClear);
  text_layer_set_text_color(s_datelayer, GColorWhite);
  text_layer_set_text(s_datelayer, "2.5.2015");
  text_layer_set_text_alignment(s_datelayer, GTextAlignmentCenter);
  text_layer_set_font(s_datelayer, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_datelayer);
  
  // s_bitmaplayer_outbound
  s_bitmaplayer_outbound = bitmap_layer_create(GRect(5, 110, 14, 14));
  bitmap_layer_set_bitmap(s_bitmaplayer_outbound, s_res_image_outbound);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_outbound);
  
  // s_outboundlayer
  s_outboundlayer = text_layer_create(GRect(24, 100, 115, 26));
  text_layer_set_background_color(s_outboundlayer, GColorClear);
  text_layer_set_text_color(s_outboundlayer, GColorWhite);
  text_layer_set_text(s_outboundlayer, "Text layer");
  text_layer_set_font(s_outboundlayer, s_res_gothic_18);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_outboundlayer);
  
  // s_bitmaplayer_inbound
  s_bitmaplayer_inbound = bitmap_layer_create(GRect(5, 135, 14, 14));
  bitmap_layer_set_bitmap(s_bitmaplayer_inbound, s_res_image_inbound);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_inbound);
  
  // s_inboundlayer
  s_inboundlayer = text_layer_create(GRect(24, 125, 115, 26));
  text_layer_set_background_color(s_inboundlayer, GColorClear);
  text_layer_set_text_color(s_inboundlayer, GColorWhite);
  text_layer_set_text(s_inboundlayer, "Text layer");
  text_layer_set_font(s_inboundlayer, s_res_gothic_18);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_inboundlayer);

  // s_bitmaplayer_bt
  s_bitmaplayer_bt = bitmap_layer_create(GRect(125, 110, 14, 14));
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_bt);
  
  // s_btlayer
  s_btlayer = text_layer_create(GRect(5, 100, 115, 26));
  text_layer_set_background_color(s_btlayer, GColorClear);
  text_layer_set_text_color(s_btlayer, GColorWhite);
  text_layer_set_text(s_btlayer, "Text layer");
  text_layer_set_font(s_btlayer, s_res_gothic_18);
  text_layer_set_text_alignment(s_btlayer, GTextAlignmentRight);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_btlayer);
  
  // s_bitmaplayer_battery
  s_bitmaplayer_battery = bitmap_layer_create(GRect(125, 135, 14, 14));
  bitmap_layer_set_bitmap(s_bitmaplayer_battery, s_res_image_battery);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_battery);
  
  // s_batterylayer
  s_batterylayer = text_layer_create(GRect(5, 125, 115, 26));
  text_layer_set_background_color(s_batterylayer, GColorClear);
  text_layer_set_text_color(s_batterylayer, GColorWhite);
  text_layer_set_text(s_batterylayer, "Text layer");
  text_layer_set_font(s_batterylayer, s_res_gothic_18);
  text_layer_set_text_alignment(s_batterylayer, GTextAlignmentRight);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_batterylayer);
}
Esempio n. 14
0
void handle_init(void) {
    my_window = window_create();
	window_set_background_color(my_window, GColorBlack);
    window_stack_push(my_window, true);

    date_text_layer = text_layer_create(GRect(8, 0, 144, 30));
    text_layer_set_font(date_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
    text_layer_set_text_alignment(date_text_layer, GTextAlignmentLeft);
    text_layer_set_text_color(date_text_layer, GColorSpringBud);	
    text_layer_set_background_color(date_text_layer, GColorBlack);
    text_layer_set_text(date_text_layer, "Sun Jan 1");
	layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(date_text_layer));	
 
    temp_text_layer = text_layer_create(GRect(8, 24, 144, 30));
    text_layer_set_font(temp_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
    text_layer_set_text_alignment(temp_text_layer, GTextAlignmentLeft);
    text_layer_set_text_color(temp_text_layer, GColorSpringBud);	
    text_layer_set_background_color(temp_text_layer, GColorBlack);
    text_layer_set_text(temp_text_layer, "0000\u00B0C");
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(temp_text_layer));	
	
    time_text_layer = text_layer_create(GRect(0, 46, 144, 80));
    text_layer_set_font(time_text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_52)));
    text_layer_set_text_alignment(time_text_layer, GTextAlignmentCenter);
    text_layer_set_text_color(time_text_layer, GColorBrightGreen);	
    text_layer_set_background_color(time_text_layer, GColorBlack);
	text_layer_set_text(time_text_layer, "00:00");
	layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(time_text_layer));

	s_icon_layer = bitmap_layer_create(GRect(48, 27, 20, 20));
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(s_icon_layer));

    for (unsigned int i = 0; i < ARRAY_LENGTH(AMD_LOGO_BACKGROUND_RESOURCE_IDS); i++) {
        bkgd_amd_img[i] = gbitmap_create_with_resource(AMD_LOGO_BACKGROUND_RESOURCE_IDS[i]);
    }
    
    layer_bkgd_img  = bitmap_layer_create(GRect(0, 102, 144, 68));
    bitmap_layer_set_bitmap(layer_bkgd_img, bkgd_amd_img[0]);
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(layer_bkgd_img));	
 	
#if defined(PBL_COLOR)
    bt_connect_img     = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CONNECT);
    bt_disconnect_img  = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_DISCONNECT);
#elif defined(PBL_BW)
    bt_connect_img     = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CONNECT_BW);
    bt_disconnect_img  = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_DISCONNECT_BW);
#endif
    layer_conn_img     = bitmap_layer_create(GRect(118, 10, 20, 20));
    bitmap_layer_set_bitmap(layer_conn_img, bt_connect_img);
    layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(layer_conn_img));	

	bluetooth_connection_service_subscribe(&handle_bluetooth);
    tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	
	app_message_open(64, 64);
    Tuplet initial_values[] = {
    	TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
    	TupletCString(WEATHER_TEMPERATURE_KEY, "----\u00B0C"),
    	TupletCString(WEATHER_CITY_KEY, "St Pebblesburg"),
  	};
	app_sync_init(&s_sync, s_sync_buffer, sizeof(s_sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);
 }
Esempio n. 15
0
static void init(void) {
  window = window_create();
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload
  });
Esempio n. 16
0
/**
 * \brief Create and initialise a new eventdemo window.
 * The returned eventdemo instance should be destroyed using \c eventdemo_destroy().
 * \param d associated display
 */
static struct eventdemo *
eventdemo_create(struct display *d)
{
	struct eventdemo *e;

	e = malloc(sizeof (struct eventdemo));
	if(e == NULL)
		return NULL;

	e->window = window_create(d);

	if (noborder) {
		/* Demonstrate how to create a borderless window.
		 * Move windows with META + left mouse button.
		 */
		e->widget = window_add_widget(e->window, e);
	} else {
		e->widget = window_frame_create(e->window, e);
		window_set_title(e->window, title);
	}
	e->display = d;

	/* The eventdemo window draws a red rectangle as a demonstration
	 * of per-window data. The dimensions of that rectangle are set
	 * here.
	 */
	e->x = width * 1.0 / 4.0;
	e->w = width * 2.0 / 4.0;
	e->y = height * 1.0 / 4.0;
	e->h = height * 2.0 / 4.0;

	/* Connect the user data to the window */
	window_set_user_data(e->window, e);

	/* Set the callback redraw handler for the window */
	widget_set_redraw_handler(e->widget, redraw_handler);

	/* Set the callback resize handler for the window */
	widget_set_resize_handler(e->widget, resize_handler);

	/* Set the callback focus handler for the window */
	window_set_keyboard_focus_handler(e->window,
					  keyboard_focus_handler);

	/* Set the callback key handler for the window */
	window_set_key_handler(e->window, key_handler);

	/* Set the callback button handler for the window */
	widget_set_button_handler(e->widget, button_handler);

	/* Set the callback motion handler for the window */
	widget_set_motion_handler(e->widget, motion_handler);

	/* Set the callback axis handler for the window */
	widget_set_axis_handler(e->widget, axis_handler);

	/* Initial drawing of the window */
	window_schedule_resize(e->window, width, height);

	return e;
}
Esempio n. 17
0
static void initialise_ui(void) {
  s_window = window_create();
  #ifndef PBL_SDK_3
    window_set_fullscreen(s_window, true);
  #endif
  
  s_res_roboto_bold_subset_49 = fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49);
  s_res_roboto_condensed_21 = fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21);
  
  // s_time
  s_time = text_layer_create(GRect(0, 0, 144, 25));
  text_layer_set_text(s_time, "12:34");
  text_layer_set_text_alignment(s_time, GTextAlignmentCenter);
  text_layer_set_font(s_time, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_time);
  
  // s_time_elapsed
  s_time_elapsed = text_layer_create(GRect(0, 25, 144, 25));
  text_layer_set_background_color(s_time_elapsed, GColorClear);
  text_layer_set_text_color(s_time_elapsed, GColorBlack);
  text_layer_set_text(s_time_elapsed, "00:00:00");
  text_layer_set_text_alignment(s_time_elapsed, GTextAlignmentCenter);
  text_layer_set_font(s_time_elapsed, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_time_elapsed);
  
  // s_countdown
  s_countdown = text_layer_create(GRect(20, 50, 100, 49));
  text_layer_set_background_color(s_countdown, GColorClear);
  text_layer_set_text(s_countdown, "23");
  text_layer_set_text_alignment(s_countdown, GTextAlignmentCenter);
  text_layer_set_font(s_countdown, s_res_roboto_bold_subset_49);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_countdown);
  
  // s_countup
  s_countup = text_layer_create(GRect(20, 108, 100, 23));
  text_layer_set_background_color(s_countup, GColorClear);
  text_layer_set_text(s_countup, "37");
  text_layer_set_text_alignment(s_countup, GTextAlignmentCenter);
  text_layer_set_font(s_countup, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_countup);
  
  // s_set
  s_set = text_layer_create(GRect(0, 143, 144, 25));
  text_layer_set_text(s_set, "Set: 1");
  text_layer_set_font(s_set, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_set);
  
  // s_menubar
  s_menubar = bitmap_layer_create(GRect(112, 0, 32, 168));
  bitmap_layer_set_background_color(s_menubar, GColorBlack);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_menubar);
  
  // s_restart1
  s_restart1 = text_layer_create(GRect(108, 15, 35, 21));
  text_layer_set_background_color(s_restart1, GColorClear);
  text_layer_set_text_color(s_restart1, GColorWhite);
  text_layer_set_text(s_restart1, "1");
  text_layer_set_text_alignment(s_restart1, GTextAlignmentRight);
  text_layer_set_font(s_restart1, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_restart1);
  
  // s_restart2
  s_restart2 = text_layer_create(GRect(108, 70, 35, 21));
  text_layer_set_background_color(s_restart2, GColorClear);
  text_layer_set_text_color(s_restart2, GColorWhite);
  text_layer_set_text(s_restart2, "2");
  text_layer_set_text_alignment(s_restart2, GTextAlignmentRight);
  text_layer_set_font(s_restart2, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_restart2);
  
  // s_restart3
  s_restart3 = text_layer_create(GRect(108, 129, 35, 21));
  text_layer_set_background_color(s_restart3, GColorClear);
  text_layer_set_text_color(s_restart3, GColorWhite);
  text_layer_set_text(s_restart3, "3");
  text_layer_set_text_alignment(s_restart3, GTextAlignmentRight);
  text_layer_set_font(s_restart3, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_restart3);
  
  /*
  // s_duration
  s_duration = text_layer_create(GRect(20, 43, 100, 23));
  text_layer_set_background_color(s_duration, GColorClear);
  text_layer_set_text(s_duration, "12");
  text_layer_set_text_alignment(s_duration, GTextAlignmentCenter);
  text_layer_set_font(s_duration, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_duration);
  */
}
Esempio n. 18
0
static void initialise_ui(void) {
  s_window = window_create();
  #ifndef PBL_SDK_3
    window_set_fullscreen(s_window, true);
  #endif
}
Esempio n. 19
0
File: land.c Progetto: Kinniken/naev
/**
 * @brief Recreates the land windows.
 *
 *    @param load Is loading game?
 *    @param changetab Should it change to the last open tab?
 */
void land_genWindows( int load, int changetab )
{
   int i, j;
   const char *names[LAND_NUMWINDOWS];
   int w, h;
   Planet *p;
   int regen;

   /* Destroy old window if exists. */
   if (land_wid > 0) {
      land_regen = 2; /* Mark we're regenning. */
      window_destroy(land_wid);

      /* Mark tabs as not generated. */
      land_generated = 0;
   }
   land_loaded = 0;

   /* Get planet. */
   p     = land_planet;
   regen = landed;

   /* Create window. */
   if ((gl_screen.rw < 1024) || (gl_screen.rh < 768)) {
      w = -1; /* Fullscreen. */
      h = -1;
   }
   else {
      w = 800 + 0.5 * (SCREEN_W - 800);
      h = 600 + 0.5 * (SCREEN_H - 600);
   }
   land_wid = window_create( p->name, -1, -1, w, h );
   window_onClose( land_wid, land_cleanupWindow );

   /* Set window map to invalid. */
   for (i=0; i<LAND_NUMWINDOWS; i++)
      land_windowsMap[i] = -1;

   /* See what is available. */
   j = 0;
   /* Main. */
   land_windowsMap[LAND_WINDOW_MAIN] = j;
   names[j++] = land_windowNames[LAND_WINDOW_MAIN];
   /* Bar. */
   if (planet_hasService(land_planet, PLANET_SERVICE_BAR)) {
      land_windowsMap[LAND_WINDOW_BAR] = j;
      names[j++] = land_windowNames[LAND_WINDOW_BAR];
   }
   /* Missions. */
   if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS)) {
      land_windowsMap[LAND_WINDOW_MISSION] = j;
      names[j++] = land_windowNames[LAND_WINDOW_MISSION];
   }
   /* Outfits. */
   if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS)) {
      land_windowsMap[LAND_WINDOW_OUTFITS] = j;
      names[j++] = land_windowNames[LAND_WINDOW_OUTFITS];
   }
   /* Shipyard. */
   if (planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) {
      land_windowsMap[LAND_WINDOW_SHIPYARD] = j;
      names[j++] = land_windowNames[LAND_WINDOW_SHIPYARD];
   }
   /* Equipment. */
   if (planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) ||
         planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) {
      land_windowsMap[LAND_WINDOW_EQUIPMENT] = j;
      names[j++] = land_windowNames[LAND_WINDOW_EQUIPMENT];
   }
   /* Commodity. */
   if (planet_hasService(land_planet, PLANET_SERVICE_COMMODITY)) {
      land_windowsMap[LAND_WINDOW_COMMODITY] = j;
      names[j++] = land_windowNames[LAND_WINDOW_COMMODITY];
   }

   /* Create tabbed window. */
   land_windows = window_addTabbedWindow( land_wid, -1, -1, -1, -1, "tabLand", j, names, 0 );

   /*
    * Order here is very important:
    *
    *  1) Create main tab - must have decent background.
    *  2) Set landed, play music and run land hooks - so hooks run well.
    *  3) Generate missions - so that campaigns are fluid.
    *  4) Create other tabs - lists depend on NPC and missions.
    */

   /* 1) Create main tab. */
   land_createMainTab( land_getWid(LAND_WINDOW_MAIN) );

   /* Add local system map button. */
   land_checkAddMap();

   /* 2) Set as landed and run hooks. */
   if (!regen) {
      landed = 1;
      music_choose("land"); /* Must be before hooks in case hooks change music. */
      if (!load) {
         hooks_run("land");
      }
      events_trigger( EVENT_TRIGGER_LAND );

      /* 3) Generate computer and bar missions. */
      if (planet_hasService(land_planet, PLANET_SERVICE_MISSIONS))
         mission_computer = missions_genList( &mission_ncomputer,
               land_planet->faction, land_planet->name, cur_system->name,
               MIS_AVAIL_COMPUTER );
      if (planet_hasService(land_planet, PLANET_SERVICE_BAR))
         npc_generate(); /* Generate bar npc. */
   }

   /* 4) Create other tabs. */
#define should_open(s, w) \
   (planet_hasService(land_planet, s) && (!land_tabGenerated(w)))

   /* Things get a bit hairy here. Hooks may have triggered a GUI reload via
    * e.g. player.swapShip, so the land tabs may have been generated already
    * and we need to check that before regenerating them.
    */

   /* Basic - bar + missions */
   if (should_open( PLANET_SERVICE_BAR, LAND_WINDOW_BAR ))
      bar_open( land_getWid(LAND_WINDOW_BAR) );
   if (should_open( PLANET_SERVICE_MISSIONS, LAND_WINDOW_MISSION ))
      misn_open( land_getWid(LAND_WINDOW_MISSION) );
   /* Outfits. */
   if (should_open( PLANET_SERVICE_OUTFITS, LAND_WINDOW_OUTFITS ))
      outfits_open( land_getWid(LAND_WINDOW_OUTFITS) );
   /* Shipyard. */
   if (should_open( PLANET_SERVICE_SHIPYARD, LAND_WINDOW_SHIPYARD ))
      shipyard_open( land_getWid(LAND_WINDOW_SHIPYARD) );
   /* Equipment. */
   if ((planet_hasService(land_planet, PLANET_SERVICE_OUTFITS) ||
         planet_hasService(land_planet, PLANET_SERVICE_SHIPYARD)) &&
         !land_tabGenerated( LAND_WINDOW_EQUIPMENT ))
      equipment_open( land_getWid(LAND_WINDOW_EQUIPMENT) );
   /* Commodity. */
   if (should_open( PLANET_SERVICE_COMMODITY, LAND_WINDOW_COMMODITY ))
      commodity_exchange_open( land_getWid(LAND_WINDOW_COMMODITY) );
#undef should_open

   if (!regen) {
      /* Reset markers if needed. */
      mission_sysMark();

      /* Check land missions. */
      if (!has_visited(VISITED_LAND)) {
         missions_run(MIS_AVAIL_LAND, land_planet->faction,
               land_planet->name, cur_system->name);
         visited(VISITED_LAND);
      }
   }

   /* Go to last open tab. */
   window_tabWinOnChange( land_wid, "tabLand", land_changeTab );
   if (changetab && land_windowsMap[ last_window ] != -1)
      window_tabWinSetActive( land_wid, "tabLand", land_windowsMap[ last_window ] );

   /* Refresh the map button in case the player couldn't afford it prior to
    * mission payment.
    */
   land_checkAddMap();

   /* Refuel if necessary. */
   land_refuel();

   /* Finished loading. */
   land_loaded = 1;
}
Esempio n. 20
0
void window_item_create(WI_ITEM_REC *item, int automatic)
{
	WINDOW_REC *window;
        WINDOW_BIND_REC *bind;
	GSList *tmp, *sorted;
	int clear_waiting, reuse_unused_windows;

	g_return_if_fail(item != NULL);

	reuse_unused_windows = settings_get_bool("reuse_unused_windows");

	clear_waiting = TRUE;
	window = NULL;
        sorted = windows_get_sorted();
	for (tmp = sorted; tmp != NULL; tmp = tmp->next) {
		WINDOW_REC *rec = tmp->data;

                /* is item bound to this window? */
		if (item->server != NULL) {
			bind = window_bind_find(rec, item->server->tag,
						item->visible_name);
			if (bind != NULL) {
                                if (!bind->sticky)
					window_bind_destroy(rec, bind);
				window = rec;
				clear_waiting = FALSE;
				break;
			}
		}

		/* use this window IF:
		     - reuse_unused_windows is ON
		     - window has no existing items
		     - window has no name
		     - window has no sticky binds (/LAYOUT SAVEd)
		     - we already haven't found "good enough" window,
		       except if
                         - this is the active window
                         - old window had some temporary bounds and this
			   one doesn't
		     */
		if (reuse_unused_windows && rec->items == NULL &&
		    rec->name == NULL && !window_bind_has_sticky(rec) &&
		    (window == NULL || rec == active_win ||
		     window->bound_items != NULL))
			window = rec;
	}
        g_slist_free(sorted);

        if (window == NULL && !settings_get_bool("autocreate_windows")) {
                /* never create new windows automatically */
                window = active_win;
        }

	if (window == NULL) {
		/* create new window to use */
		if (settings_get_bool("autocreate_split_windows")) {
			signal_emit("gui window create override", 1,
				    GINT_TO_POINTER(MAIN_WINDOW_TYPE_SPLIT));
		}
		window = window_create(item, automatic);
	} else {
		/* use existing window */
		window_item_add(window, item, automatic);
	}

	if (clear_waiting)
                window_bind_remove_unsticky(window);
}
static void initialise_ui(void) {
  s_window = window_create();
  window_set_background_color(s_window, GColorBlack);
  #ifndef PBL_SDK_3
    window_set_fullscreen(s_window, 1);
  #endif

  s_res_bitham_30_black = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD);
  s_res_roboto_condensed_21 = fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21);
  s_res_roboto_condensed_16 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_16));
  // s_time_text_layer
  s_time_text_layer = text_layer_create(GRect(0, 20, 144, 50));
  text_layer_set_text(s_time_text_layer, "03:04");
  text_layer_set_text_alignment(s_time_text_layer, GTextAlignmentCenter);
  text_layer_set_font(s_time_text_layer, s_res_bitham_30_black);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_time_text_layer);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_time_text_layer);

  // s_temperature_text_layer
  s_temperature_text_layer = text_layer_create(GRect(10, 0, 110, 16));
  text_layer_set_background_color(s_temperature_text_layer, GColorBlack);
  text_layer_set_text_color(s_temperature_text_layer, GColorWhite);
  text_layer_set_text(s_temperature_text_layer, "...");
  //text_layer_set_text_alignment(s_temperature_text_layer, GTextAlignmentCenter);
  text_layer_set_font(s_temperature_text_layer, s_res_roboto_condensed_16);;
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_temperature_text_layer);

  // s_battery_textlayer
  s_battery_textlayer = text_layer_create(GRect(110, 0, 30, 16));
  text_layer_set_background_color(s_battery_textlayer, GColorBlack);
  text_layer_set_text_color(s_battery_textlayer, GColorWhite);
  text_layer_set_text(s_battery_textlayer, "...");
  text_layer_set_font(s_battery_textlayer, s_res_roboto_condensed_16);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_battery_textlayer);

  // s_date_layer
  s_date_text_layer = text_layer_create(GRect(15, 67, 116, 25));
  text_layer_set_text(s_date_text_layer, "00/00/0000");
  text_layer_set_text_color(s_date_text_layer, GColorWhite);
  text_layer_set_text_alignment(s_date_text_layer, GTextAlignmentCenter);
  text_layer_set_font(s_date_text_layer, s_res_roboto_condensed_21);
  layer_add_child(window_get_root_layer(s_window), (Layer *)s_date_text_layer);

  #ifndef PBL_SDK_2
    text_layer_set_background_color(s_time_text_layer, GColorDarkCandyAppleRed);
    text_layer_set_background_color(s_date_text_layer, GColorDarkCandyAppleRed);
    text_layer_set_text_color(s_time_text_layer, GColorWhite);
    #else
    text_layer_set_background_color(s_time_text_layer, GColorWhite);
    text_layer_set_background_color(s_date_text_layer, GColorWhite);
  #endif
  
  
  // Create battery meter Layer
  s_battery_layer = layer_create(GRect(10, 0, 30, 10));
  layer_set_update_proc(s_battery_layer, battery_update_proc);


  // Add to Window
  layer_add_child(window_get_root_layer(s_window), s_battery_layer);
}
Esempio n. 22
0
void win_train_station_create(void) {
  window = window_create();
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload
  });
Esempio n. 23
0
TimeWindow* time_window_create(TimeWindowCallbacks callbacks, ETimeState state) {
    TimeWindow *time_window = (TimeWindow*)malloc(sizeof(TimeWindow));
    if (time_window) {
        time_window->window = window_create();
        time_window->callbacks = callbacks;
        if (time_window->window) 
        {
            time_t current_time = time(NULL);
            struct tm* current_tm = localtime(&current_time);
            
            time_window->field_selection = 0;
            time_window->state = state;
            time_window->time.digits[0] = current_tm->tm_hour;
            time_window->time.digits[1] = current_tm->tm_min;
//            for(int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) {
//                time_window->time.digits[i] = 0;
//            }

            // Get window parameters
            Layer *window_layer = window_get_root_layer(time_window->window);
            GRect bounds = layer_get_bounds(window_layer);

            // Main TextLayer
            const GEdgeInsets main_text_insets = {.top = 30};
            time_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets));
            text_layer_set_text(time_window->main_text, "Time Required");
            text_layer_set_font(time_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
            text_layer_set_text_alignment(time_window->main_text, GTextAlignmentCenter);
            layer_add_child(window_layer, text_layer_get_layer(time_window->main_text));

            // Sub TextLayer
            const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5};
            time_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets));
            text_layer_set_text(time_window->sub_text, "up/down to change time");
            text_layer_set_text_alignment(time_window->sub_text, GTextAlignmentCenter);
            text_layer_set_font(time_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
            layer_add_child(window_layer, text_layer_get_layer(time_window->sub_text));

            // Create selection layer
            const GEdgeInsets selection_insets = GEdgeInsets(
                (bounds.size.h - TIME_WINDOW_SIZE.h) / 2,
                (bounds.size.w - TIME_WINDOW_SIZE.w) / 2);
            time_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), TIME_WINDOW_NUM_CELLS);
            for (int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) {
                selection_layer_set_cell_width(time_window->selection, i, 60);
            }
            selection_layer_set_cell_padding(time_window->selection, 6);
            selection_layer_set_active_bg_color(time_window->selection, GColorRed);
            selection_layer_set_inactive_bg_color(time_window->selection, GColorDarkGray);
            selection_layer_set_click_config_onto_window(time_window->selection, time_window->window);
            selection_layer_set_callbacks(time_window->selection, time_window, (SelectionLayerCallbacks) {
                .get_cell_text = selection_handle_get_text,
                .complete = selection_handle_complete,
                .increment = selection_handle_inc,
                .decrement = selection_handle_dec,
            });
            layer_add_child(window_get_root_layer(time_window->window), time_window->selection);

            // Create status bar
            time_window->status = status_bar_layer_create();
            status_bar_layer_set_colors(time_window->status, GColorClear, GColorBlack);
            layer_add_child(window_layer, status_bar_layer_get_layer(time_window->status));
            return time_window;
        }
    }

  APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create TimeWindow");
  return NULL;
}
Esempio n. 24
0
static void main_window_load(Window *window) {
  s_menu_icon_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MENU_ICON_1);

  int num_a_items = 0;

  s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Dairy",
    .callback = menu_select_callback,
};
  s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Fruits and Veggies",
    .callback = menu_select_callback,
  };
  s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Meats and Fish",
    .callback = menu_select_callback,
  };
   s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Grains",
    .callback = menu_select_callback,
  };
 s_first_menu_items[num_a_items++] = (SimpleMenuItem) {
    .title = "Misc.",
    .callback = menu_select_callback,
  };

  s_menu_sections[0] = (SimpleMenuSection) {
    .num_items = NUM_FIRST_MENU_ITEMS,
    .items = s_first_menu_items,
  };
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  s_simple_menu_layer = simple_menu_layer_create(bounds, window, s_menu_sections, NUM_MENU_SECTIONS, NULL);

  layer_add_child(window_layer, simple_menu_layer_get_layer(s_simple_menu_layer));
}

void main_window_unload(Window *window) {
  simple_menu_layer_destroy(s_simple_menu_layer);
  gbitmap_destroy(s_menu_icon_image);
}

static void init() {
  s_main_window = window_create();
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload,
  });

}

static void deinit() {
  window_destroy(s_main_window);
}

int main(void) {
  init();
  products_init();
  handle_init();
  app_event_loop();
  deinit();
  products_deinit();
  handle_deinit();
}
Esempio n. 25
0
/**
 * @brief Opens the system editor interface.
 */
void uniedit_open( unsigned int wid_unused, char *unused )
{
   (void) wid_unused;
   (void) unused;
   unsigned int wid;

   /* Needed to generate faction disk. */
   map_setZoom( 1. );

   /* Must have no diffs applied. */
   diff_clear();

   /* Reset some variables. */
   uniedit_mode   = UNIEDIT_DEFAULT;
   uniedit_drag   = 0;
   uniedit_dragSys = 0;
   uniedit_tsys   = NULL;
   uniedit_tadd   = 0;
   uniedit_zoom   = 1.;
   uniedit_xpos   = 0.;
   uniedit_ypos   = 0.;

   /* Create the window. */
   wid = window_create( "Universe Editor", -1, -1, -1, -1 );
   window_handleKeys( wid, uniedit_keys );
   uniedit_wid = wid;

   /* Close button. */
   window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnClose", "Close", uniedit_close );

   /*Save button. */
   window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*1, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnSave", "Save", uniedit_save );

   /* Jump toggle. */
   window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*3, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnJump", "Jump", uniedit_btnJump );

   /* Rename system. */
   window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*4, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnRename", "Rename", uniedit_btnRename );

   /* Edit system. */
   window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*5, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnEdit", "Edit", uniedit_btnEdit );

   /* New system. */
   window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*6, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnNew", "New Sys", uniedit_btnNew );

   /* Open a system. */
   window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*7, BUTTON_WIDTH, BUTTON_HEIGHT,
         "btnOpen", "Open", uniedit_btnOpen );

   /* Zoom buttons */
   window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", uniedit_buttonZoom );
   window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", uniedit_buttonZoom );

   /* Presence. */
   window_addText( wid, -20, -140, 90, 20, 0, "txtSPresence",
         &gl_smallFont, &cDConsole, "Presence:" );
   window_addText( wid, -20, -140-gl_smallFont.h-5, 80, 100, 0, "txtPresence",
         &gl_smallFont, &cBlack, "N/A" );

   /* Selected text. */
   window_addText( wid, 140, 10, SCREEN_W - 80 - 30 - 30 - BUTTON_WIDTH - 20, 30, 0,
         "txtSelected", &gl_smallFont, &cBlack, NULL );

   /* Actual viewport. */
   window_addCust( wid, 20, -40, SCREEN_W - 150, SCREEN_H - 100,
         "cstSysEdit", 1, uniedit_render, uniedit_mouse, NULL );
   window_custSetOverlay( wid, "cstSysEdit", uniedit_renderOverlay );

   /* Deselect everything. */
   uniedit_deselect();
}
Esempio n. 26
0
static void init() {
  s_main_window = window_create();
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload,
  });
Esempio n. 27
0
int main (int argc, char ** argv) {
	setup_windowing();

	int width  = wins_globals->server_width;
	int height = wins_globals->server_height;

	win_width = width;
	win_height = height;

	init_shmemfonts();
	set_font_size(14);

	/* Create the panel */
	window_t * panel = window_create(0, 0, width, PANEL_HEIGHT);
	window_reorder (panel, 0xFFFF);
	ctx = init_graphics_window_double_buffer(panel);
	draw_fill(ctx, rgba(0,0,0,0));
	flip(ctx);

	init_sprite_png(0, "/usr/share/panel.png");
	init_sprite_png(1, "/usr/share/icons/panel-shutdown.png");

	for (uint32_t i = 0; i < width; i += sprites[0]->width) {
		draw_sprite(ctx, sprites[0], i, 0);
	}

	size_t buf_size = panel->width * panel->height * sizeof(uint32_t);
	char * buf = malloc(buf_size);
	memcpy(buf, ctx->backbuffer, buf_size);

	flip(ctx);

	struct timeval now;
	int last = 0;
	struct tm * timeinfo;
	char   buffer[80];

	struct utsname u;
	uname(&u);

	/* UTF-8 Strings FTW! */
	uint8_t * os_name_ = "とあるOS";
	uint8_t final[512];
	uint32_t l = snprintf(final, 512, "%s %s", os_name_, u.release);

	syscall_signal(2, sig_int);

	/* Enable mouse */
	win_use_threaded_handler();
	mouse_action_callback = panel_check_click;

	while (_continue) {
		/* Redraw the background by memcpy (super speedy) */
		memcpy(ctx->backbuffer, buf, buf_size);
		syscall_gettimeofday(&now, NULL); //time(NULL);
		if (now.tv_sec != last) {
			last = now.tv_sec;
			timeinfo = localtime((time_t *)&now.tv_sec);
			strftime(buffer, 80, "%I:%M:%S %p", timeinfo);

			draw_string(ctx, width - 120, 17, rgb(255,255,255), buffer);
			draw_string(ctx, 10, 17, rgb(255,255,255), final);

			draw_sprite(ctx, sprites[1], win_width - 23, 1); /* Logout button */

			flip(ctx);
		}
		syscall_nanosleep(0,50);
	}
Esempio n. 28
0
static void init(void) {

  memset(&normal_time_digits_layers, 0, sizeof(normal_time_digits_layers));
  memset(&normal_time_digits_images, 0, sizeof(normal_time_digits_images));
		
  // Setup messaging
  const int inbound_size = 256;
  const int outbound_size = 256;
  app_message_open(inbound_size, outbound_size);	
	
  window = window_create();
  if (window == NULL) {
      //APP_LOG(APP_LOG_LEVEL_DEBUG, "OOM: couldn't allocate window");
      return;
  }
  window_stack_push(window, true /* Animated */);
  window_layer = window_get_root_layer(window);

  window_set_background_color(window, GColorBlack);


  GRect dummy_frame = { {0, 0}, {0, 0} };

	for (int i = 0; i < TOTAL_NORMAL_DIGITS; ++i) {
    normal_time_digits_layers[i] = bitmap_layer_create(dummy_frame);
   layer_add_child(window_layer, bitmap_layer_get_layer(normal_time_digits_layers[i]));
  }	
 
	
	 // ** { begin setup mask for MASK effect
  mask.text = NULL;
  mask.bitmap_mask = NULL;

  #ifdef PBL_COLOR
    mask.mask_colors = malloc(sizeof(GColor)*4);
    mask.mask_colors[0] = GColorWhite;
    mask.mask_colors[1] = GColorDarkGray;
    mask.mask_colors[2] = GColorLightGray;
//    mask.mask_colors[3] = GColorClear;
  #else
    mask.mask_colors = malloc(sizeof(GColor)*2);
    mask.mask_colors[0] = GColorWhite;
    mask.mask_colors[1] = GColorClear;
  #endif
	  
  mask.background_color = GColorClear;
  mask.bitmap_background = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MASK);


  // ** end setup mask }
	
  //creating effect layer
  effect_layer_mask = effect_layer_create(GRect(0,0,144,168));
  effect_layer_add_effect(effect_layer_mask, effect_mask, &mask);
  layer_add_child((window_layer), effect_layer_get_layer(effect_layer_mask));

	
	img_battery_100   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_080_100);
    img_battery_30   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_005_030);
    img_battery_00   = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_000_005);
    img_battery_charge = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATT_CHARGING);
    layer_batt_img  = bitmap_layer_create(GRect(66, 102, 9,11));
	bitmap_layer_set_bitmap(layer_batt_img, img_battery_100);
	layer_add_child(window_layer, bitmap_layer_get_layer(layer_batt_img));
		
   bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_ICON_NOBLUETOOTH);
#ifdef PBL_PLATFORM_BASALT
  GRect bitmap_bounds_bt_on = gbitmap_get_bounds(bluetooth_image);
#else
  GRect bitmap_bounds_bt_on = bluetooth_image->bounds;
#endif	
  GRect frame_bt = GRect(66, 102, bitmap_bounds_bt_on.size.w, bitmap_bounds_bt_on.size.h);
  bluetooth_layer = bitmap_layer_create(frame_bt);
  bitmap_layer_set_bitmap(bluetooth_layer, bluetooth_image);
  layer_add_child(window_layer, bitmap_layer_get_layer(bluetooth_layer));
	
	date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ODIN_24));

	layer_date_text = text_layer_create(GRect(0, 10, 144, 26));
	text_layer_set_text_color(layer_date_text, GColorWhite);		
    text_layer_set_background_color(layer_date_text, GColorClear);
    text_layer_set_font(layer_date_text, date_font);
    text_layer_set_text_alignment(layer_date_text, GTextAlignmentRight);
    layer_add_child(window_layer, text_layer_get_layer(layer_date_text));

	layer_ampm_text = text_layer_create(GRect(0, 114, 140, 26));
    text_layer_set_text_color(layer_ampm_text, GColorWhite);
	text_layer_set_background_color(layer_ampm_text, GColorClear);
    text_layer_set_font(layer_ampm_text, date_font);
    text_layer_set_text_alignment(layer_ampm_text, GTextAlignmentRight);
    layer_add_child(window_layer, text_layer_get_layer(layer_ampm_text));

	
  // Avoids a blank screen on watch start.
  time_t now = time(NULL);
  struct tm *tick_time = localtime(&now);  
  handle_tick(tick_time, MONTH_UNIT + DAY_UNIT + HOUR_UNIT + MINUTE_UNIT + SECOND_UNIT);

  Tuplet initial_values[] = {
    TupletInteger(BLUETOOTHVIBE_KEY, persist_read_bool(BLUETOOTHVIBE_KEY)),
    TupletInteger(HOURLYVIBE_KEY, persist_read_bool(HOURLYVIBE_KEY)),
	TupletInteger(FLIP_KEY, persist_read_bool(FLIP_KEY)),
	TupletInteger(COLOUR_KEY, persist_read_bool(COLOUR_KEY)),
	TupletInteger(BLINK_KEY, persist_read_bool(BLINK_KEY)),
  };

  app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values,
                ARRAY_LENGTH(initial_values), sync_tuple_changed_callback,
                NULL, NULL);

  appStarted = true;
 
	 // handlers
    battery_state_service_subscribe(&update_battery);
    bluetooth_connection_service_subscribe(&bluetooth_connection_callback);
    tick_timer_service_subscribe(SECOND_UNIT, handle_tick);

	 // draw first frame
    force_update();
}
Esempio n. 29
0
/** Load the game from the specified file.
    @param create_main_window Whether to create and show the main window. */
gboolean
load_save_load_game(const gchar* filename, gboolean create_main_window)
{
#ifdef DEBUG
    printf("load_save_load_game\n");
#endif

    GString *buf = g_string_new("");
    gchar *fullname = (g_str_has_suffix(filename, const_str("string_fs_save_suffix"))) ?
                      g_strdup(filename) :
                      g_strdup_printf("%s%s", filename, const_str("string_fs_save_suffix"));
    gchar *basename = g_path_get_basename(fullname),
                      *dirname = g_path_get_dirname(fullname);
    gchar *prefix = (g_str_has_suffix(basename, const_str("string_fs_save_suffix"))) ?
                    g_strndup(basename, strlen(basename) - strlen(const_str("string_fs_save_suffix"))) :
                    g_strdup(basename);
    gchar *pwd = g_get_current_dir();

    if(g_str_has_suffix(filename, "last_save"))
    {
        g_free(basename);
        g_free(dirname);
        g_free(prefix);
        g_free(fullname);

        basename = file_load_text_from_saves("last_save");

        if(basename != NULL)
        {
            load_save_load_game(basename, create_main_window);
            g_free(basename);
            return TRUE;
        }
        else
        {
            game_gui_show_warning(_("Last save file not found."));
            return FALSE;
        }
    }

    if(window.main != NULL)
        gtk_widget_hide(window.main);

    gui_show_progress(0, _("Uncompressing savegame..."),
                      PIC_TYPE_LOAD);

    file_decompress(fullname);

    if(debug > 60)
        g_print("load_save_load options\n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading options..."),
        PIC_TYPE_LOAD);

    g_string_sprintf(buf, "%s%s%s___options", dirname, G_DIR_SEPARATOR_S, prefix);
    file_load_opt_file(buf->str, &options, FALSE);
    g_string_sprintf(buf, "%s%s%s___settings", dirname, G_DIR_SEPARATOR_S, prefix);
    file_load_opt_file(buf->str, &settings, FALSE);
    language_set(language_get_code_index(opt_str("string_opt_language_code")) + 1);

    if(debug > 60)
        g_print("load_save_load leagues \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading leagues and cups..."),
        PIC_TYPE_LOAD);

    xml_loadsave_leagues_cups_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load users \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading users..."),
        PIC_TYPE_LOAD);

    xml_load_users(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load transfers \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading transfer list..."),
        PIC_TYPE_LOAD);

    xml_load_transfers(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load stats \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading season stats..."),
        PIC_TYPE_LOAD);

    xml_loadsave_season_stats_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load jobs \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        /* The 'job exchange' is a list of teams looking for a manager. */
        _("Loading job exchange..."),
        PIC_TYPE_LOAD);

    xml_loadsave_jobs_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load newspaper \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading newspaper..."),
        PIC_TYPE_LOAD);

    xml_loadsave_newspaper_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load misc \n");

    gui_show_progress(
        ((PROGRESS_MAX * gui_get_progress_bar_fraction()) + 1) / PROGRESS_MAX,
        _("Loading miscellaneous..."),
        PIC_TYPE_LOAD);

    xml_loadsave_misc_read(dirname, prefix);

    if(debug > 60)
        g_print("load_save_load done \n");

    gui_show_progress(1, _("Done."),
                      PIC_TYPE_LOAD);

    chdir(dirname);
    GPtrArray *files = file_dir_get_contents(dirname, prefix, "");
    // Remove the zipfile from the list
    gint i;
    for(i=0; i<files->len; i++)
    {
        if (g_strcmp0((gchar*)g_ptr_array_index(files, i),basename)==0)
        {
            g_ptr_array_remove_index_fast(files, i);
        }
    }
    file_remove_files(files);
    chdir(pwd);
    g_free(pwd);
    free_gchar_array(&files);


    misc_string_assign(&save_file, fullname);

    file_store_text_in_saves("last_save", fullname);

    gui_show_progress(-1, "",
                      PIC_TYPE_LOAD);

    if(create_main_window)
    {
        window_create(WINDOW_MAIN);
        on_button_back_to_main_clicked(NULL, NULL);
    }
    else if(window.main != NULL)
    {
        gtk_widget_show(window.main);
        window_main_load_geometry();
    }

    g_string_free(buf, TRUE);

    g_free(basename);
    g_free(dirname);
    g_free(prefix);
    g_free(fullname);

    return TRUE;
}
Esempio n. 30
0
//if filename passed is NULL, show normal credits
void credits_show(char *credits_filename)
{
	credits *cr;
	window *wind;
	int i;
	int pcx_error;
	char * tempp;
	char filename[32];
	ubyte backdrop_palette[768];
	
	MALLOC(cr, credits, 1);
	if (!cr)
		return;
	
	cr->have_bin_file = 0;
	cr->buffer_line = 0;
	cr->first_line_offset = 0;
	cr->extra_inc = 0;
	cr->done = 0;
	cr->row = 0;

	// Clear out all tex buffer lines.
	for (i=0; i<NUM_LINES; i++ )
		cr->buffer[i][0] = 0;

	sprintf(filename, "%s", CREDITS_FILE);
	cr->have_bin_file = 0;
	if (credits_filename) {
		strcpy(filename,credits_filename);
		cr->have_bin_file = 1;
	}
	cr->file = PHYSFSX_openReadBuffered( filename );
	if (cr->file == NULL) {
		char nfile[32];
		
		if (credits_filename)
		{
			d_free(cr);
			return;		//ok to not find special filename
		}

		tempp = strchr(filename, '.');
		*tempp = '\0';
		sprintf(nfile, "%s.txb", filename);
		cr->file = PHYSFSX_openReadBuffered(nfile);
		if (cr->file == NULL)
			Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
		cr->have_bin_file = 1;
	}

	set_screen_mode(SCREEN_MENU);
	cr->backdrop.bm_data=NULL;

	pcx_error = pcx_read_bitmap(STARS_BACKGROUND,&cr->backdrop, BM_LINEAR,backdrop_palette);
	if (pcx_error != PCX_ERROR_NONE)		{
		PHYSFS_close(cr->file);
		d_free(cr);
		return;
	}

	songs_play_song( SONG_CREDITS, 1 );

	gr_remap_bitmap_good( &cr->backdrop,backdrop_palette, -1, -1 );

	gr_set_current_canvas(NULL);
	show_fullscr(&cr->backdrop);
	gr_palette_load( gr_palette );

	key_flush();

	wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))credits_handler, cr);
	if (!wind)
	{
		d_event event = { EVENT_WINDOW_CLOSE };
		credits_handler(NULL, &event, cr);
		return;
	}

	while (window_exists(wind))
		event_process();
}