home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / displytl / gallery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  13.9 KB  |  392 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23. /* $Header: /Source/Media/collab/DisplayTool/RCS/gallery.c,v 1.11 93/02/07 17:51:38 drapeau Exp $ */
  24. /* $Log:    gallery.c,v $
  25.  * Revision 1.11  93/02/07  17:51:38  drapeau
  26.  * Cosmetic changes, added calls to UpdateHeader() to indicate status of
  27.  * currently open document.
  28.  * 
  29.  * Revision 1.1  92/10/29  13:55:03  drapeau
  30.  * Initial revision
  31.  *  */
  32. static char dtGallery[] = "$Header: /Source/Media/collab/DisplayTool/RCS/gallery.c,v 1.11 93/02/07 17:51:38 drapeau Exp $";
  33.  
  34. #include "DisplayTool.h"
  35. #include "externs.h"
  36.  
  37.  
  38.  
  39. /*
  40.  * Event callback function for `gallery'.
  41.  */
  42. Notify_value
  43.   DisplayTool_baseWindow_gallery_event_callback(Xv_window win, Event *event, Notify_arg arg, Notify_event_type type)
  44. {
  45.   if (event_id(event) == LOC_DRAG) 
  46.   {
  47.     GalleryEventProc(win, event, arg, type);
  48.   }
  49.   /* gxv_start_connections DO NOT EDIT THIS SECTION */
  50.   
  51.   if (event_action(event) == ACTION_SELECT)
  52.   {
  53.     GalleryEventProc(win, event, arg, type);
  54.   }
  55.   
  56.   if (event_action(event) == ACTION_ADJUST)
  57.   {
  58.     GalleryEventProc(win, event, arg, type);
  59.   }
  60.   
  61.   if (event_action(event) == ACTION_MENU)
  62.   {
  63.     GalleryEventProc(win, event, arg, type);
  64.   }
  65.   
  66.   /* gxv_end_connections */
  67.   
  68.   return notify_next_event_func(win, (Notify_event) event, arg, type);
  69. }
  70.  
  71.  
  72.  
  73. /*
  74.  * Called when an event is received in the gallery canvas.
  75.  */
  76. Notify_value
  77.   GalleryEventProc(Xv_window        win,
  78.            Event*        event,
  79.            Notify_arg        arg,
  80.            Notify_event_type    type)
  81. {
  82.   static int    oldx, oldy;
  83.   static int    first;
  84.   static int    dragging = FALSE;
  85.   int        i;
  86.   int        scrollbarOffset;
  87.   int        oldSelectedGalleryImage;
  88.   XPoint    loc;
  89.   XEvent    compressedEvent;
  90.   IMAGE        tempImage;
  91.   
  92.   if (event_action(event) != event_id(event))                /* If the event does have an XView action associated... */
  93.     {                                    /* ...with it then the id number and the action value... */
  94.       switch (event_action(event))                    /* ...will be distinct -- Volume 7, pg. 126 */
  95.     {
  96.     case ACTION_SELECT :  /* the action */
  97.     case MS_LEFT :          /* the actual (literal) event */
  98.     case ACTION_ADJUST :
  99.     case MS_MIDDLE :
  100.     case ACTION_MENU :
  101.     case MS_RIGHT :
  102.       if (event_is_down(event))
  103.         {
  104.           loc.x = event_x(event);
  105.           loc.y = event_y(event);
  106.           oldSelectedGalleryImage = selectedGalleryImage;
  107.           selectedGalleryImage = loc.x/102+(loc.y/102)*imagesPerRow;
  108.           PrintDTDiagnostics(diagString);
  109.           if (selectedGalleryImage < numGalleryImages)
  110.             HighlightGalleryImage(selectedGalleryImage, oldSelectedGalleryImage);
  111.           else
  112.         {
  113.           if (oldSelectedGalleryImage != None)
  114.             HighlightGalleryImage(oldSelectedGalleryImage, oldSelectedGalleryImage);
  115.           selectedGalleryImage = None;
  116.         }
  117.         }
  118.       else
  119.             if (event_is_up(event) && dragging)
  120.           {
  121.         tempImage = gallery[selectedGalleryImage];
  122.         if (tempImage->galleryImage == (XImage*)NULL)        /* If the galleryImage doesn't exist, create it first. */
  123.           tempImage->galleryImage = Resize(tempImage->imageData,
  124.                           tempImage->origWidth,
  125.                           tempImage->origHeight,
  126.                           100, 100);
  127.         XPutImage(display, galleryWin, theGC,
  128.               tempImage->galleryImage, 0, 0,
  129.                       oldx, oldy, 100, 100);
  130.         if (first)
  131.           CreateCopyOfImage(oldx, oldy);
  132.         HighlightGalleryImage(selectedGalleryImage, selectedGalleryImage);
  133.         oldx     = 0;
  134.         oldy     = 0;
  135.         first    = FALSE;
  136.         dragging = FALSE;
  137.           }
  138.       break;
  139.       default : ;
  140.     }
  141.     }
  142.   else                                    /* If the doesn't have a specific action associated... */
  143.     switch (event_id(event))                        /* ...with it, only an id number */
  144.       {
  145.       case LOC_DRAG:
  146.     if (selectedGalleryImage != None)                /* Is an image currently selected?  I.e., is there.... */
  147.       {                                /* ...something to drag around? */
  148.         tempImage = gallery[selectedGalleryImage];            /* Yes, point to the currently-selected Gallery image */
  149.         if (tempImage->galleryImage == (XImage*)NULL)        /* If the galleryImage doesn't exist, create it first. */
  150.           tempImage->galleryImage = Resize(tempImage->imageData,
  151.                           tempImage->origWidth,
  152.                           tempImage->origHeight,
  153.                           100, 100);
  154.         dragging = TRUE;
  155.         PrintDTDiagnostics(diagString);
  156.         if (oldx!=0 || oldy!=0)
  157.           XPutImage(display, galleryWin, theGC,            /* Draw the image in XOR mode in its previous position,... */
  158.             tempImage->galleryImage,            /* ...to erase it */
  159.             0, 0,  oldx, oldy, 100, 100);
  160.         XPutImage(display, galleryWin, theGC,            /* Draw the image again in XOR mode in its new position,... */
  161.               tempImage->galleryImage,                /* ...to show it */
  162.               0, 0,  event_x(event), event_y(event), 100, 100);
  163.         if (event_y(event) > 100*(int)xv_get(galleryScrollbar,  /* Has the image been dragged close enough to the slides... */
  164.                          SCROLLBAR_VIEW_START))    /* ...window that the image should be drawn in the... */
  165.           {                                /* ...slides window? */
  166.         scrollbarOffset =                    /* Yes, determine where to position the image */
  167.           (int)(SmallHeight) * (int)xv_get(slidesScrollbar,
  168.                            SCROLLBAR_VIEW_START) -
  169.             104 * (int)xv_get(galleryScrollbar, SCROLLBAR_VIEW_START);
  170.         if (first)
  171.           XPutImage(display, slidesWin, theGC,
  172.                 tempImage->galleryImage,
  173.                 0, 0,  oldx, 
  174.                 oldy-borderOffset+scrollbarOffset, 100, 100);
  175.         else
  176.           first = TRUE;
  177.         
  178.         XPutImage(display, slidesWin, theGC,
  179.               tempImage->galleryImage,
  180.               0, 0,  event_x(event), 
  181.               event_y(event)-borderOffset+scrollbarOffset,
  182.               100, 100);
  183.           }
  184.         oldx = event_x(event);
  185.         oldy = event_y(event);
  186.       }
  187.     break;
  188.       default:
  189.     ;
  190.       }
  191.   if (display)
  192.     for (i=XEventsQueued(display, QueuedAlready); i > 1; i--)
  193.       XNextEvent(display, &compressedEvent); 
  194.   
  195.   /* gxv_start_connections DO NOT EDIT THIS SECTION */
  196.   
  197.   /* gxv_end_connections */
  198.   
  199.   return notify_next_event_func(win, (Notify_event) event, arg, type);
  200. }                                    /* end function GalleryEventProc */
  201.  
  202.  
  203.  
  204.  
  205. /*
  206.  *   GalleryEventProc sub-function when the mouse is released -- copy the image
  207.  */
  208. void
  209.   CreateCopyOfImage(int oldx, int oldy)
  210. {
  211.   int    i;
  212.   IMAGE    tempImage;
  213.   char    errorMessage[MaxLength];
  214.   int    scrollbarOffset = SmallHeight * (int)xv_get(slidesScrollbar,  SCROLLBAR_VIEW_START) - 
  215.     104 * (int)xv_get(galleryScrollbar, SCROLLBAR_VIEW_START);
  216.   
  217.   PrintDTDiagnostics("Entering CreateCopyOfImage.\n");
  218.   if (oldy - borderOffset+scrollbarOffset < 0)
  219.     return;
  220.   if (dtImage[numSlidesImages] != (IMAGE)NULL)                /* Free up space taken by this image, if necessary */
  221.     FreeImage(dtImage[numSlidesImages]);
  222.   dtImage[numSlidesImages] =                        /* Create a new image with the same file data as the... */
  223.     CreateImage(gallery[selectedGalleryImage]->filename);        /* ...one being copied */
  224.   if (dtImage[numSlidesImages] == (IMAGE)NULL)
  225.   {
  226.     sprintf(diagString, "In CreateCopyOfImage, could not create new image for file %s.\n",
  227.         gallery[selectedGalleryImage]->filename);
  228.     PrintDTDiagnostics(diagString);
  229.     return;
  230.   }
  231.   tempImage = dtImage[numSlidesImages];                    /* Point temp variable to newly-created image */
  232.   sprintf(diagString, "Before 3 Resizes, tempImage stuff: origWidth=%d, origHeight=%d, largeWidth=%d, largeHeight=%d.\n",
  233.       tempImage->origWidth, tempImage->origHeight,
  234.       tempImage->largeWidth, tempImage->largeHeight);
  235.   PrintDTDiagnostics(diagString);
  236.   if (tempImage->galleryImage == (XImage*)NULL)                /* If the galleryImage doesn't exist, create it first. */
  237.     tempImage->galleryImage = Resize(tempImage->imageData,
  238.                      tempImage->origWidth,
  239.                      tempImage->origHeight,
  240.                      100, 100);
  241.   if (tempImage->slideImage == (XImage*)NULL)                /* If the slideImage doesn't exist, create it first. */
  242.     tempImage->slideImage = Resize(tempImage->imageData,
  243.                    tempImage->origWidth,
  244.                    tempImage->origHeight,
  245.                    tempImage->largeWidth / largeFactor,
  246.                    tempImage->largeHeight / largeFactor);
  247.   if (tempImage->largeImage == (XImage*)NULL)                /* If the largeImage doesn't exist, create it first. */
  248.     tempImage->largeImage = Resize(tempImage->imageData,
  249.                    tempImage->origWidth,
  250.                    tempImage->origHeight,
  251.                    tempImage->largeWidth,
  252.                    tempImage->largeHeight);
  253.   tempImage->slide = WhichSlide(oldx, oldy-borderOffset+scrollbarOffset,
  254.                 slideSize, &tempImage->corner);
  255.   if (tempImage->slide > MaxNumSlides-1)
  256.   {
  257.     sprintf(errorMessage, "Can't exceed %d slides.", MaxNumSlides);
  258.     notice_prompt(baseWindow->baseWindow, NULL,
  259.           NOTICE_MESSAGE_STRINGS,
  260.           errorMessage,
  261.           " ",
  262.           "Images beyond this limit shall",
  263.           "be placed in the last slide.",
  264.           NULL,
  265.           NOTICE_BUTTON_YES, "OK",
  266.           NULL);
  267.     tempImage->slide = MaxNumSlides - 1;
  268.     SlidesRepaint(NULL, NULL, NULL, NULL);
  269.   }
  270.   for (i=0; i < tempImage->nfcols && i<=NumColors; i++)
  271.     cmap[(int)tempImage->freecols[i]]++;
  272. /*  
  273.   GetOffsets(numSlidesImages, &xoffset, &yoffset);
  274.   PaintSlide(tempImage->slide);
  275.   
  276.   XClearArea(display, slidesWin, 0, 0,
  277.          SmallWidth, SmallHeight, True); 
  278.   XPutImage(display, slidesWin, theGC, tempImage->slideImage,
  279.         0, 0, xoffset + tempImage->corner.x,
  280.         yoffset + tempImage->corner.y,
  281.         tempImage->largeWidth / largeFactor,
  282.         tempImage->largeHeight / largeFactor);
  283. */  
  284.   selectedSlide = tempImage->slide;
  285.   numSlidesImages++;
  286.   SetCurrentSlide(selectedSlide+1);
  287.   changes = True;
  288.   UpdateHeader(True);
  289.   SetTotalNumberOfSlides();
  290.   PaintSlide(selectedSlide);
  291.   RedrawRectangles();
  292.   return;
  293. }                                    /* end function CreateCopyOfImage */
  294.  
  295.  
  296.  
  297.  
  298. void
  299.   HighlightGalleryImage(int imageNum, int oldImageNum)
  300. {
  301.   char    theMsg[256];
  302.   
  303.   PrintDTDiagnostics("Entering HighlightGalleryImage.\n");
  304.   XSetLineAttributes(display, theGC, 2, LineSolid, CapProjecting, JoinMiter);
  305.   XSetFunction(display, theGC, GXcopy); 
  306.   if (oldImageNum==None)
  307.     {
  308.       sprintf(theMsg, "Current Image: %s", gallery[imageNum]->filename);
  309.       xv_set(baseWindow->currentImageMsg, PANEL_LABEL_STRING, theMsg, NULL);
  310.       XSetForeground(display, theGC, pixelValues[Red]);
  311.       XDrawRectangle(display, galleryWin, theGC, (imageNum%imagesPerRow)*100+4*(imageNum%imagesPerRow)+1, 
  312.              (imageNum/imagesPerRow)*100+4*(imageNum/imagesPerRow)+1, 102, 102);
  313.     }
  314.   else if (imageNum == oldImageNum)
  315.     {
  316.       sprintf(theMsg, "Current Image: None");
  317.       xv_set(baseWindow->currentImageMsg, PANEL_LABEL_STRING, theMsg, NULL);
  318.       XSetForeground(display, theGC, BlackPixel(display, DefaultScreen(display)));
  319.       XDrawRectangle(display, galleryWin, theGC, (imageNum%imagesPerRow)*100+4*(imageNum%imagesPerRow)+1, 
  320.              (imageNum/imagesPerRow)*100+4*(imageNum/imagesPerRow)+1, 102, 102);
  321.       selectedGalleryImage = None;
  322.     }
  323.   else                                    /* (imageNum!=oldImageNum && oldImageNum!=None)  */
  324.     {
  325.       sprintf(theMsg, "Current Image: %s", gallery[imageNum]->filename);
  326.       xv_set(baseWindow->currentImageMsg, PANEL_LABEL_STRING, theMsg, NULL);
  327.       XSetForeground(display, theGC, BlackPixel(display, DefaultScreen(display)));
  328.       XDrawRectangle(display, galleryWin, theGC, (oldImageNum%imagesPerRow)*100+4*(oldImageNum%imagesPerRow)+1, 
  329.              (oldImageNum/imagesPerRow)*100+4*(oldImageNum/imagesPerRow)+1, 102, 102);
  330.       XSetForeground(display, theGC, pixelValues[Red]);
  331.       XDrawRectangle(display, galleryWin, theGC, (imageNum%imagesPerRow)*100+4*(imageNum%imagesPerRow)+1, 
  332.              (imageNum/imagesPerRow)*100+4*(imageNum/imagesPerRow)+1, 102, 102);
  333.     }
  334.   XSetFunction(display, theGC, GXxor); 
  335. }                                    /* end function HighlightGalleryImage */
  336.  
  337.  
  338.  
  339. /*
  340.  * Repaint callback function for `gallery'.
  341.  */
  342. void
  343.   GalleryRepaint(Canvas        canvas,
  344.          Xv_window    paint_window, 
  345.          Window        xid,
  346.          Xv_xrectlist*    rects)
  347. {
  348.   int    i;
  349.   
  350.   PrintDTDiagnostics("Called GalleryRepaint.\n");
  351.   XSetFunction(display, theGC, GXcopy); 
  352.   XClearArea(display, galleryWin, 0, 0, 645, 4*MaxNumImages, True);
  353.   XSetForeground(display, theGC, WhitePixel(display, DefaultScreen(display)));
  354.   XFillRectangle(display, galleryWin, theGC, 0, 0, 645, 4*MaxNumImages);
  355.   for (i = 0; i < numGalleryImages; i++)
  356.   {
  357.     if (selectedGalleryImage == i)
  358.       XSetForeground(display, theGC, pixelValues[Red]);
  359.     else
  360.       XSetForeground(display, theGC, BlackPixel(display, DefaultScreen(display)));
  361.     XDrawRectangle(display, galleryWin, theGC, (i%imagesPerRow)*100+4*(i%imagesPerRow)+1, 
  362.            (i/imagesPerRow)*100+4*(i/imagesPerRow)+1, 102, 102);
  363.     if (!performing)
  364.     {
  365.       PaintGalleryImage(i);
  366.     }
  367.   }
  368.   XSetFunction(display, theGC, GXxor); 
  369. }                                    /* end function GalleryRepaint */
  370.  
  371.  
  372.  
  373. void PaintGalleryImage(int imageNum)
  374. {
  375.   IMAGE    theImage;
  376.  
  377.   theImage = gallery[imageNum];
  378.   if (theImage->galleryImage == (XImage*)NULL)                /* If the galleryImage doesn't exist, create it first. */
  379.     theImage->galleryImage = Resize(theImage->imageData,
  380.                     theImage->origWidth,
  381.                     theImage->origHeight,
  382.                     100, 100);
  383.   XPutImage(display, galleryWin, theGC,
  384.         theImage->galleryImage,
  385.         0, 0,
  386.         (imageNum % imagesPerRow) * 100 +
  387.         4 * ((imageNum % imagesPerRow) + 1) - 2, 
  388.         (imageNum / imagesPerRow) * 100 +
  389.         4 * ((imageNum / imagesPerRow) + 1) - 2, 
  390.         100, 100);
  391. }                                    /* end function PaintGalleryImage */
  392.