From fd92ff0f123a9aae41c017ec7d7ea7811dbcb7b5 Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Mon, 14 May 2012 22:47:38 -0400 Subject: [PATCH] Version 0.9.1.3 - Alpha (see changelog.txt) --- changelog.txt | 16 +++ debug.lua | 22 +++- init.lua | 3 +- objects/base.lua | 77 ++++++++++++ objects/frame.lua | 118 +++++++++++++++--- .../columnlist/columnlist-listarea.lua | 2 +- objects/internal/modalbackground.lua | 81 ++++++++++++ objects/internal/tabbutton.lua | 1 + skins/Blue/skin.lua | 24 +++- skins/Orange/skin.lua | 24 +++- 10 files changed, 341 insertions(+), 27 deletions(-) create mode 100644 objects/internal/modalbackground.lua diff --git a/changelog.txt b/changelog.txt index 8ba4787..60ea1aa 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,19 @@ +================================================ +Version 0.9.1.3 - Alpha (May 14 - 2012) +================================================ +[ADDED] modal system for frames +[ADDED] a new frame method: SetModal(bool) +[ADDED] a new frame method: GetModal() +[ADDED] a new frame method: SetVisible(bool) - this override is part of a frame bug fix +[ADDED] "showclose" property for the frame object +[ADDED] a new internal object: modal background +[ADDED] a new base method: IsActive() +[ADDED] a new base method: CenterX() +[ADDED] a new base method: CenterY() +[ADDED] a new skin function: DrawOverColumList() + +[FIXED] a bug that made the frame's close button become visisble when the frame was made visible and show close button was set to false + ================================================ Version 0.9.1.2 - Alpha (May 12 - 2012) ================================================ diff --git a/debug.lua b/debug.lua index 5ece23f..f93a8dc 100644 --- a/debug.lua +++ b/debug.lua @@ -237,9 +237,29 @@ function loveframes.debug.ExamplesMenu() local text1 = loveframes.Create("text", frame1) text1:SetText("This is an example frame.") text1.Update = function(object2, dt) - object2:Center() + object2:CenterX() + object2:SetY(40) end + local button1 = loveframes.Create("button", frame1) + button1:SetText("Modal") + button1:SetWidth(100) + button1:Center() + button1.Update = function(object2, dt) + local modal = object2:GetParent():GetModal() + + if modal == true then + object2:SetText("Remove Modal") + object2.OnClick = function() + object2:GetParent():SetModal(false) + end + else + object2:SetText("Set Modal") + object2.OnClick = function() + object2:GetParent():SetModal(true) + end + end + end end exampleslist:AddItem(frameexample) diff --git a/init.lua b/init.lua index 78ff562..8fba353 100644 --- a/init.lua +++ b/init.lua @@ -9,7 +9,7 @@ loveframes = {} -- library info loveframes.info = {} loveframes.info.author = "Nikolai Resokav" -loveframes.info.version = "0.9.1.2" +loveframes.info.version = "0.9.1.3" loveframes.info.stage = "Alpha" -- library configurations @@ -22,6 +22,7 @@ loveframes.config["DEBUG"] = true loveframes.drawcount = 0 loveframes.hoverobject = false +loveframes.modalobject = false --[[--------------------------------------------------------- - func: load() diff --git a/objects/base.lua b/objects/base.lua index 1a09909..a72b7e2 100644 --- a/objects/base.lua +++ b/objects/base.lua @@ -284,6 +284,42 @@ function base:Center() end +--[[--------------------------------------------------------- + - func: CenterX() + - desc: centers the object by it's x value +--]]--------------------------------------------------------- +function base:CenterX() + + local parent = self.parent + + if parent == loveframes.base then + local width = love.graphics.getWidth() + self.x = width/2 - self.width/2 + else + local width = parent.width + self.staticx = width/2 - self.width/2 + end + +end + +--[[--------------------------------------------------------- + - func: CenterY() + - desc: centers the object by it's y value +--]]--------------------------------------------------------- +function base:CenterY() + + local parent = self.parent + + if parent == loveframes.base then + local height = love.graphics.getHeight() + self.y = height/2 - self.height/2 + else + local height = parent.height + self.staticy = height/2 - self.height/2 + end + +end + --[[--------------------------------------------------------- - func: SetSize(width, height) - desc: sets the object's size @@ -578,6 +614,7 @@ function base:CheckHover() local x, y = love.mouse.getPosition() local selfcol = loveframes.util.BoundingBox(x, self.x, y, self.y, 1, self.width, 1, self.height) local hoverobject = loveframes.hoverobject + local modalobject = loveframes.modalobject -- is the mouse inside the object? if selfcol == true then @@ -610,6 +647,26 @@ function base:CheckHover() end + if modalobject ~= false then + + if modalobject ~= self then + + local baseparent = self:GetBaseParent() + + if baseparent ~= modalobject then + + self.hover = false + + if self.focus then + self.focus = false + end + + end + + end + + end + -- this chunk of code handles mouse enter and exit if self.hover == true then @@ -814,4 +871,24 @@ function base:GetRetainSize() return self.retainsize +end + +--[[--------------------------------------------------------- + - func: IsActive() + - desc: gets whether or not the object is active within + it's parent's child table +--]]--------------------------------------------------------- +function base:IsActive() + + local parent = self.parent + local valid = false + + for k, v in ipairs(parent.children) do + if v == self then + valid = true + end + end + + return valid + end \ No newline at end of file diff --git a/objects/frame.lua b/objects/frame.lua index 94620e5..12c6ad5 100644 --- a/objects/frame.lua +++ b/objects/frame.lua @@ -13,19 +13,22 @@ frame:include(loveframes.templates.default) --]]--------------------------------------------------------- function frame:initialize() - self.type = "frame" - self.name = "Frame" - self.width = 300 - self.height = 150 - self.clickx = 0 - self.clicky = 0 - self.internal = false - self.draggable = true - self.screenlocked = false - self.dragging = false - self.internals = {} - self.children = {} - self.OnClose = nil + self.type = "frame" + self.name = "Frame" + self.width = 300 + self.height = 150 + self.clickx = 0 + self.clicky = 0 + self.internal = false + self.draggable = true + self.screenlocked = false + self.dragging = false + self.modal = false + self.modalbackground = false + self.showclose = true + self.internals = {} + self.children = {} + self.OnClose = nil local close = closebutton:new() close.parent = self @@ -90,6 +93,23 @@ function frame:update(dt) end + if self.modal == true then + + local numtooltips = 0 + + for k, v in ipairs(loveframes.base.children) do + if v.type == "tooltip" then + numtooltips = numtooltips + 1 + end + end + + if self.draworder ~= #loveframes.base.children - numtooltips then + self.modalbackground:MoveToTop() + self:MoveToTop() + end + + end + for k, v in ipairs(self.internals) do v:update(dt) end @@ -280,7 +300,8 @@ function frame:ShowCloseButton(bool) local close = self.internals[1] close.visible = bool - + self.showclose = bool + end --[[--------------------------------------------------------- @@ -315,4 +336,73 @@ function frame:MakeTop() loveframes.base.children[key]:mousepressed(x, y, "l") +end + +--[[--------------------------------------------------------- + - func: SetModal(bool) + - desc: makes the object the top object in the drawing + order +--]]--------------------------------------------------------- +function frame:SetModal(bool) + + self.modal = bool + + if bool == true then + + if loveframes.modalobject ~= false then + loveframes.modalobject:SetModal(false) + end + + loveframes.modalobject = self + + if self.modalbackground == false then + self.modalbackground = modalbackground:new(self) + self.modal = true + end + + else + + if loveframes.modalobject == self then + + loveframes.modalobject = false + + if self.modalbackground ~= false then + self.modalbackground:Remove() + self.modalbackground = false + self.modal = false + end + + end + + end + +end + +--[[--------------------------------------------------------- + - func: GetModal() + - desc: gets whether or not the object is in a modal + state +--]]--------------------------------------------------------- +function frame:GetModal() + + return self.modal + +end + +--[[--------------------------------------------------------- + - func: SetVisible(bool) + - desc: set's whether the object is visible or not +--]]--------------------------------------------------------- +function frame:SetVisible(bool) + + self.visible = bool + + for k, v in ipairs(self.children) do + v:SetVisible(bool) + end + + if self.showclose == true then + self.internals[1].visible = bool + end + end \ No newline at end of file diff --git a/objects/internal/columnlist/columnlist-listarea.lua b/objects/internal/columnlist/columnlist-listarea.lua index 5c02d0b..22d8f58 100644 --- a/objects/internal/columnlist/columnlist-listarea.lua +++ b/objects/internal/columnlist/columnlist-listarea.lua @@ -116,7 +116,7 @@ function columnlistarea:draw() love.graphics.setStencil() if self.Draw == nil then - skin.DrawColumnListArea(self) + skin.DrawOverColumnListArea(self) end end diff --git a/objects/internal/modalbackground.lua b/objects/internal/modalbackground.lua new file mode 100644 index 0000000..609fe88 --- /dev/null +++ b/objects/internal/modalbackground.lua @@ -0,0 +1,81 @@ +--[[------------------------------------------------ + -- LÖVE Frames -- + -- By Nikolai Resokav -- +--]]------------------------------------------------ + +-- panel class +modalbackground = class("modalbackground", base) +modalbackground:include(loveframes.templates.default) + +--[[--------------------------------------------------------- + - func: initialize() + - desc: initializes the object +--]]--------------------------------------------------------- +function modalbackground:initialize(object) + + self.type = "modalbackground" + self.width = love.graphics.getWidth() + self.height = love.graphics.getHeight() + self.x = 0 + self.y = 0 + self.internal = true + self.parent = loveframes.base + self.object = object + + table.insert(loveframes.base.children, self) + + if self.object.type ~= "frame" then + self:Remove() + end + +end + +--[[--------------------------------------------------------- + - func: update(deltatime) + - desc: updates the element +--]]--------------------------------------------------------- +function modalbackground:update(dt) + + if self.visible == false then + if self.alwaysupdate == false then + return + end + end + + if self.object:IsActive() == false then + self:Remove() + loveframes.modalobject = false + end + + if self.Update then + self.Update(self, dt) + end + +end + +--[[--------------------------------------------------------- + - func: draw() + - desc: draws the object +--]]--------------------------------------------------------- +function modalbackground:draw() + + if self.visible == false then + return + end + + -- skin variables + local index = loveframes.config["ACTIVESKIN"] + local defaultskin = loveframes.config["DEFAULTSKIN"] + local selfskin = self.skin + local skin = loveframes.skins.available[selfskin] or loveframes.skins.available[index] or loveframes.skins.available[defaultskin] + + loveframes.drawcount = loveframes.drawcount + 1 + self.draworder = loveframes.drawcount + + if self.Draw ~= nil then + self.Draw(self) + else + skin.DrawModalBackground(self) + end + +end \ No newline at end of file diff --git a/objects/internal/tabbutton.lua b/objects/internal/tabbutton.lua index 5d65b4f..2c9ec6f 100644 --- a/objects/internal/tabbutton.lua +++ b/objects/internal/tabbutton.lua @@ -28,6 +28,7 @@ function tabbutton:initialize(parent, text, tabnumber, tip, image) if tip then self.tooltip = tooltip:new(self, tip) self.tooltip:SetFollowCursor(false) + self.tooltip:SetOffsets(0, -5) end if image then diff --git a/skins/Blue/skin.lua b/skins/Blue/skin.lua index 012bcc5..c0d2383 100644 --- a/skins/Blue/skin.lua +++ b/skins/Blue/skin.lua @@ -164,6 +164,9 @@ skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} skin.controls.columnlistrow_border2_color = bordercolor skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +-- modalbackground +skin.controls.modalbackground_body_color = {255, 255, 255, 100} + --[[--------------------------------------------------------- - func: OutlinedRectangle(object) - desc: creates and outlined rectangle @@ -1162,12 +1165,12 @@ end --[[--------------------------------------------------------- - func: skin.DrawOverColumnListArea(object) - - desc: draws the column list area object + - desc: draws over the column list area object --]]--------------------------------------------------------- -function skin.DrawColumnListArea(object) - - love.graphics.setColor(unpack(skin.controls.columnlistarea_border_color)) - skin.OutlinedRectangle(object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight()) +function skin.DrawOverColumnListArea(object) + + love.graphics.setColor(unpack(skin.controls.columnlist_border_color)) + skin.OutlinedRectangle(object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight(), true, false, true, true) end @@ -1204,5 +1207,16 @@ function skin.DrawColumnListRow(object) end +--[[--------------------------------------------------------- + - func: skin.DrawModalBackground(object) + - desc: draws the modal background object +--]]--------------------------------------------------------- +function skin.DrawModalBackground(object) + + love.graphics.setColor(unpack(skin.controls.modalbackground_body_color)) + love.graphics.rectangle("fill", object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight()) + +end + -- register the skin loveframes.skins.Register(skin) \ No newline at end of file diff --git a/skins/Orange/skin.lua b/skins/Orange/skin.lua index 8b97b33..f81d064 100644 --- a/skins/Orange/skin.lua +++ b/skins/Orange/skin.lua @@ -164,6 +164,9 @@ skin.controls.columnlistrow_body1_color = {232, 232, 232, 255} skin.controls.columnlistrow_border2_color = bordercolor skin.controls.columnlistrow_body2_color = {200, 200, 200, 255} +-- modalbackground +skin.controls.modalbackground_body_color = {255, 255, 255, 100} + --[[--------------------------------------------------------- - func: OutlinedRectangle(object) - desc: creates and outlined rectangle @@ -1163,12 +1166,12 @@ end --[[--------------------------------------------------------- - func: skin.DrawOverColumnListArea(object) - - desc: draws the column list area object + - desc: draws over the column list area object --]]--------------------------------------------------------- -function skin.DrawColumnListArea(object) - - love.graphics.setColor(unpack(skin.controls.columnlistarea_border_color)) - skin.OutlinedRectangle(object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight()) +function skin.DrawOverColumnListArea(object) + + love.graphics.setColor(unpack(skin.controls.columnlist_border_color)) + skin.OutlinedRectangle(object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight(), true, false, true, true) end @@ -1205,5 +1208,16 @@ function skin.DrawColumnListRow(object) end +--[[--------------------------------------------------------- + - func: skin.DrawModalBackground(object) + - desc: draws the modal background object +--]]--------------------------------------------------------- +function skin.DrawModalBackground(object) + + love.graphics.setColor(unpack(skin.controls.modalbackground_body_color)) + love.graphics.rectangle("fill", object:GetX(), object:GetY(), object:GetWidth(), object:GetHeight()) + +end + -- register the skin loveframes.skins.Register(skin) \ No newline at end of file