Hi,
On my SAM440ep (AmigaOS 4.1 update 6), when I create a prop gadget with NewObject(), and slide the knob at a certain speed, few IDCMP_IDCMPUPDATE messages are sent to my program. It seems the processor is very busy with something. Strange thing is, this does not happen when I put the gadget in the right window border with GA_RightBorder. Similar code on my A4000 does not behave like this. Anyone any idea what's going on?
My crappy code is below, compiled with the SDK:
/**************************
* *
* PropGadgetTest.c *
* *
**************************/
/**************
* includes *
**************/
#include <exec/exec.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/icclass.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include "stdio.h" /* for printf() */
#include "stdlib.h" /* for exit() */
#include "string.h" /* for strlen() */
/*************
* defines *
*************/
#define PROPGAD 1
#define PROPGADWIDTH 16
/**********************
* global variables *
**********************/
struct Library *DosBase = NULL;
struct Library *IntuitionBase = NULL;
struct IntuitionIFace *IIntuition = NULL;
struct Library *GfxBase = NULL;
struct GraphicsIFace *IGraphics = NULL;
struct Window *Window = NULL;
struct Gadget *PropGadget = NULL;
/***************
* functions *
***************/
void CloseAll(void)
{
if (PropGadget)
{
IIntuition->RemoveGadget(Window, PropGadget);
IIntuition->DisposeObject((Object *) PropGadget);
}
if (Window) IIntuition->CloseWindow(Window);
if (IGraphics) IExec->DropInterface((struct Interface *) IGraphics);
if (GfxBase) IExec->CloseLibrary(GfxBase);
if (IIntuition) IExec->DropInterface((struct Interface *) IIntuition);
if (IntuitionBase) IExec->CloseLibrary(IntuitionBase);
}
void Fail(char *failtext)
{
printf("%s\n", failtext);
CloseAll();
exit(FALSE);
}
void OpenAll(void)
{
static char WindowTitle[] = "PropGadgetTest";
if (!(IntuitionBase = IExec->OpenLibrary("intuition.library", 0)))
Fail("could not open intuition.library");
if (!(IIntuition = (struct IntuitionIFace *) IExec->GetInterface(IntuitionBase, "main", 1, NULL)))
Fail("could not get intuition interface");
if (!(GfxBase = IExec->OpenLibrary("graphics.library", 0)))
Fail("could not open graphics.library");
if (!(IGraphics = (struct GraphicsIFace *) IExec->GetInterface(GfxBase, "main", 1, NULL)))
Fail("could not get graphics.library interface");
/* set miniumum width and height */
if (!(Window = IIntuition->OpenWindowTags(NULL,
WA_Title, WindowTitle,
WA_Width, 640,
WA_Height, 480,
WA_MinWidth, 400,
WA_MinHeight, 200,
WA_MaxWidth, -1,
WA_MaxHeight, -1,
WA_Flags, WFLG_CLOSEGADGET | WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE,
TAG_END)))
Fail("could not open window");
if (!(PropGadget = (struct Gadget *) IIntuition->NewObject(NULL, "propgclass",
GA_ID, PROPGAD,
GA_RelRight, -(Window->BorderRight + PROPGADWIDTH),
GA_Top, Window->BorderTop + 4,
GA_Width, PROPGADWIDTH,
GA_RelHeight, - Window->BorderTop - Window->BorderBottom - 8,
GA_Immediate, TRUE,
GA_RelVerify, TRUE,
GA_RightBorder, FALSE, // set to TRUE and updates come more often
ICA_TARGET, ICTARGET_IDCMP,
PGA_Total, 100,
PGA_Top, 0,
PGA_Visible, 10,
PGA_Freedom, FREEVERT,
PGA_NewLook, TRUE,
PGA_Borderless, TRUE,
TAG_DONE )))
{
Fail("could not create prop gadget");
}
IIntuition->AddGadget(Window, PropGadget, -1);
IIntuition->RefreshGadgets(PropGadget, Window, NULL);
}
/************************
* *
* PropGadgetTest *
* *
************************/
int main(void)
{
BOOL done = FALSE;
struct IntuiMessage *imsg;
struct RastPort *rp;
char infoString[100];
ULONG top;
OpenAll();
while (!done)
{
imsg = (struct IntuiMessage *) IExec->GetMsg(Window->UserPort);
if (!imsg)
{
IExec->Wait(1 << Window->UserPort->mp_SigBit);
continue;
}
switch (imsg->Class)
{
case IDCMP_CLOSEWINDOW:
done = TRUE;
break;
case IDCMP_IDCMPUPDATE:
IIntuition->GetAttr(PGA_Top, (Object *) PropGadget, &top);
snprintf(infoString, sizeof(infoString), "% 5d", (int) top);
rp = Window->RPort;
IGraphics->Move(rp, Window->BorderLeft, Window->BorderTop + rp->TxBaseline);
IGraphics->SetAPen(rp, 1);
IGraphics->Text(rp, infoString, strlen(infoString));
break;
}
IExec->ReplyMsg((struct Message *) imsg);
}
CloseAll();
return 0;
}
Weird prop gadget problem
Weird prop gadget problem
Last edited by djg on Sun Jan 27, 2013 3:52 pm, edited 1 time in total.
- salass00
- AmigaOS Core Developer
- Posts: 534
- Joined: Sat Jun 18, 2011 4:12 pm
- Location: Finland
- Contact:
Re: Weird prop gadget problem
@djg
I compiled and ran your code with GA_RightBorder set to both and FALSE and TRUE and the IDCMP_IDCMPUPDATE worked fine for me in either case. I did find and fix a couple of errors in your code though:
1. There is a TAG_DONE missing from your OpenWindowTags() call.
2. You don't have a "return 0;" statement at the end of your main() function.
I also changed the sprintf() call to:
snprintf(infoString, sizeof(infoString), "% 5d", (int)top);
as snprintf() is a better function to use IMO. The cast to int I added to get rid of a gcc warning.
In the future I suggest that you always use -Wall and also -Werror when compiling and fix all the warnings reported as they may help you to find bugs in your code.
I compiled and ran your code with GA_RightBorder set to both and FALSE and TRUE and the IDCMP_IDCMPUPDATE worked fine for me in either case. I did find and fix a couple of errors in your code though:
1. There is a TAG_DONE missing from your OpenWindowTags() call.
2. You don't have a "return 0;" statement at the end of your main() function.
I also changed the sprintf() call to:
snprintf(infoString, sizeof(infoString), "% 5d", (int)top);
as snprintf() is a better function to use IMO. The cast to int I added to get rid of a gcc warning.
In the future I suggest that you always use -Wall and also -Werror when compiling and fix all the warnings reported as they may help you to find bugs in your code.
Re: Weird prop gadget problem
@salass00,
Ok, thanks, I've fixed those things too now (and moved ReplyMsg() thinking that might be the cause).
The missing TAG_DONE was a big error, and I thought adding it would fix things.
So I compiled again (with the -W options) but got the same result.
I noticed that the very program I am writing this with (MUI OWB) suffers the same problem here.
Moving the knob at a certain speed does not make the content move at all!
Ok, thanks, I've fixed those things too now (and moved ReplyMsg() thinking that might be the cause).
The missing TAG_DONE was a big error, and I thought adding it would fix things.
So I compiled again (with the -W options) but got the same result.
I noticed that the very program I am writing this with (MUI OWB) suffers the same problem here.
Moving the knob at a certain speed does not make the content move at all!