1 module rpui.render.components; 2 3 import gapi.geometry; 4 import gapi.geometry_quad; 5 import gapi.texture; 6 import gapi.shader; 7 import gapi.vec; 8 import gapi.transform; 9 import gapi.text; 10 import gapi.font; 11 12 import rpui.primitives; 13 14 struct CameraView { 15 mat4 mvpMatrix; 16 float viewportWidth; 17 float viewportHeight; 18 } 19 20 struct Geometry { 21 Buffer indicesBuffer; 22 Buffer verticesBuffer; 23 Buffer texCoordsBuffer; 24 25 VAO vao; 26 } 27 28 struct LinesGeometry { 29 Buffer indicesBuffer; 30 Buffer verticesBuffer; 31 uint pointsCount; 32 33 VAO vao; 34 } 35 36 struct QuadTransforms { 37 Transform2D transform; 38 mat4 modelMatrix; 39 mat4 mvpMatrix; 40 } 41 42 struct LinesTransforms { 43 Transform2D transform; 44 mat4 modelMatrix; 45 mat4 mvpMatrix; 46 } 47 48 // TODO(Andrey): Rename to ChainTransforms 49 struct HorizontalChainTransforms { 50 QuadTransforms[ChainPart] quadTransforms; 51 } 52 53 struct TextureQuad { 54 Geometry geometry; 55 Texture2D texture; 56 } 57 58 struct TexAtlasTextureQuad { 59 Geometry geometry; 60 Texture2D texture; 61 OriginalWithNormilizedTextureCoords texCoords; 62 } 63 64 struct StatefulTexAtlasTextureQuad { 65 Geometry geometry; 66 Texture2D texture; 67 OriginalWithNormilizedTextureCoords[State] texCoords; 68 State state; 69 70 @property inout(OriginalWithNormilizedTextureCoords) currentTexCoords() inout { 71 return texCoords[state]; 72 } 73 } 74 75 struct OriginalWithNormilizedTextureCoords { 76 Texture2DCoords originalTexCoords; 77 Texture2DCoords normilizedTexCoords; 78 } 79 80 struct StatefulChain { 81 TextureQuad[ChainPart] parts; 82 float[ChainPart] widths; 83 Texture2DCoords[ChainPart][State] texCoords; 84 State state; 85 } 86 87 struct Chain { 88 TextureQuad[ChainPart] parts; 89 float[ChainPart] widths; 90 float height; 91 Texture2DCoords[ChainPart] texCoords; 92 } 93 94 struct Block { 95 float[ChainPart][BlockRow] widths; 96 float[BlockRow] heights; 97 98 Chain topChain; 99 Chain middleChain; 100 Chain bottomChain; 101 } 102 103 struct BlockTransforms { 104 HorizontalChainTransforms topChain; 105 HorizontalChainTransforms middleChain; 106 HorizontalChainTransforms bottomChain; 107 } 108 109 struct UiTextRender { 110 Geometry geometry; 111 Text text; 112 Texture2D texture; 113 } 114 115 struct StatefulUiText { 116 UiTextRender render; 117 UiTextAttributes[State] attrs; 118 State state; 119 } 120 121 struct UiText { 122 UiTextRender render; 123 UiTextAttributes attrs; 124 } 125 126 struct UiTextAttributes { 127 vec4 color; 128 vec2 offset; 129 int fontSize; 130 dstring caption; 131 Align textAlign = Align.center; 132 VerticalAlign textVerticalAlign = VerticalAlign.middle; 133 Font font; 134 } 135 136 struct UiTextTransforms { 137 vec2 size; 138 vec2 relativePosition; 139 mat4 mvpMatrix; 140 dstring cachedString = ""; 141 } 142 143 enum State { 144 leave, 145 enter, 146 click, 147 } 148 149 enum ChainPart { 150 left, 151 center, 152 right, 153 top, 154 middle, 155 bottom, 156 } 157 158 enum BlockRow { 159 top, 160 middle, 161 bottom, 162 } 163 164 immutable horizontalChainParts = [ 165 ChainPart.left, 166 ChainPart.center, 167 ChainPart.right, 168 ]; 169 170 immutable verticalChainParts = [ 171 ChainPart.top, 172 ChainPart.middle, 173 ChainPart.bottom, 174 ]; 175 176 string getStateRdplName(in State state) { 177 switch (state) { 178 case State.leave: 179 return "Leave"; 180 181 case State.enter: 182 return "Enter"; 183 184 case State.click: 185 return "Click"; 186 187 default: 188 throw new Error("Unknown state"); 189 } 190 } 191 192 string getChainPartRdplName(in ChainPart part) { 193 switch (part) { 194 case ChainPart.left: 195 return "left"; 196 197 case ChainPart.center: 198 return "center"; 199 200 case ChainPart.right: 201 return "right"; 202 203 case ChainPart.top: 204 return "top"; 205 206 case ChainPart.middle: 207 return "middle"; 208 209 case ChainPart.bottom: 210 return "bottom"; 211 212 default: 213 throw new Error("Unknown part"); 214 } 215 }