#ifdef powerc #define round(x) rint(x) #else #define round(x) floor(x) #endif #define ubyte unsigned char #define ulong unsigned long #define ushort unsigned short #define Double float #define MAX_start 2.7 #define MAX_end 4.0 #define MAX_top 1.0 #define MAX_bottom 0.0 #define PRE_ITERS 1000 #define PLOT_ITERS 400 #include /* All the basic stuff */ #include #include #include #include #include struct ezGWorld { CGrafPtr frontPort; GWorldPtr backPort; GDHandle frontDev; GDHandle backDev; Rect frontRect; Rect backRect; }; typedef struct ezGWorld ezGWorld; const Pattern patt[2] = {0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0x0000, 0x5555, 0x0000, 0x5555, 0x0000, 0x5555, 0x0000, 0x5555}; /*****************************/ /* P R O T O T Y P E S */ /*****************************/ void ErrHndl(OSErr), SetupStuff(); void DrawIt(Double start_v, Double end_v, Double bottom_v, Double top_v, Rect window_r ); void MainEventLoop(long time); void DoClick(), DoClickInContent(), DoMenu(long), DoKey(), DoUpdate(), DoActivate(); //GW Protos void ezSetupGW(ezGWorld *mgw, Rect *r); void ezUpdateGW(ezGWorld *mgw); void ezCleanupGW(ezGWorld *mgw); char Done; char CancelKey = false; char Im_Drawing = false; WindowRef MainWP; Double start, end, bottom, top, Aspect; ulong Pre_Iters, Plot_Iters; void main() { GrafPtr OldPtr; Rect r; start = MAX_start; end = MAX_end; bottom = MAX_bottom; top = MAX_top; Pre_Iters = PRE_ITERS; Plot_Iters = PLOT_ITERS; SetupStuff(); GetPort(&OldPtr); MainWP = GetNewCWindow(128, nil, nil); r = OldPtr->portRect; //MoveWindow(MainWp, r.left, r.top, false); SizeWindow(MainWP, r.right - r.left, r.bottom - (r.top+GetMBarHeight()), false); ShowWindow(MainWP); r = MainWP->portRect; Aspect = (Double) (r.bottom - r.top) / (Double) (r.right - r.left); SetPort( (GrafPtr) MainWP); DrawIt(start, end, bottom, top, r); do {MainEventLoop(700L);} while (!Done); CloseWindow(MainWP); SetPort(OldPtr); ExitToShell(); } void MainEventLoop(long time) { EventRecord event; long int myMask; Boolean eventOccured; CancelKey = false; myMask = everyEvent & (!mUpMask | !keyUpMask | !diskMask); myMask = mDownMask | keyDownMask | autoKeyMask | updateMask | activMask | osMask; eventOccured = WaitNextEvent(everyEvent, &event, time, nil); if(eventOccured) { switch(event.what) { case nullEvent: break; case mouseDown: DoClick(&event); break; case mouseUp: break; case keyDown: DoKey(&event); break; case keyUp: break; case autoKey: DoKey(&event); break; case updateEvt: DoUpdate(&event); break; case diskEvt: break; case activateEvt: DoActivate(&event); break; case networkEvt: break; case driverEvt: break; case app1Evt: break; case app2Evt: break; case app3Evt: break; case osEvt: //PlayNote(90, 1); PlayNote(92, 1); PlayNote(94, 1); //if( (event.message >> 24) == suspendResumeMessage) // BackgroundFlag = !(event.message & resumeFlag); break; default: break; } } } void DoClick(EventRecord *evt) { WindowPtr theWindow; if (IsDialogEvent(evt)) { return; } switch(FindWindow(evt->where, &theWindow)) { case inDesk: break; case inMenuBar: DoMenu(MenuSelect(evt->where)); break; case inSysWindow: SystemClick(evt,theWindow); break; case inContent: if (theWindow != FrontWindow()) { SelectWindow(theWindow); } else { DoClickInContent(evt,theWindow); } break; case inDrag: break; case inGrow: break; case inGoAway: break; case inZoomIn: break; case inZoomOut: break; default: break; } } void DoClickInContent(EventRecord *evt, WindowPtr theWindow) { Point pt, ppt; Rect r, r2; Double ph, pv, tmpA, tmpB, mid; char flagg; if (Im_Drawing) { PostEvent(evt->what, (UInt32)evt); CancelKey = true; return; } SetPort(theWindow); pt = evt->where; GlobalToLocal(&pt); r.left = r.right = pt.h; r.top = r.bottom = pt.v; flagg = 0; PenMode(srcXor); do { EventRecord event; flagg = (flagg)? 0 : 1; PenPat(&(patt[flagg])); if (r.right != r.left && r.top != r.bottom) FrameRect(&r); WaitNextEvent(everyEvent, &event, (long int)7200, nil); GetMouse(&ppt); if (r.right != r.left && r.top != r.bottom) FrameRect(&r); if (ppt.h > r.left) { r.right = ppt.h; r.left = pt.h; } else { r.left = ppt.h; r.right = pt.h; } if (ppt.v > r.top) { r.bottom = ppt.v; r.top = pt.v;} else { r.top = ppt.v; r.bottom = pt.v; } } while (StillDown()); PenNormal(); r2 = theWindow->portRect; ph = (end - start) / (Double) (r2.right - r2.left); pv = (top - bottom) / (Double) (r2.bottom - r2.top); tmpA = (end - start) / (top - bottom); end = start + (Double) (r.right - r2.left) * ph; start += (Double) (r.left - r2.left) * ph; top = bottom + (Double) (r2.bottom - r.top) * pv; bottom += (Double) ( r2.bottom - r.bottom) * pv; tmpB = (end - start) / (top - bottom); if (tmpA>tmpB) { mid = (top+bottom)/2.0; top = mid + (end - start) / (2.0*tmpA); bottom = mid - (end - start) / (2.0*tmpA); } else { mid = (start+end)/2.0; end = mid + (top - bottom) * tmpA / 2.0; start = mid - (top - bottom) * tmpA / 2.0; } if (end > MAX_end) end = MAX_end; if (top > MAX_top) top = MAX_top; DrawIt(start, end, bottom, top, r2); } void DoMenu(long msel) { short item, menu; item = LoWord(msel); menu = HiWord(msel); if(menu != 0) { switch(menu) { case 128: // Apple Menu if(item == 1) { item = Alert(128,nil); } else { GrafPtr savePort; short daRefNum; Str255 daName; GetPort(&savePort); GetItem(GetMHandle(128), item, daName); daRefNum = OpenDeskAcc(daName); SetPort(savePort); } break; case 129: // File Menu switch (item) { case 1: CancelKey = true; Done++; break; case 2: break; default: break; } break; case 130: // Control Menu switch (item) { case 1: // Reset start = MAX_start; end = MAX_end; bottom = MAX_bottom; top = MAX_top; Pre_Iters = PRE_ITERS; Plot_Iters = PLOT_ITERS; DrawIt(start, end, bottom, top, MainWP->portRect); break; case 2: // Separator break; case 3: // Increase Pre_Iters Pre_Iters += 100; break; case 4: if (Pre_Iters >= 100) Pre_Iters -= 100; break; case 5: // Separator break; case 6: Plot_Iters += 100; break; case 7: if (Plot_Iters >= 100) Plot_Iters -= 100; break; case 8: // Separator break; case 9: // Redraw DrawIt(start, end, bottom, top, MainWP->portRect); break; default: break; } break; default: break; } } } void DoKey(EventRecord *evt) { char c; c = (char) evt->message & charCodeMask; if( (evt->modifiers & cmdKey) == FALSE) { switch (c) { default: break; } } else { if (c == '.') CancelKey = true; else DoMenu(MenuKey(evt->message & charCodeMask)); HiliteMenu(0); /* remove menu title hiliting */ } } void DoUpdate(EventRecord *evt) { if (IsDialogEvent(evt)) { } } void DoActivate(EventRecord *evt) { if (IsDialogEvent(evt)) { } } #define WAIT_HOW_LONG 45 void DrawIt(Double start_v, Double end_v, Double bottom_v, Double top_v, Rect window_r ) { Double mu, step, v_scale; register Double x; ulong N, M; register ulong i, j; short h, w, xx, yy; ulong Tickss; char *points, *pp; ezGWorld ezGW; Im_Drawing = true; N = Pre_Iters; // Number of Iterations until plot M = Plot_Iters; // Number of plots Tickss = TickCount(); // reference for updates w = window_r.right - window_r.left; h = window_r.bottom - window_r.top; points = (char *) NewPtrClear(h); mu = start_v; step = (end_v - start_v) / (Double)w; v_scale = (top_v - bottom_v) / (Double)h; ezSetupGW(&ezGW, &window_r); // Setup GWorld for (j=0; j WAIT_HOW_LONG) { ezUpdateGW(&ezGW); MainEventLoop(10L); Tickss = TickCount(); } x = 0.4; // Initail value xx = j; for (i=0; i0 && yybackRect.left = 0; // create new back window dimensions mgw->backRect.right = r->right - r->left; mgw->backRect.top = 0; mgw->backRect.bottom = r->bottom - r->top; mgw->frontRect.left = r->left; // remember current window dimaensions mgw->frontRect.right = r->right; mgw->frontRect.top = r->top; mgw->frontRect.bottom = r->bottom; mgw->frontPort = oldPtr; // remember current port mgw->frontDev = oldDev; mgw->backDev = oldDev; ErrHndl( NewGWorld(&GW, nil, &(mgw->backRect), nil, nil, nil) ); // create GW mgw->backPort = GW; LockPixels(GetGWorldPixMap(GW)); SetGWorld( mgw->backPort, mgw->backDev); // remember GW EraseRect(&(mgw->backRect)); // clear for drawing } void ezUpdateGW(ezGWorld *mgw) { CopyBits( (BitMapPtr)*(mgw->backPort->portPixMap), (BitMapPtr)*(mgw->frontPort->portPixMap), &(mgw->backRect), &(mgw->frontRect), srcCopy, nil); } void ezCleanupGW(ezGWorld *mgw) { SetGWorld( mgw->frontPort, mgw->frontDev); UnlockPixels(GetGWorldPixMap(mgw->backPort)); DisposeGWorld(mgw->backPort); } void ErrHndl(OSErr e) { Str255 s; if (e == 0) return; NumToString((short)e, s); ParamText(s, nil, nil, nil); Alert(128, nil); } void SetupStuff() { Handle Hand; // Get as much memory as possible MaxApplZone(); MoreMasters(); // Test the computer to be sure we can do color. // If not we would crash, which would be bad. // If we can't run, just beep and exit. InitGraf(&qd.thePort); // initialize QuickDraw InitWindows(); // initialize Window Manager InitCursor(); // initialize the Cursor control //InitCursorCtl(); // initialize animated cursor // Splash screen /* GetPort(&origPort); Wind = GetNewCWindow(300, NIL, (WindowPtr)-1); SetPort(Wind); Pic = GetPicture(300); HLock((Handle)Pic); r = (**Pic).picFrame; ShowWindow(Wind); DrawPicture(Pic, &r); HUnlock((Handle)Pic); ReleaseResource( (Handle)Pic);*/ InitFonts(); // initialize Font Manager InitCursor(); // initialize the cursor to an arrow InitDialogs(nil); // initialize the Dialog Manager GetDateTime( (unsigned long *)&qd.randSeed); // Setup my menus InitMenus(); Hand = GetNewMBar(128); if (Hand == nil) ExitToShell(); SetMenuBar(Hand); DisposeHandle(Hand); AppendResMenu(GetMenuHandle(128), 'DRVR'); DrawMenuBar(); //InsertMenu(GetMenu(2), -1); //InsertMenu(GetMenu(3), -1); //InsertMenu(GetMenu(4), -1); FlushEvents(everyEvent, everyEvent); Done = false; //DisposeWindow(Wind); }