博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
绘图 Painter转接口封装的方式
阅读量:6709 次
发布时间:2019-06-25

本文共 2083 字,大约阅读时间需要 6 分钟。

 

 

记录下思想

适用于业务逻辑相对单纯的一些画法,比如画背景(颜色,背景,边框等)

一个Draw方法中如果绘制比较复杂的话,就会导致代码混乱,而不灵活,每次需求更改就得重新画过,可重用性差.

以接口的方式可以很好的重复利用功能,不必因为需求的更改而大量变更代码

chrome的方法定义如下

// Painting ------------------------------------------------------------------// Backgroundscoped_ptr
background_;// Border.scoped_ptr
border_;// Focus border.scoped_ptr
focus_border_;

 

// The background object is owned by this object and may be NULL.void set_background(Background* b) { background_.reset(b); }const Background* background() const { return background_.get(); }Background* background() { return background_.get(); }// The border object is owned by this object and may be NULL.void set_border(Border* b) { border_.reset(b); }const Border* border() const { return border_.get(); }Border* border() { return border_.get(); }// The focus_border object is owned by this object and may be NULL.void set_focus_border(FocusBorder* b) { focus_border_.reset(b); }const FocusBorder* focus_border() const { return focus_border_.get(); }FocusBorder* focus_border() { return focus_border_.get(); }

具体调用

void View::OnPaintBackground(gfx::Canvas* canvas) {  if (background_.get()) {    TRACE_EVENT2("views", "View::OnPaintBackground",                 "width", canvas->sk_canvas()->getDevice()->width(),                 "height", canvas->sk_canvas()->getDevice()->height());    background_->Paint(canvas, this);  }}void View::OnPaintBorder(gfx::Canvas* canvas) {  if (border_.get()) {    TRACE_EVENT2("views", "View::OnPaintBorder",                 "width", canvas->sk_canvas()->getDevice()->width(),                 "height", canvas->sk_canvas()->getDevice()->height());    border_->Paint(*this, canvas);  }}void View::OnPaintFocusBorder(gfx::Canvas* canvas) {  if (focus_border_.get() &&      HasFocus() && (focusable() || IsAccessibilityFocusable())) {    TRACE_EVENT2("views", "views::OnPaintFocusBorder",                 "width", canvas->sk_canvas()->getDevice()->width(),                 "height", canvas->sk_canvas()->getDevice()->height());    focus_border_->Paint(*this, canvas);  }}

转载地址:http://zrnlo.baihongyu.com/

你可能感兴趣的文章
【Android错误集锦】AppBarLayout is overlapping the RecyclerView in one of my xml files.
查看>>
Mybatis入门例子
查看>>
C#进阶系列——DDD领域驱动设计初探(一):聚合
查看>>
4.3. CMD
查看>>
第 16 章 Apache Hbase
查看>>
Linux Autotools
查看>>
【批处理学习笔记】第十三课:常用dos命令(3)
查看>>
笔试题练习(四)
查看>>
大数据的最大价值: 大数据+物体=智能
查看>>
一脸懵逼加从入门到绝望学习hadoop之Caused by: java.net.UnknownHostException: master报错...
查看>>
前端MVC学习总结(二)——AngularJS验证、过滤器、指令
查看>>
Mac环境下svn的使用
查看>>
人工智能成功识别“色情暴力”信息????
查看>>
Open edX 学习、开发、运维相关链接整理
查看>>
PHP中$_SERVER的详细参数与说明
查看>>
For input string: "null"
查看>>
基于密度的聚类之Dbscan算法
查看>>
Introduction to Partitioning
查看>>
SQL优化常用方法30
查看>>
Oracle备库无法连接主库的问题分析
查看>>