diff --git a/src/gui/drawables.h b/src/gui/drawables.h old mode 100644 new mode 100755 index a72aa991..919918cf --- a/src/gui/drawables.h +++ b/src/gui/drawables.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/src/gui/drawables/picturedrawable.cc b/src/gui/drawables/picturedrawable.cc new file mode 100755 index 00000000..cc691dbf --- /dev/null +++ b/src/gui/drawables/picturedrawable.cc @@ -0,0 +1,48 @@ +#include + +namespace cdroid{ + +PictureDrawable::PictureDrawable(Picture picture){ + mPicture=picture; +} + +Picture PictureDrawable::getPicture(){ + return mPicture; +} + +void PictureDrawable::setPicture(Picture picture){ + mPicture=picture; +} + +void PictureDrawable::draw(Canvas& canvas){ + if (mPicture) { + Rect bounds = getBounds(); + canvas.save(); + canvas.set_source(mPicture,bounds.x, bounds.y); + canvas.rectangle(bounds.x, bounds.y,bounds.width, bounds.height); + canvas.clip(); + canvas.paint(); + canvas.restore(); + } +} + +int PictureDrawable::getIntrinsicWidth()const{ + return mPicture ? mPicture->ink_extents().width : -1; +} + +int PictureDrawable::getIntrinsicHeight()const{ + return mPicture ? mPicture->ink_extents().height: -1; +} + +int PictureDrawable::getOpacity(){ + // not sure, so be safe + return TRANSLUCENT; +} + +void PictureDrawable::setColorFilter(ColorFilter* colorFilter) { +} + +void PictureDrawable::setAlpha(int alpha){ +} + +} diff --git a/src/gui/drawables/picturedrawable.h b/src/gui/drawables/picturedrawable.h new file mode 100755 index 00000000..9cc75472 --- /dev/null +++ b/src/gui/drawables/picturedrawable.h @@ -0,0 +1,24 @@ +#pragma once +#include + +namespace cdroid{ + +typedef RefPtrPicture; + +class PictureDrawable:public Drawable{ +private: + Picture mPicture; +public: + PictureDrawable(Picture picture); + Picture getPicture(); + void setPicture(Picture picture); + void draw(Canvas& canvas); + int getIntrinsicWidth()const override; + + int getIntrinsicHeight()const override; + int getOpacity()override; + void setColorFilter(ColorFilter* colorFilter); + void setAlpha(int alpha)override; +}; + +} diff --git a/tests/gui/drawable_tests.cc b/tests/gui/drawable_tests.cc index 55cf0cd2..ded8a524 100755 --- a/tests/gui/drawable_tests.cc +++ b/tests/gui/drawable_tests.cc @@ -116,6 +116,28 @@ TEST_F(DRAWABLE,ninepatch2){ delete d; } +TEST_F(DRAWABLE,picture){ + Cairo::Rectangle rc={0,0,400,50}; + RefPtrpicture= RecordingSurface::create(rc); + RefPtrctxpic=Cairo::Context::create(picture); + ctxpic->set_source_rgba(1,1,1,1); + ctxpic->rectangle(0,0,400,50); + ctxpic->fill(); + ctxpic->set_source_rgba(1,0,0,1); + ctxpic->move_to(50,20); + ctxpic->set_font_size(32); + ctxpic->show_text("PictureDrawable"); + ctxpic->fill(); + ctxpic->set_source_rgba(0,1,0,.5); + ctxpic->arc(200,25,50,0,M_PI*2.f); + ctxpic->fill(); + PictureDrawable*pd=new PictureDrawable(picture); + pd->setBounds(100,100,400,50); + + pd->draw(*ctx); + delete pd; +} + TEST_F(DRAWABLE,transition){ std::vectords; ds.push_back(new ColorDrawable(0x80FF0000));