diff --git a/README.md b/README.md
index 8927ecc..6c9e652 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ CScreen is very simple to use, and can be implemented in nearly any type of game
local CScreen = require "cscreen"
function love.load()
- CScreen.init(800, 600, true)
+ CScreen.init(800, 600, true, "resources/lettertile.png")
end
function love.draw(dt)
@@ -31,11 +31,12 @@ end
Description |
- | init(tw, th, center) |
+ init(tw, th, center, image) |
tw (800) the target screen width
th (600) the target screen height
center (true) whether or not to letterbox
+ image (nil) whether or not to use a repeated tile as letterbox
|
Use tw and th to set the target width and height of the game screen. This defaults to 800 and 600, or a 4:3 screen ratio. Set center to true to center, or letterbox, the game screen (generally this should be true). Usually this is called in love.load().
@@ -66,7 +67,7 @@ end
none
|
- Actually draws the letterbox borders using love.graphics.rectangle(..) using the set color (see setColor()), then restores the previously set color. **This is called at the end of love.draw(dt), as drawing after this line will result in an incorrect ratio!
+ Actually draws the letterbox borders using love.graphics.rectangle(..) using the set color (see setColor()), if image is nil, then restores the previously set color. Otherwise, draws the letterbox borders as a repeated tile of the image. **This is called at the end of love.draw(dt), as drawing after this line will result in an incorrect ratio!
|
@@ -81,4 +82,13 @@ end
Sets the color to use for the screen letterbox borders (default is black).
-
\ No newline at end of file
+
+ | setImage(image) |
+
+ image new image
+ |
+
+ Replaces old image by a new one, if in letterbox mode.
+ |
+
+
diff --git a/cscreen.lua b/cscreen.lua
index fc43bce..c5681d7 100644
--- a/cscreen.lua
+++ b/cscreen.lua
@@ -32,28 +32,41 @@ local rx, ry, ctr = 800, 600, true
local rxv, ryv, fsv, fsvr = 800, 600, 1.0, 1.0
local tx, ty, rwf, rhf = 0, 0, 800, 600
local cr, cg, cb, ca = 0, 0, 0, 255
+local ltile = nil
-- Initializes CScreen with the initial size values
-function CScreen.init(tw, th, cntr)
+function CScreen.init(tw, th, cntr, image)
rx = tw or 800
ry = th or 600
ctr = cntr or false
- CScreen.update(love.graphics.getWidth(), love.graphics.getHeight())
+ if image and ctr then
+ ltile = love.graphics.newImage(image)
+ ltw, lth = ltile:getDimensions()
+ ltile:setWrap("repeat", "repeat")
+ end
+ CScreen.update(love.graphics.getWidth(), love.graphics.getHeight())
end
-- Draws letterbox borders
function CScreen.cease()
if ctr then
local pr, pg, pb, pa = love.graphics.getColor()
- love.graphics.setColor(cr, cg, cb, ca)
love.graphics.scale(fsvr, fsvr)
- if tx ~= 0 then
- love.graphics.rectangle("fill", -tx, 0, tx, rhf)
- love.graphics.rectangle("fill", rxv, 0, tx, rhf)
- elseif ty ~= 0 then
- love.graphics.rectangle("fill", 0, -ty, rwf, ty)
- love.graphics.rectangle("fill", 0, ryv, rwf, ty)
+ if not ltile then
+ love.graphics.setColor(cr, cg, cb, ca)
+ if tx ~= 0 then
+ love.graphics.rectangle("fill", -tx, 0, tx, rhf)
+ love.graphics.rectangle("fill", rxv, 0, tx, rhf)
+ elseif ty ~= 0 then
+ love.graphics.rectangle("fill", 0, -ty, rwf, ty)
+ love.graphics.rectangle("fill", 0, ryv, rwf, ty)
+ end
+ else
+ if tx ~= 0 or ty ~= 0 then
+ love.graphics.draw(ltile, rightbox, rbx, rby)
+ love.graphics.draw(ltile, leftbox, lbx, lby)
+ end
end
love.graphics.setColor(pr, pg, pb, pa)
@@ -87,6 +100,20 @@ function CScreen.update(w, h)
rhf = h
rxv = rx * fsv
ryv = ry * fsv
+ -- Updating quads
+ if ltile then
+ if tx ~= 0 then
+ rightbox = love.graphics.newQuad(0, 0, tx, rhf, ltw, lth)
+ rbx, rby = -tx, 0
+ leftbox = love.graphics.newQuad(0, 0, tx, rhf, ltw, lth)
+ lbx, lby = rxv, 0
+ elseif ty ~= 0 then
+ rightbox = love.graphics.newQuad(0, 0, rwf, ty, ltw, lth)
+ rbx, rby = 0, -ty
+ leftbox = love.graphics.newQuad(0, 0, rwf, ty, ltw, lth)
+ lbx, lby = 0, ryv
+ end
+ end
end
-- Convert from window coordinates to target coordinates
@@ -102,5 +129,14 @@ function CScreen.setColor(r, g, b, a)
ca = a
end
+function CScreen.setImage(image)
+ if image and ctr then
+ ltile = love.graphics.newImage(image)
+ ltw, lth = ltile:getDimensions()
+ ltile:setWrap("repeat", "repeat")
+ end
+ CScreen.update(love.graphics.getWidth(), love.graphics.getHeight())
+end
+
-- Return the table for use
return CScreen