1-- This file is a part of Avoision. 2-- 3-- Copyright (C) 2012 Jared Krinke. 4-- 5-- Avoision is free software; you can redistribute it and/or 6-- modify it under the terms of the GNU General Public License 7-- as published by the Free Software Foundation; either version 2 8-- of the License, or (at your option) any later version. 9-- 10-- This program is distributed in the hope that it will be useful, 11-- but WITHOUT ANY WARRANTY; without even the implied warranty of 12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13-- GNU General Public License for more details. 14-- 15-- You should have received a copy of the GNU General Public License 16-- along with this program; if not, write to the Free Software 17-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 19require("UI/Label.lua") 20 21local defaultColor = Color.new(1, 1, 1) 22local focusedColor = Color.new(0.5, 0.5, 1) 23local disabledColor = Color.new(0.6, 0.6, 0.6) 24 25Button = { 26 defaultColor = defaultColor, 27 focusedColor = focusedColor, 28 disabledColor = disabledColor, 29} 30 31function Button.new(text, activated, silent) 32 local button = Label.new(text) 33 34 button.active = true 35 button.silent = silent 36 37 if isFunction(activated) then 38 button.activated = function() 39 activated() 40 41 local silent = button.silent 42 43 if not isBoolean(silent) or not silent then 44 Audio.play("Sounds/Select.wav") 45 end 46 end 47 end 48 49 button.textElement.color = defaultColor 50 51 function button.setActive(self, active) 52 local color = defaultColor 53 54 if not active then 55 color = disabledColor 56 end 57 58 self.active = active 59 self:setColor(color) 60 end 61 62 function button.getActive(self) 63 return self.active 64 end 65 66 function button.focused(self) 67 self:setColor(focusedColor) 68 end 69 70 function button.unfocused(self) 71 self:setColor(defaultColor) 72 end 73 74 return button 75end 76 77