1 /* 2 Copyright (c) 2013 Andrey Penechko 3 4 Boost Software License - Version 1.0 - August 17th, 2003 5 6 Permission is hereby granted, free of charge, to any person or organization 7 obtaining a copy of the software and accompanying documentation covered by 8 this license the "Software" to use, reproduce, display, distribute, 9 execute, and transmit the Software, and to prepare derivative works of the 10 Software, and to permit third-parties to whom the Software is furnished to 11 do so, all subject to the following: 12 13 The copyright notices in the Software and this entire statement, including 14 the above license grant, this restriction and the following disclaimer, 15 must be included in all copies of the Software, in whole or in part, and 16 all derivative works of the Software, unless such copies or derivative 17 works are solely in the form of machine-executable object code generated by 18 a source language processor. 19 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 23 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 24 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 DEALINGS IN THE SOFTWARE. 27 */ 28 29 module anchovy.core.types; 30 31 import std.conv; 32 public import dlib.math.vector; 33 public import anchovy.utils.rect; 34 public import anchovy.utils.rectoffset; 35 import dlib.math.utils: clampValue = clamp; 36 37 enum StatusType : int { 38 StatusAppMissingAsset = -4, ///< Application failed due to missing asset file 39 StatusAppStackEmpty = -3, ///< Application States stack is empty 40 StatusAppInitFailed = -2, ///< Application initialization failed 41 StatusError = -1, ///< General error status response 42 StatusAppOK = 0, ///< Application quit without error 43 StatusNoError = 0, ///< General no error status response 44 StatusFalse = 0, ///< False status response 45 StatusTrue = 1, ///< True status response 46 StatusOK = 1, ///< OK status response 47 }; 48 49 enum ShaderType : uint { 50 FRAGMENT = 0x8B30, 51 VERTEX = 0x8B31, 52 GEOMETRY = 0x8DD9, 53 COMPUTE = 0x91B9, 54 TESS_EVALUATION = 4, 55 TESS_CONTROL = 5, 56 } 57 58 59 struct Color 60 { 61 this(ubyte gray) 62 { 63 r = gray; 64 g = gray; 65 b = gray; 66 a = 255; 67 } 68 69 this(ubyte r, ubyte g, ubyte b, ubyte a = 255) 70 { 71 this.r = r; 72 this.g = g; 73 this.b = b; 74 this.a = a; 75 } 76 77 ubyte r, g, b, a; 78 } 79 80 struct Color4f 81 { 82 float r, g, b, a; 83 84 this(Color col) 85 { 86 r=cast(float)col.r/255; 87 g=cast(float)col.g/255; 88 b=cast(float)col.b/255; 89 a=cast(float)col.a/255; 90 } 91 this(float a, float b, float c, float d = 1.0f) 92 { 93 this.r = a; 94 this.g = b; 95 this.b = c; 96 this.a = d; 97 } 98 99 bool opEquals()(auto ref const Color4f rc) inout 100 { 101 return r == rc.r && g == rc.g && b == rc.b && a == rc.a; 102 } 103 } 104 105 class IdArray(T) 106 { 107 uint add(T newElement) 108 { 109 array[currentId] = newElement; 110 return currentId++; 111 } 112 113 T remove(uint id) 114 { 115 T temp = array[id]; 116 array.remove(id); 117 return temp; 118 } 119 120 /// Deprecated: use array[index] instead 121 deprecated T get(uint id) 122 { 123 T* item = id in array; 124 return (item is null) ? null: *item; 125 } 126 127 T opIndex(uint index) 128 in 129 { 130 assert(index < currentId); 131 } 132 body 133 { 134 T* item = index in array; 135 return (item is null) ? null: *item; 136 } 137 138 T opIndexAssign(T value, uint index) 139 in 140 { 141 assert(index < currentId); 142 } 143 body 144 { 145 array[index] = value; 146 return array[index]; 147 } 148 149 uint currentId = 1; 150 T[uint] array; 151 }