2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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
21 #include "vquestion.h"
29 VQuestion::VQuestion(void* treplyTo)
35 buttonYes.setPosition(40, 130);
36 buttonNo.setPosition(140, 130);
38 buttonYes.setText(tr("Yes"));
39 buttonNo.setText(tr("No"));
40 buttonNo.setActive(1);
46 VQuestion::~VQuestion()
48 if (mainText) delete[] mainText;
51 void VQuestion::setMainText(const char* takeText)
53 int length = strlen(takeText);
54 mainText = new char[length + 1];
55 strcpy(mainText, takeText);
58 void VQuestion::draw()
62 if (mainText) drawPara(mainText, 10, 45, Colour::LIGHTTEXT);
65 void VQuestion::swap()
67 if (selectedOption == NO)
70 buttonYes.setActive(1);
71 buttonNo.setActive(0);
73 else if (selectedOption == YES)
76 buttonYes.setActive(0);
77 buttonNo.setActive(1);
81 int VQuestion::handleCommand(int command)
90 BoxStack::getInstance()->update(this);
93 case Remote::DF_RIGHT:
98 BoxStack::getInstance()->update(this);
107 if (selectedOption != YES) return 4;
109 Message* m = new Message(); // Question/answer mech
112 m->message = Message::QUESTION_YES;
113 Command::getInstance()->postMessageNoLock(m);
121 void VQuestion::setDefault(UCHAR option)
123 selectedOption = option;
126 void VQuestion::processMessage(Message* m)
128 if (m->message == Message::MOUSE_MOVE)
130 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
132 buttonNo.setActive(0);
133 selectedOption = YES;
135 BoxStack::getInstance()->update(this);
137 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
139 buttonYes.setActive(0);
142 BoxStack::getInstance()->update(this);
145 else if (m->message == Message::MOUSE_LBDOWN)
147 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
149 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
151 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
153 BoxStack::getInstance()->handleCommand(Remote::OK); //simulate OK press
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())
162 BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press