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)
89 BoxStack::getInstance()->update(this);
97 BoxStack::getInstance()->update(this);
106 if (selectedOption != YES) return 4;
108 Message* m = new Message(); // Question/answer mech
111 m->message = Message::QUESTION_YES;
112 MessageQueue::getInstance()->postMessage(m);
120 void VQuestion::setDefault(UCHAR option)
122 selectedOption = option;
125 void VQuestion::processMessage(Message* m)
127 if (m->message == Message::MOUSE_MOVE)
129 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
131 buttonNo.setActive(0);
132 selectedOption = YES;
134 BoxStack::getInstance()->update(this);
136 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
138 buttonYes.setActive(0);
141 BoxStack::getInstance()->update(this);
144 else if (m->message == Message::MOUSE_LBDOWN)
146 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
148 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
150 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
152 BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
156 //check if press is outside this view! then simulate cancel
157 int x=(m->parameter>>16)-getScreenX();
158 int y=(m->parameter&0xFFFF)-getScreenY();
159 if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
161 BoxStack::getInstance()->handleCommand(Input::BACK); //simulate cancel press