English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 20 July 2013, 07:30   #1
zharn
Registered User
 
Join Date: Nov 2012
Location: Brisbane Australia
Posts: 150
gadtools

Hi,

Im playing around with gadtools.h, my array of gadgets is displaying correctly.

i having trouble getting GA_Disabled/GT_Disabled to work for an INTERGER_KIND, yet i can read and write to the gadget fine.

example is

GT_SetGadgetAttrs(myGadgets[1], myWindow, NULL,
GA_Disabled, TRUE);

i get unidentified identifier "GA_Disabled"

RKM says...
INTEGER_KIND:

GA_Disabled (BOOL) - Set to TRUE to disable gadget, FALSE otherwise (V36) GTIN_Number (ULONG) - New value of the integer gadget (V36)



any clues please..
zharn is offline  
Old 20 July 2013, 09:44   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,025
GT_Disabled is defined in intuition/gadgetclass.h. However, you shouldn't need to include it explicitely because it is automatically included if you include proto/gadtools.h which you need to use GadTools.

Furthermore you have to finish each call to GT_SetGadgetAttrs with TAG_DONE or TAG_END, otherwise you will crash.
thomas is offline  
Old 21 July 2013, 00:27   #3
zharn
Registered User
 
Join Date: Nov 2012
Location: Brisbane Australia
Posts: 150
Thanks Thomas i just found your gadtools.c, cant read the comments but it helped with how to process returned strings properly.. I was almost there, just missed a &.
zharn is offline  
Old 21 July 2013, 00:29   #4
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,025
Here is an example for GA_Disabled:

Code:
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>

#define GID_ACTIVE       1001
#define GID_NUMBER       1002

int main (void)

{
struct Screen *scr;

if (scr = LockPubScreen (NULL))
	{
	long x,y,w,h;
	struct NewGadget ng = {0};
	struct Gadget *glist = NULL;
	struct Gadget *gad = CreateContext (&glist);
	struct Window *win;
	struct Gadget *numgad;

	ng.ng_VisualInfo = GetVisualInfo (scr,TAG_END);
	ng.ng_TextAttr   = scr->Font;
	ng.ng_Flags      = 0;

	w = scr->RastPort.TxWidth;;
	h = scr->RastPort.TxHeight;

	x = scr->WBorLeft + 8 + 8 * w;
	y = scr->WBorTop + h + 9;

	ng.ng_LeftEdge   = x;
	ng.ng_TopEdge    = y;
	ng.ng_Height     = h + 6;
	ng.ng_Width      = ng.ng_Height;
	ng.ng_GadgetText = "Active";
	ng.ng_GadgetID   = GID_ACTIVE;
	gad = CreateGadget (CHECKBOX_KIND,gad,&ng,GTCB_Scaled,TRUE,GTCB_Checked,TRUE,TAG_END);

	ng.ng_TopEdge   += ng.ng_Height + 4;
	ng.ng_Width      = 10 * w + 20;
	ng.ng_GadgetText = "Number";
	ng.ng_GadgetID   = GID_NUMBER;
	gad = CreateGadget (INTEGER_KIND,gad,&ng,GTIN_Number,123,TAG_END);
	numgad = gad;

	w = ng.ng_LeftEdge + ng.ng_Width + 8 + scr->WBorRight;
	h = ng.ng_TopEdge + ng.ng_Height + 8 + scr->WBorBottom;

	if (gad)
	if (win = OpenWindowTags (NULL,
			WA_Width,w,
			WA_Height,h,
			WA_Left,(scr->Width - w) / 2,
			WA_Top,(scr->Height - h) / 2,
			WA_PubScreen,scr,
			WA_Title,"Demo",
			WA_Flags,WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE,
			WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY | CHECKBOXIDCMP | INTEGERIDCMP,
			WA_Gadgets,glist,
			TAG_END))
		{
		BOOL cont = TRUE;

		GT_RefreshWindow (win,NULL);

		do	{
			struct IntuiMessage *imsg;

			if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
				cont = FALSE;

			while (imsg = GT_GetIMsg (win->UserPort))
				{
				switch (imsg->Class)
					{
				case IDCMP_REFRESHWINDOW:
					GT_BeginRefresh (win);
					GT_EndRefresh (win,TRUE);
					break;
				case IDCMP_GADGETUP:
					{
					struct Gadget *gad = (struct Gadget *) imsg->IAddress;
					ULONG sel;
					switch (gad->GadgetID)
						{
					case GID_ACTIVE:
						GT_GetGadgetAttrs (gad,win,NULL,GTCB_Checked,&sel,TAG_END);
						GT_SetGadgetAttrs (numgad,win,NULL,GA_Disabled,(sel == 0),TAG_END);
						break;
					case GID_NUMBER:
						GT_GetGadgetAttrs (gad,win,NULL,GTIN_Number,&sel,TAG_END);
						Printf ("number = %ld\n",sel);
						break;
						}
					break;
					}
				case IDCMP_VANILLAKEY:
					if (imsg->Code == 0x1b)
						cont = FALSE;
					break;
				case IDCMP_CLOSEWINDOW:
					cont = FALSE;
					break;
					}

				GT_ReplyIMsg (imsg);
				}
			}
		while (cont);

		CloseWindow (win);
		}

	FreeGadgets (glist);
	FreeVisualInfo (ng.ng_VisualInfo);

	UnlockPubScreen (NULL,scr);
	}

return (RETURN_OK);
}

Last edited by thomas; 21 July 2013 at 11:44. Reason: window truely centered on screen, the right IDCMP macros used, quit with Esc added
thomas is offline  
Old 21 July 2013, 09:38   #5
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Germany
Posts: 585
Nice example, especially the calculations for font-sensitivity. Thanks!
bubbob42 is offline  
Old 21 July 2013, 11:48   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 7,025
Quote:
Originally Posted by bubbob42 View Post
Nice example, especially the calculations for font-sensitivity. Thanks!
Well, text width is approximated by average character width times number of characters. If a string contains many wide characters, this might fail. But it's easier than to get TextLength from every string and search the maximum.
thomas is offline  
Old 21 February 2014, 20:26   #7
bubbob42
Registered User
 
Join Date: Oct 2012
Location: Germany
Posts: 585
I'm reviving this, because I just starting with GadTools again - after a very long time.

However, to compile the above example, one has to explicitly include intuition/gadgetclass.h, when using original 3.1 or SAS/C includes.

If you're using the includes from the NDK 3.5, you'll be fine without any changes.
bubbob42 is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:42.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07417 seconds with 12 queries