fabricjs 自定义类型
https://stackoverflow.com/questions/36660108/how-to-create-custom-fabricjs-object
I have to create a custom fabricjs object(say, fabric.Demo) which extends fabric.Group object. fabric.Demo object will be used to grouped other two fabric.Group objects. I have searched on the Internet and found only these links as useful.
But I'm getting this error 'this._objects is undefined'. I know I haven't write _render(). But I don't understand that what to code in _render(). If anyone knows the answer, it will be appreciated.
Here is my code.
(function (global) {
var fabric = global.fabric || (global.fabric = {}),
extend = fabric.util.object.extend,
clone = fabric.util.object.clone;
var stateProperties = fabric.Text.prototype.stateProperties.concat();
stateProperties.push(
'top',
'left'
);
fabric.Demo = fabric.util.createClass(fabric.Group, {
type: 'demo',
initialize: function () {
this.grp = new fabric.Group([], {
selectable: false,
padding: 0
});
this.grp.add([
new fabric.Group([
new fabric.Text('A', {top: 200, left: 200}),
new fabric.Text('B', {top: 200, left: 200})
]),
new fabric.Group([
new fabric.Text('C', {top: 200, left: 200}),
new fabric.Text('D', {top: 200, left: 200})
])
]);
},
_render: function (ctx) {
}
});
})(typeof exports !== 'undefined' ? exports : this);
---------------------------------------------------------------------------------------------------------------------------------------------------
If you want to extend Group you have to respect its basic function, render a handfull of objects stored in the _objects
array.
So when you initialize your class do not create a this.grp
.
instead push your 2 groups inside a _objects
array.
fabric.Demo = fabric.util.createClass(fabric.Group, {
type: 'demo',
initialize: function () {
this.grp = new fabric.Group([], {
selectable: false,
padding: 0
});
this._objects.push(
new fabric.Group([
new fabric.Text('A', {top: 200, left: 200}),
new fabric.Text('B', {top: 200, left: 200})
]));
this._objects.push(
new fabric.Group([
new fabric.Text('C', {top: 200, left: 200}),
new fabric.Text('D', {top: 200, left: 200})
]));
}
});
})(typeof exports !== 'undefined' ? exports : this);
extend render functions thinking what you need different from standard group, and do not forget to put the fromObject function if you want to load and restore your canvas.
fabricjs 自定义类型的更多相关文章
- 《精通C#》自定义类型转化-扩展方法-匿名类型-指针类型(11.3-11.6)
1.类型转化在C#中有很多,常用的是int类型转string等,这些都有微软给我们定义好的,我们需要的时候直接调用就是了,这是值类型中的转化,有时候我们还会需要类类型(包括结构struct)的转化,还 ...
- C#简单问题,不简单的原理:不能局部定义自定义类型(不含匿名类型)
今天在进行代码测试时发现,尝试在一个方法中定义一个委托,注意是定义一个委托,而不是声明一个委托变量,在编写的时候没有报错,VS也能智能提示,但在编译时却报语法不完整,缺少方括号,但实际查询并没有缺少, ...
- Struts2框架的自定义类型转换器
前言:对于java的基本数据类型及一些系统类(如Date类.集合类),Struts2提供了内置类型转换功能,但是也有一定的限制.所以就演示出自定义类型转换器 一.应用于局部类型转换器 eg.用户登录出 ...
- sruts2 自定义类型转换器
1.1.1 Struts2中自定义类型转换器:(了解) 类型转换的过程是双向的过程: JSP---->Action参数提交:String---Date. Action---->JSP ...
- 一个关于自定义类型作为HashMap的key的问题
在之前的项目需要用到以自定义类型作为HashMap的key,遇到一个问题:如果修改了已经存储在HashMap中的实例,会发生什么情况呢?用一段代码来试验: import java.util.HashM ...
- Struts2之自定义类型转换器
Struts2自定义类型转换器分为局部类型转换器和全局类型转换器 (1)局部类型转换器 如果页面传来一个参数reg.action?birthday=2010-11-12到后台action,然后属性用d ...
- [原创]java WEB学习笔记67:Struts2 学习之路-- 类型转换概述, 类型转换错误修改,如何自定义类型转换器
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 自定义类型转换器converter
作用:目前将日期转换成string,将string转换成我想要的类型 0509课件里讲 一.数据类型转换在web应用程序中,数据存在两个方向上的转换:1.当提交表单时 表单数据以字符串的形式提交 ...
- 用SQLData读写数据库自定义类型
如何读写自定义类型?SQLData是个很直观的解决办法 在oracle使用手册上找到了很好的资料 点击打开链接 http://docs.oracle.com/cd/B10501_01/java.920 ...
随机推荐
- vue动态(type可变)input绑定
遇到如下错误: v-model does not support dynamic input types 解决方法: vue 2.5.0以上,支持动态绑定 <input :type=" ...
- ACM-The Coco-Cola Store
题目: Once upon a time, there is a special coco-cola store. If you return three empty bottles to the s ...
- Java面试题之CyclicBarrier和CountDownLatch的区别
1.CyclicBarrier的某个线程运行到某个点后停止运行,直到所有线程都达到同一个点,所有线程才会重新运行: CountDownLatch线程运行到某个点后,计数值-1,该线程继续运行,直到计数 ...
- RHN Classic and Red Hat Subscription Management
What's the difference between RHN Classic and Red Hat Subscription Management? Introduction With the ...
- Linux下mknod详解
mknod - make block or character special filesmknod [OPTION]... NAME TYPE [MAJOR MINOR] option 有用的就是 ...
- 【Android开发日记】之入门篇(十一)——Android的Intent机制
继续我们的Android之路吧.今天我要介绍的是Android的Intent. 对于基于组件的应用开发而言,不仅需要构造和寻找符合需求的组件,更重要的是要将组件有机的连接起来,互联互通交换信息,才能够 ...
- 洛谷P3120 [USACO15FEB]Cow Hopscotch
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented ...
- 2590: [Usaco2012 Feb]Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 306 Solved: 154[Su ...
- 【原创】Linux环境下的图形系统和AMD R600显卡编程(4)——AMD显卡显存管理机制
显卡使用的内存分为两部分,一部分是显卡自带的显存称为VRAM内存,另外一部分是系统主存称为GTT内存(graphics translation table和后面的GART含义相同,都是指显卡的页表,G ...
- POCO库中文编程参考指南(6)Poco::Timestamp
1 类型别名 三个时间戳相关的类型别名,TimeDiff表示两个时间戳的差,第二个是以微秒为单位的时间戳,第三个是以 100 纳秒(0.1 微妙)为单位的时间戳: typedef Int64 Time ...