Skip to content

Commit de8f3e9

Browse files
committed
Ponify the root window.
Signed-off-by: Katharine Berry <[email protected]>
1 parent a352878 commit de8f3e9

File tree

9 files changed

+156
-12
lines changed

9 files changed

+156
-12
lines changed

app/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ add_executable(tiny_assistant_app
5555
src/c/menus/alarm_menu.c
5656
src/c/menus/alarm_menu.h
5757
src/c/menus/legal_window.c
58-
src/c/consent/consent.c)
58+
src/c/consent/consent.c
59+
src/c/util/vector_layer.c)

app/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@
7575
"file": "button_indicator.png",
7676
"name": "BUTTON_INDICATOR",
7777
"type": "bitmap"
78+
},
79+
{
80+
"file": "images/root_screen/pony.pdc",
81+
"name": "ROOT_SCREEN_PONY",
82+
"type": "raw"
83+
},
84+
{
85+
"file": "images/root_screen/speech_bubble.pdc",
86+
"name": "ROOT_SCREEN_SPEECH_BUBBLE",
87+
"type": "raw"
7888
}
7989
]
8090
}
169 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Loading
69 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Loading

app/src/c/root_window.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020
#include "root_window.h"
2121
#include "converse/session_window.h"
2222
#include "menus/root_menu.h"
23+
#include "util/vector_layer.h"
2324

2425
struct RootWindow {
2526
Window* window;
2627
ActionBarLayer* action_bar;
2728
SessionWindow* session_window;
2829
GBitmap* dictation_icon;
2930
GBitmap* more_icon;
31+
GDrawCommandImage *pony_image;
32+
GDrawCommandImage *speech_bubble_image;
33+
VectorLayer *pony_layer;
34+
VectorLayer *speech_bubble_layer;
3035
TextLayer* time_layer;
3136
TextLayer* blurb_layer;
3237
EventHandle event_handle;
@@ -49,24 +54,38 @@ RootWindow* root_window_create() {
4954
.appear = prv_window_appear,
5055
.disappear = prv_window_disappear,
5156
});
57+
window_set_background_color(window->window, COLOR_FALLBACK(GColorRichBrilliantLavender, GColorWhite));
5258
window->dictation_icon = gbitmap_create_with_resource(RESOURCE_ID_DICTATION_ICON);
5359
window->more_icon = gbitmap_create_with_resource(RESOURCE_ID_MORE_ICON);
5460
window->action_bar = action_bar_layer_create();
5561
action_bar_layer_set_context(window->action_bar, window);
5662
action_bar_layer_set_icon(window->action_bar, BUTTON_ID_SELECT, window->dictation_icon);
5763
action_bar_layer_set_icon(window->action_bar, BUTTON_ID_DOWN, window->more_icon);
5864
window_set_user_data(window->window, window);
59-
window->time_layer = text_layer_create(GRect(0, 10, 144 - ACTION_BAR_WIDTH, 40));
65+
window->time_layer = text_layer_create(GRect(0, 5, 144 - ACTION_BAR_WIDTH, 40));
6066
window->event_handle = NULL;
6167
text_layer_set_text_alignment(window->time_layer, GTextAlignmentCenter);
6268
text_layer_set_font(window->time_layer, fonts_get_system_font(FONT_KEY_LECO_36_BOLD_NUMBERS));
6369
text_layer_set_text(window->time_layer, "12:34");
70+
text_layer_set_background_color(window->time_layer, GColorClear);
6471
layer_add_child(window_get_root_layer(window->window), (Layer *)window->time_layer);
65-
window->blurb_layer = text_layer_create(GRect(5, 55, 144 - ACTION_BAR_WIDTH - 10, 113));
66-
text_layer_set_text_alignment(window->blurb_layer, GTextAlignmentCenter);
67-
text_layer_set_font(window->blurb_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
72+
window->speech_bubble_image = gdraw_command_image_create_with_resource(RESOURCE_ID_ROOT_SCREEN_SPEECH_BUBBLE);
73+
window->speech_bubble_layer = vector_layer_create(GRect(4, 56, 106, 91));
74+
vector_layer_set_vector(window->speech_bubble_layer, window->speech_bubble_image);
75+
layer_add_child(window_get_root_layer(window->window), vector_layer_get_layer(window->speech_bubble_layer));
76+
77+
window->pony_image = gdraw_command_image_create_with_resource(RESOURCE_ID_ROOT_SCREEN_PONY);
78+
window->pony_layer = vector_layer_create(GRect(0, 109, 57, 59));
79+
vector_layer_set_vector(window->pony_layer, window->pony_image);
80+
layer_add_child(window_get_root_layer(window->window), vector_layer_get_layer(window->pony_layer));
81+
82+
window->blurb_layer = text_layer_create(GRect(15, 55, 95, 80));
83+
text_layer_set_background_color(window->blurb_layer, GColorClear);
84+
text_layer_set_text_alignment(window->blurb_layer, GTextAlignmentLeft);
85+
text_layer_set_font(window->blurb_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
6886
text_layer_set_text(window->blurb_layer, "Hello! How can I help you?");
6987
layer_add_child(window_get_root_layer(window->window), (Layer *)window->blurb_layer);
88+
7089
return window;
7190
}
7291

@@ -79,6 +98,12 @@ void root_window_destroy(RootWindow* window) {
7998
action_bar_layer_destroy(window->action_bar);
8099
gbitmap_destroy(window->dictation_icon);
81100
gbitmap_destroy(window->more_icon);
101+
text_layer_destroy(window->time_layer);
102+
text_layer_destroy(window->blurb_layer);
103+
vector_layer_destroy(window->pony_layer);
104+
vector_layer_destroy(window->speech_bubble_layer);
105+
gdraw_command_image_destroy(window->pony_image);
106+
gdraw_command_image_destroy(window->speech_bubble_image);
82107
free(window);
83108
}
84109

@@ -124,16 +149,16 @@ static void prv_time_changed(struct tm *tick_time, TimeUnits time_changed, void
124149
strftime(rw->time_string, 6, "%I:%M", tick_time);
125150
}
126151
if (tick_time->tm_hour >= 6 && tick_time->tm_hour < 12) {
127-
text_layer_set_text(rw->blurb_layer, "Good morning! How can I help you today?");
152+
text_layer_set_text(rw->blurb_layer, "Good morning!");
128153
} else if (tick_time->tm_hour >= 12 && tick_time->tm_hour < 18) {
129-
text_layer_set_text(rw->blurb_layer, "Good afternoon! How can I help you today?");
154+
text_layer_set_text(rw->blurb_layer, "Good afternoon!");
130155
} else if (tick_time->tm_hour >= 18 && tick_time->tm_hour < 22) {
131-
text_layer_set_text(rw->blurb_layer, "Good evening! How can I help you today?");
156+
text_layer_set_text(rw->blurb_layer, "Good evening!");
132157
} else {
133-
text_layer_set_text(rw->blurb_layer, "Hello there! How can I help you tonight?");
158+
text_layer_set_text(rw->blurb_layer, "Hello there!");
134159
}
135160
text_layer_set_text(rw->time_layer, rw->time_string);
136-
};
161+
}
137162

138163
static void prv_click_config_provider(void *context) {
139164
window_single_click_subscribe(BUTTON_ID_SELECT, prv_prompt_clicked);
@@ -145,5 +170,5 @@ static void prv_prompt_clicked(ClickRecognizerRef recognizer, void *context) {
145170
}
146171

147172
static void prv_more_clicked(ClickRecognizerRef recognizer, void* context) {
148-
root_menu_window_push();
149-
}
173+
root_menu_window_push();
174+
}

app/src/c/util/vector_layer.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "vector_layer.h"
18+
#include <pebble.h>
19+
20+
typedef struct {
21+
GDrawCommandImage *vector;
22+
GColor background_color;
23+
} VectorLayerData;
24+
25+
static void prv_layer_update(Layer *layer, GContext *ctx);
26+
27+
VectorLayer* vector_layer_create(GRect frame) {
28+
Layer *layer = layer_create_with_data(frame, sizeof(VectorLayerData));
29+
VectorLayerData *vector_layer_data = layer_get_data(layer);
30+
vector_layer_data->vector = NULL;
31+
vector_layer_data->background_color = GColorClear;
32+
layer_set_update_proc(layer, prv_layer_update);
33+
return layer;
34+
}
35+
36+
void vector_layer_destroy(VectorLayer *layer) {
37+
layer_destroy(vector_layer_get_layer(layer));
38+
}
39+
40+
Layer* vector_layer_get_layer(VectorLayer *layer) {
41+
return layer;
42+
}
43+
44+
void vector_layer_set_vector(VectorLayer *layer, GDrawCommandImage *image) {
45+
VectorLayerData *data = layer_get_data(layer);
46+
data->vector = image;
47+
layer_mark_dirty(layer);
48+
}
49+
50+
GDrawCommandImage* vector_layer_get_vector(VectorLayer *layer) {
51+
VectorLayerData *data = layer_get_data(layer);
52+
return data->vector;
53+
}
54+
55+
void vector_layer_set_background_color(VectorLayer *layer, GColor color) {
56+
VectorLayerData *data = layer_get_data(layer);
57+
data->background_color = color;
58+
}
59+
60+
61+
static void prv_layer_update(Layer *layer, GContext *ctx) {
62+
VectorLayerData *data = layer_get_data(layer);
63+
GRect bounds = layer_get_bounds(layer);
64+
if (!gcolor_equal(data->background_color, GColorClear)) {
65+
graphics_context_set_fill_color(ctx, data->background_color);
66+
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
67+
}
68+
gdraw_command_image_draw(ctx, data->vector, GPoint(0, 0));
69+
}

app/src/c/util/vector_layer.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef VECTOR_LAYER_H
18+
#define VECTOR_LAYER_H
19+
20+
#include <pebble.h>
21+
22+
typedef Layer VectorLayer;
23+
24+
VectorLayer* vector_layer_create(GRect frame);
25+
void vector_layer_destroy(VectorLayer *layer);
26+
Layer* vector_layer_get_layer(VectorLayer *layer);
27+
void vector_layer_set_vector(VectorLayer *layer, GDrawCommandImage *image);
28+
GDrawCommandImage *vector_layer_get_vector(VectorLayer *layer);
29+
void vector_layer_set_background_color(VectorLayer *layer, GColor color);
30+
31+
#endif //VECTOR_LAYER_H

0 commit comments

Comments
 (0)