mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +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,10 +187,9 @@ int main(int argc, char* argv[])
|
|||||||
else {
|
else {
|
||||||
ch = getch();
|
ch = getch();
|
||||||
}
|
}
|
||||||
if (ch == -1) {
|
|
||||||
/* idle timeout */
|
if (ch != -1) { /* -1 = idle timeout */
|
||||||
}
|
if (ch == '\t') { /* tab */
|
||||||
else if (ch == 9) { /* tab */
|
|
||||||
focusNextInLayout(state);
|
focusNextInLayout(state);
|
||||||
}
|
}
|
||||||
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
|
else if (ch >= KEY_F(0) && ch <= KEY_F(12)) {
|
||||||
@ -201,42 +200,13 @@ int main(int argc, char* argv[])
|
|||||||
changeLayout(state, &libraryLayout);
|
changeLayout(state, &libraryLayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ch == KEY_NPAGE) {
|
|
||||||
if (state.scrollable) {
|
|
||||||
state.scrollable->PageDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ch == KEY_PPAGE) {
|
|
||||||
if (state.scrollable) {
|
|
||||||
state.scrollable->PageUp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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) {
|
else if (state.input) {
|
||||||
state.input->WriteChar(ch);
|
state.input->WriteChar(ch);
|
||||||
}
|
}
|
||||||
else if (state.keyHandler) {
|
else if (state.keyHandler) {
|
||||||
state.keyHandler->KeyPress(ch);
|
state.keyHandler->KeyPress(ch);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Window::WriteToScreen();
|
Window::WriteToScreen();
|
||||||
WindowMessageQueue::Instance().Dispatch();
|
WindowMessageQueue::Instance().Dispatch();
|
||||||
|
@ -74,14 +74,14 @@ void CommandWindow::WriteChar(int64 ch) {
|
|||||||
|
|
||||||
waddch(this->GetContent(), ch);
|
waddch(this->GetContent(), ch);
|
||||||
|
|
||||||
if (ch == 8) { /* backspace */
|
if (ch == '\b') { /* backspace */
|
||||||
wdelch(this->GetContent());
|
wdelch(this->GetContent());
|
||||||
|
|
||||||
if (bufferPosition > 0) {
|
if (bufferPosition > 0) {
|
||||||
--bufferPosition;
|
--bufferPosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ch == 10) { /* return */
|
else if (ch == '\n') { /* return */
|
||||||
this->buffer[bufferPosition] = 0;
|
this->buffer[bufferPosition] = 0;
|
||||||
std::string cmd(buffer);
|
std::string cmd(buffer);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ void TrackListView::OnQueryCompleted(QueryPtr query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TrackListView::KeyPress(int64 ch) {
|
void TrackListView::KeyPress(int64 ch) {
|
||||||
if (ch == 10) { /* return */
|
if (ch == '\n') { /* return */
|
||||||
size_t selected = this->GetSelectedIndex();
|
size_t selected = this->GetSelectedIndex();
|
||||||
if (this->metadata->size() > selected) {
|
if (this->metadata->size() > selected) {
|
||||||
TrackPtr track = this->metadata->at(selected);
|
TrackPtr track = this->metadata->at(selected);
|
||||||
@ -55,6 +55,9 @@ void TrackListView::KeyPress(int64 ch) {
|
|||||||
this->transport->Start(fn);
|
this->transport->Start(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
ListWindow::KeyPress(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackListView::ProcessMessage(IWindowMessage &message) {
|
void TrackListView::ProcessMessage(IWindowMessage &message) {
|
||||||
|
@ -15,7 +15,7 @@ using musik::core::QueryPtr;
|
|||||||
using musik::core::LibraryPtr;
|
using musik::core::LibraryPtr;
|
||||||
using musik::core::audio::Transport;
|
using musik::core::audio::Transport;
|
||||||
|
|
||||||
class TrackListView : public ListWindow, public IKeyHandler, public sigslot::has_slots<> {
|
class TrackListView : public ListWindow, public sigslot::has_slots<> {
|
||||||
public:
|
public:
|
||||||
TrackListView(Transport& transport, LibraryPtr library, IWindow *parent = NULL);
|
TrackListView(Transport& transport, LibraryPtr library, IWindow *parent = NULL);
|
||||||
~TrackListView();
|
~TrackListView();
|
||||||
|
@ -25,6 +25,17 @@ ScrollPos& ScrollableWindow::GetScrollPosition() {
|
|||||||
return this->scrollPosition;
|
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() {
|
void ScrollableWindow::OnAdapterChanged() {
|
||||||
IScrollAdapter *adapter = &GetScrollAdapter();
|
IScrollAdapter *adapter = &GetScrollAdapter();
|
||||||
|
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "IScrollAdapter.h"
|
#include "IScrollAdapter.h"
|
||||||
#include "IScrollable.h"
|
#include "IScrollable.h"
|
||||||
|
#include "IKeyHandler.h"
|
||||||
|
|
||||||
class ScrollableWindow : public IScrollable, public Window {
|
class ScrollableWindow : public IScrollable, public IKeyHandler, public Window {
|
||||||
public:
|
public:
|
||||||
ScrollableWindow(IWindow *parent = NULL);
|
ScrollableWindow(IWindow *parent = NULL);
|
||||||
virtual ~ScrollableWindow();
|
virtual ~ScrollableWindow();
|
||||||
@ -13,6 +14,8 @@ class ScrollableWindow : public IScrollable, public Window {
|
|||||||
virtual void Show();
|
virtual void Show();
|
||||||
virtual void SetSize(int width, int height);
|
virtual void SetSize(int width, int height);
|
||||||
|
|
||||||
|
virtual void KeyPress(int64 ch);
|
||||||
|
|
||||||
virtual void ScrollToTop();
|
virtual void ScrollToTop();
|
||||||
virtual void ScrollToBottom();
|
virtual void ScrollToBottom();
|
||||||
virtual void ScrollUp(int delta = 1);
|
virtual void ScrollUp(int delta = 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user