void LayerModel::moveLayerUp() { for(int i=0; i < m_layers.size()-1; i++){ if(m_layers.at(1)->selected){ moveLayer(i,i+1); break; } } }
void TDDSubMenu::onTouchMoved(Touch *touch, Event *event) { if(mIsPressed == false){ return; } Point posGL = touch->getLocation(); // from bottom Point nodeLoc = convertToNodeSpace(posGL); Point diff = Point(posGL.x - mLastPos.x, posGL.y - mLastPos.y); // log("moved: posGL=%f,%f nodeLoc=%f,%f diff=%f,%f", // posGL.x, posGL.y, nodeLoc.x, nodeLoc.y, diff.x, diff.y); if(moveLayer(diff)) { mLastPos = posGL; } return; }
//2. 2nd layer contains date & hour text static void date_update_proc(Layer *layer, GContext *ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); strftime(s_day_buffer, sizeof(s_day_buffer), "%a\n%d %b", t); //print e.g. Wed\n16 Jun text_layer_set_text(s_day_label, s_day_buffer); text_layer_set_text_color(s_day_label, dateQuadrantUseApc? #ifdef INVERT_COLOURS GColorWhite: GColorBlack); //(GColor8){.argb=COLOURS[m_nColourIndex][1]}: //(GColor8){.argb=COLOURS[m_nColourIndex][0]}); #else GColorBlack: GColorWhite); //(GColor8){.argb=COLOURS[m_nColourIndex][0]}: //(GColor8){.argb=COLOURS[m_nColourIndex][1]}); #endif moveLayer((Layer*)s_day_label, (Layer*)s_day_label, dateQuadrant); }
void MplayerWindow::moveDown() { if ((allow_video_movement) || ( mplayerlayer->y() < 0 )) moveLayer( 0, +16 ); }
void MplayerWindow::moveUp() { if ((allow_video_movement) || (mplayerlayer->y()+mplayerlayer->height() > height() )) moveLayer( 0, -16 ); }
void MplayerWindow::moveRight() { if ((allow_video_movement) || ( mplayerlayer->x() < 0 )) moveLayer( +16, 0 ); }
void MplayerWindow::moveLeft() { if ((allow_video_movement) || (mplayerlayer->x()+mplayerlayer->width() > width() )) moveLayer( -16, 0 ); }
//1. Base layer contains coloured analogue watch face static void bg_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); int widthHalf = bounds.size.w / 2, heightHalf = bounds.size.h / 2; int32_t width = bounds.size.w * 3; time_t now = time(NULL); struct tm *t = localtime(&now); hr = t->tm_hour; min = t->tm_min; //hr = 7; min = 20; //DEBUG #ifdef DEBUG_MODE int sec = t->tm_sec; min = sec; if (min == 59) --lastSurpriseHr; //force re-selection of surprise min after every round of min hand #endif int32_t angleM = TRIG_MAX_ANGLE * min / 60; //int32_t angleH = TRIG_MAX_ANGLE * (hr % 12) / 12; //without minutes contribution int32_t angleH = (TRIG_MAX_ANGLE * (((hr % 12) * 6) + (min / 10))) / (12 * 6); //with minutes contribution int32_t angleMid; #ifdef DEBUG_COLOURS m_nColourIndex = t->tm_sec * MAX_COLOURS / 60; #else m_nColourIndex = (t->tm_yday * 24 + hr) % MAX_COLOURS; #endif //APP_LOG(APP_LOG_LEVEL_DEBUG, "h:m %d:%d => angles: %d, %d", hr, min, (int) (angleM * 360 / TRIG_MAX_ANGLE), (int) (angleH * 360 / TRIG_MAX_ANGLE)); bool bIsSmallSectorLight = true; if (angleM >= angleH) { if ((angleM - angleH) <= ANGLE_DEG_180) { angleMid = (angleM + angleH) / 2; } else { bIsSmallSectorLight = false; angleMid = (TRIG_MAX_ANGLE - angleM + angleH) / 2 + angleM; } } else //angleH > angleM { if ((angleH - angleM) <= ANGLE_DEG_180) { angleMid = (angleM + angleH) / 2; bIsSmallSectorLight = false; } else { angleMid = (TRIG_MAX_ANGLE - angleH + angleM) / 2 + angleH; } } int mInQ = angleM / ANGLE_DEG_90, hInQ = angleH / ANGLE_DEG_90; dateQuadrant = DATE_QUAD_INDEX[mInQ][hInQ]; dateQuadrantUseApc = (mInQ != hInQ)? DATE_QUAD_USE_PRI[mInQ][hInQ]: (angleM < angleH); surpQuadrant = SURPRISE_QUAD_INDEX[mInQ][hInQ]; surpQuadrantUseApc = (mInQ != hInQ)? SURPRISE_QUAD_USE_PRI[mInQ][hInQ]: (angleM < angleH); //create rectangle (for simplicity instead of sector; triangle is insufficient as at wide angles, it won't cover the corner!) GPathInfo sectorInfo = { .num_points = 4, .points = (GPoint []) { {0, 0}, {width * sin_lookup(angleH) / TRIG_MAX_RATIO, -width * cos_lookup(angleH) / TRIG_MAX_RATIO}, {width * sin_lookup(angleMid) / TRIG_MAX_RATIO, -width * cos_lookup(angleMid) / TRIG_MAX_RATIO}, {width * sin_lookup(angleM) / TRIG_MAX_RATIO, -width * cos_lookup(angleM) / TRIG_MAX_RATIO} } }; GPath *sector = gpath_create(§orInfo); GPoint center = grect_center_point(&bounds); gpath_move_to(sector, center); //bIsSmallSectorLight = ! bIsSmallSectorLight; //try inverting colour scheme to more light (i.e. bigger light sector) #ifdef INVERT_COLOURS GColor clrDark = (GColor8){.argb=COLOURS[m_nColourIndex][1]}; GColor clrLight = (GColor8){.argb=COLOURS[m_nColourIndex][0]}; #else GColor clrDark = (GColor8){.argb=COLOURS[m_nColourIndex][0]}; GColor clrLight = (GColor8){.argb=COLOURS[m_nColourIndex][1]}; #endif //draw background (rest, i.e. big sector) graphics_context_set_fill_color(ctx, !bIsSmallSectorLight? clrLight: clrDark); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); //draw small sector GColor c = bIsSmallSectorLight? clrLight: clrDark; graphics_context_set_fill_color(ctx, c); graphics_context_set_stroke_color(ctx, c); gpath_draw_filled(ctx, sector); gpath_draw_outline(ctx, sector); gpath_destroy(sector); //write 'hour' hint strftime(s_hour_buffer, sizeof(s_hour_buffer), "%l", t); //strftime(s_hour_buffer, sizeof(s_hour_buffer), "12", t); //DEBUG: Try widest hour displayed: 12 /** * In FONT_KEY_BITHAM_30_BLACK, digit '6' is ~18x21 px. * Thus, need vertical offset (of 5 px) as top of font character is 9px down. **/ #ifdef DEBUG_HOUR_HINT int32_t angle = angleM + ANGLE_HOUR_HINT; #else int32_t angle = angleH + ANGLE_HOUR_HINT; #endif int radius = heightHalf - 18; //less font size & margin if (((angle >= ANGLE_DEG_45) && (angle <= ANGLE_DEG_135)) || ((angle >= ANGLE_DEG_225) && (angle <= ANGLE_DEG_315))) { radius = widthHalf - 18; } int i; for (i = 0; i < 5; ++i) { text_layer_set_text(s_hour_label[i], s_hour_buffer); GRect frame = layer_get_frame((Layer*)s_hour_label[i]); frame.origin.x = OFFSET_OUTLINE[i][0] + center.x - (frame.size.w / 2) + radius * sin_lookup(angle) / TRIG_MAX_RATIO; frame.origin.y = OFFSET_OUTLINE[i][1] + center.y - (frame.size.h / 2) - 5 //offset 5px up - radius * cos_lookup(angle) / TRIG_MAX_RATIO; layer_set_frame((Layer*)s_hour_label[i], frame); if (i < 4) { text_layer_set_text_color(s_hour_label[i], (hr >= 12)? GColorBlack: GColorWhite); } else { text_layer_set_text_color(s_hour_label[i], (hr >= 12)? GColorWhite: GColorBlack); } } bool bToShowPicFor1stTime = false; if (lastSurpriseHr < 0) { bToShowPicFor1stTime = true; //show pic when watchface is first loaded } if (bToShowPicFor1stTime || (hr != lastSurpriseHr)) { lastSurpriseHr = hr; //randomly pick a min to show surprise pic: if (!bToShowPicFor1stTime) { nextSurpriseMin = rand() % 60; } else if (nextSurpriseMin < 59) //showing pic for 1st time, so randomly pick a min after current min { nextSurpriseMin = (rand() % (59 - min)) + min + 1; } surpriseShownCnt = 0; } if (bToShowPicFor1stTime || ((min == nextSurpriseMin) && (surpriseShownCnt == 0))) { if (!bToShowPicFor1stTime) { ++surpriseShownCnt; } m_bSupriseShowing = true; layer_set_hidden(m_sLayerWeather, true); bitmap_layer_set_bitmap(m_spbmLayer, m_spbmPics[rand() % MAX_PICS]); //move surprise pic to appropriate quadrant: moveLayer((Layer*)m_spbmLayer, layer, surpQuadrant); m_sptimer1 = app_timer_register(PIC_SHOW_INTERVAL, (AppTimerCallback) hidePic, NULL); } if (m_bWeatherEnabled) { moveLayer2((Layer*)m_sLayerWeather, layer, surpQuadrant, !m_bSupriseShowing && m_bWeatherEnabled); } if ((m_nVibes & MASKV_HOURLY) //option enabled to vibrate hourly && (min == 0) //hourly mark reached && (m_nLastHourlyShake != now)) //sometimes update proc gets called several times in the same min, so shake only once! { int from = (m_nVibes & MASKV_FROM) >> 8, to = m_nVibes & MASKV_TO; bool bShake = false; if (from <= to) { bShake = (hr >= from) && (hr <= to); } else { bShake = (hr >= from) || (hr <= to); } if (bShake) { m_nLastHourlyShake = now; vibes_double_pulse(); } } }