static BOOL LayOutReq (struct AHIAudioModeRequesterExt *req, struct TextAttr *TextAttr) { struct Gadget *gad; struct NewGadget ng; struct TextAttr *gadtextattr; struct TextFont *font; LONG fontwidth,buttonheight,buttonwidth,pixels; struct IntuiText intuitext = {1,0,JAM1,0,0,NULL,NULL,NULL}; LONG sliderlevels,sliderlevel; LONG selected; selected=GetSelected(req); GetSliderAttrs(req,&sliderlevels,&sliderlevel); // Calculate gadget area req->gx=req->Window->BorderLeft+4; req->gy=req->Window->BorderTop+2; req->gw=req->Window->Width-req->gx-(req->Window->BorderRight+4); req->gh=req->Window->Height-req->gy-(req->Window->BorderBottom+2); if(req->Gadgets) { RemoveGList(req->Window,req->Gadgets,-1); FreeGadgets(req->Gadgets); SetAPen(req->Window->RPort,0); SetDrMd(req->Window->RPort,JAM1); EraseRect(req->Window->RPort, req->Window->BorderLeft, req->Window->BorderTop, req->Window->Width-req->Window->BorderRight-1,req->Window->Height-req->Window->BorderBottom-1); RefreshWindowFrame(req->Window); } req->Gadgets=NULL; if((gad=CreateContext(&req->Gadgets))) { if(TextAttr) gadtextattr=TextAttr; else gadtextattr=req->Window->WScreen->Font; if((font=OpenFont(gadtextattr))) { fontwidth=font->tf_XSize; CloseFont(font); } else return FALSE; buttonheight=gadtextattr->ta_YSize+6; intuitext.ITextFont=gadtextattr; intuitext.IText=req->PositiveText; buttonwidth=IntuiTextLength(&intuitext); intuitext.IText=req->NegativeText; pixels=IntuiTextLength(&intuitext); buttonwidth=max(pixels,buttonwidth); buttonwidth+=4+fontwidth; // Create gadgets and check if they fit // Do the two buttons fit? if(2*buttonwidth > req->gw) return FALSE; ng.ng_TextAttr=gadtextattr; ng.ng_VisualInfo=req->vi; ng.ng_UserData=req; // OK button ng.ng_LeftEdge=req->gx; ng.ng_TopEdge=req->gy+req->gh-buttonheight; ng.ng_Width=buttonwidth; ng.ng_Height=buttonheight; ng.ng_GadgetText=req->PositiveText; ng.ng_GadgetID=OKBUTTON; ng.ng_Flags=PLACETEXT_IN; gad=CreateGadget(BUTTON_KIND,gad,&ng,TAG_END); // Cancel button ng.ng_LeftEdge=req->gx+req->gw-ng.ng_Width; ng.ng_GadgetText=req->NegativeText; ng.ng_GadgetID=CANCELBUTTON; gad=CreateGadget(BUTTON_KIND,gad,&ng,TAG_END); // Frequency if(req->Flags & freqgad) { intuitext.IText = GetString(msgReqFrequency, req->Catalog); pixels=IntuiTextLength(&intuitext)+INTERWIDTH; if(pixels+MINSLIDERWIDTH+INTERWIDTH+FREQLEN2*fontwidth > req->gw) return FALSE; ng.ng_Width=req->gw-pixels-INTERWIDTH-FREQLEN2*fontwidth; ng.ng_LeftEdge=req->gx+pixels; ng.ng_TopEdge-=2+buttonheight; ng.ng_GadgetText = GetString(msgReqFrequency, req->Catalog); ng.ng_GadgetID=FREQSLIDER; ng.ng_Flags=PLACETEXT_LEFT; gad=CreateGadget(SLIDER_KIND,gad,&ng, GTSL_Min,0, GTSL_Max,sliderlevels-1, GTSL_Level,sliderlevel, GTSL_LevelFormat, (ULONG) FREQTEXT2, GTSL_MaxLevelLen,FREQLEN2, GTSL_LevelPlace,PLACETEXT_RIGHT, GTSL_DispFunc, (ULONG) m68k_IndexToFrequency, GA_RelVerify,TRUE, GA_Disabled,!sliderlevels || (req->tempAudioID == AHI_DEFAULT_ID), TAG_DONE); req->slidergadget=gad; // Save for HadleReq()... } // ListView if((ng.ng_Height=ng.ng_TopEdge-2-req->gy) < buttonheight) return FALSE; ng.ng_LeftEdge=req->gx; ng.ng_TopEdge=req->gy; ng.ng_Width=req->gw; ng.ng_GadgetText=NULL, ng.ng_GadgetID=LISTVIEW; ng.ng_Flags=PLACETEXT_ABOVE; gad=CreateGadget(LISTVIEW_KIND,gad,&ng, GTLV_ScrollWidth,(fontwidth>8 ? fontwidth*2 : 18), GTLV_Labels, (ULONG) req->list, GTLV_ShowSelected,NULL, ((selected == ~0) || (GadToolsBase->lib_Version >= 39) ? TAG_IGNORE : GTLV_Top),selected, (selected == ~0 ? TAG_IGNORE : GTLV_MakeVisible),selected, GTLV_Selected,selected, TAG_DONE); req->listviewgadget=gad; // Save for HadleReq()... if(!gad) return FALSE; } else return FALSE; AddGList(req->Window,req->Gadgets,~0,-1,NULL); RefreshGList(req->Gadgets,req->Window,NULL,-1); GT_RefreshWindow(req->Window,NULL); return TRUE; }
BOOL get_string(UBYTE * buff, LONG max_len) { struct Gadget *g, *sg; struct NewGadget ng; struct Gadget *gl; struct Window *win; struct IntuiMessage *msg; struct StringInfo *strinfo; UWORD koodi, msgID; ULONG classi; APTR address; UWORD offy; BOOL quit, ok; g = CreateContext(&gl); if (!g) return FALSE; offy = scr->WBorTop + scr->RastPort.TxHeight + 1; ng.ng_TextAttr = &topaz8; ng.ng_VisualInfo = VisInfo; ng.ng_Flags = PLACETEXT_IN; ng.ng_LeftEdge = 14; ng.ng_TopEdge = offy + 34; ng.ng_Width = 90; ng.ng_Height = 15; ng.ng_GadgetText = (UBYTE *) "OK"; ng.ng_GadgetID = GAD_OK; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_LeftEdge = 246; ng.ng_TopEdge = offy + 34; ng.ng_GadgetText = (UBYTE *) "Cancel"; ng.ng_GadgetID = GAD_CANCEL; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_LeftEdge = 14; ng.ng_TopEdge = offy + 10; ng.ng_Width = 322; ng.ng_Height = 15; ng.ng_GadgetText = NULL; ng.ng_GadgetID = GAD_STRING; sg = CreateGadget(STRING_KIND, g, &ng, GTST_String, buff, GTST_MaxChars, max_len, TAG_DONE); strinfo = (struct StringInfo *) sg->SpecialInfo; ok = FALSE; newwindow.Title = "Amiga Disk File"; newwindow.Width = 350; newwindow.Height = 65; newwindow.FirstGadget = gl; newwindow.Screen = scr; newwindow.LeftEdge = scr->MouseX - (newwindow.Width / 2); if (newwindow.LeftEdge + newwindow.Width > scr->Width) newwindow.LeftEdge = scr->Width - newwindow.Width; newwindow.TopEdge = scr->MouseY - (newwindow.Height / 2); if (newwindow.TopEdge + newwindow.Height > scr->Height) newwindow.TopEdge = scr->Height - newwindow.Height; win = OpenWindow(&newwindow); if (win) { ActivateGadget(sg, win, NULL); quit = FALSE; while (!quit) { WaitPort(win->UserPort); while (msg = (struct IntuiMessage *) GT_GetIMsg(win->UserPort)) { classi = msg->Class; koodi = msg->Code; address = msg->IAddress; if (classi == IDCMP_GADGETUP) msgID = ((struct Gadget *) msg->IAddress)->GadgetID; else msgID = msg->Code; GT_ReplyIMsg((struct IntuiMessage *) msg); switch (classi) { case IDCMP_CLOSEWINDOW: quit = TRUE; break; case IDCMP_GADGETUP: switch (msgID) { case GAD_CANCEL: quit = TRUE; break; case GAD_OK: case GAD_STRING: strcpy(buff, strinfo->Buffer); quit = ok = TRUE; break; } break; default: break; } } } CloseWindow(win); } FreeGadgets(gl); return ok; }
struct Window *initWindow(void) { struct Window *win; gad[0] = CreateContext(&glist); ng.ng_LeftEdge = 8; ng.ng_TopEdge = fontheight+7; ng.ng_Width = 192; ng.ng_Height = 11*fontheight+4; ng.ng_VisualInfo = vi; ng.ng_TextAttr = scr->Font; ng.ng_GadgetText = NULL; ng.ng_UserData = NULL; ng.ng_GadgetID = 1; lvgad[0] = CreateGadget(LISTVIEW_KIND,gad[0],&ng,GTLV_Labels,&list[0],TAG_END); ng.ng_LeftEdge = 206; ng.ng_Width = 186; ng.ng_GadgetText = NULL; ng.ng_GadgetID++; lvgad[1] = CreateGadget(LISTVIEW_KIND,lvgad[0],&ng,GTLV_Labels,&list[1],TAG_END); ng.ng_TopEdge += ng.ng_Height+3; ng.ng_LeftEdge = 8; ng.ng_Height = fontheight+4; ng.ng_Width = TLn("New")+16; ng.ng_Flags = PLACETEXT_IN; ng.ng_GadgetText = "New"; ng.ng_GadgetID++; gad[0] = CreateGadget(BUTTON_KIND,lvgad[1],&ng,GA_Immediate,TRUE,TAG_END); ng.ng_LeftEdge += ng.ng_Width+6; ng.ng_Width = TLn("Copy")+16; ng.ng_GadgetText = "Copy"; ng.ng_GadgetID++; gad[1] = CreateGadget(BUTTON_KIND,gad[0],&ng,TAG_END); ng.ng_LeftEdge += ng.ng_Width+6; ng.ng_Width = TLn("Delete")+16; ng.ng_GadgetText = "Delete"; ng.ng_GadgetID++; gad[2] = CreateGadget(BUTTON_KIND,gad[1],&ng,TAG_END); if ((win = OpenWindowTags(NULL,WA_Title, "gtdrag - Test", WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE, WA_IDCMP, IDCMP_CLOSEWINDOW | DRAGIDCMP, WA_Width, 400, WA_Height, fontheight*13+23, WA_Gadgets, glist, TAG_END)) != 0) { GT_RefreshWindow(win,NULL); GTD_AddGadget(LISTVIEW_KIND,lvgad[0],win,GTDA_InternalType, 1, GTDA_NoPosition, TRUE, GTDA_Type, ODT_NODE, TAG_END); GTD_AddGadget(LISTVIEW_KIND,lvgad[1],win,GTDA_InternalType,1, GTDA_Same, TRUE, GTDA_Type, ODT_NODE, TAG_END); GTD_AddGadget(BUTTON_KIND,gad[0],win,GTDA_Object, &in, GTDA_Image, in.in_Image, GTDA_InternalType,2, GTDA_AcceptTypes, 0, GTDA_Width, newImg.Width, GTDA_Height, newImg.Height, TAG_END); GTD_AddGadget(BUTTON_KIND,gad[1],win,GTDA_AcceptTypes,1,TAG_END); GTD_AddGadget(BUTTON_KIND,gad[2],win,GTDA_AcceptTypes,1,TAG_END); GTD_AddWindow(win,TAG_END); return(win); } return(NULL); }
/***************************************** * Opens up the window & sets the gadgets * *****************************************/ int setup_window(void) { struct Gadget *g; struct NewGadget ng; UWORD offy; ULONG drawtags[20]; static const char *keyb_langs[] = { "US", "DE", "SE", "FR", "IT", NULL }; scr = LockPubScreen(NULL); if (!scr) return (0); VisInfo = GetVisualInfo(scr, TAG_DONE); if (!VisInfo) return (0); offy = scr->WBorTop + scr->RastPort.TxHeight + 1; /* Create buttons */ g = CreateContext(&glist); if (!g) return (0); ng.ng_TextAttr = &topaz8; ng.ng_VisualInfo = VisInfo; ng.ng_Flags = PLACETEXT_IN; ng.ng_LeftEdge = 284; ng.ng_TopEdge = offy + 86; ng.ng_Width = 96; ng.ng_Height = 15; ng.ng_GadgetText = (UBYTE *) "Hard Reset"; ng.ng_GadgetID = GAD_RESET; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 105; ng.ng_GadgetText = (UBYTE *) "Debug"; ng.ng_GadgetID = GAD_DEBUG; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 135; ng.ng_GadgetText = (UBYTE *) "Quit UAE"; ng.ng_GadgetID = GAD_EXITEMU; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); /* Eject buttons */ ng.ng_LeftEdge = 262; ng.ng_TopEdge = offy + 11; ng.ng_Width = 70; ng.ng_GadgetID = GAD_EJECT_DF0; ng.ng_GadgetText = (UBYTE *) "Eject"; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 28; ng.ng_GadgetID = GAD_EJECT_DF1; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 45; ng.ng_GadgetID = GAD_EJECT_DF2; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 62; ng.ng_GadgetID = GAD_EJECT_DF3; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); /* Insert buttons */ ng.ng_LeftEdge = 332; ng.ng_TopEdge = offy + 11; ng.ng_GadgetID = GAD_INSERT_DF0; ng.ng_GadgetText = (UBYTE *) "Insert"; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 28; ng.ng_GadgetID = GAD_INSERT_DF1; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 45; ng.ng_GadgetID = GAD_INSERT_DF2; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_TopEdge = offy + 62; ng.ng_GadgetID = GAD_INSERT_DF3; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); /* Sound & Joystick buttons */ ng.ng_LeftEdge = 133; ng.ng_TopEdge = 97; ng.ng_GadgetID = GAD_SOUND; ng.ng_GadgetText = (UBYTE *) "Sound:"; ng.ng_Flags = PLACETEXT_LEFT; g = CreateGadget(CHECKBOX_KIND, g, &ng, GTCB_Checked, config.do_output_sound ? 1 : 0, TAG_DONE); ng.ng_TopEdge = 114; ng.ng_GadgetID = GAD_JOYSTICK; ng.ng_GadgetText = (UBYTE *) "Fake Joystick:"; g = CreateGadget(CHECKBOX_KIND, g, &ng, GTCB_Checked, config.do_fake_joystick ? 1 : 0, TAG_DONE); ng.ng_TopEdge = 129; ng.ng_GadgetID = GAD_LANGUAGE; ng.ng_GadgetText = (UBYTE *) "Language:"; g = CreateGadget(CYCLE_KIND, g, &ng, GTCY_Labels, (ULONG) keyb_langs, GTCY_Active, config.keyboard, TAG_DONE); ng.ng_TopEdge = 146; ng.ng_GadgetID = GAD_FRAMERATE; ng.ng_GadgetText = (UBYTE *) "Framerate:"; g = CreateGadget(INTEGER_KIND, g, &ng, GTIN_Number, config.framerate, TAG_DONE); newwindow.Title = "UAE-Control"; newwindow.Width = 419; newwindow.Height = 171; newwindow.LeftEdge = 20; newwindow.TopEdge = 20; newwindow.FirstGadget = glist; newwindow.Screen = scr; /* Store screen ptr */ window = OpenWindow(&newwindow); if (!window) return (0); /* Draw texts etc... */ SetAPen(window->RPort, 1); SetDrMd(window->RPort, JAM2); Move(window->RPort, 19, offy + 11 + 10); Text(window->RPort, (UBYTE *) "DF0:", 4); Move(window->RPort, 19, offy + 28 + 10); Text(window->RPort, (UBYTE *) "DF1:", 4); Move(window->RPort, 19, offy + 45 + 10); Text(window->RPort, (UBYTE *) "DF2:", 4); Move(window->RPort, 19, offy + 62 + 10); Text(window->RPort, (UBYTE *) "DF3:", 4); drawtags[0] = GT_VisualInfo; drawtags[1] = (ULONG) VisInfo; drawtags[2] = GTBB_Recessed; drawtags[3] = 1; drawtags[4] = TAG_DONE; DrawBevelBoxA(window->RPort, 14, offy + 10, 390, 17, (struct TagItem *) &drawtags); DrawBevelBoxA(window->RPort, 14, offy + 27, 390, 17, (struct TagItem *) &drawtags); DrawBevelBoxA(window->RPort, 14, offy + 44, 390, 17, (struct TagItem *) &drawtags); DrawBevelBoxA(window->RPort, 14, offy + 61, 390, 17, (struct TagItem *) &drawtags); print_drive_status(); return (1); }