diff options
| author | jussi | 2023-12-19 02:02:26 +0200 |
|---|---|---|
| committer | jussi | 2023-12-19 02:02:26 +0200 |
| commit | 9884c544bb2e9870bbda9607685bd478c9f3fda0 (patch) | |
| tree | e77d4a39e7d5d9bbe38b5b08606d23639ea7f875 /examples | |
| parent | 917ce853fcfb212e2343b6b2dac816b14ee50e46 (diff) | |
| download | reilua-enhanced-9884c544bb2e9870bbda9607685bd478c9f3fda0.tar.gz reilua-enhanced-9884c544bb2e9870bbda9607685bd478c9f3fda0.tar.bz2 reilua-enhanced-9884c544bb2e9870bbda9607685bd478c9f3fda0.zip | |
DrawTextureNPatchRepeat.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/n-patches/main.lua | 40 | ||||
| -rw-r--r-- | examples/resources/images/LICENCE | 3 | ||||
| -rw-r--r-- | examples/resources/images/nPatch.png | bin | 0 -> 1131 bytes | |||
| -rw-r--r-- | examples/resources/lib/camera3d.lua | 6 |
4 files changed, 36 insertions, 13 deletions
diff --git a/examples/n-patches/main.lua b/examples/n-patches/main.lua index a4491bc..013a930 100644 --- a/examples/n-patches/main.lua +++ b/examples/n-patches/main.lua @@ -1,10 +1,19 @@ -local dstRec = { 160.0, 160.0, 8.0, 8.0 }; -local origin = { 0.0, 0.0 } +package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" --- local ninePatchInfo = { { 0.0, 0.0, 24.0, 24.0 }, 8, 8, 8, 8, NPATCH_NINE_PATCH } -local ninePatchInfo = { source = { 0, 0, 24.0, 24.0 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH } +Vec2 = require( "vector2" ) +Rect = require( "rectangle" ) -local nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) +local dstRec = Rect:new( 100.0, 100.0, 8.0, 8.0 ) +local origin = Vec2:new( 0.0, 0.0 ) +local stretched = true + +-- local ninePatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH } +-- local nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/ui_border.png" ) + +local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_NINE_PATCH } +-- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_VERTICAL } +-- local ninePatchInfo = { source = { 0, 0, 96, 96 }, left = 32, top = 32, right = 32, bottom = 32, layout = RL.NPATCH_THREE_PATCH_HORIZONTAL } +local nPatchTexture = RL.LoadTexture( RL.GetBasePath().."../resources/images/nPatch.png" ) function RL.init() RL.SetWindowTitle( "N-Patches" ) @@ -12,14 +21,27 @@ function RL.init() end function RL.process( delta ) - local mousePosition = RL.GetMousePosition(); + local mousePosition = Vec2:new( RL.GetMousePosition() ) -- Resize the n-patch based on mouse position - dstRec[3] = mousePosition[1] - dstRec[1]; - dstRec[4] = mousePosition[2] - dstRec[2]; + dstRec.width = mousePosition.x - dstRec.x; + dstRec.height = mousePosition.y - dstRec.y; + + if RL.IsKeyPressed( RL.KEY_SPACE ) then + stretched = not stretched + end end function RL.draw() RL.ClearBackground( RL.RAYWHITE ) - RL.DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, RL.WHITE ) + local modeText = "Stretched" + + if stretched then + RL.DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, RL.WHITE ) + else + RL.DrawTextureNPatchRepeat( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, RL.WHITE ) + modeText = "Repeat" + end + + RL.DrawText( "Press space to toggle mode: "..modeText, { 20, 20 }, 20, RL.BLACK ) end diff --git a/examples/resources/images/LICENCE b/examples/resources/images/LICENCE index 414d253..8666043 100644 --- a/examples/resources/images/LICENCE +++ b/examples/resources/images/LICENCE @@ -7,7 +7,8 @@ snake.png Jussi Viitala CC0 ui_border.png Jussi Viitala CC0 ui_bgr.png Jussi Viitala CC0 gradient.png Jussi Viitala CC0 -light.png Jussi Viitala CC0 +light.png Jussi Viitala CC0 +nPatch.png Jussi Viitala CC0 check-mark.png Delapouite Creative Commons 3.0 https://game-icons.net Resized circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized plain-circle.png Delapouite Creative Commons 3.0 https://game-icons.net Resized diff --git a/examples/resources/images/nPatch.png b/examples/resources/images/nPatch.png Binary files differnew file mode 100644 index 0000000..9a6eaa6 --- /dev/null +++ b/examples/resources/images/nPatch.png diff --git a/examples/resources/lib/camera3d.lua b/examples/resources/lib/camera3d.lua index cea6e8d..8d3c884 100644 --- a/examples/resources/lib/camera3d.lua +++ b/examples/resources/lib/camera3d.lua @@ -135,11 +135,11 @@ function Camera3D:process( delta ) elseif RL.IsKeyDown( self.KEYS.BACKWARD ) then RL.Camera3DMoveForward( self.camera, -distance, false ) end - + if RL.IsKeyDown( self.KEYS.RIGHT ) then - RL.Camera3DMoveRight( self.camera, distance, false ) + RL.Camera3DMoveRight( self.camera, distance, true ) elseif RL.IsKeyDown( self.KEYS.LEFT ) then - RL.Camera3DMoveRight( self.camera, -distance, false ) + RL.Camera3DMoveRight( self.camera, -distance, true ) end elseif self.mode == self.MODES.ORBITAL then RL.Camera3DYaw( self.camera, self.ORBITAL_SPEED * delta, true ) |
