⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapper.c

📁 CD_高级PALM编程
💻 C
📖 第 1 页 / 共 2 页
字号:
	// Save the new origin and redraw the map.	panInfoP->mapOrigin.x = newX;	panInfoP->mapOrigin.y = newY;	 	MainFormDraw( frmP );	}/*********************************************************************** * FUNCTION:    	MainFormDoMenuCommand * * DESCRIPTION: 	This routine handles menu commands. * * RETURNED:    	nothing ***********************************************************************/ static Boolean MainFormDoMenuCommand(	UInt16 	command			// The ID of menu command to do){	Boolean handled = false;	FormPtr frmP;	switch ( command )	{		case MainOptionsAboutMapper:					MenuEraseStatus ( 0 );			frmP = FrmInitForm ( AboutForm );			FrmDoDialog ( frmP );			FrmDeleteForm ( frmP );			handled = true;			break;	}	return handled;}/*********************************************************************** * FUNCTION:    	MainFormPOI * * DESCRIPTION: 	This routine handles map taps * * RETURNED:    	nothing ***********************************************************************/static int MainFormPOI( 	PointType *mapPointP,	TPanllInfoTypePtr panInfoP ){	int poiIdx = -1;	RectangleType hitRect;	int i;	TMapPOILayerItemPtr poiP;		// Only look for a POI if the POI layer is on.	if ( panInfoP->layerP )	{// Initialize the target rectangle.		RctSetRectangle ( &hitRect, mapPointP->x-mapHitRadius, 			mapPointP->y-mapHitRadius, 			2*mapHitRadius, 			2*mapHitRadius );// Search for a POI around the tap point.// NB: If a layer has lots of POIs, this is best done with a binary search// using SysBinarySearch. However, for only a handful of POI's (up to around// fifty or one hundred), a good old linear search is fine.// Another optimization: only search POI's known to be on the screen.		for ( i = 0; i < panInfoP->layerP->count; i++ )		{					poiP = (TMapPOILayerItemPtr)&panInfoP->layerP->layerDataPtr[i];			if ( RctPtInRectangle( poiP->pos.x, poiP->pos.y, &hitRect ) )			{				poiIdx = i;			}		}	}		return poiIdx;}/*********************************************************************** * FUNCTION:    	MainFormDoTap * * DESCRIPTION: 	This routine handles map taps * * RETURNED:    	nothing ***********************************************************************/static void MainFormDoMapTap( 	FormType *frmP,	Coord x, Coord y // (in) point on which tap occurred){	TPanllInfoTypePtr panInfoP;	PointType *mapPointP, screenPoint;	int poiIdx;	panInfoP = FrmGetGadgetData ( frmP, 			FrmGetObjectIndex ( frmP, MainMapGadget ) );// Convert tap window-relative coordinates to map-relative coords.	screenPoint.x = x ;	screenPoint.y = y ;	mapPointP = TapCoordToMapCoord( &screenPoint, &panInfoP->mapOrigin, &mapGadgetRect );// Check to see if it's over a POI.	poiIdx = MainFormPOI( mapPointP, panInfoP );	if ( poiIdx > -1  )	{		TMapPOILayerItemPtr poiP;		poiP = (TMapPOILayerItemPtr)&panInfoP->layerP->layerDataPtr[poiIdx];		StrCopy( panInfoP->layerLabelP, poiP->label );		panInfoP->layerPOICoord.x = poiP->pos.x;		panInfoP->layerPOICoord.y = poiP->pos.y;	}	else	{// Nope. Clear the label and zoom.		MemSet( panInfoP->layerLabelP, sizeof( TMapLabel ), 0 );		panInfoP->layerPOICoord.x = panInfoP->layerPOICoord.y = 0;		MainFormZoom( mapPointP, panInfoP );	}	MainFormDraw( frmP );}/*********************************************************************** * FUNCTION:    	MainFormZoom * * DESCRIPTION: 	This routine zooms the map to the opposite state. * * RETURNED:    	nothing ***********************************************************************/static void MainFormZoom(	PointType *mapPointP,	TPanllInfoTypePtr panInfoP ){	Err anErr;// If we got here with no hit point, the control was hit.// Center on the control instead,	if ( mapPointP == NULL )	{		mapPointP = &panInfoP->mapOrigin;	}// Release the old map	if ( panInfoP->layerP )	{		MapReleaseLayer( panInfoP->mapP->mapID, panInfoP->layerP );	}	MapReleaseMap( panInfoP->mapP->mapID, panInfoP->mapP );	if ( panInfoP->zoom == mapZoomLow )	{// Zoom in.  Adjust the coordinates by the scale to center on the zoom point.		panInfoP->mapOrigin.x = mapPointP->x * 2;		panInfoP->mapOrigin.y = mapPointP->y * 2;// Fetch the new map.		panInfoP->mapP = MapFetchMap( mapBoulderCreek12, &anErr );		if ( panInfoP->layerP )		{			panInfoP->layerP = MapFetchLayer( mapBoulderCreek12, mapLayerPOI, &anErr );		}		panInfoP->zoom = mapZoomHigh;			}	else	{// Zoom out. Adjust the coordinates by the scale to center on the zoom point.		panInfoP->mapOrigin.x = mapPointP->x / 2;		panInfoP->mapOrigin.y = mapPointP->y / 2;				// Fetch the new map.		panInfoP->mapP = MapFetchMap( mapBoulderCreek24, &anErr );		if ( panInfoP->layerP )		{			panInfoP->layerP = MapFetchLayer( mapBoulderCreek24, mapLayerPOI, &anErr );		}		panInfoP->zoom = mapZoomLow;	}// Clip the map as required.			RestrictToDisplay( panInfoP, &panInfoP->mapOrigin.x, &panInfoP->mapOrigin.y );}/*********************************************************************** * FUNCTION:    	MainFormHandleEvent * * DESCRIPTION: 	This routine is the event handler for MainForm. * * RETURNED:    	true if the event is handled. ***********************************************************************/ static Boolean MainFormHandleEvent(	EventPtr eventP		// Pointer to an EventType that contains the event to handle){    Boolean 	handled = false;    FormPtr		frmP = FrmGetActiveForm ();	switch ( eventP->eType ) 	{		case frmOpenEvent:				MainFormInit ( frmP );	// ***** WARNING  - falls thru to next case *****					case frmUpdateEvent:			FrmDrawForm ( frmP );			MainFormDraw( frmP );			handled = true;			break; 								case frmCloseEvent:					MainFormDone ( frmP );			handled = false;			break;						// Menu & Control Events			case menuEvent:				handled = MainFormDoMenuCommand ( eventP->data.menu.itemID );			break;					case ctlSelectEvent:			{				TPanllInfoTypePtr panInfoP;				panInfoP = FrmGetGadgetData ( frmP, 	FrmGetObjectIndex ( frmP, MainMapGadget ) );								if ( eventP->data.ctlSelect.controlID == MainZoomGraphicButton )				{					handled = true;					MainFormZoom( NULL, panInfoP );				}				else 				if ( eventP->data.ctlSelect.controlID == MainLayerGraphicButton )				{					if ( panInfoP->layerP )					{						MapReleaseLayer( panInfoP->mapP->mapID, panInfoP->layerP );						MemSet( panInfoP->layerLabelP, sizeof( TMapLabel ), 0 );						panInfoP->layerPOICoord.x = panInfoP->layerPOICoord.y = 0;						panInfoP->layerP = NULL;					}					else					{						Err anErr;												panInfoP->layerP = MapFetchLayer( panInfoP->mapP->mapID, 							mapLayerPOI,							&anErr );					}									handled = true;				}				MainFormDraw( frmP );				break;				}			// Pen events -- used for map scrolling & selection.		case penDownEvent:		{			if ( RctPtInRectangle( eventP->screenX, eventP->screenY, &mapGadgetRect ) )			{				MainFormStartPan( frmP );				handled = true;			}			break;		}		}	return handled;}/*********************************************************************** * FUNCTION:    	AppHandleEvent * * DESCRIPTION: 	Loads a form's resources and set its event handler. * * RETURNED:    	true if the event is handled. ***********************************************************************/ static Boolean AppHandleEvent(	EventPtr eventP		// Pointer to an EventType that contains the event to handle){	    Boolean 	handled = false;	if ( eventP->eType == frmLoadEvent )	{	// Form load event--initialize the form and make it the active form.		UInt16 	formId = eventP->data.frmLoad.formID;		FormPtr	frmP = FrmInitForm ( formId );		FrmSetActiveForm ( frmP );// Set the event handler for the form.		switch (formId)		{			case MainForm:							FrmSetEventHandler(frmP, MainFormHandleEvent);				handled = true;				break;//	Insert other cases as needed for other forms.		}		handled = true;	}	return handled;}/*********************************************************************** * FUNCTION:    	AppEventLoop * * DESCRIPTION: 	The main event loop for the application.   * * RETURNED:    	nothing ***********************************************************************/ static void AppEventLoop(	void){	UInt16 		error;	EventType 	event;	do {		EvtGetEvent ( &event, evtWaitForever );		if (! SysHandleEvent ( &event))			if (! MenuHandleEvent ( 0, &event, &error ))				if (! AppHandleEvent ( &event ))					FrmDispatchEvent ( &event );	} while ( event.eType != appStopEvent );}/*********************************************************************** * FUNCTION:     	AppStart * * DESCRIPTION:  	Do whatever is necessary to get started, like read the app preferences. * * RETURNED:     	Err value or 0 if nothing went wrong ***********************************************************************/ static UInt32 AppStart(	void){// Return an error code if necessary. // Let's try to get a grayscale mode if 8 colors isn't supported.	UInt32 depth;	WinScreenMode(winScreenModeGetSupportedDepths, 0, 0, &depth, 0);	if ( depth > 2 && depth < 8 ) depth = 2; else depth = 8;	WinScreenMode(winScreenModeSet, 0, 0, &depth, 0);	return 0;}/*********************************************************************** * FUNCTION:    	AppStop * * DESCRIPTION: 	Do whatever you need to do, like save the preferences. * * RETURNED:    	nothing ***********************************************************************/static void AppStop(	void){	UInt32 depth;	WinScreenMode(winScreenModeGetDefaults, 0, 0, &depth, 0);	WinScreenMode(winScreenModeSet, 0, 0, &depth, 0);}/*********************************************************************** * FUNCTION:    PilotMain * * DESCRIPTION: The application main entry point. * * RETURNED:    0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/ UInt32 PilotMain(	UInt16	cmd,					// The launch code	MemPtr	/* cmdPBP*/,		// Pointer to the launch code structure	UInt16	launchFlags			// Extra launch info){	UInt32 error = 0;// Check the ROM version for compatibility.	error = RomVersionCompatible ( MIN_ROM_VERSION, launchFlags);	if ( error == 0 ){// ROM OK, check for the various launch codes as needed.			switch (cmd)		{			case sysAppLaunchCmdNormalLaunch:							error = AppStart ();				if ( error == 0 )				{					FrmGotoForm ( MainForm );					AppEventLoop ();					AppStop ();				}				break;		}	}	return error;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -