diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..fd67093 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,345 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es6": true, + "node": true + }, + "extends": [ + "plugin:@typescript-eslint/recommended", + "prettier", + "prettier/@typescript-eslint" + ], + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint", "prettier","autofix", "sort-imports-es6-autofix"], + "parserOptions": { + "project": "./tsconfig.json", + "ecmaFeatures": { + "jsx": true + }, + "useJSXTextNode": true + }, + "rules": { + "autofix/no-debugger": "warn", + "@typescript-eslint/adjacent-overload-signatures": ["warn"], + // "@typescript-eslint/array-type": ["warn", "generic"], + "@typescript-eslint/ban-types": ["warn"], + "@typescript-eslint/ban-ts-ignore": ["warn"], + "@typescript-eslint/camelcase": ["warn"], + "@typescript-eslint/class-name-casing": ["warn"], + "@typescript-eslint/explicit-function-return-type": ["off"], + "@typescript-eslint/explicit-member-accessibility": ["off"], + "@typescript-eslint/generic-type-naming": ["warn"], + "@typescript-eslint/indent": ["warn", "tab"], + "@typescript-eslint/interface-name-prefix": ["warn", "always"], + "@typescript-eslint/member-delimiter-style": ["warn"], + "@typescript-eslint/member-naming": ["warn"], + "@typescript-eslint/member-ordering": ["off"], + "@typescript-eslint/no-angle-bracket-type-assertion": ["off"], + "@typescript-eslint/no-array-constructor": ["warn"], + "@typescript-eslint/no-ety-interface": ["off"], + "@typescript-eslint/no-explicit-any": ["off"], + "@typescript-eslint/no-extraneous-class": ["off"], + "@typescript-eslint/no-for-in-array": ["warn"], + "@typescript-eslint/no-inferrable-types": ["warn"], + "@typescript-eslint/no-misused-new": ["warn"], + "@typescript-eslint/no-namespace": ["warn"], + "@typescript-eslint/no-non-null-assertion": ["warn"], + "@typescript-eslint/no-object-literal-type-assertion": ["off"], + "@typescript-eslint/no-parameter-properties": ["off"], + "@typescript-eslint/no-require-imports": ["off"], + "@typescript-eslint/no-this-alias": ["warn"], + "@typescript-eslint/no-triple-slash-reference": ["off"], + "@typescript-eslint/no-type-alias": ["warn"], + "@typescript-eslint/no-unnecessary-qualifier": ["off"], + "@typescript-eslint/no-unnecessary-type-assertion": ["off"], + "@typescript-eslint/no-unused-vars": ["off"], + "@typescript-eslint/no-use-before-define": ["warn"], + "@typescript-eslint/no-useless-constructor": ["warn"], + "@typescript-eslint/no-var-requires": ["warn"], + "@typescript-eslint/prefer-function-type": ["warn"], + "@typescript-eslint/prefer-interface": ["off"], + "@typescript-eslint/prefer-namespace-keyword": ["warn"], + "@typescript-eslint/promise-function-async": ["off"], + "@typescript-eslint/restrict-plus-operands": ["off"], + "@typescript-eslint/type-annotation-spacing": ["off"], + "@typescript-eslint/unified-signatures": ["warn"], + + "array-element-newline": "warn", + "arrow-spacing": "warn", + "block-spacing": "warn", + "capitalized-comments": ["warn", "never"], + "comma-dangle": "warn", + "comma-spacing": "warn", + "comma-style": "warn", + "dot-location": "warn", + "dot-notation": "warn", + "eol-last": ["warn", "never"], + "eqeqeq": "off", + "func-call-spacing": "warn", + "function-paren-newline": "warn", + "generator-star-spacing": "warn", + "implicit-arrow-linebreak": "warn", + "jsx-quotes": "warn", + "key-spacing": "warn", + "keyword-spacing": "warn", + "lines-around-comment": "warn", + "lines-around-directive": "warn", + "lines-between-class-members": ["warn", "always"], + "multiline-comment-style": "off", + "newline-after-var": "warn", + "no-confusing-arrow": "warn", + "no-else-return": "warn", + "no-extra-bind": "warn", + "no-extra-boolean-cast": "warn", + "no-extra-label": "warn", + "no-extra-parens": "off", + "no-extra-semi": "warn", + "no-floating-decimal": "warn", + "no-implicit-coercion": "warn", + "no-lonely-if": "off", + "no-multi-spaces": "warn", + "no-multiple-empty-lines": "warn", + "no-regex-spaces": "warn", + "no-spaced-func": "warn", + "no-trailing-spaces": "warn", + "no-undef-init": "warn", + "no-unneeded-ternary": "warn", + "no-unsafe-negation": "warn", + "no-unused-expressions": "warn", + "no-unused-labels": "warn", + "no-useless-computed-key": "warn", + "no-useless-rename": "warn", + "no-useless-return": "warn", + "no-whitespace-before-property": "warn", + "nonblock-statement-body-position": "warn", + "object-curly-newline": "warn", + "object-curly-spacing": "warn", + "object-property-newline": "warn", + "object-shorthand": "warn", + "one-var": ["warn", "never"], + "one-var-declaration-per-line": "warn", + "operator-assignment": "warn", + "semi": ["error", "always"], + "operator-linebreak": "warn", + "padded-blocks": ["warn", "never"], + "padding-line-between-statements": "warn", + "prefer-arrow-callback": "warn", + "prefer-destructuring": "warn", + "prefer-numeric-literals": "warn", + "prefer-spread": "warn", + "quote-props": ["warn", "as-needed"], + "quotes": "warn", + "rest-spread-spacing": "warn", + "semi-spacing": "warn", + "semi-style": "warn", + "sort-imports-es6-autofix/sort-imports-es6": [2, { + "ignoreCase": false, + "ignoreMemberSort": false, + "memberSyntaxSortOrder": ["none", "all", "multiple", "single"] + }], + "space-before-blocks": "warn", + "space-in-parens": "warn", + "space-infix-ops": "warn", + "space-unary-ops": "warn", + "spaced-comment": "warn", + "switch-colon-spacing": "warn", + "template-curly-spacing": "warn", + "template-tag-spacing": "warn", + "unicode-bom": "warn", + "valid-jsdoc": "warn", + "wrap-iife": "warn", + "wrap-regex": "warn", + "yield-star-spacing": "warn", + "yoda": "warn", + "computed-property-spacing": "warn", + "arrow-body-style": "warn", + "array-bracket-spacing": "warn", + "prefer-const": "warn", + "indent": ["warn", "tab"], + "curly": "warn", + "arrow-parens": "warn", + "linebreak-style": ["warn", "windows"], + "new-parens": "warn", + "newline-before-return": "warn", + "newline-per-chained-call": "warn", + "prefer-object-spread": "warn", + "prefer-template": "warn", + "space-before-function-paren": "warn", + "sort-vars": "warn", + "brace-style": ["error", "1tbs", { "allowSingleLine": false }], + "array-bracket-newline": "warn", + "strict": "off", + "no-var": "warn", + "function-call-argument-newline":"off", + "no-with": "off", + "symbol-description": "off", + "no-unreachable": "off", + "sort-keys": "warn", + "class-methods-use-this": "off", + "no-fallthrough": "off", + "no-multi-str": "off", + "no-undef": "off", + "init-declarations": "off", + "line-comment-position": "off", + "for-direction": "off", + "getter-return": "off", + "block-scoped-var": "off", + "callback-return": "off", + "no-empty-character-class": "off", + "no-empty-function": "off", + "no-func-assign": "off", + "no-global-assign": "off", + "no-unused-vars": "off", + "no-use-before-define": "off", + "no-useless-call": "off", + "prefer-promise-reject-errors": "off", + "prefer-reflect": "off", + "prefer-rest-params": "off", + "valid-typeof": "off", + "vars-on-top": "off", + "array-callback-return": "off", + "use-isnan": "off", + "radix": "off", + "func-name-matching": "off", + "func-names": "off", + "no-alert": "off", + "no-ex-assign": "off", + "multiline-ternary": "off", + "new-cap": "off", + "no-void": "off", + "no-warning-comments": "off", + "no-useless-concat": "off", + "no-useless-constructor": "off", + "no-useless-escape": "off", + "require-await": "off", + "require-jsdoc": "off", + "require-yield": "off", + "no-undefined": "off", + "no-underscore-dangle": "off", + "no-unexpected-multiline": "off", + "no-unmodified-loop-condition": "off", + "no-sync": "off", + "no-tabs": "off", + "no-template-curly-in-string": "off", + "no-ternary": "off", + "no-this-before-super": "off", + "no-throw-literal": "off", + "global-require": "off", + "guard-for-in": "off", + "handle-callback-err": "off", + "id-blacklist": "off", + "id-length": "off", + "id-match": "off", + "no-array-constructor": "off", + "no-await-in-loop": "off", + "no-buffer-constructor": "off", + "no-caller": "off", + "no-eq-null": "off", + "no-case-declarations": "off", + "no-catch-shadow": "off", + "no-class-assign": "off", + "no-compare-neg-zero": "off", + "no-cond-assign": "off", + "no-implicit-globals": "off", + "no-implied-eval": "off", + "no-inline-comments": "off", + "no-inner-declarations": "off", + "no-invalid-regexp": "off", + "no-loop-func": "off", + "no-mixed-operators": "off", + "no-mixed-requires": "off", + "no-mixed-spaces-and-tabs": "off", + "no-multi-assign": "off", + "no-iterator": "off", + "no-label-var": "off", + "no-labels": "off", + "no-lone-blocks": "off", + "no-empty": "off", + "no-magic-numbers": "off", + "no-duplicate-imports": "off", + "no-console": "off", + "no-native-reassign": "off", + "no-negated-condition": "off", + "no-negated-in-lhs": "off", + "no-nested-ternary": "off", + "complexity": "off", + "consistent-return": "off", + "consistent-this": "off", + "constructor-super": "off", + "default-case": "off", + "no-restricted-globals": "off", + "no-restricted-imports": "off", + "no-restricted-modules": "off", + "no-restricted-properties": "off", + "no-restricted-syntax": "off", + "no-return-assign": "off", + "no-script-url": "off", + "no-self-assign": "off", + "no-self-compare": "off", + "no-sequences": "off", + "no-shadow": "off", + "no-shadow-restricted-names": "off", + "no-const-assign": "off", + "no-constant-condition": "off", + "no-continue": "off", + "no-control-regex": "off", + "no-delete-var": "off", + "no-div-regex": "off", + "no-dupe-args": "off", + "no-dupe-class-members": "off", + "no-dupe-keys": "off", + "no-duplicate-case": "off", + "no-empty-pattern": "off", + "no-extend-native": "off", + "no-new": "off", + "no-new-func": "off", + "no-new-object": "off", + "no-new-require": "off", + "no-new-symbol": "off", + "no-new-wrappers": "off", + "no-obj-calls": "off", + "no-octal": "off", + "no-octal-escape": "off", + "no-param-reassign": "off", + "no-path-concat": "off", + "no-plusplus": "off", + "no-process-env": "off", + "no-process-exit": "off", + "no-proto": "off", + "no-prototype-builtins": "off", + "no-redeclare": "off", + "no-bitwise": "off", + "no-debugger": "off", + "no-eval": "off", + "no-invalid-this": "off", + "no-irregular-whitespace": "off", + "no-return-await": "off", + "no-sparse-arrays": "off", + "no-unsafe-finally": "off", + "accessor-pairs": "off", + "func-style": "off", + "camelcase": "off", + "max-depth": "off", + "max-len": [ + "off", + { + "code": 150 + } + ], + "max-lines": "off", + "max-nested-callbacks": "off", + "max-params": "off", + "max-statements": ["off", 40], + "max-statements-per-line": [ + "off", + { + "max": 40 + } + ] + } +} diff --git a/.vs/NodejsApp1/v16/.suo b/.vs/NodejsApp1/v16/.suo new file mode 100644 index 0000000..6196cdb Binary files /dev/null and b/.vs/NodejsApp1/v16/.suo differ diff --git a/.vs/Supercharger/NodejsApp1/codemap.dat b/.vs/Supercharger/NodejsApp1/codemap.dat new file mode 100644 index 0000000..3cd2358 --- /dev/null +++ b/.vs/Supercharger/NodejsApp1/codemap.dat @@ -0,0 +1 @@ +NodejsApp1 \ No newline at end of file diff --git a/.vs/Supercharger/NodejsApp1/global_history.dat b/.vs/Supercharger/NodejsApp1/global_history.dat new file mode 100644 index 0000000..3661095 --- /dev/null +++ b/.vs/Supercharger/NodejsApp1/global_history.dat @@ -0,0 +1 @@ +NodejsApp1 \ No newline at end of file diff --git a/.vs/Supercharger/NodejsApp1/workbench.dat b/.vs/Supercharger/NodejsApp1/workbench.dat new file mode 100644 index 0000000..19e16a0 --- /dev/null +++ b/.vs/Supercharger/NodejsApp1/workbench.dat @@ -0,0 +1 @@ +NodejsApp1 \ No newline at end of file diff --git a/NodejsApp1.njsproj b/NodejsApp1.njsproj new file mode 100644 index 0000000..e8e0d61 --- /dev/null +++ b/NodejsApp1.njsproj @@ -0,0 +1,331 @@ + + + + Debug + 2.0 + {0b7002ae-9614-4852-b170-08d987e88227} + . + ShowAllFiles + global.d.ts + . + . + {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD} + true + 16.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + True + 0 + / + http://localhost:48022/ + False + True + http://localhost:1337 + False + + + + + + + CurrentPage + True + False + False + False + + + + + + + + + False + False + + + + + \ No newline at end of file diff --git a/Plugin/test.js b/Plugin/test.js new file mode 100644 index 0000000..b422894 --- /dev/null +++ b/Plugin/test.js @@ -0,0 +1,5 @@ +function a(){ + //#endregion +} + +window.plugin=a \ No newline at end of file diff --git a/Src/Components/BasicComponents/LayoutStack.ts b/Src/Components/BasicComponents/LayoutStack.ts index 9344f83..54cd343 100644 --- a/Src/Components/BasicComponents/LayoutStack.ts +++ b/Src/Components/BasicComponents/LayoutStack.ts @@ -5,6 +5,14 @@ export class LayoutStack extends Behaviour { padding: number = 0; alignment: ListAlignment = ListAlignment.horizontal; + awake() { + this.update(); + } + + start(){ + this.update() + } + update() { let children = this.transform.Children; diff --git a/Src/Components/BasicComponents/List.ts b/Src/Components/BasicComponents/List.ts index d28b690..8462f23 100644 --- a/Src/Components/BasicComponents/List.ts +++ b/Src/Components/BasicComponents/List.ts @@ -2,6 +2,8 @@ import { DoubleBind } from "../../Core/DoubleBind"; import { Vector2, EditableVector2 } from "../../Core/Math/Vector2"; import { StormComponent } from "../../Core/StormComponent"; import { StormObject } from "../../Core/Widgets/StormObject"; +import { Updater } from "../../Core/Utils/Updater"; +import { UIEventListhenner } from "./UIEventListhenner"; export class List extends StormComponent { data: any[] | null = null; @@ -26,7 +28,12 @@ export class List extends StormComponent { this.render(); } + update() { + // this.render(); + } + render() { + this.computeSize(); this.renderItems(); } @@ -62,19 +69,24 @@ export class List extends StormComponent { let parentRect = this.stormObject.transfrom.Parent.getGlobalRect(); let visibleStartX = - clientRect.x > parentRect.x ? clientRect.x : parentRect.x - clientRect.x; + clientRect.x > parentRect.x ? clientRect.x : parentRect.x; let visibleStartY = - clientRect.y > parentRect.y ? clientRect.y : parentRect.y - clientRect.y; - let visibleEndX = visibleStartX + clientRect.width; - let parentEndX = parentRect.x + parentRect.width; - if (visibleEndX > parentEndX) { - visibleEndX = parentEndX; - } - let visibleEndY = visibleStartY + clientRect.height; - let parentEndY = parentRect.y + parentRect.height; - if (visibleEndY > parentEndY) { - visibleEndY = parentEndY; - } + clientRect.y > parentRect.y ? clientRect.y : parentRect.y; + + let visibleEndX = + clientRect.x + clientRect.width > parentRect.x + parentRect.width + ? parentRect.x + parentRect.width + : clientRect.x + clientRect.width; + + let visibleEndY = + clientRect.y + clientRect.height > parentRect.y + parentRect.height + ? parentRect.y + parentRect.height + : clientRect.y + clientRect.height; + + visibleStartX = visibleStartX - clientRect.x; + visibleStartY = visibleStartY - clientRect.y; + visibleEndX = visibleEndX - clientRect.x; + visibleEndY = visibleEndY - clientRect.y; let visibleIndexs: Vector2[] = []; let visibleIndexStartX = Math.floor( @@ -92,8 +104,15 @@ export class List extends StormComponent { (visibleEndY - this.itemHeight) / (this.itemHeight + this.paddingY) ); - for (let y = visibleIndexStartY; y <= visibleIndexEndY; y++) { - for (let x = visibleIndexStartX; x <= visibleIndexEndX; x++) { + // for (let y = visibleIndexStartY; y <= visibleIndexEndY; y++) { + // for (let x = visibleIndexStartX; x <= visibleIndexEndX; x++) { + // let value = new Vector2(x, y); + // visibleIndexs.push(value); + // } + // } + + for (let y = 0; y <= (clientRect.height - this.itemHeight) / (this.itemHeight + this.paddingY); y++) { + for (let x = 0; x <= (clientRect.width - this.itemWidth) / (this.itemWidth + this.paddingX); x++) { let value = new Vector2(x, y); visibleIndexs.push(value); } @@ -103,9 +122,10 @@ export class List extends StormComponent { } renderItems() { - this.removeItems(); + // this.removeItems(); let visibleIndexs = this.getVisibleIndex(); + for (const index2d of visibleIndexs) { let index = this.index2d2index(index2d); this.addItem(this.data[index], index2d); @@ -132,7 +152,9 @@ export class List extends StormComponent { if (index >= this.data.length) { return; } - let itemWidget = this.selectItemStyleOnRender(data); + let itemWidget = StormObject.Instantiate( + this.selectItemStyleOnRender(data) + ); let item = itemWidget; item.transfrom.Width = this.itemWidth; item.transfrom.Height = this.itemHeight; @@ -149,6 +171,16 @@ export class List extends StormComponent { } } + let event = item.addBehaviour(UIEventListhenner); + // console.log(data) + event.OnClick.Regist( + (a, b, item, index) => { + this.onItemClick(item, this.data[index]); + }, + undefined, + item, + index + ); this.items.push(item); } diff --git a/Src/Components/BasicComponents/Panel.ts b/Src/Components/BasicComponents/Panel.ts new file mode 100644 index 0000000..1112d33 --- /dev/null +++ b/Src/Components/BasicComponents/Panel.ts @@ -0,0 +1,12 @@ +import {StormComponent} from "../../Core/StormComponent"; + +export class Panel extends StormComponent { + depth: number = 0; + parentPanel:Panel + + awake(){ + + let panel= this.stormObject.transfrom.Parent.StormObject.getBehaviour(Panel) + + } +} \ No newline at end of file diff --git a/Src/Components/BasicComponents/ScrollBar.ts b/Src/Components/BasicComponents/ScrollBar.ts new file mode 100644 index 0000000..04492e6 --- /dev/null +++ b/Src/Components/BasicComponents/ScrollBar.ts @@ -0,0 +1,35 @@ +import {StormComponent} from "../../Core/StormComponent"; +import {StormObject} from "../../Core/Widgets/StormObject"; +import {ScrollView} from "./ScrollView"; +import {UIEventListhenner} from "./UIEventListhenner"; +export class ScrollBar extends StormComponent { + background: StormObject = undefined; + + up: StormObject | undefined = undefined; + + down: StormObject | undefined = undefined; + + front: StormObject | undefined = undefined; + + value: number = 0; + + scrollView: ScrollView | undefined = undefined; + + direction: "horizontal" | "vertical" = "horizontal"; + + awake () { + const a = this.down.addBehaviour(UIEventListhenner); + + a.OnClick.Regist(); + + const b = this.up.addBehaviour(UIEventListhenner); + + b.OnClick.Regist(); + + const front = this.front.addBehaviour(UIEventListhenner); + + front.OnMouseMove.Regist(); + } + + update () {} +} \ No newline at end of file diff --git a/Src/Components/BasicComponents/ScrollView.ts b/Src/Components/BasicComponents/ScrollView.ts new file mode 100644 index 0000000..f115099 --- /dev/null +++ b/Src/Components/BasicComponents/ScrollView.ts @@ -0,0 +1,70 @@ +import {StormComponent} from "../../Core/StormComponent"; +import {StormObject} from "../../Core/Widgets/StormObject"; +import {MathEx} from "../../Core/Math/MathEx"; +export class ScrollView extends StormComponent { + child: StormObject | undefined = undefined; + + value: number = 0; + + direction: "horizontal" | "vertical" = "horizontal"; + + awake () { + if (this.transform.Children.length > 0) { + this.child = this.transform.Children[0].StormObject; + } + } + + setValue (value: number) { + if (this.child == undefined) { + return; + } + + this.value = value; + const thisRect = this.transform.getGlobalRect(); + const childRect = this.child.transfrom.getGlobalRect(); + + if (this.direction == "horizontal") { + const width = childRect.width - thisRect.width; + + this.child.transfrom.WorldPosition.x = MathEx.lerp( + thisRect.x, + thisRect.x - width, + value + ); + } else { + const height = childRect.height - thisRect.height; + + this.child.transfrom.WorldPosition.y = MathEx.lerp( + thisRect.y, + thisRect.y - height, + value + ); + } + } + + update () { + if (this.child == undefined) { + return; + } + const thisRect = this.transform.getGlobalRect(); + const childRect = this.child.transfrom.getGlobalRect(); + + if (this.direction == "horizontal") { + const width = childRect.width - thisRect.width; + + this.value = MathEx.getPercentage( + thisRect.x, + thisRect.x - width, + childRect.x + ); + } else { + const height = childRect.height - thisRect.height; + + this.value = MathEx.getPercentage( + thisRect.y, + thisRect.y - height, + childRect.y + ); + } + } +} \ No newline at end of file diff --git a/Src/Components/BasicComponents/TreeView.ts b/Src/Components/BasicComponents/TreeView.ts index 6efd36b..bf2edc7 100644 --- a/Src/Components/BasicComponents/TreeView.ts +++ b/Src/Components/BasicComponents/TreeView.ts @@ -4,7 +4,8 @@ import { StormObject } from "../../Core/Widgets/StormObject"; import { Vector2 } from "../../Core/Math/Vector2"; import { UIEventListhenner } from "./UIEventListhenner"; import { isArray } from "util"; - +import { HierachyItem } from "../HierachyItem"; +@HierachyItem("TreeView") export class TreeView extends StormComponent { datas: any; zonePrefab; @@ -48,6 +49,7 @@ export class TreeView extends StormComponent { } } + export class TreeItem { isZoneItem: boolean = false; isExpand: boolean = false; diff --git a/Src/Components/BasicComponents/UIEventListhenner.ts b/Src/Components/BasicComponents/UIEventListhenner.ts index 02aec9f..42fca78 100644 --- a/Src/Components/BasicComponents/UIEventListhenner.ts +++ b/Src/Components/BasicComponents/UIEventListhenner.ts @@ -1,21 +1,30 @@ -import { StormComponent } from "../../Core/StormComponent"; -import { IClickable, IMouseDown, IMouseUp } from "../../Core/Input"; -import { EventManager } from "../../Core/EventManager"; -import { InputEvent } from "../../Core/InputEvent"; +import {StormComponent} from "../../Core/StormComponent"; +import {IClickable, IMouseDown, IMouseMove, IMouseUp} from "../../Core/Input"; +import {EventManager} from "../../Core/EventManager"; +import {InputEvent} from "../../Core/InputEvent"; export class UIEventListhenner extends StormComponent - implements IClickable, IMouseDown, IMouseUp { + implements IClickable, IMouseDown, IMouseUp, IMouseMove { OnClick: EventManager = new EventManager(); + OnMouseUp: EventManager = new EventManager(); + OnMouseDown: EventManager = new EventManager(); - onClick(inputEvent: InputEvent) { + OnMouseMove: EventManager = new EventManager(); + + onClick (inputEvent: InputEvent) { this.OnClick.Call(this, inputEvent); } - onMouseUP(inputEvent: InputEvent) { + + onMouseUP (inputEvent: InputEvent) { this.OnMouseUp.Call(this, inputEvent); } - onMouseDown(inputEvent: InputEvent) { + onMouseDown (inputEvent: InputEvent) { this.OnMouseDown.Call(this, inputEvent); } -} + + onMouseMove (inputEvent: InputEvent) { + this.OnMouseMove.Call(this, inputEvent); + } +} \ No newline at end of file diff --git a/Src/Components/BasicComponents/Widgret.ts b/Src/Components/BasicComponents/Widgret.ts new file mode 100644 index 0000000..4e4b0a9 --- /dev/null +++ b/Src/Components/BasicComponents/Widgret.ts @@ -0,0 +1,5 @@ +import {StormComponent} from "../../Core/StormComponent"; + +export class Widget extends StormComponent { + order: number = 0; +} \ No newline at end of file diff --git a/Src/Components/TreeView.ts b/Src/Components/TreeView.ts deleted file mode 100644 index 152f21b..0000000 --- a/Src/Components/TreeView.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { ListViewBase } from "./ListViewBase"; - -export class TreeView extends ListViewBase { - OnSelectStyle: (data: any) => string; - FilterItem: (data: any) => boolean; - size: number = 100; - padding: number = 1; - onItemClick: ( - event: MouseEvent, - data: T, - element: HTMLElement, - state - ) => void; - - public SetDiv(html: HTMLElement) { - this.element = html; - this.panel = document.createElement("div"); - this.element.appendChild(this.panel); - } - - public SetData(data: Array, type) { - this.data = data; - this.render(data, type); - } - - render(data: Array, type) { - for (const value of data) { - if (!this.FilterItem(value)) { - continue; - } - - let style = this.OnSelectStyle(value); - const node = this.GenerateStyleNode(style); - let div = document.createElement("div"); - - div.style.height = this.size.toString(); - div.style.width = "100%"; - div.style.paddingTop = this.padding.toString() + "px"; - div.setAttribute("draggable", "true"); - this.panel.appendChild(div); - div.appendChild(node); - let state = {}; - div.onclick = (event: MouseEvent) => { - event.stopPropagation(); - - if (this.onItemClick != null) { - this.onItemClick(event, value, div, state); - } - }; - - this.ParseContent(value, node); - } - } -} diff --git a/Src/Core/Attributes/Transform.ts b/Src/Core/Attributes/Transform.ts index 1e3f63f..ebac572 100644 --- a/Src/Core/Attributes/Transform.ts +++ b/Src/Core/Attributes/Transform.ts @@ -1,10 +1,10 @@ -import { Vector2 } from "../Math/Vector2"; -import { StormObject } from "../Widgets/StormObject"; -import { Matrix3 } from "../Math/Matrix3"; -import { Anchor } from "../Widgets/Anchor"; -import { Rect } from "../Math/Rect"; -import { GUID } from "../Utils/GUID"; -import { Serializable } from "../Serializer"; +import {Vector2} from "../Math/Vector2"; +import {StormObject} from "../Widgets/StormObject"; +import {Matrix3} from "../Math/Matrix3"; +import {Anchor} from "../Widgets/Anchor"; +import {Rect} from "../Math/Rect"; +import {GUID} from "../Utils/GUID"; +import {Serializable} from "../Serializer"; // updateMatrix() { // if (this.mountedElement == undefined) { @@ -47,7 +47,7 @@ export interface TransFormAttributes { world2LocalMatrix: Matrix3; stormObject: StormObject | null; parent: Transform | null; - child: Transform[]; + child: Array; isDirty: boolean; WorldWidth; WorldHeight; @@ -56,23 +56,38 @@ export interface TransFormAttributes { @Serializable() export class Transform { private worldPosition: Vector2 = new Vector2(0, 0); + private worldScale: Vector2 = new Vector2(1, 1); + private worldDegree: number = 0; + private localPositon: Vector2 = new Vector2(0, 0); + private localScale: Vector2 = new Vector2(1, 1); + private localDegree: number = 0; + Width: number = 100; + Height: number = 100; + private local2WorldMatrix: Matrix3 = new Matrix3(); + private world2LocalMatrix: Matrix3 = new Matrix3(); + private stormObject: StormObject | null = null; + private parent: Transform | null = null; - private child: Transform[] = []; + + private child: Array = []; + private isDirty: boolean = false; + readonly anchor: Anchor = new Anchor(); + hash: GUID = new GUID(); - destroy() { + destroy () { if (this.parent != null) { this.parent.child.remove(this); } @@ -80,8 +95,9 @@ export class Transform { this.parent = null; } - get Children(): Transform[] { - let result = []; + get Children (): Array { + const result = []; + for (const child of this.child) { result.push(child); } @@ -89,7 +105,7 @@ export class Transform { return result; } - set StormObject(value) { + set StormObject (value) { if (this.stormObject == null) { this.stormObject = value; } @@ -97,75 +113,93 @@ export class Transform { this.anchor.transform = this; } - get StormObject() { + get StormObject () { return this.stormObject; } - get Parent() { + get Parent () { return this.parent; } - set Parent(value) { + set Parent (value) { if (this.parent != null) { - (>this.parent.child).remove(this); + (> this.parent.child).remove(this); } this.parent = value; this.parent.child.push(this); this.isDirty = true; + if (this.stormObject.getRenderer() != undefined) { + this.stormObject.getRenderer().awake(); + } + this.updateRenderer(this); + } + + private updateRenderer (target:Transform) { + for (const child of target.child) { + if (child.stormObject.getRenderer() != undefined) { + child.stormObject.getRenderer().awake(); + } + + this.updateRenderer(child); + } } - appendChild(obj: Transform) { + appendChild (obj: Transform) { if (obj.parent != undefined) { obj.parent.child.remove(obj); } obj.parent = this; this.child.push(obj); + obj.stormObject.getRenderer().awake(); + this.updateRenderer(obj); } - get IsDirty() { + get IsDirty () { return this.isDirty; } - get Local2WorldMatrix() { + get Local2WorldMatrix () { this.UpdateMatrixUp(); + return this.local2WorldMatrix; } - get World2LocalMatrix() { + get World2LocalMatrix () { this.UpdateMatrixUp(); + return this.world2LocalMatrix; } - get LocalDegree() { + get LocalDegree () { return this.localDegree; } - set LocalDegree(value) { + set LocalDegree (value) { this.localDegree = value; this.isDirty = true; } - set LocalScale(value) { + set LocalScale (value) { this.localScale = value; this.isDirty = true; } - get LocalScale() { + get LocalScale () { return this.localScale; } - set LocalPositon(value) { + set LocalPositon (value) { this.localPositon = value; this.isDirty = true; } - get LocalPositon() { + get LocalPositon () { return this.localPositon; } - updateWorldTransform() { + updateWorldTransform () { if (this.parent != null) { this.worldPosition = this.parent.worldPosition.add(this.localPositon); this.worldDegree = this.parent.worldDegree + this.localDegree; @@ -181,8 +215,8 @@ export class Transform { } } - UpdateLocalTransform() { - let stack = []; + UpdateLocalTransform () { + const stack = []; let current = this; while (current != undefined) { @@ -191,9 +225,7 @@ export class Transform { } if (current.parent != null) { - current.localPositon = current.worldPosition.sub( - current.parent.worldPosition - ); + current.localPositon = current.worldPosition.sub(current.parent.worldPosition); current.localDegree = current.worldDegree - current.parent.worldDegree; current.localScale = current.worldScale.div(current.parent.worldScale); } else { @@ -206,7 +238,7 @@ export class Transform { } } - UpdateMatrixUp() { + UpdateMatrixUp () { if (this.parent != null) { this.parent.UpdateMatrixUp(); } @@ -214,16 +246,16 @@ export class Transform { this.UpdateMatrix(); } - UpdateMatrixDown() { + UpdateMatrixDown () { this.UpdateMatrix(); for (const child of this.child) { child.UpdateMatrixDown(); } } - UpdateMatrix() { - let world2Local = new Matrix3(); - let local2World = new Matrix3(); + UpdateMatrix () { + const world2Local = new Matrix3(); + const local2World = new Matrix3(); local2World.translate(-this.localPositon.x, -this.localPositon.y); local2World.Rotate(-this.LocalDegree); @@ -240,7 +272,7 @@ export class Transform { this.local2WorldMatrix = local2World; } - updateWorldPosition() { + updateWorldPosition () { if (this.parent != null) { this.parent.updateWorldPosition(); this.worldPosition = this.parent.worldPosition.add(this.localPositon); @@ -249,7 +281,7 @@ export class Transform { } } - updateW2LPostion() { + updateW2LPostion () { if (this.parent != null) { this.localPositon = this.worldPosition.sub(this.parent.worldPosition); } else { @@ -257,7 +289,7 @@ export class Transform { } } - updateW2LScale() { + updateW2LScale () { if (this.parent != null) { this.localScale = this.worldScale.div(this.parent.worldScale); } else { @@ -265,7 +297,7 @@ export class Transform { } } - updateW2LDegree() { + updateW2LDegree () { if (this.parent != null) { this.localDegree = this.worldDegree - this.parent.worldDegree; } else { @@ -273,7 +305,7 @@ export class Transform { } } - set WorldPosition(value) { + set WorldPosition (value) { this.updateWorldPosition(); this.worldPosition = value; this.updateW2LPostion(); @@ -281,12 +313,13 @@ export class Transform { this.isDirty = true; } - get WorldPosition() { + get WorldPosition () { this.updateWorldPosition(); + return this.worldPosition; } - updateWorldDegree() { + updateWorldDegree () { if (this.parent != null) { this.parent.updateWorldDegree(); this.worldDegree = this.parent.worldDegree + this.localDegree; @@ -295,11 +328,13 @@ export class Transform { } } - get WorldDegree() { + get WorldDegree () { this.updateWorldDegree(); + return this.worldDegree; } - set WorldDegree(value) { + + set WorldDegree (value) { this.updateWorldDegree(); this.worldDegree = value; this.updateW2LDegree(); @@ -307,7 +342,7 @@ export class Transform { this.isDirty = true; } - updateWorldScale() { + updateWorldScale () { if (this.parent != null) { this.parent.updateWorldScale(); this.worldScale = this.parent.worldScale.mul(this.localScale); @@ -316,7 +351,7 @@ export class Transform { } } - set WorldScale(value) { + set WorldScale (value) { this.updateWorldScale(); this.worldScale = value; this.updateW2LScale(); @@ -324,23 +359,24 @@ export class Transform { this.isDirty = true; } - get WorldScale() { + get WorldScale () { this.updateWorldScale(); + return this.worldScale; } - get WorldHeight() { + get WorldHeight () { return this.worldScale.y * this.Height; } - get WorldWidth() { + get WorldWidth () { return this.worldScale.x * this.Width; } - getGlobalRect() { - let position = this.WorldPosition; - let scale = this.WorldScale; - let rect = new Rect( + getGlobalRect () { + const position = this.WorldPosition; + const scale = this.WorldScale; + const rect = new Rect( position.x, position.y, this.WorldWidth * scale.x, @@ -349,4 +385,4 @@ export class Transform { return rect; } -} +} \ No newline at end of file diff --git a/Src/Core/Behaviours.ts b/Src/Core/Behaviours.ts index f3bcebb..18a53bc 100644 --- a/Src/Core/Behaviours.ts +++ b/Src/Core/Behaviours.ts @@ -1,33 +1,37 @@ -import { StormObject } from "./Widgets/StormObject"; -import { Transform } from "./Attributes/Transform"; -import { GUID } from "./Utils/GUID"; +import {StormObject} from "./Widgets/StormObject"; +import {Transform} from "./Attributes/Transform"; +import {GUID} from "./Utils/GUID"; export class Behaviour { isDisposed: boolean = false; + stormObject: StormObject; + transform: Transform; + _hash: GUID = new GUID(); - constructor() {} - get hash(): GUID { + constructor () {} + + get hash (): GUID { return this._hash; } - awake() {} + awake () {} - start() {} + start () {} - onEnable() {} + onEnable () {} - onDisable() {} + onDisable () {} // update() {} // lateUpdate() {} - onDestroy() {} + onDestroy () {} - destroy() { + destroy () { this.onDestroy(); this.isDisposed = true; } -} +} \ No newline at end of file diff --git a/Src/Core/DomElement.ts b/Src/Core/DomElement.ts index efe87d8..9881813 100644 --- a/Src/Core/DomElement.ts +++ b/Src/Core/DomElement.ts @@ -1,21 +1,24 @@ -import { JsonProperty, Serializable } from "./SerializeHelper"; -import { DoubleBind } from "./DoubleBind"; -import { StyleCacher } from "./StyleCacher"; -import { StyleAttributes } from './Attributes/StyleAttributes'; +import {JsonProperty, Serializable} from "./SerializeHelper"; +import {DoubleBind} from "./DoubleBind"; +import {StyleCacher} from "./StyleCacher"; +import {StyleAttributes} from "./Attributes/StyleAttributes"; @Serializable() export class DomElement { @JsonProperty() public domFileName: string | null = null; + public element: HTMLElement | null = null; + @JsonProperty() public attributes: StyleAttributes | null = null; - public destroy() { + public destroy () { if (this.element == null) { return; } const parent = this.element.parentNode; + if (parent != null) { parent.removeChild(this.element); } else { @@ -23,7 +26,7 @@ export class DomElement { } } - public SetAttribute(key: string, value: string) { + public SetAttribute (key: string, value: string) { if (this.element == null) { return; } @@ -31,40 +34,45 @@ export class DomElement { this.element.setAttribute(key, value); } - public create() { + public create () { const parser = new DOMParser(); const theme = StyleCacher.instance.get(this.domFileName); + if (theme == null) { return; } const doc = parser.parseFromString(theme, "text/html"); const node = doc.body.childNodes[0] as HTMLElement; + this.element = node; this.BindAttributes(node); } - public Load() { + public Load () { const parser = new DOMParser(); const theme = StyleCacher.instance.get(this.domFileName); + if (theme == null) { return; } const doc = parser.parseFromString(theme, "text/html"); const node = doc.body.childNodes[0] as HTMLElement; + this.element = node; this.LoadAttributes(); this.BindAttributes(this.element); } - public BindAttributes(element: HTMLElement) { + public BindAttributes (element: HTMLElement) { this.attributes = new StyleAttributes(); - var attributeKey = Reflect.ownKeys(this.attributes); + let attributeKey = Reflect.ownKeys(this.attributes); + this.UpdateAttributes(); console.log(this.attributes); DoubleBind.DataToBind(this.attributes); (this.attributes as any).___eventListener.onChange(() => { - for (let key of attributeKey) { + for (const key of attributeKey) { if (this.attributes[key] != undefined && this.attributes[key] != "") { element.style[key] = this.attributes[key]; } @@ -72,28 +80,31 @@ export class DomElement { }); } - public LoadAttributes() { + public LoadAttributes () { if (this.attributes == null) { return; } const attributes = new StyleAttributes(); const attributeKey = Reflect.ownKeys(attributes); - for (let key of attributeKey) { + + for (const key of attributeKey) { this.element.style[key] = this.attributes[key]; } } - public UpdateAttributes() { + public UpdateAttributes () { if (this.attributes == null) { return; } const attributes = new StyleAttributes(); const attributeKey = Reflect.ownKeys(attributes); - for (let key of attributeKey) { + + for (const key of attributeKey) { const value = this.element.style[key]; + this.attributes[key] = value; } } -} +} \ No newline at end of file diff --git a/Src/Core/EventManager.ts b/Src/Core/EventManager.ts index 0063d65..486e8d1 100644 --- a/Src/Core/EventManager.ts +++ b/Src/Core/EventManager.ts @@ -68,7 +68,7 @@ export class EventManager { public Regist( callback: Function, - target: object, + target: object|undefined, ...args: any[] | undefined ) { let callbackInfo = new CallbackInfo(); diff --git a/Src/Core/Input.ts b/Src/Core/Input.ts index 66ffb38..49df955 100644 --- a/Src/Core/Input.ts +++ b/Src/Core/Input.ts @@ -1,89 +1,141 @@ -import { StormObject } from "./Widgets/StormObject"; -import { Vector2 } from "./Math/Vector2"; -import { InputEvent } from "./InputEvent"; -import { Behaviour } from "./Behaviours"; +import {StormObject} from "./Widgets/StormObject"; +import {Vector2} from "./Math/Vector2"; +import {InputEvent} from "./InputEvent"; +import {Behaviour} from "./Behaviours"; +import {RendererPanel} from "./Renderer/Virtual/RendererPanel"; export class IClickable { - onClick(inputEvent: InputEvent) {} + onClick (inputEvent: InputEvent) {} } export class IMouseDown { - onMouseDown(inputEvent: InputEvent) {} + onMouseDown (inputEvent: InputEvent) {} } export class IMouseUp { - onMouseUP(inputEvent: InputEvent) {} + onMouseUP (inputEvent: InputEvent) {} } export class IDragStart { - onDragStart(inputEvent: InputEvent) {} + onDragStart (inputEvent: InputEvent) {} } export class IDragMove { - onDragMove(inputEvent: InputEvent) {} + onDragMove (inputEvent: InputEvent) {} } export class IDrop { - onDrop(inputEvent: InputEvent) {} + onDrop (inputEvent: InputEvent) {} } export class IMouseMove { - onMouseMove(inputEvent: InputEvent) {} + onMouseMove (inputEvent: InputEvent) {} } export class StormIter { private count = -2; + public children: StormIter[] = []; - public GetNext() { + + public GetNext () { if (this.count == -2) { this.count = this.children.length - 1; } if (this.count >= 0) { - let result = this.children[this.count]; + const result = this.children[this.count]; + this.count--; - return result; + + return result; } return undefined; } + stormObject: StormObject; } class InputTargetFinder { behaviours: Behaviour[] = []; + objects: StormObject[] = []; } export class InputInfo { target: StormObject; + DragStartTarget: StormObject | null = null; + inputEvent: InputEvent; } export class Input { public static CurrentInputTarget = new InputInfo(); + public static instance: Input = new Input(); - private constructor() {} + currentMouseDownTarget: StormObject | undefined = undefined; + + private constructor () {} + + FindTopObject ( + stormObject: StormObject, + inputEvent: InputEvent + ): InputTargetFinder { + const result = new InputTargetFinder(); + + const items: StormObject[] = []; + const tempList:StormObject[] = []; + + tempList.push(stormObject); + while (tempList.length > 0) { + const current = tempList.shift(); + + for (const iterator of current.transfrom.Children) { + tempList.push(iterator.StormObject); + } + if ( + current.transfrom. + getGlobalRect(). + IsIncluded(new Vector2(inputEvent.x, inputEvent.y)) + ) { + items.push(current); + } + } + + + for (let i = items.length - 1; i >= 0; i--) { + result.objects.push(items[i]); + const behaviours = items[i].getBehaviours(); + + for (const behaviour of behaviours) { + result.behaviours.push(behaviour); + } + } - FindTopObject( + return result; + } + + OldFindTopObject ( stormObject: StormObject, inputEvent: InputEvent ): InputTargetFinder { - let result = new InputTargetFinder(); - let stormList: StormObject[] = []; - let IterStack: StormIter[] = []; + const result = new InputTargetFinder(); + const stormList: StormObject[] = []; + const IterStack: StormIter[] = []; let currentStorm = stormObject; let currentStormIter = new StormIter(); - let root: StormIter = currentStormIter; + const root: StormIter = currentStormIter; + currentStormIter.stormObject = currentStorm; while (currentStorm != undefined) { for (const child of currentStorm.transfrom.Children) { stormList.push(child.StormObject); - let iter = new StormIter(); + const iter = new StormIter(); + iter.stormObject = child.StormObject; currentStormIter.children.push(iter); IterStack.push(iter); @@ -94,7 +146,7 @@ export class Input { } currentStormIter = root; - let stack: StormIter[] = []; + const stack: StormIter[] = []; while (currentStormIter != undefined || stack.length > 0) { while (currentStormIter != undefined) { @@ -103,18 +155,36 @@ export class Input { } currentStormIter = stack.pop(); - let behaviours = currentStormIter.stormObject.getBehaviours(); + const behaviours = currentStormIter.stormObject.getBehaviours(); if ( - currentStormIter.stormObject.transfrom - .getGlobalRect() - .IsIncluded(new Vector2(inputEvent.x, inputEvent.y)) + currentStormIter.stormObject.transfrom. + getGlobalRect(). + IsIncluded(new Vector2(inputEvent.x, inputEvent.y)) ) { + let currentRenderer = currentStormIter.stormObject.getRenderer(); + + while (currentRenderer instanceof RendererPanel == false) { + if (currentRenderer == undefined || currentRenderer == null) { + break; + } + + currentRenderer = currentRenderer.rendererPanel; + } + + + console.log(currentRenderer); + + if (currentRenderer == undefined) { + continue; + } + + for (const behaviour of behaviours) { if ( - behaviour.transform - .getGlobalRect() - .IsIncluded(new Vector2(inputEvent.x, inputEvent.y)) + behaviour.transform. + getGlobalRect(). + IsIncluded(new Vector2(inputEvent.x, inputEvent.y)) ) { result.behaviours.push(behaviour); } @@ -128,15 +198,14 @@ export class Input { return result; } - HandleClick(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleClick (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onClick != undefined; - }) - .first(); + const obj = ((inputEvent.behaviours)). + filter((item) => item.onClick != undefined). + first(); if (obj != null) { Input.CurrentInputTarget = new InputInfo(); @@ -146,17 +215,17 @@ export class Input { } } - HandleMouseDown(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleMouseDown (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onMouseDown != undefined; - }) - .first(); + const obj = ((inputEvent.behaviours)). + filter((item) => item.onMouseDown != undefined). + first(); if (obj != null) { + this.currentMouseDownTarget = (obj); Input.CurrentInputTarget = new InputInfo(); Input.CurrentInputTarget.target = ((obj)).stormObject; Input.CurrentInputTarget.inputEvent = inputEvent; @@ -165,15 +234,15 @@ export class Input { } } - HandleMouseUp(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleMouseUp (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onMouseUP != undefined; - }) - .first(); + this.currentMouseDownTarget = undefined; + const obj = ((inputEvent.behaviours)). + filter((item) => item.onMouseUP != undefined). + first(); if (obj != null) { Input.CurrentInputTarget = new InputInfo(); @@ -184,15 +253,14 @@ export class Input { } } - HandleMouseMove(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleMouseMove (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onMouseMove != undefined; - }) - .first(); + const obj = ((inputEvent.behaviours)). + filter((item) => item.onMouseMove != undefined). + first(); if (obj != null) { Input.CurrentInputTarget = new InputInfo(); @@ -203,15 +271,14 @@ export class Input { } } - HandleDragStart(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleDragStart (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onDragStart != undefined; - }) - .first(); + const obj = ((inputEvent.behaviours)). + filter((item) => item.onDragStart != undefined). + first(); if (obj != null) { Input.CurrentInputTarget = new InputInfo(); @@ -224,15 +291,14 @@ export class Input { } } - HandleDragMove(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleDragMove (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onDragMove != undefined; - }) - .first(); + const obj = ((inputEvent.behaviours)). + filter((item) => item.onDragMove != undefined). + first(); if (obj != null) { if (obj == Input.CurrentInputTarget.target) { @@ -242,15 +308,14 @@ export class Input { } } - HandleDrop(stormObject: StormObject, inputEvent: InputEvent) { - let objs = this.FindTopObject(stormObject, inputEvent); + HandleDrop (stormObject: StormObject, inputEvent: InputEvent) { + const objs = this.FindTopObject(stormObject, inputEvent); + inputEvent.behaviours = (objs.behaviours); inputEvent.objects = objs.objects; - let obj = ((inputEvent.behaviours)) - .filter(item => { - return item.onDrop != undefined; - }) - .first(); + const obj = ((inputEvent.behaviours)). + filter((item) => item.onDrop != undefined). + first(); if (obj != null) { if (obj == Input.CurrentInputTarget.target) { @@ -259,4 +324,4 @@ export class Input { } } } -} +} \ No newline at end of file diff --git a/Src/Core/InputEvent.ts b/Src/Core/InputEvent.ts index 15d905e..030c0ff 100644 --- a/Src/Core/InputEvent.ts +++ b/Src/Core/InputEvent.ts @@ -1,5 +1,5 @@ -import { Behaviour } from "./Behaviours"; -import { StormObject } from "./Widgets/StormObject"; +import {Behaviour} from "./Behaviours"; +import {StormObject} from "./Widgets/StormObject"; export const enum MouseKey { left = 0, middle, @@ -8,8 +8,12 @@ export const enum MouseKey { export class InputEvent { x: number; + y: number; + mouseKey: MouseKey; - behaviours: Behaviour[] = []; - objects: StormObject[] = []; -} + + behaviours: Array = []; + + objects: Array = []; +} \ No newline at end of file diff --git a/Src/Core/Layer.ts b/Src/Core/Layer.ts index 05f09ba..279d27a 100644 --- a/Src/Core/Layer.ts +++ b/Src/Core/Layer.ts @@ -1,3 +1,3 @@ export const enum Layer{ - default + default } \ No newline at end of file diff --git a/Src/Core/Math/MathEx.ts b/Src/Core/Math/MathEx.ts index 652f730..7643cb0 100644 --- a/Src/Core/Math/MathEx.ts +++ b/Src/Core/Math/MathEx.ts @@ -1,5 +1,13 @@ export class MathEx { - static degree2Radian(degree: number) { + static degree2Radian (degree: number) { return ((2 * Math.PI) / 360) * degree; } -} + + static lerp (x: number, y: number, t: number) { + return (1 - t) * x + t * y; + } + + static getPercentage (x: number, y: number, t: number) { + return (y - t) / (y - x); + } +} \ No newline at end of file diff --git a/Src/Core/Math/Rect.ts b/Src/Core/Math/Rect.ts index ecf0397..4588a77 100644 --- a/Src/Core/Math/Rect.ts +++ b/Src/Core/Math/Rect.ts @@ -1,17 +1,21 @@ -import { Vector2 } from "./Vector2"; +import {Vector2} from "./Vector2"; export class Rect { x: number; + y: number; + width: number; + height: number; - constructor(x: number, y: number, width: number, height: number) { + + constructor (x: number, y: number, width: number, height: number) { this.x = x; this.y = y; this.width = width; this.height = height; } - IsIncluded(vector2: Vector2): boolean { + IsIncluded (vector2: Vector2): boolean { if ( vector2.x > this.x + this.width || vector2.x < this.x || @@ -23,4 +27,13 @@ export class Rect { return true; } -} + + IsIncludedRect (rect:Rect):boolean { + if (rect.x + rect.width < this.x || rect.x > this.x + this.width || + rect.y + rect.height < this.y || rect.y > this.y + this.height) { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/Src/Core/Math/Vector2.ts b/Src/Core/Math/Vector2.ts index 5aac05b..93aada0 100644 --- a/Src/Core/Math/Vector2.ts +++ b/Src/Core/Math/Vector2.ts @@ -1,32 +1,33 @@ -import { Matrix3 } from "./Matrix3"; -import { Vector3 } from "./Vector3"; -import { Serializable } from "../Serializer"; +import {Matrix3} from "./Matrix3"; +import {Vector3} from "./Vector3"; +import {Serializable} from "../Serializer"; export class EditableVector2 { x: number; + y: number; - copy() { + copy () { return new Vector2(this.x, this.y); } - add(target: Vector2) { + add (target: Vector2) { return new Vector2(this.x + target.x, this.y + target.y); } - sub(target: Vector2) { + sub (target: Vector2) { return new Vector2(this.x - target.x, this.y - target.y); } - div(target: Vector2) { + div (target: Vector2) { return new Vector2(this.x / target.x, this.y / target.y); } - mul(target: Vector2) { + mul (target: Vector2) { return new Vector2(this.x * target.x, this.y * target.y); } - isEqual(target: Vector2) { + isEqual (target: Vector2) { if (this.x == target.x && this.y == target.y) { return true; } @@ -34,8 +35,9 @@ export class EditableVector2 { return false; } - multiplyMatrix3(matrix: Matrix3): Vector2 { - let vector = new Vector3(this.x, this.y, 1); + multiplyMatrix3 (matrix: Matrix3): Vector2 { + const vector = new Vector3(this.x, this.y, 1); + vector.multiplyMatrix3(matrix); this.x = vector.x; @@ -47,12 +49,13 @@ export class EditableVector2 { @Serializable() export class Vector2 extends EditableVector2 { - readonly x: number = 0; - readonly y: number = 0; + x: number = 0; - constructor(x: number = 0, y: number = 0) { + y: number = 0; + + constructor (x: number = 0, y: number = 0) { super(); this.x = x; this.y = y; } -} +} \ No newline at end of file diff --git a/Src/Core/Renderer/Virtual/RendererContainer.ts b/Src/Core/Renderer/Virtual/RendererContainer.ts index 52a6dd8..988b5bc 100644 --- a/Src/Core/Renderer/Virtual/RendererContainer.ts +++ b/Src/Core/Renderer/Virtual/RendererContainer.ts @@ -1,32 +1,36 @@ -import { RendererEmpty } from "./RendererEmpty"; -import { RenderItemConstructor, RenderItemBase } from "../RenderItemBase"; -import { CallMapper } from "../../Mapper"; -import { Enviroment } from "../../../Components/Enviroment"; -import { RendererType } from "./RendererType"; -import { Color } from "../../Math/Color"; +import {RendererEmpty} from "./RendererEmpty"; +import {RenderItemBase, RenderItemConstructor} from "../RenderItemBase"; +import {CallMapper} from "../../Mapper"; +import {Enviroment} from "../../../Components/Enviroment"; +import {RendererType} from "./RendererType"; +import {Color} from "../../Math/Color"; export class Border { color: Color = new Color(); + size: number = 1; } class Shader { color: Color = new Color(); + size: number = 1; } export class RendererContainer extends RendererEmpty { background: Color = new Color(); + border: Border | null = null; + shader: Shader = new Shader(); - renderItem(): RenderItemBase { - let constructor = CallMapper( + renderItem (): RenderItemBase { + const constructor = CallMapper( RendererType.Container, Enviroment.rendererTarget ); - let element = new constructor(); + const element = new constructor(); return element; } -} +} \ No newline at end of file diff --git a/Src/Core/Renderer/Virtual/RendererEmpty.ts b/Src/Core/Renderer/Virtual/RendererEmpty.ts index 952f7ea..3396cff 100644 --- a/Src/Core/Renderer/Virtual/RendererEmpty.ts +++ b/Src/Core/Renderer/Virtual/RendererEmpty.ts @@ -1,23 +1,40 @@ -import { RenderItemBase, RenderItemConstructor } from "../RenderItemBase"; -import { StormObject } from "../../Widgets/StormObject"; -import { Behaviour } from "../../Behaviours"; -import { CallMapper } from "../../Mapper"; -import { RendererType } from "./RendererType"; -import { Enviroment } from "../../../Components/Enviroment"; +import {RenderItemBase, RenderItemConstructor} from "../RenderItemBase"; +import {StormObject} from "../../Widgets/StormObject"; +import {Behaviour} from "../../Behaviours"; +import {CallMapper} from "../../Mapper"; +import {RendererType} from "./RendererType"; +import {Enviroment} from "../../../Components/Enviroment"; +import {RendererPanel} from "./RendererPanel"; export class RendererEmpty extends Behaviour { - setStromObject(stromObject: StormObject) { + rendererPanel: RendererPanel | undefined; + + awake () { + const renderer = this.stormObject.getParentRenderer(); + + if (renderer == undefined) { + return; + } + + if (renderer instanceof RendererPanel) { + this.rendererPanel = renderer; + } else { + this.rendererPanel = renderer.rendererPanel; + } + } + + setStromObject (stromObject: StormObject) { this.stormObject = stromObject; this.transform = stromObject.transfrom; } - renderItem(): RenderItemBase { - let constructor = CallMapper( + renderItem (): RenderItemBase { + const constructor = CallMapper( RendererType.Empty, Enviroment.rendererTarget ); - let element = new constructor(); + const element = new constructor(); return element; } -} +} \ No newline at end of file diff --git a/Src/Core/Renderer/Virtual/RendererPanel.ts b/Src/Core/Renderer/Virtual/RendererPanel.ts index 8190558..920c707 100644 --- a/Src/Core/Renderer/Virtual/RendererPanel.ts +++ b/Src/Core/Renderer/Virtual/RendererPanel.ts @@ -1,19 +1,24 @@ -import { RendererEmpty } from "./RendererEmpty"; -import { RenderItemConstructor, RenderItemBase } from "../RenderItemBase"; -import { CallMapper } from "../../Mapper"; -import { Enviroment } from "../../../Components/Enviroment"; -import { RendererType } from "./RendererType"; -import { Color } from "../../Math/Color"; +import {Enviroment} from "../../../Components/Enviroment"; +import {CallMapper} from "../../Mapper"; +import {Color} from "../../Math/Color"; +import {RenderItemBase, RenderItemConstructor} from "../RenderItemBase"; +import {RendererEmpty} from "./RendererEmpty"; +import {RendererType} from "./RendererType"; export class RendererPanel extends RendererEmpty { + depth: number = 0; + background: Color = new Color(); - renderItem(): RenderItemBase { - let constructor = CallMapper( + + isScrollable:boolean=false + + renderItem (): RenderItemBase { + const constructor = CallMapper( RendererType.Panel, Enviroment.rendererTarget ); - let element = new constructor(); + const element = new constructor(); return element; } -} +} \ No newline at end of file diff --git a/Src/Core/Renderer/Web/WebRenderer.ts b/Src/Core/Renderer/Web/WebRenderer.ts index 87808f9..aee9488 100644 --- a/Src/Core/Renderer/Web/WebRenderer.ts +++ b/Src/Core/Renderer/Web/WebRenderer.ts @@ -1,17 +1,17 @@ -import { Renderer } from "../Renderer"; -import { StormObject } from "../../Widgets/StormObject"; -import { WebPage } from "./WebPage"; -import { Vector2 } from "../../Math/Vector2"; -import { RenderItemBase } from "../RenderItemBase"; -import { Updater } from "../../Utils/Updater"; -import { Time } from "../../Time"; -import { WebEvent } from "./WebEvent"; -import { TransFormAttributes } from "../../Attributes/Transform"; -import { Anchor } from "../../Widgets/Anchor"; -import { RendererPanel } from "../Virtual/RendererPanel"; -import { RendererEmpty } from "../Virtual/RendererEmpty"; -import { Dictionary } from "../../Utils/Dictionary "; -import { RendererMask } from "../Virtual/RendererMask"; +import {Renderer} from "../Renderer"; +import {StormObject} from "../../Widgets/StormObject"; +import {WebPage} from "./WebPage"; +import {Vector2} from "../../Math/Vector2"; +import {RenderItemBase} from "../RenderItemBase"; +import {Updater} from "../../Utils/Updater"; +import {Time} from "../../Time"; +import {WebEvent} from "./WebEvent"; +import {TransFormAttributes} from "../../Attributes/Transform"; +import {Anchor} from "../../Widgets/Anchor"; +import {RendererPanel} from "../Virtual/RendererPanel"; +import {RendererEmpty} from "../Virtual/RendererEmpty"; +import {Dictionary} from "../../Utils/Dictionary "; +import {RendererMask} from "../Virtual/RendererMask"; export const enum EStormLifeCycle { awake = 1, @@ -27,26 +27,32 @@ export interface BehaviourLifeCycle { class RenderItemInfo { renderItem: RenderItemBase; + renderFrame: number; } export class WebRenderer extends Renderer { root: WebPage = new WebPage(); + parent: HTMLElement; + renderItems: Dictionary = new Dictionary< - string, - RenderItemInfo + string, + RenderItemInfo >(); + renderer: RendererEmpty | null = null; + renderFrame: number = 0; - updateRenderFrame() { + updateRenderFrame () { this.renderFrame++; this.renderFrame %= 10000000; } - mount(id: string) { - let element = document.getElementById(id); + mount (id: string) { + const element = document.getElementById(id); + this.parent = element; if (element != null) { element.appendChild(this.root.element); @@ -59,43 +65,14 @@ export class WebRenderer extends Renderer { } } - private executeBehaviourUpdate(stormObject: StormObject) { - let stormList: StormObject[] = []; - stormList.push(stormObject); - - let currentStorm = stormList.pop(); - while (currentStorm != undefined) { - for (const child of currentStorm.transfrom.Children) { - stormList.push(child.StormObject); - } - let behaviours = currentStorm.getBehaviours(); - - for (const behaviour of behaviours) { - let behaviourLifeCycle = (behaviour); - if ( - behaviourLifeCycle.__currentLife == EStormLifeCycle.update && - behaviour["update"] != undefined - ) { - behaviour["update"](); - } - if ( - behaviourLifeCycle.__currentLife == EStormLifeCycle.update && - behaviour["lateUpdate"] != undefined - ) { - behaviour["lateUpdate"](); - } - } - - currentStorm = stormList.pop(); - } - } - - private executeUpdateAnchor(stormObject: StormObject) { + private executeUpdateAnchor (stormObject: StormObject) { Anchor.UpdateAnchorFrame(); - let stormList: StormObject[] = []; + const stormList: Array = []; + stormList.push(stormObject); let currentStorm = stormList.pop(); + while (currentStorm != undefined) { for (const child of currentStorm.transfrom.Children) { stormList.push(child.StormObject); @@ -107,20 +84,22 @@ export class WebRenderer extends Renderer { } } - private executeInitBehaviour(stormObject: StormObject) { - let stormList: StormObject[] = []; + private executeInitBehaviour (stormObject: StormObject) { + const stormList: Array = []; + stormList.push(stormObject); let currentStorm = stormList.pop(); + while (currentStorm != undefined) { for (const child of currentStorm.transfrom.Children) { stormList.push(child.StormObject); } - let behaviours = currentStorm.getBehaviours(); + const behaviours = currentStorm.getBehaviours(); for (const behaviour of behaviours) { - let behaviourLifeCycle = (behaviour); + const behaviourLifeCycle = (behaviour); if (behaviourLifeCycle.__currentLife == undefined) { behaviourLifeCycle.__currentLife = EStormLifeCycle.awake; @@ -140,13 +119,26 @@ export class WebRenderer extends Renderer { behaviour.start(); behaviourLifeCycle.__currentLife++; } + + if ( + behaviourLifeCycle.__currentLife == EStormLifeCycle.update && + behaviour.update != undefined + ) { + behaviour.update(); + } + if ( + behaviourLifeCycle.__currentLife == EStormLifeCycle.update && + behaviour.lateUpdate != undefined + ) { + behaviour.lateUpdate(); + } } currentStorm = stormList.pop(); } } - private RenderImp(stormObject: StormObject) { + private RenderImp (stormObject: StormObject) { Time.deltaTime = new Date().getTime() - this.recordTime; Time.deltaTime /= 1000; this.updateRenderFrame(); @@ -156,12 +148,12 @@ export class WebRenderer extends Renderer { } this.recordTime = new Date().getTime(); - let stormList: StormObject[] = []; + const stormList: Array = []; + stormList.push(stormObject); let currentStorm = stormList.pop(); this.executeInitBehaviour(stormObject); - this.executeBehaviourUpdate(stormObject); stormObject.transfrom.updateWorldTransform(); this.executeUpdateAnchor(stormObject); @@ -172,16 +164,14 @@ export class WebRenderer extends Renderer { stormList.push(child.StormObject); } - let renderer = currentStorm.getRenderer(); + const renderer = currentStorm.getRenderer(); if (renderer == undefined) { currentStorm = stormList.shift(); continue; } - let renderItemInfo: RenderItemInfo = this.renderItems.Get( - renderer.hash.toString() - ); + let renderItemInfo: RenderItemInfo = this.renderItems.Get(renderer.hash.toString()); if (renderItemInfo == undefined) { renderItemInfo = new RenderItemInfo(); @@ -197,9 +187,7 @@ export class WebRenderer extends Renderer { while (render != undefined) { if (render.StormObject.getRenderer() != undefined) { - item = this.renderItems.Get( - render.StormObject.getRenderer().hash.toString() - ); + item = this.renderItems.Get(render.StormObject.getRenderer().hash.toString()); break; } @@ -218,7 +206,7 @@ export class WebRenderer extends Renderer { // renderItemInfo.renderItem.setVisible(visible); // }); - let transFormAttributes = ( + const transFormAttributes = ( (currentStorm.transfrom) ); @@ -230,7 +218,8 @@ export class WebRenderer extends Renderer { currentObj.transfrom.Parent != undefined ) { currentObj = currentObj.transfrom.Parent.StormObject; - let renderer = currentObj.getRenderer(); + const renderer = currentObj.getRenderer(); + if (renderer == null || renderer == undefined) { position = position.add(currentObj.transfrom.LocalPositon); } else { @@ -240,12 +229,10 @@ export class WebRenderer extends Renderer { renderItemInfo.renderItem.setPosition(position); - renderItemInfo.renderItem.setScale( - new Vector2( - transFormAttributes.WorldWidth, - transFormAttributes.WorldHeight - ) - ); + renderItemInfo.renderItem.setScale(new Vector2( + transFormAttributes.WorldWidth, + transFormAttributes.WorldHeight + )); renderItemInfo.renderItem.setRotate(transFormAttributes.worldDegree); currentStorm = stormList.shift(); @@ -254,11 +241,11 @@ export class WebRenderer extends Renderer { this.destroyUnusedRenderItem(); } - private destroyUnusedRenderItem() { - let keys = this.renderItems.Keys(); + private destroyUnusedRenderItem () { + const keys = this.renderItems.Keys(); for (const key of keys) { - let value = this.renderItems[key.toString()]; + const value = this.renderItems[key.toString()]; if (value.renderFrame != this.renderFrame) { value.renderItem.destroy(); @@ -270,16 +257,18 @@ export class WebRenderer extends Renderer { recordTime: number = 0; maskCount = 0; - masks: StormObject[] = []; - setMask(count: number) { + + masks: Array = []; + + setMask (count: number) { this.maskCount = Math.max(count, 3); } - getMask(index: number) { + getMask (index: number) { return this.masks[index]; } - Render(renderer: RendererPanel) { + Render (renderer: RendererPanel) { if (this.parent != undefined) { renderer.transform.Width = this.parent.offsetWidth; renderer.transform.Height = this.parent.offsetHeight; @@ -294,19 +283,20 @@ export class WebRenderer extends Renderer { }, null); for (let index = 0; index < this.maskCount; index++) { - let mask = new StormObject(); + const mask = new StormObject(); + mask.name = "MaskLayer"; - mask.name = "maskLayer" + index; + mask.name = `maskLayer${index}`; mask.setRenderer(RendererMask); mask.transfrom.Parent = renderer.transform; - mask.transfrom.anchor.left.target=renderer.transform - mask.transfrom.anchor.right.target=renderer.transform - mask.transfrom.anchor.top.target=renderer.transform - mask.transfrom.anchor.bottom.target=renderer.transform + mask.transfrom.anchor.left.target = renderer.transform; + mask.transfrom.anchor.right.target = renderer.transform; + mask.transfrom.anchor.top.target = renderer.transform; + mask.transfrom.anchor.bottom.target = renderer.transform; this.masks.push(mask); } WebEvent.reigst(this.root.element, renderer.stormObject); Updater.instance.start(); } -} +} \ No newline at end of file diff --git a/Src/Core/StormObject.ts b/Src/Core/StormObject.ts index a997dda..85c957e 100644 --- a/Src/Core/StormObject.ts +++ b/Src/Core/StormObject.ts @@ -1,64 +1,73 @@ -import { DomElement } from "./DomElement"; -import { StormComponent } from "./StormComponent"; -import { JsonProperty, Serializable } from "./SerializeHelper"; -import { Md5 } from "ts-md5"; -import { StormPool } from "./StormPool"; +import {DomElement} from "./DomElement"; +import {StormComponent} from "./StormComponent"; +import {JsonProperty, Serializable} from "./SerializeHelper"; +import {Md5} from "ts-md5"; +import {StormPool} from "./StormPool"; @Serializable() export class StormObject { @JsonProperty() public domElement: DomElement = new DomElement(); + @JsonProperty() public components: Array = []; + parent: StormObject; + children: Array = []; + @JsonProperty() parentHash: string; + @JsonProperty() childrenHash: Array = []; + @JsonProperty() hash: string; + @JsonProperty() - styles:string[] + styles: Array; - private constructor() {} + private constructor () {} + + public static New (): StormObject { + const result = new StormObject(); - public static New(): StormObject { - let result = new StormObject(); result.init(); return result; } - public init() { + public init () { this.hash = Md5.hashStr(Date.now().toString()).toString(); StormPool.instance.add(this); } - public LoadHash() { + public LoadHash () { StormPool.instance.add(this); } - public startLife() { + public startLife () { for (const component of this.components) { // component.stormObject = this; } } - public Load() { + public Load () { this.startLife(); this.domElement.Load(); this.domElement.SetAttribute("key", this.hash); } - public addComponent(component: any) { + public addComponent (component: any) { this.components.push(component); component.stormObject = this; } - public removeComponent(component: any) { + public removeComponent (component: any) { for (let index = 0; index < this.components.length; index++) { const element = this.components[index]; + if (element == component) { if (element == component) { return; @@ -67,24 +76,24 @@ export class StormObject { } } - public setDom(path: any) { + public setDom (path: any) { this.domElement.domFileName = path; } - public Refresh() { + public Refresh () { this.domElement.destroy(); this.domElement.create(); this.domElement.SetAttribute("key", this.hash); } - public static Destroy(stormObject: StormObject) { + public static Destroy (stormObject: StormObject) { StormPool.instance.remove(stormObject); stormObject.domElement.destroy(); } - public RemoveChild(stormObject: StormObject) {} + public RemoveChild (stormObject: StormObject) {} - public AddChild(stormObject: StormObject) { + public AddChild (stormObject: StormObject) { this.children.push(stormObject); this.childrenHash.push(stormObject.hash); stormObject.parent = this; @@ -92,7 +101,7 @@ export class StormObject { this.domElement.element.appendChild(stormObject.domElement.element); } - public static FindFromHash(hash: string): StormObject { + public static FindFromHash (hash: string): StormObject { return StormPool.instance.get(hash); } -} +} \ No newline at end of file diff --git a/Src/Core/StormPool.ts b/Src/Core/StormPool.ts index 7feaa7c..20003e7 100644 --- a/Src/Core/StormPool.ts +++ b/Src/Core/StormPool.ts @@ -1,19 +1,20 @@ -import { StormObject } from "./StormObject"; +import {StormObject} from "./StormObject"; export class StormPool { public static instance: StormPool = new StormPool(); - private constructor() {} + private constructor () {} + stormObjects: { [key: string]: StormObject } = {}; - public add(stormObject: StormObject) { + public add (stormObject: StormObject) { this.stormObjects[stormObject.hash] = stormObject; } - public get(hash: string) { + public get (hash: string) { return this.stormObjects[hash]; } - public remove(stormObject: StormObject) { + public remove (stormObject: StormObject) { this.stormObjects[stormObject.hash] = null; } -} +} \ No newline at end of file diff --git a/Src/Core/StyleCacher.ts b/Src/Core/StyleCacher.ts index dcde653..d859e71 100644 --- a/Src/Core/StyleCacher.ts +++ b/Src/Core/StyleCacher.ts @@ -1,11 +1,13 @@ export class StyleCacher { public static instance: StyleCacher = new StyleCacher(); + themes: { [key: string]: string } = {}; - public AddStyle(key: string, value: string) { + + public AddStyle (key: string, value: string) { this.themes[key] = value; } - public get(key: string) { + public get (key: string) { return this.themes[key]; } -} +} \ No newline at end of file diff --git a/Src/Core/Utils/Dictionary .ts b/Src/Core/Utils/Dictionary .ts index 96faf50..c0c5574 100644 --- a/Src/Core/Utils/Dictionary .ts +++ b/Src/Core/Utils/Dictionary .ts @@ -1,13 +1,14 @@ -import { ObjectMarker, MarkedObject } from "./ObjectMarker"; +import {MarkedObject, ObjectMarker} from "./ObjectMarker"; export class Dictionary< TType extends number | object | string, TValue extends any > { private keys: TType[] = []; + private values: TValue[] = []; - Add(key: TType, value: TValue): void { + Add (key: TType, value: TValue): void { if (key == null || key == undefined) { return; } @@ -15,7 +16,8 @@ export class Dictionary< let strKey: string; if (typeof key == "object") { - let obj = ObjectMarker.MarkObject(key); + const obj = ObjectMarker.MarkObject(key); + strKey = obj.___Hash___; } else { strKey = key.toString(); @@ -26,30 +28,30 @@ export class Dictionary< this.values.push(value); } - private getKeyStr(key: TType): string { + private getKeyStr (key: TType): string { if (typeof key == "object") { if (ObjectMarker.IsMarkedObject(key)) { return (key).___Hash___; } return undefined; - } else { - return key.toString(); } + + return key.toString(); } - Get(key: TType): TValue { - let strKey = this.getKeyStr(key); + Get (key: TType): TValue { + const strKey = this.getKeyStr(key); return this[strKey]; } - Remove(key: TType): void { + Remove (key: TType): void { if (key == null || key == undefined) { return; } - let strKey = this.getKeyStr(key); + const strKey = this.getKeyStr(key); if (this[strKey] == undefined) { return; @@ -57,7 +59,7 @@ export class Dictionary< delete this[strKey]; - var index = this.keys.indexOf(key, 0); + const index = this.keys.indexOf(key, 0); if (index >= 0 && index < this.keys.length) { this.keys.splice(index, 1); @@ -65,27 +67,28 @@ export class Dictionary< } } - Keys(): TType[] { + Keys (): TType[] { return this.keys.copy(); } - Values(): TValue[] { + Values (): TValue[] { return this.values.copy(); } - ContainsKey(key: TType): boolean { - let strKey = this.getKeyStr(key); + ContainsKey (key: TType): boolean { + const strKey = this.getKeyStr(key); return this[strKey] != undefined; } - ToList() { - let result = []; + ToList () { + const result = []; for (let index = 0; index < this.keys.length; index++) { const key = this.keys[index]; const value = this.values[index]; - let keyValuePair = new KeyValuePair(); + const keyValuePair = new KeyValuePair(); + keyValuePair.key = key; keyValuePair.value = value; result.push(keyValuePair); @@ -97,5 +100,6 @@ export class Dictionary< export class KeyValuePair { key: TType; + value: TValue; -} +} \ No newline at end of file diff --git a/Src/Core/Widgets/Scene.ts b/Src/Core/Widgets/Scene.ts index f0720c3..a2536a6 100644 --- a/Src/Core/Widgets/Scene.ts +++ b/Src/Core/Widgets/Scene.ts @@ -1,9 +1,9 @@ -import { StormObject } from "./StormObject"; -import { RendererContainer } from "../Renderer/Virtual/RendererContainer"; +import {StormObject} from "./StormObject"; +import {RendererContainer} from "../Renderer/Virtual/RendererContainer"; export class Scene extends StormObject { - constructor() { + constructor () { super(); this.setRenderer(RendererContainer); } -} +} \ No newline at end of file diff --git a/Src/Core/Widgets/StormObject.ts b/Src/Core/Widgets/StormObject.ts index 06d4f52..b12e6c9 100644 --- a/Src/Core/Widgets/StormObject.ts +++ b/Src/Core/Widgets/StormObject.ts @@ -1,44 +1,54 @@ -import { Behaviour } from "../Behaviours"; +import {Behaviour} from "../Behaviours"; -import { DeepCloner } from "./DeepCloner"; -import { GUID } from "../Utils/GUID"; -import { RendererEmpty } from "../Renderer/Virtual/RendererEmpty"; -import { Transform } from "../Attributes/Transform"; -import { Layer } from "../Layer"; -import { EventManager } from "../EventManager"; -import { HierachyItem } from "../../Components/HierachyItem"; +import {DeepCloner} from "./DeepCloner"; +import {GUID} from "../Utils/GUID"; +import {RendererEmpty} from "../Renderer/Virtual/RendererEmpty"; +import {Transform} from "../Attributes/Transform"; +import {Layer} from "../Layer"; +import {EventManager} from "../EventManager"; +import {HierachyItem} from "../../Components/HierachyItem"; import { BehaviourLifeCycle, EStormLifeCycle } from "../Renderer/Web/WebRenderer"; -import { Serializable } from "../Serializer"; +import {Serializable} from "../Serializer"; +import {RendererPanel} from "../Renderer/Virtual/RendererPanel"; @HierachyItem("StormObject") @Serializable() export class StormObject { private renderer: RendererEmpty | undefined = undefined; + private active: boolean = true; - behaviours: Behaviour[] = []; + + behaviours: Array = []; + hash: GUID = new GUID(); + name: string = "StormObject"; + transfrom: Transform; + drag: DragDrop | null = null; + drop: DragDrop | null = null; + layer: Layer = Layer.default; + onActiveChange: EventManager = new EventManager(); - constructor() { + constructor () { this.transfrom = new Transform(); this.transfrom.StormObject = this; } - getParentRenderer(): RendererEmpty { + getParentRenderer (): RendererEmpty { if (this.transfrom.Parent == undefined) { return undefined; } - let renderer: RendererEmpty = this.transfrom.Parent.StormObject.renderer; + let {renderer} = this.transfrom.Parent.StormObject; if (renderer == undefined) { renderer = this.transfrom.Parent.StormObject.getRenderer(); @@ -47,17 +57,39 @@ export class StormObject { return renderer; } - setRenderer(c: new () => T): T { + getScrollableRenderer ():RendererPanel { + const result = this.getRenderer(); + + + return result; + } + + findParent (where:(obj:StormObject)=>boolean):StormObject { + let result:StormObject = this.transfrom.StormObject; + + while (!where(result)) { + if (result == undefined) { + return undefined; + } + + result = result.transfrom.Parent.StormObject; + } + + return result; + } + + setRenderer (c: new () => T): T { this.renderer = new c(); this.renderer.setStromObject(this); - return this.renderer; + + return this.renderer; } - getRenderer() { - return (this.renderer); + getRenderer () { + return ( this.renderer); } - setActive(visible: boolean) { + setActive (visible: boolean) { if (visible == this.active) { return; } @@ -65,7 +97,8 @@ export class StormObject { this.active = visible; for (const behaviour of this.behaviours) { - let behaviourLifeCycle = (behaviour); + const behaviourLifeCycle = (behaviour); + if ( behaviourLifeCycle.__currentLife == undefined || behaviourLifeCycle.__currentLife <= EStormLifeCycle.enable @@ -82,12 +115,13 @@ export class StormObject { this.onActiveChange.Call(this, this.active); } - getActive() { + getActive () { return this.active; } - addBehaviour(c: new () => T): T { - let behaviour = new c(); + addBehaviour (c: new () => T): T { + const behaviour = new c(); + behaviour.stormObject = this; behaviour.transform = this.transfrom; this.behaviours.push(behaviour); @@ -95,7 +129,7 @@ export class StormObject { return behaviour; } - getBehaviour(type): undefined | T { + getBehaviour (type): undefined | T { for (const behaviour of this.behaviours) { if (behaviour instanceof type) { return behaviour; @@ -105,11 +139,11 @@ export class StormObject { return undefined; } - getBehaviours() { + getBehaviours () { return this.behaviours; } - destroy() { + destroy () { for (const child of this.transfrom.Children) { child.StormObject.destroy(); } @@ -125,8 +159,8 @@ export class StormObject { this.transfrom.destroy(); } - static Instantiate(widget: StormObject): StormObject { - let obj = DeepCloner.Clone(widget); + static Instantiate (widget: StormObject): StormObject { + const obj = DeepCloner.Clone(widget); return obj; } @@ -151,6 +185,8 @@ export class StormObject { export class DragDrop { id: string; + canDrag: boolean = false; - canDropId: string[] = []; -} + + canDropId: Array = []; +} \ No newline at end of file diff --git a/Src/Core/main.ts b/Src/Core/main.ts index 833840a..ba36b42 100644 --- a/Src/Core/main.ts +++ b/Src/Core/main.ts @@ -1,7 +1,10 @@ -import { Storm, StormData } from "./Storm"; -var model = { name1: 11, name2: 22 }; -var data = { name: "root", data: model } -var a = new Storm(data); +import {Storm, StormData} from "./Storm"; +let model = {name1: 11, +name2: 22}; +let data = {name: "root", +data: model}; +let a = new Storm(data); + setTimeout(() => { - model.name1 = 11111; -}, 1000); + model.name1 = 11111; +}, 1000); \ No newline at end of file diff --git a/Src/Editor/Bottom/ComponentFile.ts b/Src/Editor/Bottom/ComponentFile.ts new file mode 100644 index 0000000..0501a7a --- /dev/null +++ b/Src/Editor/Bottom/ComponentFile.ts @@ -0,0 +1,34 @@ +import {Behaviour} from "../../Core/Behaviours"; +import {Inject} from "../Core/Decorators/Inject"; +import {GlobalData} from "../../GlobalData"; +import {fstat, readdir, readdirSync} from "fs"; +import {StormObject} from "../../Core/Widgets/StormObject"; +import {List} from "../../Components/BasicComponents/List"; +import {RendererLabel} from "../../Core/Renderer/Virtual/RendererLabel"; +import {Label} from "../../Components/BasicComponents/Label"; +export class ComponentFile extends Behaviour { + @Inject(GlobalData) + globalData: GlobalData; + + awake () { + let path = `${this.globalData.currentPath}d:/`; + + path = "d://"; + const values = readdirSync(path); + + console.log(values); + + const cmpList = this.stormObject.getBehaviour(List); + const obj = new StormObject(); + + obj.setRenderer(RendererLabel); + obj.addBehaviour