OPT PREPROCESS

MODULE 'feelin','libraries/feelin','a4'

/*
   Here is the beginning of our simple new class...

   This is an example for the simplest possible Feelin'  class.  It's  just
   some  kind  of  custom image and supports only two methods: FM_AskMinMax
   and FM_Draw.

   This class is realy simple and do not requires any instance data.
*/

PROC myDispatcher(cl,obj:PTR TO feelinObject,method,args:PTR TO LONG)
/*
   Here comes the dispatcher for our custom class. We  only  need  to  care
   about  FM_AskMinMax  and  FM_Draw  in  this  simple case. Unknown/unused
   methods are passed to the superclass immediately.
*/
	SELECT method
		CASE FM_AskMinMax ; mAskMinMax(cl,obj)
		CASE FM_Draw      ; mDraw     (cl,obj,args)
		DEFAULT           ; RETURN F_SuperDoA(cl,obj,method,args)
	ENDSELECT
ENDPROC 
PROC mAskMinMax(cl,obj:PTR TO feelinObject)
/*
   FM_AskMinMax will be called before  the  window  is  opened  and  before
   layout takes place. We need to tell Feelin' the minimum and maximum size
   of our object.
*/

   F_SuperDoA(cl,obj,FM_AskMinMax,NIL)

   _minw(obj) += 100 ; _maxw(obj) := 500
   _minh(obj) +=  40 ; _maxh(obj) := 300
ENDPROC
PROC mDraw(cl,obj:PTR TO feelinObject,args:PTR TO feelinArgs_Draw)
   DEF i,c,rp

   /*
	  let our superclass draw itself first, area class would e.g. draw  the
	  frame  and  clear  the  whole region. What it does exactly depends on
	  flags.
   */

   F_SuperDoA(cl,obj,FM_Draw,args)

   /*
	  If FF_Draw_Object isn't set, we shouldn't draw anything. Feelin' just
	  wanted to update the frame or something like that.
   */

   IF FF_Draw_Object AND args.flags = NIL THEN RETURN NIL

   -> Ok, everything ready to render...

   rp := _rp(obj)
   c  := FV_Pen_Shine

   FOR i := _mleft(obj) TO _mright(obj) STEP 5
	  _APen(_pens(obj)[c])
	  _Move(_mleft(obj),_mbottom(obj))
	  _Draw(i,_mtop(obj))
	  _Move(_mright(obj),_mbottom(obj))
	  _Draw(i,_mtop(obj))
	  INC c ; IF c = FV_Pen_Highlight THEN c := FV_Pen_Shine
   ENDFOR
ENDPROC
->PROC
__MyDispatcher:
   MOVEM.L  D2-D7/A2-A6,-(A7)
   MOVE.L   A2,-(A7)
   MOVE.L   A0,-(A7)
   MOVE.L   D0,-(A7)
   MOVE.L   A1,-(A7)

   LEA      __Global(PC),A0
   MOVEA.L  (A0),A4
   BSR      myDispatcher

   ADDA.L   #16,A7
   MOVEM.L  (A7)+,D2-D7/A2-A6
   RTS
->ENDPROC
PROC main() HANDLE
   DEF c=NIL,w,
	   fcc=NIL:PTR TO feelinClass

   sys_SGlob() -> Save AmigaE global base

   IF (feelinbase := OpenLibrary(FEELIN_NAME,NIL)) = NIL THEN Raise('Unable to open feelin.library\n')
   IF (fcc := F_CreateClass(NIL,FC_Area,NIL,NIL,NIL,{__MyDispatcher})) = NIL THEN Raise('Unable to create custom class\n')

   c := ClientObject,
	  Child, w := WindowObject, FA_Window_Title, 'A Simple Custom Class', FA_ID, "CLS1",
		 Child, VGroup, NoFrame,
			Child, F_NewObjA(fcc.id,[TextFrame, TextBack, FA_Inner,[4,2,4,2]:CHAR, NIL]),
		 End,
	  End,
   End

   IF c
	  F_DoA(w,FM_Notify,[FA_Window_CloseRequest,TRUE,FV_Notify_Client,2,FM_Client_ReturnID,FV_Client_Quit])
	  F_Set(w,FA_Window_Open,TRUE)

	  WHILE F_DoA(c,FM_Client_WaitEvent,NIL) <> FV_Client_Quit DO NOP
   ELSE
	  WriteF('Failed to create Client.\n')
   ENDIF
EXCEPT DO
   IF c          THEN F_DisposeObj(c)
   IF fcc        THEN F_RemoveClass(fcc)
   IF feelinbase THEN CloseLibrary(feelinbase)
   IF exception  THEN WriteF('\s\n',exception)
ENDPROC
