mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-11-30 11:18:02 +08:00
rename Drawable.TRANSLUCENT... to PixelFormat,add some shapedrawables method
This commit is contained in:
parent
6e7f8229a3
commit
75708c4208
@ -16,12 +16,13 @@ namespace cdroid{
|
||||
Assets::Assets(){
|
||||
addResource("cdroid.pak","cdroid");
|
||||
}
|
||||
|
||||
Assets::Assets(const std::string&path):Assets(){
|
||||
addResource(path);
|
||||
mName=path;
|
||||
}
|
||||
|
||||
Assets::~Assets(){
|
||||
strings.clear();
|
||||
for(auto it=mResources.begin();it!=mResources.end();it++)
|
||||
delete it->second;
|
||||
mResources.clear();
|
||||
|
@ -155,44 +155,44 @@ bool BitmapDrawable::isAutoMirrored(){
|
||||
|
||||
int BitmapDrawable::computeTransparency(RefPtr<ImageSurface>bmp){
|
||||
if(bmp==nullptr||bmp->get_width()==0||bmp->get_height()==0)
|
||||
return Drawable::TRANSPARENT;
|
||||
return PixelFormat::TRANSPARENT;
|
||||
if((bmp->get_content()&Cairo::Content::CONTENT_ALPHA)==0)
|
||||
return Drawable::OPAQUE;
|
||||
return PixelFormat::OPAQUE;
|
||||
|
||||
if(bmp->get_content()&CONTENT_COLOR==0){
|
||||
switch(bmp->get_format()){
|
||||
case Surface::Format::A1: return Drawable::TRANSPARENT;//CAIRO_IMAGE_HAS_BILEVEL_ALPHA;
|
||||
case Surface::Format::A1: return PixelFormat::TRANSPARENT;//CAIRO_IMAGE_HAS_BILEVEL_ALPHA;
|
||||
case Surface::Format::A8:
|
||||
for(int y=0;y<bmp->get_height();y++){
|
||||
uint8_t*alpha=bmp->get_data()+bmp->get_stride()*y;
|
||||
for(int x=0;x<bmp->get_width();x++,alpha++)
|
||||
if(*alpha > 0 && *alpha < 255)
|
||||
return Drawable::TRANSLUCENT;//CAIRO_IMAGE_HAS_ALPHA;
|
||||
return PixelFormat::TRANSLUCENT;//CAIRO_IMAGE_HAS_ALPHA;
|
||||
}
|
||||
return Drawable::TRANSPARENT;//CAIRO_IMAGE_HAS_BILEVEL_ALPHA;
|
||||
default:return Drawable::TRANSLUCENT;
|
||||
return PixelFormat::TRANSPARENT;//CAIRO_IMAGE_HAS_BILEVEL_ALPHA;
|
||||
default:return PixelFormat::TRANSLUCENT;
|
||||
}
|
||||
}
|
||||
if(bmp->get_format()==Surface::Format::RGB16_565||bmp->get_format()==Surface::Format::RGB24)
|
||||
return Drawable::OPAQUE;
|
||||
return PixelFormat::OPAQUE;
|
||||
if(bmp->get_format()!=Surface::Format::ARGB32)
|
||||
return Drawable::TRANSLUCENT;
|
||||
return PixelFormat::TRANSLUCENT;
|
||||
for(int y=0;y<bmp->get_height();y++){
|
||||
uint32_t*pixel=(uint32_t*)(bmp->get_data()+bmp->get_stride()*y);
|
||||
for (int x = 0; x < bmp->get_width(); x++, pixel++){
|
||||
int a = (*pixel & 0xff000000) >> 24;
|
||||
if (a > 0 && a < 255)return Drawable::TRANSLUCENT;//CAIRO_IMAGE_HAS_ALPHA;
|
||||
else if(a==0)return Drawable::TRANSPARENT;//CAIRO_IMAGE_HAS_BILEVEL_ALPHA
|
||||
if (a > 0 && a < 255)return PixelFormat::TRANSLUCENT;//CAIRO_IMAGE_HAS_ALPHA;
|
||||
else if(a==0)return PixelFormat::TRANSPARENT;//CAIRO_IMAGE_HAS_BILEVEL_ALPHA
|
||||
}
|
||||
}
|
||||
return Drawable::OPAQUE;
|
||||
return PixelFormat::OPAQUE;
|
||||
}
|
||||
|
||||
int BitmapDrawable::getOpacity(){
|
||||
if(mBitmapState->mGravity != Gravity::FILL)
|
||||
return TRANSLUCENT;
|
||||
return PixelFormat::TRANSLUCENT;
|
||||
if(mBitmapState->mBitmap==nullptr)
|
||||
return TRANSPARENT;
|
||||
return PixelFormat::TRANSPARENT;
|
||||
|
||||
return mBitmapState->mTransparency;
|
||||
}
|
||||
|
@ -53,15 +53,15 @@ void ClipDrawable::setOrientation(int orientation){
|
||||
|
||||
int ClipDrawable::getOpacity(){
|
||||
Drawable* dr = getDrawable();
|
||||
if (dr->getOpacity() == Drawable::TRANSPARENT || dr->getLevel() == 0) {
|
||||
return Drawable::TRANSPARENT;
|
||||
if (dr->getOpacity() == PixelFormat::TRANSPARENT || dr->getLevel() == 0) {
|
||||
return PixelFormat::TRANSPARENT;
|
||||
}
|
||||
|
||||
if (getLevel() >= MAX_LEVEL) {
|
||||
return dr->getOpacity();
|
||||
}
|
||||
// Some portion of non-transparent drawable is showing.
|
||||
return Drawable::TRANSLUCENT;
|
||||
return PixelFormat::TRANSLUCENT;
|
||||
}
|
||||
|
||||
bool ClipDrawable::onLevelChange(int level){
|
||||
|
@ -4,9 +4,10 @@
|
||||
#include <core/canvas.h>
|
||||
namespace cdroid{
|
||||
enum TintMode{
|
||||
CLEAR =0,
|
||||
SRC =1,
|
||||
DST =2,
|
||||
NONOP =-1,
|
||||
CLEAR = 0,
|
||||
SRC = 1,
|
||||
DST = 2,
|
||||
SRC_OVER=3,
|
||||
DST_OVER=4,
|
||||
SRC_IN =5,
|
||||
|
@ -33,6 +33,13 @@ public:
|
||||
virtual bool unregisterAnimationCallback(AnimationCallback callback)=0;
|
||||
};
|
||||
|
||||
enum PixelFormat{
|
||||
UNKNOWN=0,
|
||||
TRANSLUCENT=1,
|
||||
TRANSPARENT=2,
|
||||
OPAQUE=3
|
||||
};
|
||||
|
||||
class Drawable{
|
||||
public:
|
||||
class Callback{
|
||||
@ -64,12 +71,6 @@ protected:
|
||||
virtual bool onLayoutDirectionChanged(int layoutDirection){return false;}
|
||||
virtual void onBoundsChange(const Rect& bounds){}
|
||||
public:
|
||||
enum Opacity{
|
||||
UNKNOWN=0,
|
||||
TRANSLUCENT=1,
|
||||
TRANSPARENT=2,
|
||||
OPAQUE=3
|
||||
};
|
||||
Drawable();
|
||||
virtual ~Drawable();
|
||||
void setBounds(int x,int y,int w,int h);
|
||||
|
@ -33,10 +33,12 @@ int ShapeDrawable::ShapeState::getChangingConfigurations()const{
|
||||
|
||||
ShapeDrawable::ShapeDrawable(std::shared_ptr<ShapeState>state){
|
||||
mShapeState=state;
|
||||
mTintFilter=nullptr;
|
||||
}
|
||||
|
||||
ShapeDrawable::ShapeDrawable(){
|
||||
mShapeState=std::make_shared<ShapeState>();
|
||||
mTintFilter=nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Drawable::ConstantState>ShapeDrawable::getConstantState(){
|
||||
@ -53,6 +55,22 @@ void ShapeDrawable::onBoundsChange(const Rect&bounds){
|
||||
updateShape();
|
||||
}
|
||||
|
||||
bool ShapeDrawable::onStateChange(const std::vector<int>&stateset){
|
||||
if(mShapeState->mTint&&mShapeState->mTintMode!=TintMode::NONOP){
|
||||
mTintFilter= updateTintFilter(mTintFilter,mShapeState->mTint,mShapeState->mTintMode);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ShapeDrawable::isStateful()const{
|
||||
return Drawable::isStateful()||(mShapeState->mTint&&mShapeState->mTint->isStateful());
|
||||
}
|
||||
|
||||
bool ShapeDrawable::hasFocusStateSpecified()const{
|
||||
return mShapeState->mTint&&mShapeState->mTint->hasFocusStateSpecified();
|
||||
}
|
||||
|
||||
Shape*ShapeDrawable::getShape()const{
|
||||
return mShapeState->mShape;
|
||||
}
|
||||
@ -82,6 +100,39 @@ void ShapeDrawable::setPadding(int left, int top, int right, int bottom){
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeDrawable::setAlpha(int alpha){
|
||||
mShapeState->mAlpha =alpha;
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
int ShapeDrawable::ShapeDrawable::getAlpha()const{
|
||||
return mShapeState->mAlpha;
|
||||
}
|
||||
|
||||
int ShapeDrawable::getOpacity(){
|
||||
switch(mShapeState->mAlpha){
|
||||
case 255: return PixelFormat::OPAQUE;
|
||||
case 0: return PixelFormat::TRANSPARENT;
|
||||
default : return PixelFormat::TRANSLUCENT;
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeDrawable::setTintList(ColorStateList*tint){
|
||||
mShapeState->mTint = tint;
|
||||
mTintFilter=updateTintFilter(mTintFilter,tint,mShapeState->mTintMode);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
void ShapeDrawable::setTintMode(int tintMode){
|
||||
mShapeState->mTintMode = tintMode;
|
||||
mTintFilter=updateTintFilter(mTintFilter,mShapeState->mTint,tintMode);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
void ShapeDrawable::setColorFilter(ColorFilter*colorFilter){
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
int ShapeDrawable::getIntrinsicWidth()const{
|
||||
return mShapeState->mIntrinsicWidth;
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ private:
|
||||
class ShapeState:public std::enable_shared_from_this<ShapeState>,public ConstantState{
|
||||
public:
|
||||
Shape*mShape;
|
||||
ColorStateList* mTint;
|
||||
int mTintMode;
|
||||
Rect mPadding;
|
||||
int mChangingConfigurations;
|
||||
int mIntrinsicWidth;
|
||||
@ -22,12 +24,14 @@ private:
|
||||
int getChangingConfigurations()const override;
|
||||
};
|
||||
bool mMutated;
|
||||
PorterDuffColorFilter*mTintFilter;
|
||||
std::shared_ptr<ShapeState>mShapeState;
|
||||
void updateShape();
|
||||
ShapeDrawable(std::shared_ptr<ShapeState>state);
|
||||
void updateLocalState();
|
||||
protected:
|
||||
void onBoundsChange(const Rect&bounds)override;
|
||||
bool onStateChange(const std::vector<int>&stateset)override;
|
||||
public:
|
||||
ShapeDrawable();
|
||||
|
||||
@ -36,11 +40,18 @@ public:
|
||||
bool getPadding(Rect&rect)override;
|
||||
void setPadding(const Rect& padding);
|
||||
void setPadding(int left, int top, int right, int bottom);
|
||||
|
||||
void setAlpha(int alpha)override;
|
||||
int getAlpha()const override;
|
||||
int getOpacity()override;
|
||||
void setTintList(ColorStateList*)override;
|
||||
void setTintMode(int tintMode)override;
|
||||
void setColorFilter(ColorFilter*colorFilter)override;
|
||||
int getIntrinsicWidth()const;
|
||||
int getIntrinsicHeight()const;
|
||||
void setIntrinsicWidth(int width);
|
||||
void setIntrinsicHeight(int height);
|
||||
bool isStateful()const override;
|
||||
bool hasFocusStateSpecified()const override;
|
||||
std::shared_ptr<ConstantState>getConstantState()override;
|
||||
Drawable*mutate()override;
|
||||
void clearMutated()override;
|
||||
|
BIN
src/gui/res/mipmap/ic_launcher.png
Executable file
BIN
src/gui/res/mipmap/ic_launcher.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
BIN
src/gui/res/mipmap/ic_search.png
Executable file
BIN
src/gui/res/mipmap/ic_search.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
BIN
src/gui/res/mipmap/progressbar_indeterminate1.png
Executable file
BIN
src/gui/res/mipmap/progressbar_indeterminate1.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 687 B |
BIN
src/gui/res/mipmap/progressbar_indeterminate2.png
Executable file
BIN
src/gui/res/mipmap/progressbar_indeterminate2.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 624 B |
BIN
src/gui/res/mipmap/progressbar_indeterminate3.png
Executable file
BIN
src/gui/res/mipmap/progressbar_indeterminate3.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 637 B |
@ -673,7 +673,7 @@ void DrawerLayout::computeScroll() {
|
||||
bool DrawerLayout::hasOpaqueBackground(View* v) {
|
||||
Drawable* bg = v->getBackground();
|
||||
if (bg != nullptr) {
|
||||
return bg->getOpacity() == Drawable::OPAQUE;
|
||||
return bg->getOpacity() == PixelFormat::OPAQUE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -2595,7 +2595,7 @@ void ListView::setDivider(Drawable* divider) {
|
||||
mDividerHeight = 0;
|
||||
}
|
||||
mDivider = divider;
|
||||
mDividerIsOpaque = divider == nullptr || divider->getOpacity() == Drawable::OPAQUE;
|
||||
mDividerIsOpaque = divider == nullptr || divider->getOpacity() == PixelFormat::OPAQUE;
|
||||
if(mAdapter && mItemCount)requestLayout();
|
||||
invalidate(true);
|
||||
}
|
||||
|
@ -720,7 +720,7 @@ bool View::isOpaque()const{
|
||||
}
|
||||
|
||||
void View::computeOpaqueFlags(){
|
||||
if (mBackground && mBackground->getOpacity() == Drawable::OPAQUE) {
|
||||
if (mBackground && mBackground->getOpacity() == PixelFormat::OPAQUE) {
|
||||
mPrivateFlags |= PFLAG_OPAQUE_BACKGROUND;
|
||||
} else {
|
||||
mPrivateFlags &= ~PFLAG_OPAQUE_BACKGROUND;
|
||||
|
Loading…
Reference in New Issue
Block a user