home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / hotspot / editor / hotspot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-05  |  5.4 KB  |  176 lines

  1. /**************************************************************************
  2.  *
  3.  *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4.  *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5.  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6.  *  PURPOSE.
  7.  *
  8.  *  Copyright (c) 1993  Microsoft Corporation.  All Rights Reserved.
  9.  * 
  10.  **************************************************************************/
  11. /*
  12.     hotspot.c:
  13.         InitHotspots -- reads hotspots from HOT file into linked list
  14.         DeleteHotspot -- deletes a hotspot from linked list in PMOVIEINFO
  15.         DeleteHotspotList -- deletes them all
  16.         AddHotspot -- adds a hotspot to linked list in PMOVIEINFO
  17. */
  18.  
  19. #include <windows.h>
  20. #include <mmsystem.h>
  21. #include <digitalv.h>
  22. #include <viewer.h>
  23. #include <string.h>
  24. #include <direct.h>
  25. #include <stdlib.h>
  26.  
  27. #include "hotspot.h"
  28.  
  29. char szMovieInfo[] = "MovieInfo";
  30.  
  31. /* 
  32.     InitHotspots -- you give it a pointer to a movie structure and a
  33.         filename, and it adds a hotspot list to the movie structure from
  34.         the data in the file.  The file is a HOT file, and is stored
  35.         in a binary format: there's a tag indicating a .HOT file, then
  36.         the number of hotspots.  Then it loops through, reading six numbers
  37.         (the rect and the start/end frames) and two strings (the hostpotID
  38.         and the viewer command) for each one.  Strings of length 0 are
  39.         transformed into NULLs.
  40. */
  41. BOOL InitHotspots(PMOVIEINFO pMovieInfo, LPSTR pszHotFile)
  42. {
  43.     HFILE hFile;
  44.     char szBuf[256];
  45.     int hotcount, i;
  46.     PHOTSPOT pHotspot;
  47.     
  48.     hFile = _lopen(pszHotFile,READ);
  49.     if (hFile == HFILE_ERROR)
  50.     {
  51.         MessageBox(GetFocus(),pszHotFile,"Can't read this file:",MB_OK);
  52.     }
  53.    
  54.     _lread(hFile,szBuf,2); 
  55.     if (szBuf[0] != 'H' || szBuf[1] != 'H')
  56.     {
  57.         MessageBox(GetFocus(),"File is not a hotspot file","Out of luck",MB_OK);
  58.     }
  59.     _lread(hFile,&hotcount,sizeof(hotcount));
  60.         
  61.     for (i=0;i<hotcount;i++)
  62.     {
  63.         int x;
  64.         if (! (pHotspot = (PHOTSPOT)ALLOCATE(sizeof(HOTSPOT))))
  65.          {
  66.             MessageBox(GetFocus(),"Unable to allocate HOTSPOT structure",
  67.             "Big Problem Here",MB_OK);
  68.         }
  69.            
  70.         _lread(hFile,&pHotspot->rc.left,sizeof(pHotspot->rc.left));
  71.         _lread(hFile,&pHotspot->rc.top,sizeof(pHotspot->rc.top));
  72.         _lread(hFile,&pHotspot->rc.right,sizeof(pHotspot->rc.right));
  73.         _lread(hFile,&pHotspot->rc.bottom,sizeof(pHotspot->rc.bottom));
  74.         
  75.         _lread(hFile,&x,sizeof(x));
  76.         if (x)
  77.         {
  78.             _lread(hFile,szBuf,x); szBuf[x] = '\0';
  79.             pHotspot->pszHotspotID = (LPSTR) ALLOCATE(lstrlen(szBuf) + 1);
  80.             lstrcpy(pHotspot->pszHotspotID, szBuf);                
  81.         }
  82.         else pHotspot->pszHotspotID = NULL;
  83.         
  84.         _lread(hFile,&x,sizeof(x)); szBuf[x] = '\0';
  85.         if (x) _lwrite(hFile,pHotspot->pszCommand,x);
  86.         if (x)
  87.         {
  88.             _lread(hFile,szBuf,x);
  89.             pHotspot->pszCommand = (LPSTR) ALLOCATE(lstrlen(szBuf) + 1);
  90.             lstrcpy(pHotspot->pszCommand, szBuf);                
  91.         }
  92.          else pHotspot->pszCommand = NULL;
  93.  
  94.         _lread(hFile,&pHotspot->BeginFrame,sizeof(pHotspot->BeginFrame));
  95.         _lread(hFile,&pHotspot->EndFrame,sizeof(pHotspot->EndFrame));
  96.         _lread(hFile,&pHotspot->OnClick,sizeof(pHotspot->OnClick));
  97.         _lread(hFile,&pHotspot->ToFrame,sizeof(pHotspot->ToFrame));
  98.         AddHotspot(pMovieInfo, pHotspot);
  99.     }
  100.     _lclose(hFile);
  101.     return TRUE;
  102.  }
  103.  
  104. /*
  105.     DeleteHotspot -- give it a pointer to a hotspot structure and
  106.         a pointer to a movieinfo structure, and it will delete the
  107.         hotspot from the movieinfo's hotspot list.  Minor bug: 
  108.         If you give it a hotspot for a different movieinfo,
  109.         it will free it anyway, but if you give it a hotspot and
  110.         a NULL movieinfo, it won't.  The list is doubly linked, so
  111.          it just switches some pointers.
  112. */
  113. void DeleteHotspot(PMOVIEINFO pMovieInfo, PHOTSPOT pHotspot)
  114. {
  115.     PHOTSPOT pPrev, pNext;    
  116.     
  117.     if (!pMovieInfo || !pHotspot)
  118.         return;
  119.  
  120.     pPrev = pHotspot->pPrev;
  121.     pNext = pHotspot->pNext;
  122.     
  123.     if (pPrev) {
  124.         pPrev->pNext = pNext;
  125.     } else {
  126.         pMovieInfo->pHotspotList = pNext;
  127.     }
  128.     if (pNext) {
  129.         pNext->pPrev = pPrev;
  130.     }
  131.  
  132.     if (pHotspot->pszCommand)
  133.         FREE(pHotspot->pszCommand);
  134.  
  135.     if (pHotspot->pszHotspotID)
  136.         FREE(pHotspot->pszHotspotID);
  137.                 
  138.     FREE(pHotspot);    
  139.     pHotspot = NULL;
  140. }
  141.  
  142. /*
  143.     DeleteHotspotList --
  144.         deletes a list of hotspots in a movieinfo -- faster that using
  145.         DeleteHotspot because it doesn't twiddle pointers -- just
  146.         marches down the next pointers and frees everything.
  147. */
  148. void DeleteHotspotList(PMOVIEINFO pMovieInfo)
  149. {
  150.     PHOTSPOT pHotspot, pNext;
  151.     
  152.     pHotspot = pMovieInfo->pHotspotList;
  153.     while (pHotspot) {
  154.         pNext = pHotspot->pNext;
  155.         DeleteHotspot(pMovieInfo, pHotspot);
  156.         pHotspot = pNext;
  157.     }
  158.     pMovieInfo->pHotspotList = NULL;
  159. }
  160.  
  161. /*
  162.     AddHotspot -- adds a hotspot (which you give it) to the front of
  163.         a hotspot list in the movieinfo (which you also give it).
  164.         The hotspot should be allocated using ALLOCATE -- see hotspot.h
  165. */
  166. void AddHotspot(PMOVIEINFO pMovieInfo, PHOTSPOT pHotspot)
  167. {    
  168.  
  169.     if (pMovieInfo->pHotspotList) {
  170.         pMovieInfo->pHotspotList->pPrev = pHotspot;
  171.         pHotspot->pNext = pMovieInfo->pHotspotList;
  172.     }
  173.     pMovieInfo->pHotspotList = pHotspot;
  174. }
  175.  
  176.