mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-02 04:07:42 +08:00
add LayerDrawable::LayerState::getOpacity
This commit is contained in:
parent
266acaa448
commit
b7d9b87c09
@ -144,11 +144,46 @@ int LayerDrawable::LayerState::getChangingConfigurations()const{
|
||||
return mChangingConfigurations | mChildrenChangingConfigurations;
|
||||
}
|
||||
|
||||
int LayerDrawable::LayerState::getOpacity(){
|
||||
if (mCheckedOpacity) {
|
||||
return mOpacity;
|
||||
}
|
||||
|
||||
// Seek to the first non-null drawable.
|
||||
int firstIndex = -1;
|
||||
const size_t N = mChildren.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (mChildren[i]->mDrawable) {
|
||||
firstIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int op;
|
||||
if (firstIndex >= 0) {
|
||||
op = mChildren[firstIndex]->mDrawable->getOpacity();
|
||||
} else {
|
||||
op = PixelFormat::TRANSPARENT;
|
||||
}
|
||||
|
||||
// Merge all remaining non-null drawables.
|
||||
for (int i = firstIndex + 1; i < N; i++) {
|
||||
Drawable* dr = mChildren[i]->mDrawable;
|
||||
if (dr != nullptr) {
|
||||
op = Drawable::resolveOpacity(op, dr->getOpacity());
|
||||
}
|
||||
}
|
||||
|
||||
mOpacity = op;
|
||||
mCheckedOpacity = true;
|
||||
return op;
|
||||
}
|
||||
|
||||
bool LayerDrawable::LayerState::isStateful()const{
|
||||
bool isStateful = false;
|
||||
for (auto child:mChildren) {
|
||||
Drawable*dr=child->mDrawable;
|
||||
if (dr != nullptr && dr->isStateful()) {
|
||||
Drawable*dr = child->mDrawable;
|
||||
if (dr && dr->isStateful()) {
|
||||
isStateful = true;
|
||||
break;
|
||||
}
|
||||
@ -165,7 +200,7 @@ bool LayerDrawable::LayerState::hasFocusStateSpecified()const{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LayerDrawable::LayerState::canConstantState() {
|
||||
bool LayerDrawable::LayerState::canConstantState() const{
|
||||
for (auto child:mChildren) {
|
||||
Drawable* dr = child->mDrawable;
|
||||
if (dr && dr->getConstantState() == nullptr) {
|
||||
@ -940,12 +975,12 @@ int LayerDrawable::getOpacity() {
|
||||
if (mLayerState->mOpacityOverride != PixelFormat::UNKNOWN) {
|
||||
return mLayerState->mOpacityOverride;
|
||||
}
|
||||
return mLayerState->mOpacity;//getOpacity();
|
||||
return mLayerState->getOpacity();
|
||||
}
|
||||
|
||||
Drawable* LayerDrawable::getFirstNonNullDrawable()const{
|
||||
for(auto child:mLayerState->mChildren){
|
||||
Drawable*dr=child->mDrawable;
|
||||
Drawable*dr = child->mDrawable;
|
||||
if(dr)return dr;
|
||||
}
|
||||
return nullptr;
|
||||
@ -955,10 +990,8 @@ LayerDrawable*LayerDrawable::mutate(){
|
||||
if (!mMutated && Drawable::mutate() == this) {
|
||||
mLayerState = createConstantState(mLayerState.get(),nullptr);
|
||||
for (auto child:mLayerState->mChildren) {
|
||||
Drawable*dr=child->mDrawable;
|
||||
if (dr != nullptr) {
|
||||
dr->mutate();
|
||||
}
|
||||
Drawable*dr = child->mDrawable;
|
||||
if (dr)dr->mutate();
|
||||
}
|
||||
mMutated = true;
|
||||
}
|
||||
@ -970,8 +1003,7 @@ void LayerDrawable::clearMutated() {
|
||||
|
||||
for (auto child:mLayerState->mChildren) {
|
||||
Drawable* dr = child->mDrawable;
|
||||
if (dr)
|
||||
dr->clearMutated();
|
||||
if (dr)dr->clearMutated();
|
||||
}
|
||||
mMutated = false;
|
||||
}
|
||||
|
@ -47,9 +47,10 @@ protected:
|
||||
~LayerState();
|
||||
LayerDrawable*newDrawable()override;
|
||||
int getChangingConfigurations()const override;
|
||||
int getOpacity();
|
||||
bool isStateful()const;
|
||||
bool hasFocusStateSpecified()const;
|
||||
bool canConstantState();
|
||||
bool canConstantState()const;
|
||||
void invalidateCache();
|
||||
void setDensity(int targetDensity);
|
||||
virtual void onDensityChanged(int sourceDensity, int targetDensity);
|
||||
|
Loading…
Reference in New Issue
Block a user