improvements/new features

This commit is contained in:
Paul Liverman III 2017-04-08 17:10:44 -07:00
parent b0e4b99528
commit 978562774a
13 changed files with 110 additions and 20 deletions

View File

@ -412,7 +412,7 @@
</div> <!-- id="main" -->
<div id="about">
<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="container" -->
</body>

View File

@ -144,7 +144,7 @@
</div> <!-- id="main" -->
<div id="about">
<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="container" -->
</body>

View File

@ -84,7 +84,7 @@
</div> <!-- id="main" -->
<div id="about">
<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="container" -->
</body>

View File

@ -491,7 +491,7 @@
</div> <!-- id="main" -->
<div id="about">
<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="container" -->
</body>

View File

@ -105,7 +105,7 @@
</div> <!-- id="main" -->
<div id="about">
<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="container" -->
</body>

View File

@ -137,7 +137,8 @@
</tr>
<tr>
<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>
<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>
if none is focused).
</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>
@ -640,6 +646,7 @@ table.insert element.parent, element.parent\removeChild(element),</td>
</dt>
<dd>
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="about">
<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="container" -->
</body>

View File

@ -126,7 +126,7 @@
</div> <!-- id="main" -->
<div id="about">
<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="container" -->
</body>

View File

@ -21,7 +21,7 @@ do
toPixel = true
end
if not (self.data.align) then
return false
return self
end
if horizontal then
self.data.horizontal = horizontal

View File

@ -47,7 +47,7 @@ class element
--- @todo doc me
align: (horizontal, vertical, toPixel=true) =>
unless @data.align return false
unless @data.align return @
@data.horizontal = horizontal if horizontal
@data.vertical = vertical if vertical

View File

@ -17,9 +17,26 @@ do
self.data.h = self.font:getHeight() * (select(2, self.data.text:gsub("\n", "\n")) + 1)
return self
end,
getText = function(self)
return self.data.text
end,
setText = function(self, text)
self.data.text = text
return self:setSize()
self.data.text = tostring(text)
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
}
_base_0.__index = _base_0
@ -37,6 +54,11 @@ do
end
self.parent, self.data = parent, 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"
if not (self.data.text) then
self.data.text = text

View File

@ -12,6 +12,12 @@ class text extends element
new: (@parent, @data={}, text="", fontFile, fontSize=14) =>
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.text = text unless @data.text
@data.fontFile = fontFile unless @data.fontFile
@ -35,12 +41,36 @@ class text extends element
return @
--- Size is dependant on the text and font, so you cannot specify a size.
--- @treturn element self
setSize: =>
@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
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.
--- @tparam string text The text to set.
--- @treturn element self
setText: (text) =>
@data.text = text
return @setSize!
@data.text = tostring text
@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 @

View File

@ -61,6 +61,7 @@ pop.skins = { }
pop.extensions = { }
pop.screen = false
pop.focused = false
pop.hovered = false
pop.log = log
pop.load = function(load_path)
if load_path == nil then
@ -145,6 +146,7 @@ pop.load = function(load_path)
end
if not (pop.screen) then
pop.screen = pop.create("element", false):setSize(graphics.getWidth(), graphics.getHeight())
pop.screen.data.update = true
return log("Created \"pop.screen\"")
end
end
@ -207,8 +209,17 @@ pop.draw = function(element)
end
end
end
pop.mousemoved = function(x, y, dx, dy)
if pop.focused and pop.focused.mousemoved then
pop.mousemoved = function(x, y, dx, dy, element)
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)
end
return false
@ -352,7 +363,11 @@ pop.printElementTree = function(element, depth)
end
cls = cls .. " (" .. tostring(bg) .. ")"
end
log(string.rep("-", depth) .. " " .. tostring(cls))
if depth > 0 then
log(string.rep("-", depth) .. " " .. tostring(cls))
else
log(cls)
end
for i = 1, #element.child do
pop.printElementTree(element.child[i], depth + 1)
end

View File

@ -42,6 +42,8 @@ import dumps, loads from require "#{path}/lib/bitser/bitser"
--- screen. Initialized in `pop.load()`
--- @tfield ?Element|false focused The currently focused GUI element (or `false`
--- 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 Element
@ -75,6 +77,7 @@ pop.skins = {}
pop.extensions = {}
pop.screen = false
pop.focused = false
pop.hovered = false
pop.log = log
@ -163,6 +166,7 @@ pop.load = (load_path=path) ->
-- Initialize pop.screen (top element, GUI area)
unless pop.screen
pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!)
pop.screen.data.update = true
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.
--- @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?
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 false
@ -480,7 +493,10 @@ pop.printElementTree = (element=pop.screen, depth=0) ->
cls = cls .. " (#{bg})"
log string.rep("-", depth) .. " #{cls}"
if depth > 0
log string.rep("-", depth) .. " #{cls}"
else
log cls
for i = 1, #element.child
pop.printElementTree element.child[i], depth + 1