From 4d71e9b44fd043472eb523207765fd882578a2e0 Mon Sep 17 00:00:00 2001 From: Vlad Adrian Date: Sun, 28 Jun 2020 00:59:14 +0300 Subject: [PATCH] Added new function `DrawTextureTiled()` (#1291) * Implemented DrawTextureTiled() * Example added --- examples/textures/resources/pat.png | Bin 0 -> 7387 bytes examples/textures/textures_draw_tiled.c | 148 ++++++++++++++++++++++++ src/raylib.h | 1 + src/textures.c | 74 ++++++++++++ 4 files changed, 223 insertions(+) create mode 100644 examples/textures/resources/pat.png create mode 100644 examples/textures/textures_draw_tiled.c diff --git a/examples/textures/resources/pat.png b/examples/textures/resources/pat.png new file mode 100644 index 0000000000000000000000000000000000000000..58b3c372c7dbfaf53bca771a9dc32e83d37dbd0d GIT binary patch literal 7387 zcmc(Di96I^^#6OtSjKK>L^NZ`*4VOTA6rPFkL+a|TlRgInJB~{G87?8Bx{njjJ+(O zvSl!~knEL_?K^sY-{<-M2fvwT-uJ%Gz2}_QeVu#mGKr?f`YepRi~sy z6$CKQQHxsvWv&1~1CO|A74)BDDAF&$*Y%E<3o`AQ`@<~VOo`WD}X2gTo;7Ww>3 z(ittUsm)kUt9QRS=+!GdL9z{rW4Mw7G`FJOvV7o4qI{Sdu@D#!eb{%Ittyr6$BnML z%xY>X58`}iY7u(B#b6qQFGu?-gh2nun7HH11&GAiP^;Upg^DMr=O%oE0qrDZ5gpRs zfFMOF&wRUvyrKL~jJV*CTAc94jIZ?4`->aNd5#?MuxZ#8ll0Ii3~;Ft80t@4PZ)B) zn=p8;Ub=cK1M@71qR7%A&8AVJbzWa8e`RU8acORs=5w{b?~6^f*T3Wk5Nemgza?ze zRz-f=2uwK$QgGo@&eu^l)^;q)J+d*ZX>gJ6tjwPBp&h&-#iBfhN#eFC(q`_;fCZP! z)8N(bd?jP%+kt@ryh}eHic!gW_=|`9WU&D^{qcjF90uW^{Gy(FH+V(j`3S0x;+&5; z-X6L!XYL#7*^97nV0YZpH}FE2DSuY1}Iue1(eEUU?ttRDAPsCD+3 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5A_Z0!vPo32ar3etlz$ffcSUHd z@j9BH;(-*D$=kVbohp0+{W0GEnJ3@>(7d*xM8-TXkCjK_W=~a0Pw}k}iqTHR79?R!cQ({1E z@kWaEX-lM{Vq;dO_e%?^f+674KZPhd_0TXi89z2cxn!vf&x0Vx3i)LdPe&H{EZX3` z?U+PwM-k9<>rGL{yij-mzrXqDv#$%gVM+uI=058st1vF?L{f;eq((Y-t@-FQTobA| z)a81q&tl1HQHGA)b74~#vLi?xcyIdq714{4!+dyYvrNnlEYOwRpc!}SKlIJH-K}oX z8it}E>sP2_oTcYWUzkOaryZ=no_VYR0>R4hjE_5XToglNwF!IYJ&(w;jU$f0q6 z@T2GElGU#SI*=+xevZjwp!>>Vq 10.0f) scale = 10.0f; + else if( scale <= 0.0f) scale = 0.25f; + + // Change rotation + if(IsKeyPressed(KEY_LEFT)) rotation -= 25.0f; + if(IsKeyPressed(KEY_RIGHT)) rotation += 25.0f; + + // Reset + if(IsKeyPressed(KEY_SPACE)) { rotation = 0.0f; scale = 1.0f; } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + ClearBackground(RAYWHITE); + + // Draw the tiled area + DrawTextureTiled(ptex, patRec[activePat], (Rectangle){OPT_WIDTH+MARGIN_SIZE, MARGIN_SIZE, screenWidth - OPT_WIDTH - 2*MARGIN_SIZE, screenHeight - 2*MARGIN_SIZE}, + (Vector2){0.0f, 0.0f}, rotation, scale, colors[activeCol]); + + // Draw options + DrawRectangle(MARGIN_SIZE, MARGIN_SIZE, OPT_WIDTH - MARGIN_SIZE, screenHeight-2*MARGIN_SIZE, ColorAlpha(LIGHTGRAY, 0.5f)); + + DrawText("Select Pattern", 2+MARGIN_SIZE, 30+MARGIN_SIZE, 10, BLACK); + DrawTexture(ptex, 2+MARGIN_SIZE, 40+MARGIN_SIZE, BLACK); + DrawRectangle(2+MARGIN_SIZE + patRec[activePat].x, 40+MARGIN_SIZE+patRec[activePat].y,patRec[activePat].width, patRec[activePat].height, ColorAlpha(DARKBLUE, 0.3f)); + + DrawText("Select Color", 2+MARGIN_SIZE, 10+256+MARGIN_SIZE, 10, BLACK); + for(int i=0; i