Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
205 user(s) are online (125 user(s) are browsing Forums)

Members: 0
Guests: 205

more...

Headlines

 
  Register To Post  

Newbie question about ENUM and GUI development
Just can't stay away
Just can't stay away


See User information
Hi Guys,

sorry for this newbie question I apologize but I am going crazy to find an answer (documentation) about the use of C word ENUM inside the development of an Amiga GUI..

I know what is an ENUM in C but what I cannot understand, reading/studying the examples is the use of the ENUM inside the GUI building process..

I have looked through all the wikipage and the ADCD but I wasn't able to find any answer that could give me a clue about it..

What I cannot understand is always this, I took a little part of code that you can find in any example available for the Amiga OS 4.x:

Quote:


enum
{
    WID_MAIN = 0,
    WID_LAST
};

enum
{
    OID_MAIN = 0,
    OID_LAST
};



As you can see there is always an OID_LAST or a WID_LAST but these two elements are not defined inside the GUI layout creation.. They are always put inside the code as last elements of a list of objects that toghether define the gui of your project but what I would like to know is why.. where can i find a proper documentation??

Sorry for this stupid question but while I was able to find documentation about amigaos libraries and exec, I wasn't about this..

May you help me please?

;/* Window Example
gcc -o Window Window.c -lauto
quit
*/

/**
 **  Window.c -- Window Example.
 **
 **  Simple window.class example used to test newer features.
 **/

#include <dos/dos.h>
#include <classes/window.h>
#include <gadgets/button.h>
#include <gadgets/layout.h>

#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/window.h>
#include <proto/layout.h>
#include <proto/button.h>

enum
{
    
WID_MAIN 0,
    
WID_LAST
};

enum
{
    
OID_MAIN 0,
    
OID_LAST
};

int main()
{
    
// Make sure class files were loaded.
    
if ( WindowBase == NULL || LayoutBase == NULL || ButtonBase == NULL)
    {
        return 
RETURN_FAIL;
    }

    
struct Window *windows[WID_LAST];
    
Object *objects[OID_LAST];

    
struct MsgPort *AppPort IExec->AllocSysObjectTags(ASOT_PORTTAG_DONE);

    if ( 
AppPort != NULL )
    {
        
objects[OID_MAIN] = IIntuition->NewObject(NULL"window.class",
            
WA_ScreenTitle"Window Example",
            
WA_Title"Window Example",
            
WA_ActivateTRUE,
            
WA_DepthGadgetTRUE,
            
WA_DragBarTRUE,
            
WA_CloseGadgetTRUE,
            
WA_SizeGadgetTRUE,

            
// If on the Workbench screen, this tells window.class that
            // we can handle the iconify/uniconify when changing screens.
            
WINDOW_IconifiableTRUE,

            
WINDOW_AppPortAppPort,
            
WINDOW_PositionWPOS_CENTERMOUSE,
            
WINDOW_LayoutIIntuition->NewObject(NULL"layout.gadget",
                
LAYOUT_OrientationLAYOUT_ORIENT_VERT,
                
LAYOUT_SpaceOuterTRUE,
                
LAYOUT_DeferLayoutTRUE,
                
LAYOUT_AddChildIIntuition->NewObject(NULL"button.gadget",
                    
GA_Text"Click Me",
                
TAG_DONE),
           
TAG_DONE),
        
TAG_DONE);

        if (
objects[OID_MAIN] != NULL)
        {
            
//  Open the window.
            
windows[WID_MAIN] = (struct Window *)IIntuition->IDoMethod(objects[OID_MAIN], WM_OPEN);

            if (
windows[WID_MAIN] != NULL)
            {
                
// Obtain the window wait signal mask.

                
uint32 signal 0;
                
IIntuition->GetAttr(WINDOW_SigMaskobjects[OID_MAIN], &signal);

                
// Input Event Loop

                
BOOL done FALSE;

                while (!
done)
                {
                    
uint32 wait IExec->Wait(signal SIGBREAKF_CTRL_C);

                    if ( 
wait SIGBREAKF_CTRL_C )
                    {
                        
done TRUE;
                        break;
                    }

                    if ( 
wait signal )
                    {
                        
uint32 result WMHI_LASTMSG;
                        
int16 code 0;

                        while ((
result IIntuition->IDoMethod(objects[OID_MAIN], WM_HANDLEINPUT, &code)) !=
WMHI_LASTMSG)
                        {
                            switch (
result WMHI_CLASSMASK)
                            {
                                case 
WMHI_CLOSEWINDOW:
                                    
windows[WID_MAIN] = NULL;
                                    
done TRUE;
                                    break;

                                case 
WMHI_ICONIFY:
                                    
IIntuition->IDoMethod(objects[OID_MAIN], WM_ICONIFY);
                                    
windows[WID_MAIN] = NULL;
                                    break;

                                case 
WMHI_UNICONIFY:
                                    
windows[WID_MAIN] = (struct Window *)IIntuition->IDoMethod(objects[OID_MAIN],
WM_OPEN);
                                    break;
                            }
                        }
                    }
                }
            }

            
/* Disposing of the window object will also close the window if it is
             * already opened, and it will dispose of the layout object attached to it.
             */
            
IIntuition->DisposeObject(objects[OID_MAIN]);
        }

    }

    
IExec->FreeSysObject(ASOT_PORTAppPort);

    return 
RETURN_OK;
}

Go to top
Re: Newbie question about ENUM and GUI development
Amigans Defender
Amigans Defender


See User information
@nubechecorre

The WID_LAST, OID_LAST etc are to make it easier to define your arrays.

enum {
  
OID_MAIN 0,
  
OID_LAST
};

Object *objects[OID_LAST];

objects[OID_MAIN] = NewObject(blah);


Go to top
Re: Newbie question about ENUM and GUI development
Just can't stay away
Just can't stay away


See User information
Ok but what i don't understand is why there is an oid_last if in the layout of the GUI it isn't used?...


Go to top
Re: Newbie question about ENUM and GUI development
Just can't stay away
Just can't stay away


See User information
As Chris posted is for defining the array length (remember arrays in C starts from 0, maybe other languages don't):
...
// I have 6 gadgets
enum
{
    
GID_MAIN=0,
    
GID_INTEGER1,
    
GID_INTEGER2,
    
GID_DOWN,
    
GID_UP,
    
GID_QUIT,
    
GID_LAST
};

// I have 1 window
enum
{
    
WID_MAIN=0,
    
WID_LAST
};

// I have 1 object
enum
{
    
OID_MAIN=0,
    
OID_LAST
};

int main(void)
{
    
struct MsgPort *AppPort;
    
struct Window *windows[WID_LAST];
    
struct Gadget *gadgets[GID_LAST];
    
Object *objects[OID_LAST];

    
/* make sure our classes opened... */
...

Go to top
Re: Newbie question about ENUM and GUI development
Just can't stay away
Just can't stay away


See User information
Ok but where is reported all this? Because i wasn't able to find any documentation about it..

I am talking about Every id_last that are defined inside the enum but are not used in the GUI layout.. And why the object pointer always point to the last enum id if this one (ID_LAST) is never used?

Go to top
Re: Newbie question about ENUM and GUI development
Home away from home
Home away from home


See User information
@nubechecorre Quote:
Ok but what i don't understand is why there is an oid_last if in the layout of the GUI it isn't used?...

It looks like OID_LAST is very needed to me:
Quote:
    Object *objects[OID_LAST];


In other words, OID_LAST is used as a count of how many items an array needs to hold all your objects. In the above code, you can use array indexes from 0 to OID_LAST-1.

Author of the PortablE programming language.
Go to top
Re: Newbie question about ENUM and GUI development
Just can't stay away
Just can't stay away


See User information
Ok thanks that's the idea that i made on my mind reading and studying the examples.. Sorry for the question but, is there any reference/link about this method and object *object_[last element] inside the Amiga SDK?..

Go to top
Re: Newbie question about ENUM and GUI development
Home away from home
Home away from home


See User information
@nubechecorre

It's simply a neat trick to get the size of the array need to hold all the object pointers, gadget pointers or image pointers, depending on what you enum is decribing.

enum {
GAD_ID_ZERO, // = 0
GAD_ID_ONE, // = 1
GAD_ID_TWO, // =2
GAD_ID_LAST // = 3
};

Thus by defining the array

Object * gadgets[GAD_ID_LAST]

you create an array of the correct size, which will always resize (after recompilation) if you add more gadgets,

so your enum becomes

enum {
GAD_ID_ZERO, // = 0
GAD_ID_ONE, // = 1
GAD_ID_TWO, // =2
GAD_ID_THREE, // = 3
GAD_ID_LAST // = 4
};

The array is autmaticall resixed when you recompile your code, this avoids having to calculate the numeber or keep track of the number of gadgets you are using.


I personally always make my last item

GAD_ID_NUMGADS or IMG_ID_NUMIMGS etc to make it more obvious.


It's probably not described in detail in any amiga specific doc as it's a general C prgramming trick.


Go to top
Re: Newbie question about ENUM and GUI development
Just can't stay away
Just can't stay away


See User information
Most important, thanks to all, now is much clear!!

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project