/* Listing 9 */ #include #include #include #include #include #include #include #include struct operacja { char *name; char key; void (*fun)(struct IntuiMessage*, struct Window*); }; char *names[]= { "JAM1", "JAM2", "COMPLEMENT", "JAM2 | COMPLEMENT", "INVERSID", "JAM2 | INVERSID", "COMPLEMENT | INVERSID", "JAM2 | COMPLEMENT | INVERSID" }; struct GfxBase *GfxBase; struct IntuitionBase *IntuitionBase; ULONG dajKolorA(struct RastPort*); ULONG dajKolorB(struct RastPort*); void linia(struct IntuiMessage*, struct Window*); void punkt(struct IntuiMessage*, struct Window*); void napis(struct IntuiMessage*, struct Window*); void drmd(struct IntuiMessage*, struct Window*); void color(struct IntuiMessage*, struct Window*); void kwadrat(struct IntuiMessage*, struct Window*); void elipsa(struct IntuiMessage*, struct Window*); struct operacja op_tab[]= { "Punkt - P", 'P', &punkt, "Color - C", 'C', &color, "Elipsa - E", 'E', &elipsa, "Kwadrat - K", 'K', &kwadrat, "Linia - L", 'L', &linia, "DrawMode - M", 'M', &drmd, "Napis - N",'N', &napis }; int main(int argc, char *argv[]) { check_os(OS_20); if (IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library", 37)) { if (GfxBase=(struct GfxBase*)OpenLibrary("graphics.library", 37)) { struct Window *window; short op_pos=0; if (window=OpenWindowTags(0, WA_Left, 10, WA_Top, 10, WA_Width, 610, WA_Height, 220, WA_Flags, WFLG_DRAGBAR | WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_REPORTMOUSE, WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_VANILLAKEY, WA_ScreenTitle, "Double-click na gadûecie zamykania zamyka okno", WA_Title, op_tab[op_pos].name, TAG_END)) { ULONG last_sec=0, last_micro=0; char koniec; for (koniec=0; !koniec;) { struct IntuiMessage *msg_ptr; WaitPort(window->UserPort); if (msg_ptr=(struct IntuiMessage*)GetMsg(window->UserPort)) { struct IntuiMessage msg; /* Wykonanie kopii */ #if __STDC__ msg=*msg_ptr; /* ANSI C */ #else CopyMem(msg_ptr, &msg, sizeof(struct IntuiMessage)); #endif ReplyMsg((struct Message*)msg_ptr); switch (msg.Class) { case IDCMP_VANILLAKEY: if (msg.Code==27) /* Kod znaku Esc */ koniec=1; else { short pom; for (pom=0; pomCode == SELECTDOWN) Draw(win->RPort, msg_ptr->MouseX, msg_ptr->MouseY); } void punkt(struct IntuiMessage *msg_ptr, struct Window *win) { if (msg_ptr->Code == SELECTDOWN) { WritePixel(win->RPort, msg_ptr->MouseX, msg_ptr->MouseY); Move(win->RPort, msg_ptr->MouseX, msg_ptr->MouseY); } } void napis(struct IntuiMessage *msg_ptr, struct Window *win) { char *tekst = "Przykîadowy napis"; if (msg_ptr->Code == SELECTDOWN) { Move(win->RPort, msg_ptr->MouseX, msg_ptr->MouseY); Text(win->RPort, tekst, strlen(tekst)); } } void drmd(struct IntuiMessage *msg_ptr, struct Window *win) { if (msg_ptr->Code == SELECTDOWN) { char pom; SetDrMd(win->RPort, pom = 7 & 1+(GfxBase->LibNode.lib_Version<39 ? win->RPort->DrawMode : GetDrMd(win->RPort))); SetWindowTitles(win, names[pom], (STRPTR)-1); } } void color(struct IntuiMessage *msg_ptr, struct Window *win) { switch (msg_ptr->Code) { case SELECTDOWN: SetAPen(win->RPort, dajKolorA(win->RPort)+1); break; case MENUDOWN: SetBPen(win->RPort, dajKolorB(win->RPort)+1); break; } } void kwadrat(struct IntuiMessage *msg_ptr, struct Window *win) { short xMin, xMax, yMin, yMax; if (msg_ptr->Code == SELECTDOWN) { xMin=(win->RPort->cp_xMouseX ? win->RPort->cp_x : msg_ptr->MouseX); xMax=(win->RPort->cp_x>msg_ptr->MouseX ? win->RPort->cp_x : msg_ptr->MouseX); yMin=(win->RPort->cp_yMouseY ? win->RPort->cp_y : msg_ptr->MouseY); yMax=(win->RPort->cp_y>msg_ptr->MouseY ? win->RPort->cp_y : msg_ptr->MouseY); RectFill(win->RPort, xMin, yMin, xMax, yMax); } } void elipsa(struct IntuiMessage *msg_ptr, struct Window *win) { short a, b; if (msg_ptr->Code == SELECTDOWN) { a=((a=win->RPort->cp_x-msg_ptr->MouseX)>0 ? a : -a); b=((b=win->RPort->cp_y-msg_ptr->MouseY)>0 ? b : -b); DrawEllipse(win->RPort, win->RPort->cp_x, win->RPort->cp_y, a, b); } } ULONG dajKolorA(struct RastPort *rp) { return (GfxBase->LibNode.lib_Version<39 ? rp->FgPen : GetAPen(rp)); } ULONG dajKolorB(struct RastPort *rp) { return (GfxBase->LibNode.lib_Version<39 ? rp->BgPen : GetBPen(rp)); }