]> git.vomp.tv Git - vompclient.git/blob - vserverselect.cc
Windows fixes
[vompclient.git] / vserverselect.cc
1 /*
2     Copyright 2004-2020 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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/>.
18 */
19
20 #include "defines.h"
21 #include "input.h"
22 #include "colour.h"
23 #include "video.h"
24 #include "boxstack.h"
25 #include "i18n.h"
26 #include "messagequeue.h"
27
28 #include "vserverselect.h"
29
30 VServerSelect::VServerSelect(const VDPC& servers, void* treplyTo)
31 {
32   setSize(300, 200);
33   createBuffer();
34   if (Video::getInstance()->getFormat() == Video::PAL)
35   {
36     setPosition(220, 200);
37   }
38   else
39   {
40     setPosition(210, 150);
41   }
42
43   setTitleBarOn(1);
44   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
45   setTitleText(tr("Choose a VDR server"));
46
47   sl.setPosition(10, 30 + 5);
48   sl.setSize(area.w - 20, area.h - 30 - 15);
49   add(&sl);
50
51   sl.addOption(servers[0].name.c_str(), 0, 1);
52   for(UINT k = 1; k < servers.numServers(); k++)
53   {
54     sl.addOption(servers[k].name.c_str(), 0, 0);
55   }
56
57   replyTo = treplyTo;
58 }
59
60 VServerSelect::~VServerSelect()
61 {
62 }
63
64 void VServerSelect::draw()
65 {
66   TBBoxx::draw();
67 }
68
69 int VServerSelect::handleCommand(int command)
70 {
71   switch(command)
72   {
73     case Input::UP:
74     {
75       sl.up();
76       sl.draw();
77       BoxStack::getInstance()->update(this);
78       return 2;
79     }
80     case Input::DOWN:
81     {
82       sl.down();
83       sl.draw();
84       BoxStack::getInstance()->update(this);
85       return 2;
86     }
87     case Input::OK:
88     {
89       Message* m = new Message(); // Question/Answer mech. Better being messages
90       m->to = replyTo;
91       m->message = Message::SERVER_SELECTED;
92       m->parameter = sl.getCurrentOption();
93       MessageQueue::getInstance()->postMessage(m);
94       return 4;
95     }
96   }
97
98   return 1;
99 }
100
101 void VServerSelect::processMessage(Message* m)
102 {
103   if (m->message == Message::MOUSE_MOVE)
104   {
105     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
106     {
107       sl.draw();
108       BoxStack::getInstance()->update(this);
109     }
110   }
111   else if (m->message == Message::MOUSE_LBDOWN)
112   {
113     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
114     {
115       BoxStack::getInstance()->handleCommand(Input::OK); //simulate OK press
116     }
117   }
118 }