From c9ca14e6595c45e3cf71aeaca49c2379302dff99 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 04:48:46 -0300 Subject: [PATCH 1/9] Update raylib.h Added NinePatch struc definition and function prototype. --- src/raylib.h | 9 +++++++++ 1 file changed, 9 insertions(+) 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) From 7cc2a5585b548510ec9a0756672b9a163fb6d30f Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 04:51:26 -0300 Subject: [PATCH 2/9] Update textures.c Added DrawNinePatch() function implementation. --- src/textures.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) 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 //---------------------------------------------------------------------------------- From 6ef03ea4e80a538149c1a09d364182901d08297d Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 20:50:13 -0300 Subject: [PATCH 3/9] 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(-) 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) From 28424141f000aed5d053845bd0c6b30002864310 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Fri, 3 Aug 2018 20:53:15 -0300 Subject: [PATCH 4/9] 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 | 377 +++++++++++++++++++++++++++++++------------------ 1 file changed, 238 insertions(+), 139 deletions(-) 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); - - // 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) + if (nPatch.type == NPT_3PATCH_HORIZONTAL) { // ------------------------------------------------------------ - // MIDDLE-LEFT QUAD + // LEFT QUAD // Bottom-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-right 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); // 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 + // CENTER QUAD // Bottom-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-right 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); // 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 + // 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); + // 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(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.y); + rlTexCoord2f(coordD.x, coordA.y); rlVertex2f(vertD.x, vertA.y); // Top-left corner for texture and quad - rlTexCoord2f(coordB.x, coordC.y); rlVertex2f(vertB.x, vertC.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); - // 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, coordB.y); rlVertex2f(vertD.x, vertB.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-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, coordA.y); rlVertex2f(vertA.x, vertA.y); - // Top-left corner for texture and quad - rlTexCoord2f(coordC.x, coordC.y); rlVertex2f(vertC.x, vertC.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) + { + // ------------------------------------------------------------ + // 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(); From 34c3ae5ab368bd26eed3f54556fb63af993a5f23 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Wed, 8 Aug 2018 16:21:33 -0300 Subject: [PATCH 5/9] Added 9-patch texture used in the example code. --- examples/textures/resources/ninepatch_button.png | Bin 0 -> 5923 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/textures/resources/ninepatch_button.png diff --git a/examples/textures/resources/ninepatch_button.png b/examples/textures/resources/ninepatch_button.png new file mode 100644 index 0000000000000000000000000000000000000000..d1b59970763dd6e152717f47ff29e2151d3892c8 GIT binary patch literal 5923 zcmZWt2T)Vp)=feJp?8obp^H=n=}168dJ$<-rAZNp^iGf_O`25cNJr^K1cZQe1StkV zN~D7{>4@+r_`Z4XoBz(-d(NEMYwfl7*=L_jqI9(GlM*o!0RR9}RTaet*bxo@00B^Z z>QM=bN`M9K~Ic$4^fKp@n=)tHy`I zOkhtRtHYvHrJSB@{$!%8O@_nY`+Pi|D}Se^Z|GT~#%5ctm%@Xp$}Har+^8tZAC!2p zmSgNrH`;fL+F|IV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&c}swS%_NyCP-8Xi3p+X}Vkp;D13=Pb2rQjVK>G3nR*`*A za&+@$I(>waqd3)lBR;O@SI+t~d)9#%My~j?vSGt5?D2rz+?fAs7VYai z{m8FoB&NJ(MiOfk;W(k~-0p~mo~&``c9iJ}IdrHU^w?JB{Fzv(@VYw5<0Y5(@C*vX z1+5Q%mWWw2IDv<91aiQ5N`PASIyFFLmgIgeV>MOVGlq&Mat){DEZDAMH%ukH@bg>R zU#A8mL5}BqswM5;>sL)8JzdW6Uy>$i5f|sd z4wfcO|J50X%n(rm+LN-l_>Nk*9R93$mpXlC@v1xdsel3m;v4*q^wUbbECwHf?1m7{ zi$DC5uO|U41{W)H0wC>$Ftubv`MRn_(1VPShFpk!a* zYR_XQ>vE?9Cb#wAZoe+=|2O(LT=@!z3JLAYn4~BAEN? zyf=ORv9ie3g4C~pFKw|4M$Ie*IMD^yqH!vsP%)lDf8jT z=dVcGwK(nIB~G? zU`I%?JVBTbF`R(J?Sp0rUDt?xJym{$e5ghU&XSBy$`WCo^Y{%l$>rFCB`JJzF%l`* zlnFq}QYEOJ?Lbh(ZUN=Gz8iy%DKU>lVjX>gs(xJjVtaB>y<+OJMhh56~ zi)hxCmZ80w`RjkWwrAxIqhHeHREXeVb-$o2R`J`{#5goX(#Uxko_7ug{w`j8FO@|+ zI_E{R5U?qLQEkc~yC22Vx*M8yD@xAKf2r?hr1#d@df5x;nY9K9W^9V_+*Tk!!HINT z7a+4PHG{eFo2iPmEv{@ivdVjtZuy$%jd4nvB{2mZ3S;8jp;%!QrY~q>gxn&Hd-+na z^JV;qQ!aDww9g zr`T!y+d3?*hlMp3Xk?26dV~wyVzYcNa7%C@u?lCWj)MfBpm2P@xp3Md Date: Wed, 8 Aug 2018 16:22:51 -0300 Subject: [PATCH 6/9] Added texture_image_9patch.c example --- examples/textures/textures_image_9patch.c | 108 ++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 examples/textures/textures_image_9patch.c diff --git a/examples/textures/textures_image_9patch.c b/examples/textures/textures_image_9patch.c new file mode 100644 index 00000000..74eda6ad --- /dev/null +++ b/examples/textures/textures_image_9patch.c @@ -0,0 +1,108 @@ +/******************************************************************************************* +* +* raylib [textures] example - 9-patch drawing +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* This example has been created using raylib 2.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2016 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - 9-patch drawing"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Texture2D nPatchTexture = LoadTexture("resources/ninepatch_button.png"); + Vector2 mousePosition; + Vector2 origin = {0.0f, 0.0f}; + + // The location and size of the n-patches. + Rectangle dstRec1 = {480.0f, 160.0f, 32.0f, 32.0f}; + Rectangle dstRec2 = {160.0f, 160.0f, 32.0f, 32.0f}; + Rectangle dstRecH = {160.0f, 93.0f, 32.0f, 32.0f}; // this rec's height is ignored + Rectangle dstRecV = {92.0f, 160.0f, 32.0f, 32.0f}; // this rec's width is ignored + + // A 9-patch (NPT_9PATCH) changes its sizes in both axis + NPatchInfo ninePatchInfo1 = {(Rectangle){0.0f, 0.0f, 64.0f, 64.0f}, 12, 40, 12, 12, NPT_9PATCH }; + NPatchInfo ninePatchInfo2 = {(Rectangle){0.0f, 128.0f, 64.0f, 64.0f}, 16, 16, 16, 16, NPT_9PATCH }; + // A horizontal 3-patch (NPT_3PATCH_HORIZONTAL) changes its sizes along the x axis only + NPatchInfo h3PatchInfo = {(Rectangle){0.0f, 64.0f, 64.0f, 64.0f}, 8, 8, 8, 8, NPT_3PATCH_HORIZONTAL }; + // A vertical 3-patch (NPT_3PATCH_VERTICAL) changes its sizes along the y axis only + NPatchInfo v3PatchInfo = {(Rectangle){0.0f, 192.0f, 64.0f, 64.0f}, 6, 6, 6, 6, NPT_3PATCH_VERTICAL }; + + SetTargetFPS(60); + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + mousePosition = GetMousePosition(); + // resize the n-patches based on mouse position. + dstRec1.width = mousePosition.x - dstRec1.x; + dstRec1.height = mousePosition.y - dstRec1.y; + dstRec2.width = mousePosition.x - dstRec2.x; + dstRec2.height = mousePosition.y - dstRec2.y; + dstRecH.width = mousePosition.x - dstRecH.x; + dstRecV.height = mousePosition.y - dstRecV.y; + + // set a minimum width and/or height + if (dstRec1.width < 1.0f) dstRec1.width = 1.0f; + if (dstRec1.width > 300.0f) dstRec1.width = 300.0f; + if (dstRec1.height < 1.0f) dstRec1.height = 1.0f; + if (dstRec2.width < 1.0f) dstRec2.width = 1.0f; + if (dstRec2.width > 300.0f) dstRec2.width = 300.0f; + if (dstRec2.height < 1.0f) dstRec2.height = 1.0f; + if (dstRecH.width < 1.0f) dstRecH.width = 1.0f; + if (dstRecV.height < 1.0f) dstRecV.height = 1.0f; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw the n-patches + DrawTextureNPatch(nPatchTexture, ninePatchInfo2, dstRec2, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, ninePatchInfo1, dstRec1, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, h3PatchInfo, dstRecH, origin, 0.0f, WHITE); + DrawTextureNPatch(nPatchTexture, v3PatchInfo, dstRecV, origin, 0.0f, WHITE); + + // Draw the source texture + DrawRectangleLines( 5, 88, 74, 266, BLUE); + DrawTexture(nPatchTexture, 10, 93, WHITE); + DrawText("TEXTURE", 15, 360, 10, DARKGRAY); + + DrawRectangle( 10, 10, 250, 73, Fade(SKYBLUE, 0.5)); + DrawRectangleLines( 10, 10, 250, 73, BLUE); + + DrawText("9-Patch and 3-Patch example", 20, 20, 10, BLACK); + DrawText(" Move the mouse to stretch or", 40, 40, 10, DARKGRAY); + DrawText(" shrink the n-patches.", 40, 60, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(nPatchTexture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} From 921cacacfb057d0447896641e580611be107ca7e Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Wed, 8 Aug 2018 16:26:51 -0300 Subject: [PATCH 7/9] Added example screenshot. --- examples/textures/textures_image_9patch.png | Bin 0 -> 18306 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/textures/textures_image_9patch.png diff --git a/examples/textures/textures_image_9patch.png b/examples/textures/textures_image_9patch.png new file mode 100644 index 0000000000000000000000000000000000000000..5258811b42c76e7662a971a547b81c39f4e58a1b GIT binary patch literal 18306 zcmch<2{_d2|2JONtc8%hl9aXVyCO-pvJS#zUkcfGO_FSpWn^zd%wWjAj(sO&?1T`q z@B4EPI;Xzp{Jzig{IBQwpX)l;WX$Kj-}mdizwY-4xThjdModq9;=~Cug*&&@PMp9! zf8xZ+s#7@Noi``NlE4drk)r%9@CyFhk}dH8FGO~CbR15cAg{sxe=>@boZ-ZY^CuK; z-PCZ6pGyevIBQz|X^Vee$Ys8clu&L^RP0*M5@n&U2;qIalP-Og2)x_1ukU}Q&~`o> zz-e)-Z$l1Wfv^#$Z{wpSJ0oQF{i0eF?mP!oHl9 zg`Na2S6-m8hrFj0jHX|#V!IXHE1b%B;zS{=7nYZ|OHUIP2wxPV9V{_>wo zz05$XF?ER$E_bg9|sn1;dbgIm?D@zzzj zD|y~cdEPo|GKY|jeL)BAHj8|A4k)T!g|i;e9i+Xoi6K@{@zM_S)tbJy$jXQr6P>2R?EpHbkzhfn*lRF7ovlFOCYQyt{7RVTeJ z=nLY;_y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d294190cfdac5be6139 Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Wed, 8 Aug 2018 16:39:10 -0300 Subject: [PATCH 8/9] Update raylib.h --- src/raylib.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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) From dab78d59f34efcaae46966e35410687a13dd838e Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" Date: Wed, 8 Aug 2018 16:42:39 -0300 Subject: [PATCH 9/9] 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(-) 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 width = (float)texture.width; + float height = (float)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; + float patchWidth = (destRec.width <= 0.0f)? 0.0f : destRec.width; + float patchHeight = (destRec.height <= 0.0f)? 0.0f : destRec.height; - if (usePadding) - { - patchWidth += (float)(nPatch.padding[0] + nPatch.padding[2]); - patchHeight += (float)(nPatch.padding[1] + nPatch.padding[3]); - } - - 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; } + 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(); + } }