home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / System / ReqToolsLib / Source / reqtools / boopsi.asm next >
Encoding:
Assembly Source File  |  2001-07-02  |  9.2 KB  |  461 lines

  1.  
  2.     SECTION "text",CODE
  3.  
  4.     INCLUDE "exec/types.i"
  5.     INCLUDE "exec/funcdef.i"
  6.     INCLUDE "exec/exec_lib.i"
  7.     INCLUDE "intuition/intuitionbase.i"
  8.     INCLUDE "graphics/rastport.i"
  9.     INCLUDE "graphics/text.i"
  10.     INCLUDE "graphics/gfxbase.i"
  11.     INCLUDE "lvo/graphics_lib.i"
  12.  
  13.     INCLUDE "lvo/utility_lib.i"
  14.     INCLUDE "utility/hooks.i"
  15.  
  16.     INCLUDE "libraries/gadtools.i"
  17.  
  18.     INCLUDE "intuition/intuition.i"
  19.     INCLUDE "lvo/intuition_lib.i"
  20.     INCLUDE "intuition/classes.i"
  21.     INCLUDE "intuition/classusr.i"
  22.     INCLUDE "intuition/imageclass.i"
  23.  
  24.     INCLUDE "libraries/reqtools.i"
  25.     INCLUDE "lvo/reqtools_lib.i"
  26.  
  27.     INCLUDE    "boopsigads.i"
  28.  
  29.     XDEF _myBoopsiDispatch
  30.     XDEF @ShortDelay
  31.     XDEF _NewObject
  32.     XDEF @KeyFromStr
  33.  
  34.     XREF _LinkerDB
  35.     XREF _GfxBase
  36.     XREF _GadToolsBase
  37.     XREF _UtilityBase
  38.     XREF _IntuitionBase
  39.  
  40. _LVODrawBevelBox            equ        -$78
  41.  
  42. * int __regargs CatStrLen (char *string);
  43. * D0                       A0
  44. ;@CatStrLen:
  45. ;    moveq        #'_',d1
  46. ;    moveq        #-1,d0
  47. ;.nextchar:
  48. ;    addq.l    #1,d0
  49. ;.nextcharnoadd:
  50. ;    tst.b        (a0)
  51. ;    beq.b        .endlen
  52. ;    cmp.b        (a0)+,d1
  53. ;    bne.b        .nextchar
  54. ;    moveq        #0,d1
  55. ;    bra.b        .nextcharnoadd
  56. ;.endlen:
  57. ;    rts
  58.  
  59. * char __regargs KeyFromStr (char *string, char underchar);
  60. * D0                         A0            D0
  61. @KeyFromStr:
  62.     tst.b        (a0)
  63.     beq.b        .nounderscore
  64.     cmp.b        (a0)+,d0
  65.     bne.b        @KeyFromStr
  66.     move.b    (a0),d0
  67.     move.l    a6,-(a7)
  68.     move.l    _UtilityBase(a4),a6
  69.     jsr        _LVOToUpper(a6)
  70.     move.l    (a7)+,a6
  71.     rts
  72. .nounderscore:
  73.     moveq        #0,d0
  74.     rts
  75.  
  76. @ShortDelay:
  77.     movem.l    d2/a6,-(a7)
  78.     move.l    _GfxBase(a4),a6
  79.     moveq        #5,d2
  80. waitloop:
  81.     jsr        _LVOWaitTOF(a6)
  82.     dbf        d2,waitloop
  83.     movem.l    (a7)+,d2/a6
  84.     rts
  85.  
  86. ;_LVONewObjectA    EQU    -636
  87.  
  88. _NewObject:
  89.     movem.l    a2/a6,-(a7)
  90.     movem.l    8+4(a7),a0/a1
  91.     lea        8+12(a7),a2
  92.     move.l    _IntuitionBase(a4),a6
  93.     jsr        _LVONewObjectA(a6)
  94.     movem.l    (a7)+,a2/a6
  95.     rts
  96.  
  97. * myBoopsiDispatch (Class *cl, struct Image *im, struct impDraw *msg)
  98. *                   A0         A2                A1
  99. _myBoopsiDispatch:
  100.     movem.l    d1-d7/a0-a6,-(a7)
  101.     lea    _LinkerDB,a4
  102.     move.w    cl_InstOffset(a0),d7
  103.     move.l    _GfxBase(a4),a6
  104.  
  105.     cmp.l        #IM_DRAW,(a1)
  106.     beq        im_draw
  107.  
  108.     * This is DoSuperMethod for prepackaged "message" packets
  109.     move.l    a1,-(a7)
  110.     move.l    a2,d0
  111.     beq.s        cmnullreturn
  112.     move.l    a0,d0
  113.     beq.s        cmnullreturn
  114.     move.l    h_SIZEOF+4(a0),a0            ; substitute superclass
  115.     ; --- performs call to hook in A0 and restores a2
  116. cminvoke:
  117.     pea.l        cmreturn(pc)
  118.     move.l    h_Entry(a0),-(a7)
  119.     rts
  120. cmnullreturn:
  121.     moveq        #0,d0
  122. cmreturn:
  123.     move.l    (a7)+,a1
  124.  
  125.     cmp.l        #OM_NEW,(a1)
  126.     bne        enddispatch
  127.  
  128. ****** OM_NEW ******
  129.  
  130. om_new:
  131.     tst.l        d0                                ; error ?
  132.     beq        enddispatch
  133.     move.l    d0,a2                            ; DSM returned image pointer
  134.  
  135.     * Copy over InitData structure
  136.     move.l    ig_ImageData(a2),a0
  137.     lea        lod_IData(a2,d7.w),a1
  138.     moveq        #(idata_SIZEOF/4)-1,d0
  139. copyidata:
  140.     move.l    (a0)+,(a1)+
  141.     dbra        d0,copyidata
  142.  
  143.     move.l    lod_IData+idata_Label(a2,d7.w),a1
  144.     move.l    lod_IData+idata_TextAttr(a2,d7.w),a0
  145.     lea        lod_IData+idata_Underscore+3(a2,d7.w),a3
  146.     bsr        _myTextLength
  147.     move.w    d0,ig_Width(a2)
  148.  
  149.     * Calculate text position if we have a gadget
  150.     move.l    lod_IData+idata_Gadget(a2,d7.w),a0
  151.     move.l    a0,d0
  152.     beq.b        nogad3
  153.  
  154.     * im->LeftEdge = (gad->Width - im->Width) / 2;
  155.     move.w    gg_Width(a0),d0
  156.     sub.w        ig_Width(a2),d0
  157.     asr.w        #1,d0
  158.     move.w    d0,ig_LeftEdge(a2)
  159.  
  160.     * im->TopEdge = (gad->Height - im->Height) / 2;
  161.     move.w    gg_Height(a0),d0
  162.     sub.w        ig_Height(a2),d0
  163.     asr.w        #1,d0
  164.     move.w    d0,ig_TopEdge(a2)
  165. nogad3:
  166.  
  167.     move.l    a2,ig_ImageData(a2)
  168.     move.l    #BUTTON_MAGIC_LONGWORD,ig_Width(a2)
  169.  
  170.     move.l    a2,d0
  171.     bra        enddispatch
  172.  
  173. ****** IM_DRAW ******
  174.  
  175. im_draw:
  176.     move.l    a1,a5
  177.     move.l    impd_RPort(a5),a1            ; rp
  178.  
  179.     move.l    a1,-(a7)                        ; push rastport
  180.  
  181.     * Set drawmode to JAM1
  182.     moveq        #RP_JAM1,d0
  183.     jsr        _LVOSetDrMd(a6)
  184.  
  185.     * Open and set text font (or set default font)
  186.     move.l    lod_IData+idata_TextAttr(a2,d7.w),a0
  187.     moveq        #0,d5
  188.     move.b    ta_Style(a0),d5
  189.     jsr        _LVOOpenFont(a6)
  190.     move.l    d0,d6                            ; d6 = font
  191.     bne.b        okfont
  192.     move.l    gb_DefaultFont(a6),d0
  193. okfont:
  194.     move.l    d0,a0
  195.     move.l    (a7),a1
  196.     jsr        _LVOSetFont(a6)
  197.  
  198.     * Set style of font (bold, underlined,...)
  199.     move.l    d5,d0
  200.     move.l    d5,d1
  201.     move.l    (a7),a1
  202.     jsr        _LVOSetSoftStyle(a6)
  203.     move.l    (a7)+,a1                        ; pos rastport
  204.  
  205.     move.w    impd_OffsetY(a5),d1        ; x offset
  206.     move.w    impd_OffsetX(a5),d0        ; y offset for image only
  207.     move.l    impd_DrInfo(a5),a0
  208.     move.l    dri_Pens(a0),a0            ; a0 points to pens
  209.     move.l    a0,d2
  210.     bne.b        pensok
  211.     lea        defaultpens(PC),a0
  212. pensok:
  213.  
  214.     * is image connected to a gadget ?
  215.     move.l    lod_IData+idata_Gadget(a2,d7.w),a3    ; gadget
  216.     move.l    a3,d2
  217.     beq.b        nogad1
  218.  
  219.     * Get size of gadget container
  220.     move.w    gg_TopEdge(a3),d1
  221.     move.w    gg_LeftEdge(a3),d0
  222.     moveq        #0,d3
  223.     move.w    gg_Height(a3),d3            ; height
  224.     moveq        #0,d2
  225.     move.w    gg_Width(a3),d2            ; width
  226.  
  227.     move.l    impd_State(a5),d4            ; d4 = impd_State
  228.  
  229.     movem.l    d0-d3/a1,-(a7)                ; push gadget coords + rastport
  230.                                                 ; will be popped when bevelbox is drawn!
  231.  
  232.     * draw rectangle in BACKGROUNDPEN or FILLPEN
  233.     movem.l    d0-d3/a0-a1,-(a7)
  234.     add.w        #FILLPEN*2,a0
  235.     subq.l    #IDS_SELECTED,d4            ; d4 = !selected
  236.     beq.b        selected
  237.     addq.l    #(BACKGROUNDPEN-FILLPEN)*2,a0
  238. selected:
  239.     move.w    (a0),d0
  240.     jsr        _LVOSetAPen(a6)            ; set pen to FILLPEN
  241.     movem.l    (a7),d0-d3/a0-a1
  242.     add.l        d0,d2
  243.     subq.l    #1,d2                            ; xmax
  244.     add.l        d1,d3
  245.     subq.l    #1,d3                            ; ymax
  246.     jsr        _LVORectFill(a6)            ; draw background rectangle
  247.     movem.l    (a7),d0-d3/a0-a1
  248.  
  249.     * calculate gadget text pen
  250.     moveq        #TEXTPEN,d0
  251.     tst.l        d4
  252.     bne.b        notsel2
  253.     moveq        #FILLTEXTPEN,d0
  254. notsel2:
  255.     move.b    d0,ig_PlanePick(a2)
  256.     movem.l    (a7)+,d0-d3/a0-a1
  257. nogad1:
  258.  
  259.     * now we have d0 = xpos, d1 = ypos, a1 = rp, a0 = pens
  260.     *                  a5 = msg, a2 = image
  261.  
  262.     move.l    lod_IData+idata_Label(a2,d7.w),a3
  263.     add.w        ig_LeftEdge(a2),d0
  264.     add.w        ig_TopEdge(a2),d1
  265.  
  266.     * set front pen
  267.     movem.l    d0-d1/a1,-(a7)
  268.     moveq        #0,d0
  269.     move.b    ig_PlanePick(a2),d0
  270.     add.l        d0,d0
  271.     add.l        d0,a0
  272.     move.w    (a0),d0
  273.     jsr        _LVOSetAPen(a6)
  274.     movem.l    (a7),d0-d1/a1
  275.  
  276.     * move to text position
  277.     add.w        rp_TxBaseline(a1),d1
  278.     jsr        _LVOMove(a6)
  279.     movem.l    (a7),d0-d1/a1
  280.  
  281.     * draw first part of text (entire text if no underscore)
  282.     move.l    a3,a0
  283.     move.w    lod_UnderOff(a2,d7.w),d5
  284.     beq.b        notextbeforeunderscore
  285.     move.w    d5,d0
  286.     jsr        _LVOText(a6)
  287. notextbeforeunderscore:
  288.     movem.l    (a7)+,d0-d1/a1
  289.  
  290.     * is there an underscore in text ?
  291.     tst.b        ig_PlaneOnOff(a2)
  292.     beq.b        nounderscore
  293.  
  294.     * First draw rest of text
  295.     movem.l    d0-d1/a1,-(a7)
  296.     add.w        d5,a3
  297.     addq.w    #1,a3
  298.     move.w    rp_cp_x(a1),d5
  299.     move.w    lod_RestLen(a2,d7.w),d0
  300.     move.l    a3,a0
  301.     jsr        _LVOText(a6)
  302.     movem.l    (a7)+,d0-d1/a1
  303.  
  304.     * Draw underscore
  305.     move.w    d5,d0
  306.     add.w        lod_UnderY(a2,d7.w),d1
  307.     movem.l    d0-d1/a1,-(a7)
  308.     jsr        _LVOMove(a6)
  309.     movem.l    (a7)+,d0-d1/a1
  310.     add.w        lod_UnderWidth(a2,d7.w),d0
  311.     subq.w    #1,d0
  312.     jsr        _LVODraw(a6)
  313. nounderscore:
  314.  
  315.     tst.l        lod_IData+idata_Gadget(a2,d7.w)    ; gadget
  316.     beq.b        nogad2
  317.  
  318.     * draw bevelbox around gadget container (recessed if selected)
  319.     movem.l    (a7)+,d0-d3/a0                ; pop gadget coords + rastport (in A0!)
  320.     move.l    a7,a3
  321.     clr.l        -(a7)                            ; TAG_DONE
  322.     tst.l        d4
  323.     bne.b        notrecessed
  324.     subq.w    #4,a7
  325.     pea        GTBB_Recessed                ; recessed box
  326. notrecessed:
  327.     move.l    lod_IData+idata_VisualInfo(a2,d7.w),-(a7)    ; visinfo
  328.     pea        GT_VisualInfo
  329.     move.l    a7,a1                            ; tag array
  330.     move.l    _GadToolsBase(a4),a6
  331.     jsr        _LVODrawBevelBox(a6)
  332.     move.l    a3,a7
  333. nogad2:
  334.  
  335.     * close font we opened
  336.     tst.l        d6                                ; font opened ?
  337.     beq.b        nofont
  338.     move.l    d6,a1
  339.     move.l    _GfxBase(a4),a6
  340.     jsr        _LVOCloseFont(a6)
  341. nofont:
  342.  
  343. enddispatch:
  344.     movem.l    (a7)+,d1-d7/a0-a6
  345.     rts
  346.  
  347.  
  348.     XDEF    _myTextLength
  349.  
  350. * pixellen = myTextLength (char *str, struct TextAttr *attr,
  351. *                                              UBYTE *underscore, ULONG do_lod);
  352. * D0                       A1         A0       A3                 D7
  353. * (if D7 is non-zero => A2 must be image pointer!)
  354.  
  355. _myTextLength:
  356.     movem.l    d2-d5/d7/a2/a5/a6,-(a7)
  357.     sub.w        #rp_SIZEOF,a7
  358.     move.l    a7,a5                            ; a5 points to RastPort
  359.     move.l    _GfxBase(a4),a6
  360.  
  361.     move.l    a1,-(a7)
  362.  
  363.     move.l    a0,-(a7)
  364.  
  365.     * Initialize the RastPort
  366.     move.l    a5,a1
  367.     jsr        _LVOInitRastPort(a6)
  368.  
  369.     move.l    (a7)+,a0
  370.  
  371.     * Open and set text font (if supplied)
  372.     jsr        _LVOOpenFont(a6)
  373.     move.l    d0,d3                            ; d3 = font
  374.     bne.b        okfont2
  375.     move.l    gb_DefaultFont(a6),d0
  376. okfont2:
  377.     move.l    d0,a0
  378.     move.l    a5,a1
  379.     jsr        _LVOSetFont(a6)
  380.  
  381.     moveq        #0,d0
  382.     move.l    (a7)+,d4                        ; d4 is label
  383.     beq.b        no_label
  384.  
  385.     move.l    d4,a0
  386.     moveq        #-1,d5
  387. strlen:
  388.     addq.l    #1,d5
  389.     tst.b        (a0)+
  390.     bne.b        strlen                        ; d5 is strlen(label)
  391.  
  392.     * Image and object data variables
  393.     tst.l        d7
  394.     beq.b        no_lod
  395.     clr.b        ig_PlaneOnOff(a2)
  396.     move.w    d5,lod_UnderOff(a2,d7.w)
  397.     move.w    rp_TxHeight(a5),ig_Height(a2)
  398. no_lod:
  399.  
  400.     * Set the image width and height
  401.     move.l    d5,d0
  402.     move.l    d4,a0
  403.     move.l    a5,a1
  404.     jsr        _LVOTextLength(a6)
  405.  
  406.     move.l    d0,-(a7)
  407.  
  408.     * Search for '_' in string
  409.     move.b    (a3),d1
  410.     moveq        #-1,d0
  411.     move.l    d4,a0
  412. strloop:
  413.     tst.b        (a0)
  414.     beq.b        nounderscore2
  415.     addq.l    #1,d0
  416.     cmp.b        (a0)+,d1
  417.     bne.b        strloop
  418.  
  419.     tst.l        d7
  420.     beq.b        no_lod2
  421.  
  422.     move.b    (a0),ig_PlaneOnOff(a2)        ; store code of underscored key
  423.     move.w    d0,lod_UnderOff(a2,d7.w)    ; store offset of underscore
  424.     sub.w        d0,d5
  425.     subq.w    #1,d5
  426.     move.w    d5,lod_RestLen(a2,d7.w)        ; store len of remaining string
  427.     move.w    rp_TxBaseline(a5),d0
  428.     addq.w    #2,d0
  429.     move.w    d0,lod_UnderY(a2,d7.w)        ; Y position of underscore
  430.  
  431.     move.l    a5,a1
  432.     moveq        #1,d0
  433.     jsr        _LVOTextLength(a6)
  434.     move.w    d0,lod_UnderWidth(a2,d7.w)
  435. no_lod2:
  436.  
  437.     move.l    a5,a1
  438.     moveq        #1,d0
  439.     move.l    a3,a0
  440.     jsr        _LVOTextLength(a6)
  441.     sub.l        d0,(a7)                            ; subtract from pixel length
  442. nounderscore2:
  443.  
  444.     tst.l        d3
  445.     beq.b        nofont2
  446.     move.l    d3,a1
  447.     jsr        _LVOCloseFont(a6)
  448. nofont2:
  449.  
  450.     move.l    (a7)+,d0
  451.  
  452. no_label:
  453.     add.w        #rp_SIZEOF,a7                ; remove rastport from stack
  454.     movem.l    (a7)+,d2-d5/d7/a2/a5/a6
  455.     rts
  456.  
  457. defaultpens:
  458.     dc.w        1,0,1,2,1,3,1,0,2
  459.  
  460.     END
  461.