Différences

Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.

Lien vers cette vue

openmusic:dev-resources:classprotocol [2011/01/28 18:08]
jean-admin
— (Version actuelle)
Ligne 1: Ligne 1:
-===== OM Class protocol ===== 
- 
- 
-Classes defined by the macros **defclass!** or **defclass*** have a set of methods for instance creation, visualisation and edition. For example if you define a class by: 
- 
-<code lisp> 
-  (defclass! rgb-color () 
-    ((red-comp :initform 0 :initarg :red-comp :accessor red-comp) 
-     (green-comp :initform 0 :initarg :green-comp :accessor green-comp) 
-     (blue-comp :initform 0 :initarg :blue-comp :accessor blue-comp)) 
-    (:documentation "color with components red, blue and green.") 
-    (:icon 179)) 
-</code> 
- 
-A factory and an editor are associated to the class by default. 
- 
-{{ :openmusic:dev-resources:color.jpg }} 
- 
-To change the "miniview" appearance you need only to subclass the mehod ''draw-obj-in-rect'': 
- 
-<code lisp> 
-  (defmethod draw-obj-in-rect ((self rgb-color) x x1 y y1 edparams view)) 
-</code> 
- 
-The //view// parameter determine the view where the object is shown, //x, x1, y, y1// specify a rectangle into the view. Some instances need some values for edition (i.e. font size, etc), you can use the //edparams// parameter for this porpose. 
- 
- 
-For our example the next method definition: 
- 
-<code lisp> 
-  (defmethod draw-obj-in-rect ((self rgb-color) x x1 y y1 edparams view) 
-    (declare (ignore edparams view)) 
-    (om-with-fg-color self (om-make-color (red-comp self) (green-comp self) (blue-comp self)) 
-      (om-fill-rect x y x1 y1))) 
-</code> 
- 
-shows the rgb-color instance as a color (!!!) 
- 
-{{:openmusic:dev-resources:color2.jpg|}} 
- 
- 
-==== Writing an editor ==== 
- 
-You can define a subclass of **omboxeditcall**, for example :</P> 
- 
-<code lisp> 
-  (defclass colorfactory (omboxeditcall) ()) 
-</code> 
- 
-To associate the new box class with the //rgb-color// class using the next method: 
- 
- 
-<code lisp> 
-  (defmethod get-type-of-ed-box ((self rgb-color)) colorfactory) 
-</code> 
- 
-..and redefine methods of //omboxeditcall//. 
- 
- 
-Double-click on a factory call the ''OpenEditorFrame'' method with the factory as argument. If there is not an editor for the class the default editor is open. In order to write an editor we start to define the method ''class-has-editor-p''. 
- 
- 
-<code lisp> 
-  (defmethod Class-has-editor-p ((self rgb-color)) t) 
-</code> 
- 
- 
-The next method associate the editor's class name with the class edited: 
- 
-<code lisp> 
-  (defmethod get-editor-class ((self rgb-color)) 'colorEditor) 
-</code> 
- 
-Finally we define the editor class which is a subclass of //EditorView//: 
- 
- 
-<code lisp> 
-  (defclass colorEditor (EditorView) ()) 
-</code> 
- 
- 
- 
-==== Temporal classes ==== 
- 
- 
-You can not put //rgb-color// instances in a maquette because they are not temporal objects, if you want the instances of your class to be temporal objects your class must inherit from the **simple-container** or the **container** classes: 
- 
- 
-<code lisp> 
-  (defclass! rgb-color (simple-container) 
-    ((red-comp :initform 0 :initarg :red-comp :accessor red-comp) 
-     (green-comp :initform 0 :initarg :green-comp :accessor green-comp) 
-     (blue-comp :initform 0 :initarg :blue-comp :accessor blue-comp)) 
-    (:documentation "color with componenents red, blue and green.") 
-    (:icon 179)) 
-</code> 
-