mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
improvements/new features
This commit is contained in:
parent
b0e4b99528
commit
978562774a
@ -412,7 +412,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -144,7 +144,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -491,7 +491,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -105,7 +105,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -137,7 +137,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#mousemoved-todo2">mousemoved-todo2</a></td>
|
<td class="name" nowrap><a href="#mousemoved-todo2">mousemoved-todo2</a></td>
|
||||||
<td class="summary">Implement a way for an element to attach itself to <code>love.mousemoved()</code> events?</td>
|
<td class="summary">Implement a way for an element to attach itself to <code>love.mousemoved()</code> events?
|
||||||
|
checking element against pop.screen so that this only gets called once</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#mousereleased-todo3">mousereleased-todo3</a></td>
|
<td class="name" nowrap><a href="#mousereleased-todo3">mousereleased-todo3</a></td>
|
||||||
@ -603,6 +604,11 @@ table.insert element.parent, element.parent\removeChild(element),</td>
|
|||||||
The currently focused GUI element (or <code>false</code>
|
The currently focused GUI element (or <code>false</code>
|
||||||
if none is focused).
|
if none is focused).
|
||||||
</li>
|
</li>
|
||||||
|
<li><span class="parameter">hovered</span>
|
||||||
|
<span class="types"><span class="type">Element</span> or <span class="type">false</span></span>
|
||||||
|
The GUI element the mouse is hovering over
|
||||||
|
(or <code>false</code> if none is hovered over).
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
@ -640,6 +646,7 @@ table.insert element.parent, element.parent\removeChild(element),</td>
|
|||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Implement a way for an element to attach itself to <code>love.mousemoved()</code> events?
|
Implement a way for an element to attach itself to <code>love.mousemoved()</code> events?
|
||||||
|
checking element against pop.screen so that this only gets called once
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -716,7 +723,7 @@ table.insert element.parent, element.parent\removeChild(element),
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -126,7 +126,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2017-04-08 13:43:44 </i>
|
<i style="float:right;">Last updated 2017-04-08 17:10:29 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
@ -21,7 +21,7 @@ do
|
|||||||
toPixel = true
|
toPixel = true
|
||||||
end
|
end
|
||||||
if not (self.data.align) then
|
if not (self.data.align) then
|
||||||
return false
|
return self
|
||||||
end
|
end
|
||||||
if horizontal then
|
if horizontal then
|
||||||
self.data.horizontal = horizontal
|
self.data.horizontal = horizontal
|
||||||
|
@ -47,7 +47,7 @@ class element
|
|||||||
|
|
||||||
--- @todo doc me
|
--- @todo doc me
|
||||||
align: (horizontal, vertical, toPixel=true) =>
|
align: (horizontal, vertical, toPixel=true) =>
|
||||||
unless @data.align return false
|
unless @data.align return @
|
||||||
|
|
||||||
@data.horizontal = horizontal if horizontal
|
@data.horizontal = horizontal if horizontal
|
||||||
@data.vertical = vertical if vertical
|
@data.vertical = vertical if vertical
|
||||||
|
@ -17,9 +17,26 @@ do
|
|||||||
self.data.h = self.font:getHeight() * (select(2, self.data.text:gsub("\n", "\n")) + 1)
|
self.data.h = self.font:getHeight() * (select(2, self.data.text:gsub("\n", "\n")) + 1)
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
|
getText = function(self)
|
||||||
|
return self.data.text
|
||||||
|
end,
|
||||||
setText = function(self, text)
|
setText = function(self, text)
|
||||||
self.data.text = text
|
self.data.text = tostring(text)
|
||||||
return self:setSize()
|
self:setSize()
|
||||||
|
return self:align()
|
||||||
|
end,
|
||||||
|
setColor = function(self, r, g, b, a)
|
||||||
|
if "table" == type(r) then
|
||||||
|
self.data.color = r
|
||||||
|
else
|
||||||
|
self.data.color = {
|
||||||
|
r,
|
||||||
|
g,
|
||||||
|
b,
|
||||||
|
a
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
_base_0.__index = _base_0
|
_base_0.__index = _base_0
|
||||||
@ -37,6 +54,11 @@ do
|
|||||||
end
|
end
|
||||||
self.parent, self.data = parent, data
|
self.parent, self.data = parent, data
|
||||||
_class_0.__parent.__init(self, self.parent, self.data)
|
_class_0.__parent.__init(self, self.parent, self.data)
|
||||||
|
if "number" == type(text) then
|
||||||
|
fontSize = fontFile
|
||||||
|
fontFile = text
|
||||||
|
text = ""
|
||||||
|
end
|
||||||
self.data.type = "text"
|
self.data.type = "text"
|
||||||
if not (self.data.text) then
|
if not (self.data.text) then
|
||||||
self.data.text = text
|
self.data.text = text
|
||||||
|
@ -12,6 +12,12 @@ class text extends element
|
|||||||
new: (@parent, @data={}, text="", fontFile, fontSize=14) =>
|
new: (@parent, @data={}, text="", fontFile, fontSize=14) =>
|
||||||
super @parent, @data
|
super @parent, @data
|
||||||
|
|
||||||
|
-- this makes text optional, a number can be passed to set font size immediately
|
||||||
|
if "number" == type text
|
||||||
|
fontSize = fontFile
|
||||||
|
fontFile = text
|
||||||
|
text = ""
|
||||||
|
|
||||||
@data.type = "text"
|
@data.type = "text"
|
||||||
@data.text = text unless @data.text
|
@data.text = text unless @data.text
|
||||||
@data.fontFile = fontFile unless @data.fontFile
|
@data.fontFile = fontFile unless @data.fontFile
|
||||||
@ -35,12 +41,36 @@ class text extends element
|
|||||||
return @
|
return @
|
||||||
|
|
||||||
--- Size is dependant on the text and font, so you cannot specify a size.
|
--- Size is dependant on the text and font, so you cannot specify a size.
|
||||||
|
--- @treturn element self
|
||||||
setSize: =>
|
setSize: =>
|
||||||
@data.w = @font\getWidth @data.text
|
@data.w = @font\getWidth @data.text
|
||||||
@data.h = @font\getHeight! * (select(2, @data.text\gsub("\n", "\n")) + 1) --hack to get height of multiple lines
|
@data.h = @font\getHeight! * (select(2, @data.text\gsub("\n", "\n")) + 1) --hack to get height of multiple lines
|
||||||
return @
|
return @
|
||||||
|
|
||||||
|
--- Returns text.
|
||||||
|
--- @treturn string text
|
||||||
|
getText: =>
|
||||||
|
return @data.text
|
||||||
|
|
||||||
--- Text should be set this way, or the object will not be the correct size.
|
--- Text should be set this way, or the object will not be the correct size.
|
||||||
|
--- @tparam string text The text to set.
|
||||||
|
--- @treturn element self
|
||||||
setText: (text) =>
|
setText: (text) =>
|
||||||
@data.text = text
|
@data.text = tostring text
|
||||||
return @setSize!
|
@setSize!
|
||||||
|
return @align!
|
||||||
|
|
||||||
|
--- Change text color. Uses LOVE's 0-255 values for components of colors.
|
||||||
|
--- @tparam ?number|table r The red component or a table of RGBA values.
|
||||||
|
--- @tparam number g The green component.
|
||||||
|
--- @tparam number b The blue component.
|
||||||
|
--- @tparam number a The alpha component. While not technically required, if
|
||||||
|
--- ANYTHING uses an alpha component and you don't, it could cause bugs in
|
||||||
|
--- rendering.
|
||||||
|
--- @treturn element self
|
||||||
|
setColor: (r, g, b, a) =>
|
||||||
|
if "table" == type r
|
||||||
|
@data.color = r
|
||||||
|
else
|
||||||
|
@data.color = {r, g, b, a}
|
||||||
|
return @
|
||||||
|
19
init.lua
19
init.lua
@ -61,6 +61,7 @@ pop.skins = { }
|
|||||||
pop.extensions = { }
|
pop.extensions = { }
|
||||||
pop.screen = false
|
pop.screen = false
|
||||||
pop.focused = false
|
pop.focused = false
|
||||||
|
pop.hovered = false
|
||||||
pop.log = log
|
pop.log = log
|
||||||
pop.load = function(load_path)
|
pop.load = function(load_path)
|
||||||
if load_path == nil then
|
if load_path == nil then
|
||||||
@ -145,6 +146,7 @@ pop.load = function(load_path)
|
|||||||
end
|
end
|
||||||
if not (pop.screen) then
|
if not (pop.screen) then
|
||||||
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
|
||||||
|
pop.screen.data.update = true
|
||||||
return log("Created \"pop.screen\"")
|
return log("Created \"pop.screen\"")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -207,8 +209,17 @@ pop.draw = function(element)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
pop.mousemoved = function(x, y, dx, dy)
|
pop.mousemoved = function(x, y, dx, dy, element)
|
||||||
if pop.focused and pop.focused.mousemoved then
|
if element == nil then
|
||||||
|
element = pop.screen
|
||||||
|
end
|
||||||
|
if (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h) then
|
||||||
|
pop.hovered = element
|
||||||
|
for i = #element.child, 1, -1 do
|
||||||
|
pop.mousemoved(x, y, dx, dy, element.child[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if pop.focused and pop.focused.mousemoved and element == pop.screen then
|
||||||
return pop.focused:mousemoved(x - pop.focused.data.x, y - pop.focused.data.y, dx, dy)
|
return pop.focused:mousemoved(x - pop.focused.data.x, y - pop.focused.data.y, dx, dy)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -352,7 +363,11 @@ pop.printElementTree = function(element, depth)
|
|||||||
end
|
end
|
||||||
cls = cls .. " (" .. tostring(bg) .. ")"
|
cls = cls .. " (" .. tostring(bg) .. ")"
|
||||||
end
|
end
|
||||||
|
if depth > 0 then
|
||||||
log(string.rep("-", depth) .. " " .. tostring(cls))
|
log(string.rep("-", depth) .. " " .. tostring(cls))
|
||||||
|
else
|
||||||
|
log(cls)
|
||||||
|
end
|
||||||
for i = 1, #element.child do
|
for i = 1, #element.child do
|
||||||
pop.printElementTree(element.child[i], depth + 1)
|
pop.printElementTree(element.child[i], depth + 1)
|
||||||
end
|
end
|
||||||
|
20
init.moon
20
init.moon
@ -42,6 +42,8 @@ import dumps, loads from require "#{path}/lib/bitser/bitser"
|
|||||||
--- screen. Initialized in `pop.load()`
|
--- screen. Initialized in `pop.load()`
|
||||||
--- @tfield ?Element|false focused The currently focused GUI element (or `false`
|
--- @tfield ?Element|false focused The currently focused GUI element (or `false`
|
||||||
--- if none is focused).
|
--- if none is focused).
|
||||||
|
--- @tfield ?Element|false hovered The GUI element the mouse is hovering over
|
||||||
|
--- (or `false` if none is hovered over).
|
||||||
--- @see pop.load
|
--- @see pop.load
|
||||||
--- @see Element
|
--- @see Element
|
||||||
|
|
||||||
@ -75,6 +77,7 @@ pop.skins = {}
|
|||||||
pop.extensions = {}
|
pop.extensions = {}
|
||||||
pop.screen = false
|
pop.screen = false
|
||||||
pop.focused = false
|
pop.focused = false
|
||||||
|
pop.hovered = false
|
||||||
pop.log = log
|
pop.log = log
|
||||||
|
|
||||||
|
|
||||||
@ -163,6 +166,7 @@ pop.load = (load_path=path) ->
|
|||||||
-- Initialize pop.screen (top element, GUI area)
|
-- Initialize pop.screen (top element, GUI area)
|
||||||
unless pop.screen
|
unless pop.screen
|
||||||
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
|
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
|
||||||
|
pop.screen.data.update = true
|
||||||
log "Created \"pop.screen\""
|
log "Created \"pop.screen\""
|
||||||
|
|
||||||
|
|
||||||
@ -261,9 +265,18 @@ pop.draw = (element=pop.screen) ->
|
|||||||
--- @tparam number dy The distance on the y axis the mouse was moved.
|
--- @tparam number dy The distance on the y axis the mouse was moved.
|
||||||
--- @treturn boolean Was the event handled?
|
--- @treturn boolean Was the event handled?
|
||||||
|
|
||||||
pop.mousemoved = (x, y, dx, dy) ->
|
pop.mousemoved = (x, y, dx, dy, element=pop.screen) ->
|
||||||
|
-- first we find out if we're hovering over anything and set pop.hovered
|
||||||
|
if (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h)
|
||||||
|
-- okay, we're over this element for sure, but let's check its children
|
||||||
|
pop.hovered = element
|
||||||
|
-- check in reverse order, it will set pop.hovered to any that match
|
||||||
|
for i = #element.child, 1, -1
|
||||||
|
pop.mousemoved x, y, dx, dy, element.child[i]
|
||||||
|
|
||||||
--- @todo Implement a way for an element to attach itself to `love.mousemoved()` events?
|
--- @todo Implement a way for an element to attach itself to `love.mousemoved()` events?
|
||||||
if pop.focused and pop.focused.mousemoved
|
-- checking element against pop.screen so that this only gets called once
|
||||||
|
if pop.focused and pop.focused.mousemoved and element == pop.screen
|
||||||
return pop.focused\mousemoved x - pop.focused.data.x, y - pop.focused.data.y, dx, dy
|
return pop.focused\mousemoved x - pop.focused.data.x, y - pop.focused.data.y, dx, dy
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -480,7 +493,10 @@ pop.printElementTree = (element=pop.screen, depth=0) ->
|
|||||||
|
|
||||||
cls = cls .. " (#{bg})"
|
cls = cls .. " (#{bg})"
|
||||||
|
|
||||||
|
if depth > 0
|
||||||
log string.rep("-", depth) .. " #{cls}"
|
log string.rep("-", depth) .. " #{cls}"
|
||||||
|
else
|
||||||
|
log cls
|
||||||
|
|
||||||
for i = 1, #element.child
|
for i = 1, #element.child
|
||||||
pop.printElementTree element.child[i], depth + 1
|
pop.printElementTree element.child[i], depth + 1
|
||||||
|
Loading…
Reference in New Issue
Block a user