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