+void CL_PurgeOwner( int owner )
+{
+ int i;
+ for( i = 0 ; i < cl_num_videos ; i++ )
+ if( cl_videos[ i ].ownertag == owner )
+ CL_CloseVideo( &cl_videos[ i ] );
+}
+
+typedef struct
+{
+ dp_font_t *font;
+ float x;
+ float y;
+ float width;
+ float height;
+ float alignment; // 0 = left, 0.5 = center, 1 = right
+ float fontsize;
+ float textalpha;
+}
+cl_video_subtitle_info_t;
+
+float CL_DrawVideo_WordWidthFunc(void *passthrough, const char *w, size_t *length, float maxWidth)
+{
+ cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough;
+
+ if(w == NULL)
+ return si->fontsize * si->font->maxwidth;
+ if(maxWidth >= 0)
+ return DrawQ_TextWidth_UntilWidth(w, length, si->fontsize, si->fontsize, false, si->font, -maxWidth); // -maxWidth: we want at least one char
+ else if(maxWidth == -1)
+ return DrawQ_TextWidth(w, *length, si->fontsize, si->fontsize, false, si->font);
+ else
+ return 0;
+}
+
+int CL_DrawVideo_DisplaySubtitleLine(void *passthrough, const char *line, size_t length, float width, qboolean isContinuation)
+{
+ cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough;
+
+ int x = (int) (si->x + (si->width - width) * si->alignment);
+ if (length > 0)
+ DrawQ_String(x, si->y, line, length, si->fontsize, si->fontsize, 1.0, 1.0, 1.0, si->textalpha, 0, NULL, false, si->font);
+ si->y += si->fontsize;
+ return 1;
+}
+
+int cl_videoplaying = false; // old, but still supported
+
+void CL_DrawVideo(void)
+{
+ clvideo_t *video;
+ float videotime;
+ cl_video_subtitle_info_t si;
+ int i;
+
+ if (!cl_videoplaying)
+ return;
+
+ video = CL_GetVideoBySlot( 0 );
+
+ // fix cvars
+ if (cl_video_scale.value <= 0 || cl_video_scale.value > 1)
+ Cvar_SetValueQuick( &cl_video_scale, 1);
+ if (cl_video_brightness.value <= 0 || cl_video_brightness.value > 10)
+ Cvar_SetValueQuick( &cl_video_brightness, 1);
+
+ // draw black bg in case stipple is active or video is scaled
+ if (cl_video_stipple.integer || cl_video_scale.value != 1)
+ DrawQ_Fill(0, 0, vid_conwidth.integer, vid_conheight.integer, 0, 0, 0, 1, 0);
+
+ // enable video-only polygon stipple (of global stipple is not active)
+ if (qglPolygonStipple && !scr_stipple.integer && cl_video_stipple.integer)
+ {
+ GLubyte stipple[128];
+ int i, s, width, parts;
+
+ s = cl_video_stipple.integer;
+ parts = (s & 007);
+ width = (s & 070) >> 3;
+ qglEnable(GL_POLYGON_STIPPLE);CHECKGLERROR // 0x0B42
+ for(i = 0; i < 128; ++i)
+ {
+ int line = i/4;
+ stipple[i] = ((line >> width) & ((1 << parts) - 1)) ? 0x00 : 0xFF;
+ }
+ qglPolygonStipple(stipple);CHECKGLERROR
+ }
+
+ // draw video
+ if (cl_video_scale.value == 1)
+ DrawQ_Pic(0, 0, &video->cpif, vid_conwidth.integer, vid_conheight.integer, cl_video_brightness.value, cl_video_brightness.value, cl_video_brightness.value, 1, 0);
+ else
+ {
+ int px = (int)(vid_conwidth.integer * (1 - cl_video_scale.value) * 0.5);
+ int py = (int)(vid_conheight.integer * (1 - cl_video_scale.value) * ((bound(-1, cl_video_scale_vpos.value, 1) + 1) / 2));
+ int sx = (int)(vid_conwidth.integer * cl_video_scale.value);
+ int sy = (int)(vid_conheight.integer * cl_video_scale.value);
+ DrawQ_Pic(px, py, &video->cpif, sx , sy, cl_video_brightness.value, cl_video_brightness.value, cl_video_brightness.value, 1, 0);
+ }
+
+ // disable video-only stipple
+ if (qglPolygonStipple && !scr_stipple.integer && cl_video_stipple.integer)
+ qglDisable(GL_POLYGON_STIPPLE);CHECKGLERROR
+
+ // VorteX: draw subtitle_text
+ if (!video->subtitles || !cl_video_subtitles.integer)
+ return;
+
+ // find current subtitle
+ videotime = realtime - video->starttime;
+ for (i = 0; i < video->subtitles; i++)
+ {
+ if (videotime >= video->subtitle_start[i] && videotime <= video->subtitle_end[i])
+ {
+ // found, draw it
+ si.font = FONT_NOTIFY;
+ si.x = vid_conwidth.integer * 0.1;
+ si.y = vid_conheight.integer - (max(1, cl_video_subtitles_lines.value) * cl_video_subtitles_textsize.value);
+ si.width = vid_conwidth.integer * 0.8;
+ si.height = max(1, cl_video_subtitles_lines.integer) * cl_video_subtitles_textsize.value;
+ si.alignment = 0.5;
+ si.fontsize = cl_video_subtitles_textsize.value;
+ si.textalpha = min(1, (videotime - video->subtitle_start[i])/0.5) * min(1, ((video->subtitle_end[i] - videotime)/0.3)); // fade in and fade out
+ COM_Wordwrap(video->subtitle_text[i], strlen(video->subtitle_text[i]), 0, si.width, CL_DrawVideo_WordWidthFunc, &si, CL_DrawVideo_DisplaySubtitleLine, &si);
+ break;
+ }
+ }
+}
+
+void CL_VideoStart(char *filename, const char *subtitlesfile)
+{
+ Host_StartVideo();
+
+ if( cl_videos->state != CLVIDEO_UNUSED )
+ CL_CloseVideo( cl_videos );
+ // already contains video/
+ if( !OpenVideo( cl_videos, filename, va( CLDYNTEXTUREPREFIX "%s", filename ), 0, subtitlesfile ) )
+ return;
+ // expand the active range to include the new entry
+ cl_num_videos = max(cl_num_videos, 1);
+
+ cl_videoplaying = true;
+
+ CL_SetVideoState( cl_videos, CLVIDEO_PLAY );
+ CL_RestartVideo( cl_videos );
+}
+
+void CL_Video_KeyEvent( int key, int ascii, qboolean down )
+{
+ // only react to up events, to allow the user to delay the abortion point if it suddenly becomes interesting..
+ if( !down ) {
+ if( key == K_ESCAPE || key == K_ENTER || key == K_SPACE ) {
+ CL_VideoStop();
+ }
+ }
+}
+
+void CL_VideoStop(void)
+{
+ cl_videoplaying = false;