Initial code commit
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
#include <pebble.h>
|
||||
|
||||
// layer-age
|
||||
static Window *s_window;
|
||||
static BitmapLayer *s_leaf_layer;
|
||||
static Layer *s_top_bar_layer;
|
||||
static Layer *s_bottom_bar_layer;
|
||||
|
||||
// bitmaps
|
||||
static GBitmap *s_leaf_bmp;
|
||||
|
||||
// global vars
|
||||
static GColor s_bar_color = GColorDarkGreen;
|
||||
|
||||
// constants
|
||||
static const uint8_t s_edge_bar_height = ((PBL_DISPLAY_HEIGHT / 7) * 2);
|
||||
|
||||
static void game1_window_load() {}
|
||||
|
||||
static void game1_window_unload() {}
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
static void rect_fill_layer_update_proc(Layer *layer, GContext *ctx) {
|
||||
graphics_context_set_fill_color(ctx, s_bar_color);
|
||||
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||
}
|
||||
|
||||
static void setter_window_load() {
|
||||
window_set_background_color(s_window, GColorMintGreen);
|
||||
|
||||
// leaf
|
||||
s_leaf_bmp = gbitmap_create_with_resource(RESOURCE_ID_LEAF);
|
||||
s_leaf_layer = bitmap_layer_create(GRect(PBL_IF_ROUND_ELSE(0, -4), PBL_IF_ROUND_ELSE(0, 7), PBL_IF_ROUND_ELSE(PBL_DISPLAY_WIDTH, PBL_DISPLAY_WIDTH + 8), PBL_DISPLAY_HEIGHT));
|
||||
bitmap_layer_set_alignment(s_leaf_layer, GAlignCenter);
|
||||
bitmap_layer_set_compositing_mode(s_leaf_layer, GCompOpSet);
|
||||
bitmap_layer_set_bitmap(s_leaf_layer, s_leaf_bmp);
|
||||
|
||||
// top&bottom bars
|
||||
s_top_bar_layer = layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, s_edge_bar_height));
|
||||
layer_set_update_proc(s_top_bar_layer, rect_fill_layer_update_proc);
|
||||
s_bottom_bar_layer = layer_create(GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar_height, PBL_DISPLAY_WIDTH, s_edge_bar_height));
|
||||
layer_set_update_proc(s_bottom_bar_layer, rect_fill_layer_update_proc);
|
||||
|
||||
Layer *window_layer = window_get_root_layer(s_window);
|
||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_leaf_layer));
|
||||
layer_add_child(window_layer, s_top_bar_layer);
|
||||
layer_add_child(window_layer, s_bottom_bar_layer);
|
||||
}
|
||||
|
||||
static void setter_window_unload() {
|
||||
layer_destroy(s_bottom_bar_layer);
|
||||
layer_destroy(s_top_bar_layer);
|
||||
bitmap_layer_destroy(s_leaf_layer);
|
||||
gbitmap_destroy(s_leaf_bmp);
|
||||
}
|
||||
|
||||
static void init() {
|
||||
s_window = window_create();
|
||||
|
||||
switch (launch_reason()) {
|
||||
case APP_LAUNCH_WAKEUP:
|
||||
break; // TODO alarm game time!
|
||||
default:
|
||||
window_set_window_handlers(
|
||||
s_window,
|
||||
(WindowHandlers){.load = setter_window_load, .unload = setter_window_unload});
|
||||
window_stack_push(s_window, false);
|
||||
};
|
||||
}
|
||||
|
||||
static void deinit() {
|
||||
window_destroy(s_window);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
init();
|
||||
app_event_loop();
|
||||
deinit();
|
||||
}
|
||||
Reference in New Issue
Block a user