From c9ca14e6595c45e3cf71aeaca49c2379302dff99 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 04:48:46 -0300 Subject: Update raylib.h Added NinePatch struc definition and function prototype. --- src/raylib.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/raylib.h b/src/raylib.h index 8d1389f7..e2d5cc33 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -412,6 +412,14 @@ typedef struct RenderTexture2D { // RenderTexture type, same as RenderTexture2D typedef RenderTexture2D RenderTexture; +typedef struct NinePatch { + Texture2D texture; // The texture associated with the 9-patch (maybe Texture2D *, instead?) + Rectangle sourceRec; // The 9-patch region in the texture + Vector2 minSize; // The minimum size the 9-patch can be shrunk to + float borderWidth[4]; // The widths of the left, top, right and bottom borders + int padding[4]; // Helps the n-patch contents fit nicely inside +} NinePatch; + // Font character info typedef struct CharInfo { int value; // Character value (Unicode) @@ -999,6 +1007,7 @@ RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters +RLAPI void DrawNinePatch(NinePatch ninePatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint); //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) -- cgit v1.2.3 From 7cc2a5585b548510ec9a0756672b9a163fb6d30f Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 04:51:26 -0300 Subject: Update textures.c Added DrawNinePatch() function implementation. --- src/textures.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) (limited to 'src') diff --git a/src/textures.c b/src/textures.c index 3530e115..fb31eeb8 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2330,6 +2330,225 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V } } +void DrawNinePatch(NinePatch ninePatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint) +{ + // Check if n-patch texture is valid + if (ninePatch.texture.id > 0) + { + float width = (float)ninePatch.texture.width; + float height = (float)ninePatch.texture.height; + + float contentsWidth = (destRec.width >= ninePatch.minSize.x)? destRec.width : ninePatch.minSize.x; + float contentsHeight = (destRec.height >= ninePatch.minSize.y)? destRec.height : ninePatch.minSize.y; + + if (usePadding) + { + contentsWidth += (float)(ninePatch.padding[0] + ninePatch.padding[2]); + contentsHeight += (float)(ninePatch.padding[1] + ninePatch.padding[3]); + } + + if (ninePatch.sourceRec.width < 0) ninePatch.sourceRec.x -= ninePatch.sourceRec.width; + if (ninePatch.sourceRec.height < 0) ninePatch.sourceRec.y -= ninePatch.sourceRec.height; + + rlEnableTexture(ninePatch.texture.id); + + bool drawCenter = true; + bool drawMiddle = true; + + float borderWidth[4]; // copy the ninePatch.borderWidth[4] values so they can be adjusted + for (int i = 0; i < 4; i++) { borderWidth[i] = ninePatch.borderWidth[i]; } + + // adjust the lateral (left and right) border widths in case contentsWidth < ninePatch.texture.width + if (contentsWidth <= ninePatch.borderWidth[0] + ninePatch.borderWidth[2]) + { + drawCenter = false; + borderWidth[0] = (borderWidth[0] / (ninePatch.borderWidth[0] + ninePatch.borderWidth[2])) * (borderWidth[0] + borderWidth[2]); + borderWidth[2] = contentsWidth - borderWidth[0]; + } + // adjust the lateral (top and bottom) border heights in case contentsHeight < ninePatch.texture.height + if (contentsHeight <= ninePatch.borderWidth[1] + ninePatch.borderWidth[3]) + { + drawMiddle = false; + borderWidth[1] = (borderWidth[1] / (ninePatch.borderWidth[1] + ninePatch.borderWidth[3])) * (borderWidth[1] + borderWidth[3]); + borderWidth[3] = contentsHeight - borderWidth[1]; + } + + Vector2 vertA, vertB, vertC, vertD; + vertA.x = 0.0f; + vertA.y = 0.0f; + vertB.x = borderWidth[0]; + vertB.y = borderWidth[1]; + vertC.x = contentsWidth - borderWidth[2]; + vertC.y = contentsHeight - borderWidth[3]; + vertD.x = contentsWidth; + vertD.y = contentsHeight; + + Vector2 coordA, coordB, coordC, coordD; + coordA.x = ninePatch.sourceRec.x / width; + coordA.y = ninePatch.sourceRec.y / height; + coordB.x = (ninePatch.sourceRec.x + borderWidth[0]) / width; + coordB.y = (ninePatch.sourceRec.y + borderWidth[1]) / height; + coordC.x = (ninePatch.sourceRec.x + ninePatch.sourceRec.width - borderWidth[2]) / width; + coordC.y = (ninePatch.sourceRec.y + ninePatch.sourceRec.height - borderWidth[3]) / height; + coordD.x = (ninePatch.sourceRec.x + ninePatch.sourceRec.width) / width; + coordD.y = (ninePatch.sourceRec.y + ninePatch.sourceRec.height) / height; + + rlPushMatrix(); + if (usePadding) + { + rlTranslatef(destRec.x - (float)ninePatch.padding[0], destRec.y - (float)ninePatch.padding[2], 0); + } + else + { + rlTranslatef(destRec.x, destRec.y, 0); + } + rlRotatef(rotation, 0, 0, 1); + rlTranslatef(-origin.x, -origin.y, 0); + + rlBegin(RL_QUADS); + rlColor4ub(tint.r, tint.g, tint.b, tint.a); + rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer + + // ------------------------------------------------------------ + // TOP-LEFT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); + + if (drawCenter) + { + // TOP-CENTER QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); + } + + // TOP-RIGHT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); + + + if (drawMiddle) + { + // ------------------------------------------------------------ + // MIDDLE-LEFT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); + + if (drawCenter) + { + // MIDDLE-CENTER QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + } + + // MIDDLE-RIGHT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + } + + // ------------------------------------------------------------ + // BOTTOM-LEFT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); + + if (drawCenter) + { + // BOTTOM-CENTER QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + } + + // BOTTOM-RIGHT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + + rlEnd(); + rlPopMatrix(); + + rlDisableTexture(); + } +} + //---------------------------------------------------------------------------------- // Module specific Functions Definition //---------------------------------------------------------------------------------- -- cgit v1.2.3 From 6ef03ea4e80a538149c1a09d364182901d08297d Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 20:50:13 -0300 Subject: Update raylib.h Added support form vertical and horizontal 3-patches. Corrected the distortion caused when destRec size is smaller than 4x4. Now even 1x10 or 0x0 sizes are drawn correctly. --- src/raylib.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/raylib.h b/src/raylib.h index e2d5cc33..4aa6e299 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -412,13 +412,14 @@ typedef struct RenderTexture2D { // RenderTexture type, same as RenderTexture2D typedef RenderTexture2D RenderTexture; -typedef struct NinePatch { +typedef struct NPatch { Texture2D texture; // The texture associated with the 9-patch (maybe Texture2D *, instead?) Rectangle sourceRec; // The 9-patch region in the texture Vector2 minSize; // The minimum size the 9-patch can be shrunk to float borderWidth[4]; // The widths of the left, top, right and bottom borders int padding[4]; // Helps the n-patch contents fit nicely inside -} NinePatch; + int type; // The type of this n-patch: 9-patch, 3-patch vertical or 3-patch horizontal +} NPatch; // Font character info typedef struct CharInfo { @@ -737,6 +738,13 @@ typedef enum { HMD_SONY_PSVR } VrDeviceType; +// Type of n-patch +typedef enum { + NPT_9PATCH = 0, // 3x3 + NPT_3PATCH_VERTICAL, // 1x3 + NPT_3PATCH_HORIZONTAL // 3x1 +} NPatchType; + // Callbacks to be implemented by users typedef void (*TraceLogCallback)(int msgType, const char *text, va_list args); @@ -1007,7 +1015,7 @@ RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters -RLAPI void DrawNinePatch(NinePatch ninePatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint); +RLAPI void DrawNPatch(NPatch nPatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint); //Draw 9x9, 3x1 or 1x3 stretchable Texture2D //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) -- cgit v1.2.3 From 28424141f000aed5d053845bd0c6b30002864310 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 20:53:15 -0300 Subject: Update textures.c Added support form vertical and horizontal 3-patches. Corrected the distortion caused when destRec size is smaller than 4x4. Now even 1x10 or 0x0 sizes are drawn correctly. --- src/textures.c | 317 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 208 insertions(+), 109 deletions(-) (limited to 'src') diff --git a/src/textures.c b/src/textures.c index fb31eeb8..d610d03b 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2330,73 +2330,80 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V } } -void DrawNinePatch(NinePatch ninePatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint) + +void DrawNPatch(NPatch nPatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint) { // Check if n-patch texture is valid - if (ninePatch.texture.id > 0) + if (nPatch.texture.id > 0) { - float width = (float)ninePatch.texture.width; - float height = (float)ninePatch.texture.height; + float width = (float)nPatch.texture.width; + float height = (float)nPatch.texture.height; - float contentsWidth = (destRec.width >= ninePatch.minSize.x)? destRec.width : ninePatch.minSize.x; - float contentsHeight = (destRec.height >= ninePatch.minSize.y)? destRec.height : ninePatch.minSize.y; + float patchWidth = (destRec.width >= nPatch.minSize.x)? destRec.width : nPatch.minSize.x; + float patchHeight = (destRec.height >= nPatch.minSize.y)? destRec.height : nPatch.minSize.y; if (usePadding) { - contentsWidth += (float)(ninePatch.padding[0] + ninePatch.padding[2]); - contentsHeight += (float)(ninePatch.padding[1] + ninePatch.padding[3]); + patchWidth += (float)(nPatch.padding[0] + nPatch.padding[2]); + patchHeight += (float)(nPatch.padding[1] + nPatch.padding[3]); } - - if (ninePatch.sourceRec.width < 0) ninePatch.sourceRec.x -= ninePatch.sourceRec.width; - if (ninePatch.sourceRec.height < 0) ninePatch.sourceRec.y -= ninePatch.sourceRec.height; - rlEnableTexture(ninePatch.texture.id); + if (nPatch.sourceRec.width < 0) nPatch.sourceRec.x -= nPatch.sourceRec.width; + if (nPatch.sourceRec.height < 0) nPatch.sourceRec.y -= nPatch.sourceRec.height; + + // Ignore the destRec width if the n-patch type is NPT_3PATCH_VERTICAL + if (nPatch.type == NPT_3PATCH_VERTICAL) { patchWidth = nPatch.sourceRec.width; } + + // Ignore the destRec height if the n-patch type is NPT_3PATCH_HORIZONTAL + if (nPatch.type == NPT_3PATCH_HORIZONTAL) { patchHeight = nPatch.sourceRec.height; } bool drawCenter = true; bool drawMiddle = true; - float borderWidth[4]; // copy the ninePatch.borderWidth[4] values so they can be adjusted - for (int i = 0; i < 4; i++) { borderWidth[i] = ninePatch.borderWidth[i]; } + float borderWidth[4]; // copy the nPatch.borderWidth[4] values so they can be adjusted + for (int i = 0; i < 4; i++) { borderWidth[i] = nPatch.borderWidth[i]; } - // adjust the lateral (left and right) border widths in case contentsWidth < ninePatch.texture.width - if (contentsWidth <= ninePatch.borderWidth[0] + ninePatch.borderWidth[2]) + // adjust the lateral (left and right) border widths in case patchWidth < nPatch.texture.width + if (patchWidth <= nPatch.borderWidth[0] + nPatch.borderWidth[2]) { drawCenter = false; - borderWidth[0] = (borderWidth[0] / (ninePatch.borderWidth[0] + ninePatch.borderWidth[2])) * (borderWidth[0] + borderWidth[2]); - borderWidth[2] = contentsWidth - borderWidth[0]; + borderWidth[0] = (borderWidth[0] / (nPatch.borderWidth[0] + nPatch.borderWidth[2])) * patchWidth; + borderWidth[2] = patchWidth - borderWidth[0]; } - // adjust the lateral (top and bottom) border heights in case contentsHeight < ninePatch.texture.height - if (contentsHeight <= ninePatch.borderWidth[1] + ninePatch.borderWidth[3]) + // adjust the lateral (top and bottom) border heights in case patchHeight < nPatch.texture.height + if (patchHeight <= nPatch.borderWidth[1] + nPatch.borderWidth[3]) { drawMiddle = false; - borderWidth[1] = (borderWidth[1] / (ninePatch.borderWidth[1] + ninePatch.borderWidth[3])) * (borderWidth[1] + borderWidth[3]); - borderWidth[3] = contentsHeight - borderWidth[1]; + borderWidth[1] = (borderWidth[1] / (nPatch.borderWidth[1] + nPatch.borderWidth[3])) * patchHeight; + borderWidth[3] = patchHeight - borderWidth[1]; } Vector2 vertA, vertB, vertC, vertD; - vertA.x = 0.0f; - vertA.y = 0.0f; - vertB.x = borderWidth[0]; - vertB.y = borderWidth[1]; - vertC.x = contentsWidth - borderWidth[2]; - vertC.y = contentsHeight - borderWidth[3]; - vertD.x = contentsWidth; - vertD.y = contentsHeight; + vertA.x = 0.0f; // outer left + vertA.y = 0.0f; // outer top + vertB.x = borderWidth[0]; // inner left + vertB.y = borderWidth[1]; // inner top + vertC.x = patchWidth - borderWidth[2]; // inner right + vertC.y = patchHeight - borderWidth[3]; // inner bottom + vertD.x = patchWidth; // outer right + vertD.y = patchHeight; // outer bottom Vector2 coordA, coordB, coordC, coordD; - coordA.x = ninePatch.sourceRec.x / width; - coordA.y = ninePatch.sourceRec.y / height; - coordB.x = (ninePatch.sourceRec.x + borderWidth[0]) / width; - coordB.y = (ninePatch.sourceRec.y + borderWidth[1]) / height; - coordC.x = (ninePatch.sourceRec.x + ninePatch.sourceRec.width - borderWidth[2]) / width; - coordC.y = (ninePatch.sourceRec.y + ninePatch.sourceRec.height - borderWidth[3]) / height; - coordD.x = (ninePatch.sourceRec.x + ninePatch.sourceRec.width) / width; - coordD.y = (ninePatch.sourceRec.y + ninePatch.sourceRec.height) / height; + coordA.x = nPatch.sourceRec.x / width; + coordA.y = nPatch.sourceRec.y / height; + coordB.x = (nPatch.sourceRec.x + borderWidth[0]) / width; + coordB.y = (nPatch.sourceRec.y + borderWidth[1]) / height; + coordC.x = (nPatch.sourceRec.x + nPatch.sourceRec.width - borderWidth[2]) / width; + coordC.y = (nPatch.sourceRec.y + nPatch.sourceRec.height - borderWidth[3]) / height; + coordD.x = (nPatch.sourceRec.x + nPatch.sourceRec.width) / width; + coordD.y = (nPatch.sourceRec.y + nPatch.sourceRec.height) / height; + + rlEnableTexture(nPatch.texture.id); rlPushMatrix(); if (usePadding) { - rlTranslatef(destRec.x - (float)ninePatch.padding[0], destRec.y - (float)ninePatch.padding[2], 0); + rlTranslatef(destRec.x - (float)nPatch.padding[0], destRec.y - (float)nPatch.padding[2], 0); } else { @@ -2409,139 +2416,231 @@ void DrawNinePatch(NinePatch ninePatch, Rectangle destRec, bool usePadding, Vect rlColor4ub(tint.r, tint.g, tint.b, tint.a); rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer - // ------------------------------------------------------------ - // TOP-LEFT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); + if (nPatch.type == NPT_3PATCH_HORIZONTAL) + { + // ------------------------------------------------------------ + // LEFT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); - // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); - // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); + // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); - if (drawCenter) - { - // TOP-CENTER QUAD + if (drawCenter) + { + // CENTER QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); + } + + // RIGHT QUAD // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); } + else if (nPatch.type == NPT_3PATCH_VERTICAL) + { + // ------------------------------------------------------------ + // TOP QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); - // TOP-RIGHT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); + if (drawCenter) + { + // MIDDLE QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); - if (drawMiddle) + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); + } + + // BOTTOM QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); + + } + else if (nPatch.type == NPT_9PATCH) { // ------------------------------------------------------------ - // MIDDLE-LEFT QUAD + // TOP-LEFT QUAD // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); if (drawCenter) { - // MIDDLE-CENTER QUAD + // TOP-CENTER QUAD // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); } - // MIDDLE-RIGHT QUAD + // TOP-RIGHT QUAD // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); - } + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); - // ------------------------------------------------------------ - // BOTTOM-LEFT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); + if (drawMiddle) + { + // ------------------------------------------------------------ + // MIDDLE-LEFT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); - // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); + // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); - // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); + // Top-left corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); - if (drawCenter) - { - // BOTTOM-CENTER QUAD + if (drawCenter) + { + // MIDDLE-CENTER QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + } + + // MIDDLE-RIGHT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + } + + // ------------------------------------------------------------ + // BOTTOM-LEFT QUAD // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); - } + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); - // BOTTOM-RIGHT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); + if (drawCenter) + { + // BOTTOM-CENTER QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); + // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + // Top-left corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + } + + // BOTTOM-RIGHT QUAD + // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); + + // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); + // Top-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); + + // Top-left corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + } rlEnd(); rlPopMatrix(); -- cgit v1.2.3 From 5f89e35d1cf6543594569d294190cfdac5be6139 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Wed, 8 Aug 2018 16:39:10 -0300 Subject: Update raylib.h --- src/raylib.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/raylib.h b/src/raylib.h index 4aa6e299..af31e779 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -412,14 +412,14 @@ typedef struct RenderTexture2D { // RenderTexture type, same as RenderTexture2D typedef RenderTexture2D RenderTexture; -typedef struct NPatch { - Texture2D texture; // The texture associated with the 9-patch (maybe Texture2D *, instead?) - Rectangle sourceRec; // The 9-patch region in the texture - Vector2 minSize; // The minimum size the 9-patch can be shrunk to - float borderWidth[4]; // The widths of the left, top, right and bottom borders - int padding[4]; // Helps the n-patch contents fit nicely inside - int type; // The type of this n-patch: 9-patch, 3-patch vertical or 3-patch horizontal -} NPatch; +typedef struct NPatchInfo { + Rectangle sourceRec; // Region in the texture + int left; // left border offset + int top; // top border offset + int right; // right border offset + int bottom; // bottom border offset + int type; // layout of the n-patch: 3x3, 1x3 or 3x1 +} NPatchInfo; // Font character info typedef struct CharInfo { @@ -1015,7 +1015,7 @@ RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters -RLAPI void DrawNPatch(NPatch nPatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint); //Draw 9x9, 3x1 or 1x3 stretchable Texture2D +RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely. //------------------------------------------------------------------------------------ // Font Loading and Text Drawing Functions (Module: text) -- cgit v1.2.3 From dab78d59f34efcaae46966e35410687a13dd838e Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Wed, 8 Aug 2018 16:42:39 -0300 Subject: Update textures.c See raylib/examples/textures/textures_image_9patch.c for how to use `DrawTextureNPatch` function. --- src/textures.c | 378 +++++++++++++++++++-------------------------------------- 1 file changed, 128 insertions(+), 250 deletions(-) (limited to 'src') diff --git a/src/textures.c b/src/textures.c index d610d03b..48bf69ac 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2330,85 +2330,67 @@ void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, V } } - -void DrawNPatch(NPatch nPatch, Rectangle destRec, bool usePadding, Vector2 origin, float rotation, Color tint) +void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle destRec, Vector2 origin, float rotation, Color tint) { - // Check if n-patch texture is valid - if (nPatch.texture.id > 0) + if (texture.id > 0) { - float width = (float)nPatch.texture.width; - float height = (float)nPatch.texture.height; - - float patchWidth = (destRec.width >= nPatch.minSize.x)? destRec.width : nPatch.minSize.x; - float patchHeight = (destRec.height >= nPatch.minSize.y)? destRec.height : nPatch.minSize.y; - - if (usePadding) - { - patchWidth += (float)(nPatch.padding[0] + nPatch.padding[2]); - patchHeight += (float)(nPatch.padding[1] + nPatch.padding[3]); - } + float width = (float)texture.width; + float height = (float)texture.height; - if (nPatch.sourceRec.width < 0) nPatch.sourceRec.x -= nPatch.sourceRec.width; - if (nPatch.sourceRec.height < 0) nPatch.sourceRec.y -= nPatch.sourceRec.height; + float patchWidth = (destRec.width <= 0.0f)? 0.0f : destRec.width; + float patchHeight = (destRec.height <= 0.0f)? 0.0f : destRec.height; - // Ignore the destRec width if the n-patch type is NPT_3PATCH_VERTICAL - if (nPatch.type == NPT_3PATCH_VERTICAL) { patchWidth = nPatch.sourceRec.width; } - - // Ignore the destRec height if the n-patch type is NPT_3PATCH_HORIZONTAL - if (nPatch.type == NPT_3PATCH_HORIZONTAL) { patchHeight = nPatch.sourceRec.height; } + if (nPatchInfo.sourceRec.width < 0) nPatchInfo.sourceRec.x -= nPatchInfo.sourceRec.width; + if (nPatchInfo.sourceRec.height < 0) nPatchInfo.sourceRec.y -= nPatchInfo.sourceRec.height; + if (nPatchInfo.type == NPT_3PATCH_HORIZONTAL) patchHeight = nPatchInfo.sourceRec.height; + if (nPatchInfo.type == NPT_3PATCH_VERTICAL) patchWidth = nPatchInfo.sourceRec.width; bool drawCenter = true; bool drawMiddle = true; + float leftBorder = (float)nPatchInfo.left; + float topBorder = (float)nPatchInfo.top; + float rightBorder = (float)nPatchInfo.right; + float bottomBorder = (float)nPatchInfo.bottom; - float borderWidth[4]; // copy the nPatch.borderWidth[4] values so they can be adjusted - for (int i = 0; i < 4; i++) { borderWidth[i] = nPatch.borderWidth[i]; } - - // adjust the lateral (left and right) border widths in case patchWidth < nPatch.texture.width - if (patchWidth <= nPatch.borderWidth[0] + nPatch.borderWidth[2]) + // adjust the lateral (left and right) border widths in case patchWidth < texture.width + if (patchWidth <= (leftBorder + rightBorder) && nPatchInfo.type != NPT_3PATCH_VERTICAL) { drawCenter = false; - borderWidth[0] = (borderWidth[0] / (nPatch.borderWidth[0] + nPatch.borderWidth[2])) * patchWidth; - borderWidth[2] = patchWidth - borderWidth[0]; + leftBorder = (leftBorder / (leftBorder + rightBorder)) * patchWidth; + rightBorder = patchWidth - leftBorder; } - // adjust the lateral (top and bottom) border heights in case patchHeight < nPatch.texture.height - if (patchHeight <= nPatch.borderWidth[1] + nPatch.borderWidth[3]) + // adjust the lateral (top and bottom) border heights in case patchHeight < texture.height + if (patchHeight <= (topBorder + bottomBorder) && nPatchInfo.type != NPT_3PATCH_HORIZONTAL) { drawMiddle = false; - borderWidth[1] = (borderWidth[1] / (nPatch.borderWidth[1] + nPatch.borderWidth[3])) * patchHeight; - borderWidth[3] = patchHeight - borderWidth[1]; + topBorder = (topBorder / (topBorder + bottomBorder)) * patchHeight; + bottomBorder = patchHeight - topBorder; } Vector2 vertA, vertB, vertC, vertD; vertA.x = 0.0f; // outer left vertA.y = 0.0f; // outer top - vertB.x = borderWidth[0]; // inner left - vertB.y = borderWidth[1]; // inner top - vertC.x = patchWidth - borderWidth[2]; // inner right - vertC.y = patchHeight - borderWidth[3]; // inner bottom + vertB.x = leftBorder; // inner left + vertB.y = topBorder; // inner top + vertC.x = patchWidth - rightBorder; // inner right + vertC.y = patchHeight - bottomBorder; // inner bottom vertD.x = patchWidth; // outer right vertD.y = patchHeight; // outer bottom Vector2 coordA, coordB, coordC, coordD; - coordA.x = nPatch.sourceRec.x / width; - coordA.y = nPatch.sourceRec.y / height; - coordB.x = (nPatch.sourceRec.x + borderWidth[0]) / width; - coordB.y = (nPatch.sourceRec.y + borderWidth[1]) / height; - coordC.x = (nPatch.sourceRec.x + nPatch.sourceRec.width - borderWidth[2]) / width; - coordC.y = (nPatch.sourceRec.y + nPatch.sourceRec.height - borderWidth[3]) / height; - coordD.x = (nPatch.sourceRec.x + nPatch.sourceRec.width) / width; - coordD.y = (nPatch.sourceRec.y + nPatch.sourceRec.height) / height; + coordA.x = nPatchInfo.sourceRec.x / width; + coordA.y = nPatchInfo.sourceRec.y / height; + coordB.x = (nPatchInfo.sourceRec.x + leftBorder) / width; + coordB.y = (nPatchInfo.sourceRec.y + topBorder) / height; + coordC.x = (nPatchInfo.sourceRec.x + nPatchInfo.sourceRec.width - rightBorder) / width; + coordC.y = (nPatchInfo.sourceRec.y + nPatchInfo.sourceRec.height - bottomBorder) / height; + coordD.x = (nPatchInfo.sourceRec.x + nPatchInfo.sourceRec.width) / width; + coordD.y = (nPatchInfo.sourceRec.y + nPatchInfo.sourceRec.height) / height; - rlEnableTexture(nPatch.texture.id); + rlEnableTexture(texture.id); rlPushMatrix(); - if (usePadding) - { - rlTranslatef(destRec.x - (float)nPatch.padding[0], destRec.y - (float)nPatch.padding[2], 0); - } - else - { - rlTranslatef(destRec.x, destRec.y, 0); - } + rlTranslatef(destRec.x, destRec.y, 0); rlRotatef(rotation, 0, 0, 1); rlTranslatef(-origin.x, -origin.y, 0); @@ -2416,235 +2398,131 @@ void DrawNPatch(NPatch nPatch, Rectangle destRec, bool usePadding, Vector2 origi rlColor4ub(tint.r, tint.g, tint.b, tint.a); rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer - if (nPatch.type == NPT_3PATCH_HORIZONTAL) - { - // ------------------------------------------------------------ - // LEFT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); - - if (drawCenter) - { - // CENTER QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); - } - - // RIGHT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); - } - else if (nPatch.type == NPT_3PATCH_VERTICAL) - { - // ------------------------------------------------------------ - // TOP QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); - - if (drawCenter) - { - // MIDDLE QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); - } - - // BOTTOM QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); - - } - else if (nPatch.type == NPT_9PATCH) + if (nPatchInfo.type == NPT_9PATCH) { // ------------------------------------------------------------ // TOP-LEFT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); - + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); // Top-left corner for texture and quad if (drawCenter) { // TOP-CENTER QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); // Top-left corner for texture and quad } - // TOP-RIGHT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); - + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); // Top-left corner for texture and quad if (drawMiddle) { // ------------------------------------------------------------ // MIDDLE-LEFT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); - + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); // Top-left corner for texture and quad if (drawCenter) { // MIDDLE-CENTER QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordB.y); rlVertex2f(vertB.x, vertB.y); // Top-left corner for texture and quad } // MIDDLE-RIGHT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordB.y); rlVertex2f(vertC.x, vertB.y); // Top-left corner for texture and quad } // ------------------------------------------------------------ // BOTTOM-LEFT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); - + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); // Top-left corner for texture and quad if (drawCenter) { // BOTTOM-CENTER QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.y); // Top-left corner for texture and quad } // BOTTOM-RIGHT QUAD - // Bottom-left corner for texture and quad - rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); - - // Bottom-right corner for texture and quad - rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); - - // Top-right corner for texture and quad - rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); - - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); // Top-left corner for texture and quad + } + else if (nPatchInfo.type == NPT_3PATCH_VERTICAL) + { + // TOP QUAD + // ----------------------------------------------------------- + // Texture coords Vertices + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); // Top-left corner for texture and quad + if (drawCenter) + { + // MIDDLE QUAD + // ----------------------------------------------------------- + // Texture coords Vertices + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordB.y); rlVertex2f(vertD.x, vertB.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordB.y); rlVertex2f(vertA.x, vertB.y); // Top-left corner for texture and quad + } + // BOTTOM QUAD + // ----------------------------------------------------------- + // Texture coords Vertices + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordC.y); rlVertex2f(vertD.x, vertC.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordC.y); rlVertex2f(vertA.x, vertC.y); // Top-left corner for texture and quad + } + else if (nPatchInfo.type == NPT_3PATCH_HORIZONTAL) + { + // LEFT QUAD + // ----------------------------------------------------------- + // Texture coords Vertices + rlTexCoord2f(coordA.x, coordD.y); rlVertex2f(vertA.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordA.x, coordA.y); rlVertex2f(vertA.x, vertA.y); // Top-left corner for texture and quad + if (drawCenter) + { + // CENTER QUAD + // ----------------------------------------------------------- + // Texture coords Vertices + rlTexCoord2f(coordB.x, coordD.y); rlVertex2f(vertB.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordB.x, coordA.y); rlVertex2f(vertB.x, vertA.y); // Top-left corner for texture and quad + } + // RIGHT QUAD + // ----------------------------------------------------------- + // Texture coords Vertices + rlTexCoord2f(coordC.x, coordD.y); rlVertex2f(vertC.x, vertD.y); // Bottom-left corner for texture and quad + rlTexCoord2f(coordD.x, coordD.y); rlVertex2f(vertD.x, vertD.y); // Bottom-right corner for texture and quad + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); // Top-right corner for texture and quad + rlTexCoord2f(coordC.x, coordA.y); rlVertex2f(vertC.x, vertA.y); // Top-left corner for texture and quad } rlEnd(); rlPopMatrix(); rlDisableTexture(); + } } -- cgit v1.2.3