mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-03 12:48:56 +08:00
add picturedrawable and testcase
This commit is contained in:
parent
6cbbbf64aa
commit
e573a28e7a
1
src/gui/drawables.h
Normal file → Executable file
1
src/gui/drawables.h
Normal file → Executable file
@ -5,6 +5,7 @@
|
|||||||
#include <drawables/colordrawable.h>
|
#include <drawables/colordrawable.h>
|
||||||
#include <drawables/bitmapdrawable.h>
|
#include <drawables/bitmapdrawable.h>
|
||||||
#include <drawables/ninepatchdrawable.h>
|
#include <drawables/ninepatchdrawable.h>
|
||||||
|
#include <drawables/picturedrawable.h>
|
||||||
#include <drawables/gradientdrawable.h>
|
#include <drawables/gradientdrawable.h>
|
||||||
#include <drawables/transitiondrawable.h>
|
#include <drawables/transitiondrawable.h>
|
||||||
#include <drawables/drawablewrapper.h>
|
#include <drawables/drawablewrapper.h>
|
||||||
|
48
src/gui/drawables/picturedrawable.cc
Executable file
48
src/gui/drawables/picturedrawable.cc
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#include <drawables/picturedrawable.h>
|
||||||
|
|
||||||
|
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){
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
src/gui/drawables/picturedrawable.h
Executable file
24
src/gui/drawables/picturedrawable.h
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <drawables/drawable.h>
|
||||||
|
|
||||||
|
namespace cdroid{
|
||||||
|
|
||||||
|
typedef RefPtr<RecordingSurface>Picture;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -116,6 +116,28 @@ TEST_F(DRAWABLE,ninepatch2){
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DRAWABLE,picture){
|
||||||
|
Cairo::Rectangle rc={0,0,400,50};
|
||||||
|
RefPtr<RecordingSurface>picture= RecordingSurface::create(rc);
|
||||||
|
RefPtr<Cairo::Context>ctxpic=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){
|
TEST_F(DRAWABLE,transition){
|
||||||
std::vector<Drawable*>ds;
|
std::vector<Drawable*>ds;
|
||||||
ds.push_back(new ColorDrawable(0x80FF0000));
|
ds.push_back(new ColorDrawable(0x80FF0000));
|
||||||
|
Loading…
Reference in New Issue
Block a user