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