Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / MotifApp / PixmapCycler.C
1 /* $XConsortium: PixmapCycler.C /main/3 1996/04/21 19:40:27 drk $ */
2 /*
3  *+SNOTICE
4  *
5  *      RESTRICTED CONFIDENTIAL INFORMATION:
6  *      
7  *      The information in this document is subject to special
8  *      restrictions in a confidential disclosure agreement bertween
9  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
10  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
11  *      Sun's specific written approval.  This documment and all copies
12  *      and derivative works thereof must be returned or destroyed at
13  *      Sun's request.
14  *
15  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
16  *
17  *+ENOTICE
18  */
19
20 ///////////////////////////////////////////////////////////////////////////////
21 //////////////////////////////////////////////////////////////////////////////
22 //         This example code is from the book:
23 //
24 //           Object-Oriented Programming with C++ and OSF/Motif
25 //         by
26 //           Douglas Young
27 //           Prentice Hall, 1992
28 //           ISBN 0-13-630252-1 
29 //
30 //         Copyright 1991 by Prentice Hall
31 //         All Rights Reserved
32 //
33 //  Permission to use, copy, modify, and distribute this software for 
34 //  any purpose except publication and without fee is hereby granted, provided 
35 //  that the above copyright notice appear in all copies of the software.
36 ///////////////////////////////////////////////////////////////////////////////
37 //////////////////////////////////////////////////////////////////////////////
38
39
40 //////////////////////////////////////////////////////////////////
41 // PixmapCycler.C: Abstract class that supports a continuous cycle
42 //                 of pixmaps for short animation sequences.
43 ////////////////////////////////////////////////////////////////////
44 #include "PixmapCycler.h"
45
46 #define INVALID -1
47
48 PixmapCycler::PixmapCycler ( int numPixmaps, Dimension w, Dimension h )
49 {
50     _numPixmaps = numPixmaps;
51     _current    = INVALID;
52     _pixmapList = new Pixmap[_numPixmaps];
53     _width      = w;
54     _height     = h;
55 }
56
57 PixmapCycler::~PixmapCycler()
58 {
59     delete []_pixmapList;
60 }
61
62 Pixmap PixmapCycler::next()
63 {
64     // The first time, call the createPixmaps() function 
65     // implemented by the derived class to create the pixmaps
66     
67     if ( _current == INVALID )
68     {
69         createPixmaps();
70         _current = 0;    // Initialize to the first pixmap
71     }
72     
73     // If the counter is larger than the index of the 
74     // last pixmap, roll it over and restart with zero
75     
76     if ( _current >= _numPixmaps )
77         _current = 0;
78     
79     // Return the current pixmap and increment the counter
80     
81     return _pixmapList[_current++];
82 }