Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Copyright 1995, Brown University, Providence, RI
3
 *
4
 * Permission to use and modify this software and its documentation for
5
 * any purpose other than its incorporation into a commercial product is
6
 * hereby granted without fee.  Permission to copy and distribute this
7
 * software and its documentation only for non-commercial use is also
8
 * granted without fee, provided, however, that the above copyright notice
9
 * appear in all copies, that both that copyright notice and this permission
10
 * notice appear in supporting documentation, that the name of Brown
11
 * University not be used in advertising or publicity pertaining to
12
 * distribution of the software without specific, written prior permission,
13
 * and that the person doing the distribution notify Brown University of
14
 * such distributions outside of his or her organization. Brown University
15
 * makes no representations about the suitability of this software for
16
 * any purpose.  It is provided "as is" without express or implied warranty.
17
 * Brown University requests notification of any modifications to this
18
 * software or its documentation.
19
 *
20
 * Send the following redistribution information:
21
 *
22
 *      Name:
23
 *      Organization:
24
 *      Address (postal and/or electronic):
25
 *
26
 * To:
27
 *      Software Librarian
28
 *      Computer Science Department, Box 1910
29
 *      Brown University
30
 *      Providence, RI 02912
31
 *
32
 *              or
33
 *
34
 *      brusd@cs.brown.edu
35
 *
36
 * We will acknowledge all electronic notifications.
37
 */
38
 
39
#include <stdio.h>
40
#include <iostream.h>
41
#include "ANIMdisplay.H"
42
 
43
// Constructor for first movie in a series
44
//
45
//
46
ANIMdisplay::ANIMdisplay(ANIMbase *movie, char* displayName,
47
                         Boolean loopMovie,
48
                         int allocateFrame, int starty)
49
        : _movie(movie),
50
          originalMovie(TRUE),
51
          frameAllocated(FALSE),
52
          loop(loopMovie),
53
          movieEnded(FALSE),
54
          _displayName(strdup(displayName))
55
{
56
 
57
//for first instance
58
           xinfo.hints.x=0;
59
           xinfo.hints.y=starty;
60
           xinfo.cmap=0;
61
           xinfo.gc=0;
62
           xinfo.depth=24;
63
           xinfo.ditherType=FULL_COLOR_DITHER;
64
           xinfo.display=NULL;
65
           xinfo.visual=NULL;
66
           xinfo.ExistingWindow=0;
67
 
68
         xinfo.hints.width=movie->Width;
69
         xinfo.hints.height=movie->Height;
70
         largy=-1;
71
 
72
         init(allocateFrame);
73
 
74
         XWindowAttributes winattr;
75
         Display *display=xinfo.display;
76
 
77
         displayWidth=DisplayWidth(display,XDefaultScreen(display));
78
         XGetWindowAttributes(display, xinfo.window, &winattr);
79
 
80
         _movie->InitDither(winattr.visual->red_mask,
81
                             winattr.visual->green_mask,
82
                             winattr.visual->blue_mask);
83
}
84
 
85
// Constructor for first movie in a series
86
//
87
//
88
ANIMdisplay::ANIMdisplay(ANIMbase *movie, ANIMdisplay *lastMovie,
89
                         Boolean loopMovie,
90
                         int allocateFrame)
91
   : largy(lastMovie->largy),
92
     frameAllocated(FALSE),
93
     displayWidth(lastMovie->displayWidth),
94
     _displayName(lastMovie->_displayName),
95
     _movie(movie),
96
     originalMovie(TRUE),
97
     loop(loopMovie),
98
     movieEnded(FALSE)
99
{
100
//for n>1 instance
101
         /* get next X coordinates */
102
         xinfo.hints.x= lastMovie->xinfo.hints.x+10+ lastMovie->_movie->Width;
103
         /* Update the largest vertical size of a movie */
104
         /* If we are off the right side of the screen, cont at left */
105
         xinfo.hints.y=lastMovie->xinfo.hints.y;
106
         if (xinfo.hints.x > displayWidth - 80) {
107
                  xinfo.hints.y+=largy+30;
108
                  largy=0;
109
                  xinfo.hints.x=0;
110
         }
111
         xinfo.ExistingWindow=0;
112
         xinfo.display=lastMovie->xinfo.display;
113
         xinfo.visual=lastMovie->xinfo.visual;
114
         xinfo.cmap=lastMovie->xinfo.cmap;
115
         xinfo.gc=lastMovie->xinfo.gc;
116
         xinfo.ditherType=lastMovie->xinfo.ditherType;
117
         xinfo.display=lastMovie->xinfo.display;
118
         xinfo.depth=lastMovie->xinfo.depth;
119
         xinfo.ditherType=lastMovie->xinfo.ditherType;
120
 
121
         init(allocateFrame);
122
}
123
 
124
// Destructor
125
//
126
//
127
ANIMdisplay::~ANIMdisplay()
128
{
129
        if (frameAllocated) {
130
           free(xinfo.ximage->data);
131
           xinfo.ximage->data=NULL;
132
        }
133
        if (xinfo.ximage!=NULL) XDestroyImage(xinfo.ximage);
134
        // Add code re: xinfo.display - reference count
135
}
136
 
137
// Constructor helper code, also called when we switch movies
138
//
139
//
140
void
141
ANIMdisplay::init(Boolean allocateFrame)
142
{
143
         const char *inputName=_movie->getName();
144
 
145
         if (_movie->Height>largy) {
146
                 largy=_movie->Height;
147
         }
148
         xinfo.hints.width=_movie->Width;
149
         xinfo.hints.height=_movie->Height;
150
 
151
         xinfo.ximage=NULL;
152
         xinfo.owncmFlag=FALSE;
153
 
154
         if (inputName==NULL) {
155
            // Should be....  different
156
            xinfo.name="Display!";
157
         } else if ((xinfo.name=strrchr(inputName,'/'))==NULL) {
158
            xinfo.name=(char *) inputName;
159
         } else xinfo.name++;
160
 
161
         if (originalMovie) InitColorDisplay((char *) _displayName,&xinfo);
162
         else {
163
            XSetStandardProperties (xinfo.display, xinfo.window, xinfo.name,
164
                                    xinfo.name, None, NULL, 0,
165
                                    &xinfo.hints);
166
         }
167
         init_image(allocateFrame);
168
}
169
 
170
void
171
ANIMdisplay::init_image(Boolean allocateFrame) {
172
        Display *display=xinfo.display;
173
        Visual *fc_visual;
174
        int depth, w,h;
175
        char *where,dummy;
176
 
177
        //XImage has to be on word boundary?
178
        w = _movie->Width + (_movie->Width % 16);
179
        h = _movie->Height + (_movie->Height % 16);
180
        if (w+h==0) {
181
           xinfo.ximage=NULL;
182
           return;
183
        }
184
        frameAllocated=allocateFrame;
185
 
186
        fc_visual = FindFullColorVisual(display, &depth);
187
        if (allocateFrame) where=(char *) malloc(w*h*4);
188
        else where=&dummy;
189
        xinfo.ximage=XCreateImage(display,fc_visual,depth,ZPixmap,
190
            0,where,w, h,32,0);
191
 
192
#ifdef LITTLE_ENDIAN_ARCHITECTURE
193
        xinfo.ximage->byte_order = LSBFirst;
194
        xinfo.ximage->bitmap_bit_order = LSBFirst;
195
#else
196
        xinfo.ximage->byte_order = MSBFirst;
197
        xinfo.ximage->bitmap_bit_order = MSBFirst;
198
#endif
199
}
200
 
201
void
202
ANIMdisplay::newMovie(const char *const newMovieName)
203
{
204
        if (xinfo.ximage!=NULL) XDestroyImage(xinfo.ximage);
205
 
206
        if (newMovieName!=NULL) {
207
           _movie->newMovie(newMovieName);
208
           _movie->open();
209
        }
210
 
211
        originalMovie=FALSE;
212
        init(frameAllocated);
213
 
214
        XResizeWindow(xinfo.display,xinfo.window,
215
                      _movie->Width,
216
                      _movie->Height);
217
        XFlush(xinfo.display);
218
 
219
        movieEnded=FALSE;
220
}
221
 
222
void
223
ANIMdisplay::display(char *frame) {
224
        char *paramFrame, *tmpFrame;
225
        Boolean moreFrames, newFrame;
226
 
227
        // if frame is:
228
        //      !NULL - display frame already in xinfo
229
        //       NULL - get frame and then display it
230
        if (frame==NULL) {
231
           if (xinfo.ximage!=NULL) paramFrame=xinfo.ximage->data;
232
           else paramFrame=NULL;
233
           moreFrames=_movie->GetFrame(&paramFrame,&newFrame);
234
           if (newFrame) {
235
              // if there is no ximage so far, we are starting "anew"
236
              if (xinfo.ximage==NULL) {
237
                 frameAllocated=TRUE;  // Don't allocate a frame
238
                 newMovie(NULL);
239
              }
240
              tmpFrame=xinfo.ximage->data;
241
              xinfo.ximage->data=paramFrame;
242
           }
243
        } else newFrame=TRUE;
244
 
245
        if (newFrame) {
246
           Display *display=xinfo.display;
247
           if (frame!=NULL) xinfo.ximage->data=frame;
248
           XPutImage(display, xinfo.window, xinfo.gc, xinfo.ximage,
249
                  0,0,0,0,
250
                  (unsigned int) xinfo.ximage->width,
251
                  (unsigned int) xinfo.ximage->height);
252
        }
253
 
254
        if (frame==NULL) {
255
           // Don't copy NULL over new frame if unneeded
256
           if (newFrame) xinfo.ximage->data=tmpFrame;
257
 
258
           if (!moreFrames ) {
259
              if (loop) _movie->rewind();
260
              else movieEnded=TRUE;
261
           }
262
        }
263
}
264
 
265
Boolean ANIMdisplay::movieDone()
266
{
267
        return movieEnded;
268
}