📄 map.c
字号:
/********************************************************************* FILE: Map.c** DESCRIPTION: The map maintenance] module.** VERSION: 1.0**********************************************************************/#include <PalmOS.h>#include <PalmCompatibility.h>#include "MapperRsc.h"#include "Utils.h"#include "UtilsRsc.h"#include "Map.h"#include "bc.h"/*********************************************************************** * FUNCTION: MapFetchMap * * DESCRIPTION: Fetches a map given a map ID. * * RETURNED: An error if the map was not found; pointer to new scroll info ***********************************************************************/TMapInfoTypePtr MapFetchMap( TMapID mapID, // (in) Map to fetch Err *errP // (out) what error occurs ){ TMapInfoTypePtr infoP = MemPtrNew( sizeof( TMapInfoType ) ); *errP = dmErrCantFind; if ( infoP ) { RctSetRectangle ( &infoP->mapBounds, 0, 0, 0, 0 ); infoP->mapBitmapH = NULL; infoP->mapBitmapP = NULL; infoP->mapID = mapIDNull; if ( mapID == mapBoulderCreek24 ) { BitmapType *bitmapP; MemHandle bitmapH; UInt16 mapResourceID = (UInt16) mapID; bitmapH = DmGetResource( bitmapRsc, BC24000Bitmap2 ); if ( bitmapH ) { infoP->mapBitmapH = bitmapH; infoP->mapBitmapP = bitmapP = MemHandleLock( bitmapH ); RctSetRectangle ( &infoP->mapBounds, 0, 0, bitmapP->width, bitmapP->height ); infoP->mapID = mapID; *errP = noErr; } } else if ( mapID == mapBoulderCreek12 ) { BitmapType *bitmapP; MemHandle bitmapH; UInt16 mapResourceID = (UInt16) mapID; bitmapH = DmGetResource( bitmapRsc, BC12000Bitmap ); if ( bitmapH ) { infoP->mapBitmapH = bitmapH; infoP->mapBitmapP = bitmapP = MemHandleLock( bitmapH ); RctSetRectangle ( &infoP->mapBounds, 0, 0, bitmapP->width, bitmapP->height ); infoP->mapID = mapID; *errP = noErr; } } else { MemPtrFree( infoP ); infoP = NULL; } // MapID } // Is there enough memory for a map? return infoP;}/*********************************************************************** * FUNCTION: MapReleaseMap * * DESCRIPTION: Releases a map given a map ID and cleans the scroll info. * * RETURNED: An error if the map was not found; pointer to new scroll info ***********************************************************************/Err MapReleaseMap( TMapID mapID, TMapInfoTypePtr infoP // (in) location of map info to clear ){ #pragma unused ( mapID ) if ( infoP ) { if ( infoP->mapBitmapP ) MemHandleUnlock( infoP->mapBitmapH ); if ( infoP->mapBitmapH ) DmReleaseResource( infoP->mapBitmapH ); MemPtrFree( infoP ); } return noErr;}/*********************************************************************** * FUNCTION: MapCoordToScreenCoord * * DESCRIPTION: Converts a map point to screen point * * RETURNED: pointer to STATIC point with resutl ***********************************************************************/PointType *MapCoordToScreenCoord // (out) screen-relative coordinates( PointType *mapPoint, // (in) point on map const RectangleType *screenRect // (in) map area on screen){ static PointType screenPoint; screenPoint.x = screenRect->topLeft.x - mapPoint->x + ( screenRect->extent.x - screenRect->topLeft.x ) / 2; screenPoint.y = screenRect->topLeft.y - mapPoint->y + ( screenRect->extent.y - screenRect->topLeft.y ) / 2; return &screenPoint;}/*********************************************************************** * FUNCTION: ScreenCoordToMapCoord * * DESCRIPTION: Converts a map point to screen point * * RETURNED: pointer to STATIC point with resutl ***********************************************************************/PointType *ScreenCoordToMapCoord // (out) screen-relative coordinates( PointType *screenPoint, // (in) point on map const RectangleType *screenRect // (in) map area on screen){ static PointType mapPoint; mapPoint.x = screenRect->topLeft.x - screenPoint->x + ( screenRect->extent.x - screenRect->topLeft.x ) / 2; mapPoint.y = screenRect->topLeft.y - screenPoint->y + ( screenRect->extent.y - screenRect->topLeft.y ) / 2; return &mapPoint;}/*********************************************************************** * FUNCTION: MapCoordToTapCoord * * DESCRIPTION: Converts a map point to tap (gadget) point * * RETURNED: pointer to STATIC point with result ***********************************************************************/PointType *MapCoordToTapCoord // (out) screen-relative coordinates( PointType *mapPointP, // (in) point on map PointType *mapOriginP, // (in) scroll point of map const RectangleType *screenRectP // (in) map area on screen){ static PointType tapPoint; PointType *screenOriginP = MapCoordToScreenCoord( mapOriginP, screenRectP ); tapPoint.x = screenOriginP->x + mapPointP->x; tapPoint.y = screenOriginP->y + mapPointP->y; return &tapPoint;}/*********************************************************************** * FUNCTION: TapCoordToMapCoord * * DESCRIPTION: Converts a tap (gadget) point to map point * * RETURNED: pointer to STATIC point with result ***********************************************************************/PointType *TapCoordToMapCoord // (out) screen-relative coordinates( PointType *tapPointP, // (in) point on map PointType *mapOriginP, // (in) scroll point of map const RectangleType *screenRectP // (in) map area on screen){ static PointType mapPoint; PointType *screenOriginP = MapCoordToScreenCoord( mapOriginP, screenRectP ); mapPoint.x = tapPointP->x - screenOriginP->x; mapPoint.y = tapPointP->y - screenOriginP->y; return &mapPoint;}/*********************************************************************** * FUNCTION: MapFetchLayer * * DESCRIPTION: Fetches a map layer * * RETURNED: pointer to map layer ***********************************************************************/TMapLayerPtr MapFetchLayer( TMapID mapID, EMapLayerType layer, Err *errP){ TMapLayerPtr resP = NULL; *errP = dmErrCantFind; // validate inputs first. if ( ( mapID == mapBoulderCreek24 || mapID == mapBoulderCreek12 ) && layer == mapPOILayerTypeCafe ) { // fetch the appropriate layer data. resP = &mapLayers[mapID]; *errP = noErr; } return resP;}/*********************************************************************** * FUNCTION: MapReleaseLayer * * DESCRIPTION: Frees a map layer * * RETURNED: error if one occurs ***********************************************************************/Err MapReleaseLayer( TMapID mapID, TMapLayerPtr layerP){ #pragma unused ( mapID ) #pragma unused ( layerP ) // STUB! Our layers are compile-time generated. return noErr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -