]> git.vomp.tv Git - vompclient.git/blob - vcolourtuner.cc
Fix skip and fast forward
[vompclient.git] / vcolourtuner.cc
1 /*\r
2     Copyright 2004-2005 Chris Tallon, Andreas Vogel\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 #include "vcolourtuner.h"\r
22 \r
23 #include "wsymbol.h"\r
24 #include "remote.h"\r
25 #include "colour.h"\r
26 #include "video.h"\r
27 #include "vinfo.h"\r
28 #include "boxstack.h"\r
29 #include "i18n.h"\r
30 #include "log.h"\r
31 #include "mediaoptions.h"\r
32 \r
33 #define PICTUREFILE "/colourtest.jpg"\r
34 \r
35 int VColourTuner::rfactor=100;\r
36 int VColourTuner::gfactor=100;\r
37 int VColourTuner::bfactor=100;\r
38 \r
39 VColourTuner::VColourTuner()\r
40 {\r
41   int sw= Video::getInstance()->getScreenWidth();\r
42   int sh= Video::getInstance()->getScreenHeight();\r
43   setSize(sw-80,sh-40);\r
44   setPosition((sw-area.w)/2, (sh-area.h)/2);\r
45   createBuffer();\r
46   setTitleBarOn(0);\r
47   picture.setPosition(160,60);\r
48   add(&picture);\r
49   drawPicture=true;\r
50   vrfactor=rfactor;\r
51   vbfactor=bfactor;\r
52   vgfactor=gfactor;\r
53   hasChanged=false;\r
54   Log::getInstance()->log("VColourTuner",Log::DEBUG,"created %p",this);\r
55 }\r
56 \r
57 VColourTuner::~VColourTuner()\r
58 {\r
59   Log::getInstance()->log("VColourTuner",Log::DEBUG,"deleted %p",this);\r
60 }\r
61 \r
62 void VColourTuner::drawBox(int x, int y, int w, int h, Colour &c) {\r
63   for (int row=y;row<y+h;row++)\r
64     for (int col=x;col<x+w;col++) {\r
65       surface->drawPixel(col,row,c);\r
66     }\r
67 }\r
68 \r
69 \r
70 void VColourTuner::draw()\r
71 {\r
72     //do not call base classes draw to avoid drawing the picture...\r
73     Log::getInstance()->log("VColourTuner::draw",Log::DEBUG,"dp %s, rf=%d, gf=%d, bf=%d",\r
74         (drawPicture?"true":"false"),vrfactor,vgfactor,vbfactor);\r
75     char valbuf[20];\r
76     int x=20;\r
77     int y=20;\r
78     int bw=50;\r
79     int bh=50;\r
80     int picx=picture.getX();\r
81     Colour bc=Colour(140,140,140);\r
82     fillColour(bc);\r
83     bc=Colour(255,255,255);\r
84     drawText(tr("Colour Tuning"), x+20, y+5, Colour::LIGHTTEXT);\r
85     drawBox(x, y+50, bw, bh, Colour::RED);\r
86     drawBox(x, y+130, bw, bh, Colour::GREEN);\r
87     drawBox(x, y+190, bw, bh, Colour::BLUE);\r
88     drawBox(x, y+270, bw, bh, bc);\r
89     sprintf(valbuf,"%03d%%",vrfactor);\r
90     drawText(valbuf,x+bw+x,y+50, Colour::LIGHTTEXT);\r
91     drawText("<1 2>",x+bw+x,y+74, Colour::LIGHTTEXT);\r
92     sprintf(valbuf,"%03d%%",vgfactor);\r
93     drawText(valbuf,x+bw+x,y+120, Colour::LIGHTTEXT);\r
94     drawText("<4 5>",x+bw+x,y+144, Colour::LIGHTTEXT);\r
95     sprintf(valbuf,"%03d%%",vbfactor);\r
96     drawText(valbuf,x+bw+x,y+190, Colour::LIGHTTEXT);\r
97     drawText("<7 8>",x+bw+x,y+214, Colour::LIGHTTEXT);\r
98     sprintf(valbuf,"%03d%%",(vbfactor+vgfactor+vrfactor)/3);\r
99     drawText(valbuf,x+bw+x,y+270, Colour::LIGHTTEXT);\r
100     drawText("<3 6>",x+bw+x,y+294, Colour::LIGHTTEXT);\r
101     drawText("9 norm",x+bw+x,y+318, Colour::LIGHTTEXT);\r
102     drawText(tr("OK to save, BACK to cancel"), x+20, area.h - 50, Colour::LIGHTTEXT);\r
103     if (drawPicture) {\r
104       hasChanged=false;\r
105       picture.init(PICTUREFILE);\r
106       picture.draw();\r
107       drawPicture=false;\r
108     }\r
109     int picy=picture.getY();\r
110     int pich=picture.getHeight();\r
111     if (hasChanged) drawText(tr("0 to draw picture"), picx+30, picy+pich+10, Colour::LIGHTTEXT);\r
112 }\r
113 \r
114 int VColourTuner::handleCommand(int command)\r
115 {\r
116   int rt=0;\r
117   switch(command) {\r
118       case Remote::ONE:\r
119       updateFactor(1,-1);\r
120       rt=2;\r
121       hasChanged=true;\r
122       break;\r
123     case Remote::TWO:\r
124       updateFactor(1,1);\r
125       rt=2;\r
126       hasChanged=true;\r
127       break;\r
128     case Remote::FOUR:\r
129       updateFactor(2,-1);\r
130       rt=2;\r
131       hasChanged=true;\r
132       break;\r
133     case Remote::FIVE:\r
134       updateFactor(2,1);\r
135       rt=2;\r
136       hasChanged=true;\r
137       break;\r
138     case Remote::SEVEN:\r
139       updateFactor(3,-1);\r
140       rt=2;\r
141       hasChanged=true;\r
142       break;\r
143     case Remote::EIGHT:\r
144       updateFactor(3,1);\r
145       hasChanged=true;\r
146       rt=2;\r
147       break;\r
148     case Remote::THREE:\r
149       updateFactor(4,-1);\r
150       hasChanged=true;\r
151       rt=2;\r
152       break;\r
153     case Remote::SIX:\r
154       updateFactor(4,1);\r
155       hasChanged=true;\r
156       rt=2;\r
157       break;\r
158     case Remote::NINE:\r
159       updateFactor(5,0);\r
160       hasChanged=true;\r
161       rt=2;\r
162       break;\r
163     case Remote::ZERO:\r
164       drawPicture=true;\r
165       rt=2;\r
166       break;\r
167     case Remote::BACK:\r
168       vrfactor=rfactor;\r
169       vgfactor=gfactor;\r
170       vbfactor=bfactor;\r
171 #ifndef WIN32\r
172 #ifndef _MIPS_ARCH\r
173 #ifndef __ANDROID__\r
174     ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);\r
175 #endif\r
176 #endif\r
177 #endif\r
178       rt=4;\r
179       break;\r
180     case Remote::OK:\r
181       rfactor=vrfactor;\r
182       gfactor=vgfactor;\r
183       bfactor=vbfactor;\r
184       MediaOptions::getInstance()->setIntOption("FactorRed",rfactor);\r
185       MediaOptions::getInstance()->setIntOption("FactorGreen",gfactor);\r
186       MediaOptions::getInstance()->setIntOption("FactorBlue",bfactor);\r
187       rt=4;\r
188       break;\r
189   }\r
190   if (rt == 2) {\r
191 #ifndef WIN32\r
192 #ifndef _MIPS_ARCH\r
193 #ifndef __ANDROID__\r
194     ((Surface_TYPE *)surface)->initConversionTables(vrfactor,vgfactor,vbfactor);\r
195 #endif\r
196 #endif\r
197 #endif\r
198     bool updateAll=drawPicture;\r
199     draw();\r
200     if (updateAll) {\r
201       BoxStack::getInstance()->update(this);\r
202     }\r
203     else {\r
204       Region r;\r
205       r.x=0;\r
206       r.w=picture.getX()-1;\r
207       r.y=0;\r
208       r.h=area.h;\r
209       BoxStack::getInstance()->update(this,&r);\r
210       r.x=picture.getX();\r
211       r.y=picture.getY();\r
212       r.h=area.h-r.y;\r
213       r.w=area.w-picture.getX();\r
214       BoxStack::getInstance()->update(this,&r);\r
215     }\r
216   }\r
217   return rt;\r
218 }\r
219 \r
220 \r
221 \r
222 void VColourTuner::processMessage(Message* m)\r
223 {\r
224   if (m->message == Message::MOUSE_MOVE)\r
225   {\r
226     \r
227   }\r
228   else if (m->message == Message::MOUSE_LBDOWN)\r
229   {\r
230     //check if press is outside this view! then simulate cancel\r
231     int x=(m->parameter>>16)-getScreenX();\r
232     int y=(m->parameter&0xFFFF)-getScreenY();\r
233     if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())\r
234     {\r
235       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press\r
236     }\r
237     else if (y>=(int)area.h-24 && y<=(int)area.h-6)\r
238     {\r
239       ;\r
240     }\r
241   }\r
242 }\r
243 \r
244 void VColourTuner::updateFactor(int color, int amount) {\r
245   switch (color) {\r
246     case 1:\r
247       vrfactor+=amount;\r
248       if (vrfactor < 20 ) vrfactor=20;\r
249       if (vrfactor > 200) vrfactor=200;\r
250       break;\r
251     case 2:\r
252       vgfactor+=amount;\r
253       if (vgfactor < 20 ) vgfactor=20;\r
254       if (vgfactor > 200) vgfactor=200;\r
255       break;\r
256     case 3:\r
257       vbfactor+=amount;\r
258       if (vbfactor < 20 ) vbfactor=20;\r
259       if (vbfactor > 200) vbfactor=200;\r
260       break;\r
261     case 4:\r
262       updateFactor(1,amount);\r
263       updateFactor(2,amount);\r
264       updateFactor(3,amount);\r
265       break;\r
266     case 5:\r
267       while ((vrfactor+vbfactor+vgfactor) > 300) updateFactor(4,-1);\r
268       while ((vrfactor+vbfactor+vgfactor) < 300) updateFactor(4,1);\r
269   }\r
270 }\r
271 \r
272 void VColourTuner::initFactors(){\r
273   MediaOptions * options=MediaOptions::getInstance();\r
274   int rf=options->getIntOption("FactorRed");\r
275   int gf=options->getIntOption("FactorGreen");\r
276   int bf=options->getIntOption("FactorBlue");\r
277   if (rf >= 20 && bf >= 20 && gf >= 20)\r
278   rfactor=rf;\r
279   gfactor=gf;\r
280   bfactor=bf;\r
281   Log::getInstance()->log("VColourTuner",Log::DEBUG,"setting initial factors r=%d,g=%d,b=%d",rf,gf,bf);\r
282 #ifndef __ANDROID__\r
283 #ifndef WIN32\r
284 #ifndef _MIPS_ARCH\r
285   Surface_TYPE::initConversionTables(rfactor,gfactor,bfactor);\r
286 #endif\r
287 #endif\r
288 #endif\r
289 }\r