|
@@ -4,12 +4,14 @@ import { PointerInfo, PointerEventTypes } from "babylonjs/Events/pointerEvents";
|
|
|
|
|
|
import { Rectangle } from "../rectangle";
|
|
|
import { Grid } from "../grid";
|
|
|
+import { Image } from "../image";
|
|
|
import { Control } from "../control";
|
|
|
import { Container } from "../container";
|
|
|
import { Measure } from "../../measure";
|
|
|
import { AdvancedDynamicTexture } from "../../advancedDynamicTexture";
|
|
|
import { _ScrollViewerWindow } from "./scrollViewerWindow";
|
|
|
import { ScrollBar } from "../sliders/scrollBar";
|
|
|
+import { ImageScrollBar } from "../sliders/imageScrollBar";
|
|
|
import { _TypeStore } from 'babylonjs/Misc/typeStore';
|
|
|
|
|
|
/**
|
|
@@ -20,10 +22,12 @@ export class ScrollViewer extends Rectangle {
|
|
|
private _horizontalBarSpace: Rectangle;
|
|
|
private _verticalBarSpace: Rectangle;
|
|
|
private _dragSpace: Rectangle;
|
|
|
- private _horizontalBar: ScrollBar;
|
|
|
- private _verticalBar: ScrollBar;
|
|
|
+ private _horizontalBar: ScrollBar | ImageScrollBar;
|
|
|
+ private _verticalBar: ScrollBar | ImageScrollBar;
|
|
|
private _barColor: string;
|
|
|
private _barBackground: string;
|
|
|
+ private _barImage: Image;
|
|
|
+ private _barBackgroundImage: Image;
|
|
|
private _barSize: number = 20;
|
|
|
private _endLeft: number;
|
|
|
private _endTop: number;
|
|
@@ -33,18 +37,22 @@ export class ScrollViewer extends Rectangle {
|
|
|
private _onPointerObserver: Nullable<Observer<PointerInfo>>;
|
|
|
private _clientWidth: number;
|
|
|
private _clientHeight: number;
|
|
|
+ private _useImageBar: Boolean;
|
|
|
+ private _thumbLength: number = 0.5;
|
|
|
+ private _thumbHeight: number = 1;
|
|
|
+ private _barImageHeight: number = 1;
|
|
|
|
|
|
/**
|
|
|
* Gets the horizontal scrollbar
|
|
|
*/
|
|
|
- public get horizontalBar(): ScrollBar {
|
|
|
+ public get horizontalBar(): ScrollBar | ImageScrollBar {
|
|
|
return this._horizontalBar;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Gets the vertical scrollbar
|
|
|
*/
|
|
|
- public get verticalBar(): ScrollBar {
|
|
|
+ public get verticalBar(): ScrollBar | ImageScrollBar {
|
|
|
return this._verticalBar;
|
|
|
}
|
|
|
|
|
@@ -88,9 +96,11 @@ export class ScrollViewer extends Rectangle {
|
|
|
* Creates a new ScrollViewer
|
|
|
* @param name of ScrollViewer
|
|
|
*/
|
|
|
- constructor(name?: string) {
|
|
|
+ constructor(name?: string, isImageBased?: boolean) {
|
|
|
super(name);
|
|
|
|
|
|
+ this._useImageBar = isImageBased ? isImageBased : false;
|
|
|
+
|
|
|
this.onDirtyObservable.add(() => {
|
|
|
this._horizontalBarSpace.color = this.color;
|
|
|
this._verticalBarSpace.color = this.color;
|
|
@@ -106,8 +116,14 @@ export class ScrollViewer extends Rectangle {
|
|
|
});
|
|
|
|
|
|
this._grid = new Grid();
|
|
|
- this._horizontalBar = new ScrollBar();
|
|
|
- this._verticalBar = new ScrollBar();
|
|
|
+ if (this._useImageBar) {
|
|
|
+ this._horizontalBar = new ImageScrollBar();
|
|
|
+ this._verticalBar = new ImageScrollBar();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._horizontalBar = new ScrollBar();
|
|
|
+ this._verticalBar = new ScrollBar();
|
|
|
+ }
|
|
|
|
|
|
this._window = new _ScrollViewerWindow();
|
|
|
this._window.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
|
|
@@ -121,57 +137,29 @@ export class ScrollViewer extends Rectangle {
|
|
|
super.addControl(this._grid);
|
|
|
this._grid.addControl(this._window, 0, 0);
|
|
|
|
|
|
- this._verticalBar.paddingLeft = 0;
|
|
|
- this._verticalBar.width = "100%";
|
|
|
- this._verticalBar.height = "100%";
|
|
|
- this._verticalBar.barOffset = 0;
|
|
|
- this._verticalBar.value = 0;
|
|
|
- this._verticalBar.maximum = 1;
|
|
|
- this._verticalBar.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
|
|
|
- this._verticalBar.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
|
|
|
- this._verticalBar.isVertical = true;
|
|
|
- this._verticalBar.rotation = Math.PI;
|
|
|
- this._verticalBar.isVisible = false;
|
|
|
-
|
|
|
this._verticalBarSpace = new Rectangle();
|
|
|
this._verticalBarSpace.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
|
|
|
this._verticalBarSpace.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
|
|
|
this._verticalBarSpace.thickness = 1;
|
|
|
this._grid.addControl(this._verticalBarSpace, 0, 1);
|
|
|
- this._verticalBarSpace.addControl(this._verticalBar);
|
|
|
-
|
|
|
- this._verticalBar.onValueChangedObservable.add((value) => {
|
|
|
- this._window.top = value * this._endTop + "px";
|
|
|
- });
|
|
|
-
|
|
|
- this._horizontalBar.paddingLeft = 0;
|
|
|
- this._horizontalBar.width = "100%";
|
|
|
- this._horizontalBar.height = "100%";
|
|
|
- this._horizontalBar.barOffset = 0;
|
|
|
- this._horizontalBar.value = 0;
|
|
|
- this._horizontalBar.maximum = 1;
|
|
|
- this._horizontalBar.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
|
|
|
- this._horizontalBar.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
|
|
|
- this._horizontalBar.isVisible = false;
|
|
|
+ this._addBar(this._verticalBar, this._verticalBarSpace, true, Math.PI);
|
|
|
|
|
|
this._horizontalBarSpace = new Rectangle();
|
|
|
this._horizontalBarSpace.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
|
|
|
this._horizontalBarSpace.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP;
|
|
|
this._horizontalBarSpace.thickness = 1;
|
|
|
this._grid.addControl(this._horizontalBarSpace, 1, 0);
|
|
|
- this._horizontalBarSpace.addControl(this._horizontalBar);
|
|
|
-
|
|
|
- this._horizontalBar.onValueChangedObservable.add((value) => {
|
|
|
- this._window.left = value * this._endLeft + "px";
|
|
|
- });
|
|
|
+ this._addBar(this._horizontalBar, this._horizontalBarSpace, false, 0);
|
|
|
|
|
|
this._dragSpace = new Rectangle();
|
|
|
this._dragSpace.thickness = 1;
|
|
|
this._grid.addControl(this._dragSpace, 1, 1);
|
|
|
|
|
|
// Colors
|
|
|
- this.barColor = "grey";
|
|
|
- this.barBackground = "transparent";
|
|
|
+ if (!this._useImageBar) {
|
|
|
+ this.barColor = "grey";
|
|
|
+ this.barBackground = "transparent";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** Reset the scroll viewer window to initial size */
|
|
@@ -228,6 +216,19 @@ export class ScrollViewer extends Rectangle {
|
|
|
this._wheelPrecision = value;
|
|
|
}
|
|
|
|
|
|
+ /** Gets or sets the scroll bar container background color */
|
|
|
+ public get scrollBackground(): string {
|
|
|
+ return this._horizontalBarSpace.background;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set scrollBackground(color: string) {
|
|
|
+ if (this._horizontalBarSpace.background === color) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._horizontalBarSpace.background = color;
|
|
|
+ this._verticalBarSpace.background = color;
|
|
|
+ }
|
|
|
+
|
|
|
/** Gets or sets the bar color */
|
|
|
public get barColor(): string {
|
|
|
return this._barColor;
|
|
@@ -243,6 +244,23 @@ export class ScrollViewer extends Rectangle {
|
|
|
this._verticalBar.color = color;
|
|
|
}
|
|
|
|
|
|
+ /** Gets or sets the bar image */
|
|
|
+ public get thumbImage(): Image {
|
|
|
+ return this._barImage;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set thumbImage(value: Image) {
|
|
|
+ if (this._barImage === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this._barImage = value;
|
|
|
+ let hb = <ImageScrollBar>this._horizontalBar;
|
|
|
+ let vb = <ImageScrollBar>this._verticalBar;
|
|
|
+ hb.thumbImage = value;
|
|
|
+ vb.thumbImage = value;
|
|
|
+ }
|
|
|
+
|
|
|
/** Gets or sets the size of the bar */
|
|
|
public get barSize(): number {
|
|
|
return this._barSize;
|
|
@@ -264,6 +282,75 @@ export class ScrollViewer extends Rectangle {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** Gets or sets the length of the thumb */
|
|
|
+ public get thumbLength(): number {
|
|
|
+ return this._thumbLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set thumbLength(value: number) {
|
|
|
+ if (this._thumbLength === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (value <= 0) {
|
|
|
+ value = 0.1;
|
|
|
+ }
|
|
|
+ if (value > 1) {
|
|
|
+ value = 1;
|
|
|
+ }
|
|
|
+ this._thumbLength = value;
|
|
|
+ var hb = <ImageScrollBar>this._horizontalBar;
|
|
|
+ var vb = <ImageScrollBar>this._verticalBar;
|
|
|
+ hb.thumbLength = value;
|
|
|
+ vb.thumbLength = value;
|
|
|
+ this._markAsDirty();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Gets or sets the height of the thumb */
|
|
|
+ public get thumbHeight(): number {
|
|
|
+ return this._thumbHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set thumbHeight(value: number) {
|
|
|
+ if (this._thumbHeight === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (value <= 0) {
|
|
|
+ value = 0.1;
|
|
|
+ }
|
|
|
+ if (value > 1) {
|
|
|
+ value = 1;
|
|
|
+ }
|
|
|
+ this._thumbHeight = value;
|
|
|
+ var hb = <ImageScrollBar>this._horizontalBar;
|
|
|
+ var vb = <ImageScrollBar>this._verticalBar;
|
|
|
+ hb.thumbHeight = value;
|
|
|
+ vb.thumbHeight = value;
|
|
|
+ this._markAsDirty();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Gets or sets the height of the bar image */
|
|
|
+ public get barImageHeight(): number {
|
|
|
+ return this._barImageHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set barImageHeight(value: number) {
|
|
|
+ if (this._barImageHeight === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (value <= 0) {
|
|
|
+ value = 0.1;
|
|
|
+ }
|
|
|
+ if (value > 1) {
|
|
|
+ value = 1;
|
|
|
+ }
|
|
|
+ this._barImageHeight = value;
|
|
|
+ var hb = <ImageScrollBar>this._horizontalBar;
|
|
|
+ var vb = <ImageScrollBar>this._verticalBar;
|
|
|
+ hb.barImageHeight = value;
|
|
|
+ vb.barImageHeight = value;
|
|
|
+ this._markAsDirty();
|
|
|
+ }
|
|
|
+
|
|
|
/** Gets or sets the bar background */
|
|
|
public get barBackground(): string {
|
|
|
return this._barBackground;
|
|
@@ -275,11 +362,29 @@ export class ScrollViewer extends Rectangle {
|
|
|
}
|
|
|
|
|
|
this._barBackground = color;
|
|
|
- this._horizontalBar.background = color;
|
|
|
- this._verticalBar.background = color;
|
|
|
+ let hb = <ScrollBar>this._horizontalBar;
|
|
|
+ let vb = <ScrollBar>this._verticalBar;
|
|
|
+ hb.background = color;
|
|
|
+ vb.background = color;
|
|
|
this._dragSpace.background = color;
|
|
|
}
|
|
|
|
|
|
+ /** Gets or sets the bar background image */
|
|
|
+ public get barImage(): Image {
|
|
|
+ return this._barBackgroundImage;
|
|
|
+ }
|
|
|
+
|
|
|
+ public set barImage(value: Image) {
|
|
|
+ if (this._barBackgroundImage === value) {
|
|
|
+ }
|
|
|
+
|
|
|
+ this._barBackgroundImage = value;
|
|
|
+ let hb = <ImageScrollBar>this._horizontalBar;
|
|
|
+ let vb = <ImageScrollBar>this._verticalBar;
|
|
|
+ hb.backgroundImage = value;
|
|
|
+ vb.backgroundImage = value;
|
|
|
+ }
|
|
|
+
|
|
|
/** @hidden */
|
|
|
private _updateScroller(): void {
|
|
|
let windowContentsWidth = this._window._currentMeasure.width;
|
|
@@ -326,11 +431,8 @@ export class ScrollViewer extends Rectangle {
|
|
|
this._rebuildLayout = true;
|
|
|
}
|
|
|
|
|
|
- let horizontalMultiplicator = this._clientWidth / windowContentsWidth;
|
|
|
- let verticalMultiplicator = this._clientHeight / windowContentsHeight;
|
|
|
-
|
|
|
- this._horizontalBar.thumbWidth = (this._clientWidth * horizontalMultiplicator) + "px";
|
|
|
- this._verticalBar.thumbWidth = (this._clientHeight * verticalMultiplicator) + "px";
|
|
|
+ this._horizontalBar.thumbWidth = this._thumbLength * 0.9 * this._clientWidth + "px";
|
|
|
+ this._verticalBar.thumbWidth = this._thumbLength * 0.9 * this._clientHeight + "px";
|
|
|
}
|
|
|
|
|
|
public _link(host: AdvancedDynamicTexture): void {
|
|
@@ -340,6 +442,32 @@ export class ScrollViewer extends Rectangle {
|
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
|
+ private _addBar(barControl: ScrollBar | ImageScrollBar, barContainer: Rectangle, isVertical: boolean, rotation: number) {
|
|
|
+ barControl.paddingLeft = 0;
|
|
|
+ barControl.width = "100%";
|
|
|
+ barControl.height = "100%";
|
|
|
+ barControl.barOffset = 0;
|
|
|
+ barControl.value = 0;
|
|
|
+ barControl.maximum = 1;
|
|
|
+ barControl.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_CENTER;
|
|
|
+ barControl.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
|
|
|
+ barControl.isVertical = isVertical;
|
|
|
+ barControl.rotation = rotation;
|
|
|
+ barControl.isVisible = false;
|
|
|
+
|
|
|
+ barContainer.addControl(barControl);
|
|
|
+
|
|
|
+ barControl.onValueChangedObservable.add((value) => {
|
|
|
+ if (rotation > 0) {
|
|
|
+ this._window.top = value * this._endTop + "px";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._window.left = value * this._endLeft + "px";
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @hidden */
|
|
|
private _attachWheel() {
|
|
|
if (!this._host || this._onPointerObserver) {
|
|
|
return;
|