Aros Developer Zune

puzzlegamesios sportsappsios wargamesios
 03 October 21:04   

    What is Zune?

    Zune is an acquisitive GUI toolkit. It is about a carbon (at both API and Look&Feel level) of MUI, a acclaimed Amiga shareware artefact by Stefan Stuntz. Accordingly MUI developers will feel at home here, while others will ascertain the concepts and qualities that Zune shares with MUI.

    The programmer has a abundant easier time to architecture its GUI: no charge for hardcoded values, Zune is font-sensitive, and adapts to any window admeasurement due to its blueprint system. He/she mostly needs to alone specify the semantic of its GUI to Zune, which will align the low-level data for him automatically.

    As a side-effect, the user has added ascendancy on the Look&Feel of the GUI: its he/she who decides the accurate settings that Zune will use to present the GUI that the programmer designed.

    Zune is based on the BOOPSI system, the framework affiliated from AmigaOS for acquisitive programming in C. Zune classes dont acquire from absolute BOOPSI apparatus classes; instead, the Acquaint chic (base chic of the Zune hierarchy) derives from the BOOPSI basis class.

    Some ability of OO (object-oriented) programming is added than welcome. If not, Google may advice you acquisition acceptable anterior affidavit on this archetypal subject.

    Knowing AROS (or AmigaOS) APIs and concepts like taglists and BOOPSI is essential. Accepting the Amiga Advertence Manuals (aka RKM) is actual handy.

    As Zune is a MUI clone, all the affidavit pertaining to MUI is applicative to Zune. In particular, the latest accessible MUI developer kit can be begin at [http://main.aminet.net/dev/mui/mui38dev.lha here]. In this LHA archive, 2 abstracts are acquiescently recommended:

    MUIdev.guide, the MUI programmer documentation.

    PSI.c, the sourcecode of an appliance demonstrating all the avant-garde MUI practices like acquisitive architecture and activating item creation.

    Additionally, this annal contains MUI autodocs, which are the advertence documentations for all Zune classes.

    A chic is authentic by its name, its ancestor chic and a dispatcher.

    name: either a cord for the accessible classes, so that they may be acclimated by any program in the system, or none if its a clandestine chic acclimated alone by a individual application.

    parent class: all BOOPSI classes are basic a bureaucracy abiding at the chic appropriately called rootclass. It allows anniversary bracket to apparatus its own adaptation of specific ancestor operation, or to abatement aback on the one provided by its parent. Aswell accepted as abject chic or cool class.

    dispatcher: it gives admission to all operations (called methods) provided by this class, ensuring that anniversary operation is handled by the able cipher or anesthetized to its cool class.

    BOOPSI blazon for a chic is Chic

    An item is an instance of class: anniversary item has its specific data, but all altar of the aforementioned chic allotment the aforementioned behavior. An item has several classes if we calculation the parents of its true chic (the alotof acquired one) up to the rootclass.

    BOOPSI blazon for an item is Item

    An aspect is accompanying to the instance data of anniversary object: you deceit admission these data directly, you can alone set or get the attributes provided by an item to adapt its centralized state. An aspect is implemented as a Tag (ULONG amount ored with TAG_USER).

    GetAttr() and SetAttrs() are acclimated to adapt an altar attributes.

    Attributes can be one or added of the following:

    Initialization-settable (I) : the aspect can be accustomed as constant at the item creation.

    Settable (S) : You can set this aspect at any time (or at least, not alone creation).

    Gettable (G) : You can get the amount of this attribute.

    Method

    A BOOPSI adjustment is a action which receives as ambit an object, a chic and a message:

    object: the item you act on

    class: the advised chic for this object.

    message: contains a adjustment ID which determines the action to alarm aural a dispatcher, and is followed by its parameters.

    To forward a bulletin to an object, use DoMethod(). It will use the true chic first. If the chic accouterments this method, it will handle it. Abroad it will try its ancestor class, until the bulletin is handled or the rootclass is accomplished (in this case, the alien bulletin is silently discarded).

    Lets see basal examples of this OOP framework:

    Getting an attribute

    Well concern a MUI Cord item for its content:

    void f(Object

    Object IPTR haveto be acclimated for the blazon of the result, which can be an accumulation or a pointer. An IPTR is consistently accounting in memory, so using a abate blazon would advance to anamnesis corruption!

    Here we concern a MUI Cord item for its content: MUIA_String_Contents, as any additional attribute, is a ULONG (its a Tag)

    Zune applications use added generally the get() and XGET() macros instead:

    get(string, MUIA_String_Contents, &result);

    result = XGET(string, MUIA_String_Contents);

    Setting an attribute

    Lets change the agreeable of our string:

    SetAttrs(string, MUIA_String_Contents, (IPTR)hello, TAG_DONE);

    Pointers ambit haveto be casted to IPTR to abstain warnings.

    After the item parameter, a taglist is anesthetized to SetAttrs and appropriately haveto end with TAG_DONE.

    Youll acquisition the set() macro useful:

    set(string, MUIA_String_Contents, (IPTR)hello);

    But its alone with SetAttrs() that you can set several attributes at once:

    SetAttrs(string,

     MUIA_Disabled, TRUE,

     MUIA_String_Contents, (IPTR)hmmm...,

     TAG_DONE);

    Calling a method

    Lets see the alotof alleged adjustment in a Zune program, the accident processing adjustment alleged in your capital loop:

    result = DoMethod(obj, MUIM_Application_NewInput, (IPTR)&sigs);

    Parameters are not a taglist, and appropriately dont end with TAG_DONE.

    You accept to casting pointers to IPTR to abstain warnings.

    Hello world

    First things first! I knew you would be all excited.

    Lets abstraction our first absolute activity example:

    // gcc hello.c -lmui

    #include

    #include

    #include

    #include

    #include

    #include

    int main(void)

     }

     }

     // Abort our appliance and all its objects

     MUI_DisposeObject(app);

     }

    

     acknowledgment 0;

    }

    We dont manually accessible libraries, its done automatically for us.

    We use a macro-based accent to calmly body our GUI. A Zune appliance has consistently 1 and alone 1 Appliance object:

    : app = ApplicationObject,

    An appliance can accept 0, 1 or added Window objects. Alotof generally a individual one:

    : SubWindow, wnd = WindowObject,

    Be nice, accord a appellation to the window:

    : MUIA_Window_Title, Accost world!,

    A window haveto accept 1 and alone 1 child, usually a group. This one is vertical, that agency that its accouchement will be abiding vertically:

    : WindowContents, VGroup,

    A accumulation haveto accept at atomic 1 child, actuality its just a text:

    : Child, TextObject,

    Zune accepts assorted escape codes (here, to centermost the text) and newlines:

    : MUIA_Text_Contents, 33cHello world!
How are you?,

    An End macro haveto bout every xxxObject macro (here, TextObject):

    : End,

    Lets add a additional adolescent to our group, a button! With a keyboard adjustment o adumbrated by an underscore:

    : Child, but = SimpleButton(_Ok),

    Finish the group:

    : End,

    Finish the window:

    : End,

    Finish the application:

    : End;

    So, who still needs a GUI builder? :-)

    Error handling

    If any of the item in the appliance timberline deceit be created, Zune destroys all the altar already created and appliance conception fails. If not, you accept a absolutely alive application:

    : if (app != NULL)

    :

    Notifications

    Notifications are the simplest way to acknowledge on events. The principle? We wish to be notified if a assertive aspect of a assertive item is set to a assertive value:

    : DoMethod(wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,

    Here able-bodied accept to the MUIA_Window_CloseRequest of our Window item and be notified whenever this aspect is set to TRUE. So what happens if a notification is triggered? A bulletin is beatific to an object, actuality we acquaint our Appliance to acknowledgment MUIV_Application_ReturnID_Quit on the next accident bend iteration:

    : (IPTR)app, 2,

    : MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

    As we can specify annihilation we wish here, we accept to acquaint the amount of added ambit we are bartering to MUIM_Notify: here, 2 parameters.

    For the button, we accept to its MUIA_Pressed attribute: its set to False whenever the button is getting appear (reacting if its apprenticed is bad practice, you may wish to absolution the abrasion alfresco of the button to abolish your activity - additional we wish to see how it looks if its pressed). The activity is the aforementioned as the previous, forward a bulletin to the application:

    : DoMethod(but, MUIM_Notify, MUIA_Pressed, FALSE,

    : (IPTR)app, 2,

    : MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

    Opening the window

    Windows arent accessible until you ask them to:

    : set(wnd, MUIA_Window_Open, TRUE);

    If all goes well, your window should be displayed at this point. But it can fail! So dont overlook to analysis by querying the attribute, which should be TRUE:

    : if (XGET(wnd, MUIA_Window_Open))

    Main loop

    Let me acquaint you my lil friend, the ideal Zune accident loop:

    : ULONG sigs = 0;

    Dont overlook to initialize the signals to 0 ... The analysis of the bend is the MUIM_Application_NewInput method:

    : ...

    : while((LONG) DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs)

    : != MUIV_Application_ReturnID_Quit)

    It takes as ascribe the signals of the contest it has to action (result from Wait(), or 0), will adapt this amount to abode the signals Zune is cat-and-mouse for (for the next Wait()) and will acknowledgment a value. This acknowledgment amount apparatus was historically the alone way to acknowledge on events, but it was animal and has been deprecated in favor of custom classes and acquisitive design.

    The physique of the bend is absolutely empty, we alone delay for signals and handle Ctrl-C to breach out of the loop:

    :

    : }

    This program gets you started with Zune, and allows you to toy with GUI design, but not more.

    As apparent in hello.c, you use MUIM_Notify to alarm a adjustment if a assertive action happens. If you wish your appliance to acknowledge in a specific way to events, you can use one of these schemes:

    MUIM_Application_ReturnID: you can ask your appliance to acknowledgment an approximate ID on the next bend iteration, and analysis for the amount in the loop. This is the bedraggled old way of accomplishing things.

    MUIM_CallHook, to alarm a accepted Amiga callback hook: this is an boilerplate choice, not acquisitive but not that animal either.

    custom method: the adjustment belongs to one of your custom class. It is the best band-aid as it supports acquisitive architecture in applications. It requires you to make custom classes, so it may not be the easiest for beginners or humans in a hurry.

    

 


Tags: program, specific, system, child, design, application, class, content, classes, custom, attributes, window, programming, called, button, provided, value, signals, event, method

 object, class, application, string, window, attribute, method, boopsi, classes, value, message, oriented, returnid, contents, parameters, setattrs, objects, return, notify, design, domethod, child, parent, result, macro, events, group, certain, creation, signals, custom, attributes, button, pressed, newinput, finish, react, modify, dispatcher, program, system, programmer, amiga, rootclass, specific, ulong, content, developer, called, provided, event, , object oriented, application returnid, muim application, string contents, muia string, muia window, string muia, muim notify, muiv application, returnid quit, tag done, oriented design, parent class, contents iptr, application newinput, finish the, muia string contents, string muia string, application returnid quit, muiv application returnid, string contents iptr, muim application returnid, muim application newinput, object oriented design, returnid muiv application, muia window open, wnd muia window, muia window closerequest, application returnid muiv, application newinput iptr, mui string object, object oriented programming, setattrs string muia, contents iptr hello, newinput iptr &sigs, aros developer zune, muim notify muia,

Share Aros Developer Zune: Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  Graphical