Class: Skin2D

LuxModule: gui

The Skin2D class is a two dimensional graphical representation for abstract information. It defines the look and feel of components.

I.e. this information could be a button. A skin does only have to provide some mechanisms for hiding, creating and deleting. Any class that requires a twodimensional representation (x,y,width,height) can use a skin to display itself. The skin takes only care about its graphical representation, its position and dimensions.

Skins can provide multiple "surfaces". Surfaces are variations of a skin. Components may request certain surfacetypes for a skin (i.e. mouseover event) to change the visual appearance of the skin.

A Skin can also provide mechanisms to show text on the label.

Hierarchy

o-+ Skin2D
  o-- StretchedSkinnedImage

Methods:

Method overview:


new (class)
returns: (Skin2D)
Sets metatable index to class. Per default, a skin does not create any visual objects during start. These must be created by calling createVisibles.
ALIGN.BOTTOM
{[string]} - position information for label
ALIGN.CENTER
{[string]} - position information for label
ALIGN.ICONTOBOTTOM
{[string]} - position information for icon
ALIGN.ICONTOLEFT
{[string]} - position information for icon
ALIGN.ICONTORIGHT
{[string]} - position information for icon
ALIGN.ICONTOTOP
{[string]} - position information for icon
ALIGN.LEFT
{[string]} - position information for label
ALIGN.RIGHT
{[string]} - position information for label
ALIGN.TOP
{[string]} - position information for label
REASON.COLORCHANGED
{[string]}=colorchanged - changed color (Skin/font) reason
REASON.CREATEDVIS
{[string]}=createdvis - vischange reason
REASON.DELETEDVIS
{[string]}=deletedvis - vischange reason
REASON.ICONCHANGED
{[string]}=iconchanged - changed icon reason
REASON.NEWTEXT
{[string]}=newtext - new label text
REASON.RESIZED
{[string]}=resized - resized skin
REASON.SKINCHANGE
{[string]}=skinchange - skinchange reason
REASON.VISCHANGE
{[string]}=vischange - vischange reason
bound.h
[float] - height
bound.w
[float] - width
bound.x
[float] - position x
bound.y
[float] - position y
bounds
[table] - contains bounds of image
clone (Skin2D)
returns: (Skin2D)
returns a copy of the skin. This function MUST be overloaded, otherwise an error is thrown.
contains (Skin2D, x,y)
returns: (boolean)
returns true (default) if the skin contains a certain pixel in local coordinates. This method can be overloaded to let the mouse pointing reject transparent areas on the skin.
copystylefrom (Skin2D to,Skin2D from)
returns: ()
copies style of another skin (padding and iconmargin)
createVisibles (Skin2D,l2dnode parent)
returns: ()
restores resources for visual representation
currentskin
[string]=default - current key of used skin
defaultfont
[string]=arial11-16x16 - fontname to be used as default
delete (Skin2D)
returns: ()
deletes the skin. This function might get called multiple times so flag your skin once it got deleted. Per default it calls the deleteVisibles method.
deleteVisibles (Skin2D)
returns: ()
deletes resources for visual representation
getBounds (Skin2D)
returns: (x,y,w,h)
returns location and dimension of skin
getClip (Skin2D)
returns: ([x,y,w,h])
Gets clipping for skin. If no value is returned, the clipping is disabled.
getClipping (Skin2D)
returns: (boolean)
returns clipping value
getFontColor (Skin2D)
returns: (float r,g,b,a)
RGBA Color for the label
getFontset (Skin2D)
returns: (fontset)
returns currently fontset
getIcon (Skin2D)
returns: ([Icon])
gets the Icon to be used for this skin.
getIconMargin (Skin2D)
returns: (float margin)
returns margin arount the icon
getIconSkinSelection (Skin2D)
returns: ([id])
returns current iconskinselection preference
getLabelSize (Skin2D)
returns: (w,h)
Returns the current size of the label.
getLabelText (Skin2D)
returns: ([text])
gets the text for the skin.
getPadding (Skin2D)
returns: (float top,right,bottom,left)
returns current padding values
getPreferredBounds (Skin2D,x,y,w,h)
returns: (x,y,w,h)
returns preferred bounds for this skin. Calls getPreferredSize and getPreferredLocation per default.
getPreferredLocation (Skin2D,x,y)
returns: (x,y)
Returns position which is preferred by the skin. Since most textures are drawn filtered, a component might like to be positionend at an integer position.
getPreferredSize (Skin2D,w,h)
returns: (w,h)
Returns preferred size of the skin. A skin may have a minimum or maximum size - or wants to be sized in multiplies of a certain size.
getSelectedSkin (Skin2D)
returns: (string)
Returns the currently selected skin.
getSkinColor (Skin2D)
returns: (float r,g,b,a)
Primary RGBA Color for the skin
icon
[Icon]=nil - the icon for this skin
iconalignhorizontal
[float/string]=ALIGN.ICONTOLEFT - alignment for icon
iconalignvertical
[float/string]=ALIGN.CENTER - alignment for icon
id
[int]=0 - sortid for l2dlistset
onDestroy (Skin2D)
returns: ()
called by garbagecollecter. Calls delete.
paddings
[table] - table containing paddings for different skins
pbottom
[float] - current padding to bottom
pleft
[float] - current padding to left
pright
[float] - current padding to right
ptop
[float] - current padding to top
selectSkin (Skin2D)
returns: (skin)
returns currently selected skin
setAutowidth (Skin2D, on)
returns: ()
Autowidth will change the *visual* appearance of the component to a width that is chosen depending on the current size of the caption and/or icon.
setBounds (Skin2D,x,y,w,h)
returns: ()
sets location and dimension of skin. Calls sizechanged ("resize") - only if the size and position was truly changed!
setClip (Skin2D,[x,y,w,h])
returns: ()
Sets clipping for skin. If no value is passed, the clipping is disabled.
setClipping (Skin2D,on)
returns: ()
Enables or disables clipping.
setDimensions (Skin2D,w,h)
returns: ()
sets width and height of skin (calls directly setBounds)
setFont (Skin2D,[string fontname])
returns: ()
Name of font to be used, pass nil (or nothing) if the defaultfont should be used
setFontColor (Skin2D, float r,g,b,a)
returns: ()
sets RGBA Color for the label
setIcon (Skin2D,Icon,[iconskinname, [alignh,[alignv] ] ])
returns: ()
sets the Icon to be used for this skin. The second parameter denotes the name of the skin that should be used for the icon when displayed. If it is nil, the currently set skinname for the icon (that can be nil) is not overwritten. If it is false, it will be set to nil, otherwise it is set to the given value. If the 3rd and 4th parameter is not nil, the icon alignment is set to these values.
setIconAlignment (Skin2D,string/number horizontal, vertical)
returns: ()
sets alignment for icon. If number is passed it is used as coordinate from the top left corner.
setIconMargin (Skin2D,float margin)
returns: ()
margin arount the icon
setIconSkinSelection (Skin2D, [id])
returns: ()

if a skiniconselection is present, it is preferred if the skin of the Skin2D object is changed, otherwise, the icon's selection is using the same name as the current skinname.

setLabelFontSize (Skin2D, size)
returns: ()
size of the font for the label. 1 = 100%, 2 = 200% etc. Default value: 1
setLabelFontSpacing (Skin2D, size)
returns: ()
spacing of the font for the label
setLabelPosition (Skin2D,horizontal,vertical)
returns: ()
sets position of label. The position can be a string as described in Skin2D.ALIGN or a number.
setLabelTabWidth (Skin2D, spacing)
returns: ()
tab spacing of font for the label. 0 means spacing * 4 is used.
setLabelText (Skin2D, [text])
returns: ()
sets the text for the skin. If no argument is nil or is missing the text is removed.
setLocation (Skin2D,x,y)
returns: ()
sets 2D location of skin (calls directly setBounds)
setPadding (Skin2D,float top,right,bottom,left,[string/table key=default])
returns: ()
padding of text and icon to the sides, sets default valueif the key is not present. The key is used when a different skin is selected. The key can be a table of keys that should be assigned with the given padding values.
setPaddingAll (Skin2D,[float top],[right],[bottom],[left],boolean incremental=false)
returns: ()
Sets padding of all padding keys. If nil is passed, the given value (top,right,bottom,left) isnot modified. If incremental is true, the values are added to the current values.
setSkinColor (Skin2D, float r,g,b,a)
returns: ()
sets Primary RGBA Color for the skin
setSortID (Skin2D,int id)
returns: (nextid)
sets sortid for l2d sorting. Returns the next id that can be used without interfering the l2delements of the skin. Per default it reserves 4 elements.
setTextAlignment (Skin2D,string/number horizontal, vertical)
returns: ()
sets alignment for text. If number is passed it is used as coordinate from the top left corner.
setVisibility (Skin2D,boolean visible)
returns: ()
sets visibility of the skin. Won't create visibles, call createvisibles. Calls update function
setZ (Skin2D,float z)
returns: ()
sets z offset in l2d system - 0 per default
texthorizontal
[float/string]=ALIGN.CENTER - alignment for text
textvertical
[float/string]=ALIGN.CENTER - alignment for text
toString (Skin2D)
returns: (string)
returns simple text representation of the skin. It is called whenever the tostring function is called.
update (Skin2D, string reason)
returns: ()
called if the visual appearance changed. The reason contains the source which caused the modification. Depending on your implementation, it might be useful to collect modifications until the frame is finaly really drawn.
z
[float]=0 - z position in space