Class: Image

Ycc.UI. Image

new Ycc.UI.Image(option)

图片UI
Name Type Description
option object 所有可配置的配置项
Name Type Default Description
rect Ycc.Math.Rect 容纳区。会根据属性设置动态修改。
fillMode string none 填充方式
none -- 无填充方式。左上角对齐,超出隐藏,不修改rect大小。
repeat -- 重复。左上角对齐,重复平铺图片,不修改rect大小,超出隐藏。
scale -- 缩放。左上角对齐,缩放至整个rect区域,不修改rect大小。
scaleRepeat -- 先缩放再重复。左上角对齐,缩放至某个rect区域,再重复填充整个rect区域,不修改rect大小。
auto -- 自动。左上角对齐,rect大小自动适配图片。若图片超出rect,会动态修改rect大小。
scale9Grid -- 9宫格模式填充。左上角对齐,中间区域将拉伸,不允许图片超出rect区域大小,不会修改rect大小。
res Image 需要填充的图片资源。注:必须已加载完成。
mirror Number 将图片镜像绘制方式
0 -- 无
1 -- 上下颠倒
2 -- 左右翻转
3 -- 上下左右颠倒
scale9GridRect Ycc.Math.Rect 9宫格相对于res图片的中间区域,当且仅当fillMode为scale9Grid有效。

Extends

Members

anchorXnumber

UI对象的锚点坐标。相对坐标。相对于rect的x 锚点坐标主要用于图形的旋转、平移、缩放

anchorYnumber

UI对象的锚点坐标。相对坐标。相对于rect的y 锚点坐标主要用于图形的旋转、平移、缩放

baseUIYcc.UI

基础绘图UI

belongToYcc.Layer

UI所属的图层

coordinatesnull

多边形点坐标的数组,为保证图形能够闭合,起点和终点必须相等

ctxnull

绘图环境

ctxCachenull

缓存的绘图环境

disableTypeObject

被禁用的事件类型。key为type,val为boolean

dpinumber

设备像素比

fillboolean

是否填充

fillModestring

填充方式
none -- 无填充方式。左上角对齐,超出隐藏,不修改rect大小。
repeat -- 重复。左上角对齐,重复平铺图片,不修改rect大小,超出隐藏。
scale -- 缩放。左上角对齐,缩放至整个rect区域,不修改rect大小。
auto -- 自动。左上角对齐,rect大小自动适配图片。若图片超出rect,会动态修改rect大小。
scale9Grid -- 9宫格模式填充。左上角对齐,中间区域将拉伸,不允许图片超出rect区域大小,不会修改rect大小。 *

fillStylestring

颜色

ghostboolean

是否幽灵状态,默认false 幽灵状态的UI:只能用于显示,不可点击,事件也不会触发,其子元素的事件也不会触发,不能通过getUIFromPointer获取 用于解决多个UI重叠时是否需要穿透,以点击被覆盖UI的问题

idnumber

UI的唯一ID

isDrawIndexboolean

是否绘制点的下标

isShowRotateBeforeUIboolean

是否显示缩放之前的位置

lineWidthnumber

线条宽度

listenersObject

所有的监听器。key为type,val为listener数组。

mirrornumber

图片颠倒方式
0 -- 无
1 -- 左右颠倒
2 -- 上下翻转
3 -- 上下左右颠倒

namestring

UI实例的名字

noneZeroModenumber

光线投射模式 1-升级模式 2-普通模式

onclickfunction

点击 的监听。默认为null

oncomputeendfunction

计算属性后的hook

oncomputestartfunction

计算属性前的hook

ondragendfunction

拖拽结束 的监听。默认为null

ondraggingfunction

拖拽 的监听。默认为null

ondragstartfunction

拖拽开始 的监听。默认为null

onmousedownfunction

鼠标按下 的监听。默认为null

onmousemovefunction

鼠标移动 的监听。默认为null

onmouseoutfunction

鼠标移出 的监听。默认为null

onmouseoverfunction

鼠标移入 的监听。默认为null

onmouseupfunction

鼠标抬起 的监听。默认为null

onrenderendfunction

渲染后的hook

onrenderstartfunction

渲染前的hook

ontapfunction

点击事件 的监听。默认为null

ontouchendfunction

触摸结束 的监听。默认为null

ontouchmovefunction

触摸移动 的监听。默认为null

ontouchstartfunction

触摸开始 的监听。默认为null

opacitynumber

透明度
UI的绘图区域

rectBgColorstring

容纳区的背景色

rectBorderColorstring

容纳区边框颜色

rectBorderWidthnumber

容纳区的边框宽度

resImage

需要填充的图片资源。注:必须已加载完成。

rotationnumber

相对于锚点的旋转角度

scale9GridRectYcc.Math.Rect

9宫格相对于res图片的中间区域,当且仅当fillMode为scale9Grid有效。

scaleRepeatRectnull

缩放重复模式下,原始图片的缩放区域,当且仅当fillMode为scaleRepeat有效。

showboolean

是否显示

stopAllEventboolean

只会阻止当前UI事件的触发,不会阻止其下面子元素事件的触发

stopEventBubbleUpboolean

默认情况下,UI阻止事件冒泡,但不会阻止事件传播给图层

stopTypeObject

被阻止的事件类型。key为type,val为boolean

strokeStylestring

线条颜色

userDatanull

用户自定义的数据

readonlyxnumber

位置x

readonlyynumber

位置y

yccClass

构造器的引用,Ycc中的每个类都有此属性

Methods

添加子ui
Name Type Description
ui
Returns:
Type Description
Ycc.UI.Base

inherited addListener(type, listener)

添加某个类型的监听器
Name Type Description
type string
listener function
克隆ui
Returns:
Type Description
Ycc.UI

inherited containDot(dot, noneZeroMode){boolean}

重载基类的包含某个点的函数,用于点击事件等的响应 两种方法: 方法一:经过该点的水平射线与多边形的焦点数,即Ray-casting Algorithm 方法二:某个点始终位于多边形逆时针向量的左侧、或者顺时针方向的右侧即可判断,算法名忘记了 此方法采用方法一,并假设该射线平行于x轴,方向为x轴正方向
Name Type Description
dot Ycc.Math.Dot 需要判断的点,绝对坐标
noneZeroMode Number 是否noneZeroMode 1--启用 2--关闭 默认启用 从这个点引出一根“射线”,与多边形的任意若干条边相交,计数初始化为0,若相交处被多边形的边从左到右切过,计数+1,若相交处被多边形的边从右到左切过,计数-1,最后检查计数,如果是0,点在多边形外,如果非0,点在多边形内
Returns:
Type Description
boolean
禁止某个事件触发
Name Type Description
type
合并参数,只会合并对象中已存在的key
Name Type Description
option
Returns:
Type Description
Ycc.UI
获取能容纳当前UI的最小方形区域
Returns:
Type Description
Ycc.Math.Rect
获取当前UI在树结构中的深度

inherited getMaxContentInWidth(content, width){string}

给定宽度,获取能容纳的最长单行字符串
Name Type Description
content string 文本内容
width number 指定宽度
Returns:
Type Description
string
在某个图层中初始化UI
Name Type Description
layer Layer 图层
判断当前区域在某个区域外
Name Type Description
rect Ycc.Math.Rect

inherited isOutOfStage(){boolean}

判断ui是否存在于舞台之外,渲染时可以不予渲染 在compute之后使用,判断更准确
Returns:
Type Description
boolean
删除子ui
Name Type Description
ui

inherited removeListener(type, listener)

移除某个类型的监听器
Name Type Description
type
listener
删除自身。 若子类包含多个UI,需要重载
绘制
根据coordinates绘制路径 只绘制路径,不填充、不描边 继承的子类若不是多边形,需要重载此方法
开启离屏canvas后,此过程只会发生在离屏canvas中
Name Type Description
ctx 离屏canvas的绘图环境

inherited renderRectBgColor(absoluteRect)

渲染容纳区rect的背景色
开启离屏canvas后,此过程只会发生在离屏canvas中
Name Type Description
absoluteRect Ycc.Math.Rect 容纳区的绝对位置

inherited renderRectBorder(absoluteRect)

渲染容纳区rect的边框
开启离屏canvas后,此过程只会发生在离屏canvas中
Name Type Description
absoluteRect Ycc.Math.Rect 容纳区的绝对位置
恢复某个事件的触发
Name Type Description
type
坐标系的缩放和旋转。 先缩放、再旋转。
TODO
  • 子类渲染前需要调用此方法
  • 多边形替换rect后,此方法废弃,不再调用
阻止某个事件类型继续传递
Name Type Description
type
根据当前的锚点、旋转角度获取某个点的转换之后的坐标
Name Type Description
dot Ycc.Math.Dot | Array.<Ycc.Math.Dot> 需要转换的点,该点为相对坐标,相对于当前UI的父级
Returns:
Type Description
Ycc.Math.Dot 转换后的点,该点为绝对坐标

inherited transformToAbsolute(dotOrArr){Ycc.Math.Dot|Array.<Ycc.Math.Dot>}

根据图层坐标和UI位置坐标,将某个点的相对坐标(相对于UI的父级),转换为舞台的绝对坐标
Name Type Description
dotOrArr Ycc.Math.Dot | Array.<Ycc.Math.Dot>
Returns:
Type Description
Ycc.Math.Dot | Array.<Ycc.Math.Dot>

inherited transformToLocal(dotOrArr){Ycc.Math.Dot|Array.<Ycc.Math.Dot>}

根据图层坐标和UI位置坐标,将某个点的绝对坐标,转换为相对于UI父级的相对坐标
Name Type Description
dotOrArr Ycc.Math.Dot | Array.<Ycc.Math.Dot>
Returns:
Type Description
Ycc.Math.Dot | Array.<Ycc.Math.Dot>

inherited triggerListener(type, data)

触发某一类型的监听器
Name Type Description
type
data

inherited triggerUIEventBubbleUp(type, x, y, originEvent){Array.<Ycc.UI>}

冒泡触发UI的事件
Name Type Description
type
x
y
originEvent ycc事件所对应的原始事件
Returns:
Type Description
Array.<Ycc.UI> 返回已触发事件的UI列表