
                incdir  "inc:"
                include "jvdbmacros.i"
                include "intuition/intuition.i"
                include "intuition/classes.i"
                include "intuition/classusr.i"
                include "intuition/imageclass.i"
                include "libraries/gadtools.i"

                include lvo/intuition.i
                include lvo/graphics.i
                include lvo/utility.i
                include lvo/gadtools.i

                XDEF    _initPrev
                XDEF    initPrev

                XREF    _IntuitionBase
                XREF    _GfxBase
                XREF    _UtilityBase
                XREF    _GadToolsBase

MY_Height	equ	$80000001
MY_Width	equ	$80000002

                SECTION "Next",CODE
;
; --- This routine call's this class it's super class.
; --- First it get's the class it's super class in a0.
; --- Then it pushes "ourRet" on the stack which will be
; --- the return address of the superclass dispatcher.
; --- Then it pushes the lowlevel entry of the superclass
; --- dispatcher on the stack and performs an rts which
; --- causes a jump to the superclass dispatcher. When the
; --- superclass dispatcher is done it will return to "ourRet".
;
callSuper:      push.l      a2                  ; save a2
                move.l      cl_Super(a0),a0     ; get superclass in a0
                pea.l       ourRet              ; push return address
                push.l      h_Entry(a0)         ; push superclass dispatcher
                rts                             ; jump to super dispatcher
ourRet:         pop.l       a2                  ; restore a2
                rts

;
; --- Initialize our private class. It set's up a class
; --- with "imageclass" as superclass.
;
_initPrev:
initPrev:
                pushem.l    a2/a6               ; save registers
                move.l      _IntuitionBase,a6
                cladr       a0                  ; class ID
                lea.l       IClassName,a1       ; points to "imageclass"
                cladr       a2                  ; no superclass pointer
                cldat       d0                  ; no instance data
                cldat       d1                  ; no flags
                libcall     MakeClass           ; make the class
                move.l      d0,a0               ; put class in a0
                tst.l       d0
                beq.s       noClass             ; failed!!!
                lea.l       dispatchGet(pc),a1  ; pointer to dispatcher
                move.l      a1,h_Entry(a0)      ; set our dispatcher
noClass:        popem.l     a2/a6               ; restore registers
                rts

dispatchGet:    pushem.l    d2-d7/a2-a6         ; save registers
                move.l      a0,a4               ; class to a4
                move.l      a1,a3               ; msg to a3

                cmp.l       #OM_NEW,(a3)        ; user want a new object ?
                bne.s       noNew               ; no!

                move.l      _UtilityBase,a6
                move.l      #GT_VisualInfo,d0   ; the tag we want
                cldat       d1                  ; default = NULL
                move.l      ops_AttrList(a3),a0 ; tags to a0
                libcall     GetTagData          ; look for the tag
                tst.l       d0                  ; tag found ?
                beq.s       newErrorV           ; no
                push.l      d0                  ; stack visualinfo

                move.l      a4,a0               ; class to a0
                move.l      a3,a1               ; msg to a1
                bsr         callSuper           ; call the superclass
                move.l      d0,a2               ; put object in a0
                tst.l       d0
                beq.s       newErrorO           ; failed!!!


                move.l      #MY_Width,d0
                move.l      #20,d1
                move.l      ops_AttrList(a3),a0 ; tags to a0
                libcall     GetTagData          ; look for the tag
                move.w      d0,ig_Width(a2)     ; tag found ?

                move.l      #MY_Height,d0
                move.l      #14,d1
                move.l      ops_AttrList(a3),a0 ; tags to a0
                libcall     GetTagData          ; look for the tag
                move.w      d0,ig_Height(a2)    ; tag found ?

                pop.l       ig_ImageData(a2)    ; set visualInfo
		move.l      a2,d0
                bra         Done                ; return Object
newErrorO:      addq.w      #4,sp               ; restore stack
newErrorV:      cldat       d0                  ; 0 for error
                bra         Done

noNew:          cmp.l       #IM_DRAW,(a3)       ; must we draw  ?
                bne         default             ; no!

draw:           cldat       d4                  ; left = 0
                cldat       d5                  ; top = 0
                move.w      ig_Width(a2),d6
                move.w      ig_Height(a2),d7

                move.w      impd_OffsetX(a3),d4 ; left = x offset
                move.w      impd_OffsetY(a3),d5 ; top = y offset

                move.l      _GfxBase,a6
                move.l      impd_RPort(a3),a5   ; rport to a5
                move.l      ig_ImageData(a2),a4 ; visualinfo to a4

                move.l      impd_DrInfo(a3),a2  ; drawinfo to a2
                move.l      dri_Pens(a2),a2     ; drawinfo pens to a2

                clr.l       rp_AreaPtrn(a5)     ; clear area pattern
                clr.b       rp_AreaPtSz(a5)

                move.l      a5,a1               ; rport to a1

                cmp.l       #IDS_INACTIVENORMAL,impd_State(a3) ; draw selected ?
                beq.s       inactive
                cmp.l       #IDS_INACTIVESELECTED,impd_State(a3) ; draw selected ?
                beq.s       inactive
                cmp.l       #IDS_INACTIVEDISABLED,impd_State(a3) ; draw selected ?
                beq.s       inactive
                move.w      hifillPen*2(a2),d0  ; FILLPEN color
                libcall     SetAPen             ; set the pen

                move.l      a5,a1               ; rport to a1
                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                move.w      d4,d2
                add.w       d6,d2
                dec.w       d2                  ; left + width - 1 to d2
                move.w      d5,d3
                add.w       d7,d3
                dec.w       d3                  ; top + height - 1 to d3
                libcall     RectFill
		bra	    filldone

inactive:       move.w      backgroundPen*2(a2),d0 ; BACKGROUNDPEN color
                libcall     SetAPen             ; set the pen

                move.l      a5,a1               ; rport to a1
                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                move.w      d4,d2
                add.w       d6,d2
                dec.w       d2                  ; left + width - 1 to d2
                move.w      d5,d3
                add.w       d7,d3
                dec.w       d3                  ; top + height - 1 to d3
                libcall     RectFill

filldone:
                move.l      a5,a1               ; rport to a1
                cmp.l       #IDS_SELECTED,impd_State(a3) ; selected text pen?
                bne.s       noFPen
                move.w      SHADOWPEN*2(a2),d0
                bra.s       setPen
noFPen:         move.w      SHINEPEN*2(a2),d0
setPen:         libcall     SetAPen             ; set the pen

                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                add.w       d7,d1
                subq.w      #2,d1                  ; top + height - 1 to d3
                move.l      a5,a1               ; rport to a1
                libcall     Move                ; move to this point

                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                move.l      a5,a1               ; rport to a1
                libcall     Draw                ; move to this point

                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                add.w       d6,d0
                subq.w      #1,d0
                move.l      a5,a1               ; rport to a1
                libcall     Draw                ; move to this point

                move.l      a5,a1               ; rport to a1
                cmp.l       #IDS_SELECTED,impd_State(a3) ; selected text pen?
                beq.s       noFPen2
                move.w      SHADOWPEN*2(a2),d0
                bra.s       setPen2
noFPen2:        move.w      SHINEPEN*2(a2),d0
setPen2:        libcall     SetAPen             ; set the pen

                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                add.w       d6,d0
                subq.w      #1,d0
                addq.w      #1,d1
                move.l      a5,a1               ; rport to a1
                libcall     Move                ; move to this point

                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                add.w       d6,d0
                add.w       d7,d1
                subq.w      #1,d0
                subq.w      #1,d1
                move.l      a5,a1               ; rport to a1
                libcall     Draw                ; move to this point

                move.w      d4,d0               ; left to d0
                move.w      d5,d1               ; top to d1
                add.w       d7,d1
                subq.w      #1,d1
                move.l      a5,a1               ; rport to a1
                libcall     Draw                ; move to this point

                move.l      a5,a1               ; rport to a1
                move.w      TEXTPEN*2(a2),d0
                libcall     SetAPen             ; set the pen

; horizontal
					move.w	d7,d1
					asr.w		#1,d1
					add.w		d5,d1
					move.w	d4,d0
					addq.w	#4,d0

                move.l      a5,a1               ; rport to a1
                libcall     Move                ; move to this point

					move.w	d7,d1
					asr.w		#1,d1
					add.w		d5,d1
					move.w	d4,d0
					add.w		d6,d0
					subq.w	#5,d0

                move.l      a5,a1               ; rport to a1
                libcall     Draw                ; move to this point

					move.w	d7,d1
					asr.w		#1,d1
					subq.w	#1,d1
					add.w		d5,d1
					move.w	d4,d0
					addq.w	#4,d0

                move.l      a5,a1               ; rport to a1
                libcall     Move                ; move to this point

					move.w	d7,d1
					asr.w		#1,d1
					subq.w	#1,d1
					add.w		d5,d1
					move.w	d4,d0
					add.w		d6,d0
					subq.w	#5,d0

                move.l      a5,a1               ; rport to a1
                libcall     Draw                ; move to this point

                moveq       #1,d0               ; return TRUE
                bra.s       Done

default:        move.l      a4,a0               ; class to a0
                move.l      a3,a1               ; msg to a1
                bsr         callSuper           ; call superclass
Done:           popem.l     d2-d7/a2-a6         ; restore registers
                rts

IClassName:     dc.b        'imageclass',0      ; superclass ID
                even

	end
