📄 ctrlbar.c
字号:
else fprintf(stderr, "DrawButton called with unknown button\n");}/* * * WindowSearch -- * * Search window id's to see if an expose event is on a display window * */#if __STDC__static int WindowSearch(XInfo *xinfo, Window win, int num)#elsestatic int WindowSearch(xinfo, win, num)XInfo *xinfo;Window win;int num;#endif{ int i; for (i=0;(i<num) && (xinfo[i].window!=win);i++) { } if (i==num) return -1; else return i;}/* *-------------------------------------------------------------- * * ControlBar -- * * Checks XEvent queue for control commands. * * Results: * Adjusts global variables ControlState, loopFlag as appropriate. * * Side effects: * May adjust StopWatch state. * *-------------------------------------------------------------- */void ControlBar(vid_stream,xinfo,numMovies)VidStream **vid_stream;XInfo *xinfo;int numMovies;{ GC gc; int gcflag, winNum; Window oldbutton, newbutton; XEvent event; static int LastState = CTRL_UNDEFINED; Display *display=xinfo[0].display; gcflag = 0; /* Check to see if ControlState was modified outside this function, */ /* and update control displays if it was. */ if (LastState != ControlState) { if (!gcflag) { gc = CreateCtrlGC(display); gcflag = 1; } if ((oldbutton = GetStateButton(LastState)) != (Window)NULL) { XClearWindow(display, oldbutton); DrawButton(oldbutton, gc, display, vid_stream, numMovies); if (LastState == CTRL_EOF) { XClearWindow(display, playwin); DrawButton(playwin, gc, display, vid_stream, numMovies); } } DrawButton(GetStateButton(LastState = ControlState), gc, display, vid_stream, numMovies); } /* Process events, if any */ if (XPending(display) < 1) { /* No events */ if (gcflag) { XFreeGC(display, gc); } LastState = ControlState; return; } if (!gcflag) { gc=CreateCtrlGC(display); gcflag=1; } do { XNextEvent(display, &event);#ifdef HAVE_XFILTEREVENT /* Define if needed; Some older X's don't have this */ if (XFilterEvent(&event, ctrlwindow)) continue;#endif switch(event.type) { case ButtonPress: /* Toggle Buttons */ if (event.xbutton.window == loopwin) { if (loopFlag) { XClearWindow(display,loopwin); loopFlag = 0; } else { loopFlag = 1; if (ControlState == CTRL_EOF && ControlMotion == CTRLMOTION_ON) { ControlState = CTRL_REWIND; DrawRewind(gc,display); XClearWindow(display, playwin); DrawPlay(gc,display); XClearWindow(display, pausewin); DrawPause(gc,display); } } DrawLoop(gc,display); break; } /* Click in display window */ else if (WindowSearch(xinfo,event.xbutton.window,numMovies) != -1) { if (ControlShow) { ControlShow = CTRLBAR_OFF; } else { ControlShow = CTRLBAR_ON; } ShowHideControls(&xinfo[0]); break; } /* ControlState buttons --- */ /* Get currently selected button */ oldbutton = GetStateButton(ControlState); /* Update state */ if (event.xbutton.window == pausewin) { if ((ControlState == CTRL_EOF || ControlState == CTRL_FFWD) && ControlMotion == CTRLMOTION_ON) { ControlMotion = CTRLMOTION_OFF; XClearWindow(display, playwin); DrawPlay(gc,display); } else if (ControlState == CTRL_PLAY) { ControlMotion = CTRLMOTION_OFF; ControlState = CTRL_PAUSE; } else if (ControlState == CTRL_PAUSE) { ControlMotion = CTRLMOTION_ON; ControlState = CTRL_PLAY; } } else if (event.xbutton.window == stepwin) { if (ControlState == CTRL_PAUSE || ControlState == CTRL_PLAY) ControlState = CTRL_STEP; else if (ControlState == CTRL_EOF && loopFlag) ControlState = CTRL_REWIND; ControlMotion = CTRLMOTION_OFF; } else if (event.xbutton.window == playwin) { ControlMotion = CTRLMOTION_ON; if (ControlState == CTRL_EOF) { if (loopFlag) { ControlState = CTRL_REWIND; } DrawButton(playwin, gc, display, vid_stream, numMovies); } else if (ControlState == CTRL_PAUSE) { ControlState = CTRL_PLAY; } } else if (event.xbutton.window == rewindwin) { ControlState = CTRL_REWIND; } else if (event.xbutton.window == exitwin) { ControlState = CTRL_EXIT; } /* Get newly selected button */ newbutton = GetStateButton(ControlState); if (LastState == ControlState) break; /* Adjust stopwatch */ if (LastState == CTRL_PLAY) StopWatch(STOPWATCH_STOP); /* Stop playing */ else if (ControlState == CTRL_PLAY) StopWatch(STOPWATCH_START); /* Start playing */ /* Update button display */ if (oldbutton != (Window)NULL) { XClearWindow(display,oldbutton); DrawButton(oldbutton,gc,display,vid_stream,numMovies); } DrawButton(newbutton,gc,display,vid_stream,numMovies); break; case ClientMessage: if (event.xclient.message_type != protocol_atom || event.xclient.data.l[0] != delete_atom || event.xclient.format != 32) break; /* Not WM_DELETE_WINDOW */ /* Otherwise drop through to DestroyNotify */ case DestroyNotify: ControlState=CTRL_EXIT; break; case Expose: if (event.xexpose.count > 0) { break; /* Wait for last expose event */ } if ((winNum= WindowSearch(xinfo,event.xexpose.window, numMovies)) != -1) { if ( vid_stream[winNum]->current != NULL) { ExecuteDisplay(vid_stream[winNum],0,&xinfo[winNum]); } } else { DrawButton(event.xexpose.window,gc,display,vid_stream,numMovies); } break; default: break; } } while (XPending(display) > 0); if (gcflag) { XFreeGC(display, gc); } LastState = ControlState;}/* *-------------------------------------------------------------- * * ControlLoop -- * * Main control loop. Intermixes video processing (as * determined by ControlState) with user input. * * Results: * None. * * Side effects: * Adjusts StopWatch state, totNumFrames, ControlState. * May also reset video state. * *-------------------------------------------------------------- */void ControlLoop(vid_stream,xinfo,numStreams)VidStream **vid_stream;XInfo *xinfo;int numStreams;{ int itemp, i, allMovies; XEvent event; Display *display=xinfo[0].display; for (i=0;(display==NULL) && (i<numStreams); i++) { display=xinfo[i].display; } if (!ctrl_init) { fprintf(stderr,"ControlLoop() accessed without initialization\n"); exit(1); } StopWatch(STOPWATCH_RESET); TotalFrameCount = 0; StopWatch(STOPWATCH_START); for (i=0;i<numStreams;i++) { itemp = vid_stream[i]->totNumFrames; while (vid_stream[i]->totNumFrames == itemp) mpegVidRsrc(0, vid_stream[i], 0, &xinfo[i]); /* Advance to 1st frame */ } if (startFrame > vid_stream[0]->totNumFrames) { ControlState = CTRL_FFWD; ControlMotion = CTRLMOTION_OFF; StopWatch(STOPWATCH_STOP); } else if (ControlShow != CTRLBAR_ON || noDisplayFlag) { ControlState = CTRL_PLAY; ControlMotion = CTRLMOTION_ON; } else { ControlState = INITIAL_STATE; ControlMotion = CTRLMOTION_OFF; if (ControlState == CTRL_PAUSE) { StopWatch(STOPWATCH_STOP); } else { StopWatch(STOPWATCH_START); } } while (1) { ControlBar(vid_stream,&xinfo[0],numStreams); if (ControlState == CTRL_PAUSE || ControlState == CTRL_EOF) { XPeekEvent(display, &event); /* Block until user input */ } else { switch(ControlState) { case CTRL_PLAY: allMovies=1; for (i=0;i<numStreams;i++) { /* If Film end reached, don't play frames */ if ((vid_stream[i]!=NULL) && (!vid_stream[i]->film_has_ended)) { itemp = vid_stream[i]->totNumFrames; /* Advance 1 frame */ while (vid_stream[i]->totNumFrames == itemp) { mpegVidRsrc(0, vid_stream[i], 0, &xinfo[i]); } allMovies=allMovies && (vid_stream[i]->film_has_ended); } } if (allMovies) { /* Film end reached for all movies*/ StopWatch(STOPWATCH_STOP); XSync(display, FALSE); /* Kludge to update frametotalwin */ if (loopFlag) { ControlState = CTRL_REWIND; } else { ControlState = CTRL_EOF; } } break; case CTRL_FFWD: allMovies=1; for (i=0;i<numStreams;i++) { if (vid_stream[i]!=NULL) { mpegVidRsrc(0, vid_stream[i], 0, &xinfo[i]); allMovies=allMovies && vid_stream[i]->film_has_ended; } } for (i=0;(i<numStreams) && ((vid_stream[i]==NULL) || (startFrame <= vid_stream[i]->totNumFrames));i++) { ; } if (i==numStreams) { if (ControlMotion == CTRLMOTION_ON) { ControlState = CTRL_PLAY; StopWatch(STOPWATCH_START); } else { ControlState = CTRL_PAUSE; } } /* Film end just reached---Degenerate case */ if (allMovies) { StopWatch(STOPWATCH_STOP); if (loopFlag) { ControlState = CTRL_REWIND; } else { ControlState = CTRL_EOF; } } break; case CTRL_EOF: if (loopFlag) { ControlState = CTRL_REWIND; } break; case CTRL_STEP: StopWatch(STOPWATCH_START); allMovies=1; for (i=0;i<numStreams;i++) { if ((vid_stream[i]!=NULL) && !vid_stream[i]->film_has_ended) { itemp = vid_stream[i]->totNumFrames; /* Advance 1 frame */ while (vid_stream[i]->totNumFrames == itemp) { mpegVidRsrc(0, vid_stream[i], 0, &xinfo[i]); } allMovies=allMovies && vid_stream[i]->film_has_ended; } } StopWatch(STOPWATCH_STOP); ControlState = CTRLMOTION_OFF; /* Film end just reached for last ending movie */ if (allMovies) ControlState = CTRL_EOF; else ControlState = CTRL_PAUSE; break; case CTRL_REWIND: StopWatch(STOPWATCH_STOP); for (i=0;i<numStreams;i++) { rewind(vid_stream[i]->input); } ControlBar(vid_stream, &xinfo[0], numStreams); for (i=0;i<numStreams;i++) { if (vid_stream[i]!=NULL) { ResetVidStream(vid_stream[i]);/* Reinitialize vid_stream pointers */ if (vid_stream[i]->seekValue < 0) { vid_stream[i]->seekValue = 0 - vid_stream[i]->seekValue; } } } for (i=0; i<numStreams; i++) { if (vid_stream[i] != NULL) { /* Process start codes */ mpegVidRsrc(0, vid_stream[i], 1, &xinfo[i]); } } if (startFrame > 0) { ControlState = CTRL_FFWD; } else { /* Do 1st frame */ for (i=0;i<numStreams;i++) { if (vid_stream[i] != NULL) { vid_stream[i]->realTimeStart = ReadSysClock(); while (vid_stream[i]->totNumFrames == 0) { mpegVidRsrc(0, vid_stream[i], 0, &xinfo[i]); } } } /* Time like original pass */ StopWatch(STOPWATCH_START); if (ControlMotion == CTRLMOTION_ON) { ControlState = CTRL_PLAY; } else { ControlState = CTRL_PAUSE; StopWatch(STOPWATCH_STOP); } } break; case CTRL_EXIT: if (ctrlfont != NULL) { XFreeFont(display, ctrlfont); } XDestroyWindow(display, ctrlwindow); return; default: fprintf(stderr,"Code error: Illegal control state: %d (main())", ControlState); exit(1); break; } } }}#endif /* !NOCONTROLS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -