Saltar al contenido
  • Global

    Global

    Chatroom Rules

    • NO SE DA SOPORTE EN CHATBOX
    • NO SPAM
    • NO FLOOD

Publicaciones recomendadas

  • Usuario
Publicado

¡Buenas! Quisiera saber como hacer un sistema, o función para hacer un EditBox basado en un dxDrawRectangle y dxDrawText. eh visto algunos, pero quiero saber como se hacen. :huh:

 

Espero Respuestas, Gracias de Antemano! :D

  • 3 weeks later...
  • Usuario
Publicado

fíjate acá te dejo unas funciones que te servirán

esto de acá es una libreria de dx acá podrás obtener dicha función

 

 

dxLib = {
	imageURL = "Imagenes/",
	globalAlpha = 1,
	font = "default-bold"
}

--####################################################################
--##		dxLib Events											##
--####################################################################

addEvent("onDxLibButtonClick",true)
addEvent("onDxLibEditChange",true)
addEvent("onDxLibGridlistClick",true)
addEvent("onDxLibScrollMouse",true)

--####################################################################
--##		Main Functions											##
--####################################################################

local sX,sY = guiGetScreenSize()

function dxLibCreateButton(buttonElement,positionX,positionY,sizeX,sizeY,buttonLabel,labelSize,red,green,blue,lR,lG,lB,alpha,postGUI,coloredLabel)
	if not getElementData(buttonElement,"dxButtonCreate") then
		setElementData(buttonElement,"dxButtonCreate",true,false)
		setElementData(buttonElement,"dxButtonHover",false,false)
		setElementData(buttonElement,"dxButtonClick",false,false)
		return
	end
	setElementData(buttonElement,"dxButtonLabel",tostring(buttonLabel),false)
	setElementData(buttonElement,"dxButtonHover",false,false)
	local scaleX = sizeX/932
	if isCursorHover(positionX,positionY,sizeX,sizeY) and not getElementData(buttonElement,"dxButtonClick") then
		setElementData(buttonElement,"dxButtonHover",true,false)
		dxDrawImageSection(positionX-25*scaleX+sizeX,positionY,25*scaleX,sizeY,0,0,25,174,dxLib.imageURL.."button.png",180,0,0,tocolor(red,green,blue,alpha*dxLib.globalAlpha),postGUI)
		dxDrawImageSection(positionX,positionY,25*scaleX,sizeY,907,0,25,174,dxLib.imageURL.."button.png",180,0,0,tocolor(red,green,blue,alpha*dxLib.globalAlpha),postGUI)
		dxDrawImageSection(positionX+25*scaleX,positionY,sizeX-50*scaleX,sizeY,26,0,1,174,dxLib.imageURL.."button.png",180,0,0,tocolor(red,green,blue,alpha*dxLib.globalAlpha),postGUI)
		dxDrawText(buttonLabel,positionX,positionY,positionX+sizeX+1,positionY+sizeY+2,tocolor(0,0,0,alpha*dxLib.globalAlpha),labelSize,dxLib.font,"center","center",true,false,postGUI,coloredLabel or false)
		dxDrawText(buttonLabel,positionX,positionY,positionX+sizeX,positionY+sizeY,tocolor(lR,lG,lB,alpha*dxLib.globalAlpha),labelSize,dxLib.font,"center","center",true,false,postGUI,coloredLabel or false)
	else
		dxDrawImageSection(positionX,positionY,25*scaleX,sizeY,0,0,25,174,dxLib.imageURL.."button.png",0,0,0,tocolor(red,green,blue,alpha*dxLib.globalAlpha),postGUI)
		dxDrawImageSection(positionX-25*scaleX+sizeX,positionY,25*scaleX,sizeY,907,0,25,174,dxLib.imageURL.."button.png",0,0,0,tocolor(red,green,blue,alpha*dxLib.globalAlpha),postGUI)
		dxDrawImageSection(positionX+25*scaleX,positionY,sizeX-50*scaleX,sizeY,26,0,1,174,dxLib.imageURL.."button.png",0,0,0,tocolor(red,green,blue,alpha*dxLib.globalAlpha),postGUI)
		if not getElementData(buttonElement,"dxButtonClick") then
			dxDrawText(buttonLabel,positionX,positionY,positionX+sizeX+1,positionY+sizeY+2,tocolor(0,0,0,alpha*dxLib.globalAlpha),labelSize,dxLib.font,"center","center",true,false,postGUI,coloredLabel or false)
			dxDrawText(buttonLabel,positionX,positionY,positionX+sizeX,positionY+sizeY,tocolor(lR,lG,lB,alpha*dxLib.globalAlpha),labelSize,dxLib.font,"center","center",true,false,postGUI,coloredLabel or false)
		else
			dxDrawText(buttonLabel,positionX,positionY,positionX+sizeX+1,positionY+sizeY+2,tocolor(0,0,0,alpha/1.2*dxLib.globalAlpha),labelSize,dxLib.font,"center","center",true,false,postGUI,coloredLabel or false)
			dxDrawText(buttonLabel,positionX,positionY,positionX+sizeX,positionY+sizeY,tocolor(lR,lG,lB,alpha/1.2*dxLib.globalAlpha),labelSize,dxLib.font,"center","center",true,false,postGUI,coloredLabel or false)
		end
	end
	setElementData(buttonElement,"dxButtonClick",false,false)
end


function dxLibCreateGridlist(gridlistElement,gridlistData,positionX,positionY,sizeX,sizeY,fontSize,emptyString,colorRed,colorGreen,colorBlue,alphaGridlist,coloredLabels,postGUI)
	if not getElementData(gridlistElement,"dxGridlistCreate") then
		setElementData(gridlistElement,"dxGridlistCreate",true,false)
		setElementData(gridlistElement,"dxGridlistScroll",0,false)
		setElementData(gridlistElement,"dxGridlistScrollTo",0,false)
		setElementData(gridlistElement,"dxGridlistSelected",0,false)
		setElementData(gridlistElement,"dxGridlistDataCount",1,false)
		setElementData(gridlistElement,"dxGridlistHover",false,false)
		setElementData(gridlistElement,"dxGridlistDataHover",false,false)
		setElementData(gridlistElement,"dxGridlistTick",getTickCount(),false)
		setElementData(gridlistElement,"dxGridlistScrollHover",false,false)
		setElementData(gridlistElement,"dxGridlistScrollClicked",false,false)
		setElementData(gridlistElement,"dxGridlistDatatable",gridlistData,false)
		local renderTarget = dxCreateRenderTarget(sizeX,sizeY,true)
		setElementData(gridlistElement,"dxGridlistRenderTarget",renderTarget,false)
		return
	end
	if type(gridlistData) == "table" then
		local dataCount = getElementData(gridlistElement,"dxGridlistDataCount")
		if dataCount ~= #gridlistData then
			setElementData(gridlistElement,"dxGridlistDataCount",#gridlistData,false)
			setElementData(gridlistElement,"dxGridlistDatatable",gridlistData,false)
		end
		if getElementData(gridlistElement,"dxGridlistSelected") > #gridlistData then
			setElementData(gridlistElement,"dxGridlistSelected",0,false)
		end
	else
		outputDebugString("dxLib: Data for gridlist must be a table value!")
		return
	end
	setElementData(gridlistElement,"dxGridlistHover",false,false)
	if isCursorHover(positionX,positionY,sizeX,sizeY) then
		setElementData(gridlistElement,"dxGridlistHover",true,false)
	end
	local renderTarget = getElementData(gridlistElement,"dxGridlistRenderTarget")
	if renderTarget then
		local rowSize = dxGetFontHeight(fontSize,dxLib.font)+10
		local gridlistTick = getElementData(gridlistElement,"dxGridlistTick")
		local scroll = getElementData(gridlistElement,"dxGridlistScroll")
		local scrollTo = getElementData(gridlistElement,"dxGridlistScrollTo")
		local visibleRows = sizeY/rowSize
		if #gridlistData*rowSize > sizeY then
			if scrollTo < 0 then
				scrollTo = 0
				setElementData(gridlistElement,"dxGridlistScrollTo",0,false)
			elseif scrollTo > #gridlistData-visibleRows then
				scrollTo = #gridlistData-visibleRows
				setElementData(gridlistElement,"dxGridlistScrollTo",#gridlistData-visibleRows,false)
			end
			if scroll ~= scrollTo then
				local tick = getTickCount() - gridlistTick
				local progress = tick/500
				if progress >= 1 then progress = 1 end
				scroll = interpolateBetween(scroll,0,0,scrollTo,0,0,progress,"Linear")
				setElementData(gridlistElement,"dxGridlistScroll",scroll,false)
			end
		else
			scroll = 0
			setElementData(gridlistElement,"dxGridlistScroll",0,false)
			setElementData(gridlistElement,"dxGridlistScrollTo",0,false)
		end
		local scrollPosition = rowSize*scroll
		dxSetRenderTarget(renderTarget)
		dxDrawRectangle(0,0,sizeX,sizeY,tocolor(15,15,15,160))
		setElementData(gridlistElement,"dxGridlistDataHover",false,false)
		local selectedRow = getElementData(gridlistElement,"dxGridlistSelected")
		if #gridlistData ~= 0 then
			for id,dataPart in pairs(gridlistData) do
				if (positionY+(rowSize*(id-1))-scrollPosition)>=positionY-rowSize and (positionY+(rowSize*(id-1))-scrollPosition)<=positionY+sizeY+rowSize then
					if isCursorHover(positionX,positionY+(rowSize*(id-1))-scrollPosition,sizeX,rowSize) and getElementData(gridlistElement,"dxGridlistHover") then
						setElementData(gridlistElement,"dxGridlistDataHover",id,false)
						if selectedRow == id then
							dxDrawRectangle(0,rowSize*(id-1)-scrollPosition,sizeX,rowSize,tocolor(colorRed,colorGreen,colorBlue,220),false)
							dxDrawText(tostring(dataPart),5,rowSize*(id-1)+5-scrollPosition,sizeX,rowSize*id-5-scrollPosition,tocolor(255,255,255,255),fontSize,dxLib.font,"left","center",true,false,false,true)
						else
							dxDrawRectangle(0,rowSize*(id-1)-scrollPosition,sizeX,rowSize,tocolor(50,50,50,200),false)
							dxDrawText(tostring(dataPart),5,rowSize*(id-1)+5-scrollPosition,sizeX,rowSize*id-5-scrollPosition,tocolor(255,255,255,255),fontSize,dxLib.font,"left","center",true,false,false,true)
						end
					else
						if selectedRow == id then
							dxDrawRectangle(0,rowSize*(id-1)-scrollPosition,sizeX,rowSize,tocolor(colorRed,colorGreen,colorBlue,200),false)
							dxDrawText(tostring(dataPart),5,rowSize*(id-1)+5-scrollPosition,sizeX,rowSize*id-5-scrollPosition,tocolor(255,255,255,255),fontSize,dxLib.font,"left","center",true,false,false,true)
						else
							dxDrawRectangle(0,rowSize*(id-1)-scrollPosition,sizeX,rowSize,tocolor(20,20,20,150),false)
							dxDrawText(tostring(dataPart),5,rowSize*(id-1)+5-scrollPosition,sizeX,rowSize*id-5-scrollPosition,tocolor(255,255,255,255),fontSize,dxLib.font,"left","center",true,false,false,true)
						end
					end
				end
			end
		else
			dxDrawText(tostring(emptyString),6,4,sizeX,rowSize-5,tocolor(0,0,0,255),fontSize,dxLib.font,"left","center",true,false,false,true)
			dxDrawText(tostring(emptyString),5,5,sizeX,rowSize-5,tocolor(200,15,15,255),fontSize,dxLib.font,"left","center",true,false,false,true)
		end
		dxSetRenderTarget()
		dxDrawImage(positionX,positionY,sizeX,sizeY,renderTarget,0,0,0,tocolor(255,255,255,alphaGridlist or 255),postGUI or false)
		dxDrawLine(positionX,positionY,positionX+sizeX,positionY,tocolor(0,0,0,alphaGridlist or 255),1,postGUI or false)
		dxDrawLine(positionX,positionY+sizeY,positionX+sizeX,positionY+sizeY,tocolor(0,0,0,alphaGridlist or 255),1,postGUI or false)
		dxDrawLine(positionX+sizeX,positionY,positionX+sizeX,positionY+sizeY,tocolor(0,0,0,alphaGridlist or 255),1,postGUI or false)
		dxDrawLine(positionX,positionY,positionX,positionY+sizeY,tocolor(0,0,0,alphaGridlist or 255),1,postGUI or false)
		local scrollBar = {}
		if #gridlistData*rowSize > sizeY then
			scrollBar.size = (sizeY-(sizeY/3))/(#gridlistData-visibleRows)
			if scrollBar.size<=sizeY/8 then
				scrollBar.size = sizeY/8
			end
			scrollBar.position = ((sizeY-scrollBar.size)/(#gridlistData-visibleRows))*scroll
			dxDrawRectangle(positionX+sizeX+1,positionY,sX*0.02,sizeY,tocolor(40,40,40,100*((alphaGridlist or 255)/255)),postGUI)
			dxDrawRectangle(positionX+sizeX+1,positionY+scrollBar.position,sX*0.02,scrollBar.size,tocolor(colorRed,colorGreen,colorBlue,255*((alphaGridlist or 255)/255)),postGUI)
			if getElementData(gridlistElement,"dxGridlistScrollClicked") then
				if getKeyState("mouse1") then
					local x,y = getCursorPosition()
					local x,y = x*sX,y*sY
					local newPos = y-positionY
					local barSize = (((#gridlistData-visibleRows)*rowSize)*(newPos/sizeY))/rowSize
					setElementData(gridlistElement,"dxGridlistScroll",barSize,false)
					setElementData(gridlistElement,"dxGridlistScrollTo",barSize,false)
				else
					setElementData(gridlistElement,"dxGridlistScrollClicked",false,false)
				end
			else
				if isCursorHover(positionX+sizeX,positionY+scrollBar.position,sX*0.02,scrollBar.size) then
					setElementData(gridlistElement,"dxGridlistScrollHover",true,false)
				else
					setElementData(gridlistElement,"dxGridlistScrollHover",false,false)
				end
			end
		end
	else
		outputDebugString("dxLib: Cant find a render target")
	end
end


function dxLibCreateEdit(editElement,positionX,positionY,sizeX,sizeY,defaultText,iconImage,colorRed,colorGreen,colorBlue,editAlpha,postGUI,maskedText)
	if not getElementData(editElement,"dxEditCreated") then
		setElementData(editElement,"dxEditCreated",true,false)
		setElementData(editElement,"dxEditTextCache","",false)
		setElementData(editElement,"dxEditHover",false,false)
		setElementData(editElement,"dxEditActive",false,false)
		setElementData(editElement,"dxEditSelected",false,false)
		local fontSize = 0
		local findedSize = false
		local i = 0
		local fontSizeCache = 0
		repeat
			i = i+0.1
			fontSizeCache = fontSize
			fontSize = dxGetFontHeight(i,dxLib.font)
			if fontSize>=(sizeY-(sY*0.01)) then
				findedSize = true
			end
		until findedSize
		setElementData(editElement,"dxEditTextSize",i,false)
		return
	end
	local fontSize = getElementData(editElement,"dxEditTextSize")
	local postGUI = postGUI or false
	if isCursorHover(positionX,positionY,sizeX,sizeY) then
		setElementData(editElement,"dxEditHover",true,false)
	else
		setElementData(editElement,"dxEditHover",false,false)
	end
	if getElementData(editElement,"dxEditActive") or getElementData(editElement,"dxEditHover") then
		dxDrawRectangle(positionX,positionY,sizeX,sizeY,tocolor(255,255,255,255*(editAlpha/255)),postGUI)
		dxDrawLine(positionX,positionY,positionX,positionY+sizeY,tocolor(0,0,0,255*(editAlpha/255)),1,postGUI)
		dxDrawLine(positionX+sizeX,positionY,positionX+sizeX,positionY+sizeY,tocolor(0,0,0,255*(editAlpha/255)),1,postGUI)
		dxDrawLine(positionX,positionY,positionX+sizeX,positionY,tocolor(0,0,0,255*(editAlpha/255)),1,postGUI)
		dxDrawLine(positionX,positionY+sizeY,positionX+sizeX,positionY+sizeY,tocolor(0,0,0,255*(editAlpha/255)),1,postGUI)
		local textPos = sY*0.005
		if getElementData(editElement,"dxEditActive") then
			local defaultText = tostring(getElementData(editElement,"dxEditTextCache"))
			if dxGetTextWidth(defaultText,fontSize,dxLib.font) > (positionX+sizeX-sY*0.005)-(positionX+textPos) then
				if getElementData(editElement,"dxEditSelected") then
					dxDrawRectangle(positionX+textPos,positionY+sY*0.005,(positionX+sizeX-sY*0.005)-(positionX+textPos),sizeY-sY*0.01,tocolor(200,200,200,255*(editAlpha/255)*dxLib.globalAlpha),postGUI)
				end
				if maskedText then
					local defaultText = string.rep("*",string.len(defaultText))
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
				else
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
				end
				dxDrawLine(positionX+sizeX-sY*0.01,positionY+sY*0.005,positionX+sizeX-sY*0.01,positionY+sizeY-sY*0.005,tocolor(0,0,0,255*(editAlpha/255)*dxLib.globalAlpha),2,postGUI)
			else
				if getElementData(editElement,"dxEditSelected") then
					dxDrawRectangle(positionX+textPos,positionY+sY*0.005,dxGetTextWidth(defaultText,fontSize,dxLib.font),sizeY-sY*0.01,tocolor(200,200,200,255*(editAlpha/255)*dxLib.globalAlpha),postGUI)
				end
				if maskedText then
					local defaultText = string.rep("*",string.len(defaultText))
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
				else
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
				end
				if maskedText then
					local defaultText = string.rep("*",string.len(defaultText))
					dxDrawLine(positionX+textPos+dxGetTextWidth(defaultText,fontSize,dxLib.font),positionY+sY*0.005,positionX+textPos+dxGetTextWidth(defaultText,fontSize,dxLib.font),positionY+sizeY-sY*0.005,tocolor(0,0,0,255*(editAlpha/255)*dxLib.globalAlpha),2,postGUI)
				else
					dxDrawLine(positionX+textPos+dxGetTextWidth(defaultText,fontSize,dxLib.font),positionY+sY*0.005,positionX+textPos+dxGetTextWidth(defaultText,fontSize,dxLib.font),positionY+sizeY-sY*0.005,tocolor(0,0,0,255*(editAlpha/255)*dxLib.globalAlpha),2,postGUI)
				end
			end
			local charPressed = checkPressedKey()
			if charPressed ~= "" then
				if charPressed == "backspace" then
					defaultText = string.sub(defaultText,1,string.len(defaultText)-1)
					setElementData(editElement,"dxEditTextCache",defaultText,false)
					triggerEvent("onDxLibEditChange",getResourceRootElement(getThisResource()),editElement)
					if getElementData(editElement,"dxEditSelected") then 
						setElementData(editElement,"dxEditTextCache","",false)
						setElementData(editElement,"dxEditSelected",false,false)
					end
				else
					if not getElementData(editElement,"dxEditSelected") and not (getKeyState("lctrl") or getKeyState("rctrl")) then
						setElementData(editElement,"dxEditTextCache",defaultText..charPressed,false)
						triggerEvent("onDxLibEditChange",getResourceRootElement(getThisResource()),editElement)
					elseif not (getKeyState("lctrl") or getKeyState("rctrl")) then
						setElementData(editElement,"dxEditTextCache",charPressed,false)
						setElementData(editElement,"dxEditSelected",false,false)
						triggerEvent("onDxLibEditChange",getResourceRootElement(getThisResource()),editElement)
					end
				end
			end
			if (getKeyState("lctrl") or getKeyState("rctrl")) and getKeyState("a") then
				setElementData(editElement,"dxEditSelected",true,false)
			end
		else
			if getElementData(editElement,"dxEditTextCache") == "" then
				if dxGetTextWidth(defaultText,fontSize,dxLib.font) > (positionX+sizeX-sY*0.005)-(positionX+textPos) then
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"right","center",true,false,postGUI)
				else
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
				end
			else
				local defaultText = tostring(getElementData(editElement,"dxEditTextCache"))
				if maskedText then
					defaultText = string.rep("*",string.len(defaultText))
				end
				if dxGetTextWidth(defaultText,fontSize,dxLib.font) > (positionX+sizeX-sY*0.005)-(positionX+textPos) then
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"right","center",true,false,postGUI)
				else
					dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,255*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
				end
			end
		end
	else
		dxDrawRectangle(positionX,positionY,sizeX,sizeY,tocolor(220,220,220,220*(editAlpha/255)),postGUI)
		dxDrawLine(positionX,positionY,positionX,positionY+sizeY,tocolor(0,0,0,220*(editAlpha/255)),1,postGUI)
		dxDrawLine(positionX+sizeX,positionY,positionX+sizeX,positionY+sizeY,tocolor(0,0,0,220*(editAlpha/255)),1,postGUI)
		dxDrawLine(positionX,positionY,positionX+sizeX,positionY,tocolor(0,0,0,220*(editAlpha/255)),1,postGUI)
		dxDrawLine(positionX,positionY+sizeY,positionX+sizeX,positionY+sizeY,tocolor(0,0,0,220*(editAlpha/255)),1,postGUI)
		local textPos = sY*0.005
		if getElementData(editElement,"dxEditTextCache") == "" then
			if dxGetTextWidth(defaultText,fontSize,dxLib.font) > (positionX+sizeX-sY*0.005)-(positionX+textPos) then
				dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,220*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"right","center",true,false,postGUI)
			else
				dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,220*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
			end
		else
			local defaultText = tostring(getElementData(editElement,"dxEditTextCache"))
			if maskedText then
				defaultText = string.rep("*",string.len(defaultText))
			end
			if dxGetTextWidth(defaultText,fontSize,dxLib.font) > (positionX+sizeX-sY*0.005)-(positionX+textPos) then
				dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,220*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"right","center",true,false,postGUI)
			else
				dxDrawText(defaultText,positionX+textPos,positionY+sY*0.005,positionX+sizeX-sY*0.005,positionY+sizeY-sY*0.005,tocolor(colorRed,colorGreen,colorBlue,220*(editAlpha/255)*dxLib.globalAlpha),fontSize,dxLib.font,"left","center",true,false,postGUI)
			end
		end
	end
end


function isCursorHover(posX,posY,sizeX,sizeY)
	local x,y = 0,0
	if isCursorShowing() then x,y = getCursorPosition() x,y = sX*x,sY*y else return false end
	if x>=posX and x<=posX+sizeX and y>=posY and y<=posY+sizeY then
		return true
	else
		return false
	end
end


function onDxLibPlayerClick(button,state)
	if isCursorShowing() then
		if button == "left" and state == "down" then
			for i,dxButton in pairs(getElementsByType("dxButton")) do
				if getElementData(dxButton,"dxButtonHover") then
					setElementData(dxButton,"dxButtonClick",true,false)
					triggerEvent("onDxLibButtonClick",getRootElement(),dxButton)
					--outputDebugString("Triggering event: \"onDxLibButtonClick\"",0,100,100,100)
					setElementData(dxButton,"dxButtonHover",false,false)
				end
			end
			for i,dxGridlist in pairs(getElementsByType("dxGridlist")) do
				if getElementData(dxGridlist,"dxGridlistHover") then
					if getElementData(dxGridlist,"dxGridlistDataHover") then
						setElementData(dxGridlist,"dxGridlistSelected",tonumber(getElementData(dxGridlist,"dxGridlistDataHover")),false)
						triggerEvent("onDxLibGridlistClick",getRootElement(),dxGridlist)
					end
				elseif getElementData(dxGridlist,"dxGridlistScrollHover") then
					setElementData(dxGridlist,"dxGridlistScrollClicked",true,false)
				end
			end
			for i,dxEdit in pairs(getElementsByType("dxEdit")) do
				if getElementData(dxEdit,"dxEditHover") then
					setElementData(dxEdit,"dxEditActive",true,false)
					setElementData(dxEdit,"dxEditSelected",false,false)
				elseif getElementData(dxEdit,"dxEditActive") and not getElementData(dxEdit,"dxEditHover") then
					setElementData(dxEdit,"dxEditActive",false,false)
				end
			end
		end
	end
end
addEventHandler("onClientClick",getRootElement(),onDxLibPlayerClick)


function onDxLibMouseScroll(keyPressed)
	if keyPressed == "mouse_wheel_up" then
		for i,dxGridlist in pairs(getElementsByType("dxGridlist")) do
			if getElementData(dxGridlist,"dxGridlistHover") then
				setElementData(dxGridlist,"dxGridlistTick",getTickCount(),false)
				setElementData(dxGridlist,"dxGridlistScrollTo",getElementData(dxGridlist,"dxGridlistScrollTo")-(3),false)
			end
		end
		triggerEvent("onDxLibScrollMouse",getRootElement(),"up")
	elseif keyPressed == "mouse_wheel_down" then
		for i,dxGridlist in pairs(getElementsByType("dxGridlist")) do
			if getElementData(dxGridlist,"dxGridlistHover") then
				setElementData(dxGridlist,"dxGridlistTick",getTickCount(),false)
				setElementData(dxGridlist,"dxGridlistScrollTo",getElementData(dxGridlist,"dxGridlistScrollTo")+(3),false)
			end
		end
		triggerEvent("onDxLibScrollMouse",getRootElement(),"down")
	end
end
bindKey("mouse_wheel_up","down",onDxLibMouseScroll)
bindKey("mouse_wheel_down","down",onDxLibMouseScroll)


keysTable = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
			"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z","backspace","num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
			"num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sub", "num_div", "num_dec","space","[", "]", ";", ",", "-", ".", "/", "#", "\\", "=","'"
} 
shiftTable = {")","!","@","#","$","%","^","&","*","("}

keyState = {}

function checkPressedKey()
	for i,key in ipairs(keysTable) do
		if getKeyState(key) then
			if true then
				if not keyState[i] then
					keyState[i] = getTickCount() + 500
					if key == "num_0" then return "0"
					elseif key == "num_1" then return "1"
					elseif key == "num_2" then return "2"
					elseif key == "num_3" then return "3"
					elseif key == "num_4" then return "4"
					elseif key == "num_5" then return "5"
					elseif key == "num_6" then return "6"
					elseif key == "num_7" then return "7"
					elseif key == "num_8" then return "8"
					elseif key == "num_9" then return "9"
					elseif key == "num_add" then return "+"
					elseif key == "num_sub" then return "-"
					elseif key == "num_div" then return "/"
					elseif key == "num_mul" then return "*"
					elseif key == "num_dec" then return ","
					elseif key == "space" then return " "
					else
						if not (getKeyState("lshift") or getKeyState("rshift")) then
							return key
						else
							if tonumber(key) then
								return shiftTable[tonumber(key)+1]
							else
								if key == '\\' then return "|" 
								elseif key == '[' then return "{" 
								elseif key == ']' then return "}" 
								elseif key == '-' then return "_" 
								elseif key == '=' then return "+" 
								elseif key == '/' then return "?" 
								elseif key == '.' then return "<"
								elseif key == '`' then return "~"
								elseif key == ',' then return ">"
								else
									return string.upper(key)
								end
							end
						end
					end
				elseif keyState[i] and keyState[i] < getTickCount() then
					keyState[i] = getTickCount()+100
					if key == "num_0" then return "0"
					elseif key == "num_1" then return "1"
					elseif key == "num_2" then return "2"
					elseif key == "num_3" then return "3"
					elseif key == "num_4" then return "4"
					elseif key == "num_5" then return "5"
					elseif key == "num_6" then return "6"
					elseif key == "num_7" then return "7"
					elseif key == "num_8" then return "8"
					elseif key == "num_9" then return "9"
					elseif key == "num_add" then return "+"
					elseif key == "num_sub" then return "-"
					elseif key == "num_div" then return "/"
					elseif key == "num_mul" then return "*"
					elseif key == "num_dec" then return ","
					elseif key == "space" then return " "
					else
						if not (getKeyState("lshift") or getKeyState("rshift")) then
							return key
						else
							if tonumber(key) then
								return shiftTable[tonumber(key)+1]
							else
								if key == '\\' then return "|" 
								elseif key == '[' then return "{" 
								elseif key == ']' then return "}" 
								elseif key == '-' then return "_" 
								elseif key == '=' then return "+" 
								elseif key == '/' then return "?" 
								elseif key == '.' then return "<"
								elseif key == '`' then return "~"
								elseif key == ',' then return ">"
								else
									return string.upper(key)
								end
							end
						end
					end
				end
			else
				return ""
			end
		else
			keyState[i] = false
		end
	end
	return ""
end


function dxLibEditGetText(editElement)
	if isElement(editElement) or not getElementData(editElement,"dxEditCreated") then
		return tostring(getElementData(editElement,"dxEditTextCache"))
	else
		outputDebugString("dxLib: Bad element!")
	end
end


function dxLibEditSetText(editElement,stringToSet)
	if isElement(editElement) then
		setElementData(editElement,"dxEditTextCache",stringToSet,false)
	else
		outputDebugString("dxLib: Bad element!")
	end
end


function dxLibGridlistGetSelectedRowText(gridlistElement)
	if isElement(gridlistElement) or not getElementData(gridlistElement,"dxGridlistCreate") then
		if getElementData(gridlistElement,"dxGridlistSelected") and getElementData(gridlistElement,"dxGridlistSelected") ~= 0 then
			local data = getElementData(gridlistElement,"dxGridlistDatatable")
			local row = tonumber(getElementData(gridlistElement,"dxGridlistSelected"))
			local gridlistData = data[row]
			return gridlistData
		else
			return false
		end
	else
		outputDebugString("dxLib: Bad element!")
	end
end

function dxLibGridlistGetSelectedRowNumber(gridlistElement)
	if isElement(gridlistElement) or not getElementData(gridlistElement,"dxGridlistCreate") then
		if getElementData(gridlistElement,"dxGridlistSelected") then
			local row = tonumber(getElementData(gridlistElement,"dxGridlistSelected"))
			if row then
				return row
			else
				return false
			end
		else
			return false
		end
	else
		outputDebugString("dxLib: Bad element!")
	end
end


function findFontSize(dxFont,toSize)
	local fontSize = 0
	local relativeSize = 0
	local perLoop = 0.01
	repeat
		fontSize = fontSize+perLoop
		relativeSize = dxGetFontHeight(fontSize,dxFont)
	until relativeSize>=toSize
	fontSize = fontSize - perLoop
	return fontSize
end

--[[local button = createElement("dxButton")
local gridlist = createElement("dxGridlist")
local edit = createElement("dxEdit")

gridData = {}


for i=1,2000 do
	gridData[i] = " "..i
end

showCursor(true)

function test()
	dxLibCreateButton(button,350,760,400,50,"Find me!",3,255,0,120,0,255,0,255,false)
	dxLibCreateGridlist(gridlist,gridData,350,150,400,600,3,50,0,255,255)
	dxLibCreateEdit(edit,350,100,400,40,"Search player...","person",50,50,50,255)
end
addEventHandler("onClientRender",getRootElement(),test)]]


--####################################################################
--##		Copyrights © & ™ All rights reserved, Apple 2013.		##
--####################################################################


fileDelete('dx_lib.lua') 

 

 

 

 

 

--[[--------------------------------------------------
	GUI Editor
	client
	dx_editbox.lua
	
	creates a dx editbox widget for use in the right click menus
--]]--------------------------------------------------

local gKeysPressed = {}
local gCapslock = false

DX_Editbox = {}
DX_Editbox.__index = DX_Editbox
DX_Editbox.instances = {}
DX_Editbox.inUse = 
	function()
		for _,e in ipairs(DX_Editbox.instances) do
			if e:visible() and e.edit then
				return true
			end
		end
		
		return false
	end


function DX_Editbox:create(x, y, w, h, text)
	local new = setmetatable(
		{
			x = x,
			y = y,
			width = w,
			height = h,
			text = text,
			scale = 1,
			font = "default",
			alignment = {
				horizontal = "left",
				vertical = "top"
			},
			textColour = {255, 255, 255, 255},
			backgroundEditColour = {255, 255, 255, 50},
			highlightColour = {255, 255, 255, 50},
			caratColour = {0, 0, 200, 255},
			caratBlink = 0,
			filter = gFilters.characters,
			visible_ = false,
			postGUI = true,
			enabled_ = true,
			selected = {},
		},
		DX_Editbox
	)
	
	DX_Editbox.instances[#DX_Editbox.instances + 1] = new
	
	return new
end


function DX_Editbox:getEditableTextDimensions()
	if self.replace then
		local s,e = string.find(self.text, self.replace, 0, false)
		
		if s and e then
			local text = self.text
			local height = dxGetFontHeight(self.scale, self.font)
			local startY = self.y
			
			local prefix = string.sub(text, 1, s - 1)
			local suffix = string.sub(text, e + 1)
			-- find all instances of \n before the %value match
			local _, count = string.gsub(prefix, "\n", "")
			if count and count > 0 then
		
				startY = startY + (height * count)
				
				local s2, e2 = string.find(string.reverse(prefix), "\n", 0, false)
				
				outputDebug("find in (".. string.reverse(prefix) ..") "..tostring(s2), "MULTILINE_EDITBOX")

				if s2 and e2 then
					prefix = string.sub(prefix, -s2)
					outputDebug("prefix: '"..tostring(prefix).."'", "MULTILINE_EDITBOX")
				end
			end
			
			-- count all instances of \n after the %value match
			_, count2 = string.gsub(suffix, "\n", "")

			local startX = dxGetTextWidth(prefix, self.scale, self.font) + self.x			
			local width = dxGetTextWidth(self.edit and self.edit.text or self:getReplacement(), self.scale, self.font)
			
			
			if self.alignment.vertical == "center" then
				startY = (self.y + (self.height / 2)) - ((height * (count + 1 + count2)) / 2) + (height * count)
			-- multi line won't work with this alignment - here's my number, fix later maybe
			elseif self.alignment.vertical == "bottom" then
				startY = self.y + self.height - height
			end
			
			width = math.min(width, self.width - (startX - self.x))
						
			local buffer = 1
			
			return startX - buffer, startY, width + (buffer * 2), height
		else
			--outputDebugString("DX_Editbox:getEditableTextDimensions: error looking for '"..tostring(self.replace).."' in '"..tostring(self.text).."'")
		end	
	end
	
	return self.x, self.y, self.width, self.height
end


function DX_Editbox:getEditCaratPosition()
	return self:getPositionFromCharacterIndex(self.edit.carat)
end


function DX_Editbox:getPositionFromCharacterIndex(index)
	if self.edit then
		local text = string.sub(self.edit.text, 0, index)
		local width = dxGetTextWidth(text, self.scale, self.font)
		
		if width > 0 then
			--width = width + 2
		end
		
		return width
	end	
end


function DX_Editbox:visible(v)
	if v ~= nil then
		self.visible_ = v
	else
		return self.visible_
	end
end


function DX_Editbox:position(x, y)
	if x then
		self.x = x
		self.y = y
	else
		return self.x, self.y
	end
end


function DX_Editbox:size(width, height)
	if width then
		self.width = width
		self.height = height
	else
		return self.width, self.height
	end
end


function DX_Editbox:enabled(value)
	if value ~= nil then
		self.enabled_ = value
	else
		return self.enabled_
	end
end


function DX_Editbox:setReplacement(replace, replaceWith, ...)
	self.replace = replace
	self.replaceWith = replaceWith
	self.replaceWithArgs = {...}
end


function DX_Editbox:getReplacement()
	if self.replaceWithArgs then
		return self.replaceWith(unpack(self.replaceWithArgs))
	else
		return self.replaceWith()
	end
	
	return 
end


function DX_Editbox:startEditing(x, y, w, h)	
	self.edit = {}
																	
	self.edit.x = x
	self.edit.y = y
	self.edit.w = w
	self.edit.h = h
	self.edit.editable = true

	if self.replace then
		self.edit.text = tostring(self:getReplacement())
	else
		self.edit.text = self.text
	end
									
	self.edit.carat = #self.edit.text
	
	if self.onEditStart then
		self.onEditStart()
	end
	
	guiSetInputMode("no_binds")
end


function DX_Editbox:stopEditing()
	if not self.edit then
		return
	end
	
	if self.replace then
		
	else
		self.text = self.edit.text
	end

	if self.onEditStop then
		self.onEditStop(self)
	end

	self.edit = nil
	self.selected = {}
		
	if not DX_Editbox.inUse() then
		guiSetInputMode(gDefaultInputMode)
	end		
	
	if self.onEditStopped then
		self.onEditStopped(self)
	end	
end


function DX_Editbox:onEditedHandler(added)
	if added and not filterInput(self.filter, self.edit.text) then
		self.edit.text = string.sub(self.edit.text, 0, self.edit.carat - 1) .. string.sub(self.edit.text, self.edit.carat +  1)
		self.edit.carat = self.edit.carat - 1
		return
	end

	self.edit.x, self.edit.y, self.edit.w, self.edit.h = self:getEditableTextDimensions()

	if self.onEdited then
		self.onEdited(self)
	end
end


function DX_Editbox:setCaratBlink(alpha)
	self.caratBlink = getTickCount()
	
	if alpha then
		self.caratColour[4] = alpha
	else
		self.caratColour[4] = self.caratColour[4] > 0 and 0 or 255
	end
end


function DX_Editbox:draw()
	if self:visible() then		
		if self.edit then
			dxDrawRectangle(self.edit.x, self.edit.y, self.edit.w, self.edit.h, tocolor(unpack(self.backgroundEditColour)), self.postGUI)

			local w,_,_,_ = self:getEditCaratPosition()
			
			if self.edit.x + w <= self.x + self.width then
				dxDrawLine(0,0,0,0, tocolor(255, 255, 255, 255), 0)
				dxDrawLine(self.edit.x + w, self.edit.y, self.edit.x + w, self.edit.y + self.edit.h, tocolor(unpack(self.caratColour)), 2, self.postGUI)				
			end
		end		
				
		local t = ""

		if self.replace then
			t = self.text:gsub(self.replace, self.edit and self.edit.text or self:getReplacement())
		elseif self.edit then
			t = self.edit.text
		else
			t = self.text
		end

		dxDrawText(
			t,
			--self.text:gsub(self.replace or "", (self.edit and self.edit.text) or (self.replaceWith and self.replaceWith()) or ""), 
			self.x, 
			self.y, 
			self.x + self.width, 
			self.y + self.height, 		
			tocolor(unpack(self.textColour)), 
			self.scale, 
			self.font, 
			self.alignment.horizontal, 
			self.alignment.vertical,
			true,
			false,
			self.postGUI
		)
		
		if self.edit then
			if self.selected then
				if self.selected.start and self.selected.finish then
					local x = self:getPositionFromCharacterIndex(math.min(self.selected.start, self.selected.finish))
					local w = self:getPositionFromCharacterIndex(math.max(self.selected.start, self.selected.finish)) - x
					
					dxDrawRectangle(self.edit.x + x, self.edit.y, w, self.edit.h, tocolor(unpack(self.highlightColour)), self.postGUI) 
				end
			end
			
			local w,_,_,_ = self:getEditCaratPosition()
			
			if self.edit.x + w <= self.x + self.width then
				-- fix for bizarre dx line bug
				-- random (or not so random), completely unconnected lines elsewhere on the screen were taking on the 
				-- line width of whatever line was drawn here. So draw with a width of 1 and cross our fingers it happens on something with 1 width
				dxDrawLine(0,0,0,0, tocolor(255, 255, 255, 255), 1, self.postGUI)
				
				dxDrawLine(self.edit.x + w, self.edit.y, self.edit.x + w, self.edit.y + self.edit.h, tocolor(unpack(self.caratColour)), 2, self.postGUI)					
			end
		end			
	end
end


addEventHandler("onClientDoubleClick", root,
	function(button, absoluteX, absoluteY)
		if not gEnabled then
			return
		end
	
		if not isCursorShowing() then
			return
		end
		
		if button == "left" then
			for _,editbox in ipairs(DX_Editbox.instances) do
				if editbox:visible() and editbox:enabled() then
					local x, y, w, h = editbox:getEditableTextDimensions()
										
					if absoluteX > x and absoluteX < (x + w) and
						absoluteY > y and absoluteY < (y + h) then
						if not editbox.edit then
							editbox:startEditing(x, y, w, h)
							break
						end
					else
						if editbox.edit --[[and item.mouseState == Menu.mouseStates.on]] then
							editbox:stopEditing()
							break
						end
					end
				end
			end			
		end	
	end
)



function keyPressed(button, pressed)
	if pressed then
		for _,editbox in ipairs(DX_Editbox.instances) do
			if editbox.edit and editbox:enabled() and (editbox.edit.editable == nil or editbox.edit.editable == true) then
				local used
				
				if button == "arrow_l" then
					if editbox.edit.carat > 0 then
						editbox.edit.carat = editbox.edit.carat - 1
						used = true
					end
				elseif button == "arrow_r" then
					if editbox.edit.carat < #editbox.edit.text then
						editbox.edit.carat = editbox.edit.carat + 1
						used = true
					end
				elseif button == "backspace" then
					if editbox.selected and editbox.selected.start and editbox.selected.finish and math.abs(editbox.selected.finish - editbox.selected.start) > 0 then
						editbox.edit.text = string.sub(editbox.edit.text, 0, math.min(editbox.selected.finish, editbox.selected.start)) .. string.sub(editbox.edit.text, math.max(editbox.selected.finish, editbox.selected.start) + 1)                     
						editbox.edit.carat = math.min(editbox.selected.finish, editbox.selected.start)
						editbox:onEditedHandler()
						used = true			
					elseif editbox.edit.carat > 0 then
						editbox.edit.text = string.sub(editbox.edit.text, 0, editbox.edit.carat - 1) .. string.sub(editbox.edit.text, editbox.edit.carat + 1)                     
						editbox.edit.carat = editbox.edit.carat - 1
						editbox:onEditedHandler()
						used = true
					end
				elseif button == "delete" then
					if editbox.selected and editbox.selected.start and editbox.selected.finish and math.abs(editbox.selected.finish - editbox.selected.start) > 0 then
						editbox.edit.text = string.sub(editbox.edit.text, 0, math.min(editbox.selected.finish, editbox.selected.start)) .. string.sub(editbox.edit.text, math.max(editbox.selected.finish, editbox.selected.start) + 1)                     
						editbox.edit.carat = math.min(editbox.selected.finish, editbox.selected.start)
						editbox:onEditedHandler()
						used = true					
					elseif editbox.edit.carat < #editbox.edit.text then
						editbox.edit.text = string.sub(editbox.edit.text, 0, editbox.edit.carat) .. string.sub(editbox.edit.text, editbox.edit.carat + 2)
						editbox:onEditedHandler()
						used = true
					end
				elseif button == "enter" then
					editbox:stopEditing()
				elseif button == "space" then
					if editbox.selected and editbox.selected.start and editbox.selected.finish and math.abs(editbox.selected.finish - editbox.selected.start) > 0 then
						keyPressed("delete", true)
						keyPressed("delete", false)
					end
					
					editbox.edit.text = string.insert(editbox.edit.text, " ", editbox.edit.carat)
					editbox.edit.carat = editbox.edit.carat + 1
					editbox:onEditedHandler(" ")
					used = true
				elseif button == "capslock" then
					--gCapslock = not gCapslock
				elseif button == "home" then
					editbox.edit.carat = 0
				elseif button == "end" then
					editbox.edit.carat = #editbox.edit.text
				elseif gCharacterKeys[button] or gCharacterKeys[string.lower(button)] then
					if editbox.selected and editbox.selected.start and editbox.selected.finish and math.abs(editbox.selected.finish - editbox.selected.start) > 0 then
						keyPressed("delete", true)
						keyPressed("delete", false)
					end
					
					--editbox.edit.text = string.insert(editbox.edit.text, gCapslock and string.upper(button) or button, editbox.edit.carat)
					editbox.edit.text = string.insert(editbox.edit.text, button, editbox.edit.carat)
					
					editbox.edit.carat = editbox.edit.carat + 1
					
					--editbox:onEditedHandler(gCapslock and string.upper(button) or button)
					editbox:onEditedHandler(button)
					used = true
				end
				
				if used then
					editbox:setCaratBlink(255)
					editbox.selected = {}
					
					if not gKeysPressed[button] then
						gKeysPressed[button] = getTickCount() + 500
					else
						gKeysPressed[button] = getTickCount()
					end
				end
			end
		end	
	else
		if gKeysPressed[button] then
			gKeysPressed[button] = nil
		end
	end
end
addEventHandler("onClientKey", root, 
	function(button, pressed)
		if not gEnabled then
			return
		end
	
		-- let onClientCharacter handle the single characters
		if not gCharacterKeys[button] then
			keyPressed(button, pressed)
		end
	end
)
addEventHandler("onClientCharacter", root,
	function(c)
		if not gEnabled then
			return
		end
	
		keyPressed(c, true)
		keyPressed(c, false)
	end
)


addEventHandler("onClientRender", root,
	function()
		if not gEnabled then
			return
		end
	
		local currentTick = getTickCount()
		
		for _,editbox in ipairs(DX_Editbox.instances) do
			if editbox.edit then		
				if currentTick > (editbox.caratBlink + 400) then
					editbox:setCaratBlink()
				end
			end
		end
		
		for key,tick in pairs(gKeysPressed) do
			if currentTick > (tick + 40) then
				keyPressed(key, true)
			end	
		end
	end
)


addEventHandler("onClientClick", root,
	function(button, state, absoluteX, absoluteY)
		if not gEnabled then
			return
		end
	
		if not isCursorShowing() then
			return
		end
		
		if button == "left" and state == "down" then
			for _,editbox in ipairs(DX_Editbox.instances) do	
				if editbox.edit and editbox:enabled() then	
					editbox.selected = {}
					
					local x, y, w, h = editbox:getEditableTextDimensions()
											
					--if absoluteX > x and absoluteX < (x + w) and
					--	absoluteY > y and absoluteY < (y + h) then
					if absoluteY > y and absoluteY < (y + h) then	
						local aX = absoluteX
						
						if absoluteX < x then
							aX = x
						elseif absoluteX > (x + w) then
							aX = x + w
						end
						
						local diff = aX - x
						
						for i = 1, #editbox.edit.text do
							local text = string.sub(editbox.edit.text, 0, i)
							local width = dxGetTextWidth(text, editbox.scale, editbox.font)
							
							if width > diff then							
								local char = string.sub(editbox.edit.text, i, i)
								local charWidth = dxGetTextWidth(char, editbox.scale, editbox.font)	
								
								if (width - (charWidth / 2)) > diff then
									editbox.edit.carat = i - 1
									break
								else
									editbox.edit.carat = i 
									break
								end
							end
						end
						
						editbox.dragging = {tick = getTickCount()}
						editbox.selected.start = editbox.edit.carat
					end
				end
			end	
		elseif button == "left" and state == "up" then
			for _,editbox in ipairs(DX_Editbox.instances) do
				if editbox.dragging then	
					editbox.dragging = nil
				end
			end
		end
	end
)


addEventHandler("onClientCursorMove", root,
	function(x, y, absoluteX, absoluteY)
		if not gEnabled then
			return
		end
	
		for _,editbox in ipairs(DX_Editbox.instances) do
			if editbox.dragging and editbox.edit then	
				if editbox.dragging.tick < (getTickCount() - 100) then
					local x, y, w, h = editbox:getEditableTextDimensions()
											
					if absoluteX > x and absoluteX < (x + w) and
						absoluteY > y and absoluteY < (y + h) then
						local diff = absoluteX - x
						
						for i = 1, #editbox.edit.text do
							local text = string.sub(editbox.edit.text, 0, i)
							local width = dxGetTextWidth(text, editbox.scale, editbox.font)
							
							if width > diff then							
								local char = string.sub(editbox.edit.text, i, i)
								local charWidth = dxGetTextWidth(char, editbox.scale, editbox.font)	
								
								if (width - (charWidth / 2)) > diff then
									editbox.selected.finish = i - 1
									break
								else
									editbox.selected.finish = i 
									break
								end
							end
						end	
					end
				end
			end
		end
	end
) 

 

esto es lo del dxeditbox

sigue el consejo de gothem con mucho cuidado y delicadeza te equivocas en algo y te falla el script fuerte

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Invitado
Responder a este tema...

×   Pegar como texto enriquecido.   Pegar como texto sin formato

  Only 75 emoji are allowed.

×   Tu enlace se ha incrustado automáticamente..   Mostrar como un enlace en su lugar

×   Se ha restaurado el contenido anterior.   Limpiar editor

×   No se pueden pegar imágenes directamente. Carga o inserta imágenes desde la URL.

  • Explorando recientemente   0 miembros

    • No hay usuarios registrados viendo esta página.
×
×
  • Crear nuevo...