static const char* messages[] = {"", " "," "," "," "," - "," "," ",""," - "," , "," "," "," "," "," "," - "," - "," "," ","",};
The order is not important, they will still be chosen randomly from it. window_set_fullscreen(window, true);
The first argument is the name of the window, the second, respectively, true - full screen, false - with bar. Subtlety - this function must be called before window_stack_push, otherwise the miracle will not happen. srand(time(NULL));
text_layer_set_text(text_layer, messages[rand() % 21]);
#include "pebble.h" Window *window; /* */ TextLayer *text_layer; /* */ static const char* messages[] = {"", " "," "," "," "," - "," "," ",""," - "," , "," "," "," "," "," "," - "," - "," "," ","",}; /* */ int main(void) { window = window_create(); /* */ window_set_background_color(window, GColorBlack); /* */ window_set_fullscreen(window, true); /* */ window_stack_push(window, true); /* */ text_layer = text_layer_create(GRect(1, 47, 142, 77)); /* */ text_layer_set_text_color(text_layer, GColorWhite); /* */ text_layer_set_background_color(text_layer, GColorClear); /* */ text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); /* */ text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); /* */ layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer)); /* */ srand(time(NULL)); /* */ text_layer_set_text(text_layer, messages[rand() % 21]); /* */ app_event_loop(); /* - */ text_layer_destroy(text_layer); /* , */ window_destroy(window); /* , */ }
window_set_click_config_provider(window, WindowsClickConfigProvider);
The window pointer is window, the function name is WindowsClickConfigProvider. Create it: void WindowsClickConfigProvider(void *context) { }
window_single_click_subscribe(BUTTON_ID_UP, click);
In this case, when you press the up button, we call click. #include "pebble.h" Window *window; /* */ TextLayer *text_layer; /* */ static const char* messages[] = {"", " "," "," - "," "," - "," "," ",""," - "," , "," "," "," "," "," "," - "," - "," "," ","",}; /* */ void click(ClickRecognizerRef recognizer, void *context) /* */ { text_layer_set_text(text_layer, messages[rand() % 21]); /* */ } void WindowsClickConfigProvider(void *context) /* , */ { window_single_click_subscribe(BUTTON_ID_UP, click); /* click */ window_single_click_subscribe(BUTTON_ID_SELECT, click); window_single_click_subscribe(BUTTON_ID_DOWN, click); } int main(void) { window = window_create(); /* */ window_set_background_color(window, GColorBlack); /* */ window_set_fullscreen(window, true); /* */ window_stack_push(window, true); /* */ text_layer = text_layer_create(GRect(0, 7, 144, 168)); /* */ text_layer_set_text_color(text_layer, GColorWhite); /* */ text_layer_set_background_color(text_layer, GColorClear); /* */ text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); /* */ text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); /* */ layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer)); /* */ srand(time(NULL)); /* */ window_set_click_config_provider(window, WindowsClickConfigProvider); /* , */ text_layer_set_text(text_layer, "Magic Pebble \n , \"\" \"\" "); /* */ app_event_loop(); /* */ text_layer_destroy(text_layer); /* , */ window_destroy(window); /* , */ }
void config_text_layer(int16_t x,int16_t y,int16_t h,int16_t w, const char *font_key) { }
text_layer = text_layer_create(GRect(x, y, h, w)); text_layer_set_font(text_layer, fonts_get_system_font(font_key));
text_layer_destroy(text_layer); config_text_layer(5, 40, 134, 120, FONT_KEY_GOTHIC_28);
bool first_time=true; if (first_time == true) { text_layer_destroy(text_layer); config_text_layer(5, 40, 134, 120, FONT_KEY_GOTHIC_28); first_time = false; }
float timer_delay=1;
void timer_call() /* */ { text_layer_set_text(text_layer, messages[rand() % 21]); /* */ if (timer_delay < 300*100 ) /* 300... */ { timer_delay=timer_delay/0.7; /* ... ... */ app_timer_register(timer_delay/100, timer_call, NULL); /* ... */ } else /* 300... */ { timer_delay=1; /* - */ } }
void click(ClickRecognizerRef recognizer, void *context) /* , */ { text_layer_destroy(text_layer); /* */ config_text_layer(5, 40, 134, 120, FONT_KEY_GOTHIC_28); /* */ timer_call(); /* */ }
static const char* messages[] = {" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",};
text_layer_set_text(text_layer, "Sex Roulette \n , -->");
image_layer = bitmap_layer_create(GRect(0 , 0, 144, 144));
layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(image_layer));
bitmap_layer_set_compositing_mode(image_layer, GCompOpAssignInverted);
{ "uuid": "0f7b8336-d72d-4806-9191-566ffd8f3a8c", "shortName": "SexRoulette", "longName": "SexRoulette", "companyName": "vvzvlad", "versionCode": 1, "versionLabel": "1.0.0", "watchapp": { "watchface": false }, "appKeys": { "dummy": 0 }, "resources": { "media": [ { "menuIcon": true, "type": "png", "name": "DEFAULT_MENU_ICON", "file": "img/logo.png" }, { "type": "png", "name": "POSE_1", "file": "img/1.png" },
At the beginning are familiar fields, the meaning of which is clear and without explanation, and then it describes all 32 pictures. Please note that the structure should be exactly like this: { "type": "png", "name": " ", "file": "img/1.png" }, { "type": "png", "name": " ", "file": "img/1.png" }
Traceback (most recent call last): File "/Users/vvzvlad/Documents/PebbleSDK-2.0-BETA2/Pebble/.waf-1.7.11-478a7e7e9ed077304a8092741524bf8b/waflib/Scripting.py", line 351, in execute return execute_method(self) File "/Users/vvzvlad/Documents/PebbleSDK-2.0-BETA2/Pebble/.waf-1.7.11-478a7e7e9ed077304a8092741524bf8b/waflib/Build.py", line 106, in execute self.execute_build() File "/Users/vvzvlad/Documents/PebbleSDK-2.0-BETA2/Pebble/.waf-1.7.11-478a7e7e9ed077304a8092741524bf8b/waflib/Build.py", line 109, in execute_build self.recurse([self.run_dir]) File "/Users/vvzvlad/Documents/PebbleSDK-2.0-BETA2/Pebble/.waf-1.7.11-478a7e7e9ed077304a8092741524bf8b/waflib/Context.py", line 128, in recurse user_function(self) File "/Users/vvzvlad/Documents/PebbleSDK-2.0-BETA2/SexRoulette/wscript", line 18, in build ctx.load('pebble_sdk')
Well, to hell with him. As you already understood, the icon picture for the menu is marked with the “menuIcon” field : true , and you can also access it from the program. image = gbitmap_create_with_resource(RESOURCE_ID_POSE_1);
select rand() % 31 case 1 image = gbitmap_create_with_resource(RESOURCE_ID_POSE_1); case 2 image = gbitmap_create_with_resource(RESOURCE_ID_POSE_2);
static const uint32_t images[]
static const uint32_t images[] = {RESOURCE_ID_POSE_1,RESOURCE_ID_POSE_2,RESOURCE_ID_POSE_3,RESOURCE_ID_POSE_4,RESOURCE_ID_POSE_5,RESOURCE_ID_POSE_6,RESOURCE_ID_POSE_7,RESOURCE_ID_POSE_8,RESOURCE_ID_POSE_9,RESOURCE_ID_POSE_10,RESOURCE_ID_POSE_11,RESOURCE_ID_POSE_12,RESOURCE_ID_POSE_13,RESOURCE_ID_POSE_14,RESOURCE_ID_POSE_15,RESOURCE_ID_POSE_16,RESOURCE_ID_POSE_17,RESOURCE_ID_POSE_18,RESOURCE_ID_POSE_19,RESOURCE_ID_POSE_20,RESOURCE_ID_POSE_21,RESOURCE_ID_POSE_22,RESOURCE_ID_POSE_23,RESOURCE_ID_POSE_24,RESOURCE_ID_POSE_25,RESOURCE_ID_POSE_26,RESOURCE_ID_POSE_27,RESOURCE_ID_POSE_28,RESOURCE_ID_POSE_29,RESOURCE_ID_POSE_30,RESOURCE_ID_POSE_31,RESOURCE_ID_POSE_32,};
image = gbitmap_create_with_resource(images[rand() % 31]);
bitmap_layer_set_bitmap(image_layer, image);
gbitmap_destroy(image); image = gbitmap_create_with_resource(images[rand() % 31]); bitmap_layer_set_bitmap(image_layer, image);
bool first_time=true;
void timer_call() { first_time = false;
void timer_call() { if (first_time == false) { gbitmap_destroy(image); bitmap_layer_destroy(image_layer); } first_time = false; ..... void click(ClickRecognizerRef recognizer, void *context) { if (first_time == true) { text_layer_destroy(text_layer); config_text_layer(0, 146, 144, 168-146, FONT_KEY_GOTHIC_18); }
text_layer_destroy(text_layer); window_destroy(window); gbitmap_destroy(image); bitmap_layer_destroy(image_layer);
if (first_time == false) { gbitmap_destroy(image); }
#include "pebble.h" float timer_delay=1; /* */ Window *window; /* */ TextLayer *text_layer; /* */ static BitmapLayer *image_layer; /* */ static GBitmap *image; /* */ bool first_time=true; /* */ static const char* messages[] = {" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," ",}; /* */ static const uint32_t images[] = {RESOURCE_ID_POSE_1,RESOURCE_ID_POSE_2,RESOURCE_ID_POSE_3,RESOURCE_ID_POSE_4,RESOURCE_ID_POSE_5,RESOURCE_ID_POSE_6,RESOURCE_ID_POSE_7,RESOURCE_ID_POSE_8,RESOURCE_ID_POSE_9,RESOURCE_ID_POSE_10,RESOURCE_ID_POSE_11,RESOURCE_ID_POSE_12,RESOURCE_ID_POSE_13,RESOURCE_ID_POSE_14,RESOURCE_ID_POSE_15,RESOURCE_ID_POSE_16,RESOURCE_ID_POSE_17,RESOURCE_ID_POSE_18,RESOURCE_ID_POSE_19,RESOURCE_ID_POSE_20,RESOURCE_ID_POSE_21,RESOURCE_ID_POSE_22,RESOURCE_ID_POSE_23,RESOURCE_ID_POSE_24,RESOURCE_ID_POSE_25,RESOURCE_ID_POSE_26,RESOURCE_ID_POSE_27,RESOURCE_ID_POSE_28,RESOURCE_ID_POSE_29,RESOURCE_ID_POSE_30,RESOURCE_ID_POSE_31,RESOURCE_ID_POSE_32,}; /* */ void timer_call() /* */ { if (first_time == false) /* ... */ { bitmap_layer_destroy(image_layer); /* ... ... */ gbitmap_destroy(image); /* .. */ } first_time = false; /* */ image = gbitmap_create_with_resource(images[rand() % 31]); /* */ bitmap_layer_set_bitmap(image_layer, image); /* */ text_layer_set_text(text_layer, messages[rand() % 23]); /* */ if (timer_delay < 300*100 ) /* 300... */ { timer_delay=timer_delay/0.7; /* ... ... */ app_timer_register(timer_delay/100, timer_call, NULL); /* ... */ } else /* 300... */ { timer_delay=1; /* - */ } } void config_text_layer(int16_t x,int16_t y,int16_t h,int16_t w, const char *font_key) /* , , */ { text_layer = text_layer_create(GRect(x, y, h, w)); /* , */ text_layer_set_text_color(text_layer, GColorWhite); /* */ text_layer_set_background_color(text_layer, GColorClear); /* */ text_layer_set_font(text_layer, fonts_get_system_font(font_key)); /* */ text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); /* */ layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer)); /* */ } void click(ClickRecognizerRef recognizer, void *context) /* , */ { if (first_time == true) /* ... */ { text_layer_destroy(text_layer); /* ... ... */ config_text_layer(0, 146, 144, 168-146, FONT_KEY_GOTHIC_18); /* ... */ } timer_call(); /* */ } void WindowsClickConfigProvider(void *context) /* , */ { window_single_click_subscribe(BUTTON_ID_UP, click); /* click */ window_single_click_subscribe(BUTTON_ID_SELECT, click); window_single_click_subscribe(BUTTON_ID_DOWN, click); } int main(void) { window = window_create(); /* */ window_set_background_color(window, GColorBlack); /* */ window_set_fullscreen(window, true); /* */ window_stack_push(window, true); /* */ srand(time(NULL)); /* */ window_set_click_config_provider(window, WindowsClickConfigProvider); /* , */ config_text_layer(0, 20, 144, 168, FONT_KEY_GOTHIC_24); /* */ text_layer_set_text(text_layer, "Sex Roulette \n , -->"); /* */ image_layer = bitmap_layer_create(GRect(0 , 0, 144, 144)); /* , */ layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(image_layer)); /* */ bitmap_layer_set_compositing_mode(image_layer, GCompOpAssignInverted); /* */ app_event_loop(); /* */ text_layer_destroy(text_layer); /* , */ window_destroy(window); /* , */ bitmap_layer_destroy(image_layer); /* , */ if (first_time == false) /* ... */ { gbitmap_destroy(image); /* , , - , .. */ } }
static const uint32_t images[] = {RESOURCE_ID_DICE_1,RESOURCE_ID_DICE_2,RESOURCE_ID_DICE_3,RESOURCE_ID_DICE_4,RESOURCE_ID_DICE_5,RESOURCE_ID_DICE_6,};
accel_tap_service_subscribe(accel_int);
void accel_int(AccelAxisType axis, int32_t direction) { if (first_time == true) { text_layer_destroy(text_layer); } timer_call(); }
image_layer = bitmap_layer_create(GRect(rand()%(144-75), rand()%(168-75), 75, 75));
if (timer_delay < 300*1000 ) { timer_delay=timer_delay/0.7; app_timer_register(timer_delay/1000, timer_call, NULL); }
100, — 1000. . , , . , — , , — , . light_enable(bool enable) light_enable_interaction()
text_layer_set_text(text_layer, " ");
if (first_time == true) { text_layer_destroy(text_layer); } else { bitmap_layer_destroy(image_layer); gbitmap_destroy(image); } accel_tap_service_unsubscribe();
. — , . — , — , — accel_int #include "pebble.h" float timer_delay=1; /* */ Window *window; /* */ TextLayer *text_layer; /* */ static BitmapLayer *image_layer; /* */ static GBitmap *image; /* */ bool first_time=true; /* */ static const uint32_t images[] = {RESOURCE_ID_DICE_1,RESOURCE_ID_DICE_2,RESOURCE_ID_DICE_3,RESOURCE_ID_DICE_4,RESOURCE_ID_DICE_5,RESOURCE_ID_DICE_6,}; /* */ void timer_call() /* */ { if (first_time == false)/* ... */ { bitmap_layer_destroy(image_layer); /* ... , ... */ gbitmap_destroy(image); /* ... */ } first_time = false; /* */ image_layer = bitmap_layer_create(GRect(rand()%(144-75), rand()%(168-75), 75, 75)); /* , */ layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(image_layer)); /* */ image = gbitmap_create_with_resource(images[rand() % 6]); /* */ bitmap_layer_set_bitmap(image_layer, image); /* */ light_enable_interaction(); /* */ if (timer_delay < 300*1000 ) /* 300... */ { timer_delay=timer_delay/0.7; /* ... ... */ app_timer_register(timer_delay/1000, timer_call, NULL); /* ... */ } else /* 300... */ { timer_delay=1; /* - */ } } void accel_int(AccelAxisType axis, int32_t direction) /* ... */ { if (first_time == true) /* ... */ { text_layer_destroy(text_layer); /* ... */ } timer_call(); /* */ } int main(void) { window = window_create(); /* */ window_set_background_color(window, GColorBlack); /* */ window_set_fullscreen(window, true); /* */ window_stack_push(window, true); /* */ srand(time(NULL)); /* */ text_layer = text_layer_create(GRect(0 , 30, 144, 168)); /* , */ text_layer_set_text_color(text_layer, GColorWhite); /* */ text_layer_set_background_color(text_layer, GColorClear); /* */ text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); /* */ text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); /* */ layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer)); /* */ text_layer_set_text(text_layer, " "); /* */ accel_tap_service_subscribe(accel_int); /* */ app_event_loop(); /* */ if (first_time == true) /* ... */ { text_layer_destroy(text_layer); /* ... */ } else /* ... */ { bitmap_layer_destroy(image_layer); /* ... ... */ gbitmap_destroy(image); /* ... , accel_int */ } accel_tap_service_unsubscribe(); /* */ window_destroy(window); /* , */ }
Source: https://habr.com/ru/post/204514/
All Articles