]> git.vomp.tv Git - vompclient-marten.git/blob - vquestion.cc
Fix bug in demuxer widescreen signaling
[vompclient-marten.git] / vquestion.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
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 "vquestion.h"
22
23 #include "remote.h"
24 #include "boxstack.h"
25 #include "colour.h"
26 #include "i18n.h"
27 #include "command.h"
28
29 VQuestion::VQuestion(void* treplyTo)
30 {
31   replyTo = treplyTo;
32   mainText = NULL;
33   selectedOption = NO;
34
35   buttonYes.setPosition(40, 130);
36   buttonNo.setPosition(140, 130);
37
38   buttonYes.setText(tr("Yes"));
39   buttonNo.setText(tr("No"));
40   buttonNo.setActive(1);
41   
42   add(&buttonYes);
43   add(&buttonNo);  
44 }
45
46 VQuestion::~VQuestion()
47 {
48   if (mainText) delete[] mainText;
49 }
50
51 void VQuestion::setMainText(const char* takeText)
52 {
53   int length = strlen(takeText);
54   mainText = new char[length + 1];
55   strcpy(mainText, takeText);
56 }
57
58 void VQuestion::draw()
59 {
60   TBBoxx::draw();
61
62   if (mainText) drawPara(mainText, 10, 45, DrawStyle::LIGHTTEXT);
63 }
64
65 void VQuestion::swap()
66 {
67   if (selectedOption == NO)
68   {
69     selectedOption = YES;
70     buttonYes.setActive(1);
71     buttonNo.setActive(0);
72   }
73   else if (selectedOption == YES)
74   {
75     selectedOption = NO;
76     buttonYes.setActive(0);
77     buttonNo.setActive(1);
78   }
79 }
80
81 int VQuestion::handleCommand(int command)
82 {
83   switch(command)
84   {
85     case Remote::DF_LEFT:
86     case Remote::LEFT:
87     {
88       swap();
89       draw();
90       BoxStack::getInstance()->update(this);
91       return 2;
92     }
93     case Remote::DF_RIGHT:
94     case Remote::RIGHT:
95     {
96       swap();
97       draw();
98       BoxStack::getInstance()->update(this);
99       return 2;
100     }
101     case Remote::BACK:
102     {
103       return 4;
104     }
105     case Remote::OK:
106     {
107       if (selectedOption != YES) return 4;
108
109       Message* m = new Message(); // Question/answer mech
110       m->from = this;
111       m->to = replyTo;
112       m->message = Message::QUESTION_YES;
113       Command::getInstance()->postMessageNoLock(m);
114
115       return 4;
116     }
117   }
118   return 1;
119 }
120
121 void VQuestion::setDefault(UCHAR option)
122 {
123   selectedOption = option;
124 }
125
126 void VQuestion::processMessage(Message* m)
127 {
128   if (m->message == Message::MOUSE_MOVE)
129   {
130     if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
131     {
132       buttonNo.setActive(0);
133       selectedOption = YES;
134       draw();
135       BoxStack::getInstance()->update(this);
136     }
137     else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
138     {
139       buttonYes.setActive(0);
140       selectedOption = NO;
141       draw();
142       BoxStack::getInstance()->update(this);
143     }
144   }
145   else if (m->message == Message::MOUSE_LBDOWN)
146   {
147     if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
148     {
149       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
150     }
151     else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
152     {
153       BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
154     }
155     else
156     {
157       //check if press is outside this view! then simulate cancel
158       int x=(m->parameter>>16)-getScreenX();
159       int y=(m->parameter&0xFFFF)-getScreenY();
160       if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
161       {
162         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
163       }
164     }
165   }
166 }