• Moderator
    Kronos
    Posts: 2257 from 2003/2/24
    This is Class1.lua (similar to what existed in the old release).

    "include" all needed modules and define OM_SET (since it is not in mui.h and won't be generated by current scripts)
    Code:

    require 'abox'
    require 'cdata'
    require "muidefs"
    require "muifuncs"
    require "muistructs"
    require "io"



    mui.OM_SET = 0x103


    Modes if and when DoSuperMethod() should be called, save unnecessary back and forth between the script and the mui.module but should be defined inside the module.
    Code:


    mui.NoSuper = 0
    mui.PreSuper = 1
    mui.PostSuper = 2



    Define some structs not covered by the scripts.

    Code:


    TagItem = {
    name = "TagItem",
    {types.ULONG, "ti_Tag"},
    {types.ULONG, "ti_Data"}
    };

    opSet = {
    name = "opSet",
    {types.ULONG, " MethodID"},
    {"struct TagItem", "ops_AttrList"},
    {"struct GadgetInfo *", "ops_GInfo"}
    };

    mydata = {
    name = "mydata",
    {types.ULONG,"dummy1"},
    {types.ULONG,"dummy2"},
    }


    Implementation of MUIM_AskMinMax, note that cdata.module now will now set amm to MinMaxInfo by default

    Code:

    function areaamm(cl,obj,msg)
    amm = msg.MinMaxInfo
    amm.MinWidth = amm.MinWidth + 200
    amm.DefWidth = amm.DefWidth + 220
    amm.MaxWidth = amm.MaxWidth + 500
    amm.MinHeight = amm.MinHeight + 220
    amm.DefHeight = amm.DefHeight + 190
    amm.MaxHeight = amm.MaxHeight + 300
    end



    MUIM_Draw using some special function found in abox.module.

    Code:


    function areadraw(cl,obj,msg)
    rp = obj:rp()
    data = obj:inst_data(cl)
    data.dummy1 = data.dummy1+1
    -- cache the dimesions to enhance performace
    -- as these accesses aren't as straightforward as they would be with C
    top = obj:mtop()
    left = obj:mleft()
    bottom = obj:mbottom()
    right = obj:mright()
    for i = left,right,5 do
    rp:Move(left,bottom+data.dummy1)
    rp:Draw(i,top)
    rp:Move(right,bottom)
    rp:Draw(i,top)
    end
    end


    MUIM_Set with some pointless test code. Parsing a full TagList is possible, just not in an elegant way.

    Code:

    function areaset(cl,obj,msg)
    io.write(msg.ops_AttrList.ti_Tag.." "..mui.MUIA_Window_Open.."n")
    io.write(msg.ops_AttrList[1].ti_Tag.." "..mui.MUIA_Window_Open.."n")
    msg.ops_AttrList[1].ti_Tag = 111111112
    io.write(msg.ops_AttrList[1].ti_Tag.." "..mui.MUIA_Window_Open.."n")
    end


    Definition of the dispatcher.
    Code:

    myclass_dis = {{mui.MUIM_AskMinMax,areaamm,mui.PreSuper,mui.MUIP_AskMinMax},
    {mui.MUIM_Draw,areadraw,mui.PreSuper,mui.MUIP_Draw},
    {mui.OM_SET,areaset,mui.PreSuper,"opSet"}
    }


    "Registering" structs is still needed in some cases but will disappear later on.
    Create class and object.

    Code:

    function main()
    struct.register(mui.MUI_MinMax)
    struct.register(opSet)
    struct.register(TagItem)
    mcc = mui.createcostumclass(mui.MUIC_Area,myclass_dis,mydata)
    myobj = mui.new(mcc)--, mui.TextFrame,mui.UIA_Background,mui.MUII_BACKGROUND )


    Boilerplate MUI code.
    Code:

    window = mui.WindowObject(
    mui.MUIA_Window_Title, "A Simple Custom Class",
    mui.MUIA_Window_ID , mui.makeid("CLS1"),
    mui.WindowContents, mui.HGroup (mui.Child,mui.HSpace(202),mui.Child, myobj)
    )

    app = mui.ApplicationObject(
    mui.MUIA_Application_Title , "Class1",
    mui.MUIA_Application_Version , "$VER: Class1.lua 0.2 (28.1.2023)",
    mui.MUIA_Application_Author , "Stefan Stuntz, Stefan Kleinheinrich",
    mui.MUIA_Application_Description, "LUA port of the Class1 demo",
    mui.MUIA_Application_Base , "CLASS1",
    mui.SubWindow, window )

    window:doint(mui.MUIM_Notify, mui.MUIA_Window_CloseRequest, true,
    app, 2, mui.MUIM_Application_ReturnID, mui.MUIV_Application_ReturnID_Quit)

    window:set(mui.MUIA_Window_Open, true)
    -- myobj:set(mui.MUIA_Window_Open, true,mui.MUIA_Window_Open+1, true)
    app:doint(mui.MUIM_Application_Execute)
    -- window:set(mui.MUIA_Window_Open, false)
    if app then app:dispose() end

    end

    main()



    [ Edited by Kronos 01.04.2023 - 19:17 ]
  • »01.04.23 - 18:12
    Profile