Add fromHSLA and fromHex methods to API

This commit is contained in:
Michel Kaporin
2017-07-21 13:52:49 +02:00
parent 0490818367
commit 2c45d35090
4 changed files with 50 additions and 15 deletions

View File

@@ -7,6 +7,7 @@
import * as crypto from 'crypto';
import URI from 'vs/base/common/uri';
import { Color as CommonColor, HSLA } from 'vs/base/common/color';
import { illegalArgument } from 'vs/base/common/errors';
import * as vscode from 'vscode';
@@ -1016,10 +1017,10 @@ export class DocumentLink {
}
export class Color {
red: number;
green: number;
blue: number;
alpha: number;
readonly red: number;
readonly green: number;
readonly blue: number;
readonly alpha: number;
constructor(red: number, green: number, blue: number, alpha?: number) {
this.red = red;
@@ -1027,6 +1028,19 @@ export class Color {
this.blue = blue;
this.alpha = alpha;
}
static fromHSLA(hue: number, saturation: number, luminosity: number, alpha?: number): Color {
if (!alpha) {
alpha = 1;
}
const color = CommonColor.fromHSLA(new HSLA(hue, saturation, luminosity, alpha)).toRGBA();
return new Color(color.r, color.g, color.b, color.a / 255);
}
static fromHex(hex: string): Color {
const color = CommonColor.fromHex(hex).toRGBA();
return new Color(color.r, color.g, color.b, color.a / 255);
}
}
export class ColorInfo {