static void vsid_update_text(void) { int i; vsid_clear_window(); for (i = 0; i < VSID_S_LASTLINE; i++) { PrintIText(vsid_window->RPort, &vsid_text[i], 0, 0); } }
WORD drawtext(struct Window *win, WORD x, WORD y, char *fmt, ...) { va_list args; char buf[256]; struct IntuiText it = { 1, 0, JAM2, 0, 0, NULL, buf, NULL }; va_start(args, fmt); vsprintf(buf, fmt, args); va_end(args); PrintIText(win->RPort, &it, x, y); return y + win->IFont->tf_YSize; }
/* render a standard requester */ void render_requester(struct Requester *requester, struct IntuitionBase *IntuitionBase) { struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase; struct RastPort *rp = requester->ReqLayer->rp; if ((requester->Flags & NOREQBACKFILL) == 0) SetRast(rp, requester->BackFill); if (requester->ImageBMap && requester->Flags & PREDRAWN) BltBitMapRastPort(requester->ImageBMap, 0, 0, rp, 0, 0, requester->Width, requester->Height, 0xc0); if (requester->ReqImage && requester->Flags & USEREQIMAGE) DrawImage(rp, requester->ReqImage, 0, 0); if (requester->ReqBorder) DrawBorder(rp, requester->ReqBorder, 0, 0); if (requester->ReqGadget) RefreshGList(requester->ReqGadget, requester->RWindow, requester, -1); if (requester->ReqText) PrintIText(rp, requester->ReqText, 0, 0); }
void EditColor() { extern const char *configfile; int i, done = 0, okay = 0; long code, qual, class; register struct Gadget *gd, *dgad; register struct Window *nw; register struct IntuiMessage *imsg; register struct PropInfo *pip; register struct Screen *scrn; long aidx; int msx, msy; int curcol = 0, drag = 0; int bxorx, bxory, bxxlen, bxylen; static UWORD colors[AMII_MAXCOLORS]; static UWORD svcolors[AMII_MAXCOLORS]; static int once = 0; scrn = HackScreen; if (!once) { if (WINVERS_AMIV) { Col_NewWindowStructure1.Width += 300; Col_NewWindowStructure1.Height += 20; Col_NewWindowStructure1.LeftEdge -= 150; Col_BluePen.Width += 300; Col_RedPen.Width += 300; Col_GreenPen.Width += 300; Col_Cancel.LeftEdge += 300; Col_Okay.LeftEdge += 150; Col_Cancel.TopEdge += 20; Col_Save.TopEdge += 20; Col_Okay.TopEdge += 20; } SetBorder(&Col_Okay); SetBorder(&Col_Cancel); SetBorder(&Col_Save); once = 1; } bxylen = Col_NewWindowStructure1.Height - (Col_BluePen.TopEdge + Col_BluePen.Height + 6); bxxlen = Col_BluePen.Width; bxorx = Col_BluePen.LeftEdge; bxory = Col_BluePen.TopEdge + Col_BluePen.Height + 2; /* Save the current colors */ for (i = 0; i < amii_numcolors; ++i) svcolors[i] = colors[i] = GetRGB4(scrn->ViewPort.ColorMap, i); Col_NewWindowStructure1.Screen = scrn; #ifdef INTUI_NEW_LOOK if (IntuitionBase->LibNode.lib_Version >= 37) { ((struct PropInfo *) Col_BluePen.SpecialInfo)->Flags |= PROPNEWLOOK; ((struct PropInfo *) Col_RedPen.SpecialInfo)->Flags |= PROPNEWLOOK; ((struct PropInfo *) Col_GreenPen.SpecialInfo)->Flags |= PROPNEWLOOK; } #endif if (WINVERS_AMIV || WINVERS_AMII) { #ifdef INTUI_NEW_LOOK Col_NewWindowStructure1.Extension = wintags; Col_NewWindowStructure1.Flags |= WFLG_NW_EXTENDED; #ifdef __GNUC__ fillhook.h_Entry = (void *) &LayerFillHook; #else fillhook.h_Entry = (ULONG (*) ()) LayerFillHook; #endif fillhook.h_Data = (void *) -2; fillhook.h_SubEntry = 0; #endif } nw = OpenWindow((void *) &Col_NewWindowStructure1); if (nw == NULL) { DisplayBeep(NULL); return; } PrintIText(nw->RPort, &Col_IntuiTextList1, 0, 0); ClearCol(nw); DrawCol(nw, curcol, colors); while (!done) { WaitPort(nw->UserPort); while (imsg = (struct IntuiMessage *) GetMsg(nw->UserPort)) { gd = (struct Gadget *) imsg->IAddress; code = imsg->Code; class = imsg->Class; qual = imsg->Qualifier; msx = imsg->MouseX; msy = imsg->MouseY; ReplyMsg((struct Message *) imsg); switch (class) { case VANILLAKEY: if (code == 'v' && qual == AMIGALEFT) okay = done = 1; else if (code == 'b' && qual == AMIGALEFT) okay = 0, done = 1; else if (code == 'o' || code == 'O') okay = done = 1; else if (code == 'c' || code == 'C') okay = 0, done = 1; break; case CLOSEWINDOW: done = 1; break; case GADGETUP: drag = 0; if (gd->GadgetID == GADREDPEN || gd->GadgetID == GADBLUEPEN || gd->GadgetID == GADGREENPEN) { pip = (struct PropInfo *) gd->SpecialInfo; aidx = pip->HorizPot / (MAXPOT / 15); if (gd->GadgetID == GADREDPEN) { colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (gd->GadgetID == GADBLUEPEN) { colors[curcol] = (colors[curcol] & ~0xf) | aidx; LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (gd->GadgetID == GADGREENPEN) { colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } DispCol(nw, curcol, colors); } else if (gd->GadgetID == GADCOLOKAY) { done = 1; okay = 1; } else if (gd->GadgetID == GADCOLSAVE) { FILE *fp, *nfp; char buf[300], nname[300], oname[300]; int once = 0; fp = fopen(configfile, "r"); if (!fp) { pline("can't find NetHack.cnf"); break; } strcpy(oname, dirname((char *) configfile)); if (oname[strlen(oname) - 1] != ':') { sprintf(nname, "%s/New_NetHack.cnf", oname); strcat(oname, "/"); strcat(oname, "Old_NetHack.cnf"); } else { sprintf(nname, "%sNew_NetHack.cnf", oname); strcat(oname, "Old_NetHack.cnf"); } nfp = fopen(nname, "w"); if (!nfp) { pline("can't write to New_NetHack.cnf"); fclose(fp); break; } while (fgets(buf, sizeof(buf), fp)) { if (strncmp(buf, "PENS=", 5) == 0) { once = 1; fputs("PENS=", nfp); for (i = 0; i < amii_numcolors; ++i) { fprintf(nfp, "%03x", colors[i]); if ((i + 1) < amii_numcolors) putc('/', nfp); } putc('\n', nfp); } else { fputs(buf, nfp); } } /* If none in the file yet, now write it */ if (!once) { fputs("PENS=", nfp); for (i = 0; i < amii_numcolors; ++i) { fprintf(nfp, "%03x", colors[i]); if ((i + 1) < amii_numcolors) putc(',', nfp); } putc('\n', nfp); } fclose(fp); fclose(nfp); unlink(oname); if (filecopy((char *) configfile, oname) == 0) if (filecopy(nname, (char *) configfile) == 0) unlink(nname); done = 1; okay = 1; } else if (gd->GadgetID == GADCOLCANCEL) { done = 1; okay = 0; } break; case GADGETDOWN: drag = 1; dgad = gd; break; case MOUSEMOVE: if (!drag) break; pip = (struct PropInfo *) dgad->SpecialInfo; aidx = pip->HorizPot / (MAXPOT / 15); if (dgad->GadgetID == GADREDPEN) { colors[curcol] = (colors[curcol] & ~0xf00) | (aidx << 8); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (dgad->GadgetID == GADBLUEPEN) { colors[curcol] = (colors[curcol] & ~0xf) | aidx; LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } else if (dgad->GadgetID == GADGREENPEN) { colors[curcol] = (colors[curcol] & ~0x0f0) | (aidx << 4); LoadRGB4(&scrn->ViewPort, colors, amii_numcolors); } DispCol(nw, curcol, colors); break; case MOUSEBUTTONS: if (code == SELECTDOWN) { if (msy > bxory && msy < bxory + bxylen - 1 && msx > bxorx && msx < bxorx + bxxlen - 1) { curcol = (msx - bxorx) / (bxxlen / amii_numcolors); if (curcol >= 0 && curcol < amii_numcolors) DrawCol(nw, curcol, colors); } } break; } } } if (okay) { for (i = 0; i < (amii_numcolors); ++i) sysflags.amii_curmap[i] = colors[i]; LoadRGB4(&scrn->ViewPort, sysflags.amii_curmap, amii_numcolors); } else LoadRGB4(&scrn->ViewPort, svcolors, amii_numcolors); CloseWindow(nw); }
/* ** main routine. Open required library and window and draw the images. ** This routine opens a very simple window with no IDCMP. See the ** chapters on "Windows" and "Input and Output Methods" for more info. ** Free all resources when done. */ int main(int argc, char **argv) { struct Screen *screen; struct DrawInfo *drawinfo; struct Window *win; struct IntuiText myIText; struct TextAttr myTextAttr; ULONG myTEXTPEN; ULONG myBACKGROUNDPEN; IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37); if (IntuitionBase) { #ifdef __AROS__ if ((screen = LockPubScreen(NULL))) #else if (screen = LockPubScreen(NULL)) #endif { #ifdef __AROS__ if ((drawinfo = GetScreenDrawInfo(screen))) #else if (drawinfo = GetScreenDrawInfo(screen)) #endif { /* Get a copy of the correct pens for the screen. ** This is very important in case the user or the ** application has the pens set in a unusual way. */ myTEXTPEN = drawinfo->dri_Pens[TEXTPEN]; myBACKGROUNDPEN = drawinfo->dri_Pens[BACKGROUNDPEN]; /* create a TextAttr that matches the specified font. */ myTextAttr.ta_Name = drawinfo->dri_Font->tf_Message.mn_Node.ln_Name; myTextAttr.ta_YSize = drawinfo->dri_Font->tf_YSize; myTextAttr.ta_Style = drawinfo->dri_Font->tf_Style; myTextAttr.ta_Flags = drawinfo->dri_Font->tf_Flags; /* open a simple window on the workbench screen for displaying ** a text string. An application would probably never use such a ** window, but it is useful for demonstrating graphics... */ #ifdef __AROS__ if ((win = OpenWindowTags(NULL, WA_PubScreen, (IPTR)screen, WA_RMBTrap, TRUE, WA_IDCMP, IDCMP_RAWKEY, TAG_END))) #else if (win = OpenWindowTags(NULL, WA_PubScreen, screen, WA_RMBTrap, TRUE, TAG_END)) #endif { myIText.FrontPen = myTEXTPEN; myIText.BackPen = myBACKGROUNDPEN; myIText.DrawMode = JAM2; myIText.LeftEdge = MYTEXT_LEFT; myIText.TopEdge = MYTEXT_TOP; myIText.ITextFont = &myTextAttr; myIText.IText = "Hello, World. ;-)"; myIText.NextText = NULL; /* Draw the text string at 10,10 */ PrintIText(win->RPort,&myIText,10,10); #ifdef __AROS__ /* Wait for keypress */ Wait (1L << win->UserPort->mp_SigBit); #else /* Wait a bit, then quit. ** In a real application, this would be an event loop, ** like the one described in the Intuition Input and ** Output Methods chapter. */ Delay(200); #endif CloseWindow(win); } FreeScreenDrawInfo(screen,drawinfo); } UnlockPubScreen(NULL,screen); } CloseLibrary((struct Library *)IntuitionBase); } return 0; }