Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
renderingEngine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王剑峰
renderingEngine
Commits
f987a9a6
Commit
f987a9a6
authored
Nov 08, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改代理
parent
8b44bc20
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
203 additions
and
197 deletions
+203
-197
index.js
dist/index.js
+104
-111
index.js.map
dist/index.js.map
+1
-1
auto-adjust.ts
src/zeroing/decorators/auto-adjust.ts
+86
-65
events.ts
src/zeroing/decorators/events.ts
+3
-3
scripts.ts
src/zeroing/decorators/scripts.ts
+9
-17
No files found.
dist/index.js
View file @
f987a9a6
This diff is collapsed.
Click to expand it.
dist/index.js.map
View file @
f987a9a6
This diff is collapsed.
Click to expand it.
src/zeroing/decorators/auto-adjust.ts
View file @
f987a9a6
...
...
@@ -6,59 +6,89 @@
import
{
Event
}
from
"../../2d/events"
;
/**
* 自适应数据
*/
export
class
AdjustData
{
percentWidth
:
number
=
NaN
;
percentHeight
:
number
=
NaN
;
left
:
number
=
NaN
;
top
:
number
=
NaN
;
right
:
number
=
NaN
;
bottom
:
number
=
NaN
;
horizonCenter
:
number
=
NaN
;
verticalCenter
:
number
=
NaN
;
}
function
t
(
v
)
{
return
!
isNaN
(
v
)
&&
v
!==
null
&&
v
!==
undefined
;
}
/**
* 应用自适应
* @param ctor
*/
export
function
applyAutoAdjust
(
ctor
:
Function
)
{
ctor
.
prototype
.
applyAutoAdjust
=
function
()
{
let
adjustData
=
new
AdjustData
();
this
.
__sizeDirty
=
true
;
this
.
adjustData
=
adjustData
;
this
.
addEventListener
(
Event
.
ADDED_TO_STAGE
,
this
.
__onAddedToStageAA
,
this
);
this
.
addEventListener
(
Event
.
REMOVED_FROM_STAGE
,
this
.
__onRemovedFromStageAA
,
this
);
};
ctor
.
prototype
.
__onAddedToStageAA
=
function
()
{
this
.
parent
.
addEventListener
(
Event
.
RESIZE
,
this
.
__onResizeAA
,
this
);
this
.
addEventListener
(
Event
.
ENTER_FRAME
,
this
.
__onEnterFrameAA
,
this
);
};
ctor
.
prototype
.
__onRemovedFromStageAA
=
function
()
{
this
.
parent
.
removeEventListener
(
Event
.
RESIZE
,
this
.
__onResizeAA
);
this
.
removeEventListener
(
Event
.
ENTER_FRAME
,
this
.
__onEnterFrameAA
);
let
adjustProxy
=
this
.
adjustProxy
=
new
AdjustProxy
(
this
);
this
.
addEventListener
(
Event
.
ADDED_TO_STAGE
,
adjustProxy
.
onAddedToStage
,
adjustProxy
);
this
.
addEventListener
(
Event
.
REMOVED_FROM_STAGE
,
adjustProxy
.
onRemovedFromStage
,
adjustProxy
);
};
ctor
.
prototype
.
__onResizeAA
=
function
()
{
this
.
__sizeDirty
=
true
;
let
temp
=
new
AdjustProxy
(
null
);
for
(
let
key
in
temp
.
data
)
Object
.
defineProperty
(
ctor
.
prototype
,
key
,
{
get
:
function
()
{
return
this
.
adjustProxy
.
data
[
key
];
},
set
:
function
(
v
)
{
const
adjustProxy
:
AdjustProxy
=
this
.
adjustProxy
;
if
(
adjustProxy
.
data
[
key
]
!==
v
)
{
adjustProxy
.
data
[
key
]
=
v
;
adjustProxy
.
makeDirty
();
}
},
enumerable
:
true
,
configurable
:
true
});
}
/**
* 自适应数据
*/
class
AdjustProxy
{
data
=
{
percentWidth
:
NaN
,
percentHeight
:
NaN
,
left
:
NaN
,
top
:
NaN
,
right
:
NaN
,
bottom
:
NaN
,
horizonCenter
:
NaN
,
verticalCenter
:
NaN
,
};
ctor
.
prototype
.
__onEnterFrameAA
=
function
()
{
if
(
this
.
__sizeDirty
)
{
this
.
__sizeDirty
=
false
;
private
_host
;
private
_sizeDirty
;
constructor
(
host
)
{
this
.
_host
=
host
;
this
.
makeDirty
();
}
makeDirty
()
{
this
.
_sizeDirty
=
true
;
}
onAddedToStage
(
e
)
{
this
.
_host
.
parent
.
addEventListener
(
Event
.
RESIZE
,
this
.
onResize
,
this
);
this
.
_host
.
addEventListener
(
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
);
}
onRemovedFromStage
(
e
)
{
this
.
_host
.
parent
.
removeEventListener
(
Event
.
RESIZE
,
this
.
onResize
);
this
.
_host
.
removeEventListener
(
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
);
}
private
onResize
(
e
)
{
this
.
_sizeDirty
=
true
;
}
private
onEnterFrame
(
e
)
{
if
(
this
.
_sizeDirty
)
{
this
.
_sizeDirty
=
false
;
this
.
adjustLayout
();
}
};
ctor
.
prototype
.
adjustLayout
=
function
()
{
const
that
=
this
;
const
{
width
:
pWidth
,
height
:
pHeight
}
=
this
.
parent
;
const
{
width
,
height
}
=
this
;
const
{
percentWidth
,
percentHeight
,
left
,
top
,
right
,
bottom
,
horizonCenter
,
verticalCenter
}
=
this
.
adjustData
;
}
adjustLayout
()
{
const
that
=
this
.
_host
;
const
{
width
:
pWidth
,
height
:
pHeight
}
=
that
.
parent
;
const
{
width
,
height
}
=
that
;
const
{
percentWidth
,
percentHeight
,
left
,
top
,
right
,
bottom
,
horizonCenter
,
verticalCenter
}
=
this
.
data
;
const
applyPercentWidth
=
function
()
{
if
(
t
(
percentWidth
))
{
...
...
@@ -74,16 +104,16 @@ export function applyAutoAdjust(ctor: Function) {
let
pw
=
true
,
ph
=
true
;
if
(
t
(
horizonCenter
))
{
applyPercentWidth
();
th
is
.
x
=
(
pWidth
-
this
.
width
)
/
2
+
horizonCenter
;
th
at
.
x
=
(
pWidth
-
that
.
width
)
/
2
+
horizonCenter
;
}
else
{
if
(
t
(
left
))
{
th
is
.
x
=
left
;
th
at
.
x
=
left
;
if
(
t
(
right
))
{
th
is
.
width
=
pWidth
-
left
-
right
;
th
at
.
width
=
pWidth
-
left
-
right
;
pw
=
false
;
}
}
else
if
(
t
(
right
))
{
th
is
.
x
=
pWidth
-
width
-
right
;
th
at
.
x
=
pWidth
-
width
-
right
;
}
if
(
pw
)
{
applyPercentWidth
();
...
...
@@ -92,34 +122,25 @@ export function applyAutoAdjust(ctor: Function) {
if
(
t
(
verticalCenter
))
{
applyPercentHeight
();
th
is
.
y
=
(
pHeight
-
this
.
height
)
/
2
+
verticalCenter
;
th
at
.
y
=
(
pHeight
-
that
.
height
)
/
2
+
verticalCenter
;
}
else
{
if
(
t
(
top
))
{
th
is
.
y
=
top
;
th
at
.
y
=
top
;
if
(
t
(
bottom
))
{
th
is
.
height
=
pHeight
-
top
-
bottom
;
th
at
.
height
=
pHeight
-
top
-
bottom
;
ph
=
false
;
}
}
else
if
(
t
(
bottom
))
{
th
is
.
y
=
pHeight
-
height
-
bottom
;
th
at
.
y
=
pHeight
-
height
-
bottom
;
}
if
(
ph
)
{
applyPercentHeight
();
}
}
};
for
(
let
key
in
new
AdjustData
())
Object
.
defineProperty
(
ctor
.
prototype
,
key
,
{
get
:
function
()
{
return
this
.
adjustData
[
key
];
},
set
:
function
(
v
)
{
if
(
this
.
adjustData
[
key
]
!==
v
)
{
this
.
adjustData
[
key
]
=
v
;
this
.
__sizeDirty
=
true
;
}
},
enumerable
:
true
,
configurable
:
true
});
}
function
t
(
v
)
{
return
!
isNaN
(
v
)
&&
v
!==
null
&&
v
!==
undefined
;
}
src/zeroing/decorators/events.ts
View file @
f987a9a6
...
...
@@ -21,14 +21,14 @@ const eventsConfig = {
*/
export
function
applyEvents
(
ctor
:
Function
)
{
ctor
.
prototype
.
applyEvents
=
function
()
{
let
events
=
this
.
events
=
new
Events
();
let
events
Proxy
=
this
.
eventsProxy
=
new
EventsProxy
();
for
(
let
k
in
eventsConfig
){
this
.
addEventListener
(
k
,
events
.
onEvent
,
events
);
this
.
addEventListener
(
k
,
events
Proxy
.
onEvent
,
eventsProxy
);
}
};
}
class
Events
extends
HashObject
{
class
Events
Proxy
extends
HashObject
{
constructor
(){
super
();
}
...
...
src/zeroing/decorators/scripts.ts
View file @
f987a9a6
...
...
@@ -14,20 +14,11 @@ const scriptDefs = {};
*/
export
function
applyScript
(
ctor
:
Function
)
{
ctor
.
prototype
.
applyScripts
=
function
()
{
this
.
scripts
=
new
ScriptsContainer
(
this
);
let
scriptsProxy
=
this
.
scriptsProxy
=
new
ScriptsProxy
(
this
);
this
.
addEventListener
(
Event
.
ENTER_FRAME
,
this
.
__onEnterFrameS
,
this
);
this
.
addEventListener
(
Event
.
ADDED_TO_STAGE
,
this
.
__onAddedToStageS
,
this
);
this
.
addEventListener
(
Event
.
REMOVED_FROM_STAGE
,
this
.
__onRemovedFromStageS
,
this
);
};
ctor
.
prototype
.
__onEnterFrameS
=
function
(
e
)
{
this
.
scripts
.
update
(
e
.
data
);
};
ctor
.
prototype
.
__onAddedToStageS
=
function
(
e
)
{
this
.
scripts
.
awake
();
};
ctor
.
prototype
.
__onRemovedFromStageS
=
function
(
e
)
{
this
.
scripts
.
sleep
();
this
.
addEventListener
(
Event
.
ENTER_FRAME
,
scriptsProxy
.
onEnterFrame
,
scriptsProxy
);
this
.
addEventListener
(
Event
.
ADDED_TO_STAGE
,
scriptsProxy
.
onAddedToStage
,
scriptsProxy
);
this
.
addEventListener
(
Event
.
REMOVED_FROM_STAGE
,
scriptsProxy
.
onRemovedFromStage
,
scriptsProxy
);
};
}
...
...
@@ -79,7 +70,7 @@ export function registerScriptDef(def) {
/**
* 脚本容器
*/
class
Scripts
Container
{
class
Scripts
Proxy
{
private
_host
:
Container
;
private
_scripts
:
IScript
[]
=
[];
...
...
@@ -152,7 +143,7 @@ class ScriptsContainer {
/**
* 唤醒
*/
awak
e
()
{
onAddedToStag
e
()
{
for
(
let
script
of
this
.
_scripts
)
{
if
(
!
script
.
disabled
)
{
script
.
awake
();
...
...
@@ -163,7 +154,7 @@ class ScriptsContainer {
/**
* 睡眠
*/
sleep
()
{
onRemovedFromStage
()
{
for
(
let
script
of
this
.
_scripts
)
{
if
(
!
script
.
disabled
)
{
script
.
sleep
();
...
...
@@ -174,7 +165,8 @@ class ScriptsContainer {
/**
* 更新脚本时钟
*/
update
(
t
)
{
onEnterFrame
(
e
)
{
let
t
=
e
.
data
;
for
(
let
script
of
this
.
_scripts
)
{
if
(
!
script
.
disabled
)
{
script
.
update
(
t
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment