Login
Username:

Password:

Remember me



Lost Password?

Register now!
Main Menu
Who's Online
26 user(s) are online (16 user(s) are browsing Forum)

Members: 1
Guests: 25

BSzili, more...

Browsing this Thread:   1 Anonymous Users



(1) 2 »


Portable Zune/MUI Custom Class

Joined:
2008/1/4 14:39
From Germany
Group:
Member
Posts: 53
Offline
Hi, for Zune/MUI newbies (as me...) writing portable Zune apps is quite confusing...

I'm trying to change the class1.c example from mui38dev to work an Aros, Morph and classic Amiga. Only GCC (Aros and Morphos SDK and GG on Classic) should be supported.

Anyone has an 'optimal' solution regarding Headers, Defines (e.g. #define REG(x) register __ ## x) and Dispatchers (e.g. #define DISPATCHER(Name) ULONG ASM SAVEDS Name##Dispatcher(REG(a0) struct IClass *cl,REG(a2),REG(a1) Msg msg)) for me here?

Such an example would also be a good idea for our devel docs...

Christoph

Posted on: 2008/5/8 2:25
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class

Joined:
2005/8/17 16:00
From Germany
Group:
Member
Posts: 2070
Offline
Quote:

christoph wrote:
Hi, for Zune/MUI newbies (as me...) writing portable Zune apps is quite confusing...

I'm trying to change the class1.c example from mui38dev to work an Aros, Morph and classic Amiga. Only GCC (Aros and Morphos SDK and GG on Classic) should be supported.

Anyone has an 'optimal' solution regarding Headers, Defines (e.g. #define REG(x) register __ ## x) and Dispatchers (e.g. #define DISPATCHER(Name) ULONG ASM SAVEDS Name##Dispatcher(REG(a0) struct IClass *cl,REG(a2),REG(a1) Msg msg)) for me here?

Such an example would also be a good idea for our devel docs...

Christoph


I've ported Class2.c to AROS (I'm assuming that porting of an example code is no license violation)

It should be portable with one exception: I don't know how to write BOOPSI_DISPATCHER in a platform independent way. Maybe you can find some hints in the SDI headers.

Note that I'm using IPTR instead of ULONG in several places. Otherwise it wouldn't run on 64 bit AROS.

#include <proto/graphics.h>
#include <proto/utility.h>
#include <proto/muimaster.h>
#include <libraries/mui.h>

#ifdef __AROS__

#define SAVEDS
#define ASM

#else

// Hint: IPTR already exists on Morphos
typedef ULONG IPTR;

// TODO port BOOPSI_DISPATCHER to the *others*
//#define BOOPSI_DISPATCHER(IPTR, MyDispatcher, cl, obj, msg) 
//SAVEDS ASM IPTR MyDispatcher(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)

#define BOOPSI_DISPATCHER_END

#endif

static VOID fail(APTR app,char *str)
{
        if (
app)
                
MUI_DisposeObject(app);

        if (
str)
        {
                
puts(str);
                exit(
20);
        }
        exit(
0);
}

struct MyData
{
    
struct MUI_PenSpec penspec;
    
LONG pen;
    
BOOL penchange;
};

#define MYATTR_PEN 0x8022UL

SAVEDS IPTR mNew(struct IClass *cl,Object *obj,Msg msg)
{
    
struct MyData *data;
    
struct TagItem *tags,*tag;

    if (!(
obj = (Object *)DoSuperMethodA(cl,obj,msg)))
        return(
0);

    
data INST_DATA(cl,obj);

    for (
tags=((struct opSet *)msg)->ops_AttrList tag=NextTagItem(&tags);)
    {
        switch (
tag->ti_Tag)
        {
            case 
MYATTR_PEN:
                if (
tag->ti_Data)
                    
data->penspec = *((struct MUI_PenSpec *)tag->ti_Data);
                break;
        }
    }

    return (
IPTR)obj;
}



SAVEDS IPTR mDispose(struct IClass *cl,Object *obj,Msg msg)
{
    
/* OM_NEW didnt allocates something, just do nothing here... */
    
return DoSuperMethodA(cl,obj,msg);
}

SAVEDS IPTR mSet(struct IClass *cl,Object *obj,Msg msg)
{
    
struct MyData *data INST_DATA(cl,obj);
    
struct TagItem *tags,*tag;

    for (
tags=((struct opSet *)msg)->ops_AttrList tag=NextTagItem(&tags);)
    {
        switch (
tag->ti_Tag)
        {
            case 
MYATTR_PEN:
                if (
tag->ti_Data)
                {
                    
data->penspec = *((struct MUI_PenSpec *)tag->ti_Data);
                    
data->penchange TRUE;
                    
MUI_Redraw(obj,MADF_DRAWOBJECT); /* redraw ourselves completely */
                
}
                break;
        }
    }

    return 
DoSuperMethodA(cl,obj,msg);
}

static 
IPTR mGet(struct IClass *cl,Object *obj,Msg msg)
{
    
struct MyData *data INST_DATA(cl,obj);
    
IPTR *store = ((struct opGet *)msg)->opg_Storage;

    switch (((
struct opGet *)msg)->opg_AttrID)
    {
        case 
MYATTR_PEN: *store = (ULONG)&data->penspec; return(TRUE);
    }

    return 
DoSuperMethodA(cl,obj,msg);
}


SAVEDS IPTR mSetup(struct IClass *cl,Object *obj,Msg msg)
{
    
struct MyData *data INST_DATA(cl,obj);

    if (!
DoSuperMethodA(cl,obj,msg))
        return(
FALSE);

    
data->pen MUI_ObtainPen(muiRenderInfo(obj),&data->penspec,0);

    return(
TRUE);
}


SAVEDS IPTR mCleanup(struct IClass *cl,Object *obj,Msg msg)
{
    
struct MyData *data INST_DATA(cl,obj);

    
MUI_ReleasePen(muiRenderInfo(obj),data->pen);

    return 
DoSuperMethodA(cl,obj,msg);
}


SAVEDS IPTR mAskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
{
    
DoSuperMethodA(cl,obj,(Msg)msg);

    
msg->MinMaxInfo->MinWidth  += 100;
    
msg->MinMaxInfo->DefWidth  += 120;
    
msg->MinMaxInfo->MaxWidth  += 500;

    
msg->MinMaxInfo->MinHeight += 40;
    
msg->MinMaxInfo->DefHeight += 90;
    
msg->MinMaxInfo->MaxHeight += 300;

    return 
0;
}

SAVEDS IPTR mDraw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
{
    
struct MyData *data INST_DATA(cl,obj);
    
int i;

    
DoSuperMethodA(cl,obj,(Msg)msg);

    if (!(
msg->flags MADF_DRAWOBJECT))
        return(
0);


    if (
data->penchange)
    {
        
data->penchange FALSE;
        
MUI_ReleasePen(muiRenderInfo(obj),data->pen);
        
data->pen MUI_ObtainPen(muiRenderInfo(obj),&data->penspec,0);
    }

    
SetAPen(_rp(obj),MUIPEN(data->pen));

    for (
i=_mleft(obj);i<=_mright(obj);i+=5)
    {
        
Move(_rp(obj),_mleft(obj),_mtop(obj));
        
Draw(_rp(obj),i,_mbottom(obj));
        
Move(_rp(obj),_mright(obj),_mtop(obj));
        
Draw(_rp(obj),i,_mbottom(obj));
    }

    return 
0;
}

BOOPSI_DISPATCHER(IPTRMyDispatcherclobjmsg)
{
    switch (
msg->MethodID)
    {
        case 
OM_NEW        : return(mNew      (cl,obj,(APTR)msg));
        case 
OM_DISPOSE    : return(mDispose  (cl,obj,(APTR)msg));
        case 
OM_SET        : return(mSet      (cl,obj,(APTR)msg));
        case 
OM_GET        : return(mGet      (cl,obj,(APTR)msg));
        case 
MUIM_AskMinMax: return(mAskMinMax(cl,obj,(APTR)msg));
        case 
MUIM_Setup    : return(mSetup    (cl,obj,(APTR)msg));
        case 
MUIM_Cleanup  : return(mCleanup  (cl,obj,(APTR)msg));
        case 
MUIM_Draw     : return(mDraw     (cl,obj,(APTR)msg));
    }

    return 
DoSuperMethodA(cl,obj,msg);
}
BOOPSI_DISPATCHER_END

int main
(int argc,char *argv[])
{
    
Object *app,*window,*MyObj,*pen;
    
struct MUI_CustomClass *mcc;
    
struct MUI_PenSpec *startpen;

    if (!(
mcc MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct MyData),MyDispatcher)))
        
fail(NULL,"Could not create custom class.");

    
app ApplicationObject,
        
MUIA_Application_Title      "Class2",
        
MUIA_Application_Version    "$VER: Class2 19.5 (12.02.97)",
        
MUIA_Application_Copyright  "©1993, Stefan Stuntz",
        
MUIA_Application_Author     "Stefan Stuntz",
        
MUIA_Application_Description"Demonstrate the use of custom classes.",
        
MUIA_Application_Base       "CLASS2",

        
SubWindowwindow WindowObject,
            
MUIA_Window_Title"Another Custom Class",
            
MUIA_Window_ID   MAKE_ID('C','L','S','2'),
            
WindowContentsVGroup,

                
ChildTextObject,
                    
TextFrame,
                    
MUIA_BackgroundMUII_TextBack,
                    
MUIA_Text_Contents"33cThis is a custom class with attributes.nClick on the button at the bottom ofnthe window to adjust the color.",
                    
End,

                
ChildMyObj NewObject(mcc->mcc_Class,NULL,
                    
TextFrame,
                    
MUIA_BackgroundMUII_BACKGROUND,
                    
TAG_DONE),

                
ChildHGroupMUIA_Weight10,
                    
ChildFreeLabel("Custom Class Color:"),
                    
Childpen PoppenObject,
                        
MUIA_CycleChain1,
                        
MUIA_Window_Title"Custom Class Color",
                        
End,
                    
End,

                
End,

            
End,
        
End;

    if (!
app)
        
fail(app,"Failed to create Application.");

    
DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
        
app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);

    
DoMethod(pen,MUIM_Notify,MUIA_Pendisplay_Spec,MUIV_EveryTime,
        
MyObj,3,MUIM_Set,MYATTR_PEN,MUIV_TriggerValue);

    
DoMethod(pen,MUIM_Pendisplay_SetMUIPen,MPEN_HALFSHINE);

    
get(pen,MUIA_Pendisplay_Spec,&startpen);
    
set(MyObj,MYATTR_PEN,startpen);

    
set(window,MUIA_Window_Open,TRUE);

    {
        
ULONG sigs 0;

        while (
DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
        {
            if (
sigs)
            {
                
sigs Wait(sigs SIGBREAKF_CTRL_C);
                if (
sigs SIGBREAKF_CTRL_C) break;
            }
        }
    }

    
set(window,MUIA_Window_Open,FALSE);

    
MUI_DisposeObject(app);
    
MUI_DeleteCustomClass(mcc);
    
fail(NULL,NULL);
}

Posted on: 2008/5/8 14:32
_________________
AROS - Make code, not war
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class

Joined:
2007/4/1 6:08
Group:
Member
Posts: 42
Offline
Quote:

christoph wrote:
Hi, for Zune/MUI newbies (as me...) writing portable Zune apps is quite confusing...


Here you can download what you search:

http://shinkuro.altervista.org/guida/ ... s/MUIClassTutorialOOP.zip

It's an example of portable class attached to my Amiga portable programming guide.... however my guide is (for now) olny in italian language:

http://shinkuro.altervista.org/guida/

Posted on: 2008/5/9 0:40
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class

Joined:
2008/1/4 14:39
From Germany
Group:
Member
Posts: 53
Offline
Mazze, ShInKur0 thank you for your reply.

It is really astonishing how different the implementations of the SDKs really are...

ShInKur0 your tutorial seems to be really nice and the examples are very helpful. (Unfortunately my Italian is not very good - I understand no word of the text ... Otherwise I would help to translate if I could...)

One becomes really aware of what one has to do if it should really be platform comprehensive for Amiga like systems.

Christoph

Posted on: 2008/5/9 5:45
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class -> Datatype mess

Joined:
2008/1/4 14:39
From Germany
Group:
Member
Posts: 53
Offline
Ok, gradual I'm getting a better idea of this things. Still I've some mess with those datatypes...

APTR, IPTR, CPTR, ULONG, ... ??

From Amiga C manual:
====================
APTR Absolute memory pointer
(Misdefined, use CPTR!)

Aros manual:
============
ULONG address;
...
has to be translated for AROS to:
...
IPTR address;

Amiga OS4 exec/types.h
======================
typedef unsigned long uint32 // replaces ULONG

My question is: Which datatypes to use in modern apps? What is deprecated, how to keep portable? ShInKurO, maybe the answer is in your great tutorial... unfortunately I can't read it...

Christoph!

Posted on: 2008/6/12 22:57
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class -> Datatype mess

Joined:
2004/3/30 23:19
From Clausthal-Zellerfeld, Germany
Group:
Member
Posts: 388
Offline
Quote:

My question is: Which datatypes to use in modern apps? What is deprecated, how to keep portable? ShInKurO, maybe the answer is in your great tutorial... unfortunately I can't read it...


if you want to write really portable app, you may be interested in standard datatypes defined in C99 (or earlier, dunno): int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, intptr_t, uintptr_t.

They are all defined in inttypes.h include file.

Posted on: 2008/6/12 23:06
_________________
Click to see original Image in a new window
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class -> Datatype mess

Joined:
2008/1/4 14:39
From Germany
Group:
Member
Posts: 53
Offline
Quote:

if you want to write really portable app, you may be interested in standard datatypes defined in C99 (or earlier, dunno)


Ok, let's say at least Aros, Amiga 68k, OS4, Morphos portable. Those types are heavily used e.g. in Zune/MUI apps. Just don't want to use deprecated types.


Posted on: 2008/6/13 0:07
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class -> Datatype mess

Joined:
2005/5/13 15:23
Group:
Member
Posts: 47
Offline
@cristoph

Quote:

Ok, let's say at least Aros, Amiga 68k, OS4, Morphos portable. Those types are heavily used e.g. in Zune/MUI apps. Just don't want to use deprecated types.


You can always define your own standards ;)

For Amiga coding I would use following types:

UBYTE/BYTE for 8bit
UWORD/WORD for 16bit
ULONG/LONG for 32bit
UQUAD/QUAD for 64bit

APTR for an address pointer
IPTR for mixed integer/address pointer

int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, intptr_t, uintptr_t as suggested byu mihcal are also ok. It is only matter of taste.

I prefer the original types (with AROS extensions) because existing software and headers are already using it.

But as I said you can always define your own standards and use typedef.

Posted on: 2008/6/13 7:37
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class

Joined:
2007/4/1 6:08
Group:
Member
Posts: 42
Offline
My guide is translated (CAP 0, 1, 2, 3), but the most importants capters are WIP for translate... (obviously not by me ;-D):

http://shinkuro.altervista.org/guida/english/index.htm

Posted on: 2008/6/13 13:25
Transfer the post to other applications Transfer


Re: Portable Zune/MUI Custom Class

Joined:
2008/1/4 14:39
From Germany
Group:
Member
Posts: 53
Offline
Quote:

ShInKurO wrote:
My guide is translated

Perfect!!!

Posted on: 2008/6/13 14:48
Transfer the post to other applications Transfer



(1) 2 »



You can view topic.
You cannot start a new topic.
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.

[Advanced Search]


Search
Top Posters
1 paolone
paolone
3767
2 nikolaos
nikolaos
3470
3 magorium
magorium
3129
4 phoenixkonsole
phoenixkonsole
3072
5 deadwood
deadwood
2371
6 ncafferkey
ncafferkey
2138
7 mazze
mazze
2070
8 clusteruk
clusteruk
2051
9 damocles
damocles
1771
10 Kalamatee
Kalamatee
1769
© 2004-2014 AROS Exec