00001 #ifndef OSDDATATYPES_H_
00002 #define OSDDATATYPES_H_
00003
00004 #include <qstring.h>
00005 #include <qrect.h>
00006 #include <qmap.h>
00007 #include <qvaluelist.h>
00008 #include <vector>
00009 #include <qobject.h>
00010 #include <qregexp.h>
00011 #include <cmath>
00012 #include <qcolor.h>
00013 #include "cc708window.h"
00014 #include "osdimagecache.h"
00015
00016 using namespace std;
00017
00018 class TTFFont;
00019 class OSDType;
00020 class OSDTypeText;
00021 class OSDSurface;
00022 class TV;
00023
00024 typedef QMap<QString,QString> InfoMap;
00025 typedef QMap<int,uint> HotKeyMap;
00026
00027 static inline QRect unbias(QRect rect, float wmult, float hmult)
00028 {
00029 return QRect((int)round(rect.x() / wmult),
00030 (int)round(rect.y() / hmult),
00031 (int)ceil( rect.width() / wmult),
00032 (int)ceil( rect.height() / hmult));
00033 }
00034
00035 static inline QRect bias(QRect rect, float wmult, float hmult)
00036 {
00037 return QRect((int)round(rect.x() * wmult),
00038 (int)round(rect.y() * hmult),
00039 (int)ceil( rect.width() * wmult),
00040 (int)ceil( rect.height() * hmult));
00041 }
00042
00043 class OSDSet : public QObject
00044 {
00045 Q_OBJECT
00046 public:
00047 OSDSet(const QString &name, bool cache, int screenwidth, int screenheight,
00048 float wmult, float hmult, int frint, int xoff=0, int yoff=0);
00049 OSDSet(const OSDSet &other);
00050 ~OSDSet();
00051
00052 void Clear(void);
00053 void ClearAllText(void);
00054 void AddType(OSDType *type);
00055 void Draw(OSDSurface *surface, bool actuallydraw);
00056 void Display(bool onoff = true, int osdFunctionalType = 0);
00057 void DisplayFor(int time, int osdFunctionalType = 0);
00058 void Hide(void);
00059 bool HandleKey(const QKeyEvent *e, bool *focus_change = NULL,
00060 QString *button_pressed = NULL);
00061 QString HandleHotKey(const QKeyEvent *e);
00062
00063 void Reinit(int screenwidth, int screenheight,
00064 int xoff, int yoff,
00065 int displaywidth, int displayheight,
00066 float wmult, float hmult,
00067 int frint);
00068
00069 bool NeedsUpdate(void) { return m_needsupdate; }
00070
00071
00072 QString GetName(void) const { return m_name; }
00073 bool GetCache(void) const { return m_cache; }
00074 bool GetAllowFade(void) const { return m_allowfade; }
00075 int GetPriority(void) const { return m_priority; }
00076 bool Displaying(void) const { return m_displaying; }
00077 bool HasDisplayed(void) const { return m_hasdisplayed; }
00078 int GetFadeTime(void) const { return m_fadetime; }
00079 bool IsFading(void) const
00080 { return (m_fadetime > 0) && (m_timeleft <= 0); }
00081 int GetTimeLeft(void) const { return m_timeleft; }
00082 int GetFrameInterval(void) const { return m_frameint; }
00083 void GetText(InfoMap &infoMap) const;
00084 bool CanShowWith(const QString &name) const;
00085
00086 const OSDType *GetType(const QString &name) const;
00087 const OSDTypeText *GetSelected(void) const;
00088
00089
00090 OSDType *GetType(const QString &name);
00091 OSDTypeText *GetSelected(void);
00092
00093
00094 void SetFadeTime(int time) { m_fadetime = m_maxfade = time; }
00095 void SetCache(bool cache) { m_cache = cache; }
00096 void SetName(const QString &name) { m_name = name; }
00097 void SetAllowFade(bool allow) { m_allowfade = allow; }
00098 void SetPriority(int priority) { m_priority = priority; }
00099 void SetFadeMovement(int x, int y) { m_xmove = x; m_ymove = y; }
00100 void SetFrameInterval(int frint) { m_frameint = frint; }
00101 void SetWantsUpdates(bool updates) { m_wantsupdates = updates; }
00102 void SetDrawEveryFrame(bool draw) { m_draweveryframe = draw; }
00103 void SetShowWith(const QString &re) { m_showwith = re; };
00104 bool SetSelected(int index);
00105 void SetText(const InfoMap &infoMap);
00106
00107 signals:
00108 void OSDClosed(int);
00109
00110 protected:
00111 int m_screenwidth;
00112 int m_screenheight;
00113 int m_frameint;
00114 float m_wmult;
00115 float m_hmult;
00116
00117 bool m_cache;
00118 QString m_name;
00119
00120 bool m_notimeout;
00121
00122 bool m_hasdisplayed;
00123 int m_timeleft;
00124 bool m_displaying;
00125 int m_fadetime;
00126 int m_maxfade;
00127
00128 int m_priority;
00129
00130 int m_xmove;
00131 int m_ymove;
00132
00133 int m_xoff;
00134 int m_yoff;
00135
00136 int m_xoffsetbase;
00137 int m_yoffsetbase;
00138
00139 bool m_allowfade;
00140
00141 QMap<QString, OSDType *> typeList;
00142 vector<OSDType *> *allTypes;
00143
00144 bool m_wantsupdates;
00145 bool m_needsupdate;
00146 int m_lastupdate;
00147
00148 int currentOSDFunctionalType;
00149
00150 bool m_draweveryframe;
00151
00152 QRegExp m_showwith;
00153 };
00154
00155 class OSDType : public QObject
00156 {
00157 Q_OBJECT
00158 public:
00159 OSDType(const QString &name);
00160
00161 void SetParent(OSDSet *parent) { m_parent = parent; }
00162 void Hide(bool hidden = true) { m_hidden = hidden; }
00163 bool isHidden(void) { return m_hidden; }
00164
00165 QString Name();
00166
00167 virtual void Reinit(float wmult, float hmult) = 0;
00168
00169 virtual void Draw(OSDSurface *surface, int fade, int maxfade, int xoff,
00170 int yoff) = 0;
00171
00172 protected:
00173 virtual ~OSDType();
00174
00175 protected:
00176 mutable QMutex m_lock;
00177 bool m_hidden;
00178 QString m_name;
00179 OSDSet *m_parent;
00180 };
00181
00182 class DrawInfo
00183 {
00184 public:
00185 DrawInfo(const QString &_msg, uint _width, bool _hilite)
00186 : msg(_msg), width(_width), hilite(_hilite) {}
00187
00188 public:
00189 QString msg;
00190 uint width;
00191 bool hilite;
00192 };
00193
00194 class OSDTypeText : public OSDType
00195 {
00196 public:
00197 OSDTypeText(const QString &name, TTFFont *font, const QString &text,
00198 QRect displayrect, float wmult, float hmult);
00199 OSDTypeText(const OSDTypeText &text);
00200
00201 void Reinit(float wmult, float hmult);
00202
00203 void SetAltFont(TTFFont *font);
00204 void SetUseAlt(bool usealt) { m_usingalt = usealt; }
00205
00206 void SetText(const QString &text);
00207 QString GetText(void) const;
00208
00209 void SetDefaultText(const QString &text);
00210 QString GetDefaultText(void) const;
00211
00212 void SetMultiLine(bool multi);
00213 bool GetMultiLine(void) const { return m_multiline; }
00214
00215 void SetCentered(bool docenter);
00216 bool GetCentered(void) const { return m_centered; }
00217
00218 void SetRightJustified(bool right);
00219 bool GetRightJustified(void) const { return m_right; }
00220
00221 void SetScrolling(int x, int y);
00222
00223 void SetLineSpacing(float linespacing);
00224 float GetLineSpacing(void) const { return m_linespacing; }
00225
00226 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00227 bool MoveCursor(int dir);
00228 bool Delete(int dir);
00229 void InsertCharacter(QChar);
00230
00231 bool IsSelected(void) const { return m_selected; }
00232 bool IsButton(void) const { return m_button; }
00233 int GetEntryNum(void) const { return m_entrynum; }
00234 bool IsEntry(void) const { return m_entrynum >= 0; }
00235 QRect DisplayArea(void) const { return m_displaysize; }
00236
00237 void SetSelected(bool is_selected) { m_selected = is_selected; }
00238 void SetButton(bool is_button) { m_button = is_button; }
00239 void SetEntryNum(int entrynum) { m_entrynum = entrynum; }
00240
00241 QString ConvertFromRtoL(const QString &text) const;
00242
00243 static QString BasicConvertFromRtoL(const QString &text);
00244
00245 protected:
00246 ~OSDTypeText();
00247
00248 void DrawString(OSDSurface *surface, QRect rect, const QString &text,
00249 int fade, int maxfade, int xoff, int yoff,
00250 bool double_size=false);
00251 void DrawHiLiteString(OSDSurface *surface, QRect xrect,
00252 const QString &text, int fade, int maxfade,
00253 int xoff, int yoff, bool double_size = false);
00254
00255 QRect m_displaysize;
00256 QRect m_screensize;
00257 QRect m_unbiasedsize;
00258 QString m_message;
00259 QString m_default_msg;
00260
00261 TTFFont *m_font;
00262 TTFFont *m_altfont;
00263
00264 bool m_centered;
00265 bool m_right;
00266
00267 bool m_multiline;
00268 bool m_usingalt;
00269
00270 bool m_selected;
00271 bool m_button;
00272 int m_entrynum;
00273 int m_cursorpos;
00274
00275 bool m_scroller;
00276 int m_scrollx;
00277 int m_scrolly;
00278
00279 int m_scrollstartx;
00280 int m_scrollendx;
00281 int m_scrollposx;
00282
00283 int m_scrollstarty;
00284 int m_scrollendy;
00285 int m_scrollposy;
00286
00287 bool m_scrollinit;
00288
00289 float m_linespacing;
00290
00291 mutable QString m_draw_info_str;
00292 mutable uint m_draw_info_len;
00293 mutable vector<DrawInfo> m_draw_info;
00294
00295 mutable QMutex fribidi_lock;
00296 mutable QTextCodec *codeci;
00297 };
00298
00299 class OSDTypeImage : public OSDType
00300 {
00301 public:
00302 OSDTypeImage(const QString &name, const QString &filename,
00303 QPoint displaypos, float wmult, float hmult, int scalew = -1,
00304 int scaleh = -1);
00305 OSDTypeImage(const OSDTypeImage &other);
00306 OSDTypeImage(const QString &name);
00307 OSDTypeImage(void);
00308 virtual ~OSDTypeImage();
00309
00310 void SetName(const QString &name);
00311 void Reinit(float wmult, float hmult);
00312
00313 void Load(const QString &filename, float wmult, float hmult,
00314 int scalew = -1, int scaleh = -1, bool usecache = true);
00315 void Load(const QImage &img);
00316
00317 void SetStaticSize(int scalew, int scaleh) { m_scalew = scalew;
00318 m_scaleh = scaleh; }
00319 void SetPosition(QPoint pos, float wmult, float hmult);
00320
00321 QPoint DisplayPos() const { return m_displaypos; }
00322 QRect ImageSize() const { return m_imagesize; }
00323 int width() const { return m_imagesize.width(); }
00324 int height() const { return m_imagesize.height(); }
00325
00326 virtual void Draw(OSDSurface *surface, int fade, int maxfade, int xoff,
00327 int yoff);
00328
00329 void SetDontRoundPosition(bool round) { m_dontround = round; }
00330
00331 protected:
00332 QRect m_imagesize;
00333 QPoint m_displaypos;
00334 QPoint m_unbiasedpos;
00335
00336 QString m_filename;
00337
00338 bool m_isvalid;
00339
00340 unsigned char *m_yuv;
00341 unsigned char *m_ybuffer;
00342 unsigned char *m_ubuffer;
00343 unsigned char *m_vbuffer;
00344
00345 unsigned char *m_alpha;
00346
00347 int m_scalew, m_scaleh;
00348
00349 int m_drawwidth;
00350 bool m_onlyusefirst;
00351 bool m_dontround;
00352
00353 static OSDImageCache c_cache;
00354 OSDImageCacheValue *m_cacheitem;
00355 };
00356
00357 class OSDTypePosSlider : public OSDTypeImage
00358 {
00359 public:
00360 OSDTypePosSlider(const QString &name, const QString &filename,
00361 QRect displayrect, float wmult, float hmult,
00362 int scalew = -1, int scaleh = -1);
00363 ~OSDTypePosSlider();
00364
00365 void Reinit(float wmult, float hmult);
00366
00367 void SetRectangle(QRect rect) { m_displayrect = rect; }
00368 QRect ImageSize() { return m_imagesize; }
00369
00370 void SetPosition(int pos);
00371 int GetPosition() { return m_curval; }
00372
00373 private:
00374 QRect m_displayrect;
00375 QRect m_unbiasedrect;
00376 int m_maxval;
00377 int m_curval;
00378 };
00379
00380 class OSDTypeFillSlider : public OSDTypeImage
00381 {
00382 public:
00383 OSDTypeFillSlider(const QString &name, const QString &filename,
00384 QRect displayrect, float wmult, float hmult,
00385 int scalew = -1, int scaleh = -1);
00386 ~OSDTypeFillSlider();
00387
00388 void Reinit(float wmult, float hmult);
00389
00390 void SetRectangle(QRect rect) { m_displayrect = rect; }
00391 QRect ImageSize() { return m_imagesize; }
00392
00393 void SetPosition(int pos);
00394 int GetPosition() { return m_curval; }
00395
00396 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00397
00398 private:
00399 QRect m_displayrect;
00400 QRect m_unbiasedrect;
00401 int m_maxval;
00402 int m_curval;
00403 };
00404
00405 class OSDTypeEditSlider : public OSDTypeImage
00406 {
00407 public:
00408 OSDTypeEditSlider(const QString &name, const QString &bluefilename,
00409 const QString &redfilename, QRect displayrect,
00410 float wmult, float hmult,
00411 int scalew = -1, int scaleh = -1);
00412 ~OSDTypeEditSlider();
00413
00414 void Reinit(float wmult, float hmult);
00415
00416 void SetRectangle(QRect rect) { m_displayrect = rect; }
00417 QRect ImageSize() { return m_imagesize; }
00418
00419 void ClearAll(void);
00420 void SetRange(int start, int end);
00421
00422 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00423
00424 private:
00425 QRect m_displayrect;
00426 QRect m_unbiasedrect;
00427 int m_maxval;
00428 int m_curval;
00429
00430 unsigned char *m_drawMap;
00431
00432 bool m_risvalid;
00433 unsigned char *m_ryuv;
00434 unsigned char *m_rybuffer;
00435 unsigned char *m_rubuffer;
00436 unsigned char *m_rvbuffer;
00437 unsigned char *m_ralpha;
00438 QRect m_rimagesize;
00439
00440 QString m_redname;
00441 QString m_bluename;
00442 };
00443
00444
00445 class OSDTypeBox : public OSDType
00446 {
00447 public:
00448 OSDTypeBox(const QString &name, QRect displayrect,
00449 float wmult, float hmult);
00450 OSDTypeBox(const OSDTypeBox &other);
00451 ~OSDTypeBox();
00452
00453 void Reinit(float wmult, float hmult);
00454 void SetRect(QRect newrect, float wmult, float hmult);
00455
00456 void Draw(OSDSurface *surface, int fade, int maxfade,
00457 int xoff, int yoff, unsigned int alpha);
00458
00459 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff)
00460 { Draw(surface, fade, maxfade, xoff, yoff, 192); }
00461
00462 void SetColor(QColor c) { m_color = c; }
00463 private:
00464 QRect size;
00465 QRect m_unbiasedsize;
00466 QColor m_color;
00467 };
00468
00469 class OSDTypePositionIndicator
00470 {
00471 public:
00472 OSDTypePositionIndicator(void);
00473 OSDTypePositionIndicator(const OSDTypePositionIndicator &other);
00474 ~OSDTypePositionIndicator();
00475
00476 void SetOffset(int offset) { m_offset = offset; }
00477 int GetOffset(void) { return m_offset; }
00478
00479 int GetPosition() { return m_curposition - m_offset; }
00480 void SetPosition(int pos);
00481
00482 void PositionUp();
00483 void PositionDown();
00484
00485 protected:
00486 int m_numpositions;
00487 int m_curposition;
00488 int m_offset;
00489 };
00490
00491 class OSDTypePositionRectangle : public OSDType,
00492 public OSDTypePositionIndicator
00493 {
00494 public:
00495 OSDTypePositionRectangle(const QString &name);
00496 OSDTypePositionRectangle(const OSDTypePositionRectangle &other);
00497 ~OSDTypePositionRectangle();
00498
00499 void AddPosition(QRect rect, float wmult, float hmult);
00500
00501 void Reinit(float wmult, float hmult);
00502
00503 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00504
00505 private:
00506 vector<QRect> positions;
00507 vector<QRect> unbiasedpos;
00508 };
00509
00510 class OSDTypePositionImage : public virtual OSDTypeImage,
00511 public OSDTypePositionIndicator
00512 {
00513 public:
00514 OSDTypePositionImage(const QString &name);
00515 OSDTypePositionImage(const OSDTypePositionImage &other);
00516 ~OSDTypePositionImage();
00517
00518 void Reinit(float wmult, float hmult);
00519
00520 void AddPosition(QPoint pos, float wmult, float hmult);
00521
00522 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00523
00524 private:
00525 vector<QPoint> positions;
00526 vector<QPoint> unbiasedpos;
00527 float m_wmult;
00528 float m_hmult;
00529 };
00530
00531 class ccText
00532 {
00533 public:
00534 QString text;
00535 int x;
00536 int y;
00537 int color;
00538 bool teletextmode;
00539 };
00540
00541 class OSDTypeCC : public OSDType
00542 {
00543 public:
00544 OSDTypeCC(const QString &name, TTFFont *font, int xoff, int yoff,
00545 int dispw, int disph, float wmult, float hmult);
00546 ~OSDTypeCC();
00547
00548 void Reinit(float wmult, float hmult);
00549
00550 void Reinit(int xoff, int yoff,
00551 int dispw, int disph,
00552 float wmult, float hmult);
00553
00554 void AddCCText(const QString &text, int x, int y, int color,
00555 bool teletextmode = false);
00556 void ClearAllCCText();
00557 int UpdateCCText(vector<ccText*> *ccbuf,
00558 int replace = 0, int scroll = 0, bool scroll_prsv = false,
00559 int scroll_yoff = 0, int scroll_ymax = 15);
00560
00561 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00562
00563 private:
00564 TTFFont *m_font;
00565 vector<ccText *> *m_textlist;
00566 OSDTypeBox *m_box;
00567 int m_ccbackground;
00568 float m_wmult, m_hmult;
00569 int xoffset, yoffset, displaywidth, displayheight;
00570 };
00571
00572 class OSDType708CC : public OSDType
00573 {
00574 public:
00575 OSDType708CC(const QString &name, TTFFont *fonts[48],
00576 int xoff, int yoff, int dispw, int disph);
00577 virtual ~OSDType708CC() {}
00578
00579 void Reinit(float, float) {}
00580 void Reinit(int xoff, int yoff, int dispw, int disph);
00581
00582 void SetCCService(const CC708Service *service)
00583 { cc708data = service; }
00584
00585 void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
00586
00587 private:
00588 QRect CalcBounds(const OSDSurface*, const CC708Window&,
00589 const vector<CC708String*>&, uint &min_offset);
00590 void Draw(OSDSurface*, const QPoint&,
00591 const CC708Window&, const vector<CC708String*>&);
00592
00593 const CC708Service *cc708data;
00594
00595 TTFFont *m_fonts[48];
00596
00597 int xoffset, yoffset, displaywidth, displayheight;
00598 };
00599
00600 #endif