236 lines
7.2 KiB
C++
236 lines
7.2 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppPlayDialDrawView.h
|
|
*
|
|
* Author: liuguanwu
|
|
*
|
|
* Create: 2024-10
|
|
*--------------------------------------------------------------------------*/
|
|
#ifndef TJDUI_APP_PLAY_DIAL_DRAW_VIEW_H
|
|
#define TJDUI_APP_PLAY_DIAL_DRAW_VIEW_H
|
|
|
|
/*@brief 玩转表盘(play dial)
|
|
*/
|
|
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "View.h"
|
|
#include "components/ui_barcode.h"
|
|
#include "components/ui_button.h"
|
|
#include "components/ui_canvas.h"
|
|
#include "components/ui_canvas_ext.h"
|
|
#include "components/ui_checkbox.h"
|
|
#include "components/ui_edit_text.h"
|
|
#include "components/ui_image_animator.h"
|
|
#include "components/ui_image_view.h"
|
|
#include "components/ui_label.h"
|
|
#include "components/ui_list.h"
|
|
#include "components/ui_scroll_view.h"
|
|
#include "components/ui_slider.h"
|
|
#include "components/ui_swipe_view.h"
|
|
#include "components/ui_view_group.h"
|
|
#include "ui_chart.h"
|
|
#include "ui_image_animator.h"
|
|
#include "ui_image_view.h"
|
|
#include "ui_label.h"
|
|
#include "ui_slider.h"
|
|
#include "ui_swipe_view.h"
|
|
#include <cmath>
|
|
#include <vector>
|
|
#include "TjdUiAppPlayDialPresenter.h"
|
|
#include "TjdUiAppPlayDialView.h"
|
|
|
|
namespace TJD {
|
|
|
|
// @绘图表盘:起始
|
|
|
|
class PlayDialDrawHintView : public PlayDialViewBase
|
|
{
|
|
public:
|
|
PlayDialDrawHintView();
|
|
~PlayDialDrawHintView();
|
|
static PlayDialDrawHintView *GetInstance(void);
|
|
void ShowView()
|
|
{
|
|
SetVisible(true);
|
|
if (countdownTimer_ != nullptr) {
|
|
countdownTimer_->Start();
|
|
}
|
|
}
|
|
void HideView()
|
|
{
|
|
SetVisible(false);
|
|
if (countdownTimer_ != nullptr) {
|
|
countdownTimer_->Stop();
|
|
}
|
|
}
|
|
void TimerCallBackRun(void *arg);
|
|
static void TimerCallBack(void *arg);
|
|
|
|
private:
|
|
OHOS::UILabelExt titleMid_;
|
|
OHOS::GraphicTimer *countdownTimer_{nullptr};
|
|
};
|
|
|
|
enum PlayDialStyle
|
|
{
|
|
TRISYMMETRY = 3,//三对称
|
|
TETRASYMMTRY = 4,//四对称
|
|
PENTASYMMTRY = 5,//五对称
|
|
SYMMTRY_MAX
|
|
};
|
|
|
|
class PlayDialDrawMainView : public PlayDialViewBase
|
|
{
|
|
public:
|
|
PlayDialDrawMainView();
|
|
~PlayDialDrawMainView();
|
|
static PlayDialDrawMainView *GetInstance(void);
|
|
void ShowView() override;
|
|
void HideView() override;
|
|
|
|
void ClearPoint()
|
|
{
|
|
for(auto& vec : vectorPoints_) vec.clear();
|
|
}
|
|
void UpdatePoint(OHOS::Point point);
|
|
void PersisCanvas();
|
|
void TimerCallBackRun(void *arg);
|
|
static void TimerCallBack(void *arg);
|
|
|
|
private:
|
|
OHOS::UILabel previewTime_;
|
|
PlayDialStyle style_ = PENTASYMMTRY;
|
|
uint32_t tick_;
|
|
OHOS::UIImageView clickDown_;
|
|
OHOS::UIImageView clickDownIcon_;
|
|
OHOS::UICanvasExt canvasExt_;
|
|
OHOS::GraphicTimer *logoTimer_{nullptr};
|
|
|
|
std::vector<OHOS::Point> vectorPoints_[5]; // 五对称分支点序列
|
|
OHOS::LinearGradient sharedLinearGradient_;
|
|
OHOS::ColorStop sharedColorStops_[7] = {
|
|
// {0.0f, 0xFFfa1c18}, // 位置0: 红色
|
|
// {0.166f, 0xFFffec9f}, // 位置1/6: 橙色
|
|
// {0.333f, 0xFFff8b00}, // 位置1/3: 黄色
|
|
// {0.5f, 0xFFcfffb3}, // 位置1/2: 绿色
|
|
// {0.666f, 0xFF00e5bb}, // 位置2/3: 蓝色
|
|
// {0.833f, 0xFF24b5f4}, // 位置5/6: 靛色
|
|
// {1.0f, 0xFFea91f9} // 位置1: 紫色
|
|
|
|
// {0.0f, 0xFFe33524}, // 位置0: 红色
|
|
// {0.166f, 0xFFf6c59c}, // 位置1/6: 橙色
|
|
// {0.333f, 0xFFf8da54}, // 位置1/3: 黄色
|
|
// {0.5f, 0xFFd2eda6}, // 位置1/2: 绿色
|
|
// {0.666f, 0xFF003cff}, // 位置2/3: 蓝色
|
|
// {0.833f, 0xFFd1f2f7}, // 位置5/6: 靛色
|
|
// {1.0f, 0xFFc96bfd} // 位置1: 紫色
|
|
|
|
// {0.0f, 0xFFf04032}, // 位置0: 红色
|
|
// {0.166f, 0xFFe8c28a}, // 位置1/6: 橙色
|
|
// {0.333f, 0xFFfcbe01}, // 位置1/3: 黄色
|
|
// {0.5f, 0xFF88d08c}, // 位置1/2: 绿色
|
|
// {0.666f, 0xFF1b94ef}, // 位置2/3: 蓝色
|
|
// {0.833f, 0xFF9eadff}, // 位置5/6: 靛色
|
|
// {1.0f, 0xFFb817d4} // 位置1: 紫色
|
|
|
|
// {0.0f, 0xFFff8a81}, // 位置0: 红色
|
|
// {0.166f, 0xFFff7800}, // 位置1/6: 橙色
|
|
// {0.333f, 0xFFffebae}, // 位置1/3: 黄色
|
|
// {0.5f, 0xFF00ca51}, // 位置1/2: 绿色
|
|
// {0.666f, 0xFF80c8ff}, // 位置2/3: 蓝色
|
|
// {0.833f, 0xFF00d6bf}, // 位置5/6: 靛色
|
|
// {1.0f, 0xFFcca5ed} // 位置1: 紫色
|
|
|
|
{0.0f, 0xFFff574a}, // 位置0: 红色
|
|
{0.166f, 0xFFff7800}, // 位置1/6: 橙色
|
|
{0.333f, 0xFFffd861}, // 位置1/3: 黄色
|
|
{0.5f, 0xFF00ca51}, // 位置1/2: 绿色
|
|
{0.666f, 0xFF59b7ff}, // 位置2/3: 蓝色
|
|
{0.833f, 0xFF00d6bf}, // 位置5/6: 靛色
|
|
{1.0f, 0xFFb55eff} // 位置1: 紫色
|
|
};
|
|
|
|
#if 0
|
|
// 计算俩点距离
|
|
double PointDistance(OHOS::Point pos1, OHOS::Point pos2) {
|
|
double dx = pos1.x - pos2.x;
|
|
double dy = pos1.y - pos2.y;
|
|
return std::sqrt(dx * dx + dy * dy);
|
|
}
|
|
|
|
// 计算俩点中点
|
|
OHOS::Point MiddlePoint(OHOS::Point pos1, OHOS::Point pos2) {
|
|
return (OHOS::Point){.x = (pos1.x + pos2.x) / 2, .y = (pos1.y + pos2.y) / 2,};
|
|
}
|
|
|
|
// 多点平滑连线算法
|
|
std::vector<OHOS::Point> smoothedPolyline(std::vector<OHOS::Point> vectorPoint) {
|
|
|
|
if (vectorPoint.size() <= 2) {
|
|
return vectorPoint;
|
|
}
|
|
|
|
// 初始化中点向量
|
|
std::vector<OHOS::Point> vectorMiddle;
|
|
for (size_t i = 1; i < vectorPoint.size() - 1; ++i) {
|
|
vectorMiddle.push_back(MiddlePoint(vectorPoint[i - 1], vectorPoint[i]));
|
|
}
|
|
|
|
// 对中点递归平滑处理
|
|
std::vector<OHOS::Point> vectorSmooth = smoothedPolyline(vectorMiddle);
|
|
|
|
// 将平滑处理后的中点两两之间插入原始点,形成平滑连线
|
|
for (size_t i = 0; i < vectorSmooth.size(); ++i) {
|
|
vectorSmooth.insert(vectorSmooth.begin() + 2 * i + 1, vectorPoint[i]);
|
|
}
|
|
|
|
return vectorSmooth;
|
|
}
|
|
#endif
|
|
};
|
|
|
|
class PlayDialDrawMakingIMGView : public PlayDialViewBase
|
|
{
|
|
public:
|
|
PlayDialDrawMakingIMGView();
|
|
~PlayDialDrawMakingIMGView();
|
|
static PlayDialDrawMakingIMGView *GetInstance(void);
|
|
void ShowView() override;
|
|
void HideView() override;
|
|
void TimerCallBackRun(void *arg);
|
|
static void TimerCallBack(void *arg);
|
|
bool makeDone_ = false;
|
|
|
|
private:
|
|
uint32_t tick_;
|
|
OHOS::UILabelExt titleTip_;
|
|
OHOS::UIImageView logoBg_;
|
|
OHOS::ImageAnimatorInfo logoMakingInfo_[11];
|
|
OHOS::UIImageAnimatorView logoMaking_;
|
|
OHOS::GraphicTimer *logoTimer_{nullptr};
|
|
};
|
|
|
|
class PlayDialDrawPreviewView : public PlayDialViewBase
|
|
{
|
|
public:
|
|
PlayDialDrawPreviewView();
|
|
~PlayDialDrawPreviewView() { RemoveAll(); }
|
|
|
|
void PersisImage();
|
|
|
|
private:
|
|
OHOS::UILabelExt titleTop_;
|
|
OHOS::UILabelExt titleTip_;
|
|
OHOS::UIImageView logoBg_;
|
|
OHOS::UIImageView logoBgPreview_;
|
|
OHOS::UIImageView clickLeft_;
|
|
OHOS::UIImageView clickRight_;
|
|
};
|
|
|
|
// @绘图表盘:结束
|
|
|
|
} // namespace TJD
|
|
|
|
#endif
|