Gadget Resources
The system resource mechanism allows you to customize graphic objects at runtime. Object resources are resolved when an object is added to a gadget holder using the member function addObject.
One resource setting can be applicable to an individual object or to an object class. Its scope can also be restricted to an individual storage object or to a storage class, where storage stands for IlvGadgetContainer or IlvGadgetManager.
Each graphic object class can define a set of significant parameters as resources.
Predefined Object Resources
IlvGraphic implements the following object resources:
Resource Name
Description
Value
x
x position
integer string
y
y position
integer string
w or width
horizontal size
integer string
h or height
vertical size
integer string
IlvSimpleGraphic implements the following resources.
Resource Name
Description
Value
background
palette background color
color name
foreground
palette foreground color
color name
font
palette font
font name
pattern
palette pattern
pattern name
colorPattern
palette color pattern
pattern name
lineStyle
palette line style
line style name
lineWidth
palette line width
integer string
fillStyle
palette fill style
FillPattern
FillMaskPattern
FillColorPattern
arcMode
palette arc mode
ArcPie
ArcChord
fillRule
palette fill rule
EvenOddRule
WindingRule
alpha
palette alpha value
Integer string
antialiasingMode
palette antialiasing mode
DefaultAntialiasing
UseAntialiasing
NoAntialiasing
Warning: IlvSimpleGraphic resources are only applied to graphic objects that have the default palette.
Setting Object Resources
The user defines values for these resources in the same way as described in Display System Resources: getResource in Graphic Resources. Even though the syntax is system-dependent, the global structure of a resource setting is the same. The structure is key value. The left part of the resource specification, key, is more complex than the resource specification described in Display System Resources: getResource so that the objects affected by this setting can be easily identified. The key specification is defined as follows:
Program.Storage.GraphicObject.Resource
Here is the description of these four fields:
*Program can be either an application name or the string Views.
*Storage can be either the name of a gadget container or gadget manager, or the string IlvGadgetContainer or IlvGadgetManager.
*GraphicObject can be the name of a graphic object (as returned by IlvGraphic::getName) or the name of a graphic object class (as returned by IlvGraphic::className).
*Resource is the name of the object resource as it appears in the documentation of the class defining this resource.
The fields Program, Storage and GraphicObject can be replaced by the wild card ‘*’.
It is the responsibility of the application developer to document the names of objects, gadget containers, and gadget managers.
It is the responsibility of the graphic object class designer to document the name of the resources defined by this class.
Example: Specifying Object Resources
Here is how to specify that all instances of the IlvPolygon class must be red and filled using the even-odd rule:
*On X Window, add the following to your ~/.Xdefaults file:
*Views*IlvPolygon.foreground: red
*Views*IlvPolygon.fillRule: EvenOddRule
*On Microsoft Windows, add the following to any .INI file:
Section [Views] or [<ApplicationName>]:
**IlvPolygon.foreground=red
**IlvPolygon.fillRule=EvenOddRule
Priorities and Conflicts
When several resource settings are applicable to the same target(s), Views gives priority to the most precise setting, which means that:
*any string has priority over ‘*’,
*an application name has priority over Views,
*a gadget container or gadget manager name has priority over IlvGadgetContainer or IlvGadgetManager.
*an object name has priority over an object class.
If a conflict remains in spite of these priorities, the result is undefined.
Example: Resource Priority
Using X Window syntax:
1. Views.*.*.foreground: blue
2. myApp.*.*.foreground: green
3. myApp.*.IlvButton.foreground: red
4. myApp.myPanel.*.foreground: yellow
5. myApp.myPanel.myButton.foreground: cyan
Line 5 has priority over all the others.
Line 4 has priority over lines 1 and 2.
There is an unresolved conflict between lines 3 and 4. The color of an IlvButton in a gadget container called myPanel is not predictable.
Adding New Resources
If you want to add a new resource to a graphic object, you have to overload the virtual member function IlvGraphic::applyResources. This method loads object resources and is called by the addObject member function of IlvGadgetContainer and IlvGadgetManager.
When overloading this method, subclasses should call the applyResources method of the superclass, then they should use the second getResource member function to fetch possible values for the new resources they define:
const char* getResource(const char* resourceName,
const char* objectName,
const char* objectClassName,
const char* storageName = 0,
const char* storageClassName = 0) const;
Example: Adding Resources
// Assuming class MyObjectClass: public MyObjectSuperClass
// definig a method setLabel.
// The following defines a resource called “labelString”.
 
void MyObjectClass::applyResources(const char* storageName,
const char* storageClassName,
const char* objectName,
const char* objectClassName,
IlvDisplay* display)
{
if (!display)
display = getDisplay();
MyObjectSuperClass::applyResources(storageName,
storageClassName,
objectName,
objectClassName,
display);
const char* resource = display->getResource(“labelString”,
objectName,
objectClassName,
storageName,
storageClassName);
if (resource)
setLabel(resource);
}
Published date: 05/24/2022
Last modified date: 02/24/2022