- UID
- 27
- 麦力
- 1223
- 注册时间
- 2015-5-11
- 最后登录
- 2019-1-17
- 精华
- 1
- 阅读权限
- 150
- 在线时间
- 59 小时
|
本帖最后由 mark 于 2017-9-12 16:31 编辑
你自己可以定义PI为多少的。下面给你一个使用三角函数的范例:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "maibu_sdk.h"
#include "maibu_res.h"
#define PI 3.1415926
/*表盘中心位置*/
#define CX 64
#define CY 64
/*秒针长度*/
#define SEC_SIZE 50
//务必要记得,全部变量要初始化,或者定义为static
uint8_t g_layer_s = -1;
int32_t g_p_window = -1;
/*
*--------------------------------------------------------------------------------------
* function: get_sec_layer
* parameter:
* return:
* description: 获取秒针图层
* other:
*--------------------------------------------------------------------------------------
*/
P_Layer get_sec_layer(uint8_t sec)
{
double arc = 0.0;
arc = (6 * sec) * PI / 180;
GPoint p1 = {CX,CY}, p2 = {CX + SEC_SIZE * sin(arc) + 0.5, CY - SEC_SIZE * cos(arc) + 0.5};
LayerGeometry lg;
memset(&lg, 0, sizeof(LayerGeometry));
/*直线*/
Line l1 = {p1, p2};
Geometry geometry = {GeometryTypeLine, FillOutline, GColorBlack, (void*)&l1};
Geometry *p_g[1];
p_g[0] = &geometry;
lg.num++;
lg.p_g = p_g;
/*图层1*/
P_Layer p_l = NULL;
p_l = app_layer_create_geometry(&lg);
app_layer_set_bg_color(p_l, GColorWhite);
return p_l;
}
P_Window init_watch()
{
struct date_time datetime;
app_service_get_datetime(&datetime);
/*添加图层到窗口*/
P_Window p_window = app_window_create();
P_Layer sl = get_sec_layer(datetime.sec);
g_layer_s = app_window_add_layer(p_window, sl);
return p_window;
}
void hand_watch_timer_callback(date_time_t tick_time, uint32_t millis, void *context)
{
P_Window p_window = NULL;
P_Layer p_old_sec = NULL, p_new_sec = NULL;
/*根据窗口ID获取窗口句柄*/
p_window = app_window_stack_get_window_by_id(g_p_window);
if (p_window == NULL)
{
return;
}
struct date_time datetime;
app_service_get_datetime(&datetime);
/*更新秒针图层*/
p_new_sec = get_sec_layer(datetime.sec);
p_old_sec = app_window_get_layer_by_id(p_window, g_layer_s);
app_window_replace_layer(p_window, p_old_sec, p_new_sec);
/*窗口更新*/
app_window_update(p_window);
}
int main()
{
/*APP编写*/
P_Window p_window = init_watch();
g_p_window = app_window_stack_push(p_window);
app_window_timer_subscribe(p_window, 1000, hand_watch_timer_callback, NULL);
return 0;
} |
|