- UID
- 226
- 麦力
- 13
- 注册时间
- 2015-10-13
- 最后登录
- 2016-5-6
- 精华
- 0
- 阅读权限
- 20
- 在线时间
- 13 小时
|
6#
楼主 |
发表于 2016-4-5 10:02:27
|
只看该作者
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "maibu_sdk.h"
#include "maibu_res.h"
/*时间图层位置*/
#define SHIQI_TIME_ORIGIN_X 18
#define SHIQI_TIME_ORIGIN_Y 0
#define SHIQI_TIME_SIZE_H 16
#define SHIQI_TIME_SIZE_W 92
/*分页栏图层位置*/
#define SHIQI_UNDERGROUND_ORIGIN_X 0
#define SHIQI_UNDERGROUND_ORIGIN_Y 104
#define SHIQI_UNDERGROUND_SIZE_H 24
#define SHIQI_UNDERGROUND_SIZE_W 128
/*侧边栏图层位置*/
#define SHIQI_SIDE_BG_ORIGIN_X 104
#define SHIQI_SIDE_BG_ORIGIN_Y 0
#define SHIQI_SIDE_BG_SIZE_H 128
#define SHIQI_SIDE_BG_SIZE_W 24
/*闹钟1文字图层位置*/
#define SHIQI_TIME_TEXT_ORIGIN_X 3
#define SHIQI_TIME_TEXT_ORIGIN_Y 20
#define SHIQI_TIME_TEXT_SIZE_H 16
#define SHIQI_TIME_TEXT_SIZE_W 48
/*闹钟1数字图层位置*/
#define SHIQI_TIME_DIGITAL_ORIGIN_X 3
#define SHIQI_TIME_DIGITAL_ORIGIN_Y 24
#define SHIQI_TIME_DIGITAL_SIZE_H 12
#define SHIQI_TIME_DIGITAL_SIZE_W 56
/*中间时间图层位置*/
#define SHIQI_CENTER_TIME_ORIGIN_X 1
#define SHIQI_CENTER_TIME_ORIGIN_Y 46
#define SHIQI_CENTER_TIME_SIZE_H 30
#define SHIQI_CENTER_TIME_SIZE_W 82
/*主界面图层位置*/
#define SHIQI_MAIN_ORIGIN_X 24
#define SHIQI_MAIN_ORIGIN_Y 24
#define SHIQI_MAIN_SIZE_H 80
#define SHIQI_MAIN_SIZE_W 80
typedef struct tag_shiQi
{
int8_t state; //闹钟打开状态
int8_t nTake; //闹钟n被选定
int8_t ap; //am 0 pm 1显示
int8_t page; //分页栏页数
int8_t record_index; //记录位置
int8_t flag; //定时器启动标志
uint32_t sys_micro; //系统毫秒,精度1ms
uint32_t hours; //闹钟小时
uint32_t min; //闹钟分钟
}ShiQi;
static ShiQi shiqi;
#define SHIQI_MAX_HOUR 24
#define SHIQI_MAX_MINS 60
#define Page_MAX 3
/*窗口ID*/
static int32_t id_shiqi_window = -1;
/*定时器ID*/
static int8_t id_shiqi_timer = -1;
/*中间时间图层id*/
static int8_t id_shiqi_text_center_time = -1;
/*闹钟1文字图层id*/
static int8_t id_shiqi_text_center_text = -1;
/*闹钟1数字图层id*/
static int8_t id_shiqi_text_center_digital = -1;
/*功能图层id*/
static int8_t id_shiqi_fun[3] = {-1,-1,-1};
/*分页栏图层ID*/
static int8_t id_shiqi_side_page[3] = { -1, -1, -1 };
extern P_Window shiqi_windows_create();
//extern void shiqi_timer_callback(date_time_t tick_time, uint32_t millis, void *context);
extern void init();
//返回按键
void shiqi_button_back(void *context){
P_Window p_window = (P_Window)context;
if (NULL != p_window)
{
init();
app_window_stack_pop(p_window);
}
}
//向上
void shiqi_button_up(void *context){
P_Window p_window = (P_Window)context;
if (NULL != p_window)
{
if (shiqi.page > 1) {
P_Layer page_layer1 = app_window_get_layer_by_id(p_window, id_shiqi_fun[shiqi.page]);
maibu_layer_set_visible_status(page_layer1, false);
P_Layer side_ug_page_layer1 = app_window_get_layer_by_id(p_window, id_shiqi_side_page[shiqi.page]);
maibu_layer_set_visible_status(side_ug_page_layer1, false);
shiqi.page--;
P_Layer page_layer2 = app_window_get_layer_by_id(p_window, id_shiqi_fun[shiqi.page]);
maibu_layer_set_visible_status(page_layer2, true);
P_Layer side_ug_page_layer2 = app_window_get_layer_by_id(p_window, id_shiqi_side_page[shiqi.page]);
maibu_layer_set_visible_status(side_ug_page_layer2, true);
app_window_update(p_window);
}
if (shiqi.page == 1) {
return;
}
}
}
//向下
void shiqi_button_down(void *context){
P_Window p_window = (P_Window)context;
if (NULL != p_window)
{
if (shiqi.page <3 ) {
P_Layer page_layer1 = app_window_get_layer_by_id(p_window, id_shiqi_fun[shiqi.page]);
maibu_layer_set_visible_status(page_layer1, false);
P_Layer side_ug_page_layer1 = app_window_get_layer_by_id(p_window, id_shiqi_side_page[shiqi.page]);
maibu_layer_set_visible_status(side_ug_page_layer1, false);
shiqi.page++;
P_Layer page_layer2 = app_window_get_layer_by_id(p_window, id_shiqi_fun[shiqi.page]);
maibu_layer_set_visible_status(page_layer2, true);
P_Layer side_ug_page_layer2 = app_window_get_layer_by_id(p_window, id_shiqi_side_page[shiqi.page]);
maibu_layer_set_visible_status(side_ug_page_layer2, true);
app_window_update(p_window);
}
if (shiqi.page == 3) {
return;
}
}
}
//确定按键
void shiqi_button_ok(void *context){
P_Window p_window = (P_Window)context;
if (NULL != p_window)
{
init();
app_window_stack_pop(p_window);
}
}
//添加底侧分页栏
//分页栏1
//返回图层
P_Layer shiqi_create_side_ug1_layer(){
GRect side_ug_frame = {
{ SHIQI_UNDERGROUND_ORIGIN_X, SHIQI_UNDERGROUND_ORIGIN_Y },
{ SHIQI_UNDERGROUND_SIZE_H, SHIQI_UNDERGROUND_SIZE_W }
};
GBitmap side_ug_bitmap;
res_user_get_bitmap(RES_BITMAP_SHIQI_SIDE_UG_1, &side_ug_bitmap);
LayerBitmap side_ug_struct = { side_ug_bitmap, side_ug_frame, GAlignCenter };
return app_layer_create_bitmap(&side_ug_struct);
}
//添加底侧分页栏
//分页栏2
//返回图层
P_Layer shiqi_create_side_ug2_layer(){
GRect side_ug_frame = {
{ SHIQI_UNDERGROUND_ORIGIN_X, SHIQI_UNDERGROUND_ORIGIN_Y },
{ SHIQI_UNDERGROUND_SIZE_H, SHIQI_UNDERGROUND_SIZE_W }
};
GBitmap side_ug_bitmap;
res_user_get_bitmap(RES_BITMAP_SHIQI_SIDE_UG_2, &side_ug_bitmap);
LayerBitmap side_ug_struct = { side_ug_bitmap, side_ug_frame, GAlignCenter };
return app_layer_create_bitmap(&side_ug_struct);
}
//添加底侧分页栏
//分页栏3
//返回图层
P_Layer shiqi_create_side_ug3_layer(){
GRect side_ug_frame = {
{ SHIQI_UNDERGROUND_ORIGIN_X, SHIQI_UNDERGROUND_ORIGIN_Y },
{ SHIQI_UNDERGROUND_SIZE_H, SHIQI_UNDERGROUND_SIZE_W }
};
GBitmap side_ug_bitmap;
res_user_get_bitmap(RES_BITMAP_SHIQI_SIDE_UG_3, &side_ug_bitmap);
LayerBitmap side_ug_struct = { side_ug_bitmap, side_ug_frame, GAlignCenter };
return app_layer_create_bitmap(&side_ug_struct);
}
//添加功能图层
//闹钟
//返回图层
P_Layer shiqi_create_alarm_layer(){
GRect alarm_frame = {
{ SHIQI_MAIN_ORIGIN_X, SHIQI_MAIN_ORIGIN_Y },
{ SHIQI_MAIN_SIZE_H, SHIQI_MAIN_SIZE_W }
};
GBitmap alarm_bitmap;
res_user_get_bitmap(RES_BITMAP_SHIQI_ALARM, &alarm_bitmap);
LayerBitmap alarm_struct = { alarm_bitmap, alarm_frame, GAlignCenter };
return app_layer_create_bitmap(&alarm_struct);
}
//添加功能图层
//秒表
//返回图层
P_Layer shiqi_create_stopwatch_layer(){
GRect stopwatch_frame = {
{ SHIQI_MAIN_ORIGIN_X, SHIQI_MAIN_ORIGIN_Y },
{ SHIQI_MAIN_SIZE_H, SHIQI_MAIN_SIZE_W }
};
GBitmap stopwatch_bitmap;
res_user_get_bitmap(RES_BITMAP_SHIQI_STOPWATCH, &stopwatch_bitmap);
LayerBitmap stopwatch_struct = { stopwatch_bitmap, stopwatch_frame, GAlignCenter };
return app_layer_create_bitmap(&stopwatch_struct);
}
//添加功能图层
//设置
//返回图层
P_Layer shiqi_create_set_layer(){
GRect set_frame = {
{ SHIQI_MAIN_ORIGIN_X, SHIQI_MAIN_ORIGIN_Y },
{ SHIQI_MAIN_SIZE_H, SHIQI_MAIN_SIZE_W }
};
GBitmap set_bitmap;
res_user_get_bitmap(RES_BITMAP_SHIQI_SET, &set_bitmap);
LayerBitmap set_struct = { set_bitmap, set_frame, GAlignCenter };
return app_layer_create_bitmap(&set_struct);
}
void init(){
shiqi.hours = 0;
shiqi.min = 0;
shiqi.flag = 0;
shiqi.nTake = -1;
shiqi.page = 1;
shiqi.state = 0;
}
P_Window shiqi_windows_create(){
P_Window p_window = app_window_create();
if (p_window == NULL)
return NULL;
//创建各图层
//添加时间图层
GRect time_frame = {
{ SHIQI_TIME_ORIGIN_X, SHIQI_TIME_ORIGIN_Y },
{ SHIQI_TIME_SIZE_H, SHIQI_TIME_SIZE_W }
};
struct date_time datetime;
app_service_get_datetime(&datetime);
char buf[6] = "";
sprintf(buf, "%02d:%02d", datetime.hour, datetime.min);
LayerText time_text = { buf, time_frame, GAlignCenter, U_ASCII_ARIAL_12 };
P_Layer time_layer = app_layer_create_text(&time_text);
app_window_add_layer(p_window, time_layer);
//分页栏图层
P_Layer side_ug1_layer = shiqi_create_side_ug1_layer();
if (shiqi.page != 1)
maibu_layer_set_visible_status(side_ug1_layer, false);
id_shiqi_side_page[1] = app_window_add_layer(p_window, side_ug1_layer);
P_Layer side_ug2_layer = shiqi_create_side_ug2_layer();
if (shiqi.page != 2)
maibu_layer_set_visible_status(side_ug2_layer, false);
id_shiqi_side_page[2] = app_window_add_layer(p_window, side_ug2_layer);
P_Layer side_ug3_layer = shiqi_create_side_ug3_layer();
if (shiqi.page != 3)
maibu_layer_set_visible_status(side_ug3_layer, false);
id_shiqi_side_page[3] = app_window_add_layer(p_window, side_ug3_layer);
//添加闹钟图层
P_Layer alarm_layer = shiqi_create_alarm_layer();
if (shiqi.page != 1)
maibu_layer_set_visible_status(alarm_layer, false);
id_shiqi_fun[1] = app_window_add_layer(p_window, alarm_layer);
//添加秒表图层
P_Layer stopwatch_layer = shiqi_create_stopwatch_layer();
if (shiqi.page != 2)
maibu_layer_set_visible_status(stopwatch_layer, false);
id_shiqi_fun[2] = app_window_add_layer(p_window, stopwatch_layer);
//添加设置图层
P_Layer set_layer = shiqi_create_set_layer();
if (shiqi.page != 3)
maibu_layer_set_visible_status(set_layer, false);
id_shiqi_fun[3] = app_window_add_layer(p_window, set_layer);
/*这里先注册按键回调, 在回调中再具体处理回调怎么相应*/
app_window_click_subscribe(p_window, ButtonIdBack, shiqi_button_back);
app_window_click_subscribe(p_window, ButtonIdUp, shiqi_button_up);
app_window_click_subscribe(p_window, ButtonIdDown, shiqi_button_down);
app_window_click_subscribe(p_window, ButtonIdSelect, shiqi_button_ok);
return (p_window);
}
int main(){
simulator_init();
init();
P_Window p_window = shiqi_windows_create();
app_window_stack_push(p_window);
simulator_wait();
return 0;
} |
|