]> git.vomp.tv Git - vompclient.git/blob - osdvector.h
Preparations for dynamic mode switching
[vompclient.git] / osdvector.h
1 /*\r
2     Copyright 2004-2005 Chris Tallon, 2006,2011-2012 Marten Richter\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 #ifndef OSDVECTOR_H\r
22 #define OSDVECTOR_H\r
23 #include "osd.h"\r
24 #include "mutex.h"\r
25 #include "colour.h"\r
26 #include <list>\r
27 #include <map>\r
28 #include <string>\r
29 \r
30 #include "teletextdecodervbiebu.h"\r
31 \r
32 enum SVGCommandInstr {\r
33         DrawPath,\r
34         DrawGlyph,\r
35         DrawImage,\r
36         DrawTTchar\r
37 };\r
38 enum PathIndex {\r
39         HorzLine,\r
40         VertLine,\r
41         Rectangle,\r
42         Point\r
43 };\r
44 \r
45 typedef  unsigned int ImageIndex;\r
46 \r
47 class SVGCommand\r
48 {\r
49 public:\r
50         SVGCommand(float ix, float iy,float iw,float ih,PathIndex path,unsigned int ref)\r
51         {\r
52                 instr=DrawPath;\r
53                 x=ix;\r
54                 y=iy;\r
55                 w=iw;\r
56                 h=ih;\r
57                 target.path_index=path;\r
58                 reference=ref;\r
59         };\r
60         SVGCommand(float ix, float iy,float iw,float ih,ImageIndex image_in,unsigned int ref)\r
61         {\r
62                 instr=DrawImage;\r
63                 x=ix;\r
64                 y=iy;\r
65                 w=iw;\r
66                 h=ih;\r
67                 target.image=image_in;\r
68                 reference=ref;\r
69         };\r
70         SVGCommand(float ix, float iy,float iw,float ih,unsigned int ttchar_in)\r
71         {\r
72                 instr=DrawTTchar;\r
73                 x=ix;\r
74                 y=iy;\r
75                 w=iw;\r
76                 h=ih;\r
77                 reference=0;\r
78                 target.ttchar=ttchar_in;\r
79         };\r
80         SVGCommand(float ix, float iy,wchar_t char_in,unsigned int ref)\r
81         {\r
82                 instr=DrawGlyph;\r
83                 x=ix;\r
84                 y=iy;\r
85                 w=0;\r
86                 h=0;\r
87                 reference=ref;\r
88                 target.textchar=char_in;\r
89         };\r
90 \r
91         bool Test(float tx,float ty,float tw, float th)\r
92         {\r
93                 return (x>=tx) && (y>=ty) && ((x+w)<=(tx+tw)) && ((y+h)<=(ty+th));\r
94         }\r
95         bool TTTest(float tox,float toy,float tx, float ty)\r
96         {\r
97                 return (x==tox) && (toy==y) && (w==tx) && (h==ty);\r
98         }\r
99         unsigned int getRef(){return reference;};\r
100         ImageIndex getImageIndex() {\r
101                 if (instr!=DrawImage) return 0;\r
102                 else return target.image;\r
103         };\r
104         SVGCommandInstr instr;\r
105         float x,y,w,h;\r
106         unsigned int reference;\r
107         union {\r
108                 PathIndex path_index; //path_index\r
109                 wchar_t textchar;\r
110                 ImageIndex image;\r
111                 unsigned int ttchar;\r
112         } target;\r
113 };\r
114 \r
115 class SurfaceVector;\r
116 \r
117 struct SurfaceCommands{\r
118         const SurfaceVector* surf;\r
119         list<SVGCommand> commands;\r
120         float x,y,w,h;\r
121 };\r
122 \r
123 \r
124 class OsdVector : public Osd\r
125 {\r
126   public:\r
127     OsdVector();\r
128     virtual ~OsdVector();\r
129 \r
130 \r
131     int restore();\r
132 \r
133     int getFD();\r
134 \r
135     void screenShot(const char* fileName);\r
136 \r
137     Surface * createNewSurface();\r
138         void BeginPainting();\r
139         void EndPainting();\r
140 \r
141         void Blank();\r
142 \r
143         void updateOrAddSurface(const SurfaceVector *surf,float x,float y,float height,float width,\r
144                         list<SVGCommand>& commands);\r
145         void removeSurface(const SurfaceVector *surf);\r
146 \r
147         virtual float getFontHeight()=0;\r
148         virtual float getCharWidth(wchar_t c)=0;\r
149 \r
150         virtual ImageIndex getJpegRef(const char* fileName, int *width,int *height);\r
151         virtual ImageIndex getMonoBitmapRef(void *base,int width,int height);\r
152         virtual ImageIndex getImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data);\r
153         virtual void imageUploadLine(ImageIndex index,unsigned int j,unsigned int width,void *data)=0;\r
154         void removeImageRef(const ImageIndex ref);\r
155         unsigned int getColorRef(const Colour &c); //internally this is the same as getStyleRef\r
156         unsigned int getStyleRef(const DrawStyle &c);\r
157         virtual void removeStyleRef(unsigned int ref);\r
158 \r
159 \r
160     int charSet() {return 2;}; //UTF-8\r
161 \r
162 \r
163 \r
164 protected:\r
165 \r
166         void incImageRef(ImageIndex index);\r
167         unsigned int getImageRef(ImageIndex index);\r
168         virtual void destroyImageRef(ImageIndex index)=0;\r
169         virtual ImageIndex createJpeg(const char* fileName, int *width,int *height)=0;\r
170         virtual ImageIndex createMonoBitmap(void *base,int width,int height)=0;\r
171         virtual ImageIndex createImagePalette(int width,int height,const unsigned char *image_data,const unsigned int*palette_data)=0;\r
172 \r
173         map<ImageIndex,unsigned int> images_ref;\r
174         map<void *,ImageIndex> monobitmaps;\r
175         map<string,ImageIndex> jpegs;\r
176 \r
177         void incStyleRef(unsigned int index);\r
178         unsigned int getStyleRef(ImageIndex index);\r
179         virtual void destroyStyleRef(unsigned int index)=0;\r
180         map<pair<Colour*,unsigned int>,unsigned int> styles;\r
181         map<unsigned int,unsigned int> styles_ref;\r
182         virtual unsigned int createStyleRef(const DrawStyle &c)=0;\r
183         virtual unsigned int createColorRef(const Colour &c)=0;\r
184 \r
185         void dereferenceSVGCommand(list<SVGCommand>& commands );\r
186         void referenceSVGCommand(list<SVGCommand>& commands );\r
187         void cleanupOrphanedRefs();\r
188 \r
189 \r
190 \r
191         virtual void drawSetTrans(SurfaceCommands & sc)=0;\r
192         virtual void executeDrawCommand(SVGCommand & command)=0;\r
193 \r
194 \r
195 \r
196 \r
197         list<SurfaceCommands> scommands;\r
198 \r
199         Mutex surfaces_mutex;\r
200 \r
201         void drawSurfaces();\r
202 };\r
203 \r
204 \r
205 \r
206 \r
207 #endif\r