Chap. 11D --- Skins

Style Objects

The functions drawPict and drawText both take tables full of options. If you recall:

rect:drawPict(nil, { option1=value1, option2=value2, ... })
rect:drawText(nil, { option1=value1, option2=value2, ... }, message)

These tables full of options are called "Gui Styles."

Parsing these tables can be a little expensive, so if your paint routine is taking up too much CPU time, you can precompile these into actual GuiStyle objects:

local style = GuiStyle.new({ background="josh/tiger" })
rect:drawPict(nil, style)

Using GuiStyle objects may be a little faster than using raw tables. Both the original table form and the compiled GuiStyle form are considered "Gui Styles."

Skins

A skin is a table containing a collection of styles and skins. This is a skin:

local style1 = { background="josh/tiger" } 
local style2 = { background="josh/lion" }
local skin = { tigerStyle = style1, lionStyle = style2 }

The purpose of skin objects is that you may have a routine, like drawButton, that may draw several different images depending on circumstances. The skin allows you to configure the routine to cause it to draw any images you choose.

Many of our higher-level functions that draw widgets (ie, our button-drawing routines, our menu-drawing routines, and so forth) expect skins as parameters. Not only do they require skins, but they require that those skins contain particular styles. For example, our button-drawing routine is documented as follows:

    Rect:drawButton(clip, skin, label, callback)

    Draws a button, and arranges a callback to occur if the button
    is clicked.
 
    * Uses skin[.buttonDefault].down
    * Uses skin[.buttonDefault].over
    * Uses skin[.buttonDefault].normal
    * Uses skin[.buttonDefault].text      (optional)
    * Uses skin[.buttonDefault].overlay   (optional)

As you can see from the documentation, the skin must contain the fields "down", "over", and "normal". Here is a valid call:

local downStyle = { background="josh/downImage" } 
local overStyle = { background="josh/overImage" }
local normalStyle = { background="josh/normalImage" }
local skin = { down=downStyle, over=overStyle, normal=normalStyle }
rect:drawButton(nil, skin, "OK", myCallback)

The GUI Manager provides a "standard skin" which contains all the required fields for any of our supplied widgets, but you can create your own skins to completely alter the appearance of these widgets.