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