+ 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;
+
+static 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;
+}
+
+static 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, px, py, sx, sy, st[8], b;
+ 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);
+
+ // calc video proportions
+ px = 0;
+ py = 0;
+ sx = vid_conwidth.integer;
+ sy = vid_conheight.integer;
+ st[0] = 0.0; st[1] = 0.0;
+ st[2] = 1.0; st[3] = 0.0;
+ st[4] = 0.0; st[5] = 1.0;
+ st[6] = 1.0; st[7] = 1.0;
+ if (cl_video_keepaspectratio.integer)
+ {
+ float a = video->getaspectratio(video->stream) / ((float)vid.width / (float)vid.height);
+ if (cl_video_keepaspectratio.integer >= 2)
+ {
+ // clip instead of scale
+ if (a < 1.0) // clip horizontally
+ {
+ st[1] = st[3] = (1 - a)*0.5;
+ st[5] = st[7] = 1 - (1 - a)*0.5;
+ }
+ else if (a > 1.0) // clip vertically
+ {
+ st[0] = st[4] = (1 - 1/a)*0.5;
+ st[2] = st[6] = (1/a)*0.5;
+ }
+ }
+ else if (a < 1.0) // scale horizontally
+ {
+ px += sx * (1 - a) * 0.5;
+ sx *= a;
+ }
+ else if (a > 1.0) // scale vertically
+ {
+ a = 1 / a;
+ py += sy * (1 - a);
+ sy *= a;
+ }
+ }
+
+ if (cl_video_scale.value != 1)
+ {
+ px += sx * (1 - cl_video_scale.value) * 0.5;
+ py += sy * (1 - cl_video_scale.value) * ((bound(-1, cl_video_scale_vpos.value, 1) + 1) / 2);
+ sx *= cl_video_scale.value;
+ sy *= cl_video_scale.value;
+ }
+
+ // calc brightness for fadein and fadeout effects
+ b = cl_video_brightness.value;
+ if (cl_video_fadein.value && (realtime - video->starttime) < cl_video_fadein.value)
+ b = pow((realtime - video->starttime)/cl_video_fadein.value, 2);
+ else if (cl_video_fadeout.value && ((video->starttime + video->framenum * video->framerate) - realtime) < cl_video_fadeout.value)
+ b = pow(((video->starttime + video->framenum * video->framerate) - realtime)/cl_video_fadeout.value, 2);
+
+ // draw black bg in case stipple is active or video is scaled
+ if (cl_video_stipple.integer || px != 0 || py != 0 || sx != vid_conwidth.integer || sy != vid_conheight.integer)
+ 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 (!scr_stipple.integer && cl_video_stipple.integer)
+ {
+ Con_Print("FIXME: cl_video_stipple not implemented\n");
+ Cvar_SetValueQuick(&cl_video_stipple, 0);
+ }
+
+ // draw video
+ if (v_glslgamma_video.value >= 1)
+ DrawQ_SuperPic(px, py, video->cachepic, sx, sy, st[0], st[1], b, b, b, 1, st[2], st[3], b, b, b, 1, st[4], st[5], b, b, b, 1, st[6], st[7], b, b, b, 1, 0);
+ else
+ {
+ DrawQ_SuperPic(px, py, video->cachepic, sx, sy, st[0], st[1], b, b, b, 1, st[2], st[3], b, b, b, 1, st[4], st[5], b, b, b, 1, st[6], st[7], b, b, b, 1, DRAWFLAG_NOGAMMA);
+ if (v_glslgamma_video.value > 0.0)
+ DrawQ_SuperPic(px, py, video->cachepic, sx, sy, st[0], st[1], b, b, b, v_glslgamma_video.value, st[2], st[3], b, b, b, v_glslgamma_video.value, st[4], st[5], b, b, b, v_glslgamma_video.value, st[6], st[7], b, b, b, v_glslgamma_video.value, 0);
+ }
+
+ // 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;
+ }
+ }
+}