第三方框架改为仓内子集并完善构建忽略规则

完整 NIM_Duilib_Framework 仓库移至父目录,third_party 仅保留实际使用的 base、duilib、bin/resources 与许可证;.gitignore 覆盖 MSBuild 与打包产物。
This commit is contained in:
tongtong committed 2026-11-15 08:54:17 +08:00
1 parent 249e8548de
commit e1e26acc49
391 files changed
+342850

No files matched your search

@@ -0,0 +1,288 @@
#include "StdAfx.h"
namespace ui
{
AnimationManager::AnimationManager() : m_pControl(nullptr), m_animationMap()
{
}
AnimationManager::AnimationManager(const AnimationManager& r) : m_pControl(nullptr), m_animationMap()
{
}
AnimationPlayer* AnimationManager::GetAnimationPlayer(AnimationType animationType) const
{
auto it = m_animationMap.find(animationType);
if (it != m_animationMap.end()) {
return it->second.get();
}
else {
return nullptr;
}
}
AnimationPlayer* AnimationManager::SetFadeHot(bool bFadeHot)
{
AnimationPlayer* animationArgs = nullptr;
if (bFadeHot) {
animationArgs = new AnimationPlayer();
animationArgs->SetStartValue(0);
animationArgs->SetEndValue(255);
animationArgs->SetSpeedUpRatio(0.3);
animationArgs->SetSpeedDownRatio(0.7);
animationArgs->SetTotalMillSeconds(250);
std::function<void(int)> playCallback = nbase::Bind(&Control::SetHotAlpha, m_pControl, std::placeholders::_1);
animationArgs->SetCallback(playCallback);
m_animationMap[kAnimationHot].reset(animationArgs);
}
else {
m_animationMap.erase(kAnimationHot);
}
return animationArgs;
}
AnimationPlayer* AnimationManager::SetFadeAlpha(bool bFadeVisible)
{
AnimationPlayer* animationArgs = nullptr;
if (bFadeVisible) {
animationArgs = new AnimationPlayer();
animationArgs->SetStartValue(0);
animationArgs->SetEndValue(255);
animationArgs->SetSpeedUpRatio(0.3);
animationArgs->SetSpeedDownRatio(0.7);
animationArgs->SetTotalMillSeconds(250);
std::function<void(int)> playCallback = nbase::Bind(&Control::SetAlpha, m_pControl, std::placeholders::_1);
animationArgs->SetCallback(playCallback);
m_animationMap[kAnimationAlpha].reset(animationArgs);
m_pControl->SetAlpha(0);
}
else {
m_animationMap.erase(kAnimationAlpha);
m_pControl->SetAlpha(255);
}
return animationArgs;
}
AnimationPlayer* AnimationManager::SetFadeWidth(bool bFadeWidth)
{
AnimationPlayer* animationArgs = nullptr;
if (bFadeWidth) {
animationArgs = new AnimationPlayer();
animationArgs->SetStartValue(0);
CSize size(999999, 999999);
size = m_pControl->EstimateSize(size);
ASSERT(size.cy >= -2);
animationArgs->SetEndValue(size.cx);
animationArgs->SetSpeedUpRatio(0.3);
animationArgs->SetSpeedUpfactorA(0.00084);
animationArgs->SetSpeedDownRatio(0.7);
std::function<void(int)> playCallback = nbase::Bind(&Control::SetFixedWidth, m_pControl, std::placeholders::_1, true, false);
animationArgs->SetCallback(playCallback);
m_animationMap[kAnimationWidth].reset(animationArgs);
}
else {
m_animationMap.erase(kAnimationWidth);
}
return animationArgs;
}
AnimationPlayer* AnimationManager::SetFadeHeight(bool bFadeHeight)
{
AnimationPlayer* animationArgs = nullptr;
if (bFadeHeight) {
animationArgs = new AnimationPlayer();
animationArgs->SetStartValue(0);
CSize size(999999, 999999);
size = m_pControl->EstimateSize(size);
ASSERT(size.cy > 0);
animationArgs->SetEndValue(size.cy);
animationArgs->SetSpeedUpRatio(0.3);
animationArgs->SetSpeedUpfactorA(0.00084);
animationArgs->SetSpeedDownRatio(0.7);
std::function<void(int)> playCallback = nbase::Bind(&Control::SetFixedHeight, m_pControl, std::placeholders::_1, false);
animationArgs->SetCallback(playCallback);
m_animationMap[kAnimationHeight].reset(animationArgs);
}
else {
m_animationMap.erase(kAnimationHeight);
}
return animationArgs;
}
AnimationPlayer* AnimationManager::SetFadeInOutX(bool bFade, bool bIsFromRight)
{
AnimationPlayer* animationArgs = nullptr;
if (bFade) {
animationArgs = new AnimationPlayer();
CSize size(999999, 999999);
size = m_pControl->EstimateSize(size);
if (size.cx <= 0) {
size.cx = 100;
}
animationArgs->SetEndValue(0);
animationArgs->SetSpeedUpRatio(0.3);
animationArgs->SetSpeedUpfactorA(0.006);
animationArgs->SetSpeedDownRatio(0.7);
std::function<void(int)> playCallback = nbase::Bind(&Control::SetRenderOffsetX, m_pControl, std::placeholders::_1);
animationArgs->SetCallback(playCallback);
if (bIsFromRight) {
animationArgs->SetStartValue(-size.cx);
m_animationMap[kAnimationInoutXFromRight].reset(animationArgs);
}
else {
animationArgs->SetStartValue(size.cx);
m_animationMap[kAnimationInoutXFromLeft].reset(animationArgs);
}
}
else if (!bFade){
if (bIsFromRight) {
m_animationMap.erase(kAnimationInoutXFromRight);
}
else {
m_animationMap.erase(kAnimationInoutXFromLeft);
}
}
return animationArgs;
}
AnimationPlayer* AnimationManager::SetFadeInOutY(bool bFade, bool bIsFromBottom)
{
AnimationPlayer* animationArgs = nullptr;
if (bFade) {
animationArgs = new AnimationPlayer();
CSize size(999999, 999999);
size = m_pControl->EstimateSize(size);
if (size.cy <= 0) {
size.cy = 100;
}
animationArgs->SetEndValue(0);
animationArgs->SetSpeedUpRatio(0.3);
animationArgs->SetSpeedUpfactorA(0.006);
animationArgs->SetSpeedDownRatio(0.7);
std::function<void(int)> playCallback = nbase::Bind(&Control::SetRenderOffsetY, m_pControl, std::placeholders::_1);
animationArgs->SetCallback(playCallback);
if (bIsFromBottom) {
animationArgs->SetStartValue(-size.cy);
m_animationMap[kAnimationInoutYFromBottom].reset(animationArgs);
}
else {
animationArgs->SetStartValue(size.cy);
m_animationMap[kAnimationInoutYFromTop].reset(animationArgs);
}
}
else if (!bFade){
if (bIsFromBottom) {
m_animationMap.erase(kAnimationInoutYFromBottom);
}
else {
m_animationMap.erase(kAnimationInoutYFromTop);
}
}
return animationArgs;
}
void AnimationManager::Appear()
{
m_pControl->SetVisible_(true);
if (GetAnimationPlayer(kAnimationAlpha)) {
m_animationMap[kAnimationAlpha]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationAlpha]->Continue();
}
if (GetAnimationPlayer(kAnimationWidth)) {
m_animationMap[kAnimationWidth]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationWidth]->Continue();
}
if (GetAnimationPlayer(kAnimationHeight)) {
m_animationMap[kAnimationHeight]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationHeight]->Continue();
}
if (GetAnimationPlayer(kAnimationInoutXFromLeft)) {
m_animationMap[kAnimationInoutXFromLeft]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationInoutXFromLeft]->Continue();
}
if (GetAnimationPlayer(kAnimationInoutXFromRight)) {
m_animationMap[kAnimationInoutXFromRight]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationInoutXFromRight]->Continue();
}
if (GetAnimationPlayer(kAnimationInoutYFromTop)) {
m_animationMap[kAnimationInoutYFromTop]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationInoutYFromTop]->Continue();
}
if (GetAnimationPlayer(kAnimationInoutYFromBottom)) {
m_animationMap[kAnimationInoutYFromBottom]->SetCompleteCallback(CompleteCallback());
m_animationMap[kAnimationInoutYFromBottom]->Continue();
}
}
void AnimationManager::Disappear()
{
bool handled = false;
CompleteCallback completeCallback = nbase::Bind(&Control::SetVisible_, m_pControl, false);
if (GetAnimationPlayer(kAnimationAlpha)) {
m_animationMap[kAnimationAlpha]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationAlpha]->ReverseContinue();
handled = true;
}
if (GetAnimationPlayer(kAnimationWidth)) {
m_animationMap[kAnimationWidth]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationWidth]->ReverseContinue();
handled = true;
}
if (GetAnimationPlayer(kAnimationHeight)) {
m_animationMap[kAnimationHeight]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationHeight]->ReverseContinue();
handled = true;
}
if (GetAnimationPlayer(kAnimationInoutXFromLeft)) {
m_animationMap[kAnimationInoutXFromLeft]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationInoutXFromLeft]->ReverseContinue();
handled = true;
}
if (GetAnimationPlayer(kAnimationInoutXFromRight)) {
m_animationMap[kAnimationInoutXFromRight]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationInoutXFromRight]->ReverseContinue();
handled = true;
}
if (GetAnimationPlayer(kAnimationInoutYFromTop)) {
m_animationMap[kAnimationInoutYFromTop]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationInoutYFromTop]->ReverseContinue();
handled = true;
}
if (GetAnimationPlayer(kAnimationInoutYFromBottom)) {
m_animationMap[kAnimationInoutYFromBottom]->SetCompleteCallback(completeCallback);
m_animationMap[kAnimationInoutYFromBottom]->ReverseContinue();
handled = true;
}
if (!handled) {
m_pControl->SetVisible_(false);
}
}
void AnimationManager::MouseEnter()
{
if (GetAnimationPlayer(kAnimationHot)) {
m_animationMap[kAnimationHot]->Continue();
}
}
void AnimationManager::MouseLeave()
{
if (GetAnimationPlayer(kAnimationHot)) {
m_animationMap[kAnimationHot]->ReverseContinue();
}
}
}
@@ -0,0 +1,38 @@
#ifndef UI_ANIMATION_ANIMATIONMANAGER_H_
#define UI_ANIMATION_ANIMATIONMANAGER_H_
#pragma once
namespace ui
{
class UILIB_API AnimationManager
{
public:
AnimationManager();
AnimationManager(const AnimationManager& r);
AnimationManager& operator=(const AnimationManager& r) = delete;
void Init(Control* control) { m_pControl = control; }
AnimationPlayer* GetAnimationPlayer(AnimationType animationType) const;
AnimationPlayer* SetFadeHot(bool bFadeHot);
AnimationPlayer* SetFadeAlpha(bool bFadeVisible);
AnimationPlayer* SetFadeWidth(bool bFadeWidth);
AnimationPlayer* SetFadeHeight(bool bFadeHeight);
AnimationPlayer* SetFadeInOutX(bool bFade, bool bIsFromRight);
AnimationPlayer* SetFadeInOutY(bool bFade, bool bIsFromBottom);
void Appear();
void Disappear();
void MouseEnter();
void MouseLeave();
private:
Control *m_pControl;
std::map<AnimationType, std::unique_ptr<AnimationPlayer>> m_animationMap;
};
} // namespace ui
#endif // UI_ANIMATION_ANIMATIONMANAGER_H_
@@ -0,0 +1,260 @@
#include "StdAfx.h"
#include "AnimationPlayer.h"
namespace ui
{
AnimationPlayerBase::AnimationPlayerBase() : m_bFirstRun(true), m_animationType(0)
{
Init();
}
void AnimationPlayerBase::Reset()
{
m_weakFlagOwner.Cancel();
Init();
}
void AnimationPlayerBase::Init()
{
m_startValue = 0;
m_endValue = 0;
m_currentValue = 0;
m_totalMillSeconds = DUI_NOSET_VALUE;
m_palyedMillSeconds = 0;
m_elapseMillSeconds = 0;
m_currentTime.QuadPart = 0;
m_timeFrequency.QuadPart = 0;
m_reverseStart = false;
m_bPlaying = false;
}
void AnimationPlayerBase::Start()
{
m_weakFlagOwner.Cancel();
m_palyedMillSeconds = 0;
m_reverseStart = false;
StartTimer();
}
void AnimationPlayerBase::Stop()
{
m_weakFlagOwner.Cancel();
}
void AnimationPlayerBase::Continue()
{
m_weakFlagOwner.Cancel();
if (m_reverseStart == true)
ReverseAllValue();
m_reverseStart = false;
StartTimer();
m_bFirstRun = false;
}
void AnimationPlayerBase::ReverseContinue()
{
m_weakFlagOwner.Cancel();
if (m_reverseStart == false)
ReverseAllValue();
if (m_bFirstRun)
m_palyedMillSeconds = 0;
m_reverseStart = true;
StartTimer();
m_bFirstRun = false;
}
void AnimationPlayerBase::StartTimer()
{
QueryPerformanceFrequency(&m_timeFrequency);
QueryPerformanceCounter(&m_currentTime);
m_bPlaying = true;
if (m_endValue - m_startValue == 0) {
Complete();
return;
}
m_elapseMillSeconds = m_totalMillSeconds / abs(m_endValue - m_startValue);
if (m_elapseMillSeconds == 0) {
m_elapseMillSeconds = 1;
}
Play();
auto playCallback = nbase::Bind(&AnimationPlayerBase::Play, this);
TimerManager::GetInstance()->AddCancelableTimer(m_weakFlagOwner.GetWeakFlag(), playCallback, m_elapseMillSeconds, TimerManager::REPEAT_FOREVER);
}
void AnimationPlayerBase::Play()
{
LARGE_INTEGER newCurrentTime;
QueryPerformanceCounter(&newCurrentTime);
m_palyedMillSeconds += (double(newCurrentTime.QuadPart - m_currentTime.QuadPart) * 1000 )/m_timeFrequency.QuadPart;
QueryPerformanceCounter(&m_currentTime);
int newCurrentValue = GetCurrentValue();
if (m_playCallback) {
if (m_endValue > m_startValue && newCurrentValue >= m_endValue
|| m_endValue < m_startValue && newCurrentValue <= m_endValue) {
newCurrentValue = m_endValue;
m_playCallback(newCurrentValue);
Complete();
}
else {
if (newCurrentValue != m_currentValue) {
m_playCallback(newCurrentValue);
}
}
}
else {
ASSERT(FALSE);
}
m_currentValue = newCurrentValue;
}
void AnimationPlayerBase::ReverseAllValue()
{
std::swap(m_startValue, m_endValue);
m_currentValue = m_startValue;
m_palyedMillSeconds = m_totalMillSeconds - m_palyedMillSeconds;
if (m_palyedMillSeconds < 0)
m_palyedMillSeconds = 0;
}
void AnimationPlayerBase::Complete()
{
if (m_completeCallback)
m_completeCallback();
m_weakFlagOwner.Cancel();
m_bPlaying = false;
}
AnimationPlayer::AnimationPlayer()
{
Init();
}
void AnimationPlayer::Init()
{
__super::Init();
m_speedUpRatio = 0;
m_speedDownRatio = 0;
m_speedDownMillSeconds = 0;
m_linerMillSeconds = 0;
m_linearSpeed = 0;
m_speedUpfactorA = 0;
m_speedDownfactorA = 0;
m_speedDownfactorB = 0;
m_maxTotalMillSeconds = 1000000;
}
void AnimationPlayer::StartTimer()
{
InitFactor();
__super::StartTimer();
}
int AnimationPlayer::GetCurrentValue()
{
if (m_palyedMillSeconds >= m_totalMillSeconds) {
return m_endValue;
}
int detaValue = 0;
if (m_palyedMillSeconds <= m_speedUpMillSeconds) {
detaValue = int(m_speedUpfactorA * m_palyedMillSeconds * m_palyedMillSeconds);
}
else if (m_palyedMillSeconds <= (m_speedUpMillSeconds + m_linerMillSeconds)) {
double linerTime = m_palyedMillSeconds - m_speedUpMillSeconds;
detaValue = int(m_speedUpfactorA * m_speedUpMillSeconds * m_speedUpMillSeconds + m_linearSpeed * linerTime);
}
else if (m_palyedMillSeconds <= m_totalMillSeconds) {
double speedDownTime = m_palyedMillSeconds - m_speedUpMillSeconds - m_linerMillSeconds;
detaValue = int(m_speedUpfactorA * m_speedUpMillSeconds * m_speedUpMillSeconds + m_linearSpeed * m_linerMillSeconds
+ m_speedDownfactorA * speedDownTime * speedDownTime + m_speedDownfactorB * speedDownTime);
}
else {
ASSERT(FALSE);
}
int currentValue = 0;
if (m_endValue > m_startValue) {
currentValue = m_startValue + detaValue;
}
else {
currentValue = m_startValue - detaValue;
}
return currentValue;
}
void AnimationPlayer::InitFactor()
{
double s = abs(m_endValue - m_startValue);
if (m_speedUpRatio == 0 && m_speedDownRatio == 0) { //liner
ASSERT(m_totalMillSeconds == DUI_NOSET_VALUE && m_linearSpeed != 0 || m_totalMillSeconds != DUI_NOSET_VALUE && m_linearSpeed == 0);
if (m_totalMillSeconds == DUI_NOSET_VALUE) {
m_totalMillSeconds = int(s / m_linearSpeed);
}
else {
m_linearSpeed = s / m_totalMillSeconds;
}
m_linerMillSeconds = m_totalMillSeconds;
}
else {
if (m_totalMillSeconds != DUI_NOSET_VALUE) {
if (m_speedUpRatio != 0) {
m_speedUpfactorA = s / ((m_speedUpRatio*m_speedUpRatio + (1 - m_speedUpRatio - m_speedDownRatio)*2*m_speedUpRatio + m_speedUpRatio*m_speedDownRatio)
*m_totalMillSeconds*m_totalMillSeconds);
}
else if (m_speedDownRatio != 0) {
m_speedDownfactorA = -s / ((m_speedDownRatio*m_speedDownRatio + (1 - m_speedUpRatio - m_speedDownRatio)*2*m_speedDownRatio + m_speedUpRatio*m_speedDownRatio)
*m_totalMillSeconds*m_totalMillSeconds);
}
else {
ASSERT(FALSE);
}
}
double tmpValue = 0;
if (m_speedUpfactorA != 0 && m_speedUpRatio != 0) {
tmpValue = m_speedUpfactorA * m_speedUpRatio;
if (m_speedDownRatio != 0) {
m_speedDownfactorA = -m_speedUpfactorA * m_speedUpRatio / m_speedDownRatio;
}
}
else if (m_speedDownfactorA != 0 && m_speedDownRatio != 0) {
tmpValue = -m_speedDownfactorA * m_speedDownRatio;
if (m_speedUpRatio != 0) {
m_speedUpfactorA = -m_speedDownfactorA * m_speedDownRatio / m_speedUpRatio;
}
}
else {
ASSERT(FALSE);
}
if (m_totalMillSeconds == DUI_NOSET_VALUE) {
m_totalMillSeconds = int(sqrt(s / (m_speedUpfactorA*m_speedUpRatio*m_speedUpRatio + (1 - m_speedUpRatio - m_speedDownRatio) * 2 * tmpValue
- m_speedDownfactorA*m_speedDownRatio*m_speedDownRatio) ));
if (m_totalMillSeconds > m_maxTotalMillSeconds) {
m_totalMillSeconds = m_maxTotalMillSeconds;
InitFactor();
return;
}
}
m_linearSpeed = 2 * tmpValue * m_totalMillSeconds;
m_speedDownfactorB = m_linearSpeed;
m_speedUpMillSeconds = m_totalMillSeconds * m_speedUpRatio;
m_speedDownMillSeconds = m_totalMillSeconds * m_speedDownRatio;
m_linerMillSeconds = m_totalMillSeconds - m_speedUpMillSeconds - m_speedDownMillSeconds;
}
}
}
@@ -0,0 +1,108 @@
#ifndef UI_ANIMATION_ANIMATIONPLAYER_H_
#define UI_ANIMATION_ANIMATIONPLAYER_H_
#pragma once
namespace ui
{
typedef std::function<void (int)> PlayCallback;
typedef std::function<void (void)> CompleteCallback;
class UILIB_API AnimationPlayerBase : public nbase::SupportWeakCallback
{
public:
AnimationPlayerBase();
~AnimationPlayerBase() { }
void SetAnimationType(int type) { m_animationType = type; };
int GetAnimationType() const { return m_animationType; };
void SetStartValue(int startValue) { m_startValue = startValue; }
int GetStartValue() { return m_startValue; }
void SetEndValue(int endValue) { m_endValue = endValue; }
int GetEndValue() { return m_endValue; }
void SetTotalMillSeconds(int totalMillSeconds) { m_totalMillSeconds = totalMillSeconds; }
bool IsPlaying() { return m_bPlaying; }
bool IsFirstRun() { return m_bFirstRun; }
void SetCallback(const PlayCallback& callback) { m_playCallback = callback; }
void SetCompleteCallback(const CompleteCallback& callback) { m_completeCallback = callback; }
void Reset();
virtual void Init();
virtual void Start();
virtual void Stop();
virtual void Continue();
virtual void ReverseContinue();
virtual void StartTimer();
virtual int GetCurrentValue() = 0;
private:
void Play();
void ReverseAllValue();
void Complete();
protected:
int m_animationType;
int m_startValue;
int m_endValue;
int m_currentValue;
int m_totalMillSeconds;
double m_palyedMillSeconds;
int m_elapseMillSeconds;
bool m_bFirstRun;
bool m_bPlaying;
bool m_reverseStart;
PlayCallback m_playCallback;
CompleteCallback m_completeCallback;
LARGE_INTEGER m_currentTime;
LARGE_INTEGER m_timeFrequency;
nbase::WeakCallbackFlag m_weakFlagOwner;
};
class UILIB_API AnimationPlayer : public AnimationPlayerBase
{
public:
AnimationPlayer();
virtual void Init() override;
virtual void StartTimer() override;
virtual int GetCurrentValue() override;
void InitFactor();
virtual void SetSpeedUpfactorA(double factorA) { m_speedUpfactorA = factorA; }
virtual void SetSpeedDownfactorA(double factorA) { m_speedDownfactorA = factorA; }
void SetMaxTotalMillSeconds(int maxTotalMillSeconds) { m_maxTotalMillSeconds = maxTotalMillSeconds; }
void SetLinearSpeed(double linearSpeed) { m_linearSpeed = linearSpeed; }
void SetSpeedUpRatio(double speedUpRatio) { m_speedUpRatio = speedUpRatio; }
void SetSpeedDownRatio(double speedDownRatio) { m_speedDownRatio = speedDownRatio; }
private:
double m_speedUpRatio;
double m_speedDownRatio;
double m_speedUpMillSeconds;
double m_linearSpeed;
double m_linerMillSeconds;
double m_speedDownMillSeconds;
double m_speedUpfactorA;
double m_speedDownfactorA;
double m_speedDownfactorB;
int m_maxTotalMillSeconds;
};
} // namespace ui
#endif // UI_ANIMATION_ANIMATIONPLAYER_H_