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"
23 VQuestion::VQuestion(void* treplyTo)
29 buttonYes.setSurfaceOffset(40, 130);
30 buttonNo.setSurfaceOffset(140, 130);
32 buttonYes.setText(tr("Yes"));
33 buttonNo.setText(tr("No"));
34 buttonNo.setActive(1);
37 VQuestion::~VQuestion()
39 if (mainText) delete[] mainText;
42 void VQuestion::setMainText(char* takeText)
44 int length = strlen(takeText);
45 mainText = new char[length + 1];
46 strcpy(mainText, takeText);
49 void VQuestion::draw()
53 buttonYes.setSurface(surface);
54 buttonNo.setSurface(surface);
56 if (mainText) drawPara(mainText, 10, 45, Colour::LIGHTTEXT);
61 void VQuestion::swap()
63 if (selectedOption == NO)
66 buttonYes.setActive(1);
67 buttonNo.setActive(0);
69 else if (selectedOption == YES)
72 buttonYes.setActive(0);
73 buttonNo.setActive(1);
77 int VQuestion::handleCommand(int command)
86 ViewMan::getInstance()->updateView(this);
89 case Remote::DF_RIGHT:
94 ViewMan::getInstance()->updateView(this);
103 if (selectedOption != YES) return 4;
105 Message* m = new Message(); // Question/answer mech
108 m->message = Message::QUESTION_YES;
109 Command::getInstance()->postMessageNoLock(m);
117 void VQuestion::setDefault(UCHAR option)
119 selectedOption = option;
122 void VQuestion::processMessage(Message* m)
124 if (m->message == Message::MOUSE_MOVE)
126 if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
128 buttonNo.setActive(0);
129 selectedOption = YES;
131 ViewMan::getInstance()->updateView(this);
133 else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
135 buttonYes.setActive(0);
138 ViewMan::getInstance()->updateView(this);
141 else if (m->message == Message::MOUSE_LBDOWN)
143 if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
145 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
147 else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
149 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
153 //check if press is outside this view! then simulate cancel
154 int x=(m->parameter>>16)-getScreenX();
155 int y=(m->parameter&0xFFFF)-getScreenY();
156 if (x<0 || y <0 || x>getWidth() || y>getHeight())
158 ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press