mirror of
https://github.com/IanDarwin/OpenLookCDROM.git
synced 2026-01-31 05:53:13 +00:00
93 lines
4.6 KiB
Plaintext
93 lines
4.6 KiB
Plaintext
The files "Happy.class", "Happy.stack" and "HappyProps.stack"
|
|
demonstrate how to extend HyperLook by defining a plug-in class, and
|
|
a property sheet.
|
|
|
|
"Happy.class" contains the class definition for a happy face
|
|
component. You can adjust its smile by sending it a /SetValue
|
|
message.
|
|
|
|
"Happy.stack" contains a stack with a happy face object and a slider
|
|
that adjusts its smile. You can put the stack into edit mode, select
|
|
the happy face, and press the "Props" key to get its property sheet.
|
|
|
|
"HappyProps.stack" contains a stack that is a property sheet to edit
|
|
happy faces. The happy face property sheet contains a small sample
|
|
happy face, a slider to control its smile, and a color selector to set
|
|
the color of its eyes. The "ObjectProps" stack is displayed above the
|
|
"HappyProps" stack, and allows you to set the stroke and fill colors,
|
|
as well as other generic object properties.
|
|
|
|
To create a new object from a plug-in class file, go into stack edit
|
|
mode, and select "New >> Create from Class" from the edit menu. The
|
|
"Open File" dialog will come up, so you can select a class file
|
|
(ending in ".class"). The plug-in class will be loaded, and a new
|
|
instance will be created and placed on the stack.
|
|
|
|
You can construct a property sheet to edit instances of your own
|
|
plug-in classes. Just copy another property sheet, rename it to
|
|
"<ClassName>Props" (with "Stack >> Save as..."), and create the user
|
|
interface you want.
|
|
|
|
The names of the components on a property sheet are important: if they
|
|
don't begin with a "#", they will be sent certain messages when
|
|
bringing up the property sheet and applying changes. If the name of
|
|
an object on a property sheet begins with "#" (i.e. "#4" or
|
|
"#Slider"), it will not be sent any special messages.
|
|
|
|
Here is a list of the messages sent to the property sheet components
|
|
whose names don't begin with "#":
|
|
|
|
/ResetValue % object -- component-value
|
|
Takes the object being edited by the property sheet as an argument.
|
|
Returns the value that the control should assume for that object.
|
|
It can access the object's instance variables, or send it a message,
|
|
and convert the value into a type suitable for the component on the
|
|
property sheet. For example, the slider on the HappyProps stack has
|
|
a range of -10 to 10, but the value it's editing ranges from -1 to
|
|
1, so the slider's /ResetValue method goes "/Value get 10 mul" to
|
|
convert from the happy value to the slider value. The /ResetValue
|
|
method of the color selector editing the /EyeColor instance variable
|
|
just goes "/EyeColor get", since both values are color objects.
|
|
|
|
/CurrentValue % -- object-value
|
|
Returns the property value of the object that this component is
|
|
editing. This usually converts the property sheet component's value
|
|
to the value of the object instance variable it's editing. For
|
|
example, the /CurrentValue method of the slider on the HappyProps
|
|
stack goes "Value 10 div" to convert from the slider value to the
|
|
happy value. The /CurrentValue method of the color selector editing
|
|
the /EyeColor instance variable just goes "Value", since both values
|
|
are color objects.
|
|
|
|
/Check % object -- boolean
|
|
Takes the object being edited by the property sheet as an argument.
|
|
Returns a boolean true if it's valid to apply the component's value
|
|
to the object. Usually /Check just goes "pop true", but it's used
|
|
in cases such as the object name field, which is only valid if it's
|
|
a unique name in the stack. If the value is invalid, the /Check
|
|
method should issue an error message and return false.
|
|
|
|
/Apply % object --
|
|
Takes the object being edited by the property sheet as an argument.
|
|
Applies the current value of the property sheet component to the
|
|
object being edited. Usually calls "CurrentValue" to get the
|
|
appropriate object-value to store in the edited object. For
|
|
example, the /Apply method of the slider on the HappyProps
|
|
stack goes "/Value CurrentValue put" to store the happy value into
|
|
the happy face object's /Value instance variable. The object will
|
|
be automatically updated after all the property sheet component's
|
|
values have been applied.
|
|
|
|
/Changed? % -- boolean (class or promoted instance variable)
|
|
Boolean true if the user has changed the value of the component.
|
|
The happy face just has a class variable whose value is always
|
|
"false", since it does not change its value (the smile) in response
|
|
to user input. If you want to subclass the happy face to make one
|
|
whose smile responds to direct manipulation, then make sure to
|
|
promote /Changed? to true when the user changes the value, and
|
|
unpromote it in /SetValue, when its value is programmatically
|
|
changed.
|
|
|
|
/SetValue % value --
|
|
Set the value of the component, and repaint if visible.
|