mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-29 15:48:05 +00:00
Compare commits
6 Commits
2d0cb3ae03
...
d810b7d5f1
Author | SHA1 | Date | |
---|---|---|---|
|
d810b7d5f1 | ||
|
6cb9c7c483 | ||
|
723f59dffd | ||
|
bcb555fd10 | ||
|
4f50603b8f | ||
|
275c9d98cd |
4
clay.h
4
clay.h
@ -1842,12 +1842,13 @@ void Clay__ElementPostConfiguration(void) {
|
||||
}
|
||||
} else {
|
||||
Clay_LayoutElementHashMapItem *parentItem = Clay__GetHashMapItem(floatingConfig->parentId);
|
||||
clipElementId = Clay__int32_tArray_Get(&Clay__layoutElementClipElementIds, (int32_t)(parentItem->layoutElement - Clay__layoutElements.internalArray));
|
||||
if (!parentItem) {
|
||||
Clay__errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
|
||||
.errorType = CLAY_ERROR_TYPE_FLOATING_CONTAINER_PARENT_NOT_FOUND,
|
||||
.errorText = CLAY_STRING("A floating element was declared with a parentId, but no element with that ID was found."),
|
||||
.userData = Clay__errorHandler.userData });
|
||||
} else {
|
||||
clipElementId = Clay__int32_tArray_Get(&Clay__layoutElementClipElementIds, parentItem->layoutElement - Clay__layoutElements.internalArray);
|
||||
}
|
||||
}
|
||||
Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) {
|
||||
@ -2391,6 +2392,7 @@ void Clay__CalculateFinalLayout(void) {
|
||||
Clay__WrappedTextLineArray_Add(&Clay__wrappedTextLines, CLAY__INIT(Clay__WrappedTextLine) { { measuredWord->width, lineHeight }, { .length = measuredWord->length, .chars = &textElementData->text.chars[measuredWord->startOffset] } });
|
||||
textElementData->wrappedLines.length++;
|
||||
wordIndex = measuredWord->next;
|
||||
lineStartOffset = measuredWord->startOffset + measuredWord->length;
|
||||
}
|
||||
// measuredWord->length == 0 means a newline character
|
||||
else if (measuredWord->length == 0 || lineWidth + measuredWord->width > containerElement->dimensions.width) {
|
||||
|
@ -426,7 +426,8 @@
|
||||
element.style.height = Math.round(renderCommand.boundingBox.height.value) + 'px';
|
||||
}
|
||||
|
||||
switch(renderCommand.commandType.value) {
|
||||
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
|
||||
switch(renderCommand.commandType.value & 0xff) {
|
||||
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
|
||||
break;
|
||||
}
|
||||
@ -580,7 +581,9 @@
|
||||
for (let i = 0; i < length; i++, arrayOffset += renderCommandSize) {
|
||||
let renderCommand = readStructAtAddress(arrayOffset, renderCommandDefinition);
|
||||
let boundingBox = renderCommand.boundingBox;
|
||||
switch(renderCommand.commandType.value) {
|
||||
|
||||
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
|
||||
switch(renderCommand.commandType.value & 0xff) {
|
||||
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
|
||||
break;
|
||||
}
|
||||
|
@ -38,8 +38,28 @@ typedef struct
|
||||
};
|
||||
} CustomLayoutElement;
|
||||
|
||||
// Precompute the matrices at start of the frame
|
||||
Matrix PrecomputeViewMatrix(const Camera camera){
|
||||
return MatrixLookAt(camera.position, camera.target, camera.up);
|
||||
}
|
||||
|
||||
Matrix PrecomputeProjectionMatrix(const Camera camera, int screenWidth, int screenHeight, float zDistance) {
|
||||
Matrix matProj = MatrixIdentity();
|
||||
if (camera.projection == CAMERA_PERSPECTIVE) {
|
||||
// Calculate projection matrix from perspective
|
||||
matProj = MatrixPerspective(camera.fovy * DEG2RAD, ((double)screenWidth / (double)screenHeight), 0.01f, zDistance);
|
||||
} else if (camera.projection == CAMERA_ORTHOGRAPHIC) {
|
||||
double aspect = (double)screenWidth / (double)screenHeight;
|
||||
double top = camera.fovy / 2.0;
|
||||
double right = top * aspect;
|
||||
// Calculate projection matrix from orthographic
|
||||
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
||||
}
|
||||
return matProj;
|
||||
}
|
||||
|
||||
// Get a ray trace from the screen position (i.e mouse) within a specific section of the screen
|
||||
Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int screenWidth, int screenHeight, float zDistance)
|
||||
Ray GetScreenToWorldPointWithZDistance(Vector2 position, const Matrix matView, const Matrix matProj, int screenWidth, int screenHeight) {
|
||||
{
|
||||
Ray ray = { 0 };
|
||||
|
||||
@ -52,26 +72,6 @@ Ray GetScreenToWorldPointWithZDistance(Vector2 position, Camera camera, int scre
|
||||
// Store values in a vector
|
||||
Vector3 deviceCoords = { x, y, z };
|
||||
|
||||
// Calculate view matrix from camera look at
|
||||
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||
|
||||
Matrix matProj = MatrixIdentity();
|
||||
|
||||
if (camera.projection == CAMERA_PERSPECTIVE)
|
||||
{
|
||||
// Calculate projection matrix from perspective
|
||||
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)screenWidth/(double)screenHeight), 0.01f, zDistance);
|
||||
}
|
||||
else if (camera.projection == CAMERA_ORTHOGRAPHIC)
|
||||
{
|
||||
double aspect = (double)screenWidth/(double)screenHeight;
|
||||
double top = camera.fovy/2.0;
|
||||
double right = top*aspect;
|
||||
|
||||
// Calculate projection matrix from orthographic
|
||||
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
||||
}
|
||||
|
||||
// Unproject far/near points
|
||||
Vector3 nearPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 0.0f }, matProj, matView);
|
||||
Vector3 farPoint = Vector3Unproject((Vector3){ deviceCoords.x, deviceCoords.y, 1.0f }, matProj, matView);
|
||||
@ -129,6 +129,12 @@ void Clay_Raylib_Initialize(int width, int height, const char *title, unsigned i
|
||||
|
||||
void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
||||
{
|
||||
|
||||
int screenWidth = GetScreenWidth();
|
||||
int screenHeight = GetScreenHeight();
|
||||
Matrix matView = PrecomputeViewMatrix(Raylib_camera);
|
||||
Matrix matProj = PrecomputeProjectionMatrix(Raylib_camera, screenWidth, screenHeight, 140.0f);
|
||||
|
||||
measureCalls = 0;
|
||||
for (int j = 0; j < renderCommands.length; j++)
|
||||
{
|
||||
@ -230,4 +236,4 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -317,7 +317,9 @@
|
||||
for (let i = 0; i < length; i++, arrayOffset += renderCommandSize) {
|
||||
let renderCommand = readStructAtAddress(arrayOffset, renderCommandDefinition);
|
||||
let boundingBox = renderCommand.boundingBox;
|
||||
switch(renderCommand.commandType.value) {
|
||||
|
||||
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
|
||||
switch(renderCommand.commandType.value & 0xff) {
|
||||
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
|
||||
break;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@
|
||||
let element = null;
|
||||
if (!elementCache[renderCommand.id.value]) {
|
||||
let elementType = 'div';
|
||||
switch (renderCommand.commandType.value) {
|
||||
switch (renderCommand.commandType.value & 0xff) {
|
||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
||||
if (readStructAtAddress(renderCommand.config.value, rectangleConfigDefinition).link.length.value > 0) {
|
||||
elementType = 'a';
|
||||
@ -384,7 +384,8 @@
|
||||
element.style.height = Math.round(renderCommand.boundingBox.height.value) + 'px';
|
||||
}
|
||||
|
||||
switch(renderCommand.commandType.value) {
|
||||
// note: commandType is packed to uint8_t and has 3 garbage bytes of padding
|
||||
switch(renderCommand.commandType.value & 0xff) {
|
||||
case (CLAY_RENDER_COMMAND_TYPE_NONE): {
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user