Basic subtitle loading and rendering. Still lots of todos but basic functionality now exists

This commit is contained in:
andres.delikat 2011-06-26 16:39:48 +00:00
parent 61e82793e9
commit 3a15dd6bb9
4 changed files with 56 additions and 51 deletions

View File

@ -111,7 +111,7 @@ namespace BizHawk.MultiClient
bool Resized { get; set; }
void AddMessage(string msg);
string FPS { get; set; }
string MT { get; set; }
string MT { get; set; }
}
public class SysdrawingRenderPanel : IRenderer
@ -119,7 +119,7 @@ namespace BizHawk.MultiClient
public bool Resized { get; set; }
public void Dispose() { }
public string FPS { get; set; }
public string MT { get; set; }
public string MT { get; set; }
public void Render(IVideoProvider video)
{
Color BackgroundColor = Color.FromArgb(video.BackgroundColor);
@ -149,7 +149,7 @@ namespace BizHawk.MultiClient
public Color BackgroundColor { get; set; }
public bool Resized { get; set; }
public string FPS { get; set; }
public string MT { get; set; }
public string MT { get; set; }
private Direct3D d3d;
private Device Device;
private Control backingControl;
@ -229,26 +229,28 @@ namespace BizHawk.MultiClient
Device.Present(Present.DoNotWait);
}
public void Render(IVideoProvider video)
{
try
{
RenderExec(video);
} catch (Direct3D9Exception) {
// Wait until device is available or user gets annoyed and closes app
Result r;
do
{
r = Device.TestCooperativeLevel();
Thread.Sleep(100);
} while (r == ResultCode.DeviceLost);
public void Render(IVideoProvider video)
{
try
{
RenderExec(video);
}
catch (Direct3D9Exception)
{
// Wait until device is available or user gets annoyed and closes app
Result r;
do
{
r = Device.TestCooperativeLevel();
Thread.Sleep(100);
} while (r == ResultCode.DeviceLost);
// lets try recovery!
DestroyDevice();
CreateDevice();
RenderExec(video);
}
}
// lets try recovery!
DestroyDevice();
CreateDevice();
RenderExec(video);
}
}
private void RenderExec(IVideoProvider video)
{
@ -352,13 +354,13 @@ namespace BizHawk.MultiClient
input = MakeInputDisplay();
MessageFont.DrawString(null, input, x, y, c);
}
if (Global.MainForm.UserMovie.MultiTrack.isActive)
{
MessageFont.DrawString(null, MT, Global.Config.DispFPSx + 1, //TODO: Multitrack position variables
Global.Config.DispFPSy + 1, new Color4(Color.Black));
MessageFont.DrawString(null, MT, Global.Config.DispFPSx,
Global.Config.DispFPSy, Color.FromArgb(Global.Config.MessagesColor));
}
if (Global.MainForm.UserMovie.MultiTrack.isActive)
{
MessageFont.DrawString(null, MT, Global.Config.DispFPSx + 1, //TODO: Multitrack position variables
Global.Config.DispFPSy + 1, new Color4(Color.Black));
MessageFont.DrawString(null, MT, Global.Config.DispFPSx,
Global.Config.DispFPSy, Color.FromArgb(Global.Config.MessagesColor));
}
if (Global.Config.DisplayFPS && FPS != null)
{
x = GetX(Global.Config.DispFPSx, Global.Config.DispFPSanchor);
@ -403,7 +405,7 @@ namespace BizHawk.MultiClient
if (Global.MainForm.UserMovie.GetMovieMode() == MOVIEMODE.PLAY
|| Global.MainForm.UserMovie.GetMovieMode() == MOVIEMODE.PLAY)
{
MessageFont.DrawString(null, "Play", backingControl.Size.Width-47,
MessageFont.DrawString(null, "Play", backingControl.Size.Width - 47,
0 + 1, new Color4(Color.Black));
MessageFont.DrawString(null, "Play", backingControl.Size.Width - 48,
0, new Color4(Color.Red));
@ -416,9 +418,12 @@ namespace BizHawk.MultiClient
0, new Color4(Color.Red));
}
//TODO: read subtitle positioning, implement multiple subtitles at once feature
MessageFont.DrawString(null, Global.MainForm.UserMovie.Subtitles.GetSubtitle(Global.Emulator.Frame), 0 + 1,
0 + 1, new Color4(Color.Black));
MessageFont.DrawString(null, Global.MainForm.UserMovie.Subtitles.GetSubtitle(Global.Emulator.Frame), 0 ,
0, new Color4(Color.White));
}
private string MakeFrameCounter()

View File

@ -12,7 +12,7 @@ namespace BizHawk.MultiClient
{
private MovieHeader Header = new MovieHeader();
private MovieLog Log = new MovieLog();
private SubtitleList Subtitles = new SubtitleList();
public SubtitleList Subtitles = new SubtitleList();
private bool IsText = true;
private string Filename;
@ -25,16 +25,6 @@ namespace BizHawk.MultiClient
public int lastLog;
public int rerecordCount;
public string GetSubtitle(int frame)
{
return Subtitles.GetSubtitle(frame);
}
public Point GetSutitlePoint(int frame)
{
return Subtitles.GetSubtitlePoint(frame);
}
public Movie(string filename, MOVIEMODE m)
{
Filename = filename; //TODO: Validate that file is writable

View File

@ -5,13 +5,14 @@ using System.Text;
namespace BizHawk.MultiClient
{
class Subtitle
public class Subtitle
{
public string Message;
public int Frame;
public int X;
public int Y;
public int Duration;
public UInt32 Color;
public Subtitle()
{
@ -20,15 +21,17 @@ namespace BizHawk.MultiClient
Y = 0;
Duration = 0;
Frame = 0;
Color = 0xFFFFFFFF;
}
public Subtitle(string message, int x, int y, int dur, int frame)
public Subtitle(string message, int x, int y, int dur, int frame, UInt32 color)
{
Message = message;
Frame = frame;
X = x;
Y = y;
Duration = dur;
Color = color;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Drawing;
namespace BizHawk.MultiClient
{
class SubtitleList
public class SubtitleList
{
private List<Subtitle> subs = new List<Subtitle>();
@ -25,12 +25,13 @@ namespace BizHawk.MultiClient
for (int x = 0; x < subs.Count; x++)
{
if (subs[x].Frame + subs[x].Duration >= frame)
if (frame >= subs[x].Frame && frame <= subs[x].Frame + subs[x].Duration)
return subs[x].Message;
}
return "";
}
//TODO
public Point GetSubtitlePoint(int frame)
{
Point p = new Point(0, 0);
@ -51,18 +52,24 @@ namespace BizHawk.MultiClient
int x = subtitleStr.IndexOf(' ');
if (x <= 0) return false;
string str = subtitleStr.Substring(x, subtitleStr.Length - x);
string str = subtitleStr.Substring(x + 1, subtitleStr.Length - x - 1);
string frame = str.Substring(0, str.IndexOf(' '));
try
{
s.Frame = Int16.Parse(str);
s.Frame = Int16.Parse(frame);
}
catch
{
return false;
}
x = str.IndexOf(' ');
//TODO: actually attempt to parse these things and supply with default values if they don't exist
s.X = 0;
s.Y = 0;
s.Duration = 120;
s.Message = str;
s.Color = 0xFFFFFFFF;
subs.Add(s);
return true;
}