mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Improved (?) input handling -- cursor position works on Mac now. This may break Windows.
This commit is contained in:
parent
05c36ef76b
commit
ceb629accd
@ -282,7 +282,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
ensureFocusIsValid(state);
|
||||
Window::WriteToScreen();
|
||||
Window::WriteToScreen(state.input);
|
||||
MessageQueue::Instance().Dispatch();
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,13 @@ MainLayout::MainLayout(Transport& transport, LibraryPtr library)
|
||||
this->logs.reset(new LogWindow(this));
|
||||
this->output.reset(new OutputWindow(this));
|
||||
this->resources.reset(new ResourcesWindow(this));
|
||||
this->commands.reset(new CommandWindow(this, transport, library, *this->output));
|
||||
|
||||
this->commands.reset(new CommandWindow(
|
||||
this,
|
||||
transport,
|
||||
library,
|
||||
*this->output,
|
||||
*this->logs));
|
||||
|
||||
this->AddWindow(this->commands);
|
||||
this->AddWindow(this->logs);
|
||||
|
@ -35,17 +35,26 @@ bool tostr(T& t, const std::string& s) {
|
||||
return !(iss >> t).fail();
|
||||
}
|
||||
|
||||
inline static void redrawContents(IWindow &window, const std::string& text) {
|
||||
WINDOW* c = window.GetContent();
|
||||
wclear(c);
|
||||
wprintw(c, text.c_str());
|
||||
window.Repaint();
|
||||
}
|
||||
|
||||
CommandWindow::CommandWindow(
|
||||
IWindow *parent,
|
||||
Transport& transport,
|
||||
LibraryPtr library,
|
||||
OutputWindow& output)
|
||||
OutputWindow& output,
|
||||
LogWindow& logWindow)
|
||||
: Window(parent) {
|
||||
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
|
||||
this->transport = &transport;
|
||||
this->library = library;
|
||||
this->bufferPosition = 0;
|
||||
this->bufferLength = 0;
|
||||
this->output = &output;
|
||||
this->logWindow = &logWindow;
|
||||
this->paused = false;
|
||||
this->Help();
|
||||
}
|
||||
@ -55,12 +64,11 @@ CommandWindow::~CommandWindow() {
|
||||
|
||||
void CommandWindow::Show() {
|
||||
Window::Show();
|
||||
wmove(this->GetContent(), 0, 0);
|
||||
wprintw(this->GetContent(), "%s", buffer.c_str());
|
||||
redrawContents(*this, buffer);
|
||||
}
|
||||
|
||||
void CommandWindow::Focus() {
|
||||
wmove(this->GetContent(), 0, bufferPosition);
|
||||
|
||||
}
|
||||
|
||||
void removeUtf8Char(std::string& value) {
|
||||
@ -98,10 +106,9 @@ void CommandWindow::Write(const std::string& key) {
|
||||
}
|
||||
}
|
||||
|
||||
this->Clear();
|
||||
wprintw(this->GetContent(), buffer.c_str());
|
||||
this->bufferLength = u8len(buffer);
|
||||
|
||||
this->Repaint();
|
||||
redrawContents(*this, buffer);
|
||||
}
|
||||
|
||||
void CommandWindow::Seek(const std::vector<std::string>& args) {
|
||||
@ -137,6 +144,7 @@ void CommandWindow::Help() {
|
||||
this->output->WriteLine(" pause: pause/resume", s);
|
||||
this->output->WriteLine(" stop: stop all playback", s);
|
||||
this->output->WriteLine(" volume: <0 - 100>: set % volume", s);
|
||||
this->output->WriteLine(" clear: clear the log window", s);
|
||||
this->output->WriteLine(" seek <seconds>: seek to <seconds> into track", s);
|
||||
this->output->WriteLine(" addir <dir>: add a directory to be indexed", s);
|
||||
this->output->WriteLine(" rmdir <dir>: remove indexed directory path", s);
|
||||
@ -156,6 +164,9 @@ bool CommandWindow::ProcessCommand(const std::string& cmd) {
|
||||
if (name == "plugins") {
|
||||
this->ListPlugins();
|
||||
}
|
||||
else if (name == "clear") {
|
||||
this->logWindow->ClearContents();
|
||||
}
|
||||
else if (name == "play" || name == "pl" || name == "p") {
|
||||
return this->PlayFile(args);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <core/playback/Transport.h>
|
||||
#include <core/library/LibraryFactory.h>
|
||||
#include "OutputWindow.h"
|
||||
#include "LogWindow.h"
|
||||
|
||||
namespace musik {
|
||||
namespace box {
|
||||
@ -20,11 +21,14 @@ namespace musik {
|
||||
cursespp::IWindow *parent,
|
||||
musik::core::audio::Transport& transport,
|
||||
musik::core::LibraryPtr library,
|
||||
OutputWindow& output);
|
||||
OutputWindow& output,
|
||||
LogWindow& logWindow);
|
||||
|
||||
virtual ~CommandWindow();
|
||||
|
||||
virtual void Write(const std::string& key);
|
||||
virtual size_t Length() { return this->bufferLength; }
|
||||
|
||||
virtual void Focus();
|
||||
virtual void Show();
|
||||
|
||||
@ -40,8 +44,10 @@ namespace musik {
|
||||
void Help();
|
||||
|
||||
std::string buffer;
|
||||
int bufferPosition;
|
||||
size_t bufferLength;
|
||||
|
||||
OutputWindow* output;
|
||||
LogWindow* logWindow;
|
||||
musik::core::audio::Transport* transport;
|
||||
musik::core::LibraryPtr library;
|
||||
bool paused;
|
||||
|
@ -29,6 +29,11 @@ IScrollAdapter& LogWindow::GetScrollAdapter() {
|
||||
return (IScrollAdapter&) *this->adapter;
|
||||
}
|
||||
|
||||
void LogWindow::ClearContents() {
|
||||
this->adapter->Clear();
|
||||
this->OnAdapterChanged();
|
||||
}
|
||||
|
||||
void LogWindow::Update() {
|
||||
boost::mutex::scoped_lock lock(pendingMutex);
|
||||
|
||||
|
@ -20,6 +20,7 @@ namespace musik {
|
||||
LogWindow(cursespp::IWindow *parent = NULL);
|
||||
virtual ~LogWindow();
|
||||
|
||||
void ClearContents();
|
||||
void Update();
|
||||
|
||||
protected:
|
||||
|
@ -7,5 +7,6 @@ namespace cursespp {
|
||||
public:
|
||||
virtual ~IInput() { }
|
||||
virtual void Write(const std::string& key) = 0;
|
||||
virtual size_t Length() = 0;
|
||||
};
|
||||
}
|
||||
|
@ -20,6 +20,10 @@ SimpleScrollAdapter::~SimpleScrollAdapter() {
|
||||
|
||||
}
|
||||
|
||||
void SimpleScrollAdapter::Clear() {
|
||||
this->entries.clear();
|
||||
}
|
||||
|
||||
size_t SimpleScrollAdapter::GetEntryCount() {
|
||||
return this->entries.size();
|
||||
}
|
||||
|
@ -12,12 +12,13 @@ namespace cursespp {
|
||||
|
||||
virtual void AddEntry(EntryPtr entry);
|
||||
virtual void SetMaxEntries(const size_t size = 500);
|
||||
virtual void Clear();
|
||||
|
||||
virtual size_t GetEntryCount();
|
||||
virtual EntryPtr GetEntry(size_t index);
|
||||
|
||||
private:
|
||||
typedef std::deque<EntryPtr> EntryList;
|
||||
typedef std::deque<EntryPtr> EntryList; /* TODO: this is O(n) lookup */
|
||||
typedef EntryList::iterator Iterator;
|
||||
|
||||
EntryList entries;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdafx.h>
|
||||
#include "Window.h"
|
||||
#include "IWindowGroup.h"
|
||||
#include "IInput.h"
|
||||
#include "Message.h"
|
||||
#include "MessageQueue.h"
|
||||
|
||||
@ -9,11 +10,24 @@ using namespace cursespp;
|
||||
static int NEXT_ID = 0;
|
||||
static bool drawPending = false;
|
||||
|
||||
void Window::WriteToScreen() {
|
||||
void Window::WriteToScreen(IInput* input) {
|
||||
if (drawPending) {
|
||||
drawPending = false;
|
||||
update_panels();
|
||||
doupdate();
|
||||
|
||||
/* had problems finding reliable documentation here, but it seems like
|
||||
manually moving the cursor requires a refresh() -- doupdate() is not
|
||||
good enough. further, we allow windows to repaint themselves at will,
|
||||
which may change the cursor position. after each draw cycle, move the
|
||||
cursor back to the focused input. */
|
||||
if (input) {
|
||||
Window* inputWindow = dynamic_cast<Window*>(input);
|
||||
if (inputWindow) {
|
||||
wmove(inputWindow->GetContent(), 0, input->Length());
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "IWindow.h"
|
||||
|
||||
namespace cursespp {
|
||||
class IInput;
|
||||
|
||||
class Window : public IWindow, public std::enable_shared_from_this<IWindow> {
|
||||
public:
|
||||
Window(IWindow* parent = NULL);
|
||||
@ -48,7 +50,7 @@ namespace cursespp {
|
||||
virtual int GetFocusOrder();
|
||||
virtual void SetFocusOrder(int order = -1);
|
||||
|
||||
static void WriteToScreen();
|
||||
static void WriteToScreen(IInput* input);
|
||||
|
||||
protected:
|
||||
IWindow* GetParent() const;
|
||||
|
Loading…
Reference in New Issue
Block a user