MUI Helper
Jump to navigation
Jump to search
This Page describe how to write MUI/Zune application in FreePascal comparable to C-Sources with the MUI macros. The needed functions for it are collected inside muihelper unit in the ami-extra package. Therefore this unit should be available for all Amiga-style systems.
Comparison C with Macros and Pascal with muihelper unit:
C-Source with Macros (balance example from MUI developer archive) | Pascal-Source with muihelper unit |
---|---|
#include "demo.h"
int main(int argc,char *argv[])
{
APTR app,window;
init();
app = ApplicationObject,
MUIA_Application_Title , "BalanceDemo",
MUIA_Application_Version , "$VER: BalanceDemo 19.5 (12.02.97)",
MUIA_Application_Copyright , "©1995, Stefan Stuntz",
MUIA_Application_Author , "Stefan Stuntz",
MUIA_Application_Description, "Show balancing groups",
MUIA_Application_Base , "BALANCEDEMO",
SubWindow, window = WindowObject,
MUIA_Window_Title, "Balancing Groups",
MUIA_Window_ID , MAKE_ID('B','A','L','A'),
MUIA_Window_Width , MUIV_Window_Width_Screen(50),
MUIA_Window_Height, MUIV_Window_Height_Screen(50),
WindowContents, HGroup,
Child, VGroup, GroupFrame, MUIA_Weight, 15,
Child, RectangleObject, TextFrame, MUIA_Weight, 50, End,
Child, RectangleObject, TextFrame, MUIA_Weight, 100, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, MUIA_Weight, 200, End,
End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, VGroup,
Child, HGroup, GroupFrame,
Child, RectangleObject, TextFrame, MUIA_ObjectID, 123, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, MUIA_ObjectID, 456, End,
End,
Child, HGroup, GroupFrame,
Child, RectangleObject, TextFrame, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, End,
End,
Child, HGroup, GroupFrame,
Child, HGroup,
Child, RectangleObject, TextFrame, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, End,
End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, HGroup,
Child, RectangleObject, TextFrame, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, End,
End,
End,
Child, HGroup, GroupFrame,
Child, RectangleObject, TextFrame, MUIA_Weight, 50, End,
Child, RectangleObject, TextFrame, MUIA_Weight, 100, End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, RectangleObject, TextFrame, MUIA_Weight, 200, End,
End,
Child, HGroup, GroupFrame,
Child, SimpleButton("Also"),
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, SimpleButton("Try"),
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, SimpleButton("Sizing"),
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, SimpleButton("With"),
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, SimpleButton("Shift"),
End,
Child, HGroup, GroupFrame,
Child, Label("Label 1:"),
Child, TextObject, MUIA_Text_Contents, "data...", End,
Child, BalanceObject, MUIA_CycleChain, 1, End,
Child, Label("Label 2:"),
Child, TextObject, MUIA_Text_Contents, "more data...", End,
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);
/*
** This is the ideal input loop for an object oriented MUI application.
** Everything is encapsulated in classes, no return ids need to be used,
** we just check if the program shall terminate.
** Note that MUIM_Application_NewInput expects sigs to contain the result
** from Wait() (or 0). This makes the input loop significantly faster.
*/
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);
/*
** Shut down...
*/
fail(app,NULL);
}
|
program balancing;
uses
Exec, Utility, intuition, AmigaDos, mui, muihelper;
procedure StartMe;
var
App, Window: PObject_;
Sigs: LongInt;
begin
app := MH_Application([
MUIA_Application_Title, AsTag('BalanceDemo'),
MUIA_Application_Version, AsTag('$VER: BalanceDemo 19.5 (12.02.97)'),
MUIA_Application_Copyright, AsTag('©1995, Stefan Stuntz'),
MUIA_Application_Author, AsTag('Stefan Stuntz'),
MUIA_Application_Description, AsTag('Show balancing groups'),
MUIA_Application_Base, AsTag('BALANCEDEMO'),
SubWindow, AsTag(MH_Window(Window, [
MUIA_Window_Title, AsTag('Balancing Groups'),
MUIA_Window_ID, MAKE_ID('B','A','L','A'),
MUIA_Window_Width , MUIV_Window_Width_Screen(50),
MUIA_Window_Height, MUIV_Window_Height_Screen(50),
WindowContents, AsTag(MH_HGroup([
Child, AsTag(MH_VGroup(GroupFrame, [MUIA_Weight, 15,
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_Weight, 50, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_Weight, 100, TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_Weight, 200, TAG_END])),
TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_VGroup([
Child, AsTag(MH_HGroup(GroupFrame, [
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_ObjectID, 123, TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_ObjectID, 456, TAG_END])),
TAG_END])),
Child, AsTag(MH_HGroup(GroupFrame, [
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
TAG_END])),
Child, AsTag(MH_HGroup(GroupFrame, [
Child, AsTag(MH_HGroup([
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_HGroup([
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [TAG_END])),
TAG_END])),
TAG_END])),
Child, AsTag(MH_HGroup(GroupFrame, [
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_Weight, 50, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_Weight, 100, TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Rectangle(TextFrame, [MUIA_Weight, 200, TAG_END])),
TAG_END])),
Child, AsTag(MH_HGroup(GroupFrame, [
Child, AsTag(MH_SimpleButton('Also')),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_SimpleButton('Try')),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_SimpleButton('Sizing')),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_SimpleButton('With')),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_SimpleButton('Shift')),
TAG_END])),
Child, AsTag(MH_HGroup(GroupFrame, [
Child, AsTag(MH_Label('Label 1:')),
Child, AsTag(MH_Text('data...', [TAG_END])),
Child, AsTag(MH_Balance([MUIA_CycleChain, 1, TAG_END])),
Child, AsTag(MH_Label('Label 2:')),
Child, AsTag(MH_Text('more data...', [TAG_END])),
TAG_END])),
TAG_END])),
TAG_END])),
TAG_END])),
TAG_END]);
if not Assigned(app) then
begin
writeln('Failed to create Application');
Exit;
end;
DoMethod(window, [MUIM_Notify, MUIA_Window_CloseRequest, MUI_TRUE,
AsTag(app), 2, AsTag(MUIM_Application_ReturnID), AsTag(MUIV_Application_ReturnID_Quit)]);
// This is the ideal input loop for an object oriented MUI application.
// Everything is encapsulated in classes, no return ids need to be used,
// we just check if the program shall terminate.
// Note that MUIM_Application_NewInput expects sigs to contain the result
// from Wait() (or 0). This makes the input loop significantly faster.
MH_Set(Window, MUIA_Window_Open, AsTag(True));
//
if MH_Get(Window, MUIA_Window_Open) <> 0 then
begin
while Integer(DoMethod(app, [MUIM_Application_NewInput, AsTag(@sigs)])) <> MUIV_Application_ReturnID_Quit do
begin
if Sigs <> 0 then
begin
Sigs := Wait(sigs or SIGBREAKF_CTRL_C);
if (Sigs and SIGBREAKF_CTRL_C) <>0 then
Break;
end;
end;
end;
//Shut down...
MH_Set(Window, MUIA_Window_Open, AsTag(True));
MUI_DisposeObject(app);
end;
begin
StartMe;
end.
|