Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Writing a Theme Resource File

The example code shown in the steps below is taken from the sample applet c_widgettheming_app included with this Technology Guide. The examples of a theme resource file shown below are taken from naturetheme.car.

To write a theme resource file, do the following:

  1. Create a new CAR file.
  2. Require NamedResourcesCIFHelper.cif, which can be found in the platform\ui\inc directory in the Brew MP SDK 1.1.0 and newer. The path can be resolved with cifc.exe include paths at compilation.
    local nr = require "NamedResourcesCIFHelper.cif"
  3. Include any C headers in which the properties to be used are defined.
    --defines most platform props
    include "AEEWidgetProperties.h" 
  4. Define any helper constants, such as colors and pixel sizes
    --Here you can define your own local variables
    local red = 0xff0000ff
    local green = 0x00ff00ff
    local yellow = 0x00ffffff
    local white = 0xffffffff
    local black = 0x000000ff
    local transparent = 0x00000000
  5. Insert the nr:Resources primitive. All tables of properties used for theming must defined inside nr:Resources. For example:
    --All resources must be defined inside nr:Resources
    --Once theming is enabled all widgets except containers 
    --will be applied the property table with their class id by default
    --Containers shall not be applied any property table by default
    
    nr:Resources {
  6. In the nr:Resources primitive, add the tables of properties that are required. For example:
    nr:Resources {
       AEECLSID_CButtonWidget = { --Applied by default to all button widgets
          properties = nr:Properties {
             {PROP_BGCOLOR, black},
             {PROP_BORDERCOLOR, yellow},
             {PROPEX_BORDERWIDTH, 10}, --Propexs are treated the same as props
          },
       },
       --Applied to all widgets with a "greenbgnoborderwidth" theme tag
       greenbgnoborderwidth = { 
          properties = nr:Properties {
             {PROP_BGCOLOR, green},
             {PROPEX_BORDERWIDTH, nr:PropertySkip()},
          },
       },
       AEECLSID_CStaticWidget = { --Applied by default to all static widgets
          properties = nr:Properties {
             {PROP_FGCOLOR, nr:PropertyReference("AEECLSID_CButtonWidget.properties",
              PROP_BORDERCOLOR) },
          },
       },
       whiterounded = { -- Applied to all widgets with a
                        -- "whiterounded.properties" theme tag
          properties = nr:Properties {
             {PROP_BORDERCOLOR, white},
             {PROP_BORDERSTYLE, BORDERSTYLE_NORMAL},
          },
       },
    }