Bc# Posted May 30, 2016 Share Posted May 30, 2016 Estoy creando una dxLib OPP, para un mejor manejo de los datos ya que las que he visto no me agradan. Quiero el apoyo de la comunidad para desarrollarla, estoy partiendo con los botones. Acepto criticas y sujerencias. dxCreateButton: Puedes crear un boton de color solido o integrarle una imagen propia. dxCreateButton.isInside(): retorna un bool que permite saber si el cursor esta dentro del boton dxCreateButton.isClicked(): retorna un bool que permite saber si el cursor fue clickeado dxCreateButton.isVisible(): retorna un bool que permite saber si el boton esta activo dxCreateButton.setVisible(bool activo): Agrega un valor para que el boton sea activo o inactivo Code: local ssX,ssY = guiGetScreenSize(); local temp = false function dxDrawButton(text,posX,posY,sizeX,sizeY,color,font,textScale,image) if not (text and posX and posY and sizeX and sizeY and color and font and textScale) then return false end local self = {text=text,posX=posX,posY=posY,sizeX=sizeX,sizeY=sizeY,color=color,font=font,textScale=textScale,image=image,visible=true} if not image then dxDrawRectangle ( self.posX,self.posY,self.sizeX,self.sizeY,self.color) dxDrawEmptyRectangle(self.posX,self.posY,self.sizeX,self.sizeY,tocolor(0,0,0,30),2,false) else dxDrawImage (self.posX,self.posY,self.sizeX,self.sizeY, self.image, 0, 0, 0, self.color ) end local fontWidth = dxGetTextWidth ( self.text, self.textScale, self.font ) local fontHeight = dxGetFontHeight ( self.textScale, self.font ) local x = (self.posX+(self.sizeX/2)) - ((fontWidth)/2) local y = (self.posY+(self.sizeY/2)) - ((fontHeight)/2) dxDrawText ( text, x+1, y+1,self.sizeX,self.sizeY, tocolor(0,0,0,100), self.textScale, self.font) dxDrawText ( text, x, y,self.sizeX,self.sizeY, tocolor(255,255,255,255), self.textScale, self.font) local isCursorInside = function() if isCI(self.posX,self.posY,self.sizeX,self.sizeY) then return true end return false end local isClicked = function () if isCI(self.posX,self.posY,self.sizeX,self.sizeY) and temp and visible then temp = false return true end return false end local isVisible = function () return self.visible end local setVisible = function (v) self.visible = v end return { isCursorInside = isCursorInside, isClicked = isClicked, isVisible = isVisible, setVisible = setVisible } end function isCI(pX,pY,sX,sY) if isCursorShowing() then local cX,cY,_,_,_ = getCursorPosition() if cX and cY then if cX >= pX/ssX and cX <= (pX+sX)/ssX and cY >= pY/ssY and cY <= (pY+sY)/ssY then return true end end end temp=false return false end addEventHandler("onClientClick", getRootElement(), function(button, state) if (button == "left" and state == "down") then temp = true end end) function dxDrawEmptyRectangle(startX, startY, endX, endY, color, width, postGUI) dxDrawLine ( startX, startY, startX+endX, startY, color, width, postGUI ) dxDrawLine ( startX, startY, startX, startY+endY, color, width, postGUI ) dxDrawLine ( startX, startY+endY, startX+endX, startY+endY, color, width, postGUI ) dxDrawLine ( startX+endX, startY, startX+endX, startY+endY, color, width, postGUI ) end Ejemplo: local color = tocolor(255,255,255,100) local text = "No Clickeado" addEventHandler( "onClientRender", root, function() local boton = dxDrawButton(text,350, 350, 150, 30,color,"default-bold",1) if boton.isCursorInside() then color = tocolor(255,255,255,200) else color = tocolor(255,255,255,100) end if boton.isClicked() then if text == "Clieckeado" then text = "No Clickeado" else text = "Clieckeado" end end end ) Link to comment
Enargy, Posted May 30, 2016 Share Posted May 30, 2016 Posteo un progressBar de mi librería personal (no está terminada pero tengo algo). dxElements = {} function progressbar(x, y, w, h, progress, color) if (progress <= 0) then progress = 0 elseif (progress >= 100) then progress = 100 end local element = createElement("GL_Progressbar") if not dxElements[element] then dxElements[element] = {x=x, y=y, w=w, h=h, progress=progress, color=color} end return element end addEventHandler("onClientRender", root, function() for _, v in ipairs(getElementChildren(getResourceDynamicElementRoot(getThisResource()))) do if v and dxElements[v] then local elementType = getElementType(v) --- BARRA DE PROGRESO; if elementType == "GL_Progressbar" then local curprogress local x, y, w, h, progress, color = dxElements[v].x, dxElements[v].y, dxElements[v].w, dxElements[v].h, dxElements[v].progress, dxElements[v].color curprogress = w * (progress/100) if (progress < 1) then curprogress = 4 end dxDrawRectangle(x, y, w, h, tocolor(10, 10, 10, 100), false) dxDrawRectangle(x+2, y+2, w-4, h-4, tocolor(100, 100, 100, 150), false) dxDrawRectangle(x+2, y+2, curprogress-4, h-4, color, false) end end end end) function dxGetProgressBar(elem) if getElementType(elem) ~= "GL_ProgressBar" then return nil end if dxElements[elem] ~= nil then return tonumber(dxElements[elem].progress) end end function dxSetProgressBar(elem, numb) if getElementType(elem) ~= "GL_ProgressBar" then return nil end if dxElements[elem] ~= nil then dxElements[elem].progress = numb end end Sintaxis · progressbar(int x, int y, int width, int height, int progress, func tocolor ) · dxGetProgressBar(element) Link to comment
Recommended Posts