Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- coded by TiM3
- local dxElements = {}
- ---------------
- -- Events
- addEvent ( "onClientDxButtonClick" )
- addEvent ( "onDxEditChanged" )
- addEvent ( "onDxEditAccepted" )
- addEvent ( "onDxEditFocus" )
- addEvent ( "onClientDxGridListSelect" )
- addEvent ( "onClientDxGridListDeselect" )
- addEvent ( "onClientDxGridListDoubleClick" )
- addEvent ( "onDxImageMouseEnter" )
- addEvent ( "onDxImageMouseLeave" )
- addEvent ( "onDxImageMouseMove" )
- addEvent ( "onDxImageMouseDown" )
- addEvent ( "onDxImageMouseUp" )
- addEvent ( "onDxCheckBoxChange" )
- addEvent ( "onDxRadioButtonChange" )
- -- ------------
- -- Creation functions
- function dxCreateWindow ( x, y, w, h, title, parent, border, headColor, mainColor )
- local element = createElement ( "dx_window" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = x+posX, y = y+posY, w = w, h = h, title = title, parent = parent, hc = tocolor(51,51,51,255), mc = tocolor(65,65,65,255), border = false, alpha = 255, visible = true} )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = w, h = h, title = title, parent = parent, hc = tocolor(51,51,51,255), mc = tocolor(65,65,65,255), border = false, alpha = 255, visible = true} )
- end
- return element
- end
- function dxCreateLabel ( x, y, w, h, text, parent, font, fontHeight, horAlign, verAlign, colorCoded )
- local element = createElement ( "dx_label" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, w = posX+x+w, h = posY+y+h, text = text, font = font, fontH = fontHeight, parent = parent, hor = horAlign, ver = verAlign, cc = colorCoded, alpha = 255, visible = dxIsElementVisible ( parent )} )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = x+w, h = y+h, text = text, font = font, fontH = fontHeight, parent = parent, hor = horAlign, ver = verAlign, cc = colorCoded, alpha = 255, visible = true} )
- end
- return element
- end
- function dxCreateButton ( x, y, w, h, text, parent, color )
- local element = createElement ( "dx_button" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, w = w, h = h, text = text, parent = parent, color = tocolor(67,205,243,255), originalColor = tocolor(67,205,243,255), alpha = 255, gui = guiCreateLabel ( posX+x, posY+y, w, h, "", false ), anim = {false,false,0}, visible = dxIsElementVisible ( parent )} ) -- anim < active, up, progress
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = w, h = h, text = text, parent = parent, color = tocolor(67,205,243,255), originalColor = tocolor(67,205,243,255), alpha = 255, gui = guiCreateLabel ( x, y, w, h, "", false ), anim = {false,false,0}, visible = true} ) -- anim < active, up, progress
- end
- addEventHandler ( "onClientMouseEnter", dxElements[#dxElements].gui, dxButtonMouseEnter, false )
- addEventHandler ( "onClientMouseLeave", dxElements[#dxElements].gui, dxButtonMouseLeave, false )
- addEventHandler ( "onClientGUIMouseDown", dxElements[#dxElements].gui, dxButtonMouseDown, false )
- addEventHandler ( "onClientGUIMouseUp", dxElements[#dxElements].gui, dxButtonMouseUp, false )
- addEventHandler ( "onClientGUIClick", dxElements[#dxElements].gui, dxButtonMouseClick, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateEdit ( x, y, w, h, text, parent, masked )
- local element = createElement ( "dx_edit" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, w = w, h = h, text = text, parent = parent, masked = masked, alpha = 255, gui = guiCreateEdit ( posX+x, posY+y, w, h, text, false ), visible = dxIsElementVisible ( parent )} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- guiEditSetMasked ( dxElements[#dxElements].gui, masked or false )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = w, h = h, text = text, parent = parent, masked = masked, alpha = 255, gui = guiCreateEdit ( x, y, w, h, text, false ), visible = true} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- guiEditSetMasked ( dxElements[#dxElements].gui, masked or false )
- end
- addEventHandler ( "onClientGUIFocus", dxElements[#dxElements].gui, dxGuiFocus, false )
- addEventHandler ( "onClientGUIBlur", dxElements[#dxElements].gui, dxGuiBlur, false )
- addEventHandler ( "onClientGUIChanged", dxElements[#dxElements].gui, dxEditChanged, false )
- addEventHandler ( "onClientGUIAccepted", dxElements[#dxElements].gui, dxEditAccepted, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateTabPanel ( parent, height, color, width, x, y ) -- limit of 1 tab panel inside of another
- local element = createElement ( "dx_tabpanel" )
- local posX, posY = dxGetElementPosition ( parent )
- local w, h = dxGetElementSize ( parent )
- table.insert ( dxElements, {element = element, x = posX+(x or 7), y = posY+(y or 32), w = width or w-14, h = height or h-39, parent = parent, color = tocolor(0,0,0,25), visible = dxIsElementVisible ( parent )} )
- return element
- end
- function dxCreateTab ( title, panel, color )
- local element = createElement ( "dx_tab" )
- local posX, posY = dxGetElementPosition ( panel )
- local w, h = dxGetElementSize ( window )
- local prevW = dxTabGetPreviousWidth ( panel )
- table.insert ( dxElements, {element = element, x = posX, y = posY, w = w, h = h, title = title, parent = panel, bx = posX+prevW, bw = dxGetTextWidth ( title, 1, "default-bold" ) + 10, color = tocolor(140,140,140,255), gui = guiCreateLabel ( posX+prevW, posY, dxGetTextWidth ( title, 1, "default-bold" ) + 10, 25, "", false ), active = false, visible = dxIsElementVisible ( panel )} )
- addEventHandler ( "onClientMouseEnter", dxElements[#dxElements].gui, dxTabMouseEnter, false )
- addEventHandler ( "onClientMouseLeave", dxElements[#dxElements].gui, dxTabMouseLeave, false )
- addEventHandler ( "onClientGUIClick", dxElements[#dxElements].gui, dxTabMouseClick, false )
- dxActivateFirstTab ( panel )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateCheckBox ( x, y, text, parent )
- local element = createElement ( "dx_checkbox" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, text = text, tw = dxGetTextWidth ( text, 1, "default" ), parent = parent, ticked = false, alpha = 255, gui = guiCreateLabel ( posX+x, posY+y, dxGetTextWidth ( text, 1, "default" ), 13, "", false ), visible = dxIsElementVisible ( parent )} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, text = text, tw = dxGetTextWidth ( text, 1, "default" ), parent = parent, ticked = false, alpha = 255, gui = guiCreateLabel ( x, y, dxGetTextWidth ( text, 1, "default" ), 13, "", false ), visible = true} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- end
- addEventHandler ( "onClientGUIClick", dxElements[#dxElements].gui, dxCheckBoxClick, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateGridList ( x, y, w, h, parent, clickable, font, headerColor, color, childColor ) -- y must be in the form |20+visibleRows*15|
- local element = createElement ( "dx_gridlist" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, w = w, h = h, by = posY+y+20, bh = h-20, parent = parent, font = font, alpha = 255, gui = guiCreateLabel ( posX+x, posY+y, w, h, "", false ), visible = dxIsElementVisible ( parent ), children = {}, clickable = clickable, headerColor = tocolor(140,140,140,255), color = tocolor(0,0,0,75), childColor = tocolor(255,255,255,25)} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = w, h = h, by = y+20, bh = h-20, parent = parent, font = font, alpha = 255, gui = guiCreateLabel ( x, y, w, h, "", false ), visible = true, children = {}, clickable = clickable, headerColor = tocolor(140,140,140,255), color = tocolor(0,0,0,75), childColor = tocolor(255,255,255,25)} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- end
- addEventHandler ( "onClientMouseEnter", dxElements[#dxElements].gui, dxGridListEnter, false )
- addEventHandler ( "onClientMouseLeave", dxElements[#dxElements].gui, dxGridListLeave, false )
- addEventHandler ( "onClientMouseMove", dxElements[#dxElements].gui, dxGridListMove, false )
- addEventHandler ( "onClientGUIClick", dxElements[#dxElements].gui, dxGridListClick, false )
- addEventHandler ( "onClientGUIMouseDown", dxElements[#dxElements].gui, dxGridListDown, false )
- addEventHandler ( "onClientGUIBlur", dxElements[#dxElements].gui, dxGridListBlur, true )
- addEventHandler ( "onClientMouseWheel", dxElements[#dxElements].gui, dxGridListMouseWheel, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateScrollBar ( x, y, s, pos, parent, color )
- local element = createElement ( "dx_scrollbar" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, maxPos = (pos == "horizontal" and posX+x+s-30 or posY+y+s-30), range = s-30, s = s, p = (pos == "horizontal" and posX+x or posY+y), pos = pos, slidePos = (pos == "horizontal" and posX+x or posY+y), parent = parent, color = tocolor(0,0,0,25), alpha = 255, gui = guiCreateLabel ( posX+x, posY+y, (pos == "horizontal" and s or 15), (pos == "horizontal" and 15 or s), "", false ), visible = dxIsElementVisible ( parent )} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, maxPos = (pos == "horizontal" and x+s-30 or y+s-30), range = s-30, s = s, p = (pos == "horizontal" and x or y), pos = pos, slidePos = (pos == "horizontal" and x or y), parent = parent, color = tocolor(0,0,0,25), alpha = 255, gui = guiCreateLabel ( x, y, (pos == "horizontal" and s or 15), (pos == "horizontal" and 15 or s), "", false ), visible = true} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- end
- addEventHandler ( "onClientGUIMouseDown", dxElements[#dxElements].gui, dxScrollBarDown, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateRadioButton ( x, y, text, parent )
- local element = createElement ( "dx_radiobutton" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, text = text, tw = dxGetTextWidth ( text, 1, "default" ), parent = parent, ticked = false, alpha = 255, gui = guiCreateLabel ( posX+x, posY+y, dxGetTextWidth ( text, 1, "default" ), 13, "", false ), visible = dxIsElementVisible ( parent )} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, text = text, tw = dxGetTextWidth ( text, 1, "default" ), parent = parent, ticked = false, alpha = 255, gui = guiCreateLabel ( x, y, dxGetTextWidth ( text, 1, "default" ), 13, "", false ), visible = true} )
- guiSetAlpha ( dxElements[#dxElements].gui, 0 )
- end
- addEventHandler ( "onClientGUIClick", dxElements[#dxElements].gui, dxRadioButtonClick, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- return element
- end
- function dxCreateRectangle ( x, y, w, h, color, parent )
- local element = createElement ( "dx_rectangle" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, w = w, h = h, color = color, parent = parent, alpha = 255, visible = dxIsElementVisible ( parent )} )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = w, h = h, color = color, parent = parent, alpha = 255, visible = true} )
- end
- return element
- end
- function dxCreateImage ( x, y, w, h, path, parent, color, gui )
- local element = createElement ( "dx_image" )
- if parent then
- local posX, posY = dxGetElementPosition ( parent )
- table.insert ( dxElements, {element = element, x = posX+x, y = posY+y, w = w, h = h, path = path, color = color, parent = parent, gui = guiCreateLabel ( posX+x, posY+y, w, h, "", false ), alpha = 255, visible = dxIsElementVisible ( parent )} )
- else
- table.insert ( dxElements, {element = element, x = x, y = y, w = w, h = h, path = path, color = color, parent = parent, gui = guiCreateLabel ( x, y, w, h, "", false ), alpha = 255, visible = true} )
- end
- if gui then
- addEventHandler ( "onClientMouseEnter", dxElements[#dxElements].gui, dxImageMouseEnter, false )
- addEventHandler ( "onClientMouseLeave", dxElements[#dxElements].gui, dxImageMouseLeave, false )
- addEventHandler ( "onClientMouseMove", dxElements[#dxElements].gui, dxImageMouseMove, false )
- addEventHandler ( "onClientGUIMouseDown", dxElements[#dxElements].gui, dxImageMouseDown, false )
- addEventHandler ( "onClientGUIMouseUp", dxElements[#dxElements].gui, dxImageMouseUp, false )
- guiSetVisible ( dxElements[#dxElements].gui, dxElements[#dxElements].visible )
- end
- return element
- end
- -- ------------
- -- Destroying functions
- function dxDestroyElementsWithParent ( parent )
- local a = {}
- for k, v in pairs ( dxElements ) do
- if v.parent == parent then
- table.insert ( a, k ) -- tabpanel
- for ke, va in pairs ( dxElements ) do
- if va.parent == v.element then -- tab
- table.insert ( a, ke )
- for key, val in pairs ( dxElements ) do
- if val.parent == va.element then -- tab body
- table.insert ( a, key )
- for kk, vv in pairs ( dxElements ) do
- if vv.parent == val.element then -- tab
- table.insert ( a, kk )
- for kkk, vvv in pairs ( dxElements ) do
- if vvv.parent == vv.element then -- tab body
- table.insert ( a, kkk )
- for kkkk, vvvv in pairs ( dxElements ) do
- if vvvv.parent == vvv.element then
- table.insert ( a, kkkk )
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- for k, v in pairs ( a ) do
- destroyElement ( dxElements[v].element )
- if dxElements[v].gui then
- destroyElement ( dxElements[v].gui )
- end
- end
- --for k, v in pairs ( a ) do
- --table.remove ( dxElements, v )
- --end
- end
- function dxDestroyElement ( element ) -- only destroys the element and not its children
- local a
- for k, v in pairs ( dxElements ) do
- if v.element == element then
- a = k
- if v.gui then
- destroyElement ( v.gui )
- end
- break
- end
- end
- table.remove ( dxElements, a )
- destroyElement ( element )
- end
- -- ------------
- -- Label functions
- function dxLabelSetText ( element, text )
- for key, val in pairs ( dxElements ) do
- if val.element == element then
- dxElements[key].text = text
- break
- end
- end
- end
- function dxLabelGetText ( element )
- for key, val in pairs ( dxElements ) do
- if val.element == element then
- return val.text
- end
- end
- return false
- end
- -- ------------
- -- Button functions
- function dxButtonMouseEnter ()
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].color = tocolor(63,214,255,255)--(dxElements[key].originalColor and (dxElements[key].originalColor-656640) or tocolor(110,165,255,255))
- end
- function dxButtonMouseLeave ()
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].color = dxElements[key].originalColor or tocolor(95,160,255,255)
- end
- function dxButtonMouseClick ( button, state )
- if button ~= "left" or state ~= "up" then return end
- -- play the sound
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onClientDxButtonClick", dxElements[key].element )
- end
- function dxButtonMouseDown ( button )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].color = tocolor(55,55,55,255)
- end
- function dxButtonMouseUp ( button )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].color = tocolor(63,214,255,255)--(dxElements[key].originalColor and (dxElements[key].originalColor-656640) or tocolor(110,165,255,255))
- end
- function dxButtonSetText ( button, text )
- for k, v in pairs ( dxElements ) do
- if v.element == button then
- dxElements[k].text = text
- break
- end
- end
- end
- -- ------------
- -- Edit functions
- function dxEditSetReadOnly ( element, boolean )
- for k, v in pairs ( dxElements ) do
- if v.element == element then
- guiEditSetReadOnly ( v.gui, boolean )
- break
- end
- end
- end
- function dxEditSetText ( element, text )
- for k, v in pairs ( dxElements ) do
- if v.element == element then
- guiSetText ( v.gui, text )
- break
- end
- end
- end
- function dxEditGetText ( element )
- for k, v in pairs ( dxElements ) do
- if v.element == element then
- return guiGetText ( v.gui )
- end
- end
- end
- -- havent updated the original lib with this
- function dxEditSetMaxLength ( element, length )
- for k, v in pairs ( dxElements ) do
- if v.element == element then
- guiEditSetMaxLength ( v.gui, length )
- break
- end
- end
- end
- function dxEditChanged ()
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxEditChanged", dxElements[key].element )
- end
- function dxEditAccepted ()
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxEditAccepted", dxElements[key].element )
- end
- -- ------------
- -- Tab functions
- function dxClearTabs ( panel )
- for k, v in pairs ( dxElements ) do
- if v.parent == panel then -- tab
- dxElements[k].active = false
- dxElements[k].color = nil
- for key, val in pairs ( dxElements ) do
- if val.parent == v.element then -- tab panel
- dxElements[key].visible = false
- if val.gui then
- guiSetVisible ( val.gui, false )
- end
- for kk, vv in pairs ( dxElements ) do
- if vv.parent == val.element then -- tab
- dxElements[kk].visible = false
- if vv.gui then
- guiSetVisible ( vv.gui, false )
- end
- for kkk, vvv in pairs ( dxElements ) do
- if vvv.parent == vv.element then -- body
- dxElements[kkk].visible = false
- if vvv.gui then
- guiSetVisible ( vvv.gui, false )
- end
- for kkkk, vvvv in pairs ( dxElements ) do
- if vvvv.parent == vvv.element then -- inner body
- dxElements[kkkk].visible = false
- if vvvv.gui then
- guiSetVisible ( vvvv.gui, false )
- end
- end
- end
- end
- end
- end
- end
- --[[
- if getElementType ( val.element ) == "dx_tabpanel" then
- for kaka, vava in pairs ( dxElements ) do
- if vava.parent == val.element and vava.gui then
- dxElements[kaka].visible = false
- guiSetVisible ( vava.gui, false )
- for keykey, valval in pairs ( dxElements ) do
- if valval.parent == vava.element and valval.gui then
- dxElements[keykey].visible = false
- guiSetVisible ( valval.gui, false )
- end
- end
- end
- end
- end
- --]]
- end
- end
- end
- end
- end
- function dxActivateFirstTab ( panel )
- for k, v in pairs ( dxElements ) do
- if v.parent == panel then
- triggerEvent ( "onClientGUIClick", v.gui, "left", "notup" )
- break
- end
- end
- end
- function dxTabGetPreviousWidth ( panel )
- local width = 5
- for k, v in pairs ( dxElements ) do
- if v.parent == panel then
- width = width + v.bw + 5
- end
- end
- return width
- end
- function dxTabMouseEnter ()
- local key = dxGetElementKeyFromGUI ( source )
- --if not dxdxIsElementVisible ( dxElements[key].element ) then return end
- if dxElements[key].active then return end
- dxElements[key].color = tocolor(150,150,150,255)--tocolor(95,160,255,255)--tocolor(110,165,255,255)--tocolor(70,163,255,255)
- end
- function dxTabMouseLeave ()
- local key = dxGetElementKeyFromGUI ( source )
- --if not dxdxIsElementVisible ( dxElements[key].element ) then return end
- if dxElements[key].active then return end
- dxElements[key].color = tocolor(140,140,140,255)--tocolor(95,160,255,255)--tocolor(51,153,255,255)
- end
- function dxTabMouseClick ( button, state )
- if button ~= "left" then return end
- -- play the sound
- local key = dxGetElementKeyFromGUI ( source )
- --if state == "up" and not dxdxIsElementVisible ( dxElements[key].element ) then return end
- dxClearTabs ( dxElements[key].parent )
- dxElements[key].active = true
- dxElements[key].color = tocolor(100,100,100,255)--tocolor(10,100,225,255)--tocolor(0,100,225,255)
- if not dxElements[key].visible then return end
- for k, v in pairs ( dxElements ) do
- if v.parent == dxElements[key].element then -- tab panel
- dxElements[k].visible = true
- if v.gui then
- guiSetVisible ( v.gui, true )
- end
- for kk, vv in pairs ( dxElements ) do
- if vv.parent == v.element then -- tab
- dxElements[kk].visible = true
- if vv.gui then
- guiSetVisible ( vv.gui, true )
- end
- if getElementType ( vv.element ) == "dx_tab" then
- if vv.active then
- for kkk, vvv in pairs ( dxElements ) do
- if vvv.parent == vv.element then
- dxElements[kkk].visible = true
- if vvv.gui then
- guiSetVisible ( vvv.gui, true )
- end
- for kkkk, vvvv in pairs ( dxElements ) do
- if vvvv.parent == vvv.element then
- dxElements[kkkk].visible = true
- if vvvv.gui then
- guiSetVisible ( vvvv.gui, true )
- end
- end
- end
- end
- end
- end
- else
- for kkk, vvv in pairs ( dxElements ) do
- if vvv.parent == vv.element then
- dxElements[kkk].visible = true
- if vvv.gui then
- guiSetVisible ( vvv.gui, true )
- end
- for kkkk, vvvv in pairs ( dxElements ) do
- if vvvv.parent == vvv.element then
- dxElements[kkkk].visible = true
- if vvvv.gui then
- guiSetVisible ( vvvv.gui, true )
- end
- end
- end
- end
- end
- end
- end
- end
- --[[
- if getElementType ( v.element ) == "dx_tabpanel" then
- for kaka, vava in pairs ( dxElements ) do
- if vava.parent == v.element and vava.gui then
- dxElements[kaka].visible = true
- guiSetVisible ( vava.gui, true )
- for keykey, valval in pairs ( dxElements ) do
- if valval.parent == vava.element and valval.gui and vava.active then
- dxElements[keykey].visible = true
- guiSetVisible ( valval.gui, true )
- end
- end
- end
- end
- end
- --]]
- end
- end
- end
- function dxTabSetTitle ( tab, title )
- for key, val in pairs ( dxElements ) do
- if val.element == tab then
- dxElements[key].title = title
- break
- end
- end
- end
- -- ------------
- -- CheckBox functions
- function dxCheckBoxClick ( button, state )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].ticked = not dxElements[key].ticked
- triggerEvent ( "onDxCheckBoxChange", dxElements[key].element, dxElements[key].ticked )
- end
- function dxCheckBoxSetTicked ( element, boolean )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- dxElements[k].ticked = boolean
- end
- end
- end
- function dxCheckBoxIsTicked ( element )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- return v.ticked
- end
- end
- return false
- end
- -- ------------
- -- RadioButton functions
- function dxRadioButtonClick ( button, state )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- if dxElements[key].parent then dxRadioButtonClearAll ( dxElements[key].parent ) end
- dxElements[key].ticked = not dxElements[key].ticked
- triggerEvent ( "onDxRadioButtonChange", dxElements[key].element, dxElements[key].ticked )
- end
- function dxRadioButtonSetTicked ( element, boolean )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- dxRadioButtonClearAll ( v.parent )
- dxElements[k].ticked = boolean
- break
- end
- end
- end
- function dxRadioButtonClearAll ( parent )
- for k, v in pairs ( dxElements ) do
- if v.parent == parent and getElementType ( v.element ) == "dx_radiobutton" then
- dxElements[k].ticked = false
- end
- end
- end
- function dxRadioButtonIsTicked ( element )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- return v.ticked
- end
- end
- return false
- end
- -- ------------
- -- GridList functions
- function dxGridListAddColumn ( gridlist, title, w, noCC )
- local key = dxGetKeyFromElement ( gridlist )
- if noCC then noCC = nil else noCC = true end
- if dxElements[key].children.columns then
- table.insert ( dxElements[key].children.columns, {title = tostring(title), w = w, cc = noCC} )
- else
- dxElements[key].children.columns = {{title = tostring(title), w = w, cc = noCC}}
- end
- return #dxElements[key].children.columns
- end
- function dxGridListAddRow ( gridlist, text )
- local key = dxGetKeyFromElement ( gridlist )
- table.insert ( dxElements[key].children, {tostring(text)} )
- -- calculate sight
- if #dxElements[key].children*15 > dxElements[key].bh then
- dxElements[key].onSight = dxElements[key].bh/15
- local invisibleRows = #dxElements[key].children-dxElements[key].onSight
- local maxHeight = dxElements[key].bh - 15/2
- local minHeight = 30
- local difference = maxHeight-minHeight
- local maxInvisibleRows = 60
- local height = maxHeight - (difference*math.min(invisibleRows,maxInvisibleRows)/maxInvisibleRows)
- dxElements[key].slider = {pos = dxElements[key].by, h = height, invRowsHeight = invisibleRows*15}
- dxElements[key].bk = 0
- -- other alternative:
- -- take 0.5 from by-20 until there's no more rows or it reaches 30
- end
- return #dxElements[key].children
- end
- function dxGridListClear ( gridlist )
- local key = dxGetKeyFromElement ( gridlist )
- dxElements[key].slider = nil
- dxElements[key].children = { columns = dxElements[key].children.columns }
- dxElements[key].bk = nil
- dxElements[key].onSight = nil
- end
- function dxGridListEnter ()
- dxGridListHandleHoverOnPosition ( source, x, y )
- end
- function dxGridListLeave ()
- -- clean hovers
- dxGridListClearHoveredRows ( dxGetElementKeyFromGUI ( source ) )
- end
- function dxGridListMove ( x, y )
- dxGridListHandleHoverOnPosition ( source, x, y )
- end
- function dxGridListClick ( button, state, x, y )
- if button ~= "left" then return end
- dxGridListHandleClickOnPosition ( source, x, y )
- end
- function dxGridListBlur ()
- dxGridListClearHoveredRows ( dxGetElementKeyFromGUI ( source ) )
- end
- function dxGridListHandleHoverOnPosition ( gui, x, y )
- local k = dxGetElementKeyFromGUI ( gui )
- --if not dxdxIsElementVisible ( dxElements[k].element ) then return end
- local v = dxElements[k]
- -- clean hovers
- dxGridListClearHoveredRows ( k )
- local baseWidth =v.w
- if v.slider then -- to be handled in onClientCursorMove
- -- adjust the body's width
- baseWidth = baseWidth-15
- end
- local baseKey = v.bk or 0 --v.tk or #v.children
- -- rows
- local entry = 0
- for key = baseKey+1, (v.onSight and baseKey+v.onSight or #v.children) do
- -- background
- if not v.children[key].selected and not v.children[key].hovered then
- if dxIsPointOnTopOfArea ( x, y, v.x, v.by+entry*15, baseWidth, 15 ) then
- v.children[key].hovered = true
- -- since the cursor can't be pointing at two element at a time there's no point in carrying on
- return
- end
- end
- entry = entry + 1
- end
- end
- function dxGridListHandleClickOnPosition ( gui, x, y )
- local k = dxGetElementKeyFromGUI ( gui )
- --if not dxdxIsElementVisible ( dxElements[k].element ) then return end
- local v = dxElements[k]
- if not v.clickable then return end
- local row = dxGridListGetSelectedRow ( v.element )
- -- clean hovers
- dxGridListClearHoveredRows ( k, true )
- local baseWidth =v.w
- if v.slider then -- to be handled in onClientCursorMove
- -- adjust the body's width
- baseWidth = baseWidth-15
- end
- local baseKey = v.bk or 0 --v.tk or #v.children
- -- rows
- local entry = 0
- for key = baseKey+1, (v.onSight and baseKey+v.onSight or #v.children) do
- -- background
- if not v.children[key].selected then
- if dxIsPointOnTopOfArea ( x, y, v.x, v.by+entry*15, baseWidth, 15 ) then
- v.children[key].selected = true
- triggerEvent ( "onClientDxGridListSelect", v.element, key )
- if row and row == key then
- triggerEvent ( "onClientDxGridListDoubleClick", v.element, key ) -- sort of
- end
- -- since the cursor can't be pointing at two element at a time there's no point in carrying on
- return
- end
- end
- entry = entry + 1
- end
- end
- function dxGridListMouseWheel ( up )
- local key = dxGetElementKeyFromGUI ( source )
- if not dxElements[key].slider then return end
- local push = math.floor (10*math.min(dxElements[key].slider.invRowsHeight/15, 60)/60)
- if up == 1 then -- up
- dxElements[key].bk = math.max ( 0, dxElements[key].bk-push )
- else -- down
- dxElements[key].bk = math.min ( dxElements[key].slider.invRowsHeight/15, dxElements[key].bk+push )
- end
- dxElements[key].slider.pos = dxElements[key].by + dxElements[key].bk*(dxElements[key].bh-dxElements[key].slider.h)/(dxElements[key].slider.invRowsHeight/15)
- --dxGridListHandleHoveringOnPosition ( dxElements[key].gui, getCursorPosition () )
- end
- function dxGridListClearHoveredRows ( key, selected )
- if selected then
- triggerEvent ( "onClientDxGridListDeselect", dxElements[key].element )
- end
- for k = 1, #dxElements[key].children do
- dxElements[key].children[k].hovered = nil
- if selected then
- dxElements[key].children[k].selected = nil
- end
- end
- end
- function dxGridListDown ( button, x, y )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- if dxElements[key].slider and dxIsPointOnTopOfArea ( x, y, dxElements[key].x+dxElements[key].w-15, dxElements[key].slider.pos, 15, dxElements[key].slider.h ) then
- dxElements[key].slider.active = { difToTop = y - dxElements[key].slider.pos, difToBot = dxElements[key].slider.pos + dxElements[key].slider.h - y }
- end
- end
- function dxGridListSelectRow ( gridlist, row )
- for key, val in pairs ( dxElements ) do
- if val.element == gridlist then
- dxElements[key].children[row].selected = true
- triggerEvent ( "onClientDxGridListSelect", val.element, row )
- break
- end
- end
- end
- function dxGridListGetSelectedRow ( gridlist )
- for key, val in pairs ( dxElements ) do
- if val.element == gridlist then
- for k, v in pairs ( val.children ) do
- if v.selected then
- return k
- end
- end
- end
- end
- return false
- end
- function dxGridListSetRowText ( gridlist, row, column, text )
- local key = dxGetKeyFromElement ( gridlist )
- dxElements[key].children[row][column] = tostring(text)
- end
- function dxGridListGetRowText ( gridlist, column, row )
- local key = dxGetKeyFromElement ( gridlist )
- return dxElements[key].children[row][column]
- end
- function dxGridListSetRowData ( gridlist, row, data )
- local key = dxGetKeyFromElement ( gridlist )
- dxElements[key].children[row].data = data
- end
- function dxGridListGetRowData ( gridlist, row )
- local key = dxGetKeyFromElement ( gridlist )
- return dxElements[key].children[row].data
- end
- -- ------------
- -- ScrollBar functions
- function dxScrollBarDown ( button, x, y )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- if dxElements[key].pos == "horizontal" then
- if dxIsPointOnTopOfArea ( x, y, dxElements[key].p, dxElements[key].y, 30, 15 ) then
- dxElements[key].active = {disLeft = x - dxElements[key].p, disRight = dxElements[key].p+30-x}
- end
- else
- if dxIsPointOnTopOfArea ( x, y, dxElements[key].x, dxElements[key].p, 15, 30 ) then
- dxElements[key].active = {disTop = y - dxElements[key].p, disBot = dxElements[key].p+30-y}
- end
- end
- end
- function dxScrollBarSetPosition ( element, percentage )
- local key = dxGetKeyFromElement ( element )
- dxElements[key].p = (percentage*dxElements[key].range/100) + dxElements[key].maxPos-dxElements[key].range
- end
- function dxScrollBarGetPosition ( element )
- local key = dxGetKeyFromElement ( element )
- return 100-(100*(dxElements[key].maxPos-dxElements[key].p)/dxElements[key].range)
- end
- -- ------------
- -- Rectangle functions
- function dxRectangleSetColor ( element, color )
- dxElements[dxGetKeyFromElement (element)].color = color
- end
- function dxRectangleGetColor ( element ) -- doesnt work
- return getColorFromString ( "#"..DEC_HEX ( math.abs (dxElements[dxGetKeyFromElement (element)].color) ) )
- end
- -- havent added this one to the original DX!!!
- function dxRectangleSetWidth ( element, width )
- dxElements[dxGetKeyFromElement (element)].w = width
- end
- -- ------------
- -- Image functions
- function dxImageChangeImage ( element, path )
- for key, val in pairs ( dxElements ) do
- if val.element == element then
- dxElements[key].path = path
- break
- end
- end
- end
- function dxImageMouseEnter ( x, y )
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxImageMouseEnter", dxElements[key].element, x, y )
- end
- function dxImageMouseLeave ()
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxImageMouseLeave", dxElements[key].element )
- end
- function dxImageMouseMove ( x, y )
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxImageMouseMove", dxElements[key].element, x, y )
- end
- function dxImageMouseDown ( button, x, y )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxImageMouseDown", dxElements[key].element, x, y )
- end
- function dxImageMouseUp ( button )
- if button ~= "left" then return end
- local key = dxGetElementKeyFromGUI ( source )
- triggerEvent ( "onDxImageMouseUp", dxElements[key].element )
- end
- -- ------------
- -- General purpose
- function dxMouseUp ( button, state )
- --guiMoveToBack ( source )
- if button ~= "left" or state ~= "up" or #dxElements == 0 then return end
- for k, v in pairs ( dxElements ) do
- if v.visible and isElement ( v.element ) then
- local type = getElementType ( v.element )
- if type == "dx_gridlist" then
- -- gridlist slider
- if v.slider and v.slider.active then
- v.slider.active = nil
- end
- elseif type == "dx_scrollbar" then
- v.active = nil
- end
- end
- end
- end
- addEventHandler ( "onClientClick", getRootElement (), dxMouseUp )
- function dxGuiFocus ()
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].focus = true
- triggerEvent ( "onDxEditFocus", dxElements[key].element )
- end
- function dxGuiBlur ()
- local key = dxGetElementKeyFromGUI ( source )
- dxElements[key].focus = false
- end
- -- ------------
- -- Set/Get/Is functions
- function dxSetAlpha ( element, alpha )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- dxElements[k].alpha = alpha
- end
- end
- end
- function dxGetElementPosition ( element )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- return v.x, v.y
- end
- end
- return 0, 0
- end
- function dxGetElementSize ( element )
- for k, v in pairs ( dxElements ) do
- if v.element and v.element == element then
- return v.w, v.h
- end
- end
- return 0, 0
- end
- function dxGetElementFromGUI ( gui )
- for k, v in pairs ( dxElements ) do
- if v.gui and v.gui == gui then
- return v.element
- end
- end
- return nil
- end
- function dxGetElementKeyFromGUI ( gui )
- for k, v in pairs ( dxElements ) do
- if v.gui and v.gui == gui then
- return k
- end
- end
- return nil
- end
- function dxGetKeyFromElement ( element )
- for k, v in pairs ( dxElements ) do
- if v.element == element then
- return k
- end
- end
- return nil
- end
- function dxSetVisible ( element, value )
- for k, v in pairs ( dxElements ) do
- if v.element == element then -- tab
- dxElements[k].visible = value
- for key, val in pairs ( dxElements ) do
- if val.parent == v.element then -- tab panel
- dxElements[key].visible = value
- if val.gui then
- guiSetVisible ( val.gui, value )
- end
- for kk, vv in pairs ( dxElements ) do
- if vv.parent == val.element then -- tab
- dxElements[kk].visible = value
- if vv.gui then
- guiSetVisible ( vv.gui, value )
- end
- for kkk, vvv in pairs ( dxElements ) do
- if vvv.parent == vv.element then -- body
- dxElements[kkk].visible = value
- if vvv.gui then
- guiSetVisible ( vvv.gui, value )
- end
- for kkkk, vvvv in pairs ( dxElements ) do
- if vvvv.parent == vvv.element then -- inner body
- dxElements[kkkk].visible = value
- if vvvv.gui then
- guiSetVisible ( vvvv.gui, value )
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- function dxIsElementVisible ( element )
- for key, value in pairs ( dxElements ) do
- if value.element == element then
- local type = getElementType ( value.element )
- if type == "dx_tab" then
- --if value.active then return value.visible end
- --return false
- return (value.visible and value.active)
- end
- return value.visible
- end
- end
- end
- function dxIsCursorOnTopOfArea ( x, y, w, h )
- -- assuming the cursor is showing
- local cx, cy = getCursorPosition ()
- cx, cy = x*cx, cy*y
- if cx >= x and cx <= x+w and cy >= y and cy <= y+h then return true end
- return false
- end
- function dxIsPointOnTopOfArea ( a, b, x, y, w, h )
- if a and b and x and y and w and h then
- if a >= x and a <= x+w and b >= y and b <= y+h then return true end
- end
- return false
- end
- function DEC_HEX(IN)
- local B,K,OUT,D=16,"0123456789ABCDEF",""
- while IN>0 do
- IN,D=math.floor(IN/B),math.mod(IN,B)+1
- OUT=string.sub(K,D,D)..OUT
- end
- return OUT
- end
- -- ------------
- -- Drawing
- function dxDrawElements ()
- local removeOne
- for k, v in pairs ( dxElements ) do
- -- check if the element and its parent are visible
- if not v.element or not isElement ( v.element ) then
- removeOne = k
- else
- if v.visible then --dxdxIsElementVisible ( v.element ) then
- -- assuming v.element is an element
- local type = getElementType ( v.element )
- if type == "dx_window" then
- local posX, posY = v.x, v.y
- local w, h = v.w, v.h
- if v.border then
- local borderColor = tocolor(16,16,16,255)
- -- top
- dxDrawRectangle ( posX, posY, w, 2, borderColor, true )
- -- left
- dxDrawRectangle ( posX, posY+2, 2, h-2, borderColor, true )
- -- bot
- dxDrawRectangle ( posX+2, posY+h-2, w-2, 2, borderColor, true )
- -- right
- dxDrawRectangle ( posX+w-2, posY+2, 2, h-4, borderColor, true )
- posX, posY, w, h = posX+2, posY+2, w-4, h-4
- end
- -- head
- dxDrawRectangle ( posX, posY, w, 30, v.hc or tocolor(20,25,35,255), true )
- -- text
- dxDrawText ( v.title, posX, posY, posX+w, posY+30, tocolor(255,255,255,255), 1, "default-bold", "center", "center", true, false, true )
- -- main
- dxDrawRectangle ( posX, posY+30, w, h-30, v.mc or tocolor(35,40,50,255), true )
- elseif type == "dx_label" then
- dxDrawText ( getStringWithoutColorCode(v.text), v.x+1, v.y+1, v.w+1, v.h+1, tocolor(0,0,0,v.alpha or 255), v.fontH or 1, v.font or "default", v.hor or "left", v.ver or "top", true, false, true, v.cc )
- dxDrawText ( v.text, v.x, v.y, v.w, v.h, tocolor(255,255,255,v.alpha or 255), v.fontH or 1, v.font or "default", v.hor or "left", v.ver or "top", true, false, true, v.cc )
- elseif type == "dx_button" then
- dxDrawRectangle ( v.x+1, v.y+1, v.w, v.h, tocolor(0,0,0,255), true )
- dxDrawRectangle ( v.x, v.y, v.w, v.h, v.color or tocolor(95,160,255,255), true )
- dxDrawText ( v.text, v.x+1, v.y+1, v.x+v.w+1, v.y+v.h+1, tocolor(0,0,0,255), 1, "default-bold", "center", "center", true, false, true )
- dxDrawText ( v.text, v.x, v.y, v.x+v.w, v.y+v.h, tocolor(255,255,255,255), 1, "default-bold", "center", "center", true, false, true )
- elseif type == "dx_edit" then
- dxDrawRectangle ( v.x, v.y, v.w, v.h, tocolor(223,223,223,255), true )
- --dxDrawRectangle ( v.x, v.y, v.w, 1, tocolor(0,0,0,128), true )
- --dxDrawRectangle ( v.x, v.y+1, 1, v.h-1, tocolor(0,0,0,128), true )
- local text = v.masked and string.rep ( "*", #guiGetText ( v.gui ) ) or guiGetText ( v.gui )
- if v.focus then
- local index = guiEditGetCaretIndex ( v.gui )
- text = string.sub ( text, 0, index ).."▌"..string.sub ( text, index+1 )
- --text = text.."▎"
- end
- --while (getTextExtent ( text )) >= v.w-10 do
- while (dxGetTextWidth ( text, 1, "default" )) >= v.w-8 do
- text = string.sub ( text, 2, #text )
- end
- dxDrawText ( text, v.x+5, v.y+2, v.x+v.w-5, v.y+v.h, tocolor(0,0,0,255), 1, "default", "left", "center", true, false, true )
- elseif type == "dx_tabpanel" then
- dxDrawRectangle ( v.x, v.y, v.w, 30, tocolor(20,25,35,64), true )
- if v.color then
- dxDrawRectangle ( v.x, v.y+30, v.w, v.h-30, v.color, true )
- end
- elseif type == "dx_tab" then
- dxDrawRectangle ( v.bx+1, v.y+1, v.bw, 25, tocolor(0,0,0,255), true )
- dxDrawRectangle ( v.bx, v.y, v.bw, 25, v.color or tocolor(135,135,135,255), true ) -- tocolor(95,160,255,255) tocolor(51,153,255,255)
- dxDrawText ( v.title, v.bx+1, v.y+1, v.bx+v.bw+1, v.y+24, tocolor(0,0,0,255), 1, "default-bold", "center", "center", true, false, true )
- dxDrawText ( v.title, v.bx, v.y, v.bx+v.bw, v.y+23, tocolor(255,255,255,255), 1, "default-bold", "center", "center", true, false, true )
- elseif type == "dx_checkbox" then
- -- border
- dxDrawRectangle ( v.x, v.y, 15, 1, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x, v.y+1, 1, 14, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x+1, v.y+14, 14, 1, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x+14, v.y+1, 1, 13, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x+1, v.y+1, 13, 13, tocolor(223,223,223,255), true )
- dxDrawText ( v.text, v.x+21, v.y+1, v.x+21+v.tw, v.y+16, tocolor (0,0,0,255), 1, "default", "left", "top", true, false, true )
- dxDrawText ( v.text, v.x+20, v.y, v.x+20+v.tw, v.y+15, tocolor (255,255,255,255), 1, "default", "left", "top", true, false, true )
- if v.ticked then
- --dxDrawRectangle ( v.x+2, v.y+2, 11, 11, tocolor(50,50,50,255), true )
- --dxDrawText ( "✖", v.x, v.y, v.x+13, v.y+13, tocolor(0,0,0,255), 1, "default", "center", "center", true, false, true )
- dxDrawImage ( v.x+1, v.y+1, 13, 13, "images/gui/check.png", 0, 0, 0, tocolor(255,255,255,255), true )
- end
- elseif type == "dx_gridlist" then
- -- header
- if v.children.columns then
- -- header
- dxDrawRectangle ( v.x, v.y, v.w, 20, v.headerColor or tocolor(95,160,255,255), true ) -- tocolor(50,150,255,255)
- local c = 0
- for key, val in pairs ( v.children.columns ) do
- dxDrawText ( val.title, v.x+6+c, v.y+3, v.x+c+val.w, v.y+20, tocolor(0,0,0,255), 1, "default-bold", "left", "top", true, false, true )
- dxDrawText ( val.title, v.x+5+c, v.y+2, v.x+c+val.w, v.y+20, tocolor(255,255,255,255), 1, "default-bold", "left", "top", true, false, true )
- c = c + val.w
- end
- end
- -- body
- dxDrawRectangle ( v.x, v.by, v.w, v.bh, v.color or tocolor(35,45,85,64), true )
- local baseWidth = v.w
- --if #v.children*15 > v.bh then
- if v.slider then
- -- adjust the body's width
- baseWidth = baseWidth-15
- -- check if the slider is being used
- if v.slider.active then
- -- calcs
- local cx, cy = getCursorPosition ()
- cx, cy = cx*x, cy*y
- local bodyEnd = v.by+v.bh
- local minCursorPos, maxCursorPos = cy <= v.by+v.slider.active.difToTop, cy >= bodyEnd - v.slider.active.difToBot
- if minCursorPos then
- dxElements[k].slider.pos = v.by
- elseif maxCursorPos then
- dxElements[k].slider.pos = bodyEnd - v.slider.h
- else
- dxElements[k].slider.pos = cy - v.slider.active.difToTop
- end
- -- calculate v.bk
- --dxElements[key].slider.pos = dxElements[key].by + dxElements[key].bk*(dxElements[key].bh-dxElements[key].slider.h)/(dxElements[key].slider.invRowsHeight/15)
- -- inverted function
- dxElements[k].bk = math.floor ((dxElements[k].slider.pos-dxElements[k].by)*dxElements[k].slider.invRowsHeight/15/(dxElements[k].bh-dxElements[k].slider.h))
- end
- dxDrawRectangle ( v.x+baseWidth, v.slider.pos, 15, v.slider.h, v.slider.color or tocolor(255,255,255,255), true )
- end
- local baseKey = v.bk or 0 --v.tk or #v.children
- -- rows
- local entry = 0
- for key = baseKey+1, (v.onSight and baseKey+v.onSight or #v.children) do
- -- background
- if v.children[key].selected then
- dxDrawRectangle ( v.x, v.by+entry*15, baseWidth, 15, v.childColor or tocolor (160,190,235,64), true )
- elseif v.children[key].hovered then
- dxDrawRectangle ( v.x, v.by+entry*15, baseWidth, 15, v.childColor or tocolor (160,190,235,32), true )
- end
- -- text
- local cx = v.x + 6
- for ck = 1, #v.children.columns do
- dxDrawText ( v.children.columns[ck].cc and getStringWithoutColorCode(v.children[key][ck] or "") or (v.children[key][ck] or ""), cx+1, v.by+(entry*15)+1, cx+v.children.columns[ck].w+1, v.by+((entry+1)*15)+1, tocolor(0,0,0,255), 1, v.font or "default", "left", "top", true, false, true, v.children.columns[ck].cc )
- dxDrawText ( v.children[key][ck] or "", cx, v.by+(entry*15), cx+v.children.columns[ck].w, v.by+((entry+1)*15), tocolor(255,255,255,255), 1, v.font or "default", "left", "top", true, false, true, v.children.columns[ck].cc )
- cx = cx + v.children.columns[ck].w
- end
- entry = entry + 1
- end
- elseif type == "dx_scrollbar" then
- if v.pos == "horizontal" then
- if v.active then
- local cx, cy = getCursorPosition ()
- cx, cy = cx*x, cy*y
- if cx <= v.x+v.active.disLeft then
- dxElements[k].p = v.x
- elseif cx >= v.x+v.s-v.active.disRight then
- dxElements[k].p = v.x+v.range
- else
- dxElements[k].p = cx-v.active.disLeft
- end
- end
- -- background
- dxDrawRectangle ( v.x, v.y, v.s, 15, v.color or tocolor(20,25,35,64), true )
- dxDrawRectangle ( v.p, v.y, 30, 15, tocolor(255,255,255,255), true )
- else
- if v.active then
- local cx, cy = getCursorPosition ()
- cx, cy = cx*x, cy*y
- if cy <= v.y+v.active.disTop then
- dxElements[k].p = v.y
- elseif cy >= v.y+v.s-v.active.disBot then
- dxElements[k].p = v.y+v.range
- else
- dxElements[k].p = cy-v.active.disTop
- end
- end
- -- background
- dxDrawRectangle ( v.x, v.y, 15, v.s, v.color or tocolor(20,25,35,64), true )
- dxDrawRectangle ( v.x, v.p, 15, 30, tocolor(255,255,255,255), true )
- end
- elseif type == "dx_radiobutton" then
- -- border
- dxDrawRectangle ( v.x, v.y, 15, 1, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x, v.y+1, 1, 14, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x+1, v.y+14, 14, 1, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x+14, v.y+1, 1, 13, tocolor(67,205,243,255), true )
- dxDrawRectangle ( v.x+1, v.y+1, 13, 13, tocolor(223,223,223,255), true )
- dxDrawText ( v.text, v.x+20+1, v.y, v.x+20+v.tw+1, v.y+15, tocolor(0,0,0,255), 1, "default", "left", "top", true, false, true )
- dxDrawText ( v.text, v.x+20, v.y-1, v.x+20+v.tw, v.y+14, tocolor(255,255,255,255), 1, "default", "left", "top", true, false, true )
- if v.ticked then
- dxDrawText ( "●", v.x+3, v.y-5, v.x+30, v.y+30, tocolor(20,25,35,220), 1.4, "default", "left", "top", true, false, true )
- end
- elseif type == "dx_rectangle" then
- dxDrawRectangle ( v.x, v.y, v.w, v.h, v.color, true )
- elseif type == "dx_image" then
- dxDrawImage ( v.x, v.y, v.w, v.h, v.path, 0, 0, 0, v.color or tocolor(255,255,255,255), true )
- end
- end
- end
- end
- if removeOne then
- table.remove ( dxElements, removeOne )
- end
- end
- addEventHandler ( "onClientRender", getRootElement (), dxDrawElements )
- function getStringWithoutColorCode(s)
- return string.gsub(s,"#%x%x%x%x%x%x","")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement