-
Notifications
You must be signed in to change notification settings - Fork 208
/
FlashSettings.ts
98 lines (88 loc) · 4.45 KB
/
FlashSettings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Rendering
*/
import { BeDuration, Mutable } from "@itwin/core-bentley";
/** As part of [[FlashSettings]], describes how geometry is flashed.
* @public
* @extensions
*/
export enum FlashMode {
/** The color of the geometry is mixed with the hilite color. */
Hilite,
/** The color of the geometry is brightened. Applicable only to lit geometry - i.e., meshes displayed in a view with [RenderMode.SmoothShade]($common)
* and lighting enabled.
*/
Brighten,
}
/** Options used to construct or clone a [[FlashSettings]]. All properties are mutable and optional; those left undefined receive their default
* values.
* @public
* @extensions
*/
export type FlashSettingsOptions = Mutable<Partial<FlashSettings>>;
/** Settings that control how geometry is "flashed" when hovered over in a [[Viewport]].
* When the user hovers the mouse cursor over an element (or other piece of geometry, like a reality mesh), a [[Tool]] visually indicates
* that it can interact with that geometry by "flashing" it. Flashed geometry changes color in one of the following two ways:
* - By mixing the viewport's hilite color as specified by [[Viewport.hilite]] with the geometry's own color; or
* - By brightening the geometry's own color (for lit geometry only - i.e., meshes displayed in a view with lighting enabled).
* The flash effect starts out at an intensity of zero and increases linearly over the period of time specified by [[duration]] until
* [[maxIntensity]] is reached.
* @see [[Viewport.flashSettings]] to customize the flash behavior for a viewport.
* @see [[Viewport.hilite]] to customize the hilite color used by [[FlashMode.Hilite]].
* @public
* @extensions
*/
export class FlashSettings {
/** The duration in seconds over which the flash effect increases from zero to [[maxIntensity]], in [0..10].
* Default value: 0.25 seconds.
* Values outside of [0..10] are clamped to that range.
*/
public readonly duration: BeDuration;
/** The maximum intensity of the flash effect, after [[duration]] seconds have elapsed, in [0..1].
* For [[FlashMode.Brighten]] this indicates how much brighter the the geometry will be.
* For [[FlashMode.Hilite]] this indicates the ratio of the hilite color to the geometry's own color - i.e., a max intensity of 1.0 causes
* the geometry to display entirely in the hilite color at its maximum.
* Default value: 1.0.
* Values outside of [0..1] are clamped to that range.
*/
public readonly maxIntensity: number;
/** Specifies how lit geometry (that is, meshes displayed in a view with lighting enabled) is flashed.
* Default value: [[FlashMode.Brighten]].
*/
public readonly litMode: FlashMode;
/** Construct new flash settings.
* @param options If supplied, overrides specified default values.
* Example: to change [[duration]] to 1 second and use default [[maxIntensity]] and [[litMode]]:
* ```ts
* const settings = new FlashSettings({ duration: BeDuration.fromSeconds(1) });
* ```
*/
public constructor(options?: FlashSettingsOptions) {
this.litMode = options?.litMode === FlashMode.Hilite ? FlashMode.Hilite : FlashMode.Brighten;
const maxIntensity = options?.maxIntensity ?? 1;
this.maxIntensity = Math.min(1, Math.max(0, maxIntensity));
let duration = options?.duration;
if (duration) {
const ms = Math.max(0, Math.min(10 * 1000, duration.milliseconds));
if (ms !== duration.milliseconds)
duration = BeDuration.fromMilliseconds(ms);
} else {
duration = BeDuration.fromSeconds(0.25);
}
this.duration = duration;
}
/** Create a copy of these settings identical except for properties explicitly specified by `options`.
* @param options Overrides selected properties of these settings. Any property not supplied will retain its current value. Any property
* explicitly set to `undefined` will receive its default value.
* @returns A copy of these settings identical except as specified by `options`.
*/
public clone(options?: FlashSettingsOptions): FlashSettings {
if (!options)
return this;
return new FlashSettings({ ...this, ...options });
}
}