Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
CodeWarrior (OS 9)/events.c
/* |
File: events.c |
Contains: |
Written by: Edgar Lee |
Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
7/13/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include "FX.h" |
void handleMouseDown(); |
void eventLoop() |
{ |
EventRecord event; |
WindowPtr window; |
short clickArea; |
Rect screenRect; |
long sleep = 30; |
Point point; |
for (;;) |
{ |
if (WaitNextEvent( everyEvent, &event, sleep, (RgnHandle)nil )) |
{ |
if (event.what == mouseDown) |
{ |
clickArea = FindWindow( event.where, &window ); |
if (clickArea == inDrag) |
{ |
//screenRect = (**GetGrayRgn()).rgnBBox; |
GetRegionBounds(GetGrayRgn(), &screenRect); |
DragWindow(window, event.where, &screenRect ); |
} |
else if (clickArea == inGoAway) |
{ |
if (TrackGoAway( window , event.where )) |
ExitToShell(); |
} |
else if (clickArea == inMenuBar) |
{ |
adjustMenus(); |
handleMenu( MenuSelect( event.where ) ); |
} |
else if (clickArea == inContent) |
{ |
if (window != FrontWindow()) |
SelectWindow( window ); |
else |
{ |
point = event.where; |
GlobalToLocal( &point ); |
handleMouseDown( point ); |
} |
} |
} |
else if (event.what == updateEvt) |
{ |
window = (WindowPtr)event.message; |
//SetPort( window ); |
SetPortWindowPort( window ); |
BeginUpdate( window ); |
updateWindow(); |
EndUpdate( window ); |
} |
else if (event.what == keyDown || event.what == autoKey) |
{ |
if ((event.modifiers & cmdKey) != 0) |
{ |
adjustMenus(); |
handleMenu( MenuKey( (char)(event.message & charCodeMask) ) ); |
} |
} |
} |
} |
} |
void handleMouseDown( Point point ) |
{ |
int i; |
long ticks; |
int itemNum = -1; |
Rect tempRect1, tempRect2; |
for (i = 0; i < numBItems; i++) |
if (PtInRect( point, &bItem[i].rect )) |
{ |
if (i == settings.bItem - 1) |
return; |
drawItem( bItem[settings.bItem - 1].rect.left, bItem[settings.bItem - 1].rect.top, |
&bItem[settings.bItem - 1].label, true, false ); |
drawItem( bItem[i].rect.left, bItem[i].rect.top, |
&bItem[i].label, true, true ); |
itemNum = 0; |
settings.bItem = i + 1; |
break; |
} |
if (gCurrentExample / 10 == transferID || gCurrentExample / 10 == customID) |
for (i = 0; i < numTItems && itemNum == -1; i++) |
if (PtInRect( point, &tItem[i].rect )) |
{ |
if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) |
{ |
drawItem( tItem[settings.tItem - 1].rect.left, tItem[settings.tItem - 1].rect.top, |
&tItem[settings.tItem - 1].label, true, false ); |
drawItem( tItem[i].rect.left, tItem[i].rect.top, |
&tItem[i].label, true, true ); |
itemNum = i + 1; |
settings.tItem = itemNum; |
} |
break; |
} |
if (gCurrentExample / 10 == arithmeticID || gCurrentExample / 10 == customID) |
for (i = 0; i < numAItems && itemNum == -1; i++) |
if (PtInRect( point, &aItem[i].rect )) |
{ |
if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) |
{ |
drawItem( aItem[settings.aItem - 1].rect.left, aItem[settings.aItem - 1].rect.top, |
&aItem[settings.aItem - 1].label, true, false ); |
drawItem( aItem[i].rect.left, aItem[i].rect.top, |
&aItem[i].label, true, true ); |
itemNum = i + 1; |
settings.aItem = itemNum; |
} |
break; |
} |
if (gCurrentExample / 10 == colorizationID || gCurrentExample / 10 == customID) |
for (i = 0; i < numCItems && itemNum == -1; i++) |
if (PtInRect( point, &cItem[i].rect )) |
{ |
if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) |
{ |
drawItem( cItem[settings.cItem - 1].rect.left, cItem[settings.cItem - 1].rect.top, |
&cItem[settings.cItem - 1].label, true, false ); |
drawItem( cItem[i].rect.left, cItem[i].rect.top, |
&cItem[i].label, true, true ); |
itemNum = i + 1; |
settings.cItem = itemNum; |
} |
break; |
} |
if (gCurrentExample / 10 == ditherID || gCurrentExample / 10 == customID) |
for (i = 0; i < numDItems && itemNum == -1; i++) |
if (PtInRect( point, &dItem[i].rect )) |
{ |
if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) |
{ |
drawItem( dItem[settings.dItem - 1].rect.left, dItem[settings.dItem - 1].rect.top, |
&dItem[settings.dItem - 1].label, true, false ); |
drawItem( dItem[i].rect.left, dItem[i].rect.top, |
&dItem[i].label, true, true ); |
itemNum = i + 1; |
settings.dItem = itemNum; |
} |
break; |
} |
if (gCurrentExample / 10 == searchProcID || gCurrentExample / 10 == customID) |
for (i = 0; i < numMItems && itemNum == -1; i++) |
if (PtInRect( point, &mItem[i].rect )) |
{ |
if (gCurrentExample % 10 != i + 1 || gCurrentExample / 10 == customID) |
{ |
drawItem( mItem[settings.mItem - 1].rect.left, mItem[settings.mItem - 1].rect.top, |
&mItem[settings.mItem - 1].label, true, false ); |
drawItem( mItem[i].rect.left, mItem[i].rect.top, |
&mItem[i].label, true, true ); |
itemNum = i + 1; |
settings.mItem = itemNum; |
} |
break; |
} |
if (gCurrentExample / 10 == paintBucketID) |
{ |
Rect rect; |
void paintBucketExample(); |
/*SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37, |
(*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom );*/ |
GetPortBounds(GetWindowPort(gWindow), &tempRect1); |
GetPortBounds(gGWorld, &tempRect2); |
SetRect( &rect, tempRect1.right - tempRect2.right - 20, 37, |
tempRect1.right - 20, 37 + tempRect2.bottom); |
paintBucketExample( &rect, 0, point ); |
} |
/* |
if (gCurrentExample / 10 == lassoID) |
{ |
Rect rect; |
Rect frame; |
void lassoToolExample(); |
frame.left = point.h; |
frame.top = point.v; |
while( StillDown() ) |
{ |
GetMouse( &point ); |
frame.right = point.h; |
frame.bottom = point.v; |
} |
SetRect( &rect, (*gWindow).portRect.right - (*gGWorld).portRect.right - 20, 37, |
(*gWindow).portRect.right - 20, 37 + (*gGWorld).portRect.bottom ); |
lassoToolExample( &rect, 0, &frame ); |
} |
*/ |
if (itemNum != -1) |
{ |
if (itemNum == 0) |
{ |
drawSourceImage(); |
ticks = drawFXImage(); |
drawTime( ticks ); |
} |
else |
{ |
if (gCurrentExample / 10 == customID) |
itemNum = gCurrentExample; |
else |
itemNum = ((gCurrentExample / 10) * 10) + itemNum; |
if (itemNum != gCurrentExample || itemNum / 10 == customID) |
{ |
gCurrentExample = itemNum; |
drawSourceImage(); |
ticks = drawFXImage(); |
drawTime( ticks ); |
} |
} |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-10-27