----------------------------- -- Levak ©2011 -------------- -- http://levak.free.fr/ ---- -- levak92@gmail.com -------- ----------------------------- ------ Buttons Button = {} Button.__index = Button function Button.create(x, y, w, h, scale, fun, text, icon, child) local btn = {} setmetatable(btn, Button) btn.x, btn.y = x * normal + navPos.x, y * normal + navPos.y btn.w, btn.h = (w - 1) * normal, (h - 1) * normal btn.s = scale btn.fun = fun btn.text = text if icon then if text then btn.icon = image.copy(icon, h * normal, h * normal) else btn.icon = image.copy(icon, w * normal, h * normal) end end btn.child = child return btn end function Button:isActive(x, y) return (x >= self.x - self.s/2) and (x <= self.x + self.s/2 + self.w ) and (y >= self.y - self.s/2) and (y <= self.y + self.s/2 + self.h) end function Button:paint(gc, bold) if not self.text then if not self.icon then gc:setColorRGB(0, 0, 0) gc:fillRect(self.x - self.s/2, self.y - self.s/2, self.w + self.s, self.h + self.s) else gc:drawImage(self.icon, self.x - self.s/2, self.y - self.s/2) end else gc:setColorRGB(255, 255, 255) if bold then gc:setPen("medium", "smooth") else gc:setPen("thin", "smooth") end gc:fillRect(self.x - self.s/2, self.y - self.s/2, self.w + self.s, self.h + self.s) gc:setColorRGB(0, 0, 0) gc:drawRect(self.x - self.s/2, self.y - self.s/2, self.w + self.s, self.h + self.s) if self.icon then gc:setFont("sansserif", "r", fxxsmall) gc:drawImage(self.icon, self.x - self.s/2, self.y - self.s/2) gc:setColorRGB(0, 0, 0) gc:drawString(self.text, self.x + image.width(self.icon)/2 + 5, self.y, "middle") if self.child then gc:drawImage(image.copy(nextButton, (self.h+normal)/3, self.h+normal), self.x + self.w, self.y - self.h) end else gc:setFont("sansserif", "r", math.max(math.min((self.w)/string.len(self.text), 255), 6)) local strlen = gc:getStringWidth(self.text) gc:drawString(self.text, self.x + self.w/2 - strlen/2, self.y, "middle") end end end