Advertisement
ssccsscc

TPT Object Finder (Full)

Feb 3rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 73.06 KB | None | 0 0
  1. ------------------- Configuration -------------------
  2. local rquiredAPIVersion = 2.42
  3. -----------------------------------------------------
  4. local mouseEvents = {
  5.   Down = 1,
  6.   Up = 2
  7. }
  8. ------------------- Configuration -------------------
  9. local InterfaceAPIVersion = 2.42
  10. -----------------------------------------------------
  11. local mouseEvents = {
  12.   Down = 1,
  13.   Up = 2
  14. }
  15. local function DefineInterfaceComponents()
  16.   function interface_s.Components.Window:new(x, y, Width, Height, Movable, theme)
  17.     local obj= {}
  18.     obj.Type = "Window"
  19.  
  20.     obj.AllowResize = true
  21.     obj.AlwaysFocused = false
  22.     obj.IsMovable = Movable
  23.     obj.MinWidth = 16
  24.     obj.MinHeight = 16
  25.     obj.Theme = theme
  26.     obj.X = x
  27.     obj.Y = y
  28.     obj.Width = Width
  29.     obj.Height = Height
  30.  
  31.     obj.OnShow = nil
  32.     obj.OnHide = nil
  33.     obj.OnDraw = nil
  34.     obj.OnEndDraw = nil
  35.     obj.OnMove = nil
  36.     obj.OnClick = nil
  37.  
  38.     obj.Focused=false
  39.     obj.Items = {}
  40.     obj.MoveStartX = -1
  41.     obj.MoveStartY = -1
  42.     obj.IsMoving = false
  43.     obj.IsShowing = true
  44.     obj.IsResizing = false
  45.     obj.ResizeStartX = 1
  46.     obj.ResizeStartY = 1
  47.     obj.ResizeStartWidth = 1
  48.     obj.ResizeStartHeight = 1
  49.     obj.ResizeLastWidth =0
  50.     obj.ResizeLastHeight=0  
  51.     obj.SizeOfHeader = 8  
  52.     function obj:Draw(IsFocused,mx,my)
  53.       self.Focused=IsFocused or self.AlwaysFocused
  54.       if self.OnDraw ~= nil then
  55.         if self.OnDraw(IsFocused,mx,my) == true then
  56.           return
  57.         end
  58.       end
  59.       if self.Focused == true then
  60.         gfx.fillRect(self.X, self.Y, self.Width,self.Height, gfx.getColors(self.Theme.BackColor))
  61.         gfx.drawRect(self.X, self.Y, self.Width,self.Height, gfx.getColors(self.Theme.BorderColor))
  62.         if self.IsMovable then
  63.           gfx.fillRect(self.X, self.Y, self.Width,self.SizeOfHeader, gfx.getColors(self.Theme.HeaderColor))
  64.         end
  65.         if self.AllowResize==true then
  66.           gfx.fillRect(self.X+self.Width-6, self.Y+self.Height-6, 6,6, gfx.getColors(self.Theme.BorderColor))
  67.         end
  68.       else
  69.         gfx.fillRect(self.X, self.Y, self.Width,self.Height, gfx.getColors(self.Theme.UnfocusedBackColor))
  70.         gfx.drawRect(self.X, self.Y, self.Width,self.Height, gfx.getColors(self.Theme.UnfocusedBorderColor))
  71.         if self.AllowResize==true then
  72.           gfx.fillRect(self.X+self.Width-6, self.Y+self.Height-6, 6,6, gfx.getColors(self.Theme.UnfocusedBorderColor))
  73.         end
  74.         if self.IsMovable then
  75.           gfx.fillRect(self.X, self.Y, self.Width,self.SizeOfHeader, gfx.getColors(self.Theme.UnfocusedHeaderColor))
  76.         end
  77.       end
  78.       for i=#self.Items,0,-1 do
  79.         if (self.Items[i]~=nil) and (self.Items[i].IsShowing==true) then
  80.           self.Items[i]:Draw(self.Focused,self.X,self.Y,mx-self.X,my-self.Y)
  81.         end
  82.       end
  83.       if self.OnEndDraw ~= nil then
  84.         if self.OnEndDraw(IsFocused,mx,my) == true then
  85.           return
  86.         end
  87.       end
  88.     end
  89.     function obj:Show()
  90.       self.IsShowing = true
  91.       if self.OnShow ~= nil then
  92.          self.OnShow(self)
  93.       end
  94.     end
  95.     function obj:Hide()
  96.       self.IsShowing = false
  97.       if self.OnHide ~= nil then
  98.          self.OnHide(self)
  99.       end
  100.     end
  101.     function obj:Resize(ws,hs)
  102.       if ws < self.MinWidth then
  103.         ws=self.MinWidth
  104.       end
  105.       if hs < self.MinHeight then
  106.         hs=self.MinHeight
  107.       end
  108.       self.ResizeLastHeight = self.Height
  109.       self.ResizeLastWidth = self.Width
  110.       self.Height = hs
  111.       self.Width = ws
  112.       hs = self.Height-self.ResizeLastHeight
  113.       ws = self.Width-self.ResizeLastWidth
  114.       for i=0,#self.Items do
  115.         if self.Items[i]~=nil then
  116.           if self.Items[i].Anchor.Top==true and self.Items[i].Anchor.Bottom==true then
  117.             self.Items[i].Height = self.Items[i].Height + hs
  118.           end
  119.           if self.Items[i].Anchor.Top==false and self.Items[i].Anchor.Bottom==true then
  120.             self.Items[i].Y = self.Items[i].Y + hs
  121.           end
  122.           if self.Items[i].Anchor.Left==true and self.Items[i].Anchor.Right==true then
  123.             self.Items[i].Width = self.Items[i].Width + ws
  124.           end
  125.           if self.Items[i].Anchor.Left==false and self.Items[i].Anchor.Right==true then
  126.             self.Items[i].X = self.Items[i].X + ws
  127.           end
  128.         end
  129.       end
  130.     end
  131.     function obj:AddComponent(component)
  132.       self.Items[#self.Items+1] = component
  133.       component.Base = self
  134.     end
  135.     function obj:GetComponentIndex(obj2)
  136.       for i=0, #self.Items do
  137.         if self.Items[i] == obj2 then
  138.           return i
  139.         end
  140.       end
  141.       return -1
  142.     end
  143.     function obj:focusComponent(obj2)
  144.       local index = self:GetComponentIndex(obj2)
  145.       for i=index, 1,-1 do
  146.         self.Items[i] = self.Items[i-1]
  147.       end
  148.       self.Items[0] = obj2
  149.     end
  150.     function obj:KeyPress(key, scan, r, ctrl, shift, alt)
  151.       for i=0,#self.Items do
  152.         if (self.Items[i]~=nil) and (self.Items[i].IsShowing==true) and (self.Items[i].KeyPress~=nil) then
  153.           if self.Items[i]:KeyPress(key, scan, r, ctrl, shift, alt) then
  154.             return true
  155.           end
  156.         end
  157.       end
  158.     end
  159.     function obj:Click(x,y,e,b,w)
  160.       if self.OnClick~=nil then
  161.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  162.         if x==nil then
  163.           return
  164.         end
  165.       end
  166.       if (self.IsMovable) and (e==mouseEvents.Up) and (self.IsMoving) then
  167.         self.IsMoving = false
  168.       end
  169.       if self.IsResizing== false then
  170.         for i=0,#self.Items do
  171.           if (self.Items[i]~=nil) and (self.Items[i].IsShowing==true) then
  172.             if self.Items[i]:Click(x-self.X,y-self.Y,e,b,w) then
  173.               return true
  174.             end
  175.           end
  176.         end
  177.       end
  178.       if (x>self.X) and (x<self.X+self.Width) and (y>self.Y) and (y<self.Y+self.Height) then
  179.         if self.Focused then
  180.           if self.AllowResize==true and self.IsResizing==false and e==mouseEvents.Down and x>self.X+self.Width-8 and x<self.X+self.Width and y>self.Y+self.Height-self.SizeOfHeader and y<self.Y+self.Height then
  181.             self.IsResizing=true
  182.             self.ResizeStartX = x
  183.             self.ResizeStartY = y
  184.             self.ResizeStartWidth = self.Width
  185.             self.ResizeStartHeight = self.Height
  186.             return true
  187.           end
  188.           if (self.IsMovable) and (y>self.Y) and (y<self.Y+self.SizeOfHeader) and (e==mouseEvents.Down) then
  189.             self.MoveStartX = x - self.X
  190.             self.MoveStartY = y - self.Y
  191.             self.IsMoving = true
  192.           end
  193.           if self.IsResizing==false then
  194.             return true
  195.           end
  196.         else
  197.           if e==mouseEvents.Down then
  198.             return true
  199.           end
  200.         end
  201.       else
  202.         if IsResizing==false then
  203.           return false
  204.         end
  205.       end
  206.  
  207.       if self.IsResizing==true and e==mouseEvents.Up then
  208.         self.IsResizing = false
  209.         return true
  210.       end
  211.  
  212.     end
  213.     function obj:Move(x,y,dx,dy)
  214.       if (self.IsMovable) and (self.IsMoving) then
  215.         self.X = x-self.MoveStartX
  216.         self.Y = y-self.MoveStartY
  217.         if self.OnMove~=nil then
  218.           self.OnMove(self.X,self.Y)
  219.         end
  220.       else
  221.         if self.IsResizing==true then
  222.           self:Resize(self.ResizeStartWidth-self.ResizeStartX+x,self.ResizeStartHeight-self.ResizeStartY+y)
  223.           return true
  224.         end
  225.       end
  226.     end
  227.     setmetatable(obj, self)
  228.     self.__index = self;
  229.     return obj
  230.   end
  231.   function interface_s.Components.Button:new(x, y, Width, Height, text, theme)
  232.     local obj= {}
  233.     obj.Type = "Button"
  234.  
  235.     obj.X = x
  236.     obj.Y = y
  237.     obj.Width = Width
  238.     obj.Height = Height
  239.     obj.Theme = theme
  240.     obj.IsShowing = true
  241.     obj.Text = text
  242.     obj.Enabled = true
  243.     obj.HintText = ""
  244.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  245.  
  246.     obj.OnPressed = nil
  247.     obj.OnDraw = nil
  248.     obj.OnEndDraw = nil
  249.     obj.OnClick = nil
  250.    
  251.     obj.Base = nil
  252.     obj.Focused=false
  253.     obj.ClickHelper = interface_s.ComponentsHelpers.Click:new()
  254.     obj.HintHelper = nil
  255.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  256.       if not self.IsShowing then return end
  257.       self.Focused=IsFocused
  258.       if self.OnDraw ~= nil then
  259.         if self.OnDraw(IsFocused,self.X+baseX,self.Y+baseY,x,y) == true then
  260.           return
  261.         end
  262.       end
  263.       local tw, th = gfx.textSize(self.Text)
  264.       if IsFocused == true and self.Enabled then
  265.         if (x>self.X) and (x<self.X+self.Width) and (y>self.Y) and (y<self.Y+self.Height) then
  266.           if self.ClickHelper.IsFirstClick then
  267.             gfx.fillRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.PressedBackColor))
  268.             gfx.drawText(self.X+baseX+(self.Width-tw)/2, self.Y+baseY + (self.Height-th)/2+1, self.Text, gfx.getColors(self.Theme.PressedTextColor))
  269.           else
  270.             gfx.fillRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.MouseOverColor))
  271.             gfx.drawText(self.X+baseX+(self.Width-tw)/2, self.Y+baseY + (self.Height-th)/2+1, self.Text, gfx.getColors(self.Theme.TextColor))
  272.             if self.HintHelper~=nil then
  273.               self.HintHelper:MouseOver(x+baseX,y+baseY,self.HintText)
  274.             end
  275.           end
  276.         else
  277.           if self.HintHelper~=nil then
  278.             self.HintHelper:Reset()
  279.           end
  280.           gfx.fillRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.BackColor))
  281.           gfx.drawText(self.X+baseX+(self.Width-tw)/2, self.Y+baseY + (self.Height-th)/2+1, self.Text, gfx.getColors(self.Theme.TextColor))
  282.         end
  283.         gfx.drawRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.BorderColor))
  284.       else
  285.         if self.HintHelper~=nil then
  286.           self.HintHelper:Reset()
  287.         end
  288.         if (x>self.X) and (x<self.X+self.Width) and (y>self.Y) and (y<self.Y+self.Height) then
  289.           if self.ClickHelper.IsFirstClick then
  290.             gfx.fillRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.PressedBackColor))
  291.             gfx.drawText(self.X+baseX+(self.Width-tw)/2, self.Y+baseY + (self.Height-th)/2+1, self.Text, gfx.getColors(self.Theme.PressedTextColor))
  292.           else
  293.             gfx.fillRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.UnfocusedMouseOverColor))
  294.             gfx.drawText(self.X+baseX+(self.Width-tw)/2, self.Y+baseY + (self.Height-th)/2+1, self.Text, gfx.getColors(self.Theme.UnfocusedTextColor))
  295.           end
  296.         else
  297.           gfx.fillRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.UnfocusedBackColor))
  298.           gfx.drawText(self.X+baseX+(self.Width-tw)/2, self.Y+baseY + (self.Height-th)/2+1, self.Text, gfx.getColors(self.Theme.UnfocusedTextColor))
  299.         end
  300.         gfx.drawRect(self.X+baseX, self.Y+baseY, self.Width,self.Height, gfx.getColors(self.Theme.UnfocusedBorderColor))
  301.       end
  302.       if self.OnEndDraw ~= nil then
  303.         if self.OnEndDraw(IsFocused,self.X+baseX,self.Y+baseY,x,y) == true then
  304.           return
  305.         end
  306.       end
  307.     end
  308.     function obj:Show()
  309.       self.IsShowing = true
  310.     end
  311.     function obj:Hide()
  312.       self.IsShowing = false
  313.     end
  314.     function obj:Click(x,y,e,b,w)
  315.       if self.OnClick~=nil then
  316.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  317.         if x==nil then
  318.           return
  319.         end
  320.       end
  321.       if self.Enabled then
  322.         self.ClickHelper.OnPress = self.OnPressed
  323.         self.ClickHelper:ProcessClick(self.Width,self.Height,self.X,self.Y,x,y,e,b)
  324.       end
  325.     end
  326.     function obj:AddHint(text)
  327.       self.HintText = text
  328.       self.HintHelper = interface_s.ComponentsHelpers.Hint:new()
  329.     end
  330.     setmetatable(obj, self)
  331.     self.__index = self;
  332.     return obj
  333.   end
  334.  
  335.   function interface_s.Components.Combobox:new(x, y,w,h,i, theme)
  336.     local obj= {}
  337.     obj.Type = "Combobox"
  338.  
  339.     obj.X = x
  340.     obj.Y = y
  341.  
  342.     obj.Theme = theme
  343.     obj.IsShowing = true
  344.     obj.Width = w
  345.     obj.Height = h
  346.     obj.Enabled = true
  347.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  348.     obj.Items = i
  349.     obj.IsItemsShown = false
  350.    
  351.     obj.SelectedIndex=0
  352.     obj.OnItemSelected = nil
  353.     obj.OnClick = nil
  354.  
  355.     obj.Base = nil
  356.     obj.Focused=false
  357.     obj.DropClickHelper = interface_s.ComponentsHelpers.Click:new()
  358.       obj.DropClickHelper.OnPress = function()
  359.           if obj.IsItemsShown==false then
  360.             obj.Base:focusComponent(obj)
  361.             obj.IsItemsShown = true
  362.           end
  363.         end
  364.     obj.ItemClickHelper = interface_s.ComponentsHelpers.Click:new()
  365.       obj.ItemClickHelper.OnFirstClick = function() return true end
  366.       obj.ItemClickHelper.OnPress = function(x,y)
  367.           local i = y-obj.Y-obj.Height
  368.           obj.SelectedIndex=math.floor(i/14)
  369.           if obj.OnItemSelected~= nil then
  370.             obj.OnItemSelected(obj.SelectedIndex,obj.Items[obj.SelectedIndex+1])
  371.           end
  372.           obj.IsItemsShown = false
  373.           interface_s.RemoveOnClickAction(obj)
  374.           return true
  375.         end
  376.       obj.ItemClickHelper.OnMissClick = function(x,y)
  377.         obj.IsItemsShown = false
  378.         interface_s.RemoveOnClickAction(obj)
  379.         return true
  380.       end
  381.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  382.       if not self.IsShowing then return end
  383.       self.Focused = IsFocused
  384.       if IsFocused and self.Enabled then
  385.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BorderColor))
  386.         if self.SelectedIndex>=0 then
  387.           gfx.drawText(self.X+baseX+5,self.Y+baseY+3, self.Items[self.SelectedIndex+1], gfx.getColors(self.Theme.TextColor))
  388.         end
  389.         if self.IsItemsShown==true then
  390.           gfx.fillRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height, gfx.getColors(self.Theme.ButtonPressedBackColor))
  391.         else
  392.           if x>self.X+self.Width-self.Height and x<self.X+self.Width and y>self.Y and y<self.Y+self.Height then
  393.             gfx.fillRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height, gfx.getColors(self.Theme.ButtonMouseOverBackColor))
  394.           else
  395.             gfx.fillRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height, gfx.getColors(self.Theme.ButtonBackColor))
  396.           end
  397.         end
  398.         gfx.drawRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height, gfx.getColors(self.Theme.BorderColor))
  399.         if self.IsItemsShown==true then
  400.           gfx.fillRect(self.X+baseX,self.Y+baseY+self. Height,self.Width,#self.Items*14,gfx.getColors(self.Theme.BackColor))
  401.           for i=0,#self.Items-1 do
  402.             if x>self.X and x<self.X+self.Width and y>self.Y+i*14+self.Height and y<self.Y+i*14+self.Height+15 then
  403.               gfx.fillRect(self.X+baseX,self.Y+baseY+i*14+self.Height,self.Width,14+1,gfx.getColors(self.Theme.ButtonMouseOverBackColor))
  404.             end
  405.             gfx.drawRect(self.X+baseX,self.Y+baseY+i*14+self.Height,self.Width,14+1,gfx.getColors(self.Theme.BorderColor))
  406.             gfx.drawText(self.X+baseX+5,self.Y+baseY+i*14+3+self.Height, self.Items[i+1],gfx.getColors(self.Theme.TextColor))
  407.           end
  408.         end
  409.       else
  410.         obj.IsItemsShown = false
  411.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.UnfocusedBorderColor))
  412.         if self.SelectedIndex>=0 then
  413.           gfx.drawText(self.X+baseX+5,self.Y+baseY+3, self.Items[self.SelectedIndex+1],gfx.getColors(self.Theme.UnfocusedTextColor))
  414.         end
  415.         if x>self.X+self.Width-self.Height and x<self.X+self.Width and y>self.Y and y<self.Y+self.Height then
  416.           gfx.fillRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height, gfx.getColors(self.Theme.UnfocusedButtonMouseOverBackColor))
  417.         else
  418.           gfx.fillRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height,gfx.getColors(self.Theme.UnfocusedButtonBackColor))
  419.         end
  420.         gfx.drawRect(self.X+self.Width-self.Height+baseX, self.Y+baseY, self.Height,self.Height, gfx.getColors(self.Theme.UnfocusedBorderColor))
  421.       end
  422.     end
  423.     function obj:Show()
  424.       self.IsShowing = true
  425.     end
  426.     function obj:Hide()
  427.       self.IsShowing = false
  428.     end
  429.     function obj:Click(x,y,e,b,w)
  430.       if self.OnClick~=nil then
  431.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  432.         if x==nil then
  433.           return
  434.         end
  435.       end
  436.       if self.Enabled then
  437.         if self.IsItemsShown==true then
  438.           return self.ItemClickHelper:ProcessClick(self.Width,#self.Items*14,self.X,self.Y+self.Height,x,y,e,b)
  439.         end
  440.         return self.DropClickHelper:ProcessClick(self.Height,self.Height,self.X+self.Width-self.Height,self.Y,x,y,e,b)
  441.       end
  442.     end
  443.     setmetatable(obj, self)
  444.     self.__index = self;
  445.     return obj
  446.   end
  447.  
  448.   function interface_s.Components.Graph:new(x, y,w,h, theme)
  449.     local obj= {}
  450.     obj.Type = "Graph"
  451.  
  452.     obj.X = x
  453.     obj.Y = y
  454.     obj.Theme = theme
  455.     obj.IsShowing = true
  456.     obj.Width = w
  457.     obj.Height = h
  458.     obj.UpdateSpeed = 20
  459.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  460.  
  461.     obj.GetValue = nil
  462.     obj.OnClick = nil
  463.  
  464.     obj.Focused=false
  465.     obj.ZeroHeight = 0
  466.     obj.MaxValue = 0
  467.     obj.NewMaxValue = 0
  468.     obj.MinValue = 0
  469.     obj.NewMinValue = 0
  470.     obj.UpdateCounter = 0
  471.     obj.PointX = {}
  472.     obj.PointY = {}
  473.     obj.Base = nil
  474.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  475.       if not self.IsShowing then return end
  476.       if self.UpdateCounter>self.UpdateSpeed then
  477.         if self.GetValue ~= nil then
  478.           self:AddPoint(self.GetValue())
  479.         end
  480.         self.UpdateCounter=0
  481.       end
  482.       self.UpdateCounter=self.UpdateCounter+1
  483.       self.Focused = IsFocused
  484.       if IsFocused==true then
  485.         gfx.fillRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BackColor))
  486.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BorderColor))
  487.         gfx.drawText(self.X+baseX,self.Y+baseY-10,"Max: "..self.MaxValue,gfx.getColors(self.Theme.TextColor))
  488.         gfx.drawText(self.X+baseX+100,self.Y+baseY-10,"Min: "..self.MinValue,gfx.getColors(self.Theme.TextColor))
  489.       else
  490.         gfx.fillRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.UnfocusedBackColor))
  491.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.UnfocusedBorderColor))
  492.         gfx.drawText(self.X+baseX,self.Y+baseY-10,"Max: "..self.MaxValue,gfx.getColors(self.Theme.UnfocusedTextColor))
  493.         gfx.drawText(self.X+baseX+100,self.Y+baseY-10,"Min: "..self.MinValue,gfx.getColors(self.Theme.UnfocusedTextColor))
  494.       end
  495.       self.NewMaxValue = 0
  496.       self.NewMinValue = 0
  497.       if self.PointX[#self.PointX] ~= nil then
  498.         local v = self.PointX[#self.PointX]-self.Width+1
  499.         if v>0 then
  500.           for i=v,#self.PointY do
  501.             self.PointY[i-v]=self.PointY[i]
  502.             self.PointX[i-v]=self.PointX[i]-v
  503.           end
  504.           for i=#self.PointY-v,#self.PointY do
  505.             self.PointY[i]=nil
  506.             self.PointX[i]=nil
  507.           end
  508.         end
  509.       end
  510.       for i=2, #self.PointX do
  511.         if self.PointX[i]<self.Width-1 then
  512.           if self.NewMaxValue < self.PointY[i] then
  513.             self.NewMaxValue = self.PointY[i]
  514.           else
  515.             if self.NewMinValue>self.PointY[i] then
  516.               self.NewMinValue = self.PointY[i]
  517.             end
  518.           end
  519.           if self.MaxValue < self.PointY[i] then
  520.             self.MaxValue = self.PointY[i]
  521.           else
  522.             if self.MinValue>self.PointY[i] then
  523.               self.MinValue = self.PointY[i]
  524.             end
  525.           end
  526.           local x1 = self.PointX[i]+self.X+baseX
  527.           local y1 = (self.Height-((self.PointY[i]+math.abs( self.MinValue ))/(self.MaxValue+math.abs( self.MinValue )))*(self.Height-3))+self.Y+baseY-2
  528.           local x2 = self.PointX[i-1]+self.X+baseX
  529.           local y2 = (self.Height-((self.PointY[i-1]+math.abs( self.MinValue ))/(self.MaxValue+math.abs( self.MinValue )))*(self.Height-3))+self.Y+baseY-2
  530.           if y1==y1 and y2==y2 then
  531.             if IsFocused==true then    
  532.               gfx.drawLine(x1,y1,x2,y2,gfx.getColors(self.Theme.GraphColor))
  533.             else
  534.               gfx.drawLine(x1,y1,x2,y2,gfx.getColors(self.Theme.UnfocusedGraphColor))
  535.             end
  536.           end
  537.         end
  538.       end
  539.       if self.PointY[1]~=nil then
  540.         if self.NewMaxValue < self.PointY[1] then
  541.           self.NewMaxValue = self.PointY[1]
  542.         else
  543.           if self.NewMinValue>self.PointY[1] then
  544.             self.NewMinValue = self.PointY[1]
  545.           end
  546.         end
  547.         if self.MaxValue < self.PointY[1] then
  548.           self.MaxValue = self.PointY[1]
  549.         else
  550.           if self.MinValue>self.PointY[1] then
  551.             self.MinValue = self.PointY[1]
  552.           end
  553.         end
  554.         self.ZeroHeight = (self.Height-((math.abs( self.MinValue ))/(self.MaxValue+math.abs( self.MinValue )))*(self.Height-3))+self.Y+baseY-2
  555.         if self.ZeroHeight == self.ZeroHeight then
  556.           if IsFocused== true then
  557.             gfx.drawLine(self.X+baseX,self.ZeroHeight,self.X+baseX+self.Width-1,self.ZeroHeight,gfx.getColors(self.Theme.ZeroLine))
  558.           else
  559.             gfx.drawLine(self.X+baseX,self.ZeroHeight,self.X+baseX+self.Width-1,self.ZeroHeight,gfx.getColors(self.Theme.UnfocusedZeroLine))
  560.           end
  561.         end
  562.       end
  563.       self.MaxValue = self.NewMaxValue
  564.       self.MinValue = self.NewMinValue
  565.     end
  566.     function obj:Show()
  567.       self.IsShowing = true
  568.     end
  569.     function obj:Hide()
  570.       self.IsShowing = false
  571.     end
  572.     function obj:AddPoint(v)
  573.       if v~= nil then
  574.       if #self.PointY==0 then
  575.         self.PointY[1]=v
  576.         self.PointX[1]=1
  577.       else
  578.         if #self.PointY+1 < self.Width-1 then
  579.         self.PointY[#self.PointY+1]=v
  580.         self.PointX[#self.PointX+1]=self.PointX[#self.PointX]+1
  581.         else
  582.           for i=2,#self.PointY do
  583.             self.PointY[i-1]=self.PointY[i]
  584.             self.PointX[i-1]=self.PointX[i]-1
  585.           end
  586.           self.PointY[#self.PointY]=v
  587.           self.PointX[#self.PointX]=self.PointX[#self.PointX]
  588.         end
  589.       end
  590.       end
  591.     end
  592.     function obj:ClearPoints()
  593.         self.PointY = {}
  594.         self.PointX = {}
  595.     end
  596.     function obj:Click(x,y,e,b,w)
  597.       if self.OnClick~=nil then
  598.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  599.         if x==nil then
  600.           return
  601.         end
  602.       end
  603.       if (x>self.X+self.Width-self.Height) and (x<self.X+self.Width) and (y>self.Y) and (y<self.Y+self.Height) then
  604.         return true
  605.       end
  606.     end
  607.     setmetatable(obj, self)
  608.     self.__index = self;
  609.     return obj
  610.   end
  611.  
  612.   function interface_s.Components.Label:new(x, y, t, theme)
  613.     local obj= {}
  614.     obj.Type = "Label"
  615.  
  616.     obj.X = x
  617.     obj.Y = y
  618.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  619.     obj.Theme = theme
  620.     obj.HintText = ""
  621.     obj.IsShowing = true
  622.     obj.Text = t
  623.    
  624.     obj.OnClick = nil
  625.  
  626.     obj.Base = nil
  627.     obj.Focused=false
  628.     obj.HintHelper = nil
  629.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  630.       if not self.IsShowing then return end
  631.       self.Focused = IsFocused
  632.       if IsFocused==true then
  633.         gfx.drawText(self.X+baseX,self.Y+baseY,self.Text,gfx.getColors(self.Theme.TextColor))
  634.         local tw, th = gfx.textSize(self.Text)
  635.         if (x>self.X) and (x<self.X+tw) and (y>self.Y) and (y<self.Y+th) then
  636.           if self.HintHelper~=nil then
  637.             self.HintHelper:MouseOver(x+baseX,y+baseY,self.HintText)
  638.           end
  639.         else
  640.           if self.HintHelper~=nil then
  641.             self.HintHelper:Reset()
  642.           end
  643.         end
  644.       else
  645.         if self.HintHelper~=nil then
  646.           self.HintHelper:Reset()
  647.         end
  648.         gfx.drawText(self.X+baseX,self.Y+baseY,self.Text,gfx.getColors(self.Theme.UnfocusedTextColor))
  649.       end
  650.     end
  651.     function obj:Show()
  652.       self.IsShowing = true
  653.     end
  654.     function obj:Hide()
  655.       self.IsShowing = false
  656.     end
  657.     function obj:Click(x,y,e,b,w)
  658.       if self.OnClick~=nil then
  659.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  660.         if x==nil then
  661.           return
  662.         end
  663.       end
  664.     end
  665.     function obj:AddHint(text)
  666.       self.HintText = text
  667.       self.HintHelper = interface_s.ComponentsHelpers.Hint:new()
  668.     end
  669.     setmetatable(obj, self)
  670.     self.__index = self;
  671.     return obj
  672.   end
  673.  
  674.   function interface_s.Components.Textbox:new(x, y, w, h, theme)
  675.     local obj= {}
  676.     obj.Type = "Textbox"
  677.  
  678.     obj.X = x
  679.     obj.Y = y
  680.     obj.Theme = theme
  681.     obj.IsShowing = true
  682.     obj.Width = w
  683.     obj.Height = h
  684.     obj.Text = ""
  685.     obj.Enabled = true
  686.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  687.     obj.MaxTextLength = 10
  688.     obj.PointerIndex = 0
  689.  
  690.     obj.OnTextChanged = nil
  691.     obj.OnClick = nil
  692.  
  693.     obj.Focused=false
  694.     obj.Base = nil
  695.     obj.IsActive = false
  696.     obj.PointerBlinkStep =0
  697.     obj.ClickHelper = interface_s.ComponentsHelpers.Click:new()
  698.     obj.ClickHelper.OnPress = function()
  699.         obj.IsActive = true
  700.       end
  701.     obj.ClickHelper.OnMissClick = function()
  702.         obj.IsActive = false
  703.       end
  704.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  705.       if not self.IsShowing then return end
  706.       self.Focused = IsFocused
  707.       gfx.fillRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BackColor))
  708.       if self.IsActive==true and self.Enabled then
  709.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BorderColor))
  710.         self.PointerBlinkStep = self.PointerBlinkStep + 1
  711.         if self.PointerBlinkStep > 30 then
  712.           self.PointerBlinkStep=0
  713.         end
  714.         if self.PointerBlinkStep > 15 then
  715.           local x = gfx.textSize(string.sub(self.Text, 0,self.PointerIndex) )
  716.           gfx.drawLine(x+self.X+baseX+1,self.Y+baseY+4, x+self.X+baseX+1, self.Y+baseY+self.Height-4,gfx.getColors(self.Theme.PointerColor))
  717.         end
  718.       else
  719.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.UnfocusedBorderColor))
  720.       end
  721.       local x, y = gfx.textSize(string.sub(self.Text, 0,self.PointerIndex) )
  722.       if IsFocused==true and self.Enabled then
  723.         gfx.drawText(self.X+baseX+2,self.Y+baseY+(self.Height-y+3)/2,self.Text,gfx.getColors(self.Theme.TextColor))
  724.       else
  725.         gfx.drawText(self.X+baseX+2,self.Y+baseY+(self.Height-y+3)/2,self.Text,gfx.getColors(self.Theme.UnfocusedTextColor))
  726.       end
  727.     end
  728.     function obj:Show()
  729.       self.IsShowing = true
  730.     end
  731.     function obj:Hide()
  732.       self.IsShowing = false
  733.     end
  734.     function obj:Click(x,y,e,b,w)
  735.       if self.OnClick~=nil then
  736.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  737.         if x==nil then
  738.           return
  739.         end
  740.       end
  741.       if self.Enabled then
  742.         self.ClickHelper:ProcessClick(self.Width,self.Height,self.X,self.Y,x,y,e,b)
  743.       end
  744.     end
  745.     function obj:KeyPress(code, scan, r, ctrl, shift, alt)
  746.       if self.IsActive==true and self.Enabled then
  747.         if scan~=nil then
  748.           if code==8 and self.PointerIndex>0 then
  749.             self.PointerIndex=self.PointerIndex-1
  750.             self.Text=string.sub(self.Text,0,self.PointerIndex)..string.sub(self.Text,self.PointerIndex+2)
  751.             if self.OnTextChanged~=nil then
  752.               self.OnTextChanged(self.Text)
  753.             end
  754.           elseif code==127 and self.PointerIndex~=string.len(self.Text) then
  755.             self.PointerIndex=self.PointerIndex
  756.             self.Text=string.sub(self.Text,0,self.PointerIndex)..string.sub(self.Text,self.PointerIndex+2)
  757.             if self.OnTextChanged~=nil then
  758.               self.OnTextChanged(self.Text)
  759.             end
  760.           elseif code==1073741903 and string.len(self.Text)>=self.PointerIndex+1 then
  761.             self.PointerIndex=self.PointerIndex+1
  762.           elseif code==1073741904 and self.PointerIndex>0 then
  763.             self.PointerIndex=self.PointerIndex-1
  764.           end
  765.         else
  766.           if string.len(self.Text)<=self.MaxTextLength then
  767.             self.PointerIndex=self.PointerIndex+1
  768.             self.Text=string.sub(self.Text,0,self.PointerIndex-1)..code..string.sub(self.Text,self.PointerIndex)
  769.             if self.OnTextChanged~=nil then
  770.               self.OnTextChanged(self.Text)
  771.             end
  772.           end
  773.         end
  774.         return true
  775.       end
  776.     end
  777.     setmetatable(obj, self)
  778.     self.__index = self;
  779.     return obj
  780.   end
  781.  
  782.   function interface_s.Components.Checkbox:new(x, y, s, t, theme)
  783.     local obj= {}
  784.     obj.Type = "Checkbox"
  785.  
  786.     obj.X = x
  787.     obj.Y = y
  788.     obj.Theme = theme
  789.     obj.IsShowing = true
  790.     obj.Size = s
  791.     obj.Text = t
  792.     obj.Enabled = true
  793.     obj.Checked = false
  794.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  795.  
  796.     obj.OnStateChanged = nil
  797.     obj.OnClick = nil
  798.  
  799.     obj.Focused=false
  800.     obj.Base = nil
  801.     obj.ClickHelper = interface_s.ComponentsHelpers.Click:new()
  802.     obj.ClickHelper.OnPress = function()
  803.         if obj.Checked==true then
  804.           obj.Checked = false
  805.         else
  806.           obj.Checked = true
  807.         end
  808.         if obj.OnStateChanged~=nil then
  809.           obj.OnStateChanged(obj.Checked)
  810.         end
  811.       end
  812.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  813.       if not self.IsShowing then return end
  814.       self.Focused = IsFocused
  815.       local x, y = gfx.textSize(self.Text)
  816.       if IsFocused==true and self.Enabled then
  817.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Size,self.Size,gfx.getColors(self.Theme.BorderColor))
  818.         if self.Checked==true then
  819.           gfx.fillRect(self.X+baseX+3,self.Y+baseY+3,self.Size-6,self.Size-6,gfx.getColors(self.Theme.CheckColor))
  820.         end
  821.         gfx.drawText(self.X+baseX+self.Size+4,self.Y+baseY+(self.Size-y)/2+1,self.Text,gfx.getColors(self.Theme.TextColor))
  822.       else
  823.         gfx.drawRect(self.X+baseX,self.Y+baseY,self.Size,self.Size,gfx.getColors(self.Theme.UnfocusedBorderColor))
  824.         if self.Checked==true then
  825.           gfx.fillRect(self.X+baseX+3,self.Y+baseY+3,self.Size-6,self.Size-6,gfx.getColors(self.Theme.UnfocusedCheckColor))
  826.         end
  827.         gfx.drawText(self.X+baseX+self.Size+4,self.Y+baseY+(self.Size-y)/2+1,self.Text,gfx.getColors(self.Theme.UnfocusedCheckColor))
  828.       end
  829.     end
  830.     function obj:Show()
  831.       self.IsShowing = true
  832.     end
  833.     function obj:Hide()
  834.       self.IsShowing = false
  835.     end
  836.     function obj:Click(x,y,e,b,w)
  837.       if self.OnClick~=nil then
  838.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  839.         if x==nil then
  840.           return
  841.         end
  842.       end
  843.       if self.Enabled then
  844.         return self.ClickHelper:ProcessClick(self.Size,self.Size,self.X,self.Y,x,y,e,b)
  845.       end
  846.     end
  847.     setmetatable(obj, self)
  848.     self.__index = self;
  849.     return obj
  850.   end
  851.  
  852.   function interface_s.Components.Selection:new(x, y, theme)
  853.     local obj= {}
  854.     obj.X = x
  855.     obj.Y = y
  856.     obj.Focused=false
  857.     obj.Theme = theme
  858.     obj.IsShowing = true
  859.     obj.IsPointSet = false
  860.     obj.FirstPointX = -1
  861.     obj.FirstPointY = -1
  862.     obj.IsFinished = false
  863.     obj.EndPointX = -1
  864.     obj.EndPointY = -1
  865.     obj.OnSelectionStart = nil
  866.     obj.OnSelected = nil
  867.     obj.OnSelectionAborted = nil
  868.     obj.V2EndWidth = -1
  869.     obj.V2EndHeight = -1
  870.     obj.V2StartX = -1
  871.     obj.V2StartY = -1
  872.     obj.OnClick = nil
  873.     obj.OnDraw = nil
  874.     function obj:Draw(IsFocused,x,y)
  875.       if self.OnDraw~=nil then
  876.         IsFocused,x,y = self.OnDraw(IsFocused,x,y)
  877.         if IsFocused == nil then return end
  878.       end
  879.       self.Focused = IsFocused
  880.       if IsFocused then
  881.         if (self.IsPointSet) and (self.IsFinished==false) then
  882.           local arg11 = -1
  883.           local arg12 = -1
  884.           local arg21 = -1
  885.           local arg22 = -1
  886.           if self.FirstPointX-x>=0 then
  887.             arg11 = x
  888.             arg12 = self.FirstPointX-x
  889.           else
  890.             arg11 = self.FirstPointX
  891.             arg12 = x-self.FirstPointX
  892.           end
  893.           if self.FirstPointY - y>=0 then
  894.             arg21 = y
  895.             arg22 = self.FirstPointY - y
  896.           else
  897.             arg21 = self.FirstPointY
  898.             arg22 = y-self.FirstPointY
  899.           end
  900.           if (self.IsFinished==false) and (self.IsPointSet==true)  then
  901.             self.V2EndWidth = arg12
  902.             self.V2EndHeight = arg22
  903.             self.V2StartX = arg11
  904.             self.V2StartY = arg21
  905.           end
  906.           gfx.fillRect(arg11, arg21, arg12,arg22, gfx.getColors(self.Theme.BackColor))
  907.         end
  908.       else
  909.         self.IsPointSet = false
  910.       end
  911.     end
  912.     function obj:Show()
  913.       self.IsShowing = true
  914.     end
  915.     function obj:Hide()
  916.       self.IsShowing = false
  917.     end
  918.     function obj:Click(x,y,e,b,w)
  919.       if self.OnClick~=nil then
  920.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  921.         if x==nil then
  922.           return
  923.         end
  924.       end
  925.       if (e==mouseEvents.Down) and (self.IsPointSet==false) and (b==1) then
  926.         self.IsPointSet = true
  927.         self.FirstPointX = x
  928.         self.FirstPointY = y
  929.         if self.OnSelectionStart ~= nil then
  930.           self.OnSelectionStart(self.FirstPointX,self.FirstPointY)
  931.         end
  932.         return true
  933.       else
  934.         if (e==mouseEvents.Up) and (self.IsPointSet==true) and (b==1) and (self.IsFinished == false) then
  935.           self.IsFinished = true
  936.           self.EndPointX = x
  937.           self.EndPointY = y
  938.           if self.OnSelected ~= nil then
  939.             self.OnSelected(self.FirstPointX,self.FirstPointY,self.EndPointX,self.EndPointY, self.V2StartX, self.V2StartY, self.V2EndWidth,self.V2EndHeight)
  940.           end
  941.           return true
  942.         end
  943.         if (self.IsPointSet==true) and (b~=1) and (self.IsFinished==false) then
  944.           self.IsPointSet=false
  945.           if self.OnSelectionAborted ~= nil then
  946.             self.OnSelectionAborted()
  947.           end
  948.         end
  949.       end
  950.     end
  951.     function obj:Move()
  952.     end
  953.     function obj:KeyPress(key, scan, r, ctrl, shift, alt)
  954.     end
  955.     setmetatable(obj, self)
  956.     self.__index = self;
  957.     return obj
  958.   end
  959.  
  960.   function interface_s.Components.SelectionMover:new(x, y,w,h, theme)
  961.     local obj= {}
  962.     obj.X = x
  963.     obj.Y = y
  964.     obj.Focused=false
  965.     obj.Theme = theme
  966.     obj.IsShowing = true
  967.     obj.Width = w
  968.     obj.Height = h
  969.     obj.OnMovement = nil
  970.     obj.OnAbort = nil
  971.     obj.OnDone = nil
  972.     obj.MoveStartX = -1
  973.     obj.MoveStartY = -1
  974.     obj.NewPosX = -1
  975.     obj.NewPosY = -1
  976.     obj.IsMoving = false
  977.     obj.SumDX = 0
  978.     obj.SumDY = 0
  979.     obj.IsMoved = false
  980.     obj.OnDraw = nil
  981.     obj.OnClick = nil
  982.     obj.OnMove = nil
  983.     function obj:Draw(IsFocused,x,y)
  984.       if self.OnDraw~=nil then
  985.         self.OnDraw(IsFocused,x,y)
  986.       end
  987.       self.Focused = IsFocused
  988.       gfx.fillRect(self.X, self.Y, self.Width,self.Height, gfx.getColors(self.Theme.BackColor))
  989.     end
  990.     function obj:Show()
  991.       self.IsShowing = true
  992.     end
  993.     function obj:Hide()
  994.       self.IsShowing = false
  995.     end
  996.     function obj:Click(x,y,e,b,w)
  997.       if self.OnClick~=nil then
  998.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  999.         if x==nil then
  1000.           return
  1001.         end
  1002.       end
  1003.       if (e==3) and (self.IsMoving) then  --For old versions
  1004.         if self.OnMovement ~= nil then
  1005.           self.OnMovement(-self.MoveStartX + x,- self.MoveStartY + y)
  1006.         end
  1007.         if (-self.MoveStartX + x ~= 0) and (- self.MoveStartY + y ~= 0) then
  1008.           self.IsMoved = true
  1009.         end
  1010.         self.SumDX = self.SumDX - self.MoveStartX + x
  1011.         self.SumDY = self.SumDY - self.MoveStartY + y
  1012.         self.X = self.X - self.MoveStartX + x
  1013.         self.Y = self.Y - self.MoveStartY + y
  1014.         self.MoveStartX = x
  1015.         self.MoveStartY = y
  1016.       else
  1017.         if (e==mouseEvents.Up) and (self.IsMoving) then
  1018.           if self.IsMoved == false then
  1019.             if self.OnDone ~= nil then
  1020.               self.OnDone(self.SumDX,self.SumDY)
  1021.             end
  1022.           end
  1023.           self.IsMoving = false
  1024.         end
  1025.       end
  1026.       if (x>self.X) and (x<self.X+self.Width) and (y>self.Y) and (y<self.Y+self.Height) then
  1027.         if (e==1) and (b==4) then
  1028.           if self.OnAbort ~= nil then
  1029.             self.OnAbort(self.SumDX,self.SumDY)
  1030.           end
  1031.         end
  1032.         if (y>self.Y) and (y<self.Y+self.Height) and (e==1) then
  1033.           self.MoveStartX = x
  1034.           self.MoveStartY = y
  1035.           self.IsMoving = true
  1036.         end
  1037.         if (e==1) and (b==1) then
  1038.           self.IsMoved = false
  1039.         end
  1040.         return true
  1041.       end
  1042.     end
  1043.     function obj:Move(x,y,dx,dy)
  1044.       if self.OnMove~=nil then
  1045.         x,y,dx,dy = self.OnMove(x,y,dx,dy)
  1046.         if x==nil then
  1047.           return
  1048.         end
  1049.       end
  1050.       if self.IsMoving then
  1051.         if self.OnMovement ~= nil then
  1052.           self.OnMovement(-self.MoveStartX + x,- self.MoveStartY + y)
  1053.         end
  1054.         if (-self.MoveStartX + x ~= 0) and (- self.MoveStartY + y ~= 0) then
  1055.           self.IsMoved = true
  1056.         end
  1057.         self.SumDX = self.SumDX - self.MoveStartX + x
  1058.         self.SumDY = self.SumDY - self.MoveStartY + y
  1059.         self.X = self.X - self.MoveStartX + x
  1060.         self.Y = self.Y - self.MoveStartY + y
  1061.         self.MoveStartX = x
  1062.         self.MoveStartY = y
  1063.       end
  1064.     end
  1065.     function obj:KeyPress(key, scan, r, ctrl, shift, alt)
  1066.     end
  1067.     setmetatable(obj, self)
  1068.     self.__index = self;
  1069.     return obj
  1070.   end
  1071.  
  1072.   function interface_s.Components.Listbox:new(x, y, w, h, theme)
  1073.     local obj= {}
  1074.     obj.Type = "Listbox"
  1075.     obj.X = x
  1076.     obj.Y = y
  1077.     obj.Focused=false
  1078.     obj.Theme = theme
  1079.     obj.IsShowing = true
  1080.     obj.Width = w
  1081.     obj.Height = h
  1082.     obj.Anchor = {Top = false,Bottom=false,Left=false,Right=false}
  1083.     obj.SelectedIndex = 1
  1084.     obj.Items = {}
  1085.     obj.ItemsColsCount = 1
  1086.     obj.ItemsColsPadding = {0}
  1087.  
  1088.     obj.OnItemSelected = nil
  1089.     obj.OnClick = nil
  1090.  
  1091.     obj.Base = nil
  1092.     obj.IsActive = false
  1093.     obj.ScrollStartItemIndex = 1
  1094.     obj.ItemClickHelper = interface_s.ComponentsHelpers.Click:new()
  1095.     obj.ItemClickHelper.OnPress = function(x,y)
  1096.         obj.SelectedIndex=math.floor((y-obj.Y)/11)+obj.ScrollStartItemIndex-1
  1097.         if obj.OnItemSelected~= nil then
  1098.           obj.OnItemSelected(obj.SelectedIndex,obj.Items[obj.SelectedIndex])
  1099.         end
  1100.         return true
  1101.     end
  1102.     function obj:Draw(IsFocused, baseX, baseY,x,y)
  1103.       if not self.IsShowing then return end
  1104.       self.Focused = IsFocused
  1105.       gfx.fillRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BackColor))
  1106.       gfx.drawRect(self.X+baseX,self.Y+baseY,self.Width,self.Height,gfx.getColors(self.Theme.BorderColor))
  1107.       local endindex = math.floor(self.Height/11)+self.ScrollStartItemIndex-1
  1108.       if table.getn(self.Items)<math.floor(self.Height/11) then
  1109.         endindex = table.getn(self.Items)
  1110.       end
  1111.       for i=self.ScrollStartItemIndex, endindex do
  1112.         if IsFocused then
  1113.           if self.SelectedIndex==i-1 then
  1114.             gfx.fillRect(self.X+baseX+2,self.Y+baseY+(i-self.ScrollStartItemIndex)*11+2,self.Width-4,10,gfx.getColors(self.Theme.SelectionColor))
  1115.             if self.ItemsColsCount==1 then
  1116.               gfx.drawText(self.X+baseX+3,self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i],gfx.getColors(self.Theme.SelectionTextColor))
  1117.             else
  1118.               for j=1, self.ItemsColsCount do
  1119.                 gfx.drawText(self.X+baseX+3+self.ItemsColsPadding[j],self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i][j],gfx.getColors(self.Theme.SelectionTextColor))
  1120.               end
  1121.             end
  1122.           else
  1123.             if self.ItemsColsCount==1 then
  1124.               gfx.drawText(self.X+baseX+3,self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i],gfx.getColors(self.Theme.TextColor))
  1125.             else
  1126.               for j=1, self.ItemsColsCount do
  1127.                 gfx.drawText(self.X+baseX+3+self.ItemsColsPadding[j],self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i][j],gfx.getColors(self.Theme.TextColor))
  1128.               end
  1129.             end
  1130.           end
  1131.           if x>self.X+3 and x<self.X+self.Width and y>self.Y+(i-self.ScrollStartItemIndex)*11 and y<self.Y+(i-self.ScrollStartItemIndex)*11+11 then
  1132.             gfx.fillRect(self.X+baseX+1,self.Y+baseY+(i-self.ScrollStartItemIndex)*11,self.Width-2,12,gfx.getColors(self.Theme.MouseOverColor))
  1133.           end
  1134.       else -- unfocused
  1135.         if self.SelectedIndex==i-1 then
  1136.           gfx.fillRect(self.X+baseX+2,self.Y+baseY+(i-self.ScrollStartItemIndex)*11+2,self.Width-4,10,gfx.getColors(self.Theme.UnfocusedSelectionColor))
  1137.           if self.ItemsColsCount==1 then
  1138.             gfx.drawText(self.X+baseX+3,self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i],gfx.getColors(self.Theme.UnfocusedSelectionTextColor))
  1139.           else
  1140.             for j=1, self.ItemsColsCount do
  1141.               gfx.drawText(self.X+baseX+3+self.ItemsColsPadding[j],self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i][j],gfx.getColors(self.Theme.UnfocusedSelectionTextColor))
  1142.             end
  1143.           end
  1144.         else
  1145.           if self.ItemsColsCount==1 then
  1146.             gfx.drawText(self.X+baseX+3,self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i],gfx.getColors(self.Theme.UnfocusedTextColor))
  1147.           else
  1148.             for j=1, self.ItemsColsCount do
  1149.               gfx.drawText(self.X+baseX+3+self.ItemsColsPadding[j],self.Y+baseY+3+(i-self.ScrollStartItemIndex)*11,self.Items[i][j],gfx.getColors(self.Theme.UnfocusedTextColor))
  1150.             end
  1151.           end
  1152.         end
  1153.         if x>self.X+3 and x<self.X+self.Width and y>self.Y+(i-self.ScrollStartItemIndex)*11 and y<self.Y+(i-self.ScrollStartItemIndex)*11+11 then
  1154.           gfx.fillRect(self.X+baseX+1,self.Y+baseY+(i-self.ScrollStartItemIndex)*11,self.Width-2,12,gfx.getColors(self.Theme.UnfocusedMouseOverColor))
  1155.         end
  1156.       end
  1157.     end
  1158.     end
  1159.     function obj:Show()
  1160.       self.IsShowing = true
  1161.     end
  1162.     function obj:Hide()
  1163.       self.IsShowing = false
  1164.     end
  1165.     function obj:Click(x,y,e,b,w)
  1166.       if self.OnClick~=nil then
  1167.         x,y,e,b,w = self.OnClick(x,y,e,b,w)
  1168.         if x==nil then
  1169.           return
  1170.         end
  1171.       end
  1172.       if w==1 and self.ScrollStartItemIndex<table.getn(self.Items)-math.floor( self.Height/11 )+1 then
  1173.         self.ScrollStartItemIndex=self.ScrollStartItemIndex+1
  1174.         return true
  1175.       elseif w==-1 and self.ScrollStartItemIndex>1 then
  1176.         self.ScrollStartItemIndex=self.ScrollStartItemIndex-1
  1177.         return true
  1178.       end
  1179.       return self.ItemClickHelper:ProcessClick(self.Width,(#self.Items-self.ScrollStartItemIndex+1)*11,self.X,self.Y,x,y,e,b)
  1180.     end
  1181.     setmetatable(obj, self)
  1182.     self.__index = self;
  1183.     return obj
  1184.   end
  1185.  
  1186.   function interface_s.ComponentsHelpers.Click:new(x, y)
  1187.     local obj= {}
  1188.     obj.IsFirstClick = false
  1189.     obj.OnPress = nil
  1190.     obj.OnFirstClick = nil
  1191.     obj.OnMissClick = nil
  1192.     function obj:ProcessClick(width,height,x,y,clickX,clickY,e,b)
  1193.       if (clickX>x) and (clickX<x+width) and (clickY>y) and (clickY<y+height) and (self.IsFirstClick==false) and (e==mouseEvents.Down) and (b==1) then
  1194.         self.IsFirstClick=true
  1195.         if self.OnFirstClick ~= nil then
  1196.           return self.OnFirstClick(clickX,clickY)
  1197.         else
  1198.           return true
  1199.         end
  1200.       else
  1201.         if (clickX>x) and (clickX<x+width) and (clickY>y) and (clickY<y+height) and (self.IsFirstClick==true) and (e==mouseEvents.Up) and (b==1) then
  1202.           self.IsFirstClick = false  
  1203.           if self.OnPress~= nil then
  1204.             return self.OnPress(clickX,clickY)
  1205.           else
  1206.             return true
  1207.           end
  1208.         else
  1209.           self.IsFirstClick = false
  1210.           if self.OnMissClick~= nil then
  1211.             return self.OnMissClick(clickX,clickY)
  1212.           end
  1213.         end
  1214.       end
  1215.     end
  1216.     setmetatable(obj, self)
  1217.     self.__index = self;
  1218.     return obj
  1219.   end
  1220.   function interface_s.ComponentsHelpers.Hint:new()
  1221.     local obj= {}
  1222.     obj.HintFrames = 0
  1223.     obj.Window = interface_s.Components.Window:new(0, 0, 0, 12,false, interface_s.DefaultTheme.Window)
  1224.     obj.Label = interface_s.Components.Label:new(5,2,"",interface_s.DefaultTheme.Label)
  1225.     obj.Window:AddComponent(obj.Label)
  1226.     obj.Window.AllowResize = false
  1227.     obj.Window.AlwaysFocused = true
  1228.     function obj:MouseOver(x,y,text)
  1229.       if text~="" then
  1230.         self.HintFrames = self.HintFrames + 1
  1231.         if self.HintFrames>40 then
  1232.           local w,h = gfx.textSize(text)
  1233.           self.Window.X = x
  1234.           self.Window.Y = y+12
  1235.           self.Window.Width = w+10
  1236.           self.Label.Text = text
  1237.           self.Window:Draw(true,x,y)
  1238.         end
  1239.       end
  1240.     end
  1241.     function obj:Reset()
  1242.       self.HintFrames = 0
  1243.     end
  1244.     setmetatable(obj, self)
  1245.     self.__index = self;
  1246.     return obj
  1247.   end
  1248. end
  1249. local function DefineAPI()
  1250.   interface_s.Components.Window = {}
  1251.   interface_s.Components.Button = {}
  1252.   interface_s.Components.Combobox = {}
  1253.   interface_s.Components.Graph = {}
  1254.   interface_s.Components.Label = {}
  1255.   interface_s.Components.Textbox = {}
  1256.   interface_s.Components.Checkbox = {}
  1257.   interface_s.Components.Listbox = {}
  1258.   interface_s.Components.Selection = {}
  1259.   interface_s.Components.SelectionMover = {}
  1260.   interface_s.ComponentsHelpers.Click = {}
  1261.   interface_s.ComponentsHelpers.Hint = {}
  1262.  
  1263.   interface_s.AddOnClickAction = function(func)
  1264.     for i=#interface_s.OnClick+1,2,-1 do
  1265.       interface_s.OnClick[i]=interface_s.OnClick[i-1]
  1266.     end
  1267.     if type(func) == "function" then
  1268.       interface_s.OnClick[1]={}
  1269.       interface_s.OnClick[1].Click = func
  1270.     else
  1271.       interface_s.OnClick[1] = func
  1272.     end
  1273.   end
  1274.  
  1275.   interface_s.RemoveOnClickAction = function(func)
  1276.     local index = interface_s.GetOnClickActionIndex(func)
  1277.     if index~=-1 then
  1278.       interface_s.OnClick[index] = 0
  1279.     end
  1280.   end
  1281.  
  1282.   interface_s.GetOnClickActionIndex=function(obj)
  1283.     if type(obj) == "function" then
  1284.       for i=1, #interface_s.OnClick do
  1285.         if interface_s.OnClick[i]~=0 then
  1286.           if interface_s.OnClick[i].Click == obj then
  1287.             return i
  1288.           end
  1289.         end
  1290.       end
  1291.     else
  1292.       for i=1, #interface_s.OnClick do
  1293.         if interface_s.OnClick[i] == obj then
  1294.           return i
  1295.         end
  1296.       end
  1297.     end
  1298.     return -1
  1299.   end
  1300.  
  1301.   interface_s.AddOnStepAction = function(func)
  1302.     for i=#interface_s.OnStep+1,2,-1 do
  1303.       interface_s.OnStep[i]=interface_s.OnStep[i-1]
  1304.     end
  1305.     interface_s.OnStep[1] = func
  1306.   end
  1307.  
  1308.   interface_s.RemoveOnStepAction = function(func)
  1309.     local index = interface_s.GetOnStepActionIndex(func)
  1310.     if index~=-1 then
  1311.       interface_s.OnStep[index]=0
  1312.     end
  1313.   end
  1314.  
  1315.   interface_s.GetOnStepActionIndex=function(obj)
  1316.     for i=1, #interface_s.OnStep do
  1317.       if interface_s.OnStep[i] == obj then
  1318.         return i
  1319.       end
  1320.     end
  1321.     return -1
  1322.   end
  1323.  
  1324.   interface_s.AddKeyPressAction = function(func)
  1325.     for i=#interface_s.OnKeyPress+1,2,-1 do
  1326.       interface_s.OnKeyPress[i]=interface_s.OnKeyPress[i-1]
  1327.     end
  1328.     if type(func) == "function" then
  1329.       interface_s.OnKeyPress[1]={}
  1330.       interface_s.OnKeyPress[1].KeyPress = func
  1331.     else
  1332.       interface_s.OnKeyPress[1] = func
  1333.     end
  1334.   end
  1335.  
  1336.   interface_s.RemoveKeyPressAction = function(func)
  1337.     local index = interface_s.GetOnKeyPressActionIndex(func)
  1338.     if index~=-1 then
  1339.       interface_s.OnKeyPress[index]=0
  1340.     end
  1341.   end
  1342.  
  1343.   interface_s.GetOnKeyPressActionIndex=function(obj)
  1344.     if type(obj) == "function" then
  1345.       for i=1, #interface_s.OnKeyPress do
  1346.         if interface_s.OnKeyPress[i].KeyPress == obj then
  1347.           return i
  1348.         end
  1349.       end
  1350.     else
  1351.       for i=1, #interface_s.OnKeyPress do
  1352.         if interface_s.OnKeyPress[i] == obj then
  1353.           return i
  1354.         end
  1355.       end
  1356.     end
  1357.     return -1
  1358.   end
  1359.   interface_s.AddLeftWindow=function(obj)
  1360.     for i=#interface_s.windows+1,2,-1 do
  1361.       interface_s.windows[i]=interface_s.windows[i-1]
  1362.     end
  1363.     interface_s.windows[1]=obj
  1364.   end
  1365.  
  1366.   interface_s.addComponent=function(obj)
  1367.     interface_s.AddLeftWindow(obj)
  1368.   end
  1369.  
  1370.   interface_s.GetComponentIndex=function(obj)
  1371.     for i=1, #interface_s.windows do
  1372.       if interface_s.windows[i] == obj then
  1373.         return i
  1374.       end
  1375.     end
  1376.     return -1
  1377.   end
  1378.  
  1379.   interface_s.RemoveComponent=function(obj)
  1380.     local index = interface_s.GetComponentIndex(obj)
  1381.     if index~=-1 then
  1382.       for i=index, #interface_s.windows-1 do
  1383.         interface_s.windows[i]=interface_s.windows[i+1]
  1384.       end
  1385.       interface_s.windows[#interface_s.windows] = nil
  1386.     end
  1387.   end
  1388.  
  1389.   interface_s.focusComponent = function(index)
  1390.     local temp= interface_s.windows[index]
  1391.     for i=index, 2,-1 do
  1392.       interface_s.windows[i] = interface_s.windows[i-1]
  1393.     end
  1394.     interface_s.windows[1] = temp
  1395.   end
  1396.  
  1397.   interface_s.deleteFromArray = function(ar,index)
  1398.     for i=index, #ar-1 do
  1399.       ar[i]=ar[i+1]
  1400.     end
  1401.     ar[#ar] = nil
  1402.   end
  1403.  
  1404.   interface_s.step = function()
  1405.     local deletedFound = false
  1406.     for i=1,#interface_s.OnStep do
  1407.       if interface_s.OnStep[i]~=0 then
  1408.         interface_s.OnStep[i](tpt.mousex,tpt.mousey)
  1409.       else
  1410.         deletedFound = true
  1411.       end
  1412.     end
  1413.     if deletedFound then
  1414.       for i=1,#interface_s.OnStep do
  1415.         if interface_s.OnStep[i]==0 then
  1416.           interface_s.deleteFromArray(interface_s.OnStep,i)
  1417.           i=i-1
  1418.         end
  1419.       end
  1420.     end
  1421.     for i=#interface_s.windows, 1,-1 do
  1422.       if (interface_s.windows[i] ~= nil) and (interface_s.windows[i].IsShowing==true) then
  1423.         if i==1 then
  1424.           interface_s.windows[i]:Draw(true,tpt.mousex,tpt.mousey)
  1425.         else
  1426.           interface_s.windows[i]:Draw(false,tpt.mousex,tpt.mousey)
  1427.         end
  1428.       end
  1429.     end
  1430.   end
  1431.  
  1432.   interface_s.click = function(mousex, mousey, button, event,wheel)
  1433.     if event==3 then
  1434.       interface_s.mousemove(mousex,mousey,-1,-1)
  1435.       return true
  1436.     end
  1437.     local deletedFound = false
  1438.     local f = false
  1439.     for i=1,#interface_s.OnClick do
  1440.       if interface_s.OnClick[i]~=0 then
  1441.         if interface_s.OnClick[i].Base~=nil then
  1442.           if interface_s.OnClick[i]:Click(mousex-interface_s.OnClick[i].Base.X , mousey-interface_s.OnClick[i].Base.Y , event, button,wheel) then
  1443.             f=true
  1444.           end
  1445.         else
  1446.           if interface_s.OnClick[i].Click(mousex, mousey, event, button,wheel) then
  1447.             f=true
  1448.           end
  1449.         end
  1450.       else
  1451.         deletedFound = true
  1452.       end
  1453.     end
  1454.     if deletedFound then
  1455.       for i=1,#interface_s.OnClick do
  1456.         if interface_s.OnClick[i]==0 then
  1457.           interface_s.deleteFromArray(interface_s.OnClick,i)
  1458.           i=i-1
  1459.         end
  1460.       end
  1461.     end
  1462.     for i=1,#interface_s.windows do
  1463.       if interface_s.windows[i] == nil then
  1464.         interface_s.RemoveComponent(interface_s.windows[i])
  1465.         break
  1466.       end
  1467.       if (interface_s.windows ~= nil) then
  1468.         if interface_s.windows[i]:Click(mousex , mousey , event, button,wheel) then
  1469.           if (interface_s.windows[i]~=nil) and (interface_s.windows[i].IsShowing~=nil) and (interface_s.windows[i].IsShowing==true) then
  1470.             interface_s.focusComponent(i)
  1471.             return false
  1472.           end
  1473.         end
  1474.       end
  1475.     end
  1476.     if f==true then
  1477.       return false
  1478.     end
  1479.   end
  1480.  
  1481.   interface_s.key = function(char, code, mod, evt)
  1482.     local f = false
  1483.     if interface_s.windows[1] ~= nil then
  1484.       if interface_s.windows[1]:KeyPress(char, code, mod, evt) then
  1485.         f = true
  1486.       end
  1487.     end
  1488.     local deletedFound = false
  1489.     for i=1,#interface_s.OnKeyPress do
  1490.       if interface_s.OnKeyPress[i]~=0 then
  1491.         if interface_s.OnKeyPress[i].Base~=nil then
  1492.           if interface_s.OnKeyPress[i]:KeyPress(char, code, mod, evt) then
  1493.             f=true
  1494.           end
  1495.         else
  1496.           if interface_s.OnKeyPress[i].KeyPress(char, code, mod, evt) then
  1497.             f=true
  1498.           end
  1499.         end
  1500.       else
  1501.         deletedFound = true
  1502.       end
  1503.     end
  1504.     if deletedFound then
  1505.       for i=1,#interface_s.OnKeyPress do
  1506.         if interface_s.OnKeyPress[i]==0 then
  1507.           interface_s.deleteFromArray(interface_s.OnKeyPress,i)
  1508.           i=i-1
  1509.         end
  1510.       end
  1511.     end
  1512.     if interface_s.BlockKeyboard == true or f==true then
  1513.       return false
  1514.     end
  1515.   end
  1516.  
  1517.   interface_s.mousemove = function(x, y, dx, dy)
  1518.     for i=1,#interface_s.windows do
  1519.       if interface_s.windows[i] == nil then
  1520.         interface_s.RemoveComponent(interface_s.windows[i])
  1521.         break
  1522.       end
  1523.       if (interface_s.windows ~= nil) then
  1524.         if interface_s.windows[i]:Move(x , y , dx, dy) then
  1525.           if (interface_s.windows[i]~=nil) and (interface_s.windows[i].IsShowing~=nil) and (interface_s.windows[i].IsShowing==true) then
  1526.             interface_s.focusComponent(i)
  1527.             return false
  1528.           end
  1529.         end
  1530.       end
  1531.     end
  1532.   end
  1533.  
  1534.   interface_s.mouseUpToClick = function(x, y, b)
  1535.     return interface_s.click(x,y,b,mouseEvents.Up)
  1536.   end
  1537.  
  1538.   interface_s.mouseDownToClick = function(x, y, b)
  1539.     return interface_s.click(x,y,b,mouseEvents.Down)
  1540.   end
  1541.  
  1542.   interface_s.mouseWheelToClick = function(x, y, d)
  1543.     return interface_s.click(x,y,0,0,d)
  1544.   end
  1545.  
  1546.   if tpt.version.major<=93 and tpt.version.jacob1s_mod==nil or tpt.version.jacob1s_mod~=nil and tpt.version.jacob1s_mod<42 then
  1547.     tpt.register_step(interface_s.step)
  1548.     tpt.register_mouseclick(interface_s.click)
  1549.     tpt.register_keypress(interface_s.key)
  1550.   else
  1551.     event.register(event.tick, interface_s.step)  
  1552.     event.register(event.mousedown, interface_s.mouseDownToClick)
  1553.     event.register(event.mouseup, interface_s.mouseUpToClick)
  1554.     event.register(event.mousemove, interface_s.mousemove)
  1555.     event.register(event.mousewheel, interface_s.mouseWheelToClick)
  1556.     event.register(event.keypress, interface_s.key)
  1557.     event.register(event.textinput, interface_s.key)
  1558.   end
  1559. end
  1560. local function unregisterOldVerionEvents()
  1561.   pcall(tpt.unregister_step,interface_s.step)
  1562.   pcall(tpt.unregister_mouseclick,interface_s.click)
  1563.   pcall(tpt.unregister_keypress,interface_s.key)
  1564.   if event~=nil then
  1565.     pcall(event.unregister,event.mousedown,interface_s.mouseDownToClick)
  1566.     pcall(event.unregister,event.mouseup,interface_s.mouseUpToClick)
  1567.     pcall(event.unregister,event.mousemove,interface_s.mousemove)
  1568.     pcall(event.unregister,event.mousewheel,interface_s.mouseWheelToClick)
  1569.     pcall(event.unregister,event.keypress,interface_s.key)
  1570.     pcall(event.unregister,event.textinput,interface_s.key)
  1571.   end
  1572. end
  1573. local function InitIntefaceAPI()
  1574.   if interface_s == nil then
  1575.     interface_s = {
  1576.       Version = InterfaceAPIVersion,
  1577.       Components = {},
  1578.       ComponentsHelpers = {},
  1579.       windows = {},
  1580.       step = nil,
  1581.       click = nil,
  1582.       mouseUpToClick = nil,
  1583.       mouseDownToClick = nil,
  1584.       mouseWheelToClick = nil,
  1585.       mousemove = nil,
  1586.       key = nil,
  1587.       addLeft = nil,
  1588.       addComponent = nil,
  1589.       GetComponentIndex = nil,
  1590.       RemoveComponent = nil,
  1591.       focusComponent = nil,
  1592.       BlockKeyboard = false,
  1593.       OnClick = {},
  1594.       OnKeyPress = {},
  1595.       OnStep = {},
  1596.       DefaultTheme = {}
  1597.     }
  1598.     DefineAPI()
  1599.     DefineInterfaceComponents()
  1600.   else
  1601.     if interface_s.Version<InterfaceAPIVersion then
  1602.       unregisterOldVerionEvents()
  1603.       interface_s = {
  1604.         Version = InterfaceAPIVersion,
  1605.         Components = {},
  1606.         ComponentsHelpers = {},
  1607.         windows = interface_s.windows,
  1608.         step = nil,
  1609.         click = nil,
  1610.         mouseUpToClick = nil,
  1611.         mouseDownToClick = nil,
  1612.         mouseWheelToClick = nil,
  1613.         mousemove = nil,
  1614.         key = nil,
  1615.         addLeft = nil,
  1616.         addComponent = nil,
  1617.         GetComponentIndex = nil,
  1618.         RemoveComponent = nil,
  1619.         focusComponent = nil,
  1620.         BlockKeyboard = interface_s.BlockKeyboard,
  1621.         OnClick = interface_s.OnClick or {},
  1622.         OnKeyPress = interface_s.OnKeyPress or {},
  1623.         OnStep = interface_s.OnStep or {},
  1624.         DefaultTheme = interface_s.DefaultTheme or {}
  1625.       }
  1626.       DefineAPI()
  1627.       DefineInterfaceComponents()
  1628.     end
  1629.   end
  1630. end
  1631. InitIntefaceAPI()
  1632. --=================================================================--
  1633. --                       THEME START                               --
  1634. --=================================================================--
  1635. interface_s.DefaultTheme = {
  1636.   Window = {},
  1637.   Button = {},
  1638.   Combobox = {},
  1639.   Graph = {},
  1640.   Label = {},
  1641.   Textbox = {},
  1642.   Checkbox = {},
  1643.   Listbox = {},
  1644.   Selection = {}
  1645. }
  1646.  
  1647. interface_s.DefaultTheme.Window.BackColor = gfx.getHexColor(0,0,0,255)
  1648. interface_s.DefaultTheme.Window.UnfocusedBackColor = gfx.getHexColor(0,0,0,255)
  1649. interface_s.DefaultTheme.Window.BorderColor = gfx.getHexColor(255,255,255,255)
  1650. interface_s.DefaultTheme.Window.UnfocusedBorderColor = gfx.getHexColor(150,150,150,255)
  1651. interface_s.DefaultTheme.Window.HeaderColor = gfx.getHexColor(150,150,255,255)
  1652. interface_s.DefaultTheme.Window.UnfocusedHeaderColor = gfx.getHexColor(32,32,55,255)
  1653.  
  1654. interface_s.DefaultTheme.Button.BackColor = gfx.getHexColor(0,0,0,0)
  1655. interface_s.DefaultTheme.Button.UnfocusedBackColor = gfx.getHexColor(0,0,0,0)
  1656. interface_s.DefaultTheme.Button.PressedBackColor = gfx.getHexColor(240,240,240,255)
  1657. interface_s.DefaultTheme.Button.BorderColor = gfx.getHexColor(255,255,255,255)
  1658. interface_s.DefaultTheme.Button.UnfocusedBorderColor = gfx.getHexColor(150,150,150,255)
  1659. interface_s.DefaultTheme.Button.MouseOverColor = gfx.getHexColor(255,255,255,128)
  1660. interface_s.DefaultTheme.Button.UnfocusedMouseOverColor = gfx.getHexColor(150,150,150,128)
  1661. interface_s.DefaultTheme.Button.TextColor = gfx.getHexColor(255,255,255,255)
  1662. interface_s.DefaultTheme.Button.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1663. interface_s.DefaultTheme.Button.PressedTextColor = gfx.getHexColor(0,0,0,255)
  1664.  
  1665. interface_s.DefaultTheme.Combobox.BackColor = gfx.getHexColor(0,0,0,255)
  1666. interface_s.DefaultTheme.Combobox.UnfocusedBackColor = gfx.getHexColor(0,0,0,255)
  1667. interface_s.DefaultTheme.Combobox.BorderColor = gfx.getHexColor(255,255,255,255)
  1668. interface_s.DefaultTheme.Combobox.UnfocusedBorderColor = gfx.getHexColor(150,150,150,255)
  1669. interface_s.DefaultTheme.Combobox.TextColor = gfx.getHexColor(255,255,255,255)
  1670. interface_s.DefaultTheme.Combobox.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1671. interface_s.DefaultTheme.Combobox.ButtonBackColor = gfx.getHexColor(0,0,0,255)
  1672. interface_s.DefaultTheme.Combobox.ButtonPressedBackColor = gfx.getHexColor(255,255,255,255)
  1673. interface_s.DefaultTheme.Combobox.ButtonMouseOverBackColor = gfx.getHexColor(150,150,150,128)
  1674. interface_s.DefaultTheme.Combobox.UnfocusedButtonBackColor = gfx.getHexColor(0,0,0,255)
  1675. interface_s.DefaultTheme.Combobox.UnfocusedButtonMouseOverBackColor = gfx.getHexColor(150,150,150,128)
  1676.  
  1677. interface_s.DefaultTheme.Graph.BackColor = gfx.getHexColor(0,0,0,255)
  1678. interface_s.DefaultTheme.Graph.BorderColor = gfx.getHexColor(255,255,255,255)
  1679. interface_s.DefaultTheme.Graph.UnfocusedBackColor = gfx.getHexColor(0,0,0,255)
  1680. interface_s.DefaultTheme.Graph.UnfocusedBorderColor = gfx.getHexColor(150,150,150,255)
  1681. interface_s.DefaultTheme.Graph.TextColor = gfx.getHexColor(255,255,255,255)
  1682. interface_s.DefaultTheme.Graph.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1683. interface_s.DefaultTheme.Graph.GraphColor = gfx.getHexColor(255,100,100,255)
  1684. interface_s.DefaultTheme.Graph.UnfocusedGraphColor = gfx.getHexColor(100,30,30,255)
  1685. interface_s.DefaultTheme.Graph.ZeroLine = gfx.getHexColor(255,200,200,255)
  1686. interface_s.DefaultTheme.Graph.UnfocusedZeroLine = gfx.getHexColor(100,80,80,255)
  1687.  
  1688. interface_s.DefaultTheme.Label.TextColor = gfx.getHexColor(255,255,255,255)
  1689. interface_s.DefaultTheme.Label.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1690.  
  1691. interface_s.DefaultTheme.Textbox.BackColor = gfx.getHexColor(0,0,0,255)
  1692. interface_s.DefaultTheme.Textbox.BorderColor = gfx.getHexColor(255,200,200,255)
  1693. interface_s.DefaultTheme.Textbox.TextColor = gfx.getHexColor(255,255,255,255)
  1694. interface_s.DefaultTheme.Textbox.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1695. interface_s.DefaultTheme.Textbox.PointerColor = gfx.getHexColor(255,255,255,255)
  1696. interface_s.DefaultTheme.Textbox.UnfocusedBorderColor = gfx.getHexColor(200,200,200,255)
  1697.  
  1698. interface_s.DefaultTheme.Checkbox.BorderColor = gfx.getHexColor(255,255,255,255)
  1699. interface_s.DefaultTheme.Checkbox.UnfocusedBorderColor = gfx.getHexColor(150,150,150,255)
  1700. interface_s.DefaultTheme.Checkbox.CheckColor = gfx.getHexColor(255,255,255,255)
  1701. interface_s.DefaultTheme.Checkbox.UnfocusedCheckColor = gfx.getHexColor(150,150,150,255)
  1702. interface_s.DefaultTheme.Checkbox.TextColor = gfx.getHexColor(255,255,255,255)
  1703. interface_s.DefaultTheme.Checkbox.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1704.  
  1705. interface_s.DefaultTheme.Listbox.BackColor = gfx.getHexColor(0,0,0,255)
  1706. interface_s.DefaultTheme.Listbox.BorderColor = gfx.getHexColor(255,255,255,255)
  1707. interface_s.DefaultTheme.Listbox.SelectionColor = gfx.getHexColor(255,255,255,255)
  1708. interface_s.DefaultTheme.Listbox.SelectionTextColor = gfx.getHexColor(0,0,0,255)
  1709. interface_s.DefaultTheme.Listbox.TextColor = gfx.getHexColor(255,255,255,255)
  1710. interface_s.DefaultTheme.Listbox.MouseOverColor = gfx.getHexColor(255,255,255,50)
  1711. interface_s.DefaultTheme.Listbox.UnfocusedBackColor = gfx.getHexColor(0,0,0,255)
  1712. interface_s.DefaultTheme.Listbox.UnfocusedBorderColor = gfx.getHexColor(150,150,150,255)
  1713. interface_s.DefaultTheme.Listbox.UnfocusedSelectionColor = gfx.getHexColor(150,150,150,255)
  1714. interface_s.DefaultTheme.Listbox.UnfocusedSelectionTextColor = gfx.getHexColor(0,0,0,255)
  1715. interface_s.DefaultTheme.Listbox.UnfocusedTextColor = gfx.getHexColor(150,150,150,255)
  1716. interface_s.DefaultTheme.Listbox.UnfocusedMouseOverColor = gfx.getHexColor(150,150,150,50)
  1717.  
  1718. interface_s.DefaultTheme.Selection.BackColor = gfx.getHexColor(140,140,200,70)
  1719. --=================================================================--
  1720. --                         THEME END                               --
  1721. --=================================================================--
  1722. --=================================================================--
  1723. --                    CODE IS BELOW THIS LINE                      --
  1724. --=================================================================--
  1725.   local function round(n)
  1726.     return math.floor(n+0.5)
  1727.   end
  1728.  
  1729. --==========================Zoom gfx============================--
  1730. local isZoomActive = false
  1731. local zoomPixelSize = -1
  1732. local zoomWidthInRealPixels = -1
  1733. local zoomRealPositionX = -1
  1734. local zoomRealPositionY = -1
  1735. local zoomWindowPositionX = -1
  1736. local zoomWindowPositionY = -1
  1737. local zoomWindowSize = -1
  1738. local function getZoomInfo()
  1739.   isZoomActive=false
  1740.   if sim.adjustCoords(sim.XRES-1,5)~=sim.XRES-1 then
  1741.     isZoomActive=true
  1742.     local x,y = sim.adjustCoords(sim.XRES-1,2)
  1743.     zoomRealPositionX = x
  1744.     zoomRealPositionY = y
  1745.     local i=sim.XRES-2
  1746.     while x==sim.adjustCoords(i,2) do
  1747.       i=i-1
  1748.     end
  1749.     zoomPixelSize = sim.XRES-i-1
  1750.     i=zoomPixelSize
  1751.     while sim.adjustCoords(sim.XRES-i,2)~=sim.XRES-i do
  1752.       i=i+zoomPixelSize
  1753.     end
  1754.     zoomWidthInRealPixels = (i-zoomPixelSize)/zoomPixelSize
  1755.     zoomRealPositionX=zoomRealPositionX-zoomWidthInRealPixels+1
  1756.     zoomWindowPositionX = sim.XRES-i+zoomPixelSize
  1757.     if tpt.version.jacob1s_mod~=nil then
  1758.       zoomWindowPositionY = 1
  1759.     else
  1760.       zoomWindowPositionY = 0
  1761.     end
  1762.     zoomWindowSize = zoomPixelSize*zoomWidthInRealPixels
  1763.   else
  1764.     if sim.adjustCoords(1,5)~=1 then
  1765.       isZoomActive=true
  1766.       local x,y = sim.adjustCoords(1,2)
  1767.       zoomRealPositionX = x
  1768.       zoomRealPositionY = y
  1769.       local i=2
  1770.       while x==sim.adjustCoords(i,2) do
  1771.         i=i+1
  1772.       end
  1773.       if tpt.version.jacob1s_mod~=nil then
  1774.         zoomPixelSize = i-1
  1775.       else
  1776.         zoomPixelSize = i
  1777.       end
  1778.       i=zoomPixelSize
  1779.       while sim.adjustCoords(i,2)~=i do
  1780.         i=i+zoomPixelSize
  1781.       end
  1782.       zoomWidthInRealPixels = (i-zoomPixelSize)/zoomPixelSize
  1783.       if tpt.version.jacob1s_mod~=nil then
  1784.         zoomWindowPositionX = 1
  1785.         zoomWindowPositionY = 1
  1786.       else
  1787.         zoomWindowPositionX = 0
  1788.         zoomWindowPositionY = 0
  1789.       end
  1790.       zoomWindowSize = zoomPixelSize*zoomWidthInRealPixels+1
  1791.     end
  1792.   end
  1793. end
  1794.  
  1795. local function CoordinatesToZoomWindow(x,y)
  1796.   return zoomWindowPositionX+(x-zoomRealPositionX)*zoomPixelSize,zoomWindowPositionY+(y-zoomRealPositionY)*zoomPixelSize
  1797. end
  1798.  
  1799. local function drawPixelInZoomWindow(x,y,r,g,b,a)
  1800.   if isZoomActive then
  1801.     x = round(x)
  1802.     y = round(y)
  1803.     if x>=zoomRealPositionX and x<zoomRealPositionX+zoomWidthInRealPixels and y>=zoomRealPositionY and y<zoomRealPositionY+zoomWidthInRealPixels then
  1804.       local posX,posY = CoordinatesToZoomWindow(x,y)
  1805.       graphics.fillRect(posX,posY,zoomPixelSize-1,zoomPixelSize-1,r,g,b,a)
  1806.     end
  1807.   end
  1808. end
  1809. local function drawRectangleInZoomWindow(x,y,w,h,r,g,b,a)
  1810.   if isZoomActive then
  1811.     local leftX = math.max(x,zoomRealPositionX)
  1812.     local rightX = math.min(x+w,zoomRealPositionX+zoomWidthInRealPixels)
  1813.     local topY = math.max(y,zoomRealPositionY)
  1814.     local bottomY = math.min(y+h,zoomRealPositionY+zoomWidthInRealPixels)
  1815.     if leftX < rightX and topY < bottomY then
  1816.       local posX,posY = CoordinatesToZoomWindow(leftX,topY)
  1817.       graphics.fillRect(posX,posY,(rightX-leftX)*(zoomPixelSize),(bottomY-topY)*(zoomPixelSize),r,g,b,a)
  1818.     end
  1819.   end
  1820. end
  1821. --==========================Zoom gfx end========================--
  1822.  
  1823. local DefaultTheme = interface_s.DefaultTheme
  1824. function Find()
  1825.   local mainWindow = interface_s.Components.Window:new(10, 10, 60, 60,true, DefaultTheme.Window)
  1826.   mainWindow.AllowResize = false
  1827.   interface_s.addComponent(mainWindow)
  1828.  
  1829.   local selection = nil
  1830.   local selectionMover = nil
  1831.  
  1832.   local particlesIndexes = {}
  1833.   local forSearch = {}
  1834.   local minx0 = 999
  1835.   local miny0 = 999
  1836.   local maxx0 = 0
  1837.   local maxy0 = 0
  1838.   local firstPartX = 0
  1839.   local firstPartY = 0
  1840.   local results = {}
  1841.   local selectedParts = {}
  1842.  
  1843.   local function saveToVirtual()
  1844.     forSearch = {}
  1845.     selectedParts = {}
  1846.     minx0 = 999
  1847.     miny0 = 999
  1848.     maxx0 = 0
  1849.     maxy0 = 0
  1850.     firstPartX = 0
  1851.     firstPartY = 0
  1852.     for i=1, #particlesIndexes do
  1853.       local cx,cy = sim.partPosition(particlesIndexes[i])
  1854.       local cx,cy=round(cx),round(cy)
  1855.       if cx<minx0 then
  1856.         minx0 = cx
  1857.       end
  1858.       if cy<miny0 then
  1859.         miny0 = cy
  1860.         firstPartX = cx
  1861.         firstPartY = cy
  1862.       end
  1863.       if cx>maxx0 then
  1864.         maxx0 = cx
  1865.       end
  1866.       if cy>maxy0 then
  1867.         maxy0 = cy
  1868.       end
  1869.     end
  1870.     for i=1, #particlesIndexes do
  1871.       local cx,cy = sim.partPosition(particlesIndexes[i])
  1872.       local cx,cy=round(cx),round(cy)
  1873.       cx = cx-minx0
  1874.       cy = cy-miny0
  1875.       if forSearch[cx]==nil then forSearch[cx]={} end
  1876.       if forSearch[cx][cy]==nil then forSearch[cx][cy]={} end
  1877.       forSearch[cx][cy]= {}
  1878.       forSearch[cx][cy]["t"] = sim.partProperty(particlesIndexes[i], "type")
  1879.       forSearch[cx][cy]["d"] = sim.partProperty(particlesIndexes[i], "dcolor")
  1880.       selectedParts[#selectedParts+1]={}
  1881.       selectedParts[#selectedParts]["x"] = cx
  1882.       selectedParts[#selectedParts]["y"] = cy
  1883.     end
  1884.   end
  1885.  
  1886.   local alpha = 0
  1887.   local isInc = true
  1888.   local function drawFound()
  1889.     getZoomInfo()
  1890.     for i=1,#results do
  1891.       for j=1,#selectedParts do
  1892.         graphics.fillRect(results[i]["x"]+selectedParts[j]["x"],results[i]["y"]+selectedParts[j]["y"],1,1,255,0,0,alpha)
  1893.         drawPixelInZoomWindow(results[i]["x"]+selectedParts[j]["x"],results[i]["y"]+selectedParts[j]["y"],255,0,0,alpha)
  1894.       end
  1895.     end
  1896.     if isInc then
  1897.       alpha = alpha + 4
  1898.     else
  1899.       alpha = alpha - 4
  1900.     end
  1901.     if alpha >= 255 then isInc = false end
  1902.     if alpha <= 0 then isInc = true end
  1903.   end
  1904.  
  1905.   local function search()
  1906.     local allParticlesGrid = {}
  1907.     minx = 999
  1908.     miny = 999
  1909.     maxx = 0
  1910.     maxy = 0
  1911.     for i in sim.parts() do
  1912.       local cx,cy = sim.partPosition(i)
  1913.       local cx,cy=round(cx),round(cy)
  1914.       if allParticlesGrid[cx]==nil then allParticlesGrid[cx]={} end
  1915.       if allParticlesGrid[cx][cy]==nil then allParticlesGrid[cx][cy]={} end
  1916.       allParticlesGrid[cx][cy]["t"] = sim.partProperty(i, "type")
  1917.       allParticlesGrid[cx][cy]["d"] = sim.partProperty(i, "dcolor")
  1918.       if cx>maxx then maxx=cx end
  1919.       if cx<minx then minx=cx end
  1920.       if cy>maxy then maxy=cy end
  1921.       if cy<miny then miny=cy end
  1922.     end
  1923.     results = {}
  1924.     for i=minx,maxx do
  1925.       for j=miny,maxy do
  1926.         if allParticlesGrid[i]~=nil and allParticlesGrid[i][j]~=nil and forSearch[firstPartX-minx0]~=nil and forSearch[firstPartX-minx0][firstPartY-miny0]~=nil then
  1927.           if allParticlesGrid[i][j]["t"]==forSearch[firstPartX-minx0][firstPartY-miny0]["t"] and allParticlesGrid[i][j]["d"]==forSearch[firstPartX-minx0][firstPartY-miny0]["d"] then
  1928.             local compareStartX = i-firstPartX+minx0
  1929.             local compareStartY = j-firstPartY+miny0
  1930.             local isMatch = true
  1931.             for si=0,maxx0-minx0 do
  1932.               for sj=0,maxy0-miny0 do
  1933.                 if forSearch[si]~=nil and forSearch[si][sj]~=nil then
  1934.                   if allParticlesGrid[compareStartX+si]==nil or allParticlesGrid[compareStartX+si][compareStartY+sj]==nil then
  1935.                     isMatch = false
  1936.                     break
  1937.                   end
  1938.                   if allParticlesGrid[compareStartX+si][compareStartY+sj]["t"]~=forSearch[si][sj]["t"] or allParticlesGrid[compareStartX+si][compareStartY+sj]["d"]~=forSearch[si][sj]["d"] then
  1939.                     isMatch = false
  1940.                     break
  1941.                   end
  1942.                 end
  1943.               end
  1944.               if not isMatch then
  1945.                 break
  1946.               end
  1947.             end
  1948.             if isMatch then
  1949.               results[#results+1] = {}
  1950.               results[#results]["x"] = compareStartX
  1951.               results[#results]["y"] = compareStartY
  1952.             end
  1953.           end
  1954.         end
  1955.       end
  1956.     end
  1957.     alpha = 0
  1958.     isInc = true
  1959.     interface_s.AddOnStepAction(drawFound)
  1960.   end
  1961.  
  1962.  
  1963.  
  1964.   local Exit = interface_s.Components.Button:new(5, 40, 50, 15,"Exit", DefaultTheme.Button)
  1965.   Exit.OnPressed = (function()
  1966.     interface_s.RemoveComponent(mainWindow)
  1967.     interface_s.RemoveComponent(selectionMover)
  1968.     interface_s.RemoveComponent(selection)
  1969.     interface_s.RemoveOnStepAction(drawFound)
  1970.   end)
  1971.  
  1972.   local selectButton = interface_s.Components.Button:new(5, 10, 50, 15,"Select", DefaultTheme.Button)
  1973.   selectButton.OnPressed = (function()
  1974.     selectButton.Enabled = false
  1975.     if selectionMover ~= nil then
  1976.       interface_s.RemoveComponent(selectionMover)
  1977.     end
  1978.     selection = interface_s.Components.Selection:new(50, 50, DefaultTheme.Selection)
  1979.     selection.OnDraw = function(IsFocused,x,y)
  1980.       x,y = sim.adjustCoords(x,y)
  1981.       if selection.IsPointSet then
  1982.         getZoomInfo()
  1983.         local x2,y2 = sim.adjustCoords(selection.V2StartX,selection.V2StartY)
  1984.         drawRectangleInZoomWindow(x2,y2,selection.V2EndWidth,selection.V2EndHeight,gfx.getColors(selection.Theme.BackColor))
  1985.       end
  1986.       return IsFocused,x,y
  1987.     end
  1988.     selection.OnClick = function(x,y,e,b)
  1989.       x,y = sim.adjustCoords(x,y)
  1990.       return x,y,e,b
  1991.     end
  1992.     selection.OnSelected = function(x,y,x2,y2,v2x,v2y,v2w,v2h)
  1993.       if v2w<3 or v2h<3 then
  1994.         interface_s.RemoveComponent(selection)
  1995.         selectButton.Enabled=true
  1996.         return
  1997.       end
  1998.       interface_s.RemoveComponent(selection)
  1999.       particlesIndexes={}
  2000.       for i in sim.parts() do
  2001.         local cx,cy = sim.partPosition(i)
  2002.         cx = round(cx)
  2003.         cy = round(cy)
  2004.         if (cx>v2x) and (cx<v2x+v2w) and (cy>v2y) and (cy<v2y+v2h) then
  2005.           particlesIndexes[#particlesIndexes+1]=i
  2006.         end
  2007.       end
  2008.  
  2009.       saveToVirtual()
  2010.       search()
  2011.  
  2012.       selectionMover = interface_s.Components.SelectionMover:new(v2x,v2y,v2w,v2h, DefaultTheme.Selection)
  2013.       selectionMover.OnClick = (function(x,y,e,b)
  2014.         x,y = sim.adjustCoords(x,y)
  2015.         return x,y,e,b
  2016.       end)
  2017.       selectionMover.OnMove = (function(x,y,e,b)
  2018.         return nil
  2019.       end)
  2020.       selectionMover.OnDraw = (function(f,x,y)
  2021.         drawRectangleInZoomWindow(selectionMover.X,selectionMover.Y,selectionMover.Width,selectionMover.Height,gfx.getColors(selectionMover.Theme.BackColor))
  2022.       end)
  2023.       selectionMover.OnDone = (function()
  2024.         interface_s.RemoveComponent(selectionMover)
  2025.         selectButton.Enabled=true
  2026.         interface_s.RemoveOnStepAction(drawFound)
  2027.       end)
  2028.       selectionMover.OnAbort = (function(tdx,tdy)
  2029.         interface_s.RemoveComponent(selectionMover)
  2030.         selectButton.Enabled=true
  2031.         interface_s.RemoveOnStepAction(drawFound)
  2032.       end)
  2033.       interface_s.addComponent(selectionMover)
  2034.     end
  2035.     selection.OnSelectionAborted = function()
  2036.       interface_s.RemoveComponent(selection)
  2037.       selectButton.Enabled=true
  2038.     end
  2039.     interface_s.addComponent(selection)
  2040.   end)
  2041.   mainWindow:AddComponent(selectButton)
  2042.   mainWindow:AddComponent(Exit)
  2043. end
  2044. --=================================================================--
  2045. --                    CODE IS ABOVE THIS LINE                      --
  2046. --=================================================================--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement