RTS.h

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 #pragma once
00023 
00024 #include "STS.h"
00025 #include "Rasterizer.h"
00026 #include "..\SubPic\ISubPic.h"
00027 
00028 class CMyFont : public CFont
00029 {
00030 public:
00031         int m_ascent, m_descent;
00032 
00033         CMyFont(STSStyle& style);
00034 };
00035 
00036 class CPolygon;
00037 
00038 class CWord : public Rasterizer
00039 {
00040         bool m_fDrawn;
00041         CPoint m_p;
00042 
00043         void Transform(CPoint org);
00044 
00045         bool CreateOpaqueBox();
00046 
00047 protected:
00048         CStringW m_str;
00049 
00050         virtual bool CreatePath() = 0;
00051 
00052 public:
00053         bool m_fWhiteSpaceChar, m_fLineBreak;
00054 
00055         STSStyle m_style;
00056 
00057         CPolygon* m_pOpaqueBox;
00058 
00059         int m_ktype, m_kstart, m_kend;
00060 
00061         int m_width, m_ascent, m_descent;
00062 
00063         CWord(STSStyle& style, CStringW str, int ktype, int kstart, int kend); // str[0] = 0 -> m_fLineBreak = true (in this case we only need and use the height of m_font from the whole class)
00064         virtual ~CWord();
00065 
00066         virtual CWord* Copy() = 0;
00067         virtual bool Append(CWord* w);
00068 
00069         void Paint(CPoint p, CPoint org);
00070 };
00071 
00072 class CText : public CWord
00073 {
00074 protected:
00075         virtual bool CreatePath();
00076 
00077 public:
00078         CText(STSStyle& style, CStringW str, int ktype, int kstart, int kend);
00079 
00080         virtual CWord* Copy();
00081         virtual bool Append(CWord* w);
00082 };
00083 
00084 class CPolygon : public CWord
00085 {
00086         bool GetLONG(CStringW& str, LONG& ret);
00087         bool GetPOINT(CStringW& str, POINT& ret);
00088         bool ParseStr();
00089 
00090 protected:
00091         double m_scalex, m_scaley;
00092         int m_baseline;
00093 
00094         CArray<BYTE> m_pathTypesOrg;
00095         CArray<CPoint> m_pathPointsOrg;
00096 
00097         virtual bool CreatePath();
00098 
00099 public:
00100         CPolygon(STSStyle& style, CStringW str, int ktype, int kstart, int kend, double scalex, double scaley, int baseline);
00101         virtual ~CPolygon();
00102 
00103         virtual CWord* Copy();
00104         virtual bool Append(CWord* w);
00105 };
00106 
00107 class CClipper : public CPolygon
00108 {
00109 private:
00110         CWord* Copy();
00111     virtual bool Append(CWord* w);
00112 
00113 public:
00114         CClipper(CStringW str, CSize size, double scalex, double scaley);
00115         virtual ~CClipper();
00116 
00117         CSize m_size;
00118         BYTE* m_pAlphaMask;
00119 };
00120 
00121 class CLine : public CList<CWord*>
00122 {
00123 public:
00124         int m_width, m_ascent, m_descent, m_border;
00125 
00126         virtual ~CLine();
00127 
00128         void Compact();
00129 
00130         CRect PaintShadow(SubPicDesc& spd, CRect& clipRect, BYTE* pAlphaMask, CPoint p, CPoint org, int time, int alpha);
00131         CRect PaintOutline(SubPicDesc& spd, CRect& clipRect, BYTE* pAlphaMask, CPoint p, CPoint org, int time, int alpha);
00132         CRect PaintBody(SubPicDesc& spd, CRect& clipRect, BYTE* pAlphaMask, CPoint p, CPoint org, int time, int alpha);
00133 };
00134 
00135 enum eftype
00136 {
00137         EF_MOVE = 0,    // {\move(x1=param[0], y1=param[1], x2=param[2], y2=param[3], t1=t[0], t2=t[1])} or {\pos(x=param[0], y=param[1])}
00138         EF_ORG,                 // {\org(x=param[0], y=param[1])}
00139         EF_FADE,                // {\fade(a1=param[0], a2=param[1], a3=param[2], t1=t[0], t2=t[1], t3=t[2], t4=t[3])} or {\fad(t1=t[1], t2=t[2])
00140         EF_BANNER,              // Banner;delay=param[0][;lefttoright=param[1];fadeawaywidth=param[2]]
00141         EF_SCROLL,              // Scroll up/down=param[3];top=param[0];bottom=param[1];delay=param[2][;fadeawayheight=param[4]]
00142 };
00143 
00144 #define EF_NUMBEROFEFFECTS 5
00145 
00146 class Effect
00147 {
00148 public:
00149         enum eftype type;
00150         int param[8];
00151         int t[4];
00152 };
00153 
00154 class CSubtitle : public CList<CLine*>
00155 {
00156         int GetFullWidth();
00157         int GetFullLineWidth(POSITION pos);
00158         int GetWrapWidth(POSITION pos, int maxwidth);
00159         CLine* GetNextLine(POSITION& pos, int maxwidth);
00160 
00161 public:
00162         int m_scrAlignment;
00163         int m_wrapStyle;
00164         bool m_fAnimated;
00165         int m_relativeTo;
00166 
00167         Effect* m_effects[EF_NUMBEROFEFFECTS];
00168 
00169         CList<CWord*> m_words;
00170 
00171         CClipper* m_pClipper;
00172 
00173         CRect m_rect, m_clip;
00174         int m_topborder, m_bottomborder;
00175 
00176         double m_scalex, m_scaley;
00177 
00178 public:
00179         CSubtitle();
00180         virtual ~CSubtitle();
00181         virtual void Empty();
00182 
00183         void CreateClippers(CSize size);
00184 
00185         void MakeLines(CSize size, CRect marginRect);
00186 };
00187 
00188 class CScreenLayoutAllocator
00189 {
00190         typedef struct
00191         {
00192                 CRect r;
00193                 int segment, entry, layer;
00194         } SubRect;
00195 
00196         CList <SubRect, SubRect&> m_subrects;
00197 
00198 public:
00199         virtual void Empty();
00200 
00201         void AdvanceToSegment(int segment, const CSubArray& sa);
00202         CRect AllocRect(CSubtitle* s, int segment, int entry, int layer, int collisions);
00203 };
00204 
00205 [uuid("537DCACA-2812-4a4f-B2C6-1A34C17ADEB0")]
00206 class CRenderedTextSubtitle : public CSimpleTextSubtitle, public ISubPicProviderImpl, public ISubStream
00207 {
00208         CMap <int, int, CSubtitle*, CSubtitle*> m_subtitleCache;
00209 
00210         CScreenLayoutAllocator m_sla;
00211 
00212         CSize m_size;
00213         CRect m_vidrect;
00214 
00215         // temp variables, used when parsing the script
00216         int m_time, m_delay;
00217         int m_animStart, m_animEnd;
00218         double m_animAccel;
00219         int m_ktype, m_kstart, m_kend;
00220         int m_nPolygon;
00221         int m_polygonBaselineOffset;
00222 
00223         void ParseEffect(CSubtitle* sub, CString str);
00224         void ParseString(CSubtitle* sub, CStringW str, STSStyle& style);
00225         void ParsePolygon(CSubtitle* sub, CStringW str, STSStyle& style);
00226         bool ParseSSATag(CSubtitle* sub, CStringW str, STSStyle& style, STSStyle& org, bool fAnimate = false);
00227         bool ParseHtmlTag(CSubtitle* sub, CStringW str, STSStyle& style, STSStyle& org);
00228 
00229         double CalcAnimation(double dst, double src, bool fAnimate);
00230 
00231         CSubtitle* GetSubtitle(int entry);
00232 
00233 protected:
00234         virtual void OnChanged();
00235 
00236 public:
00237         CRenderedTextSubtitle(CCritSec* pLock);
00238         virtual ~CRenderedTextSubtitle();
00239 
00240         virtual void Copy(CSimpleTextSubtitle& sts);
00241         virtual void Empty();
00242 
00243 public:
00244         bool Init(CSize size, CRect vidrect); // will call Deinit()
00245         void Deinit();
00246 
00247         DECLARE_IUNKNOWN
00248     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00249 
00250         // ISubPicProvider
00251         STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps);
00252         STDMETHODIMP_(POSITION) GetNext(POSITION pos);
00253         STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
00254         STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
00255         STDMETHODIMP_(bool) IsAnimated(POSITION pos);
00256         STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
00257 
00258         // IPersist
00259         STDMETHODIMP GetClassID(CLSID* pClassID);
00260 
00261         // ISubStream
00262         STDMETHODIMP_(int) GetStreamCount();
00263         STDMETHODIMP GetStreamInfo(int i, WCHAR** ppName, LCID* pLCID);
00264         STDMETHODIMP_(int) GetStream();
00265         STDMETHODIMP SetStream(int iStream);
00266         STDMETHODIMP Reload();
00267 };

Generated on Tue Dec 13 14:47:54 2005 for guliverkli by  doxygen 1.4.5