Commit 653f7e35 authored by wjf's avatar wjf

l

parents
# 所有空行或者以注释符号 # 开头的行都会被 Git 忽略。
# 可以使用标准的 glob 模式匹配。
# 匹配模式最后跟反斜杠(/)说明要忽略的是目录。
# 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(! )取反。
# 所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。星号(*)匹配零个或多个任
# 意字符; [abc] 匹配任何一个列在方括号中的字符(这个例子要么匹配一个 a,要么匹配一
# 个 b,要么匹配一个 c);问号(?)只匹配一个任意字符;如果在方括号中使用短划线分
# 隔两个字符,表示所有在这两个字符范围内的都可以匹配(比如 [0-9] 表示匹配所有 0 到
# 9 的数字)。
# 书上的一个例子
# #此为注释 – 将被 Git 忽略
# *.a
# 忽略所有 .a 结尾的文件
# !lib.a
# 但 lib.a 除外
# /TODO
# 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
# build/
# 忽略 build/ 目录下的所有文件
# doc/*.txt
# 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
node_modules
released
/**
* 基础
*/
export abstract class HashObject {
protected _instanceId: number = 0;
protected _instanceType: string = "HashObject";
protected static _object_id = 0;
constructor() {
this._instanceId = HashObject._object_id++;
}
/**
* 每一个对象都会有一个唯一的id码。
* @property instanceId
* @public
* @since 1.0.0
* @return {number}
* @readonly
* @example
* //获取 对象唯一码
* trace(this.instanceId);
*/
public get instanceId(): number {
return this._instanceId;
}
/**
* 每一个类都有一个实例类型字符串,通过这个字符串,你能知道这个实例是从哪个类实例而来
* @property instanceType
* @since 1.0.3
* @public
* @return {string}
* @readonly
*/
public get instanceType(): string {
return this._instanceType;
}
/**
* 销毁一个对象
* 销毁之前一定要从显示对象移除,否则将会出错
* @method destroy
* @since 2.0.0
* @public
* @return {void}
*/
abstract destroy(): void;
}
/**
* Created by rockyl on 2018/11/5.
*/
import { HashObject } from "../HashObject";
import { DisplayObject } from "../display/DisplayObject";
/**
* 组件基类
*/
export class Component extends HashObject {
/**
* 所依附的显示对象
*/
entity: DisplayObject;
/**
* 是否有效
*/
protected _enabled: boolean
constructor() {
super();
this._instanceType = "Component";
this.onCreate();
}
/**
* 是否有效状态
*/
get enabled(): boolean {
return this._enabled;
}
set enabled(value: boolean) {
if (this._enabled !== value) {
this._enabled = value;
if (this._enabled) {
this.onEnable();
} else {
this.onDisable();
}
}
}
/**
* 装配实体
* @param entity
*/
_setup(entity: DisplayObject) {
this.entity = entity;
}
/**
* 卸载实体
*/
_unSetup() {
this.entity = null;
}
/**
* 当组件被创建时
*/
onCreate() {
}
/**
* 当组件生效时
*/
onEnable() {
}
/**
* 当组件失效时
*/
onDisable() {
}
/**
* 更新
*/
onUpdate() {
}
/**
* 当组件被销毁时
*/
onDestroy() {
}
destroy() {
this.onDestroy();
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
import { Event } from "../events/Event";
import { DisplayObject } from "./DisplayObject";
import { devicePixelRatio } from "../const";
/**
* 此类对于需要在canvas上放置html其他类型元素的时候非常有用<br/>
* 比如有时候我们需要放置一个注册,登录或者其他的内容.这些内容包含了输入框<br/>
* 或者下拉框什么的,无法在canvas里实现,但这些元素又跟canvas里面的元素<br/>
* 位置,大小,缩放对应.就相当于是一个显示对象一样。可以随意设置他的<br/>
* 属性,那么将你的html元素通过此类封装成显示对象再合适不过了
* 不能用于容器
* @class FloatDisplay
* @extends DisplayObject
* @public
* @since 1.0.0
*/
export class FloatDisplay extends DisplayObject {
/**
* 需要封装起来的html元素的引用。你可以通过这个引用来调用或设置此元素自身的属性方法和事件,甚至是样式
* @property htmlElement
* @public
* @since 1.0.0
* @type{HtmlElement}
*/
public htmlElement: any = null;
/**
* 是否已经添加了舞台事件
* @property _isAdded
* @since 1.0.0
* @type {boolean}
* @private
*/
private _isAdded: boolean = false;
/**
* 记录是否需要修改位置矩阵
*/
private _transformID: number;
/**
* 构造函数
* @method FloatDisplay
* @since 1.0.0
* @public
* @example
* var floatDisplay = new FloatDisplay();
* floatDisplay.init(document.getElementById('aaa'));
* s.addChild(floatDisplay);
*
* <p><a href="" target="_blank">测试链接</a></p>
*
* @example
* //创建悬浮的html元素
* var section = document.createElement('section');
* section.id = "rule";
* section.style.overflowX = "hidden";
* section.style.overflowY = "auto";
* section.style.width = w + "px";
* section.style.height = h + "px";
* section.style.lineHeight = lh + "px";
* section.style.fontFamily = '微软雅黑';
* section.style.fontSize = fs + 'px';
* section.style.color = "#ffffff";
* //创建Floatview 把我们要悬浮的元素封装进去
* var rule = new FloatDisplay();
* stage.addChild(rule);
* rule.x = ox;
* rule.y = oy;
* rule.init(this.section);
* section.innerHTML = DataManager.ins.getData("ajaxElement").data.rule;
*
*/
public constructor() {
super();
let s = this;
s._instanceType = "FloatDisplay";
s.addEventListener(Event.REMOVED_FROM_STAGE, function (e: Event) {
if (s.htmlElement) {
s.htmlElement.style.display = "none";
}
});
s.addEventListener(Event.ADDED_TO_STAGE, function (e: Event) {
if (s.htmlElement) {
let style = s.htmlElement.style;
if (!s._isAdded) {
s._isAdded = true;
s.stage.rootDiv.insertBefore(s.htmlElement, s.stage.rootDiv.childNodes[0]);
s.stage["_floatDisplayList"].push(s);
} else {
if (s.htmlElement && s.visible) {
style.display = "block";
}
}
}
});
this._transformID = -1;
}
/**
* 初始化方法,htmlElement 一定要设置width和height样式,并且一定要用px单位
* @method init
* @public
* @since 1.0.0
* @param {HtmlElement} htmlElement 需要封装起来的html元素的引用。你可以通过这个引用来调用或设置此元素自身的属性方法和事件,甚至是样式
*/
public init(htmlElement: any): void {
let s = this;
let she: any;
if (typeof (htmlElement) == "string") {
she = document.getElementById(htmlElement);
} else if (htmlElement._instanceType == "Video") {
she = htmlElement.media;
} else {
she = htmlElement;
}
let style = she.style;
style.position = "absolute";
style.display = "none";
style.transformOrigin = style.WebkitTransformOrigin = "0 0 0";
let ws = s.getStyle(she, "width");
let hs = s.getStyle(she, "height");
let w = 0, h = 0;
if (ws.indexOf("px")) {
w = parseInt(ws);
}
if (hs.indexOf("px")) {
h = parseInt(hs);
}
// s._bounds.width = w;
// s._bounds.height = h;
s._localBoundsSelf.width = w;
s._localBoundsSelf.height = h;
s.htmlElement = she;
}
/**
* @method getStyle
* @param {HTMLElement} elem
* @param cssName
* @return {any}
*/
private getStyle(elem: HTMLElement, cssName: any): any {
//如果该属性存在于style[]中,则它最近被设置过(且就是当前的)
if (elem.style[cssName]) {
return elem.style[cssName];
}
if (document.defaultView && document.defaultView.getComputedStyle) {
//它使用传统的"text-Align"风格的规则书写方式,而不是"textAlign"
cssName = cssName.replace(/([A-Z])/g, "-$1");
cssName = cssName.toLowerCase();
//获取style对象并取得属性的值(如果存在的话)
let s = document.defaultView.getComputedStyle(elem, "");
return s && s.getPropertyValue(cssName);
}
return null;
}
/**
* @method updateStyle
* @public
* @since 1.1.4
*/
public updateStyle(): void {
let s = this;
let o = s.htmlElement;
if (o) {
let style = o.style;
let visible = s.visible;
//还得考虑是否在stage里
if (!s.stage) {
visible = false
}
if (visible) {
let parent = s.parent;
while (parent) {
if (!parent.visible) {
visible = false;
break;
}
parent = parent.parent;
}
}
let show = visible ? "block" : "none";
if (show != style.display) {
style.display = show;
}
if (visible) {
if (this._transformID != this.transform._worldID) {
this._transformID = this.transform._worldID
let mtx = s.transform.worldMatrix;
let d = devicePixelRatio;
style.transform = style.webkitTransform = "matrix(" + (mtx.a / d).toFixed(4) + "," + (mtx.b / d).toFixed(4) + "," + (mtx.c / d).toFixed(4) + "," + (mtx.d / d).toFixed(4) + "," + (mtx.tx / d).toFixed(4) + "," + (mtx.ty / d).toFixed(4) + ")";
}
style.opacity = s._worldAlpha;
}
}
}
public destroy(): void {
//清除相应的数据引用
let s = this;
let elem = s.htmlElement;
if (elem) {
elem.style.display = "none";
if (elem.parentNode) {
elem.parentNode.removeChild(elem);
}
s._isAdded = false;
s.htmlElement = null;
}
let sf: any = s.stage["_floatDisplayList"];
let len = sf.length;
for (let i = 0; i < len; i++) {
if (sf[i] == s) {
sf.splice(i, 1);
break;
}
}
super.destroy();
}
}
This diff is collapsed.
This diff is collapsed.
export { default as Container } from "./Container"
export * from "./DisplayObject"
export * from "./FloatDisplay"
export { default as Sprite } from "./Sprite"
export * from "./Stage"
\ No newline at end of file
import { HashObject } from "../HashObject";
/**
* 事件类,引擎中一切事件的基类
* @class Event
* @extends AObject
* @public
* @since 1.0.0
*/
export class Event extends HashObject {
// public static IMAGE_LOADED: string = "onImageLoaded"
/**
* 舞台尺寸发生变化时触发
* @Event
* @property RESIZE
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static RESIZE: string = "onResize";
/**
* ScrollPage组件滑动到开始位置事件
* @property SCROLL_TO_HEAD
* @static
* @since 1.1.0
* @type {string}
*/
public static SCROLL_TO_HEAD: string = "onScrollToHead";
/**
* ScrollPage组件停止滑动事件
* @property SCROLL_STOP
* @static
* @since 1.1.0
* @type {string}
*/
public static SCROLL_STOP: string = "onScrollStop";
/**
* ScrollPage组件开始滑动事件
* @property SCROLL_START
* @static
* @since 1.1.0
* @type {string}
*/
public static SCROLL_START: string = "onScrollStart";
/**
* ScrollPage组件滑动到结束位置事件
* @property ON_SCROLL_TO_END
* @static
* @since 1.1.0
* @type {string}
*/
public static SCROLL_TO_END: string = "onScrollToEnd";
/**
* 舞台初始化完成后会触发的事件
* @property INIT_STAGE
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static INIT_STAGE: string = "onInitStage";
/**
* 显示对象加入到舞台事件
* @Event
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static ADDED_TO_STAGE: string = "onAddedToStage";
/**
* 显示对象从舞台移出事件
* @Event
* @property REMOVE_TO_STAGE
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static REMOVED_FROM_STAGE: string = "onRemovedFromStage";
/**
* 显示对象 循环帧事件
* @Event
* @property ENTER_FRAME
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static ENTER_FRAME: string = "onEnterFrame";
/**
* MovieClip 播放完成事件
* @Event
* @property END_FRAME
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static END_FRAME: string = "onEndFrame";
/**
* MovieClip 帧标签事件
* @Event
* @property CALL_FRAME
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static CALL_FRAME: string = "onCallFrame";
/**
* 完成事件
* @Event
* @property COMPLETE
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static COMPLETE: string = "onComplete";
/**
* 加载过程事件
* @Event
* @property PROGRESS
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static PROGRESS: string = "onProgress";
/**
* 出错事件
* @Event
* @property ERROR
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static ERROR: string = "onError";
/**
* 中断事件
* @Event
* @property ABORT
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static ABORT: string = "onAbort";
/**
* 开始事件
* @Event
* @property START
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static START: string = "onStart";
/**
* 定时器触发事件
* @property TIMER
* @static
* @since 1.0.9
* @public
* @type {string}
*/
public static TIMER: string = "onTimer";
/**
* 定时器完成事件
* @property TIMER_COMPLETE
* @since 1.0.9
* @static
* @public
* @type {string}
*/
public static TIMER_COMPLETE: string = "onTimerComplete";
/**
* 事件类型名
* @property type
* @type {string}
* @public
* @since 1.0.0
*/
public type: string = "";
/**
* 触发此事件的对象
* @property target
* @public
* @since 1.0.0
* @type {any}
*/
public target: any = null;
/**
* 随着事件一起附带的信息对象
* 所有需要随事件一起发送的信息都可以放在此对象中
* @property data
* @public
* @since 1.0.0
* @type {any}
* @default null
*/
public data: any = null;
/**
* @method Event
* @param {string} type 事件类型
* @public
* @since 1.0.0
*/
public constructor(type: string) {
super();
this._instanceType = "Event";
this.type = type;
}
/**
* 防止对事件流中当前节点的后续节点中的所有事件侦听器进行处理。
* @method stopPropagation
* @public
* @since 2.0.0
* @return {void}
*/
public stopPropagation(): void {
this._pd = true;
}
/**
* 是否阻止事件向下冒泡
* @property _pd
* @type {boolean}
* @private
* @since 1.0.0
*/
private _pd: boolean = false;
public destroy(): void {
let s = this;
s.target = null;
s.data = null;
}
/**
* 重围事件到初始状态方便重复利用
* @method reset
* @param {string} type
* @param target
* @since 2.0.0
* @return {void}
* @public
*/
public reset(type: string, target: any): void {
let s = this;
s.target = target;
s._pd = false;
s.type = type;
}
}
This diff is collapsed.
export class GDispatcher {
/**
* 事件回调池
*/
private static callbackPool: any = {};
/**
* 事件作用域池
*/
private static thisObjPool: any = {};
/**
*
* @param name 事件名
* @param callback 回调
* @param thisObj 作用域
*/
public static addEvent(name: string, callback, thisObj?: any): void {
if (!this.callbackPool[name]) {
this.callbackPool[name] = [];
this.thisObjPool[name] = [];
}
const index: number = this.callbackPool[name].indexOf(callback);
if (index != -1) {
this.callbackPool[name][index] = callback;
this.thisObjPool[name][index] = thisObj;
} else {
this.callbackPool[name].push(callback);
this.thisObjPool[name].push(thisObj);
}
}
/**
*
* @param name 事件名
* @param callback 回调
* @param thisObj 作用域
*/
public static removeEvent(name: string, callback, thisObj?: any): void {
if (this.callbackPool[name]) {
var len = this.callbackPool[name].length;
for (let i = len - 1; i >= 0; i--) {
if (this.callbackPool[name][i] === callback && this.thisObjPool[name][i] == thisObj) {
this.callbackPool[name].splice(i, 1);
this.thisObjPool[name].splice(i, 1);
}
}
// const index: number = this.callbackPool[name].indexOf(callback);
// if (index != -1) {
// this.callbackPool[name].splice(index, 1);
// this.thisObjPool[name].splice(index, 1);
// }
}
}
/**
* 派发事件
* @param name 事件名
* @param args 任意参数
*/
public static dispatchEvent(name: string, ...args): void {
const callbacks: Function[] = this.callbackPool[name];
const thisObjs: any = this.thisObjPool[name];
if (callbacks) {
let i = 0;
const len: number = callbacks.length;
for (i; i < len; i++) {
callbacks[i].apply(thisObjs[i], args);
}
}
}
}
\ No newline at end of file
import { Event } from "./Event";
import { DisplayObject } from "../display/DisplayObject";
/**
* 鼠标事件类,电脑端鼠标,移动设备端的触摸都使用此事件来监听
* @class MouseEvent
* @extends Event
* @public
* @since 1.0.0
*/
export class MouseEvent extends Event {
/**
* 鼠标或者手指按下事件
* @property MOUSE_DOWN
* @static
* @public
* @since 1.0.0
* @type {string}
*/
public static MOUSE_DOWN: string = "onMouseDown";
/**
* 鼠标或者手指抬起事件
* @property MOUSE_UP
* @static
* @public
* @since 1.0.0
* @type {string}
*/
public static MOUSE_UP: string = "onMouseUp";
/**
* 鼠标或者手指单击
* @property CLICK
* @static
* @public
* @since 1.0.0
* @type {string}
*/
public static CLICK: string = "onMouseClick";
/**
* 鼠标或者手指移动事件
* @property MOUSE_MOVE
* @static
* @public
* @since 1.0.0
* @type {string}
*/
public static MOUSE_MOVE: string = "onMouseMove";
/**
* 鼠标或者手指移入到显示对象上里触发的事件
* @property MOUSE_OVER
* @static
* @public
* @since 1.0.0
* @type {string}
*/
public static MOUSE_OVER: string = "onMouseOver";
/**
* 鼠标或者手指移出显示对象边界触发的事件
* @property MOUSE_OUT
* @static
* @public
* @since 1.0.0
* @type {string}
*/
public static MOUSE_OUT: string = "onMouseOut";
/**
* mouse或touch事件时rootDiv坐标x点
* @property clientX
* @public
* @since 1.0.0
* @type {number}
*/
public clientX: number = 0;
/**
* mouse或touch事件时rootDiv坐标y点
* @property clientY
* @public
* @since 1.0.0
* @type {number}
*/
public clientY: number = 0;
/**
* mouse或touch事件时全局坐标x点
* @property stageX
* @public
* @since 1.0.0
* @type {number}
*/
public stageX: number = 0;
/**
* mouse或touch事件时全局坐标y点
* @property stageY
* @public
* @since 1.0.0
* @type {number}
*/
public stageY: number = 0;
/**
* mouse或touch事件时本地坐标x点
* @property localX
* @public
* @since 1.0.0
* @type {number}
*/
public localX: number = 0;
/**
* mouse或touch事件时本地坐标y点
* @property localY
* @public
* @since 1.0.0
* @type {number}
*/
public localY: number = 0;
/**
* 触发事件的终点对象
* @property currentTarget
* @public
* @since 1.0.0
* @type{DisplayObject}
* @default null
*/
public currentTarget: DisplayObject = null;
/**
* 触摸或者鼠标事件的手指唯一标识
* @property identifier
* @type {number}
* @since 1.1.2
* @public
*/
public identifier: any = 0;
/**
* @method MouseEvent
* @public
* @since 1.0.0
* @param {string} type
*/
public constructor(type: string) {
super(type);
this._instanceType = "MouseEvent";
}
/**
* 事件后立即更新显示列表状态
* @method updateAfterEvent
* @since 1.0.9
* @public
*/
public updateAfterEvent() {
this.target.stage._cp = true;
}
public destroy(): void {
//清除相应的数据引用
let s = this;
s.currentTarget = null;
super.destroy();
}
}
\ No newline at end of file
export * from "./Event";
export * from "./EventDispatcher";
export * from "./GDispatcher";
export * from "./MouseEvent";
\ No newline at end of file
import extractUniformsFromSrc from './extractUniformsFromSrc';
import { BLEND_MODES } from '../const';
import { uid } from '../utils';
import RenderTarget from '../renderers/renderTarget/RenderTarget';
const SOURCE_KEY_MAP = {};
/**
* 基本就是一个着色器,暂时不考虑集成GLShader,还不晓得咋搞
*/
export default class Filter {
//顶点着色器
vertexSrc: string;
//片元着色器
fragmentSrc: string;
// state,新的用stat,以后处理
private _blendMode: BLEND_MODES;
get blendMode(): BLEND_MODES {
return this._blendMode;
}
/**
* 别用先
*/
set blendMode(value: BLEND_MODES) {
this._blendMode = value;
}
uniformData: any;
/**
* An object containing the current values of custom uniforms.
* @example <caption>Updating the value of a custom uniform</caption>
* filter.uniforms.time = performance.now();
*
* @member {object}
*/
uniforms: any;
glShaders: any;
glShaderKey: string;
/**
* The padding of the filter. Some filters require extra space to breath such as a blur.
* Increasing this will add extra width and height to the bounds of the object that the
* filter is applied to.
*
* @member {number}
*/
padding: number;
/**
* The resolution of the filter. Setting this to be lower will lower the quality but
* increase the performance of the filter.
*
* @member {number}
*/
resolution: number;
/**
* If enabled is true the filter is applied, if false it will not.
*
* @member {boolean}
*/
enabled: boolean;
/**
* If enabled, PixiJS will fit the filter area into boundaries for better performance.
* Switch it off if it does not work for specific shader.
*
* @member {boolean}
*/
autoFit: boolean;
/**
* @param {string} [vertexSrc] - The source of the vertex shader.
* @param {string} [fragmentSrc] - The source of the fragment shader.
* @param {object} [uniforms] - Custom uniforms to use to augment the built-in ones.
*/
constructor(vertexSrc?: string, fragmentSrc?: string, uniforms?: any) {
this.vertexSrc = vertexSrc || Filter.defaultVertexSrc;
this.fragmentSrc = fragmentSrc || Filter.defaultFragmentSrc;
this._blendMode = BLEND_MODES.NORMAL;
this.uniformData = uniforms || extractUniformsFromSrc(this.vertexSrc, this.fragmentSrc);
this.uniforms = {};
for (const i in this.uniformData) {
this.uniforms[i] = this.uniformData[i].value;
if (this.uniformData[i].type) {
this.uniformData[i].type = this.uniformData[i].type.toLowerCase();
}
}
// this is where we store shader references..
// TODO we could cache this!
this.glShaders = {};
// used for cacheing.. sure there is a better way!
if (!SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc]) {
SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc] = uid();
}
this.glShaderKey = SOURCE_KEY_MAP[this.vertexSrc + this.fragmentSrc];
this.padding = 4;
this.resolution = 1;
this.enabled = true;
this.autoFit = true;
}
/**
* Applies the filter
*
* @param {FilterManager} filterManager - The renderer to retrieve the filter from
* @param {RenderTarget} input - The input render target.
* @param {RenderTarget} output - The target to output to.
* @param {boolean} clear - Should the output be cleared before rendering to it
* @param {object} [currentState] - It's current state of filter.
* There are some useful properties in the currentState :
* target, filters, sourceFrame, destinationFrame, renderTarget, resolution
*/
apply(filterManager, input: RenderTarget, output: RenderTarget, clear: boolean) {
filterManager.applyFilter(this, input, output, clear);
}
/**
* The default vertex shader source
*
* @static
* @constant
*/
private static get defaultVertexSrc() {
return [
'attribute vec2 aVertexPosition;',
'attribute vec2 aTextureCoord;',
'uniform mat3 projectionMatrix;',
'uniform mat3 filterMatrix;',
'varying vec2 vTextureCoord;',
'varying vec2 vFilterCoord;',
'void main(void){',
' gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);',
' vFilterCoord = ( filterMatrix * vec3( aTextureCoord, 1.0) ).xy;',
' vTextureCoord = aTextureCoord ;',
'}',
].join('\n');
}
/**
* The default fragment shader source
*
* @static
* @constant
*/
private static get defaultFragmentSrc() {
return [
'varying vec2 vTextureCoord;',
'varying vec2 vFilterCoord;',
'uniform sampler2D uSampler;',
'uniform sampler2D filterSampler;',
'void main(void){',
' vec4 masky = texture2D(filterSampler, vFilterCoord);',
' vec4 sample = texture2D(uSampler, vTextureCoord);',
' vec4 color;',
' if(mod(vFilterCoord.x, 1.0) > 0.5)',
' {',
' color = vec4(1.0, 0.0, 0.0, 1.0);',
' }',
' else',
' {',
' color = vec4(0.0, 1.0, 0.0, 1.0);',
' }',
// ' gl_FragColor = vec4(mod(vFilterCoord.x, 1.5), vFilterCoord.y,0.0,1.0);',
' gl_FragColor = mix(sample, masky, 0.5);',
' gl_FragColor *= sample.a;',
'}',
].join('\n');
}
}
import Filter from "../Filter";
import { defaultVert } from "../defaultVerts";
const adjustmentFrag = [
"precision mediump float;",
'varying vec2 vTextureCoord;',
'uniform sampler2D uSampler;',
'uniform float gamma;',
'uniform float contrast;',
'uniform float saturation;',
'uniform float brightness;',
'uniform float red;',
'uniform float green;',
'uniform float blue;',
'uniform float alpha;',
'void main(void)',
'{',
'vec4 c = texture2D(uSampler, vTextureCoord);',
'if (c.a > 0.0) {',
'c.rgb /= c.a;',
'vec3 rgb = pow(c.rgb, vec3(1. / gamma));',
'rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast);',
'rgb.r *= red;',
'rgb.g *= green;',
'rgb.b *= blue;',
'c.rgb = rgb * brightness;',
'c.rgb *= c.a;',
'}',
'gl_FragColor = c * alpha;',
'}'
].join("\n")
interface OptionsInt {
gamma?: number;
saturation?: number;
contrast?: number;
brightness?: number;
red?: number;
green?: number;
blue?: number;
alpha?: number;
}
/**
*
* @param {object} [options] - The optional parameters of the filter.
* @param {number} [options.gamma=1] - The amount of luminance
* @param {number} [options.saturation=1] - The amount of color saturation
* @param {number} [options.contrast=1] - The amount of contrast
* @param {number} [options.brightness=1] - The overall brightness
* @param {number} [options.red=1] - The multipled red channel
* @param {number} [options.green=1] - The multipled green channel
* @param {number} [options.blue=1] - The multipled blue channel
* @param {number} [options.alpha=1] - The overall alpha amount
*/
export class AdjustmentFilter extends Filter {
/**
* The amount of luminance
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
gamma: number = 1;
/**
* The amount of saturation
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
saturation: number = 1;
/**
* The amount of contrast
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
contrast: number = 1;
/**
* The amount of brightness
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
brightness: number = 1;
/**
* The amount of red channel
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
red: number = 1;
/**
* The amount of green channel
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
green: number = 1;
/**
* The amount of blue channel
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
blue: number = 1;
/**
* The amount of alpha channel
* @member {number}
* @memberof filters.AdjustmentFilter#
* @default 1
*/
alpha: number = 1;
constructor(options?: OptionsInt) {
super(defaultVert, adjustmentFrag);
if (typeof options == "object") {
Object.keys(options).forEach(e => { this[e] = options[e]; });
}
}
/**
* Override existing apply method in Filter
* @private
*/
apply(filterManager, input, output, clear) {
this.uniforms.gamma = Math.max(this.gamma, 0.0001);
this.uniforms.saturation = this.saturation;
this.uniforms.contrast = this.contrast;
this.uniforms.brightness = this.brightness;
this.uniforms.red = this.red;
this.uniforms.green = this.green;
this.uniforms.blue = this.blue;
this.uniforms.alpha = this.alpha;
filterManager.applyFilter(this, input, output, clear);
}
}
This diff is collapsed.
import Filter from "../Filter";
import { defaultVert } from "../defaultVerts";
const extractBrightnessFrag = [
"precision mediump float;",
'uniform sampler2D uSampler;',
'varying vec2 vTextureCoord;',
'uniform float threshold;',
'void main() {',
'vec4 color = texture2D(uSampler, vTextureCoord);',
// A simple & fast algorithm for getting brightness.
// It's inaccuracy , but good enought for this feature.
'float _max = max(max(color.r, color.g), color.b);',
'float _min = min(min(color.r, color.g), color.b);',
'float brightness = (_max + _min) * 0.5;',
'if(brightness > threshold) {',
'gl_FragColor = color;',
'} else {',
'gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);',
'}',
'}'
].join("\n")
/**
* Internal filter for AdvancedBloomFilter to get brightness.
* @class
* @private
* @param {number} [threshold=0.5] Defines how bright a color needs to be extracted.
*/
export class ExtractBrightnessFilter extends Filter {
constructor(threshold = 0.5) {
super(defaultVert, extractBrightnessFrag);
this.threshold = threshold;
}
/**
* Defines how bright a color needs to be extracted.
*
* @member {number}
* @default 0.5
*/
get threshold() {
return this.uniforms.threshold;
}
set threshold(value) {
this.uniforms.threshold = value;
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
export default function getMaxBlurKernelSize(gl) {
const maxVaryings = (gl.getParameter(gl.MAX_VARYING_VECTORS));
let kernelSize = 15;
while (kernelSize > maxVaryings) {
kernelSize -= 2;
}
return kernelSize;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
export { default as Graphics } from "./Graphics";
// export * from "./GraphicsData";//暂时不导。外部用不到暂时
export * from "./Shape";
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
export {default as Circle} from './Circle';
export {default as Ellipse} from './Ellipse';
export {default as Polygon} from './Polygon';
export {default as RoundedRectangle} from './RoundedRectangle';
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
export * from "./Loader"
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
export { Matrix } from './Matrix';
export { Point } from './Point';
export { ObservablePoint } from './ObservablePoint';
export { Rectangle } from './Rectangle';
// export {default as Transform} from './Transform';
export { default as Transform } from './Transform';
export { default as GroupD8 } from './GroupD8';
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment