All right, so it has been a little while since i posted. School just ended so I now have more time to work on my projects.
I have been working on text boxes and now they have a smooth scrolling. I will be working on password char and multiline very soon but until then here is the new code for the text box class:
Code:
----------------------textbox-------------------------------------------
textbox = class()
function textbox:init(x, y, width, text, textcolor, tbcolor, parent, selected)
self.parent = parent
self.x = x + parent.x
self.y = y + parent.y
self.xoff = x
self.yoff = y
self.width = width
if self.width < 10 then
self.width = 10
end
self.height = 11
self.text = text
self.textcolor = textcolor
self.tbcolor = tbcolor
self.selected = selected
self.cury = self.y + 1
self.curx = self.x + 1
self.curh = (self.y + self.height) - 1
self.parent = parent
self.type = "txt"
self.stwid = 0
self.dIndex = 1
self.initial = true
self.bsflag = false
table.insert(parent.controls, self)
end
function textbox:paint(gc)
self.stwid = gc:getStringWidth(self.text)
if self.initial == true then
local dtext = self.text
while gc:getStringWidth(dtext) >= self.width - 1 do
dtext = string.sub(dtext, 2)
end
self.initial = false
self.dIndex = string.find(self.text, dtext)
else
while gc:getStringWidth(string.sub(self.text, self.dIndex)) >= self.width and self.bsflag == false do
self.dIndex = self.dIndex + 1
self.dText = string.sub(self.text, self.dIndex)
end
if self.bsflag == true then
self.text = string.sub(self.text, 1, string.len(self.text) - 1)
if string.len(self.text) > string.len(string.sub(self.text, self.dIndex)) then
self.dIndex = self.dIndex - 1
while gc:getStringWidth(string.sub(self.text, self.dIndex)) >= self.width do
self.dIndex = self.dIndex + 1
self.dText = string.sub(self.text, self.dIndex)
end
end
end
end
self.bsflag = false
gc:setColorRGB(unpack(self.tbcolor))
gc:drawRect( self.x, self.y, self.width + 3, self.height)
gc:setColorRGB(unpack(self.textcolor))
gc:setFont("sansserif", "r", 8)
self.stwid =
gc:drawString( string.sub(self.text, self.dIndex), self.x + 4, self.y + 3, "middle")
gc:setColorRGB(unpack(color.black))
self.cury = self.y + 1
self.curx = self.x + gc:getStringWidth(string.sub(self.text, self.dIndex)) + 3
self.curh = (self.y + self.height) - 1
gc:drawLine(self.curx, self.cury, self.curx, self.curh)
end
function textbox:charIn(ch)
if self.selected then
self.text = self.text..ch
end
platform.window:invalidate(self.x, self.y, self.width + 2, self.height)
end
function textbox:backspaceKey()
self.bsflag = true
platform.window:invalidate(self.x, self.y, self.width + 2, self.height)
end
function textbox:click()
if self.selected then
self.selected = false
else
for _, tb in pairs(self.parent.controls) do
if tb.type == "txt" then
tb.selected = false
end
end
self.selected = true
end
end
function textbox:checkClick(x, y)
if y >= self.y and y <= self.y + self.height and x >= self.x and x <= self.x + self.width then
self:click()
end
end
Also Thank you flyingfisch for the userbar!