summaryrefslogtreecommitdiff
path: root/src/screen.h
blob: f7a790410b053084e1a12c756a7dc963e8aaf6db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/***************************************************************************
 *   Copyright (C) 2008-2009 by Andrzej Rybczak                            *
 *   electricityispower@gmail.com                                          *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

#ifndef _SCREEN_H
#define _SCREEN_H

#include "window.h"
#include "menu.h"
#include "mpdpp.h"
#include "helpers.h"
#include "status.h"

class BasicScreen
{
	public:
		BasicScreen() : hasToBeResized(0) { }
		virtual ~BasicScreen() { }
		
		virtual void *ActiveWindow() = 0;
		
		virtual void Init() = 0;
		virtual void SwitchTo() = 0;
		virtual void Resize() = 0;
		
		virtual std::string Title() = 0;
		
		virtual void Update() { }
		virtual void Refresh() = 0;
		virtual void RefreshWindow() = 0;
		virtual void ReadKey(int &) = 0;
		virtual void Scroll(Where, const int * = 0) = 0;
		
		virtual void EnterPressed() = 0;
		virtual void SpacePressed() = 0;
		virtual void MouseButtonPressed(MEVENT) { }
		
		virtual MPD::Song *CurrentSong() { return 0; }
		
		virtual bool allowsSelection() = 0;
		virtual void ReverseSelection() { }
		virtual void GetSelectedSongs(MPD::SongList &) { }
		
		virtual void ApplyFilter(const std::string &) { }
		
		virtual List *GetList() = 0;
		
		bool hasToBeResized;
};

template <typename WindowType> class Screen : public BasicScreen
{
	public:
		Screen() : w(0) { }
		virtual ~Screen() { }
		
		virtual void *ActiveWindow();
		
		WindowType *Main();
		
		virtual void Refresh();
		virtual void RefreshWindow();
		virtual void ReadKey(int &input);
		virtual void Scroll(Where where, const int * = 0);
		
		virtual void MouseButtonPressed(MEVENT me);
		
	protected:
		WindowType *w;
};

template <typename WindowType> void *Screen<WindowType>::ActiveWindow()
{
	return w;
}

template <typename WindowType> WindowType *Screen<WindowType>::Main()
{
	return w;
}

template <typename WindowType> void Screen<WindowType>::Refresh()
{
	w->Display();
}

template <typename WindowType> void Screen<WindowType>::RefreshWindow()
{
	w->Display();
}

template <typename WindowType> void Screen<WindowType>::ReadKey(int &input)
{
	w->ReadKey(input);
}

template <typename WindowType> void Screen<WindowType>::Scroll(Where where, const int *key)
{
	if (!Config.fancy_scrolling && key)
	{
		int in = key[0];
		w->SetTimeout(ncmpcpp_window_timeout/10);
		while (Keypressed(in, key))
		{
			TraceMpdStatus();
			w->Scroll(where);
			w->Refresh();
			w->ReadKey(in);
		}
		w->SetTimeout(ncmpcpp_window_timeout);
	}
	else
		w->Scroll(where);
}

template <typename WindowType> void Screen<WindowType>::MouseButtonPressed(MEVENT me)
{
	if (me.bstate & BUTTON2_PRESSED)
	{
		Scroll(wPageDown);
	}
	else if (me.bstate & BUTTON4_PRESSED)
	{
		Scroll(wPageUp);
	}
}

template <> inline void Screen<Scrollpad>::MouseButtonPressed(MEVENT me)
{
	if (me.bstate & BUTTON2_PRESSED)
	{
		for (size_t i = 0; i < 2; i++)
			Scroll(wDown);
	}
	else if (me.bstate & BUTTON4_PRESSED)
	{
		for (size_t i = 0; i < 2; i++)
			Scroll(wUp);
	}
}

#endif