1 /* 2 * Copyright (C) 2015-2017, by Laszlo Szeremi under the Boost license. 3 * 4 * Pixel Perfect Engine, concrete.stylesheet module 5 */ 6 7 module pixelperfectengine.concrete.types.stylesheet; 8 9 import pixelperfectengine.graphics.bitmap; 10 import pixelperfectengine.graphics.fontsets; 11 import collections.hashmap; 12 /** 13 * Defines style data for the Concrete GUI. 14 */ 15 public class StyleSheet{ 16 ///Default color palette. First 16 colors are reserved for GUI defaults in a single workspace, second 16 colors are of the RGBI standard, the rest could 17 ///be used for other GUI elements such as backgrounds and icons 18 public static enum Color[] defaultpaletteforGUI = 19 [Color(0x00,0x00,0x00,0x00), //transparent 20 Color(0xFF,0xFF,0xFF,0xFF), //reserved 21 Color(0x30,0x30,0x30,0xFF), //buttonTop 22 Color(0x40,0x40,0x40,0xFF), //windowascent 23 Color(0x18,0x18,0x18,0xFF), //windowdescent 24 Color(0x10,0x10,0x10,0xff), //windowBottom 25 Color(0x20,0x20,0x20,0xff), //window 26 Color(0x00,0x00,0xaa,0xFF), //WHAascent 27 Color(0x00,0x00,0x40,0xFF), //WHAdescent 28 Color(0x00,0x00,0x70,0xFF), //WHAtop 29 Color(0x00,0x00,0xFF,0xFF), //reserved (cursors now use a given color) 30 Color(0x00,0x00,0x7F,0xFF), //reserved for windowascentB 31 Color(0xFF,0xFF,0x00,0xFF), //reserved for windowBottomB 32 Color(0x0a,0x0a,0x0a,0xFF), //windowdescentB 33 Color(0x7F,0x7F,0x7F,0xFF), //reserved for WHAascentB 34 Color(0x00,0x00,0x00,0xFF), //reserved for WHAdescentB 35 36 Color(0x00,0x00,0x00,0xFF), //Black 37 Color(0x7F,0x00,0x00,0xFF), //Dark Red 38 Color(0x00,0x7F,0x00,0xFF), //Dark Green 39 Color(0x7F,0x7F,0x00,0xFF), //Dark Yellow 40 Color(0x00,0x00,0x7F,0xFF), //Dark Blue 41 Color(0x7F,0x00,0x7F,0xFF), //Dark Purple 42 Color(0x00,0x7F,0x7F,0xFF), //Dark Turquiose 43 Color(0x7F,0x7F,0x7F,0xFF), //Grey 44 Color(0x3F,0x3F,0x3F,0xFF), //Dark Grey 45 Color(0xFF,0x00,0x00,0xFF), //Red 46 Color(0x00,0xFF,0x00,0xFF), //Green 47 Color(0xFF,0xFF,0x00,0xFF), //Yellow 48 Color(0x00,0x00,0xFF,0xFF), //Blue 49 Color(0xFF,0x00,0xFF,0xFF), //Purple 50 Color(0x00,0xFF,0xFF,0xFF), //Turquiose 51 Color(0xFF,0xFF,0xFF,0xFF), //White 52 ]; 53 //public Fontset!Bitmap8Bit[string] font; 54 public HashMap!(string, Fontset!Bitmap8Bit) font;///Fonts stored here. 55 public HashMap!(string, CharacterFormattingInfo!Bitmap8Bit) _chrFormat; ///Character formatting 56 //public CharacterFormattingInfo!Bitmap8Bit[string] _chrFormat; ///Character formatting 57 //public ubyte[string] color; ///Colors are identified by strings. 58 public HashMap!(string, ubyte) color; ///Colors are identified by strings. 59 //public ubyte[][string] pattern; ///Stores line patterns. 60 public HashMap!(string, ubyte[]) pattern; ///Stores line patterns. 61 //public Bitmap8Bit[string] images; ///For icons, pattern fills, etc... 62 public HashMap!(string, Bitmap8Bit) images; ///For icons, pattern fills, etc... 63 //public int[string] drawParameters; ///Draw parameters are used for border thickness, padding, etc... 64 public HashMap!(string, int) drawParameters; ///Draw parameters are used for border thickness, padding, etc... 65 //public string[string] fontTypes; ///Font type descriptions for various kind of components. 66 67 /** 68 * Creates a default stylesheet. 69 */ 70 public this() @safe { 71 color["transparent"] = 0x0000; 72 color["normaltext"] = 0x001F; 73 color["window"] = 0x0006; 74 color["buttonTop"] = 0x0002; 75 color["windowascent"] = 0x0003; 76 color["windowdescent"] = 0x0004; 77 color["windowinactive"] = 0x0005; 78 color["selection"] = 0x0019; 79 color["red"] = 0x0019; 80 color["WHAascent"] = 0x0007; 81 color["WHAdescent"] = 0x0008; 82 color["WHTextActive"] = 0x001F; 83 color["WHTextInactive"] = 0x0017; 84 color["WHAtop"] = 0x0009; 85 color["blue"] = 0x001c; 86 color["darkblue"] = 0x0014; 87 color["yellow"] = 0x001b; 88 color["secondarytext"] = 0x001B; 89 color["grey"] = 0x0017; 90 color["black"] = 0x000F; 91 color["white"] = 0x0001; 92 color["PopUpMenuSecondaryTextColor"] = 0x001B; 93 color["MenuBarSeparatorColor"] = 0x001F; 94 color["PanelBorder"] = 0x0010; 95 color["SliderBackground"] = 0x0004; 96 color["SliderColor"] = 0x0003; 97 color["ListViewVSep"] = 0x0000; 98 color["ListViewHSep"] = 0x0000; 99 100 drawParameters["PopUpMenuHorizPadding"] = 4; 101 drawParameters["PopUpMenuVertPadding"] = 1; 102 drawParameters["PopUpMenuMinTextSpace"] = 8; 103 drawParameters["ButtonPaddingHoriz"] = 8; 104 drawParameters["PanelTitleFirstCharOffset"] = 16; 105 drawParameters["PanelPadding"] = 4; 106 107 drawParameters["MenuBarHorizPadding"] = 4; 108 drawParameters["MenuBarVertPadding"] = 2; 109 110 drawParameters["ListBoxRowHeight"] = 16; 111 drawParameters["TextSpacingTop"] = 1; 112 drawParameters["TextSpacingBottom"] = 1; 113 drawParameters["TextSpacingSides"] = 2; 114 drawParameters["WindowLeftPadding"] = 5; 115 drawParameters["WindowRightPadding"] = 5; 116 drawParameters["WindowTopPadding"] = 20; 117 drawParameters["WindowBottomPadding"] = 5; 118 drawParameters["WindowHeaderHeight"] = 16; 119 drawParameters["ComponentHeight"] = 20; 120 drawParameters["WindowHeaderHeight"] = 16; 121 drawParameters["WHPaddingTop"] = 1; 122 drawParameters["HorizScrollBarSize"] = 16; 123 drawParameters["VertScrollBarSize"] = 16; 124 drawParameters["horizTextPadding"] = 1; 125 126 pattern["blackDottedLine"] = [0x1f, 0x1f, 0x10, 0x10]; 127 } 128 /** 129 * Adds a fontset to the stylesheet with the given ID. 130 * IMPORTANT: ID of "default" must be set at least in order to ensure fallback capabilities! 131 */ 132 public void addFontset(Fontset!Bitmap8Bit f, string ID) @safe { 133 font[ID] = f; 134 } 135 /** 136 * Returns the fontset with the given ID, or the default one if not found. 137 */ 138 public Fontset!Bitmap8Bit getFontset(string ID) @safe nothrow { 139 auto result = font[ID]; 140 if (result !is null) return result; 141 else return font["default"]; 142 } 143 /** 144 * Adds a character formatting to the stylesheet with the given identifier. 145 * IMPORTANT: ID of "default" must be set at least in order to ensure fallback capabilities! 146 */ 147 public void addChrFormatting(CharacterFormattingInfo!Bitmap8Bit frmt, string ID) @safe nothrow { 148 _chrFormat[ID] = frmt; 149 //assert(_chrFormat[type] is frmt); 150 } 151 /** 152 * Duplicates character formatting for multiple IDs. 153 */ 154 public void duplicateChrFormatting(string src, string dest) @safe nothrow { 155 _chrFormat[dest] = _chrFormat[src]; 156 157 } 158 /** 159 * Returns the character formatting with the given ID, or the default one if not found. 160 */ 161 public CharacterFormattingInfo!Bitmap8Bit getChrFormatting(string ID) @safe nothrow { 162 auto result = _chrFormat[ID]; 163 if (result !is null) return result; 164 else return _chrFormat["default"]; 165 } 166 /** 167 * Sets the given color to the supplied name to be recalled by element draw functions. 168 */ 169 public void setColor(ubyte c, string colorName) @safe nothrow { 170 color[colorName] = c; 171 } 172 /** 173 * Returns the color that matches the name, or 0 if not found. 174 */ 175 public ubyte getColor(string colorName) @safe nothrow { 176 return color[colorName]; 177 } 178 /** 179 * Sets the image of the given name. 180 */ 181 public void setImage(Bitmap8Bit bitmap, string name) @safe nothrow { 182 images[name] = bitmap; 183 } 184 /** 185 * Returns the image that matches the name, or null if not found. 186 */ 187 public Bitmap8Bit getImage(string name) @safe nothrow { 188 return images[name]; 189 } 190 } 191 192 ///Stores a global, default stylesheet. 193 ///Must be initialized alongside with the GUI. 194 public static StyleSheet globalDefaultStyle;