Rename rect members from pos, size to min, max
This commit is contained in:
parent
21bf650298
commit
b75d700dd6
@ -666,7 +666,7 @@ INTERNAL void parseXmlTreeToGame(AssetManager *assetManager, MemoryArena_ *arena
|
||||
i32 valueLen = common_strlen(value);
|
||||
i32 intValue = common_atoi(value, valueLen);
|
||||
|
||||
subTex.rect.pos.x = CAST(f32) intValue;
|
||||
subTex.rect.min.x = CAST(f32) intValue;
|
||||
}
|
||||
else if (common_strcmp(subTexAttrib->name, "y") ==
|
||||
0)
|
||||
@ -675,7 +675,7 @@ INTERNAL void parseXmlTreeToGame(AssetManager *assetManager, MemoryArena_ *arena
|
||||
i32 valueLen = common_strlen(value);
|
||||
|
||||
i32 intValue = common_atoi(value, valueLen);
|
||||
subTex.rect.pos.y = CAST(f32) intValue;
|
||||
subTex.rect.min.y = CAST(f32) intValue;
|
||||
}
|
||||
else if (common_strcmp(subTexAttrib->name,
|
||||
"width") == 0)
|
||||
@ -684,7 +684,7 @@ INTERNAL void parseXmlTreeToGame(AssetManager *assetManager, MemoryArena_ *arena
|
||||
i32 valueLen = common_strlen(value);
|
||||
i32 intValue = common_atoi(value, valueLen);
|
||||
|
||||
subTex.rect.size.w = CAST(f32) intValue;
|
||||
subTex.rect.max.w = CAST(f32) intValue;
|
||||
}
|
||||
else if (common_strcmp(subTexAttrib->name,
|
||||
"height") == 0)
|
||||
@ -693,7 +693,7 @@ INTERNAL void parseXmlTreeToGame(AssetManager *assetManager, MemoryArena_ *arena
|
||||
i32 valueLen = common_strlen(value);
|
||||
i32 intValue = common_atoi(value, valueLen);
|
||||
|
||||
subTex.rect.size.h = CAST(f32) intValue;
|
||||
subTex.rect.max.h = CAST(f32) intValue;
|
||||
}
|
||||
else if (common_strcmp(subTexAttrib->name,
|
||||
"hand_offset_x") == 0)
|
||||
@ -726,9 +726,9 @@ INTERNAL void parseXmlTreeToGame(AssetManager *assetManager, MemoryArena_ *arena
|
||||
// TODO(doyle): XML specifies 0,0 top left, we
|
||||
// prefer 0,0 bottom right, so offset by size since 0,0
|
||||
// is top left and size creates a bounding box below it
|
||||
subTex.rect.pos.y = 1024 - subTex.rect.pos.y;
|
||||
subTex.rect.pos.y -= subTex.rect.size.h;
|
||||
subTex.offset.y = subTex.rect.size.h - subTex.offset.y;
|
||||
subTex.rect.min.y = 1024 - subTex.rect.min.y;
|
||||
subTex.rect.min.y -= subTex.rect.max.h;
|
||||
subTex.offset.y = subTex.rect.max.h - subTex.offset.y;
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
ASSERT(key);
|
||||
|
@ -180,7 +180,7 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory,
|
||||
{ // Init ship entity
|
||||
Entity *ship = &state->entityList[state->entityIndex++];
|
||||
ship->id = 0;
|
||||
ship->pos = V2(100, 100);
|
||||
ship->pos = V2(0, 0);
|
||||
ship->size = V2(25.0f, 50.0f);
|
||||
ship->hitbox = ship->size;
|
||||
ship->offset = v2_scale(ship->size, 0.5f);
|
||||
@ -192,8 +192,8 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory,
|
||||
ship->collides = FALSE;
|
||||
}
|
||||
|
||||
state->camera.pos = V2(0, 0);
|
||||
state->camera.size = state->renderer.size;
|
||||
state->camera.min = V2(0, 0);
|
||||
state->camera.max = state->renderer.size;
|
||||
state->init = TRUE;
|
||||
|
||||
state->worldSize = windowSize;
|
||||
@ -247,8 +247,7 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory,
|
||||
// is right facing for trig to work
|
||||
Radians rotation = DEGREES_TO_RADIANS((entity->rotation + 90.0f));
|
||||
v2 direction = V2(math_cosf(rotation), math_sinf(rotation));
|
||||
|
||||
ddP = v2_normalise(direction);
|
||||
ddP = direction;
|
||||
}
|
||||
|
||||
if (getKeyStatus(&state->input.keys[keycode_left],
|
||||
@ -322,14 +321,16 @@ void asteroid_gameUpdateAndRender(GameState *state, Memory *memory,
|
||||
renderer_entity(&state->renderer, state->camera, entity, pivotPoint, 0,
|
||||
V4(0.4f, 0.8f, 1.0f, 1.0f), flags);
|
||||
|
||||
v2 rightAlignedP = v2_add(entity->pos, entity->hitbox);
|
||||
renderer_rect(&state->renderer, state->camera, rightAlignedP, V2(10, 10),
|
||||
V2(0, 0), DEGREES_TO_RADIANS(entity->rotation), NULL,
|
||||
V4(0.4f, 0.8f, 1.0f, 1.0f), flags);
|
||||
v2 leftAlignedP = v2_sub(entity->pos, entity->offset);
|
||||
renderer_rect(&state->renderer, state->camera, leftAlignedP,
|
||||
entity->size, v2_scale(entity->size, 0.5f),
|
||||
DEGREES_TO_RADIANS(entity->rotation), NULL,
|
||||
V4(1.0f, 0.8f, 1.0f, 1.0f), flags);
|
||||
|
||||
v2 leftAlignedP = entity->pos;
|
||||
renderer_rect(&state->renderer, state->camera, leftAlignedP, V2(10, 10),
|
||||
V2(0, 0), DEGREES_TO_RADIANS(entity->rotation), NULL,
|
||||
v2 rightAlignedP = v2_add(leftAlignedP, entity->size);
|
||||
renderer_rect(&state->renderer, state->camera, rightAlignedP, V2(4, 4),
|
||||
v2_scale(pivotPoint, -1.0f),
|
||||
DEGREES_TO_RADIANS(entity->rotation), NULL,
|
||||
V4(0.4f, 0.8f, 1.0f, 1.0f), flags);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ void entity_updateAnim(Entity *const entity, const f32 dt)
|
||||
|
||||
char *frameName = anim->frameList[currEntityAnim->currFrame];
|
||||
SubTexture texRect = asset_getAtlasSubTex(anim->atlas, frameName);
|
||||
entity->size = v2_scale(texRect.rect.size, entity->scale);
|
||||
entity->size = v2_scale(texRect.rect.max, entity->scale);
|
||||
}
|
||||
|
||||
void entity_addAnim(AssetManager *const assetManager, Entity *const entity,
|
||||
|
@ -339,7 +339,7 @@ void renderer_rect(Renderer *const renderer, Rect camera, v2 pos, v2 size,
|
||||
RenderFlags flags)
|
||||
{
|
||||
// NOTE(doyle): Bottom left and top right position of quad in world space
|
||||
v2 posInCameraSpace = v2_sub(pos, camera.pos);
|
||||
v2 posInCameraSpace = v2_sub(pos, camera.min);
|
||||
|
||||
RenderTex emptyRenderTex = {0};
|
||||
if (!renderTex) renderTex = &emptyRenderTex;
|
||||
@ -385,7 +385,7 @@ void renderer_triangle(Renderer *const renderer, Rect camera,
|
||||
ARRAY_COUNT(triangleInCamSpace.points));
|
||||
|
||||
for (i32 i = 0; i < ARRAY_COUNT(triangleInCamSpace.points); i++)
|
||||
triangleInCamSpace.points[i] = v2_sub(triangle.points[i], camera.pos);
|
||||
triangleInCamSpace.points[i] = v2_sub(triangle.points[i], camera.min);
|
||||
|
||||
RenderTex emptyRenderTex = {0};
|
||||
if (!renderTex) renderTex = &emptyRenderTex;
|
||||
@ -425,7 +425,7 @@ void renderer_string(Renderer *const renderer, MemoryArena_ *arena, Rect camera,
|
||||
Vertex *vertexList =
|
||||
memory_pushBytes(arena, numVertexesToAlloc * sizeof(Vertex));
|
||||
|
||||
v2 posInCameraSpace = v2_sub(pos, camera.pos);
|
||||
v2 posInCameraSpace = v2_sub(pos, camera.min);
|
||||
pos = posInCameraSpace;
|
||||
|
||||
// TODO(doyle): Find why font is 1px off, might be arial font semantics
|
||||
@ -443,9 +443,9 @@ void renderer_string(Renderer *const renderer, MemoryArena_ *arena, Rect camera,
|
||||
asset_getAtlasSubTex(font->atlas, &CAST(char)codepoint);
|
||||
|
||||
v4 charTexRect = {0};
|
||||
charTexRect.vec2[0] = subTexture.rect.pos;
|
||||
charTexRect.vec2[0] = subTexture.rect.min;
|
||||
charTexRect.vec2[1] =
|
||||
v2_add(subTexture.rect.pos, subTexture.rect.size);
|
||||
v2_add(subTexture.rect.min, subTexture.rect.max);
|
||||
flipTexCoord(&charTexRect, FALSE, TRUE);
|
||||
|
||||
RenderTex renderTex = {tex, charTexRect};
|
||||
@ -472,17 +472,7 @@ void renderer_string(Renderer *const renderer, MemoryArena_ *arena, Rect camera,
|
||||
void renderer_entity(Renderer *renderer, Rect camera, Entity *entity,
|
||||
v2 pivotPoint, Degrees rotate, v4 color, RenderFlags flags)
|
||||
{
|
||||
// TODO(doyle): Batch into render groups
|
||||
|
||||
// NOTE(doyle): Pos + Size since the origin of an entity is it's bottom left
|
||||
// corner. Add the two together so that the clipping point is the far right
|
||||
// side of the entity
|
||||
v2 rightAlignedP = v2_add(entity->pos, entity->hitbox);
|
||||
v2 leftAlignedP = entity->pos;
|
||||
if (math_pointInRect(camera, leftAlignedP) ||
|
||||
math_pointInRect(camera, rightAlignedP))
|
||||
{
|
||||
|
||||
Radians totalRotation = DEGREES_TO_RADIANS((entity->rotation + rotate));
|
||||
RenderTex renderTex = {0};
|
||||
if (entity->tex)
|
||||
{
|
||||
@ -492,11 +482,10 @@ void renderer_entity(Renderer *renderer, Rect camera, Entity *entity,
|
||||
{
|
||||
Animation *anim = entityAnim->anim;
|
||||
char *frameName = anim->frameList[entityAnim->currFrame];
|
||||
SubTexture subTex =
|
||||
asset_getAtlasSubTex(anim->atlas, frameName);
|
||||
SubTexture subTex = asset_getAtlasSubTex(anim->atlas, frameName);
|
||||
|
||||
texRect.vec2[0] = subTex.rect.pos;
|
||||
texRect.vec2[1] = v2_add(subTex.rect.pos, subTex.rect.size);
|
||||
texRect.vec2[0] = subTex.rect.min;
|
||||
texRect.vec2[1] = v2_add(subTex.rect.min, subTex.rect.max);
|
||||
flipTexCoord(&texRect, entity->flipX, entity->flipY);
|
||||
}
|
||||
else
|
||||
@ -514,20 +503,17 @@ void renderer_entity(Renderer *renderer, Rect camera, Entity *entity,
|
||||
renderTex.texRect = texRect;
|
||||
}
|
||||
|
||||
Radians totalRotation = DEGREES_TO_RADIANS((entity->rotation + rotate));
|
||||
if (entity->renderMode == rendermode_quad)
|
||||
{
|
||||
renderer_rect(renderer, camera, entity->pos, entity->size,
|
||||
pivotPoint, totalRotation, &renderTex,
|
||||
color, flags);
|
||||
renderer_rect(renderer, camera, entity->pos, entity->size, pivotPoint,
|
||||
totalRotation, &renderTex, color, flags);
|
||||
}
|
||||
else if (entity->renderMode == rendermode_triangle)
|
||||
{
|
||||
TrianglePoints triangle = {0};
|
||||
|
||||
v2 entityPWithOffset = v2_add(entity->pos, entity->offset);
|
||||
v2 triangleTopPoint =
|
||||
V2(entityPWithOffset.x + (entity->size.w * 0.5f),
|
||||
v2 entityPWithOffset = v2_sub(entity->pos, entity->offset);
|
||||
v2 triangleTopPoint = V2(entityPWithOffset.x + (entity->size.w * 0.5f),
|
||||
entityPWithOffset.y + entity->size.h);
|
||||
|
||||
v2 triangleRightSide =
|
||||
@ -537,15 +523,14 @@ void renderer_entity(Renderer *renderer, Rect camera, Entity *entity,
|
||||
triangle.points[1] = triangleRightSide;
|
||||
triangle.points[2] = triangleTopPoint;
|
||||
|
||||
renderer_triangle(renderer, camera, triangle, pivotPoint,
|
||||
totalRotation, &renderTex, color, flags);
|
||||
renderer_triangle(renderer, camera, triangle, pivotPoint, totalRotation,
|
||||
&renderTex, color, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(INVALID_CODE_PATH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void renderer_renderGroups(Renderer *renderer)
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ i32 userInterface_button(UiState *const uiState, MemoryArena_ *const arena,
|
||||
|
||||
#if 0
|
||||
// Draw shadow
|
||||
renderer_staticRect(renderer, v2_add(V2(1, 1), rect.pos), rect.size,
|
||||
renderer_staticRect(renderer, v2_add(V2(1, 1), rect.min), rect.size,
|
||||
V2(0, 0), 0, renderTex, V4(0, 0, 0, 1));
|
||||
#endif
|
||||
|
||||
@ -68,29 +68,29 @@ i32 userInterface_button(UiState *const uiState, MemoryArena_ *const arena,
|
||||
{
|
||||
// Draw outline
|
||||
renderer_staticRect(renderer,
|
||||
v2_add(V2(-2, -2), v2_add(buttonOffset, rect.pos)),
|
||||
v2_add(V2(4, 4), rect.size), V2(0, 0), 0, &renderTex,
|
||||
v2_add(V2(-2, -2), v2_add(buttonOffset, rect.min)),
|
||||
v2_add(V2(4, 4), rect.max), V2(0, 0), 0, &renderTex,
|
||||
buttonColor, 0);
|
||||
}
|
||||
|
||||
renderer_staticRect(renderer, v2_add(buttonOffset, rect.pos), rect.size,
|
||||
renderer_staticRect(renderer, v2_add(buttonOffset, rect.min), rect.max,
|
||||
V2(0, 0), 0, &renderTex, buttonColor, 0);
|
||||
|
||||
if (label)
|
||||
{
|
||||
v2 labelDim = asset_stringDimInPixels(font, label);
|
||||
v2 labelPos = rect.pos;
|
||||
v2 labelPos = rect.min;
|
||||
|
||||
// Initially position the label to half the width of the button
|
||||
labelPos.x += (rect.size.w * 0.5f);
|
||||
labelPos.x += (rect.max.w * 0.5f);
|
||||
|
||||
// Move the label pos back half the length of the string (i.e.
|
||||
// center it)
|
||||
labelPos.x -= (CAST(f32) labelDim.w * 0.5f);
|
||||
|
||||
if (labelDim.h < rect.size.h)
|
||||
if (labelDim.h < rect.max.h)
|
||||
{
|
||||
labelPos.y += (rect.size.h * 0.5f);
|
||||
labelPos.y += (rect.max.h * 0.5f);
|
||||
labelPos.y -= (CAST(f32)labelDim.h * 0.5f);
|
||||
}
|
||||
|
||||
@ -168,13 +168,13 @@ i32 userInterface_scrollbar(UiState *const uiState,
|
||||
if (uiState->kbdItem == id)
|
||||
{
|
||||
// Draw outline
|
||||
renderer_staticRect(renderer, v2_add(V2(-2, -2), scrollBarRect.pos),
|
||||
v2_add(V2(4, 4), scrollBarRect.size), V2(0, 0), 0,
|
||||
renderer_staticRect(renderer, v2_add(V2(-2, -2), scrollBarRect.min),
|
||||
v2_add(V2(4, 4), scrollBarRect.max), V2(0, 0), 0,
|
||||
&renderTex, V4(1, 0, 0, 1), 0);
|
||||
}
|
||||
|
||||
// Render scroll bar background
|
||||
renderer_staticRect(renderer, scrollBarRect.pos, scrollBarRect.size,
|
||||
renderer_staticRect(renderer, scrollBarRect.min, scrollBarRect.max,
|
||||
V2(0, 0), 0, &renderTex, V4(0.75f, 0.5f, 0.5f, 1), 0);
|
||||
|
||||
// Render scroll bar slider
|
||||
@ -183,8 +183,8 @@ i32 userInterface_scrollbar(UiState *const uiState,
|
||||
|
||||
f32 sliderPercentageOffset = (CAST(f32) *value / CAST(f32) maxValue);
|
||||
f32 sliderYOffsetToBar =
|
||||
(scrollBarRect.size.h - sliderSize.h) * sliderPercentageOffset;
|
||||
v2 sliderPos = v2_add(scrollBarRect.pos, V2(0, sliderYOffsetToBar));
|
||||
(scrollBarRect.max.h - sliderSize.h) * sliderPercentageOffset;
|
||||
v2 sliderPos = v2_add(scrollBarRect.min, V2(0, sliderYOffsetToBar));
|
||||
|
||||
if (uiState->hotItem == id || uiState->activeItem == id)
|
||||
sliderColor = V4(1.0f, 0, 0, 1);
|
||||
@ -228,16 +228,16 @@ i32 userInterface_scrollbar(UiState *const uiState,
|
||||
|
||||
if (uiState->activeItem == id)
|
||||
{
|
||||
f32 mouseYRelToRect = input.mouseP.y - scrollBarRect.pos.y;
|
||||
f32 mouseYRelToRect = input.mouseP.y - scrollBarRect.min.y;
|
||||
|
||||
// Bounds check
|
||||
if (mouseYRelToRect < 0)
|
||||
mouseYRelToRect = 0;
|
||||
else if (mouseYRelToRect > scrollBarRect.size.h)
|
||||
mouseYRelToRect = scrollBarRect.size.h;
|
||||
else if (mouseYRelToRect > scrollBarRect.max.h)
|
||||
mouseYRelToRect = scrollBarRect.max.h;
|
||||
|
||||
f32 newSliderPercentOffset =
|
||||
(CAST(f32) mouseYRelToRect / scrollBarRect.size.h);
|
||||
(CAST(f32) mouseYRelToRect / scrollBarRect.max.h);
|
||||
|
||||
i32 newValue = CAST(i32)(newSliderPercentOffset * CAST(f32)maxValue);
|
||||
if (newValue != *value)
|
||||
@ -282,27 +282,27 @@ i32 userInterface_textField(UiState *const uiState, MemoryArena_ *const arena,
|
||||
if (uiState->kbdItem == id)
|
||||
{
|
||||
// Draw outline
|
||||
renderer_staticRect(renderer, v2_add(V2(-2, -2), rect.pos),
|
||||
v2_add(V2(4, 4), rect.size), V2(0, 0), 0,
|
||||
renderer_staticRect(renderer, v2_add(V2(-2, -2), rect.min),
|
||||
v2_add(V2(4, 4), rect.max), V2(0, 0), 0,
|
||||
&renderTex, V4(1.0f, 0, 0, 1), 0);
|
||||
}
|
||||
|
||||
// Render text field
|
||||
renderer_staticRect(renderer, rect.pos, rect.size, V2(0, 0), 0,
|
||||
renderer_staticRect(renderer, rect.min, rect.max, V2(0, 0), 0,
|
||||
&renderTex, V4(0.75f, 0.5f, 0.5f, 1), 0);
|
||||
|
||||
if (uiState->activeItem == id || uiState->hotItem == id)
|
||||
{
|
||||
renderer_staticRect(renderer, rect.pos, rect.size, V2(0, 0), 0,
|
||||
renderer_staticRect(renderer, rect.min, rect.max, V2(0, 0), 0,
|
||||
&renderTex, V4(0.75f, 0.75f, 0.0f, 1), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer_staticRect(renderer, rect.pos, rect.size, V2(0, 0), 0,
|
||||
renderer_staticRect(renderer, rect.min, rect.max, V2(0, 0), 0,
|
||||
&renderTex, V4(0.5f, 0.5f, 0.5f, 1), 0);
|
||||
}
|
||||
|
||||
v2 strPos = rect.pos;
|
||||
v2 strPos = rect.min;
|
||||
renderer_staticString(renderer, arena, font, string, strPos, V2(0, 0), 0,
|
||||
V4(0, 0, 0, 1), 0);
|
||||
|
||||
@ -365,10 +365,10 @@ i32 userInterface_window(UiState *const uiState, MemoryArena_ *const arena,
|
||||
|
||||
Rect rect = window->rect;
|
||||
RenderTex nullRenderTex = renderer_createNullRenderTex(assetManager);
|
||||
renderer_staticRect(renderer, rect.pos, rect.size, V2(0, 0), 0,
|
||||
renderer_staticRect(renderer, rect.min, rect.max, V2(0, 0), 0,
|
||||
&nullRenderTex, V4(0.25f, 0.25f, 0.5f, 0.5f), 0);
|
||||
|
||||
v2 menuTitleP = v2_add(rect.pos, V2(0, rect.size.h - 10));
|
||||
v2 menuTitleP = v2_add(rect.min, V2(0, rect.max.h - 10));
|
||||
renderer_staticString(renderer, arena, font, window->title, menuTitleP,
|
||||
V2(0, 0), 0, V4(0, 0, 0, 1), 0);
|
||||
|
||||
@ -444,11 +444,11 @@ i32 userInterface_window(UiState *const uiState, MemoryArena_ *const arena,
|
||||
for (i32 i = 0; i < window->numChildUiItems; i++)
|
||||
{
|
||||
UiItem *childUi = &window->childUiItems[i];
|
||||
childUi->rect.pos = v2_add(deltaP, childUi->rect.pos);
|
||||
childUi->rect.min = v2_add(deltaP, childUi->rect.min);
|
||||
}
|
||||
|
||||
DEBUG_PUSH_VAR("Delta Pos %4.2f, %4.2f", deltaP, "v2");
|
||||
window->rect.pos = v2_add(deltaP, window->rect.pos);
|
||||
window->rect.min = v2_add(deltaP, window->rect.min);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -70,8 +70,8 @@ typedef union v4
|
||||
|
||||
typedef struct Rect
|
||||
{
|
||||
v2 pos;
|
||||
v2 size;
|
||||
v2 min;
|
||||
v2 max;
|
||||
} Rect;
|
||||
|
||||
INTERNAL inline v2 V2i(const i32 x, const i32 y)
|
||||
@ -319,11 +319,11 @@ INTERNAL inline v4 mat4_mul_v4(const mat4 a, const v4 b)
|
||||
INTERNAL inline b32 math_pointInRect(Rect rect, v2 point)
|
||||
{
|
||||
b32 outsideOfRectX = FALSE;
|
||||
if (point.x < rect.pos.x || point.x > (rect.pos.x + rect.size.w))
|
||||
if (point.x < rect.min.x || point.x > (rect.min.x + rect.max.w))
|
||||
outsideOfRectX = TRUE;
|
||||
|
||||
b32 outsideOfRectY = FALSE;
|
||||
if (point.y < rect.pos.y || point.y > (rect.pos.y + rect.size.h))
|
||||
if (point.y < rect.min.y || point.y > (rect.min.y + rect.max.h))
|
||||
outsideOfRectY = TRUE;
|
||||
|
||||
if (outsideOfRectX || outsideOfRectY) return FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user