mirror of
https://github.com/PascalHarris/Mandy.git
synced 2024-12-10 00:49:37 +00:00
Add files via upload
This commit is contained in:
commit
0a88bcecae
1
MandyWindow.c
Normal file
1
MandyWindow.c
Normal file
@ -0,0 +1 @@
|
||||
/*****
* MandyWindow.c
*
* A simple fractal generator
*
*
*****/
#include "mwMenus.h"
#include "mwWindow.h"
extern WindowPtr mwWindow;
extern Rect dragRect;
void InitMacintosh(void);
void HandleMouseDown (EventRecord *theEvent);
void HandleEvent(void);
/* InitMacintosh()
Initialize all the managers & memory */
void InitMacintosh(void) {
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
}
void HandleMouseDown (EventRecord *theEvent) {
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode) {
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
AdjustMenus();
HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
if (theWindow == mwWindow)
DragWindow(mwWindow, theEvent->where, &dragRect);
break;
case inContent:
if (theWindow == mwWindow) {
if (theWindow != FrontWindow())
SelectWindow(mwWindow);
else
InvalRect(&mwWindow->portRect);
}
break;
case inGoAway:
if (theWindow == mwWindow &&
TrackGoAway(mwWindow, theEvent->where))
HideWindow(mwWindow);
break;
}
}
void HandleEvent(void) {
int ok;
EventRecord theEvent;
HiliteMenu(0);
SystemTask (); /* Handle desk accessories */
ok = GetNextEvent (everyEvent, &theEvent);
if (ok) {
switch (theEvent.what) {
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0) {
AdjustMenus();
HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
}
break;
case updateEvt:
BeginUpdate(mwWindow);
DrawContent(((WindowPeek) mwWindow)->hilited);
EndUpdate(mwWindow);
break;
case activateEvt:
InvalRect(&mwWindow->portRect);
break;
}
}
}
void main(void) {
InitMacintosh();
SetUpMenus();
SetUpWindow();
for (;;) {
HandleEvent();
}
}
|
1
mwMenus.c
Normal file
1
mwMenus.c
Normal file
@ -0,0 +1 @@
|
||||
/*****
* mwMenus.c
*
* Routines for Mandy Fractal Generator menus.
*
*****/
#include "mwMenus.h"
extern WindowPtr mwWindow;
extern int width;
MenuHandle appleMenu, fileMenu, editMenu, fractalMenu;
enum {
appleID = 1,
fileID,
editID,
fractalID
};
enum {
openItem = 1,
closeItem,
quitItem = 4
};
/* SetUpMenus()
Set up the menus. Normally, weÕd use a resource file, but
for this example weÕll supply ÒhardwiredÓ strings. */
void SetUpMenus(void) {
InsertMenu(appleMenu = NewMenu(appleID, "\p\024"), 0);
InsertMenu(fileMenu = NewMenu(fileID, "\pFile"), 0);
InsertMenu(editMenu = NewMenu(editID, "\pEdit"), 0);
InsertMenu(fractalMenu = NewMenu(fractalID, "\pFractal"), 0);
DrawMenuBar();
AddResMenu(appleMenu, 'DRVR');
AppendMenu(fileMenu, "\pOpen/O;Close/W;(-;Quit/Q");
AppendMenu(editMenu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
AppendMenu(fractalMenu, "\pTree/T;Mandelbrot/M;Julia/J");
}
/* AdjustMenus()
Enable or disable the items in the Edit menu if a DA window
comes up or goes away. Our application doesn't do anything with
the Edit menu. */
static void enable (MenuHandle menu, short item, short ok);
void AdjustMenus(void) {
register WindowPeek wp = (WindowPeek) FrontWindow();
short kind = wp ? wp->windowKind : 0;
Boolean DA = kind < 0;
enable(editMenu, 1, DA);
enable(editMenu, 3, DA);
enable(editMenu, 4, DA);
enable(editMenu, 5, DA);
enable(editMenu, 6, DA);
enable(fileMenu, openItem, !((WindowPeek) mwWindow)->visible);
enable(fileMenu, closeItem, DA || ((WindowPeek) mwWindow)->visible);
// CheckItem(widthMenu, width, true);
}
static
void enable(MenuHandle menu, short item, short ok) {
if (ok)
EnableItem(menu, item);
else
DisableItem(menu, item);
}
/* HandleMenu(mSelect)
Handle the menu selection. mSelect is what MenuSelect() and
MenuKey() return: the high word is the menu ID, the low word
is the menu item */
void HandleMenu (long mSelect) {
int menuID = HiWord(mSelect);
int menuItem = LoWord(mSelect);
Str255 name;
GrafPtr savePort;
WindowPeek frontWindow;
switch (menuID) {
case appleID:
GetPort(&savePort);
GetItem(appleMenu, menuItem, name);
OpenDeskAcc(name);
SetPort(savePort);
break;
case fileID:
switch (menuItem) {
case openItem:
ShowWindow(mwWindow);
SelectWindow(mwWindow);
break;
case closeItem:
if ((frontWindow = (WindowPeek) FrontWindow()) == 0L)
break;
if (frontWindow->windowKind < 0)
CloseDeskAcc(frontWindow->windowKind);
else if ((frontWindow = (WindowPeek) mwWindow) != NULL)
HideWindow(mwWindow);
break;
case quitItem:
ExitToShell();
break;
}
break;
case editID:
if (!SystemEdit(menuItem-1))
SysBeep(5);
break;
case fractalID:
CheckItem(fractalMenu, width, false);
width = menuItem;
InvalRect(&mwWindow->portRect);
break;
}
}
|
1
mwMenus.h
Normal file
1
mwMenus.h
Normal file
@ -0,0 +1 @@
|
||||
/*****
* mwMenus.h
*
* Public interfaces for mwMenus.h
*
****/
void AdjustMenus(void);
void HandleMenu (long mSelect);
void SetUpMenus(void);
|
1
mwWindow.c
Normal file
1
mwWindow.c
Normal file
File diff suppressed because one or more lines are too long
1
mwWindow.h
Normal file
1
mwWindow.h
Normal file
@ -0,0 +1 @@
|
||||
/*****
* mwWindow.h
*
* Public interfaces for mwWindow.c
*
*****/
void DrawContent (short active);
void SetUpWindow(void);
|
Loading…
Reference in New Issue
Block a user