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(MessageReceiver* treplyTo)
31 buttonYes.setPosition(40, 130);
32 buttonNo.setPosition(140, 130);
34 buttonYes.setText(tr("Yes"));
35 buttonNo.setText(tr("No"));
36 buttonNo.setActive(1);
41 MessageQueue::getInstance()->addReceiver(this);
44 VQuestion::~VQuestion()
46 MessageQueue::getInstance()->removeReceiver(this);
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);
89 return BoxStack::COMMAND_HANDLED;
95 BoxStack::getInstance()->update(this);
96 return BoxStack::COMMAND_HANDLED;
100 return BoxStack::DELETE_ME;
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);
112 return BoxStack::DELETE_ME;
115 return BoxStack::ABANDON_COMMAND;
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 - getScreenX(), m->tag - getScreenY()))
129 buttonNo.setActive(0);
130 selectedOption = YES;
132 BoxStack::getInstance()->update(this);
134 else if (buttonNo.mouseMove(m->parameter - getScreenX(), m->tag - getScreenY()))
136 buttonYes.setActive(0);
139 BoxStack::getInstance()->update(this);
142 else if (m->message == Message::MOUSE_LBDOWN)
144 if (buttonYes.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
146 Input::sendInputKey(Input::OK);
148 else if (buttonNo.mouseLBDOWN(m->parameter - getScreenX(), m->tag - getScreenY()))
150 Input::sendInputKey(Input::OK);
152 else if (coordsOutsideBox(m))
154 Input::sendInputKey(Input::BACK);