Something went wrong. Try again.
Live STIB-MIVB departures on the Pebble Time 2. It covers the bus, tram, and metro network of Brussels
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122#include "disruption_window.h"#include "badge.h"#include "detail_surface.h"#include "model.h"#include "touch.h"
#define HEADER_H 54#define BADGE_W 48#define BADGE_H 32#define TEXT_PAD 6#define TEXT_SLACK 100static Window *s_window;
static Layer *s_header;static ScrollLayer *s_scroll;static TextLayer *s_text;static char s_disruption[sizeof(((LineDetail *)NULL)->disruption)];static char s_line[LINE_LEN];static GColor s_color;static GColor s_text_color;
static void header_update(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); graphics_context_set_fill_color(ctx, s_color); graphics_fill_rect(ctx, bounds, 0, GCornerNone);
GRect badge = GRect(8, (bounds.size.h - BADGE_H) / 2, BADGE_W, BADGE_H); draw_line_badge(ctx, badge, s_line, s_color, s_text_color); graphics_context_set_stroke_color(ctx, s_text_color); graphics_context_set_stroke_width(ctx, 2); graphics_draw_round_rect(ctx, badge, 6); draw_clock(ctx, bounds, s_text_color);}
static int16_t s_pan_base;
static void touch_pan_move(GPoint d, void *ctx) { if (d.x == 0 && d.y == 0) { s_pan_base = scroll_layer_get_content_offset(s_scroll).y; } scroll_layer_set_content_offset(s_scroll, GPoint(0, s_pan_base + d.y), false);}
static void touch_pan_end(bool cancelled, void *ctx) { if (cancelled) { scroll_layer_set_content_offset(s_scroll, GPoint(0, s_pan_base), true); }}
static void touch_swipe(TouchSwipeDir dir, void *ctx) { if (dir == TOUCH_SWIPE_RIGHT) { window_stack_pop(true); }}
static void disruption_load(Window *window) { window_set_background_color(window, GColorBlack); Layer *root = window_get_root_layer(window); GRect bounds = layer_get_bounds(root);
s_header = layer_create(GRect(0, 0, bounds.size.w, HEADER_H)); layer_set_update_proc(s_header, header_update); layer_add_child(root, s_header);
GRect scroll_frame = GRect(0, HEADER_H + 2, bounds.size.w, bounds.size.h - HEADER_H - 2); s_scroll = scroll_layer_create(scroll_frame); scroll_layer_set_click_config_onto_window(s_scroll, window);
GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18); int16_t text_w = scroll_frame.size.w - TEXT_PAD * 2; GSize text_size = graphics_text_layout_get_content_size(s_disruption, font, GRect(0, 0, text_w, 2000), GTextOverflowModeWordWrap, GTextAlignmentLeft);
int16_t text_h = text_size.h + TEXT_SLACK; s_text = text_layer_create(GRect(TEXT_PAD, TEXT_PAD, text_w, text_h)); text_layer_set_text(s_text, s_disruption); text_layer_set_font(s_text, font); text_layer_set_text_color(s_text, GColorWhite); text_layer_set_background_color(s_text, GColorBlack); text_layer_set_overflow_mode(s_text, GTextOverflowModeWordWrap); scroll_layer_add_child(s_scroll, text_layer_get_layer(s_text)); scroll_layer_set_content_size(s_scroll, GSize(scroll_frame.size.w, text_h + TEXT_PAD)); layer_add_child(root, scroll_layer_get_layer(s_scroll)); touch_attach(window, &(TouchHandlers){ .on_pan_move = touch_pan_move, .on_pan_end = touch_pan_end, .on_swipe = touch_swipe, });}
static void disruption_unload(Window *window) { text_layer_destroy(s_text); scroll_layer_destroy(s_scroll); layer_destroy(s_header); touch_detach(window); window_destroy(window); s_window = NULL;}
void disruption_window_refresh(void) { if (s_window) { layer_mark_dirty(s_header); }}
void disruption_window_push(const LineDetail *detail) { if (s_window) { return; } detail_surface_pin(s_disruption, detail->disruption, sizeof(s_disruption)); detail_surface_pin(s_line, detail->line, LINE_LEN); s_color = detail->color; s_text_color = detail->text_color; s_window = window_create(); window_set_window_handlers(s_window, (WindowHandlers){ .load = disruption_load, .unload = disruption_unload, }); window_stack_push(s_window, true);}