center cursor directly in Menu class
[ncmpcpp.git] / src / outputs.cpp
bloba7096c9e146d0d76aa7be5198e4cdefbb439fece
1 /***************************************************************************
2 * Copyright (C) 2008-2010 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "outputs.h"
23 #ifdef ENABLE_OUTPUTS
25 #include "display.h"
26 #include "global.h"
28 using Global::MainHeight;
29 using Global::MainStartY;
30 using Global::myScreen;
32 Outputs *myOutputs = new Outputs;
34 void Outputs::Init()
36 w = new Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
37 w->CyclicScrolling(Config.use_cyclic_scrolling);
38 w->CenteredCursor(Config.centered_cursor);
39 w->HighlightColor(Config.main_highlight_color);
40 w->SetItemDisplayer(Display::Pairs);
42 isInitialized = 1;
43 FetchList();
46 void Outputs::SwitchTo()
48 if (myScreen == this)
49 return;
51 if (!isInitialized)
52 Init();
54 if (hasToBeResized)
55 Resize();
57 if (myScreen != this && myScreen->isTabbable())
58 Global::myPrevScreen = myScreen;
59 myScreen = this;
60 w->Window::Clear();
62 Global::RedrawHeader = 1;
65 void Outputs::Resize()
67 w->Resize(COLS, MainHeight);
68 w->MoveTo(0, MainStartY);
69 hasToBeResized = 0;
72 std::basic_string<my_char_t> Outputs::Title()
74 return U("Outputs");
77 void Outputs::EnterPressed()
79 if (w->Current().second)
81 if (Mpd.DisableOutput(w->Choice()))
82 ShowMessage("Output \"%s\" disabled", w->Current().first.c_str());
84 else
86 if (Mpd.EnableOutput(w->Choice()))
87 ShowMessage("Output \"%s\" enabled", w->Current().first.c_str());
91 void Outputs::MouseButtonPressed(MEVENT me)
93 if (w->Empty() || !w->hasCoords(me.x, me.y) || size_t(me.y) >= w->Size())
94 return;
95 if (me.bstate & BUTTON1_PRESSED || me.bstate & BUTTON3_PRESSED)
97 w->Goto(me.y);
98 if (me.bstate & BUTTON3_PRESSED)
99 EnterPressed();
101 else
102 Screen< Menu<MPD::Output> >::MouseButtonPressed(me);
105 void Outputs::FetchList()
107 if (!isInitialized)
108 return;
109 MPD::OutputList ol;
110 Mpd.GetOutputs(ol);
111 w->Clear();
112 for (MPD::OutputList::const_iterator it = ol.begin(); it != ol.end(); ++it)
113 w->AddOption(*it, it->second);
114 if (myScreen == this)
115 w->Refresh();
118 #endif // ENABLE_OUTPUTS