mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Moved up/down/pageup/pagedown/home/end key handling into
ScrollableWindow and out of the main loop.
This commit is contained in:
parent
04a4c33ae0
commit
072aa94bc5
@ -187,56 +187,26 @@ int main(int argc, char* argv[])
|
||||
else {
|
||||
ch = getch();
|
||||
}
|
||||
if (ch == -1) {
|
||||
/* idle timeout */
|
||||
}
|
||||
else if (ch == 9) { /* tab */
|
||||
focusNextInLayout(state);
|
||||
}
|
||||
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
|
||||
if (ch == KEY_F(1)) {
|
||||
changeLayout(state, &mainLayout);
|
||||
|
||||
if (ch != -1) { /* -1 = idle timeout */
|
||||
if (ch == '\t') { /* tab */
|
||||
focusNextInLayout(state);
|
||||
}
|
||||
else if (ch == KEY_F(2)) {
|
||||
changeLayout(state, &libraryLayout);
|
||||
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
|
||||
if (ch == KEY_F(1)) {
|
||||
changeLayout(state, &mainLayout);
|
||||
}
|
||||
else if (ch == KEY_F(2)) {
|
||||
changeLayout(state, &libraryLayout);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ch == KEY_NPAGE) {
|
||||
if (state.scrollable) {
|
||||
state.scrollable->PageDown();
|
||||
else if (state.input) {
|
||||
state.input->WriteChar(ch);
|
||||
}
|
||||
}
|
||||
else if (ch == KEY_PPAGE) {
|
||||
if (state.scrollable) {
|
||||
state.scrollable->PageUp();
|
||||
else if (state.keyHandler) {
|
||||
state.keyHandler->KeyPress(ch);
|
||||
}
|
||||
}
|
||||
else if (ch == KEY_DOWN) {
|
||||
if (state.scrollable) {
|
||||
state.scrollable->ScrollDown();
|
||||
}
|
||||
}
|
||||
else if (ch == KEY_UP) {
|
||||
if (state.scrollable) {
|
||||
state.scrollable->ScrollUp();
|
||||
}
|
||||
}
|
||||
else if (ch == KEY_HOME) {
|
||||
if (state.scrollable) {
|
||||
state.scrollable->ScrollToTop();
|
||||
}
|
||||
}
|
||||
else if (ch == KEY_END) {
|
||||
if (state.scrollable) {
|
||||
state.scrollable->ScrollToBottom();
|
||||
}
|
||||
}
|
||||
else if (state.input) {
|
||||
state.input->WriteChar(ch);
|
||||
}
|
||||
else if (state.keyHandler) {
|
||||
state.keyHandler->KeyPress(ch);
|
||||
}
|
||||
|
||||
Window::WriteToScreen();
|
||||
WindowMessageQueue::Instance().Dispatch();
|
||||
|
@ -74,14 +74,14 @@ void CommandWindow::WriteChar(int64 ch) {
|
||||
|
||||
waddch(this->GetContent(), ch);
|
||||
|
||||
if (ch == 8) { /* backspace */
|
||||
if (ch == '\b') { /* backspace */
|
||||
wdelch(this->GetContent());
|
||||
|
||||
if (bufferPosition > 0) {
|
||||
--bufferPosition;
|
||||
}
|
||||
}
|
||||
else if (ch == 10) { /* return */
|
||||
else if (ch == '\n') { /* return */
|
||||
this->buffer[bufferPosition] = 0;
|
||||
std::string cmd(buffer);
|
||||
|
||||
|
@ -46,7 +46,7 @@ void TrackListView::OnQueryCompleted(QueryPtr query) {
|
||||
}
|
||||
|
||||
void TrackListView::KeyPress(int64 ch) {
|
||||
if (ch == 10) { /* return */
|
||||
if (ch == '\n') { /* return */
|
||||
size_t selected = this->GetSelectedIndex();
|
||||
if (this->metadata->size() > selected) {
|
||||
TrackPtr track = this->metadata->at(selected);
|
||||
@ -55,6 +55,9 @@ void TrackListView::KeyPress(int64 ch) {
|
||||
this->transport->Start(fn);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ListWindow::KeyPress(ch);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackListView::ProcessMessage(IWindowMessage &message) {
|
||||
|
@ -15,7 +15,7 @@ using musik::core::QueryPtr;
|
||||
using musik::core::LibraryPtr;
|
||||
using musik::core::audio::Transport;
|
||||
|
||||
class TrackListView : public ListWindow, public IKeyHandler, public sigslot::has_slots<> {
|
||||
class TrackListView : public ListWindow, public sigslot::has_slots<> {
|
||||
public:
|
||||
TrackListView(Transport& transport, LibraryPtr library, IWindow *parent = NULL);
|
||||
~TrackListView();
|
||||
|
@ -25,6 +25,17 @@ ScrollPos& ScrollableWindow::GetScrollPosition() {
|
||||
return this->scrollPosition;
|
||||
}
|
||||
|
||||
void ScrollableWindow::KeyPress(int64 ch) {
|
||||
switch (ch) {
|
||||
case KEY_NPAGE: this->PageDown(); break;
|
||||
case KEY_PPAGE: this->PageUp(); break;
|
||||
case KEY_DOWN: this->ScrollDown(); break;
|
||||
case KEY_UP: this->ScrollUp(); break;
|
||||
case KEY_HOME: this->ScrollToTop(); break;
|
||||
case KEY_END: this->ScrollToBottom(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollableWindow::OnAdapterChanged() {
|
||||
IScrollAdapter *adapter = &GetScrollAdapter();
|
||||
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include "Window.h"
|
||||
#include "IScrollAdapter.h"
|
||||
#include "IScrollable.h"
|
||||
#include "IKeyHandler.h"
|
||||
|
||||
class ScrollableWindow : public IScrollable, public Window {
|
||||
class ScrollableWindow : public IScrollable, public IKeyHandler, public Window {
|
||||
public:
|
||||
ScrollableWindow(IWindow *parent = NULL);
|
||||
virtual ~ScrollableWindow();
|
||||
@ -13,6 +14,8 @@ class ScrollableWindow : public IScrollable, public Window {
|
||||
virtual void Show();
|
||||
virtual void SetSize(int width, int height);
|
||||
|
||||
virtual void KeyPress(int64 ch);
|
||||
|
||||
virtual void ScrollToTop();
|
||||
virtual void ScrollToBottom();
|
||||
virtual void ScrollUp(int delta = 1);
|
||||
|
Loading…
Reference in New Issue
Block a user