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 8d1389f73..e2d5cc33f 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 3530e115e..fb31eeb84 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 e2d5cc33f..4aa6e299c 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 fb31eeb84..d610d03b7 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 zcmeAS@N?(olHy`uVBq!ia0y~yU~phyU}WH6V_;xlb}Il;Y)RhkE(~Ds(|LD20|NtR zfk$L90|Va?5N4dJ%_q&kAa>Z(#WAE}&fB?_B_dyEwcTDl=VMQO4FB^2zQ;Vq<#P)6 zgbSL-9G86B_ei!hE#PLkfx{uS)eCgQMOZ~yZ%*I9#-R|ckdx@G(CKNFo&NfbwBV-6 z4h}mj_W!)MYMobTc6geI|BC#8;)vR8JWLRp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AUs-1^cYU{c?{~2VK8XpFlcoM`n#RcN)65sZ&A};X#UQV2&RrjQ`at6{ zNA{KqZU=UrqTRlYVu#OXY!O=6=Gg4h2vW%>W|dG7H!pFCFwg%>K~JpM_|15%6mCQ_ zSS5JW?Nj`sXPoxnQ2xsg-PgO9$MrPu1#nB4pX>Ga=hM|N=-CqZZ|Tw#r984(5+w&L zrZ!w$ygA;gw5v^2Y!;LBv;PrY0f#pvF6(%A^|bea)B49B7k|02`EYla&%yX>Mm0M! zKM3Cc*CoGe*O`yE@5}u?{O+#(*RDRXd8>_?>myHh2rl!e`t18Kb9=jpeOdUQgQshM zFMGVxY7X~>du1XIYF_I;^xQs^&%IN9&xhvehMo3R)lW{mX)k~K>*dN0j$g?>JP$A3 zkouFVTjP|?`!bNh=B3r`hZ?`7*URtiUHPOGja9;D72q^17HA&_~$RY7iRx8JIIjP=iL^=(I58d||3|8l&2IA)}K_i+EXZV3{p z|9N5B3;~1FAYBi9K&~hOxx(ImtEw7{&o+?$yhR{O<{!H)B+S$VvgCh;zYhn;CXj=q zb3sP6PXrmYUp^1yu!I#LhfM(KdCzu3NSNu@%}HUbD^yBquZL+Ie$91Za)SAu&zUS5 w@hR6&YOnrw@uq|0=Qjlko)>IvWKaCD-(I^oSz)*41JGc%r>mdKI;Vst0Jxs}_y7O^ literal 0 HcmV?d00001 From 051cf1346b42ef2f22e5edf3d5bfef08ec113d4f Mon Sep 17 00:00:00 2001 From: "Jorge A. Gomes" 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 000000000..74eda6ad4 --- /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 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYU_8XZ#K6EXgVAa}0|NtFlDE4H0~q{t-d)eY zz`$AH5n0T@z;^_M8K-LVNi#4gFnGE+hE&XXJGZl1Bz514pT_UZ%HJL1VRyY_X=QNz zqtK3K3-&-3#`2p7SF^YsofvpUFuY8pQ#-@u=66?CPxg~cH@`2*lwwlk=A3xoqGj=~ ze_D56hOAn>diIs;FJE2xZTJ2#v+Jd=p}$uDyBA`0m)Q#BAO}t6Nwy$H!#}o0Rt5%! z1rki$3=9kohAd(X3=9oP96BJ`qXH2is!MSLh!Sy5U}Rum&}cgV@??Nd&jG0qhg4mr z-!NY;!@#hk@kZm;t-r*N)aipvL`?iW$352%yM1!5;CB&rt zDQLpOO%sl?&xo__dj9zF&VNtNFn883zZSjdEt7M+B*=YN7XEN=xu(50GbpEblK#bQ z5$TPt(f0Msoe(ax=2XVYc^`zadj4pXSXT)Eh@4BffW-gJQ zVENg>$NqH5@{jD(T-A0(f(#a!H0MCqwmJH}4veOsKr0NrnR<`eg z1kR)n_mz5{Z`S!I=`VNm^T%t>zAu>#|6VRp`6#n8TNNBKd-%farxd+9E8YtVyHbIO zzX43E&Eri#c3g2JGjK_arz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D{uQH#yUG>oVQ%SoQZaMnk_|o2MbsP5XFvOMPCKIV^0#O8 zF%@z05xY6pWM?UhzFX0=VNw5`sJh5}8`Ue^#@@-hH$GW(u)j+`Vs_w_gb&S=zedGA zZM~%RV$tE$gDdS)pSm%vw!b`|Df_}A*Tej>RXetsE!&iH3N`M37fX8E2~E-f`&yP8{J(Nv_Nk>8D` zg)es{B(Zdii89EN`g=RaW%YeK-<`Crd~~Oom3zN_?cLzrUm{MFfA;&na;N4SYl(i# zjkUjboPV(Tc-Gf_lVX!Ur220?IK3}qPsI+MH*5Z?H&2e4vrRkw&*yxfXYMV3C7gF# z%>U59%U<;3Ltn*s9e?12=Q3w8PeH`0QYk`Rvbc zv3=iuOp`x!`aIIAdnK#;lI&bOr+oO%J$z8Z=l@>4{JBp>?pNl`|7~)w8JGFVv^ylY zE?uwhyz;;o2i#*mpiOO9YfYV-FFBvPGDWxJoVi8p*R1_} z1^-lEpTbx7WJ=`c`LRD19V%Ae3EE7{z<~V>7aq{54CEaCLPw3y{xf^tHSXD~z2Fz< O6dF%gKbLh*2~7ZUb&&7? literal 0 HcmV?d00001 From 5f89e35d1cf6543594569d294190cfdac5be6139 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 4aa6e299c..af31e7794 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 d610d03b7..48bf69acd 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(); + } }