]> git.vomp.tv Git - vompclient.git/blob - vquestion.cc
I18n
[vompclient.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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vquestion.h"
22
23 VQuestion::VQuestion()
24 {
25   mainText = NULL;
26   selectedOption = NO;
27
28   buttonYes.setSurfaceOffset(40, 120);
29   buttonNo.setSurfaceOffset(140, 120);
30
31   buttonYes.setText(tr("Yes"));
32   buttonNo.setText(tr("No"));
33   buttonNo.setActive(1);
34 }
35
36 VQuestion::~VQuestion()
37 {
38   if (mainText) delete[] mainText;
39 }
40
41 void VQuestion::setMainText(char* takeText)
42 {
43   int length = strlen(takeText);
44   mainText = new char[length + 1];
45   strcpy(mainText, takeText);
46 }
47
48 void VQuestion::draw()
49 {
50   View::draw();
51
52   buttonYes.setSurface(surface);
53   buttonNo.setSurface(surface);
54
55   if (mainText) drawPara(mainText, 10, 45, Colour::LIGHTTEXT);
56   buttonYes.draw();
57   buttonNo.draw();
58 }
59
60 void VQuestion::swap()
61 {
62   if (selectedOption == NO)
63   {
64     selectedOption = YES;
65     buttonYes.setActive(1);
66     buttonNo.setActive(0);
67   }
68   else if (selectedOption == YES)
69   {
70     selectedOption = NO;
71     buttonYes.setActive(0);
72     buttonNo.setActive(1);
73   }
74 }
75
76 int VQuestion::handleCommand(int command)
77 {
78   switch(command)
79   {
80     case Remote::DF_LEFT:
81     case Remote::LEFT:
82     {
83       swap();
84       draw();
85       show();
86       return 2;
87     }
88     case Remote::DF_RIGHT:
89     case Remote::RIGHT:
90     {
91       swap();
92       draw();
93       show();
94       return 2;
95     }
96     case Remote::BACK:
97     {
98       return 4;
99     }
100     case Remote::OK:
101     {
102       if (selectedOption != YES) return 4;
103
104       Message* m = new Message();
105       m->from = this;
106       m->to = parent;
107       m->message = Message::QUESTION_YES;
108       ViewMan::getInstance()->postMessage(m);
109
110       return 4;
111     }
112   }
113   return 1;
114 }
115
116 void VQuestion::setDefault(UCHAR option)
117 {
118   selectedOption = option;
119 }