Modified setImage to handle parts of a larger image, implemented image_cache for faster loading
This commit is contained in:
parent
cdf8246933
commit
cf596551ba
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,5 @@ conf.lua
|
||||
*.ttf
|
||||
*.png
|
||||
*.ogv
|
||||
multi/*
|
||||
moonshine/*
|
||||
deck/*
|
||||
377
gui/init.lua
377
gui/init.lua
@ -9,7 +9,8 @@ local bit = require("bit")
|
||||
local band, bor = bit.band, bit.bor
|
||||
local cursor_hand = love.mouse.getSystemCursor("hand")
|
||||
local clips = {}
|
||||
local max, min, abs, rad, floor, ceil = math.max, math.min, math.abs, math.rad, math.floor,math.ceil
|
||||
local max, min, abs, rad, floor, ceil = math.max, math.min, math.abs, math.rad,
|
||||
math.floor, math.ceil
|
||||
local frame, image, text, box, video, button, anim = 0, 1, 2, 4, 8, 16, 32
|
||||
local global_drag
|
||||
local object_focus = gui
|
||||
@ -145,7 +146,8 @@ end)
|
||||
function gui:setHotKey(keys, conn)
|
||||
has_hotkey = true
|
||||
local conn = conn or multi:newConnection()
|
||||
table.insert(hot_keys, {Ref=self, Connection = conn, Keys = {unpack(keys)}})
|
||||
table.insert(hot_keys,
|
||||
{Ref = self, Connection = conn, Keys = {unpack(keys)}})
|
||||
return conn
|
||||
end
|
||||
|
||||
@ -153,37 +155,33 @@ end
|
||||
gui.HotKeys = {}
|
||||
|
||||
-- Connections can be added together to create an OR logic to them, they can be multiplied together to create an AND logic to them
|
||||
gui.HotKeys.OnSelectAll = gui:setHotKey({"lctrl","a"})
|
||||
+ gui:setHotKey({"rctrl","a"})
|
||||
gui.HotKeys.OnSelectAll = gui:setHotKey({"lctrl", "a"}) +
|
||||
gui:setHotKey({"rctrl", "a"})
|
||||
|
||||
gui.HotKeys.OnCopy = gui:setHotKey({"lctrl","c"})
|
||||
+ gui:setHotKey({"rctrl","c"})
|
||||
gui.HotKeys.OnCopy = gui:setHotKey({"lctrl", "c"}) +
|
||||
gui:setHotKey({"rctrl", "c"})
|
||||
|
||||
gui.HotKeys.OnPaste = gui:setHotKey({"lctrl","v"})
|
||||
+ gui:setHotKey({"rctrl","v"})
|
||||
gui.HotKeys.OnPaste = gui:setHotKey({"lctrl", "v"}) +
|
||||
gui:setHotKey({"rctrl", "v"})
|
||||
|
||||
gui.HotKeys.OnCut = gui:setHotKey({"lctrl","x"})
|
||||
+ gui:setHotKey({"rctrl","x"})
|
||||
gui.HotKeys.OnCut = gui:setHotKey({"lctrl", "x"}) +
|
||||
gui:setHotKey({"rctrl", "x"})
|
||||
|
||||
gui.HotKeys.OnUndo = gui:setHotKey({"lctrl","z"})
|
||||
+ gui:setHotKey({"rctrl","z"})
|
||||
gui.HotKeys.OnUndo = gui:setHotKey({"lctrl", "z"}) +
|
||||
gui:setHotKey({"rctrl", "z"})
|
||||
|
||||
gui.HotKeys.OnRedo = gui:setHotKey({"lctrl","y"})
|
||||
+ gui:setHotKey({"rctrl","y"})
|
||||
+ gui:setHotKey({"lctrl", "lshift", "z"})
|
||||
+ gui:setHotKey({"rctrl", "lshift", "z"})
|
||||
+ gui:setHotKey({"lctrl", "rshift", "z"})
|
||||
+ gui:setHotKey({"rctrl", "rshift", "z"})
|
||||
gui.HotKeys.OnRedo = gui:setHotKey({"lctrl", "y"}) +
|
||||
gui:setHotKey({"rctrl", "y"}) +
|
||||
gui:setHotKey({"lctrl", "lshift", "z"}) +
|
||||
gui:setHotKey({"rctrl", "lshift", "z"}) +
|
||||
gui:setHotKey({"lctrl", "rshift", "z"}) +
|
||||
gui:setHotKey({"rctrl", "rshift", "z"})
|
||||
|
||||
-- Utils
|
||||
|
||||
function gui:getObjectFocus()
|
||||
return object_focus
|
||||
end
|
||||
function gui:getObjectFocus() return object_focus end
|
||||
|
||||
function gui:hasType(t)
|
||||
return band(self.type, t) == t
|
||||
end
|
||||
function gui:hasType(t) return band(self.type, t) == t end
|
||||
|
||||
function gui:move(x, y)
|
||||
self.dualDim.offset.pos.x = self.dualDim.offset.pos.x + x
|
||||
@ -193,7 +191,8 @@ end
|
||||
function gui:moveInBounds(dx, dy)
|
||||
local x, y, w, h = self:getAbsolutes()
|
||||
local x1, y1, w1, h1 = self.parent:getAbsolutes()
|
||||
if (x + dx >= x1 or dx > 0) and (x + w + dx <= x1 + w1 or dx < 0) and (y + dy >= y1 or dy > 0) and (y + h + dy <= y1 + h1 or dy < 0) then
|
||||
if (x + dx >= x1 or dx > 0) and (x + w + dx <= x1 + w1 or dx < 0) and
|
||||
(y + dy >= y1 or dy > 0) and (y + h + dy <= y1 + h1 or dy < 0) then
|
||||
self:move(dx, dy)
|
||||
end
|
||||
end
|
||||
@ -218,9 +217,7 @@ local function intersecpt(x1,y1,x2,y2,x3,y3,x4,y4)
|
||||
return x7, y7, abs(x7 - x8), abs(y7 - y8)
|
||||
end
|
||||
|
||||
local function toCoordPoints(x, y, w, h)
|
||||
return x,y,x+w,y+h
|
||||
end
|
||||
local function toCoordPoints(x, y, w, h) return x, y, x + w, y + h end
|
||||
|
||||
function gui:intersecpt(x, y, w, h)
|
||||
local x1, y1, x2, y2 = toCoordPoints(self:getAbsolutes())
|
||||
@ -232,23 +229,22 @@ end
|
||||
function gui:isDescendantOf(obj)
|
||||
local parent = self.parent
|
||||
while parent ~= gui do
|
||||
if parent==obj then
|
||||
return true
|
||||
end
|
||||
if parent == obj then return true end
|
||||
parent = parent.parent
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function gui:getChildren()
|
||||
return self.children
|
||||
end
|
||||
function gui:getChildren() return self.children end
|
||||
|
||||
function gui:getAbsolutes() -- returns x, y, w, h
|
||||
return (self.parent.w*self.dualDim.scale.pos.x)+self.dualDim.offset.pos.x+self.parent.x,
|
||||
(self.parent.h*self.dualDim.scale.pos.y)+self.dualDim.offset.pos.y+self.parent.y,
|
||||
(self.parent.w*self.dualDim.scale.size.x)+self.dualDim.offset.size.x,
|
||||
(self.parent.h*self.dualDim.scale.size.y)+self.dualDim.offset.size.y
|
||||
return (self.parent.w * self.dualDim.scale.pos.x) +
|
||||
self.dualDim.offset.pos.x + self.parent.x,
|
||||
(self.parent.h * self.dualDim.scale.pos.y) +
|
||||
self.dualDim.offset.pos.y + self.parent.y, (self.parent.w *
|
||||
self.dualDim.scale.size.x) + self.dualDim.offset.size.x,
|
||||
(self.parent.h * self.dualDim.scale.size.y) +
|
||||
self.dualDim.offset.size.y
|
||||
end
|
||||
|
||||
function gui:getAllChildren(vis)
|
||||
@ -267,38 +263,49 @@ function gui:getAllChildren(vis)
|
||||
end
|
||||
|
||||
function gui:newThread(func)
|
||||
return updater:newThread("ThreadHandler<"..self.type..">", func, self, thread)
|
||||
return updater:newThread("ThreadHandler<" .. self.type .. ">", func, self,
|
||||
thread)
|
||||
end
|
||||
|
||||
function gui:setDualDim(x, y, w, h, sx, sy, sw, sh)
|
||||
self.dualDim.offset = {
|
||||
pos={x=x or self.dualDim.offset.pos.x,y=y or self.dualDim.offset.pos.y},
|
||||
size={x=w or self.dualDim.offset.size.x,y=h or self.dualDim.offset.size.y}
|
||||
pos = {
|
||||
x = x or self.dualDim.offset.pos.x,
|
||||
y = y or self.dualDim.offset.pos.y
|
||||
},
|
||||
size = {
|
||||
x = w or self.dualDim.offset.size.x,
|
||||
y = h or self.dualDim.offset.size.y
|
||||
}
|
||||
}
|
||||
self.dualDim.scale = {
|
||||
pos={x=sx or self.dualDim.scale.pos.x,y=sy or self.dualDim.scale.pos.y},
|
||||
size={x=sw or self.dualDim.scale.size.x,y=sh or self.dualDim.scale.size.y}
|
||||
pos = {
|
||||
x = sx or self.dualDim.scale.pos.x,
|
||||
y = sy or self.dualDim.scale.pos.y
|
||||
},
|
||||
size = {
|
||||
x = sw or self.dualDim.scale.size.x,
|
||||
y = sh or self.dualDim.scale.size.y
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
local image_cache = {}
|
||||
function gui:getTile(i, x, y, w, h) -- returns imagedata
|
||||
local tw, wh
|
||||
if i == nil then return end
|
||||
if type(i) == "string" then i = image_cache[i] or i end
|
||||
if type(i) == "string" then
|
||||
i=love.graphics.newImage(i)
|
||||
i = love.image.newImageData(i)
|
||||
image_cache[i] = i
|
||||
elseif type(i) == "userdata" then
|
||||
-- do nothing
|
||||
elseif string.find(self.Type,"Image",1,true) then
|
||||
local i,x,y,w,h=self.Image,i,x,y,w
|
||||
elseif self:hasType(image) then
|
||||
i, x, y, w, h = self.image, i, x, y, w
|
||||
else
|
||||
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||
end
|
||||
local iw,ih=i:getDimensions()
|
||||
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||
for _x=x,w+x-1 do
|
||||
for _y=y,h+y-1 do
|
||||
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||
end
|
||||
end
|
||||
return love.graphics.newImage(_id)
|
||||
return i, love.graphics.newQuad(x, y, w, h, i:getWidth(), i:getHeight())
|
||||
end
|
||||
|
||||
function gui:topStack()
|
||||
@ -331,7 +338,8 @@ function gui:isBeingCovered(mx,my)
|
||||
for i = #children, 1, -1 do
|
||||
if children[i] == self then
|
||||
return false
|
||||
elseif children[i]:canPress(mx,my) and not(children[i] == self) and not(children[i].ignore) then
|
||||
elseif children[i]:canPress(mx, my) and not (children[i] == self) and
|
||||
not (children[i].ignore) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -357,9 +365,7 @@ function gui:setParent(parent)
|
||||
end
|
||||
end
|
||||
|
||||
local function processDo(ref)
|
||||
ref.Do[1]()
|
||||
end
|
||||
local function processDo(ref) ref.Do[1]() end
|
||||
|
||||
function gui:clone(opt)
|
||||
--[[
|
||||
@ -388,9 +394,7 @@ function gui:clone(opt)
|
||||
temp = processDo(u)
|
||||
end
|
||||
|
||||
for i, v in pairs(u) do
|
||||
temp[i] = v
|
||||
end
|
||||
for i, v in pairs(u) do temp[i] = v end
|
||||
|
||||
local conn
|
||||
if opt then
|
||||
@ -430,14 +434,10 @@ function gui:getUniques(tab)
|
||||
visibility = self.visibility,
|
||||
color = self.color,
|
||||
borderColor = self.borderColor,
|
||||
rotation = self.rotation,
|
||||
rotation = self.rotation
|
||||
}
|
||||
|
||||
if tab then
|
||||
for i, v in pairs(tab) do
|
||||
base[i] = tab[i]
|
||||
end
|
||||
end
|
||||
if tab then for i, v in pairs(tab) do base[i] = tab[i] end end
|
||||
return base
|
||||
end
|
||||
|
||||
@ -460,9 +460,7 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh, virtual)
|
||||
end
|
||||
|
||||
setmetatable(c, gui)
|
||||
c.__variables = {
|
||||
clip = {false,0,0,0,0}
|
||||
}
|
||||
c.__variables = {clip = {false, 0, 0, 0, 0}}
|
||||
c.active = true
|
||||
c.type = typ
|
||||
c.dualDim = self:newDualDim(x, y, w, h, sx, sy, sw, sh)
|
||||
@ -539,7 +537,8 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh, virtual)
|
||||
object_focus = c
|
||||
end
|
||||
|
||||
if draggable and button == dragbutton and not c:isBeingCovered(x, y) and not global_drag then
|
||||
if draggable and button == dragbutton and not c:isBeingCovered(x, y) and
|
||||
not global_drag then
|
||||
dragging = true
|
||||
global_drag = true
|
||||
c.OnDragStart:Fire(c, dx, dy, x, y, istouch)
|
||||
@ -559,15 +558,11 @@ function gui:newBase(typ,x, y, w, h, sx, sy, sw, sh, virtual)
|
||||
self.__rvert = vert
|
||||
end
|
||||
|
||||
function c:respectHierarchy(bool)
|
||||
hierarchy = bool
|
||||
end
|
||||
function c:respectHierarchy(bool) hierarchy = bool end
|
||||
|
||||
function c:OnUpdate(func) -- Not crazy about this approach, will probably rework this
|
||||
if type(self) == "function" then func = self end
|
||||
mainupdater(function()
|
||||
func(c)
|
||||
end)
|
||||
mainupdater(function() func(c) end)
|
||||
end
|
||||
|
||||
local function centerthread()
|
||||
@ -626,28 +621,17 @@ function gui:newDualDim(x, y, w, h, sx, sy, sw, sh)
|
||||
local dd = {}
|
||||
dd.offset = {}
|
||||
dd.scale = {}
|
||||
dd.offset.pos = {
|
||||
x = x or 0,
|
||||
y = y or 0
|
||||
}
|
||||
dd.offset.size = {
|
||||
x = w or 0,
|
||||
y = h or 0
|
||||
}
|
||||
dd.scale.pos = {
|
||||
x = sx or 0,
|
||||
y = sy or 0
|
||||
}
|
||||
dd.scale.size = {
|
||||
x = sw or 0,
|
||||
y = sh or 0
|
||||
}
|
||||
dd.offset.pos = {x = x or 0, y = y or 0}
|
||||
dd.offset.size = {x = w or 0, y = h or 0}
|
||||
dd.scale.pos = {x = sx or 0, y = sy or 0}
|
||||
dd.scale.size = {x = sw or 0, y = sh or 0}
|
||||
return dd
|
||||
end
|
||||
|
||||
function gui:getDualDim()
|
||||
local dd = self.dualDim
|
||||
return dd.offset.pos.x, dd.offset.pos.y, dd.offset.size.x, dd.offset.size.y, dd.scale.pos.x, dd.scale.pos.y, dd.scale.size.x, dd.scale.size.y
|
||||
return dd.offset.pos.x, dd.offset.pos.y, dd.offset.size.x, dd.offset.size.y,
|
||||
dd.scale.pos.x, dd.scale.pos.y, dd.scale.size.x, dd.scale.size.y
|
||||
end
|
||||
|
||||
-- Frames
|
||||
@ -686,7 +670,10 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
||||
love.graphics.clear(0, 0, 0, .5, false, false)
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.setFont(font)
|
||||
love.graphics.printf(self.text, 0, adjust/2, width, "left", self.rotation, self.textScaleX, self.textScaleY, 0, 0, self.textShearingFactorX, self.textShearingFactorY)
|
||||
love.graphics.printf(self.text, 0, adjust / 2, width, "left",
|
||||
self.rotation, self.textScaleX, self.textScaleY, 0,
|
||||
0, self.textShearingFactorX,
|
||||
self.textShearingFactorY)
|
||||
love.graphics.setCanvas()
|
||||
local data = canvas:newImageData()
|
||||
local f_top, f_bot = false, false
|
||||
@ -694,7 +681,11 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
||||
for xx = 0, width - 1 do
|
||||
local r, g, b, a = data:getPixel(xx, yy)
|
||||
if r ~= 0 or g ~= 0 or b ~= 0 then
|
||||
if yy<top and not f_top then top = yy f_top = true break end
|
||||
if yy < top and not f_top then
|
||||
top = yy
|
||||
f_top = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -702,7 +693,11 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
||||
for xx = 0, width - 1 do
|
||||
local r, g, b, a = data:getPixel(xx, yy)
|
||||
if r ~= 0 or g ~= 0 or b ~= 0 then
|
||||
if yy>bottom and not f_bot then bottom = yy f_bot = false break end
|
||||
if yy > bottom and not f_bot then
|
||||
bottom = yy
|
||||
f_bot = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -735,15 +730,14 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
||||
end
|
||||
else
|
||||
isdefault = true
|
||||
font = function(n)
|
||||
return love.graphics.setNewFont(n)
|
||||
end
|
||||
font = function(n) return love.graphics.setNewFont(n) end
|
||||
end
|
||||
local x, y, width, height = self:getAbsolutes()
|
||||
local Font, text = self.Font, self.text
|
||||
local s = 3
|
||||
Font = font(s)
|
||||
while height < max and Font:getHeight()<height and Font:getWidth(text)<width do
|
||||
while height < max and Font:getHeight() < height and Font:getWidth(text) <
|
||||
width do
|
||||
s = s + 1
|
||||
Font = font(s)
|
||||
end
|
||||
@ -770,7 +764,7 @@ function gui:newTextBase(typ, txt, x, y, w, h, sx, sy, sw, sh)
|
||||
textShearingFactorY = c.textShearingFactorY,
|
||||
textVisibility = c.textVisibility,
|
||||
font = c.font,
|
||||
textColor = c.textColor,
|
||||
textColor = c.textColor
|
||||
})
|
||||
end
|
||||
return c
|
||||
@ -784,9 +778,7 @@ function gui:newTextButton(txt, x, y, w, h, sx, sy, sw, sh)
|
||||
love.mouse.setCursor(cursor_hand)
|
||||
end)
|
||||
|
||||
c.OnExit(function(c, x, y, dx, dy, istouch)
|
||||
love.mouse.setCursor()
|
||||
end)
|
||||
c.OnExit(function(c, x, y, dx, dy, istouch) love.mouse.setCursor() end)
|
||||
|
||||
return c
|
||||
end
|
||||
@ -807,12 +799,16 @@ local function getTextPosition(text, self, mx, my, exact)
|
||||
for i = 1, #text do
|
||||
|
||||
local _w = font:getWidth(text:sub(i, i))
|
||||
local x, y, w, h = math.floor(width + self.adjust + self.textOffsetX), 0, _w, height
|
||||
local x, y, w, h = math.floor(width + self.adjust + self.textOffsetX),
|
||||
0, _w, height
|
||||
|
||||
width = width + _w
|
||||
|
||||
if not (mx > x + w or mx < x or my > y + h or my < y) then
|
||||
if not(exact) and (_w - (width - (mx - math.floor(self.adjust + self.textOffsetX))) < _w/2 and i >= 1) then
|
||||
if not (exact) and
|
||||
(_w -
|
||||
(width - (mx - math.floor(self.adjust + self.textOffsetX))) <
|
||||
_w / 2 and i >= 1) then
|
||||
return i - 1
|
||||
else
|
||||
return i
|
||||
@ -839,7 +835,7 @@ function gui:newTextBox(txt, x, y, w, h, sx, sy, sw, sh)
|
||||
return gui.getUniques(c, {
|
||||
doSelection = c.doSelection,
|
||||
cur_pos = c.cur_pos,
|
||||
adjust = c.adjust,
|
||||
adjust = c.adjust
|
||||
})
|
||||
end
|
||||
|
||||
@ -849,9 +845,7 @@ function gui:newTextBox(txt, x, y, w, h, sx, sy, sw, sh)
|
||||
|
||||
function c:GetSelection()
|
||||
local start, stop = c.selection[1], c.selection[2]
|
||||
if start > stop then
|
||||
start, stop = stop, start
|
||||
end
|
||||
if start > stop then start, stop = stop, start end
|
||||
return start, stop
|
||||
end
|
||||
|
||||
@ -871,9 +865,7 @@ function gui:newTextBox(txt, x, y, w, h, sx, sy, sw, sh)
|
||||
love.mouse.setCursor(love.mouse.getSystemCursor("ibeam"))
|
||||
end)
|
||||
|
||||
c.OnExit(function(c, x, y, dx, dy, istouch)
|
||||
love.mouse.setCursor(cur)
|
||||
end)
|
||||
c.OnExit(function(c, x, y, dx, dy, istouch) love.mouse.setCursor(cur) end)
|
||||
|
||||
c.OnPressed(function(c, x, y, dx, dy, istouch)
|
||||
object_focus.bar_show = true
|
||||
@ -900,9 +892,7 @@ function gui:newTextBox(txt, x, y, w, h, sx, sy, sw, sh)
|
||||
c.selection = {0, 0}
|
||||
end)
|
||||
|
||||
c.OnPressedOuter(function()
|
||||
c.bar_show = false
|
||||
end)
|
||||
c.OnPressedOuter(function() c.bar_show = false end)
|
||||
|
||||
return c
|
||||
end
|
||||
@ -922,18 +912,16 @@ end)
|
||||
local function insert(obj, n_text)
|
||||
if obj:HasSelection() then
|
||||
local start, stop = obj:GetSelection()
|
||||
obj.text = obj.text:sub(1, start - 1) .. n_text .. obj.text:sub(stop + 1, -1)
|
||||
obj.text = obj.text:sub(1, start - 1) .. n_text ..
|
||||
obj.text:sub(stop + 1, -1)
|
||||
obj:ClearSelection()
|
||||
obj.cur_pos = start
|
||||
if #n_text > 1 then
|
||||
obj.cur_pos = start + #n_text
|
||||
end
|
||||
if #n_text > 1 then obj.cur_pos = start + #n_text end
|
||||
else
|
||||
obj.text = obj.text:sub(1, obj.cur_pos) .. n_text .. obj.text:sub(obj.cur_pos + 1,-1)
|
||||
obj.text = obj.text:sub(1, obj.cur_pos) .. n_text ..
|
||||
obj.text:sub(obj.cur_pos + 1, -1)
|
||||
obj.cur_pos = obj.cur_pos + 1
|
||||
if #n_text > 1 then
|
||||
obj.cur_pos = obj.cur_pos + #n_text
|
||||
end
|
||||
if #n_text > 1 then obj.cur_pos = obj.cur_pos + #n_text end
|
||||
end
|
||||
end
|
||||
|
||||
@ -945,11 +933,15 @@ local function delete(obj, cmd)
|
||||
obj.cur_pos = start - 1
|
||||
else
|
||||
if cmd == "delete" then
|
||||
obj.text = obj.text:sub(1, obj.cur_pos) .. obj.text:sub(obj.cur_pos + 2, -1)
|
||||
obj.text = obj.text:sub(1, obj.cur_pos) ..
|
||||
obj.text:sub(obj.cur_pos + 2, -1)
|
||||
else
|
||||
obj.text = obj.text:sub(1, obj.cur_pos - 1) .. obj.text:sub(obj.cur_pos + 1, -1)
|
||||
obj.text = obj.text:sub(1, obj.cur_pos - 1) ..
|
||||
obj.text:sub(obj.cur_pos + 1, -1)
|
||||
object_focus.cur_pos = object_focus.cur_pos - 1
|
||||
if object_focus.cur_pos == 0 then object_focus.cur_pos = 1 end
|
||||
if object_focus.cur_pos == 0 then
|
||||
object_focus.cur_pos = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -965,9 +957,7 @@ gui.HotKeys.OnSelectAll(function()
|
||||
end)
|
||||
|
||||
gui.Events.OnTextInputed(function(text)
|
||||
if object_focus:hasType(box) then
|
||||
insert(object_focus, text)
|
||||
end
|
||||
if object_focus:hasType(box) then insert(object_focus, text) end
|
||||
end)
|
||||
|
||||
gui.HotKeys.OnCopy(function()
|
||||
@ -1019,9 +1009,25 @@ function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
DO = {[[setImage]], c.image or IMAGE}
|
||||
})
|
||||
end
|
||||
function c:setImage(i)
|
||||
function c:setImage(i, x, y, w, h)
|
||||
if i == nil then return end
|
||||
IMAGE = i
|
||||
if type(i) == "string" then i = image_cache[i] or i end
|
||||
if i and x then
|
||||
self.imageHeigth = h
|
||||
self.imageWidth = w
|
||||
if type(i) == "string" then
|
||||
image_cache[i] = love.graphics.newImage(i)
|
||||
i = image_cache[i]
|
||||
end
|
||||
self.image = i
|
||||
self.image:setWrap("repeat","repeat")
|
||||
self.imageColor = color.white
|
||||
self.quad = love.graphics.newQuad(x, y, w, h, self.image:getWidth(), self.image:getHeight())
|
||||
self.imageVisibility = 1
|
||||
return
|
||||
end
|
||||
|
||||
if not first_loop then
|
||||
-- Wait one cycle for things to load up
|
||||
drawer:newThread(function()
|
||||
@ -1033,6 +1039,7 @@ function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
img = love.graphics.newImage(i)
|
||||
else
|
||||
img = love.graphics.newImage(i)
|
||||
image_cache[i] = love.image.newImageData(i)
|
||||
end
|
||||
local x, y, w, h = self:getAbsolutes()
|
||||
self.imageColor = color.white
|
||||
@ -1040,7 +1047,8 @@ function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
self.image = img
|
||||
self.imageHeigth = img:getHeight()
|
||||
self.imageWidth = img:getWidth()
|
||||
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
||||
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth,
|
||||
self.imageHeigth)
|
||||
end)
|
||||
return
|
||||
end
|
||||
@ -1056,7 +1064,8 @@ function gui:newImageBase(typ,x, y, w, h, sx, sy, sw, sh)
|
||||
self.image = img
|
||||
self.imageHeigth = img:getHeight()
|
||||
self.imageWidth = img:getWidth()
|
||||
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth, self.imageHeigth)
|
||||
self.quad = love.graphics.newQuad(0, 0, w, h, self.imageWidth,
|
||||
self.imageHeigth)
|
||||
end
|
||||
return c
|
||||
end
|
||||
@ -1076,9 +1085,7 @@ function gui:newImageButton(source, x, y, w, h, sx, sy, sw, sh)
|
||||
love.mouse.setCursor(cursor_hand)
|
||||
end)
|
||||
|
||||
c.OnExit(function(c, x, y, dx, dy, istouch)
|
||||
love.mouse.setCursor()
|
||||
end)
|
||||
c.OnExit(function(c, x, y, dx, dy, istouch) love.mouse.setCursor() end)
|
||||
|
||||
return c
|
||||
end
|
||||
@ -1096,21 +1103,15 @@ function gui:newVideo(source, x, y, w, h, sx, sy, sw, sh)
|
||||
c.video = v
|
||||
end
|
||||
c.audiosource = c.video:getSource()
|
||||
if c.audiosource then
|
||||
c.audioLength = c.audiosource:getDuration()
|
||||
end
|
||||
if c.audiosource then c.audioLength = c.audiosource:getDuration() end
|
||||
c.videoHeigth = c.video:getHeight()
|
||||
c.videoWidth = c.video:getWidth()
|
||||
c.quad = love.graphics.newQuad(0, 0, w, h, c.videoWidth, c.videoHeigth)
|
||||
end
|
||||
|
||||
function c:getVideo()
|
||||
return self.video
|
||||
end
|
||||
function c:getVideo() return self.video end
|
||||
|
||||
if type(source)=="string" then
|
||||
c:setVideo(source)
|
||||
end
|
||||
if type(source) == "string" then c:setVideo(source) end
|
||||
|
||||
function c:play()
|
||||
c.playing = true
|
||||
@ -1118,14 +1119,10 @@ function gui:newVideo(source, x, y, w, h, sx, sy, sw, sh)
|
||||
end
|
||||
|
||||
function c:setVolume(vol)
|
||||
if self.audiosource then
|
||||
self.audiosource:setVolume(vol)
|
||||
end
|
||||
if self.audiosource then self.audiosource:setVolume(vol) end
|
||||
end
|
||||
|
||||
function c:pause()
|
||||
c.video:pause()
|
||||
end
|
||||
function c:pause() c.video:pause() end
|
||||
|
||||
function c:stop()
|
||||
c.playing = false
|
||||
@ -1133,17 +1130,11 @@ function gui:newVideo(source, x, y, w, h, sx, sy, sw, sh)
|
||||
c.video:rewind()
|
||||
end
|
||||
|
||||
function c:rewind()
|
||||
c.video:rewind()
|
||||
end
|
||||
function c:rewind() c.video:rewind() end
|
||||
|
||||
function c:seek(n)
|
||||
c.video:seek(n)
|
||||
end
|
||||
function c:seek(n) c.video:seek(n) end
|
||||
|
||||
function c:tell()
|
||||
return c.video:tell()
|
||||
end
|
||||
function c:tell() return c.video:tell() end
|
||||
|
||||
c:newThread(function(self)
|
||||
|
||||
@ -1158,9 +1149,7 @@ function gui:newVideo(source, x, y, w, h, sx, sy, sw, sh)
|
||||
return self.video:isPlaying()
|
||||
end
|
||||
|
||||
while true do
|
||||
thread.chain(isplaying, testCompletion)
|
||||
end
|
||||
while true do thread.chain(isplaying, testCompletion) end
|
||||
|
||||
end)
|
||||
|
||||
@ -1177,16 +1166,14 @@ local drawtypes = {
|
||||
[0] = function(child, x, y, w, h) end,
|
||||
[1] = function(child, x, y, w, h)
|
||||
if child.image then
|
||||
love.graphics.setColor(child.imageColor[1],child.imageColor[2],child.imageColor[3],child.imageVisibility)
|
||||
if w~=child.imageWidth and h~=child.imageHeigth then
|
||||
love.graphics.draw(child.image,x,y,rad(child.rotation),w/child.imageWidth,h/child.imageHeigth)
|
||||
else
|
||||
love.graphics.setColor(child.imageColor[1], child.imageColor[2],
|
||||
child.imageColor[3], child.imageVisibility)
|
||||
love.graphics.draw(child.image, child.quad, x, y, rad(child.rotation), w / child.imageWidth, h / child.imageHeigth)
|
||||
end
|
||||
end
|
||||
end,
|
||||
[2] = function(child, x, y, w, h)
|
||||
love.graphics.setColor(child.textColor[1],child.textColor[2],child.textColor[3],child.textVisibility)
|
||||
love.graphics.setColor(child.textColor[1], child.textColor[2],
|
||||
child.textColor[3], child.textVisibility)
|
||||
love.graphics.setFont(child.font)
|
||||
if child.align == gui.ALIGN_LEFT then
|
||||
child.adjust = 0
|
||||
@ -1197,40 +1184,49 @@ local drawtypes = {
|
||||
local fw = child.font:getWidth(child.text)
|
||||
child.adjust = w - fw - 4
|
||||
end
|
||||
love.graphics.printf(child.text, child.adjust + x + child.textOffsetX, y + child.textOffsetY, w, "left", child.rotation, child.textScaleX, child.textScaleY, 0, 0, child.textShearingFactorX, child.textShearingFactorY)
|
||||
love.graphics.printf(child.text, child.adjust + x + child.textOffsetX,
|
||||
y + child.textOffsetY, w, "left", child.rotation,
|
||||
child.textScaleX, child.textScaleY, 0, 0,
|
||||
child.textShearingFactorX,
|
||||
child.textShearingFactorY)
|
||||
end,
|
||||
[4] = function(child, x, y, w, h)
|
||||
if child.bar_show then
|
||||
local font = child.font
|
||||
local fh = font:getHeight()
|
||||
local fw = font:getWidth(child.text:sub(1, child.cur_pos))
|
||||
love.graphics.line(child.textOffsetX + child.adjust + x + fw, y + 4, child.textOffsetX + child.adjust + x + fw, y + fh - 2)
|
||||
love.graphics.line(child.textOffsetX + child.adjust + x + fw, y + 4,
|
||||
child.textOffsetX + child.adjust + x + fw,
|
||||
y + fh - 2)
|
||||
end
|
||||
if child:HasSelection() then
|
||||
local blue = color.highlighter_blue
|
||||
local start, stop = child.selection[1], child.selection[2]
|
||||
if start > stop then
|
||||
start, stop = stop, start
|
||||
end
|
||||
if start > stop then start, stop = stop, start end
|
||||
local x1, y1 = child.font:getWidth(child.text:sub(1, start - 1)), 0
|
||||
local x2, y2 = child.font:getWidth(child.text:sub(1, stop)), h
|
||||
love.graphics.setColor(blue[1], blue[2], blue[3], .5)
|
||||
love.graphics.rectangle("fill", x + x1 + child.adjust, y + y1, x2 - x1, y2 - y1)
|
||||
love.graphics.rectangle("fill", x + x1 + child.adjust, y + y1,
|
||||
x2 - x1, y2 - y1)
|
||||
end
|
||||
end,
|
||||
[8] = function(child, x, y, w, h)
|
||||
if child.video and child.playing then
|
||||
love.graphics.setColor(child.videoColor[1],child.videoColor[2],child.videoColor[3],child.videoVisibility)
|
||||
love.graphics.setColor(child.videoColor[1], child.videoColor[2],
|
||||
child.videoColor[3], child.videoVisibility)
|
||||
if w ~= child.imageWidth and h ~= child.imageHeigth then
|
||||
love.graphics.draw(child.video,x,y,rad(child.rotation),w/child.videoWidth,h/child.videoHeigth)
|
||||
love.graphics.draw(child.video, x, y, rad(child.rotation),
|
||||
w / child.videoWidth, h / child.videoHeigth)
|
||||
else
|
||||
love.graphics.draw(child.video,child.quad,x,y,rad(child.rotation),w/child.videoWidth,h/child.videoHeigth)
|
||||
love.graphics.draw(child.video, child.quad, x, y,
|
||||
rad(child.rotation), w / child.videoWidth,
|
||||
h / child.videoHeigth)
|
||||
end
|
||||
end
|
||||
end,
|
||||
[16] = function(child, x, y, w, h)
|
||||
--
|
||||
end,
|
||||
end
|
||||
}
|
||||
|
||||
local draw_handler = function(child)
|
||||
@ -1240,7 +1236,8 @@ local draw_handler = function(child)
|
||||
local vis = child.visibility
|
||||
local x, y, w, h = child:getAbsolutes()
|
||||
local roundness = child.roundness
|
||||
local rx, ry, segments = child.__rx or 0, child.__ry or 0, child.__segments or 0
|
||||
local rx, ry, segments = child.__rx or 0, child.__ry or 0,
|
||||
child.__segments or 0
|
||||
child.x = x
|
||||
child.y = y
|
||||
child.w = w
|
||||
@ -1262,7 +1259,7 @@ local draw_handler = function(child)
|
||||
local clip = child.__variables.clip
|
||||
love.graphics.setScissor(clip[2], clip[3], clip[4], clip[5])
|
||||
elseif type(roundness) == "string" then
|
||||
love.graphics.setScissor(x - 1, y, w + 2, h + 3)
|
||||
love.graphics.setScissor(x - 1, y - 2, w + 2, h + 3)
|
||||
end
|
||||
|
||||
-- Set color
|
||||
@ -1278,9 +1275,7 @@ local draw_handler = function(child)
|
||||
|
||||
love.graphics.setColor(bbg[1], bbg[2], bbg[3], 1)
|
||||
love.graphics.setLineWidth(1)
|
||||
love.graphics.line( x, y + ry,
|
||||
x, y + h +1,
|
||||
x + 1 + w, y + h+1,
|
||||
love.graphics.line(x, y + ry, x, y + h + 1, x + 1 + w, y + h + 1,
|
||||
x + 1 + w, y + ry)
|
||||
love.graphics.line(x, y + h, x + 1 + w, y + h)
|
||||
love.graphics.setScissor()
|
||||
@ -1292,9 +1287,7 @@ local draw_handler = function(child)
|
||||
love.graphics.setLineStyle("rough")
|
||||
love.graphics.setColor(bbg[1], bbg[2], bbg[3], 1)
|
||||
love.graphics.setLineWidth(2)
|
||||
love.graphics.line( x-1, y + ry + 1,
|
||||
x-1, y - 1,
|
||||
x + w + 1, y - 1,
|
||||
love.graphics.line(x - 1, y + ry + 1, x - 1, y - 1, x + w + 1, y - 1,
|
||||
x + w + 1, y + ry + 1)
|
||||
love.graphics.setScissor()
|
||||
love.graphics.line(x - 1, y - 1, x + w + 1, y - 1)
|
||||
@ -1310,9 +1303,7 @@ local draw_handler = function(child)
|
||||
drawtypes[band(ctype, image)](child, x, y, w, h)
|
||||
drawtypes[band(ctype, text)](child, x, y, w, h)
|
||||
drawtypes[band(ctype, box)](child, x, y, w, h)
|
||||
if child.post then
|
||||
child:post()
|
||||
end
|
||||
if child.post then child:post() end
|
||||
if child.__variables.clip[1] then
|
||||
love.graphics.setScissor() -- Remove the scissor
|
||||
end
|
||||
@ -1323,9 +1314,7 @@ drawer:newLoop(function()
|
||||
for i = 1, #children do
|
||||
local child = children[i]
|
||||
if child.effect then
|
||||
child.effect(function()
|
||||
draw_handler(child)
|
||||
end)
|
||||
child.effect(function() draw_handler(child) end)
|
||||
else
|
||||
draw_handler(child)
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user