Prechádzať zdrojové kódy

segment -> multiLinePoint

Royi Bernthal 7 rokov pred
rodič
commit
79ee4243e9
3 zmenil súbory, kde vykonal 38 pridanie a 39 odobranie
  1. 1 1
      Tools/Gulp/config.json
  2. 34 35
      gui/src/controls/multiLine.ts
  3. 3 3
      gui/src/segment.ts

+ 1 - 1
Tools/Gulp/config.json

@@ -1622,7 +1622,7 @@
                     "../../gui/src/measure.ts",
                     "../../gui/src/math2D.ts",
                     "../../gui/src/valueAndUnit.ts",
-                    "../../gui/src/segment.ts",
+                    "../../gui/src/multiLinePoint.ts",
                     "../../gui/src/controls/control.ts",
                     "../../gui/src/controls/container.ts",
                     "../../gui/src/controls/stackPanel.ts",

+ 34 - 35
gui/src/controls/multiLine.ts

@@ -6,7 +6,7 @@ module BABYLON.GUI {
 
         private _lineWidth: number = 1;
         private _dash: number[];
-        private _segments: Nullable<Segment>[];
+        private _points: Nullable<MultiLinePoint>[];
 
         private _minX: Nullable<number>;
         private _minY: Nullable<number>;
@@ -21,7 +21,7 @@ module BABYLON.GUI {
             this._verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
 
             this._dash = [];
-            this._segments = [];
+            this._points = [];
         }
 
         public get dash(): Array<number> {
@@ -37,44 +37,44 @@ module BABYLON.GUI {
             this._markAsDirty();
         }
 
-        getAt(index: number): Segment {
-            if (!this._segments[index]) {
-                this._segments[index] = new Segment(this);
+        getAt(index: number): MultiLinePoint {
+            if (!this._points[index]) {
+                this._points[index] = new MultiLinePoint(this);
             }
 
-            return this._segments[index] as Segment;
+            return this._points[index] as MultiLinePoint;
         }
 
-        onSegmentUpdate = (): void => {
+        onPointUpdate = (): void => {
             this._markAsDirty();
         }
 
         add(...items: (AbstractMesh | Control | IValueAndUnitVector2)[]): void {
             items.forEach(item => {
-                var segment: Segment = this.push();
+                var point: MultiLinePoint = this.push();
 
                 if (item instanceof AbstractMesh) {
-                    segment.mesh = item;
+                    point.mesh = item;
                 }
                 else if (item instanceof Control) {
-                    segment.control = item;
+                    point.control = item;
                 }
                 else if (item.x != null && item.y != null) {
-                    segment.x = item.x;
-                    segment.y = item.y;
+                    point.x = item.x;
+                    point.y = item.y;
                 }
             });
         }
 
-        push(): Segment {
-            return this.getAt(this._segments.length);
+        push(): MultiLinePoint {
+            return this.getAt(this._points.length);
         }
 
-        remove(value: number | Segment): void {
+        remove(value: number | MultiLinePoint): void {
             var index: number;
             
-            if (value instanceof Segment) {
-                index = this._segments.indexOf(value);
+            if (value instanceof MultiLinePoint) {
+                index = this._points.indexOf(value);
 
                 if (index === -1) {
                     return;
@@ -84,16 +84,15 @@ module BABYLON.GUI {
                 index = value;
             }
             
-            var segment: Nullable<Segment> = this._segments[index];
+            var point: Nullable<MultiLinePoint> = this._points[index];
 
-            if (!segment) {
+            if (!point) {
                 return;
             }
 
-            segment.mesh = null;
-            segment.control = null;
+            point.dispose();
 
-            this._segments.splice(index, 1);
+            this._points.splice(index, 1);
         }
         
         public get lineWidth(): number {
@@ -142,18 +141,18 @@ module BABYLON.GUI {
 
                 var first: boolean = true; //first index is not necessarily 0
 
-                this._segments.forEach(segment => {
-                    if (!segment) {
+                this._points.forEach(point => {
+                    if (!point) {
                         return;
                     }
 
                     if (first) {
-                        context.moveTo(segment._point.x, segment._point.y);
+                        context.moveTo(point._point.x, point._point.y);
 
                         first = false;
                     }
                     else {
-                        context.lineTo(segment._point.x, segment._point.y);
+                        context.lineTo(point._point.x, point._point.y);
                     }
                 });
 
@@ -169,17 +168,17 @@ module BABYLON.GUI {
             this._maxX = null;
             this._maxY = null;
             
-            this._segments.forEach((segment, index) => {
-                if (!segment) {
+            this._points.forEach((point, index) => {
+                if (!point) {
                     return;
                 }
 
-                segment.translate();
+                point.translate();
 
-                if (this._minX == null || segment._point.x < this._minX) this._minX = segment._point.x;
-                if (this._minY == null || segment._point.y < this._minY) this._minY = segment._point.y;
-                if (this._maxX == null || segment._point.x > this._maxX) this._maxX = segment._point.x;
-                if (this._maxY == null || segment._point.y > this._maxY) this._maxY = segment._point.y;
+                if (this._minX == null || point._point.x < this._minX) this._minX = point._point.x;
+                if (this._minY == null || point._point.y < this._minY) this._minY = point._point.y;
+                if (this._maxX == null || point._point.x > this._maxX) this._maxX = point._point.x;
+                if (this._maxY == null || point._point.y > this._maxY) this._maxY = point._point.y;
             });
 
             if (this._minX == null) this._minX = 0;
@@ -207,8 +206,8 @@ module BABYLON.GUI {
         }
 
         dispose(): void {
-            while (this._segments.length > 0) {
-                this.remove(this._segments.length - 1);
+            while (this._points.length > 0) {
+                this.remove(this._points.length - 1);
             }
         }
 

+ 3 - 3
gui/src/segment.ts

@@ -2,7 +2,7 @@
 
 module BABYLON.GUI {
 
-    export class Segment {
+    export class MultiLinePoint {
 
         private _multiLine: MultiLine;
 
@@ -71,7 +71,7 @@ module BABYLON.GUI {
             this._control = value;
 
             if (this._control) {
-                this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onSegmentUpdate);
+                this._controlObserver = this._control.onDirtyObservable.add(this._multiLine.onPointUpdate);
             }
 
             this._multiLine._markAsDirty();
@@ -93,7 +93,7 @@ module BABYLON.GUI {
             this._mesh = value;
 
             if (this._mesh) {
-                this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onSegmentUpdate);
+                this._meshObserver = this._mesh.getScene().onAfterCameraRenderObservable.add(this._multiLine.onPointUpdate);
             }
 
             this._multiLine._markAsDirty();