Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Gadget example */
- #include <proto/intuition.h>
- #include <proto/gadtools.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <intuition/intuition.h>
- #include <libraries/gadtools.h>
- #include <stdio.h>
- APTR visual;
- /* Type of gadgets to display */
- ULONG Gadgetkinds[3] = {STRING_KIND, INTEGER_KIND, BUTTON_KIND };
- struct TextAttr topaz8 = {
- (STRPTR)"topaz.font", 8, 0, 1
- };
- /* Data for gadget structures */
- struct NewGadget Gadgetdata[3] = {
- 63, 26, 172, 13, (UBYTE *)"Name", &topaz8, 1, PLACETEXT_LEFT, NULL, NULL,
- 62, 50, 175, 15, (UBYTE *)"Age", &topaz8, 2, PLACETEXT_LEFT, NULL, NULL,
- 111, 105, 54, 31, (UBYTE *)"Calc", &topaz8, 3, PLACETEXT_IN, NULL, NULL
- };
- /* Extra information for gadgets using Tags */
- ULONG GadgetTags[] = {
- (GTST_MaxChars), 256, (TAG_DONE),
- (GTNM_Border), TRUE, (TAG_DONE),
- (TAG_DONE)
- };
- int main() {
- struct Screen *pubScreen;
- struct Window *myWindow;
- struct Gadget *myGadgets[3], *glist=NULL, *gad1;
- int closewin = FALSE, i;
- struct IntuiMessage *msg;
- ULONG msgClass;
- /* Lock screen and get visual info for gadtools */
- if (pubScreen = LockPubScreen(NULL)) {
- if (!(visual = GetVisualInfo(pubScreen, TAG_DONE))) {
- printf("Failed to get visual info.\n");
- return(5);
- }
- }
- else {
- printf("Failed to lock screen.\n");
- return(5);
- }
- /* Create the gadget list */
- if (!(gad1 = CreateContext(&glist))) {
- printf("Failed to create gadtools context.\n");
- return(5);
- }
- /* Create gadgets specify gadget kind, a Gadget, NewGadget data and extra tag info */
- for (i=0; i<3; i++) {
- Gadgetdata[i].ng_VisualInfo = visual;
- if (myGadgets[i] = gad1 = CreateGadgetA(Gadgetkinds[i], gad1, &Gadgetdata[i], (struct TagItem *)&GadgetTags[i])) {
- printf("Gadget %d created.\n", i);
- }
- else
- printf("Failed to create gadget %d.\n",i);
- }
- /* Open window and specify gadget list (glist) */
- myWindow = OpenWindowTags(NULL,
- WA_Left, 10, WA_Top, 15,
- WA_Width, 280, WA_Height, 180,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
- WA_Flags, WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_SMART_REFRESH,
- WA_Gadgets, glist,
- WA_Title, "My Window",
- WA_PubScreenName, "Workbench",
- TAG_DONE);
- GT_RefreshWindow(myWindow, NULL); /* Update window */
- while (closewin == FALSE) {
- Wait(1L << myWindow->UserPort->mp_SigBit);
- msg = GT_GetIMsg(myWindow->UserPort);
- msgClass = msg->Class;
- GT_ReplyIMsg(msg);
- if (msgClass == IDCMP_CLOSEWINDOW) {
- closewin = TRUE;
- }
- }
- if (myWindow) CloseWindow(myWindow);
- /* Free gadgets */
- if (glist) FreeGadgets(glist);
- if (visual) FreeVisualInfo(visual);
- if (pubScreen) UnlockPubScreen(NULL, pubScreen);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement