Difference between revisions of "Lua:Class:Control"

From Cheat Engine
Jump to navigation Jump to search
Line 114: Line 114:
 
--Onclick
 
--Onclick
 
editbox2.OnClick=clickroutine -- clickroutine must have exactly one argument
 
editbox2.OnClick=clickroutine -- clickroutine must have exactly one argument
alternatively: editbox2.OnClick="clickroutine"  --the function clickroutine will then be searched in _G when the click event triggers
+
--alternatively: editbox2.OnClick="clickroutine"  --the function clickroutine will then be searched in _G when the click event triggers
  
  
  
 
</pre>
 
</pre>

Revision as of 00:21, 23 February 2015

WinControl Class: (Inheritance: Control->Component->Object)

Base class for gui controls

Properties

 Caption: string - The text of a control
 Top : integer - The x position
 Left : integer - The y position
 Width : integer - The width of the control
 Height : integer - The height of the control
 ClientWidth: integer - The usable width inside the control (minus the borders)
 ClientHeight: integer - The usable height the control (minus the borders)
 Align: AlignmentOption - Alignment of the control
 Enabled: boolean - Determines if the object is usable or greyed out
 Visible: boolean - Determines if the object is visible or not
 Color: ColorDefinition/RGBInteger - The color of the object. Does not affect the caption
 Parent: WinControl - The owner of this control
 PopupMenu: PopupMenu - The popup menu that shows when rightclicking the control
 Font: Font - The font class associated with the control
 OnClick: function - The function to call when a button is pressed

Methods

 getLeft()
 setLeft(integer)
 getTop()
 setTop(integer)
 getWidth()
 setWidth(integer)
 getHeight()
 setHeight()
 setCaption(caption) : sets the text on a control. All the gui objects fall in this category
 getCaption() : Returns the text of the control
 setPosition(x,y): sets the x and y position of the object base don the top left position (relative to the client array of the owner object)
 getPosition(): returns the x and y position of the object (relative to the client array of the owner object)
 setSize(width,height) : Sets the width and height of the control
 getSize() : Gets the size of the control
 setAlign(alignmentoption): sets the alignment of the control
 getAlign(alignmentoption): gets the alignment of the control
 getEnabled() : gets the enabled state of the control
 setEnabled(boolean) : Sets the enabled state of the control
 getVisible() : gets the visible state of the control
 setVisible(boolean) : sets the visible state of the control
 getColor() : gets the color
 setColor(rgb) : Sets the color
 getParent() : Returns nil or an object that inherits from the Wincontrol class
 setParent(wincontrol) : Sets the parent for this control
 getPopupMenu()
 setPopupMenu()
 getFont():  Returns the Font object of this object
 setFont():  Assigns a new font object. (Not recommended to use. Change the font object that's already there if you wish to change fonts)
 repaint(): Invalidates the graphical area of the control and forces and update
 update() : Only updates the invalidated areas
 setOnClick(functionnameorstring) : Sets the onclick routine
 getOnClick(): Gets the onclick function
 doClick():  Executes the current function under onClick



--Example:

function clickroutine(sender)  --  onClick()
print "editbox2 clicked"
end

local forms = createForm()
local labels = createLabel(forms)

--Caption
labels.Caption="My first label"
local variable = labels.Caption
print(variable)

--Position
labels.setPosition(30,30)
x,y=labels.getPosition()
print("X coord of label is "..x.."; Y coord of label is "..y)

--Enabled?
local editbox1 = createEdit(forms)
local editbox2 = createEdit(forms)
editbox1.Enabled=false
if editbox1.Enabled then

   else
   print "editbox1 not enabled"
   editbox1.Caption="editbox1"
end

editbox2.Enabled=true
  if editbox2.Enabled then
  print "editbox2  enabled"
  editbox2.Caption="editbox2"
end

editbox1.setPosition(30,60)
editbox2.setPosition(30,90)

--Visibility
local editbox3 = createEdit(forms)
editbox3.Visible=true  -- If false editbox3 would not be displayed on the form.
if editbox3.Visible then
  editbox3.Caption="editbox3"   -- Sets the caption only when visible
  editbox3.setPosition(editbox3,30,120)
end

--Color
labels.Color=123456  -- color code in hex (range 000000 to FFFFFF)
local colorCode = labels.Color
print(colorCode)

--Onclick
editbox2.OnClick=clickroutine -- clickroutine must have exactly one argument
--alternatively: editbox2.OnClick="clickroutine"  --the function clickroutine will then be searched in _G when the click event triggers