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, see <https://www.gnu.org/licenses/>.
20 #include "vquestion.h"
26 #include "messagequeue.h"
28 VQuestion::VQuestion(void* treplyTo)
34 buttonYes.setPosition(40, 130);
35 buttonNo.setPosition(140, 130);
37 buttonYes.setText(tr("Yes"));
38 buttonNo.setText(tr("No"));
39 buttonNo.setActive(1);
45 VQuestion::~VQuestion()
47 if (mainText) delete[] mainText;
50 void VQuestion::setMainText(const char* takeText)
52 int length = strlen(takeText);
53 mainText = new char[length + 1];
54 strcpy(mainText, takeText);
57 void VQuestion::draw()
61 if (mainText) drawPara(mainText, 10, 45, DrawStyle::LIGHTTEXT);
64 void VQuestion::swap()
66 if (selectedOption == NO)
69 buttonYes.setActive(1);
70 buttonNo.setActive(0);
72 else if (selectedOption == YES)
75 buttonYes.setActive(0);
76 buttonNo.setActive(1);
80 int VQuestion::handleCommand(int command)
88 BoxStack::getInstance()->update(this);
95 BoxStack::getInstance()->update(this);
104 if (selectedOption != YES) return 4;
106 Message* m = new Message(); // Question/answer mech
109 m->message = Message::QUESTION_YES;
110 MessageQueue::getInstance()->postMessage(m);
118 void VQuestion::setDefault(UCHAR option)
120 selectedOption = option;
123 void VQuestion::processMessage(Message* m)
125 if (m->message == Message::MOUSE_MOVE)
127 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
129 buttonNo.setActive(0);
130 selectedOption = YES;
132 BoxStack::getInstance()->update(this);
134 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
136 buttonYes.setActive(0);
139 BoxStack::getInstance()->update(this);
142 else if (m->message == Message::MOUSE_LBDOWN)
144 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
146 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
148 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
150 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
152 else if (coordsOutsideBox(m))
154 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press