758 lines
31 KiB
C++
758 lines
31 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppPlayDialDrawView.cpp
|
|
*
|
|
* Author: liuguanwu
|
|
*
|
|
* Create: 2024-10
|
|
*--------------------------------------------------------------------------*/
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "dock/focus_manager.h"
|
|
#include "graphic_service.h"
|
|
#include "style.h"
|
|
#include "sys_config.h"
|
|
#include <sys/stat.h>
|
|
|
|
#include "TjdUiAppPlayDialDrawView.h"
|
|
#include "TjdUiAppPlayDialModel.h"
|
|
#include "TjdUiAppPlayDialPresenter.h"
|
|
#include "TjdUiAppPlayDialView.h"
|
|
#include "TjdUiScreenManage.h"
|
|
|
|
// #include "common/screen.h"
|
|
#include "fstream"
|
|
|
|
using namespace std;
|
|
using namespace OHOS;
|
|
|
|
#define ENABLE_PRINT_INFO 1
|
|
#if ENABLE_PRINT_INFO
|
|
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
|
|
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
|
|
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_debug(...)
|
|
#endif
|
|
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
|
|
|
|
#define PLAY_DIAL_BIN_PATH TJD_IMAGE_PATH "img_play_dial.bin"
|
|
#define LEFUN_AI_SCREEN_AUTO_OFF_TIME (1000 * 60 * 60)
|
|
namespace TJD {
|
|
|
|
static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; }
|
|
static inline int16_t VerticalCenter(int16_t height, int16_t parentHeight) { return (parentHeight - height) / 2; }
|
|
|
|
inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text)
|
|
{
|
|
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
|
label.SetText(text);
|
|
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
static_print_debug("InitLabelHorCenter[%s] x=%d-%d-%d-%d", text, label.GetX(), label.GetWidth(), target,
|
|
HorizontalCenter(label.GetWidth(), target));
|
|
label.SetPosition(label.GetX() + HorizontalCenter(label.GetWidth(), target), y);
|
|
}
|
|
// class PlayDialDrawHintView start
|
|
PlayDialDrawHintView *g_PlayDialDrawHintView;
|
|
PlayDialDrawHintView::PlayDialDrawHintView()
|
|
{
|
|
g_PlayDialDrawHintView = this;
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0x00000000);
|
|
SetOnDragListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
|
|
// InitLabelHorCenter(titleMid_, 28, 168, 366, "请在屏幕中一笔随意\n画出图案\n点击“ √ ”生成表盘");
|
|
titleMid_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
titleMid_.SetTextId(STR_ID_411);
|
|
titleMid_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
|
titleMid_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
titleMid_.SetPosition(50, 168, 366, 47);
|
|
|
|
if (countdownTimer_ == nullptr) {
|
|
countdownTimer_ = new OHOS::GraphicTimer(3000, TimerCallBack, this);
|
|
}
|
|
|
|
Add(&titleMid_);
|
|
}
|
|
|
|
PlayDialDrawHintView::~PlayDialDrawHintView()
|
|
{
|
|
if (countdownTimer_ != nullptr) {
|
|
delete countdownTimer_;
|
|
countdownTimer_ = nullptr;
|
|
}
|
|
RemoveAll();
|
|
g_PlayDialDrawHintView = nullptr;
|
|
}
|
|
|
|
PlayDialDrawHintView *PlayDialDrawHintView::GetInstance(void) { return g_PlayDialDrawHintView; }
|
|
|
|
void PlayDialDrawHintView::TimerCallBackRun(void *arg)
|
|
{
|
|
// 跳转到绘制界面
|
|
TjdUiAppPlayDialView::GetInstance().ShowView(PlayDialViewIndex::PLAYDIAL_DRAW_MAIN);
|
|
}
|
|
|
|
void PlayDialDrawHintView::TimerCallBack(void *arg)
|
|
{
|
|
GraphicService::GetInstance()->PostGraphicEvent(
|
|
std::bind([](void *arg) { PlayDialDrawHintView::GetInstance()->TimerCallBackRun(arg); }, arg));
|
|
}
|
|
|
|
// class PlayDialDrawMainView start
|
|
PlayDialDrawMainView *g_PlayDialDrawMainView;
|
|
PlayDialDrawMainView::PlayDialDrawMainView()
|
|
{
|
|
g_PlayDialDrawMainView = this;
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0x00000000);
|
|
SetViewId(PLAYDIAL_DRAW_MAIN_VIEW_CANVAS_ID);
|
|
SetOnDragListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
SetDraggable(true);
|
|
|
|
canvasExt_.SetPosition(0, 0);
|
|
canvasExt_.Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
canvasExt_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFF000000);
|
|
|
|
// canvas_.SetPosition(0, 0);
|
|
// canvas_.Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
// canvas_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFF000000);
|
|
// canvas_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0x0);
|
|
|
|
clickDown_.SetPosition(77, 378, 312, 86);
|
|
auto img_Res =
|
|
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PLAY_DIAL_ICON_YES_DRAWING, PLAY_DIAL_BIN_PATH);
|
|
if (img_Res != nullptr) {
|
|
clickDown_.SetSrc(img_Res);
|
|
clickDown_.SetViewId(PLAYDIAL_DRAW_MAIN_VIEW_BTN_ID);
|
|
clickDown_.SetOnClickListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
clickDown_.SetTouchable(true);
|
|
// clickDown_.SetStyle(STYLE_BACKGROUND_COLOR, 0xFF000000);
|
|
clickDown_.SetStyle(STYLE_BACKGROUND_OPA, 0xff * 0.3);
|
|
}
|
|
|
|
if (logoTimer_ == nullptr) {
|
|
tick_ = 0;
|
|
logoTimer_ = new OHOS::GraphicTimer(100, TimerCallBack, this, true);
|
|
logoTimer_->Start();
|
|
TjdUiScreenManage::SetScreenKeepOnTimeout(LEFUN_AI_SCREEN_AUTO_OFF_TIME);
|
|
}
|
|
|
|
Add(&canvasExt_);
|
|
// Add(&canvas_);
|
|
Add(&clickDown_);
|
|
}
|
|
|
|
PlayDialDrawMainView::~PlayDialDrawMainView()
|
|
{
|
|
TjdUiScreenManage::ResetScreenKeepOnTimeout();
|
|
ClearPoint();
|
|
// canvas_.Clear();
|
|
canvasExt_.Clear();
|
|
RemoveAll();
|
|
if (logoTimer_ != nullptr) {
|
|
logoTimer_->Stop();
|
|
delete logoTimer_;
|
|
logoTimer_ = nullptr;
|
|
}
|
|
g_PlayDialDrawMainView = nullptr;
|
|
}
|
|
|
|
PlayDialDrawMainView *PlayDialDrawMainView::GetInstance(void) { return g_PlayDialDrawMainView; }
|
|
|
|
void PlayDialDrawMainView::ShowView()
|
|
{
|
|
ClearPoint();
|
|
// canvas_.Clear();
|
|
canvasExt_.Clear();
|
|
SetVisible(true);
|
|
}
|
|
|
|
void PlayDialDrawMainView::HideView()
|
|
{
|
|
SetVisible(false);
|
|
if (logoTimer_ != nullptr) {
|
|
logoTimer_->Stop();
|
|
delete logoTimer_;
|
|
logoTimer_ = nullptr;
|
|
}
|
|
}
|
|
|
|
void PlayDialDrawMainView::UpdatePoint(OHOS::Point point)
|
|
{
|
|
static_print_info("[%s][%d]: Style %d selected", __FILE__, __LINE__, style_);
|
|
|
|
// 清空画布和点集
|
|
// canvas_.Clear();
|
|
canvasExt_.Clear();
|
|
if (logoTimer_ == nullptr) {
|
|
tick_ = 0;
|
|
logoTimer_ = new OHOS::GraphicTimer(100, TimerCallBack, this, true);
|
|
logoTimer_->Start();
|
|
TjdUiScreenManage::SetScreenKeepOnTimeout(LEFUN_AI_SCREEN_AUTO_OFF_TIME);
|
|
}
|
|
|
|
PaintExt paint;
|
|
paint.SetStyle(Paint::STROKE_STYLE);
|
|
paint.SetStrokeWidth(9);
|
|
paint.SetStrokeColor((ColorType){.full = 0xFF0e7dff});
|
|
// paint.SetFillColor((ColorType){.full = 0xFF0e7dff});
|
|
paint.SetCapType(CAP_ROUND);
|
|
paint.SetGradientSpread(GradientSpread::SPREAD_REFLECT);
|
|
// paint.SetAntialiased(true);
|
|
// paint.SetJoinType(JoinType::JOIN_ROUND);
|
|
// 通用参数
|
|
const int16_t HOR_RES = OHOS::HORIZONTAL_RESOLUTION;
|
|
const int16_t VER_RES = OHOS::VERTICAL_RESOLUTION;
|
|
const int16_t CENTER_X = HOR_RES / 2;
|
|
const int16_t CENTER_Y = VER_RES / 2;
|
|
|
|
// 边界限制函数
|
|
auto clamp = [](int16_t val, int16_t min, int16_t max) { return val < min ? min : (val > max ? max : val); };
|
|
|
|
// 根据模式生成对称点
|
|
if (style_ == TRISYMMETRY) { // 三对称模式
|
|
constexpr float ANGLE_STEP = 120.0f;
|
|
for (int i = 0; i < 3; ++i) {
|
|
float rad = ANGLE_STEP * i * M_PI / 180.0f;
|
|
float cosA = cos(rad);
|
|
float sinA = sin(rad);
|
|
|
|
float relX = point.x - CENTER_X;
|
|
float relY = point.y - CENTER_Y;
|
|
|
|
float newX = relX * cosA - relY * sinA;
|
|
float newY = relX * sinA + relY * cosA;
|
|
|
|
vectorPoints_[i].push_back({.x = clamp(static_cast<int16_t>(newX + CENTER_X), 0, HOR_RES),
|
|
.y = clamp(static_cast<int16_t>(newY + CENTER_Y), 0, VER_RES)});
|
|
}
|
|
} else if (style_ == TETRASYMMTRY) { // 四对称模式
|
|
// 生成四个镜像点
|
|
vectorPoints_[0].push_back({.x = clamp(point.x > CENTER_X ? HOR_RES - point.x : point.x, 0, HOR_RES),
|
|
.y = clamp(point.y > CENTER_Y ? VER_RES - point.y : point.y, 0, VER_RES)});
|
|
vectorPoints_[1].push_back({.x = clamp(point.x < CENTER_X ? HOR_RES - point.x : point.x, 0, HOR_RES),
|
|
.y = clamp(point.y > CENTER_Y ? VER_RES - point.y : point.y, 0, VER_RES)});
|
|
vectorPoints_[2].push_back({.x = clamp(point.x > CENTER_X ? HOR_RES - point.x : point.x, 0, HOR_RES),
|
|
.y = clamp(point.y < CENTER_Y ? VER_RES - point.y : point.y, 0, VER_RES)});
|
|
vectorPoints_[3].push_back({.x = clamp(point.x < CENTER_X ? HOR_RES - point.x : point.x, 0, HOR_RES),
|
|
.y = clamp(point.y < CENTER_Y ? VER_RES - point.y : point.y, 0, VER_RES)});
|
|
} else if (style_ == PENTASYMMTRY) { // 五对称模式
|
|
constexpr float ANGLE_STEP = 72.0f;
|
|
for (int i = 0; i < style_; ++i) {
|
|
float rad = ANGLE_STEP * i * M_PI / 180.0f;
|
|
float cosA = cos(rad);
|
|
float sinA = sin(rad);
|
|
|
|
// 相对坐标计算
|
|
float relX = point.x - CENTER_X;
|
|
float relY = point.y - CENTER_Y;
|
|
|
|
// 旋转计算
|
|
float newX = relX * cosA - relY * sinA;
|
|
float newY = relX * sinA + relY * cosA;
|
|
|
|
vectorPoints_[i].push_back({.x = clamp(static_cast<int16_t>(newX + CENTER_X), 0, HOR_RES),
|
|
.y = clamp(static_cast<int16_t>(newY + CENTER_Y), 0, VER_RES)});
|
|
}
|
|
}
|
|
|
|
// 统一绘制逻辑
|
|
for (int idx = 0; idx < style_; ++idx) {
|
|
auto &points = vectorPoints_[idx];
|
|
if (points.empty())
|
|
continue;
|
|
|
|
// 配置渐变参数
|
|
sharedLinearGradient_.startX = points[0].x;
|
|
sharedLinearGradient_.startY = points[0].y;
|
|
sharedLinearGradient_.endX = points.back().x;
|
|
sharedLinearGradient_.endY = points.back().y;
|
|
paint.SetLinearGradient(sharedLinearGradient_, sharedColorStops_, 7);
|
|
|
|
// 绘制线段
|
|
OHOS::Point prev = points[0];
|
|
for (size_t i = 1; i < points.size(); ++i) {
|
|
if (prev.x != points[i].x || prev.y != points[i].y) {
|
|
canvasExt_.DrawLine(prev, points[i], paint);
|
|
}
|
|
prev = points[i];
|
|
}
|
|
|
|
// 绘制端点标记
|
|
if (!points.empty()) {
|
|
canvasExt_.DrawCircle(points.front(), 2, paint);
|
|
canvasExt_.DrawCircle(points.back(), 2, paint);
|
|
}
|
|
}
|
|
}
|
|
|
|
void PlayDialDrawMainView::TimerCallBackRun(void *arg)
|
|
{
|
|
PlayDialDrawMainView *p_inst = (PlayDialDrawMainView *)arg;
|
|
if (tick_ <= 5 * 10) {
|
|
tick_++;
|
|
} else {
|
|
// 超时了,跳转到表盘制作页
|
|
if (logoTimer_ != nullptr) {
|
|
logoTimer_->Stop();
|
|
delete logoTimer_;
|
|
logoTimer_ = nullptr;
|
|
TjdUiScreenManage::ResetScreenKeepOnTimeout();
|
|
}
|
|
}
|
|
}
|
|
|
|
void PlayDialDrawMainView::TimerCallBack(void *arg)
|
|
{
|
|
GraphicService::GetInstance()->PostGraphicEvent(
|
|
std::bind([](void *arg) { PlayDialDrawMainView::GetInstance()->TimerCallBackRun(arg); }, arg));
|
|
}
|
|
|
|
void PlayDialDrawMainView::PersisCanvas()
|
|
{
|
|
// 现在画布里面是需要保存的位图像素流信息了
|
|
OHOS::ImageInfo canvasImgInfo;
|
|
if (canvasExt_.GetBitmap(canvasImgInfo)) {
|
|
|
|
// 检查一下这些数据信息,然后怎么存下去??? 数据在canvasImgInfo.data中
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", canvasImgInfo.header.version);
|
|
static_print_info("header.width: %u", canvasImgInfo.header.width);
|
|
static_print_info("header.height: %u", canvasImgInfo.header.height);
|
|
static_print_info("header.compressMode: %u", canvasImgInfo.header.compressMode);
|
|
static_print_info("header.colorMode: %u", canvasImgInfo.header.colorMode);
|
|
static_print_info("dataSize: %u", canvasImgInfo.dataSize);
|
|
static_print_info("color: %u", canvasImgInfo.color);
|
|
|
|
if (access(TJD_FS_DIR_WFP, 0) != 0) {
|
|
if (access(TJD_FS_DIR_WFP, F_OK) != 0) {
|
|
int ret = mkdir(TJD_FS_DIR_WFP, 0777);
|
|
if (ret == 0) {
|
|
static_print_debug("成功创建目录: %s", TJD_FS_DIR_WFP);
|
|
} else {
|
|
static_print_debug("创建目录失败: %s, 错误: %s", TJD_FS_DIR_WFP, strerror(errno));
|
|
// 处理错误,例如尝试其他目录或退出
|
|
return; // 或其他错误处理
|
|
}
|
|
}
|
|
}
|
|
|
|
ofstream outputFile;
|
|
#if 0
|
|
DIR *dir = nullptr;
|
|
dir = opendir(TJD_CALL_LOG_DIR);
|
|
if (dir == nullptr) {
|
|
mkdir(TJD_CALL_LOG_DIR, S_IREAD | S_IWRITE);
|
|
} else {
|
|
closedir(dir);
|
|
}
|
|
outputFile.open(PLAY_DIAL_DRAW_BIN_TEMP_PATH, ios::ios_base::binary | ios::ios_base::trunc | ios::ios_base::out);
|
|
static_print_info("outputFile.is_open():fail0: %d-%d", outputFile.is_open(), outputFile.good());
|
|
if(outputFile.is_open()) {
|
|
static_print_info("outputFile.is_open():fail0 [%d]: %s", __LINE__, __func__);
|
|
FILE *file = fopen(PLAY_DIAL_DRAW_BIN_TEMP_PATH, "rw");
|
|
if (file) fclose(file);
|
|
}
|
|
#endif
|
|
|
|
outputFile.open(PLAY_DIAL_DRAW_BIN_TEMP_PATH,
|
|
ios::ios_base::binary | ios::ios_base::trunc | ios::ios_base::out);
|
|
if (outputFile.is_open() && outputFile.good()) {
|
|
char stream[128] = {0};
|
|
|
|
// 先写header
|
|
if (sizeof(ImageHeader) < 128) {
|
|
memcpy(stream, &canvasImgInfo.header, sizeof(ImageHeader));
|
|
outputFile.write(stream, sizeof(ImageHeader));
|
|
}
|
|
// 后写data
|
|
outputFile.write((char *)(canvasImgInfo.data), canvasImgInfo.dataSize);
|
|
|
|
outputFile.close();
|
|
extern std::string g_PlayDialPreviewPath;
|
|
g_PlayDialPreviewPath = PLAY_DIAL_DRAW_BIN_TEMP_PATH;
|
|
|
|
#if 0
|
|
// 加载测试
|
|
OHOS::ImageInfo *bmpImgInfo = OHOS::ImageCacheManager::GetInstance().LoadSingleRes(PLAY_DIAL_DRAW_BIN_TEMP_PATH);
|
|
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", bmpImgInfo->header.version);
|
|
static_print_info("header.width: %u", bmpImgInfo->header.width);
|
|
static_print_info("header.height: %u", bmpImgInfo->header.height);
|
|
static_print_info("header.compressMode: %u", bmpImgInfo->header.compressMode);
|
|
static_print_info("header.colorMode: %u", bmpImgInfo->header.colorMode);
|
|
static_print_info("dataSize: %u", bmpImgInfo->dataSize);
|
|
static_print_info("color: %u", bmpImgInfo->color);
|
|
#endif
|
|
} else {
|
|
static_print_info("outputFile.is_open():fail [%d]: %s", __LINE__, __func__);
|
|
}
|
|
|
|
// 记得释放掉申请的内存数据
|
|
OHOS::ImageCacheFree(canvasImgInfo);
|
|
} else {
|
|
static_print_info("canvasExt_.GetBitmap():fail [%d]: %s", __LINE__, __func__);
|
|
}
|
|
|
|
// // 这部分坐标可能没调好, 再细微调整点
|
|
// Paint paint;
|
|
// paint.SetStyle(Paint::FILL_STYLE);
|
|
// // paint.SetStrokeColor((ColorType){.full = 0xFFFFFFFF});
|
|
// paint.SetFillColor((ColorType){.full = 0xFFFFFFFF});
|
|
// // 背景是纯色的,但是预览图里面是存在前景信息的
|
|
// // 在这里需要将前景信息额外绘制出来,否则预览图也是纯色背景
|
|
// // ...待定中>>>
|
|
// paint.SetStrokeWidth(9);
|
|
// UICanvas::FontStyle Style = {};
|
|
// Style.fontName = TJD_VECTOR_FONT_FILENAME;
|
|
|
|
// Style.fontSize = 36;
|
|
// Point point1 = {
|
|
// .x = (466 - (32 * 4 + 10)) / 2,
|
|
// .y = 120,
|
|
// };
|
|
// canvas_.DrawLabel(point1, "13:14", canvas_.GetWidth(), Style, paint);
|
|
|
|
// Style.fontSize = 24;
|
|
// Point point2 = {
|
|
// .x = (466 - (24 * 5 + 6 * 3)) / 2,
|
|
// .y = 160,
|
|
// };
|
|
// canvas_.DrawLabel(point2, "Mon 24", canvas_.GetWidth(), Style, paint);
|
|
|
|
// 再存一次,将未缩放的预览图保存,在预览时将其再做缩放保存(因为画布不支持缩放)
|
|
|
|
// OHOS::Screen::GetInstance().GetCurrentScreenBitmap(canvasImgInfo)
|
|
if (GetBitmap(canvasImgInfo)) {
|
|
|
|
// 检查一下这些数据信息,然后怎么存下去??? 数据在canvasImgInfo.data中
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", canvasImgInfo.header.version);
|
|
static_print_info("header.width: %u", canvasImgInfo.header.width);
|
|
static_print_info("header.height: %u", canvasImgInfo.header.height);
|
|
static_print_info("header.compressMode: %u", canvasImgInfo.header.compressMode);
|
|
static_print_info("header.colorMode: %u", canvasImgInfo.header.colorMode);
|
|
static_print_info("dataSize: %u", canvasImgInfo.dataSize);
|
|
static_print_info("color: %u", canvasImgInfo.color);
|
|
|
|
ofstream outputFile;
|
|
outputFile.open(PLAY_DIAL_DRAW_PREVIEW_BIN_PATH,
|
|
ios::ios_base::binary | ios::ios_base::trunc | ios::ios_base::out);
|
|
|
|
if (outputFile.is_open() && outputFile.good()) {
|
|
char stream[128] = {0};
|
|
|
|
// 先写header
|
|
if (sizeof(ImageHeader) < 128) {
|
|
memcpy(stream, &canvasImgInfo.header, sizeof(ImageHeader));
|
|
outputFile.write(stream, sizeof(ImageHeader));
|
|
}
|
|
// 后写data
|
|
outputFile.write((char *)(canvasImgInfo.data), canvasImgInfo.dataSize);
|
|
|
|
outputFile.close();
|
|
|
|
#if 1
|
|
// 加载测试
|
|
OHOS::ImageInfo *bmpImgInfo =
|
|
OHOS::ImageCacheManager::GetInstance().LoadSingleRes(PLAY_DIAL_DRAW_PREVIEW_BIN_PATH);
|
|
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", bmpImgInfo->header.version);
|
|
static_print_info("header.width: %u", bmpImgInfo->header.width);
|
|
static_print_info("header.height: %u", bmpImgInfo->header.height);
|
|
static_print_info("header.compressMode: %u", bmpImgInfo->header.compressMode);
|
|
static_print_info("header.colorMode: %u", bmpImgInfo->header.colorMode);
|
|
static_print_info("dataSize: %u", bmpImgInfo->dataSize);
|
|
static_print_info("color: %u", bmpImgInfo->color);
|
|
#endif
|
|
} else {
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
}
|
|
|
|
// 记得释放掉申请的内存数据
|
|
OHOS::ImageCacheFree(canvasImgInfo);
|
|
} else {
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
}
|
|
}
|
|
// clase PlayDialDrawMainView end
|
|
|
|
// class PlayDialDrawMakingIMGView start
|
|
static PlayDialDrawMakingIMGView *g_PlayDialDrawMakingIMGView{nullptr};
|
|
PlayDialDrawMakingIMGView::PlayDialDrawMakingIMGView()
|
|
{
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
g_PlayDialDrawMakingIMGView = this;
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0x00000000);
|
|
SetOnDragListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
|
|
logoBg_.SetPosition(0, 0, 466, 466);
|
|
auto logoBg_Res = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PLAY_DIAL_BJ, PLAY_DIAL_BIN_PATH);
|
|
if (logoBg_Res != nullptr) {
|
|
logoBg_.SetSrc(logoBg_Res);
|
|
}
|
|
|
|
// InitLabelHorCenter(titleTip_, 28, 307, 466, "加速计算中,请稍等...");
|
|
titleTip_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
titleTip_.SetTextId(STR_ID_408);
|
|
titleTip_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
|
titleTip_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
titleTip_.SetPosition(0, 307, 466, 47);
|
|
|
|
// 拨动动效:
|
|
const uint32_t resId[] = {
|
|
IMG_PLAY_DIAL_LOADING_01_06, IMG_PLAY_DIAL_LOADING_02_06, IMG_PLAY_DIAL_LOADING_03_06,
|
|
IMG_PLAY_DIAL_LOADING_04_06, IMG_PLAY_DIAL_LOADING_05_06, IMG_PLAY_DIAL_LOADING_06_06,
|
|
IMG_PLAY_DIAL_LOADING_07_06, IMG_PLAY_DIAL_LOADING_08_06, IMG_PLAY_DIAL_LOADING_09_06,
|
|
IMG_PLAY_DIAL_LOADING_10_06, IMG_PLAY_DIAL_LOADING_11_06,
|
|
};
|
|
auto &image = OHOS::ImageCacheManager::GetInstance();
|
|
OHOS::ImageAnimatorInfo logoMakingInfo = {nullptr, {174, 135}, 121, 121, OHOS::IMG_SRC_IMAGE_INFO};
|
|
|
|
for (int i = 0; i < 11; i++) {
|
|
logoMakingInfo_[i] = logoMakingInfo;
|
|
logoMakingInfo_[i].imageInfo = image.LoadOneInMultiRes(resId[i], PLAY_DIAL_BIN_PATH);
|
|
}
|
|
logoMaking_.SetPosition(174, 135, 121, 121);
|
|
logoMaking_.SetImageAnimatorSrc(logoMakingInfo_, 11, 100);
|
|
logoMaking_.SetAutoEnable(false);
|
|
logoMaking_.SetResizeMode(UIImageView::ImageResizeMode::FILL);
|
|
|
|
tick_ = 0;
|
|
if (logoTimer_ == nullptr) {
|
|
logoTimer_ = new OHOS::GraphicTimer(200, TimerCallBack, this, true);
|
|
}
|
|
|
|
Add(&logoBg_);
|
|
Add(&titleTip_);
|
|
Add(&logoMaking_);
|
|
}
|
|
|
|
PlayDialDrawMakingIMGView::~PlayDialDrawMakingIMGView(void)
|
|
{
|
|
logoMaking_.Stop();
|
|
if (logoTimer_ != nullptr) {
|
|
logoTimer_->Stop();
|
|
delete logoTimer_;
|
|
logoTimer_ = nullptr;
|
|
}
|
|
RemoveAll();
|
|
g_PlayDialDrawMakingIMGView = nullptr;
|
|
}
|
|
|
|
PlayDialDrawMakingIMGView *PlayDialDrawMakingIMGView::GetInstance(void) { return g_PlayDialDrawMakingIMGView; }
|
|
|
|
void PlayDialDrawMakingIMGView::TimerCallBackRun(void *arg)
|
|
{
|
|
PlayDialDrawMakingIMGView *p_inst = (PlayDialDrawMakingIMGView *)arg;
|
|
static_print_info("[%s][%d]: %s,Result_:%d-%d\n", __FILE__, __LINE__, __func__,
|
|
TjdUiAppPlayDialView::GetInstance().Result_, p_inst->tick_);
|
|
if (logoMaking_.GetState() != OHOS::Animator::START) {
|
|
logoMaking_.Start();
|
|
logoMaking_.SetVisible(true);
|
|
}
|
|
|
|
if (p_inst->tick_ <= 2 * 10) {
|
|
p_inst->tick_++;
|
|
} else {
|
|
// 超时了,跳转到表盘制作页
|
|
if (p_inst->logoTimer_ != nullptr) {
|
|
p_inst->logoTimer_->Stop();
|
|
p_inst->tick_ = 0;
|
|
}
|
|
// TjdUiAppPlayDialView::GetInstance().TipsIndex_ = PLAYDIAL_TIPS_FAIL;
|
|
TjdUiAppPlayDialView::GetInstance().TipsIndex_ = PLAYDIAL_TIPS_SUCCESS;
|
|
TjdUiAppPlayDialView::GetInstance().ShowView(PlayDialViewIndex::PLAYDIAL_AI_PREVIEW);
|
|
}
|
|
|
|
if (makeDone_ == false) {
|
|
makeDone_ = true;
|
|
PlayDialDrawMainView::GetInstance()->PersisCanvas();
|
|
}
|
|
}
|
|
|
|
void PlayDialDrawMakingIMGView::TimerCallBack(void *arg)
|
|
{
|
|
GraphicService::GetInstance()->PostGraphicEvent(
|
|
std::bind([](void *arg) { PlayDialDrawMakingIMGView::GetInstance()->TimerCallBackRun(arg); }, arg));
|
|
}
|
|
|
|
void PlayDialDrawMakingIMGView::ShowView()
|
|
{
|
|
TjdUiScreenManage::SetScreenKeepOnTimeout(LEFUN_AI_SCREEN_AUTO_OFF_TIME);
|
|
makeDone_ = false;
|
|
tick_ = 0;
|
|
SetVisible(true);
|
|
if (logoTimer_ != nullptr) {
|
|
logoTimer_->Start();
|
|
}
|
|
}
|
|
|
|
void PlayDialDrawMakingIMGView::HideView()
|
|
{
|
|
TjdUiScreenManage::ResetScreenKeepOnTimeout();
|
|
SetVisible(false);
|
|
logoMaking_.Stop();
|
|
if (logoTimer_ != nullptr) {
|
|
logoTimer_->Stop();
|
|
}
|
|
}
|
|
// class PlayDialDrawMakingIMGView end
|
|
|
|
// class PlayDialDrawPreviewView start
|
|
PlayDialDrawPreviewView::PlayDialDrawPreviewView()
|
|
{
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
|
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0x00000000);
|
|
SetOnDragListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
|
|
logoBg_.SetPosition(0, 0, 466, 466);
|
|
auto logoBg_Res = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PLAY_DIAL_BJ, PLAY_DIAL_BIN_PATH);
|
|
if (logoBg_Res != nullptr) {
|
|
logoBg_.SetSrc(logoBg_Res);
|
|
}
|
|
|
|
// InitLabelHorCenter(titleTop_, 28, 16, 466, "绘制表盘");
|
|
titleTop_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
titleTop_.SetTextId(STR_ID_580);
|
|
titleTop_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
titleTop_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
titleTop_.SetPosition(titleTop_.GetX() + HorizontalCenter(titleTop_.GetWidth(), 466), 16);
|
|
|
|
// InitLabelHorCenter(titleTip_, 28, 323, 466, "是否设置为表盘?");
|
|
titleTip_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
titleTip_.SetTextId(STR_ID_409);
|
|
titleTip_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
|
titleTip_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
|
titleTip_.SetPosition(titleTip_.GetX() + HorizontalCenter(titleTip_.GetWidth(), 466), 323);
|
|
|
|
logoBgPreview_.SetPosition(108, 58, 250, 250);
|
|
auto logoBgPreview_Res = OHOS::ImageCacheManager::GetInstance().LoadSingleRes(PLAY_DIAL_DRAW_PREVIEW_BIN_PATH);
|
|
if (logoBgPreview_Res != nullptr) {
|
|
logoBgPreview_.SetSrc(logoBgPreview_Res);
|
|
|
|
// 对背景进行缩放,生成展示的预览图
|
|
int16_t hor_res = logoBg_Res->header.width;
|
|
int16_t ver_res = logoBg_Res->header.height;
|
|
float hor_tar = 250;
|
|
float ver_tar = 250;
|
|
|
|
Vector2<float> scale = Vector2<float>(hor_tar / hor_res, ver_tar / ver_res);
|
|
Vector2<float> pivot = Vector2<float>(0, 0); //原点缩放
|
|
logoBgPreview_.Scale(scale, pivot);
|
|
|
|
OHOS::ImageInfo imgInfo;
|
|
if (logoBgPreview_.GetBitmap(imgInfo)) {
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", imgInfo.header.version);
|
|
static_print_info("header.width: %u", imgInfo.header.width);
|
|
static_print_info("header.height: %u", imgInfo.header.height);
|
|
static_print_info("header.compressMode: %u", imgInfo.header.compressMode);
|
|
static_print_info("header.colorMode: %u", imgInfo.header.colorMode);
|
|
static_print_info("dataSize: %u", imgInfo.dataSize);
|
|
static_print_info("color: %u", imgInfo.color);
|
|
}
|
|
}
|
|
|
|
clickLeft_.SetPosition(103, 326, 92, 92);
|
|
auto clickLeft_Res =
|
|
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PLAY_DIAL_ICON_NO, PLAY_DIAL_BIN_PATH);
|
|
if (clickLeft_Res != nullptr) {
|
|
clickLeft_.SetSrc(clickLeft_Res);
|
|
clickLeft_.SetViewId(PLAYDIAL_DRAW_PREVIEW_VIEW_BTN_LEFT_ID);
|
|
clickLeft_.SetOnClickListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
clickLeft_.SetTouchable(true);
|
|
}
|
|
|
|
clickRight_.SetPosition(271, 326, 92, 92);
|
|
auto clickRight_Res =
|
|
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PLAY_DIAL_ICON_CONFIRM, PLAY_DIAL_BIN_PATH);
|
|
if (clickRight_Res != nullptr) {
|
|
clickRight_.SetSrc(clickRight_Res);
|
|
clickRight_.SetViewId(PLAYDIAL_DRAW_PREVIEW_VIEW_BTN_RIGHT_ID);
|
|
clickRight_.SetOnClickListener(&TjdUiAppPlayDialPresenter::GetInstance());
|
|
clickRight_.SetTouchable(true);
|
|
}
|
|
|
|
Add(&logoBg_);
|
|
Add(&titleTop_);
|
|
Add(&titleTip_);
|
|
Add(&logoBgPreview_);
|
|
Add(&clickLeft_);
|
|
Add(&clickRight_);
|
|
}
|
|
|
|
void PlayDialDrawPreviewView::PersisImage()
|
|
{
|
|
// 生成展示的预览图持久化
|
|
OHOS::ImageInfo imgInfo;
|
|
if (logoBgPreview_.GetBitmap(imgInfo)) {
|
|
|
|
// 检查一下这些数据信息,然后怎么存下去??? 数据在imgInfo.data中
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", imgInfo.header.version);
|
|
static_print_info("header.width: %u", imgInfo.header.width);
|
|
static_print_info("header.height: %u", imgInfo.header.height);
|
|
static_print_info("header.compressMode: %u", imgInfo.header.compressMode);
|
|
static_print_info("header.colorMode: %u", imgInfo.header.colorMode);
|
|
static_print_info("dataSize: %u", imgInfo.dataSize);
|
|
static_print_info("color: %u", imgInfo.color);
|
|
|
|
ofstream outputFile;
|
|
outputFile.open(PLAY_DIAL_DRAW_PREVIEW_BIN_PATH,
|
|
ios::ios_base::binary | ios::ios_base::trunc | ios::ios_base::out);
|
|
|
|
if (outputFile.is_open() && outputFile.good()) {
|
|
char stream[128] = {0};
|
|
|
|
// 先写header
|
|
if (sizeof(ImageHeader) < 128) {
|
|
memcpy(stream, &imgInfo.header, sizeof(ImageHeader));
|
|
outputFile.write(stream, sizeof(ImageHeader));
|
|
}
|
|
// 后写data
|
|
outputFile.write((char *)(imgInfo.data), imgInfo.dataSize);
|
|
|
|
outputFile.close();
|
|
|
|
#if 1
|
|
// 加载测试
|
|
OHOS::ImageInfo *bmpImgInfo =
|
|
OHOS::ImageCacheManager::GetInstance().LoadSingleRes(PLAY_DIAL_DRAW_PREVIEW_BIN_PATH);
|
|
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
static_print_info("header.version: %u", bmpImgInfo->header.version);
|
|
static_print_info("header.width: %u", bmpImgInfo->header.width);
|
|
static_print_info("header.height: %u", bmpImgInfo->header.height);
|
|
static_print_info("header.compressMode: %u", bmpImgInfo->header.compressMode);
|
|
static_print_info("header.colorMode: %u", bmpImgInfo->header.colorMode);
|
|
static_print_info("dataSize: %u", bmpImgInfo->dataSize);
|
|
static_print_info("color: %u", bmpImgInfo->color);
|
|
#endif
|
|
} else {
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
}
|
|
|
|
// 记得释放掉申请的内存数据
|
|
OHOS::ImageCacheFree(imgInfo);
|
|
} else {
|
|
static_print_info("[%s][%d]: %s", __FILE__, __LINE__, __func__);
|
|
}
|
|
}
|
|
// class PlayDialDrawPreviewView end
|
|
|
|
} // namespace TJD
|