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