1 /** 2 * Copyright © Novelate 2020 3 * License: MIT (https://github.com/Novelate/NovelateEngine/blob/master/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 * Website: https://novelate.com/ 6 * ------ 7 * Novelate is a free and open-source visual novel engine and framework written in the D programming language. 8 * It can be used freely for both personal and commercial projects. 9 * ------ 10 * Module Description: 11 * This module handles color management. 12 */ 13 module novelate.colormanager; 14 15 import std.array : split; 16 import std.conv : to; 17 18 import novelate.external; 19 20 /** 21 * Creates a color from given RGBA channels. 22 * Params: 23 * r = The red channel. 24 * g = The green channel. 25 * b = The blue channel. 26 * a = The alpha channel. 27 * Returns: 28 * The color created. 29 */ 30 Paint colorFromRGBA(ubyte r, ubyte g, ubyte b, ubyte a = 0xff) 31 { 32 return Paint(r, g, b, a); 33 } 34 35 /** 36 * Creates a color from given RGBA channels contained in a string. Ex. "255,255,0" fpr green or with alpha "255,255,0,150" 37 * Params: 38 * color = The color string of the RGBA channels. 39 * Returns: 40 * The color created. 41 */ 42 Paint colorFromString(string color) 43 { 44 auto data = color.split(","); 45 46 if (data.length < 3) 47 { 48 return colorFromRGBA(0,0,0); 49 } 50 51 auto r = to!ubyte(data[0]); 52 auto g = to!ubyte(data[1]); 53 auto b = to!ubyte(data[2]); 54 auto a = data.length == 4 ? to!ubyte(data[3]) : cast(ubyte)0xff; 55 56 return colorFromRGBA(r, g, b, a); 57 }