mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-29 19:20:28 +00:00
Added the ability for views to have real parent views. Added LayoutBase,
which is a subclass of Window, and now acts as a parent.
This commit is contained in:
parent
d11c4fc425
commit
7016c2aac2
@ -10,8 +10,8 @@
|
||||
using musik::core::LibraryPtr;
|
||||
using musik::core::IQuery;
|
||||
|
||||
CategoryListView::CategoryListView(LibraryPtr library)
|
||||
: ListWindow() {
|
||||
CategoryListView::CategoryListView(IWindow *parent, LibraryPtr library)
|
||||
: ListWindow(parent) {
|
||||
this->library = library;
|
||||
this->adapter = new Adapter(*this);
|
||||
this->activeQuery.reset(new CategoryListQuery());
|
||||
|
@ -14,7 +14,7 @@ using musik::core::LibraryPtr;
|
||||
|
||||
class CategoryListView : public ListWindow, public sigslot::has_slots<> {
|
||||
public:
|
||||
CategoryListView(LibraryPtr library);
|
||||
CategoryListView(IWindow *parent, LibraryPtr library);
|
||||
~CategoryListView(); /* non-virtual for now*/
|
||||
|
||||
void OnIdle();
|
||||
|
@ -32,8 +32,12 @@ bool tostr(T& t, const std::string& s) {
|
||||
return !(iss >> t).fail();
|
||||
}
|
||||
|
||||
CommandWindow::CommandWindow(Transport& transport, LibraryPtr library, OutputWindow& output)
|
||||
: Window() {
|
||||
CommandWindow::CommandWindow(
|
||||
IWindow *parent,
|
||||
Transport& transport,
|
||||
LibraryPtr library,
|
||||
OutputWindow& output)
|
||||
: Window(parent) {
|
||||
this->transport = &transport;
|
||||
this->library = library;
|
||||
this->buffer = new char[BUFFER_SIZE];
|
||||
|
@ -14,7 +14,8 @@ using namespace musik::core::audio;
|
||||
class CommandWindow : public Window, public IInput, public sigslot::has_slots<> {
|
||||
public:
|
||||
CommandWindow(
|
||||
Transport& transport,
|
||||
IWindow *parent,
|
||||
Transport& transport,
|
||||
LibraryPtr library,
|
||||
OutputWindow& output);
|
||||
|
||||
|
2
src/musikbox/LayoutBase.cpp
Executable file
2
src/musikbox/LayoutBase.cpp
Executable file
@ -0,0 +1,2 @@
|
||||
#include "stdafx.h"
|
||||
#include "LayoutBase.h"
|
15
src/musikbox/LayoutBase.h
Executable file
15
src/musikbox/LayoutBase.h
Executable file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILayout.h"
|
||||
#include "Window.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class LayoutBase : public Window, public ILayout {
|
||||
public:
|
||||
virtual IWindow* FocusNext() = 0;
|
||||
virtual IWindow* FocusPrev() = 0;
|
||||
virtual IWindow* GetFocus() = 0;
|
||||
virtual void Layout() = 0;
|
||||
virtual void OnIdle() = 0;
|
||||
};
|
@ -1,10 +1,15 @@
|
||||
#include "stdafx.h"
|
||||
#include "Colors.h"
|
||||
#include "Screen.h"
|
||||
#include "LibraryLayout.h"
|
||||
|
||||
LibraryLayout::LibraryLayout(LibraryPtr library) {
|
||||
this->albumList.reset(new CategoryListView(library));
|
||||
this->trackList.reset(new TrackListView());
|
||||
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
|
||||
this->SetPosition(0, 0);
|
||||
this->Create();
|
||||
|
||||
this->albumList.reset(new CategoryListView(this, library));
|
||||
this->trackList.reset(new TrackListView(this));
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
@ -26,11 +31,11 @@ IWindow* LibraryLayout::GetFocus() {
|
||||
|
||||
void LibraryLayout::Layout() {
|
||||
this->albumList->SetPosition(0, 0);
|
||||
this->albumList->SetSize(20, Screen::GetHeight());
|
||||
this->albumList->SetSize(20, this->GetHeight());
|
||||
this->albumList->Create();
|
||||
|
||||
this->trackList->SetPosition(20, 0);
|
||||
this->trackList->SetSize(Screen::GetWidth() - 20, Screen::GetHeight());
|
||||
this->trackList->SetSize(this->GetWidth() - 20, this->GetHeight());
|
||||
this->trackList->Create();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILayout.h"
|
||||
#include "LayoutBase.h"
|
||||
#include "CategoryListView.h"
|
||||
#include "TrackListView.h"
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
using musik::core::LibraryPtr;
|
||||
|
||||
class LibraryLayout : public ILayout {
|
||||
class LibraryLayout : public LayoutBase {
|
||||
public:
|
||||
LibraryLayout(LibraryPtr library);
|
||||
~LibraryLayout(); /* not virtual */
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
typedef IScrollAdapter::ScrollPosition ScrollPos;
|
||||
|
||||
ListWindow::ListWindow()
|
||||
: ScrollableWindow() {
|
||||
ListWindow::ListWindow(IWindow *parent)
|
||||
: ScrollableWindow(parent) {
|
||||
this->selectedIndex = 0;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
class ListWindow : public ScrollableWindow {
|
||||
public:
|
||||
ListWindow();
|
||||
ListWindow(IWindow *parent = NULL);
|
||||
virtual ~ListWindow();
|
||||
|
||||
virtual void ScrollToTop();
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
typedef IScrollAdapter::IEntry IEntry;
|
||||
|
||||
LogWindow::LogWindow()
|
||||
: ScrollableWindow() {
|
||||
LogWindow::LogWindow(IWindow *parent)
|
||||
: ScrollableWindow(parent) {
|
||||
this->SetContentColor(BOX_COLOR_WHITE_ON_BLUE);
|
||||
|
||||
this->adapter = new SimpleScrollAdapter();
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
class LogWindow : public ScrollableWindow, public sigslot::has_slots<> {
|
||||
public:
|
||||
LogWindow();
|
||||
LogWindow(IWindow *parent = NULL);
|
||||
~LogWindow();
|
||||
|
||||
void Update();
|
||||
|
@ -100,14 +100,14 @@ int main(int argc, char* argv[])
|
||||
using musik::core::LibraryFactory;
|
||||
LibraryPtr library = LibraryFactory::Libraries().at(0);
|
||||
|
||||
MainLayout mainLayout(tp, library);
|
||||
//LibraryLayout libraryLayout(library);
|
||||
//MainLayout mainLayout(tp, library);
|
||||
LibraryLayout libraryLayout(library);
|
||||
|
||||
int ch;
|
||||
timeout(IDLE_TIMEOUT_MS);
|
||||
bool quit = false;
|
||||
|
||||
ILayout* layout = &mainLayout;
|
||||
ILayout* layout = &libraryLayout;
|
||||
IWindow* focused = layout->GetFocus();
|
||||
IInput* input = dynamic_cast<IInput*>(focused);
|
||||
IScrollable* scrollable = dynamic_cast<IScrollable*>(focused);
|
||||
|
@ -19,11 +19,16 @@ static inline IWindow* adjustFocus(IWindow* oldFocus, IWindow* newFocus) {
|
||||
}
|
||||
|
||||
MainLayout::MainLayout(Transport& transport, LibraryPtr library) {
|
||||
this->logs.reset(new LogWindow());
|
||||
this->output.reset(new OutputWindow());
|
||||
this->resources.reset(new ResourcesWindow());
|
||||
this->commands.reset(new CommandWindow(transport, library, *this->output));
|
||||
this->transport.reset(new TransportWindow(transport));
|
||||
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
|
||||
this->SetPosition(0, 0);
|
||||
this->SetFrameVisible(false);
|
||||
this->Create();
|
||||
|
||||
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->transport.reset(new TransportWindow(this, transport));
|
||||
|
||||
this->focusOrder.push_back(commands.get());
|
||||
this->focusOrder.push_back(output.get());
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILayout.h"
|
||||
#include "LayoutBase.h"
|
||||
#include "LogWindow.h"
|
||||
#include "CommandWindow.h"
|
||||
#include "OutputWindow.h"
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
using musik::core::audio::Transport;
|
||||
|
||||
class MainLayout : public ILayout {
|
||||
class MainLayout : public LayoutBase {
|
||||
public:
|
||||
MainLayout(Transport& transport, LibraryPtr library);
|
||||
~MainLayout();
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
typedef IScrollAdapter::EntryPtr EntryPtr;
|
||||
|
||||
OutputWindow::OutputWindow()
|
||||
: ScrollableWindow()
|
||||
OutputWindow::OutputWindow(IWindow *parent)
|
||||
: ScrollableWindow(parent)
|
||||
{
|
||||
this->SetContentColor(BOX_COLOR_BLACK_ON_GREY);
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
class OutputWindow : public ScrollableWindow {
|
||||
public:
|
||||
OutputWindow();
|
||||
OutputWindow(IWindow *parent = NULL);
|
||||
~OutputWindow();
|
||||
|
||||
void WriteLine(const std::string& line, int64 attrs = -1);
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include <boost/format.hpp>
|
||||
|
||||
|
||||
ResourcesWindow::ResourcesWindow()
|
||||
: Window() {
|
||||
ResourcesWindow::ResourcesWindow(IWindow *parent)
|
||||
: Window(parent) {
|
||||
this->systemInfo = SystemInfo::Create();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
class ResourcesWindow : public Window {
|
||||
public:
|
||||
ResourcesWindow();
|
||||
ResourcesWindow(IWindow *parent = NULL);
|
||||
virtual ~ResourcesWindow();
|
||||
|
||||
virtual void Repaint();
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
typedef IScrollAdapter::ScrollPosition ScrollPos;
|
||||
|
||||
ScrollableWindow::ScrollableWindow()
|
||||
: Window() {
|
||||
ScrollableWindow::ScrollableWindow(IWindow *parent)
|
||||
: Window(parent) {
|
||||
}
|
||||
|
||||
ScrollableWindow::~ScrollableWindow() {
|
||||
@ -28,13 +28,15 @@ ScrollPos& ScrollableWindow::GetScrollPosition() {
|
||||
void ScrollableWindow::OnAdapterChanged() {
|
||||
IScrollAdapter *adapter = &GetScrollAdapter();
|
||||
|
||||
adapter->SetDisplaySize(GetContentWidth(), GetContentHeight());
|
||||
|
||||
if (IsLastItemVisible()) {
|
||||
this->ScrollToBottom();
|
||||
}
|
||||
else {
|
||||
ScrollPos &pos = this->GetScrollPosition();
|
||||
|
||||
GetScrollAdapter().DrawPage(
|
||||
adapter->DrawPage(
|
||||
this->GetContent(),
|
||||
pos.firstVisibleEntryIndex,
|
||||
&pos);
|
||||
|
@ -7,9 +7,10 @@
|
||||
|
||||
class ScrollableWindow : public IScrollable, public Window {
|
||||
public:
|
||||
ScrollableWindow();
|
||||
ScrollableWindow(IWindow *parent = NULL);
|
||||
virtual ~ScrollableWindow();
|
||||
|
||||
virtual void Create();
|
||||
virtual void SetSize(int width, int height);
|
||||
|
||||
virtual void ScrollToTop();
|
||||
@ -19,8 +20,6 @@ class ScrollableWindow : public IScrollable, public Window {
|
||||
virtual void PageUp();
|
||||
virtual void PageDown();
|
||||
|
||||
virtual void Create();
|
||||
|
||||
protected:
|
||||
virtual IScrollAdapter& GetScrollAdapter() = 0;
|
||||
virtual IScrollAdapter::ScrollPosition& GetScrollPosition();
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include "stdafx.h"
|
||||
#include "TrackListView.h"
|
||||
|
||||
TrackListView::TrackListView()
|
||||
: Window() {
|
||||
TrackListView::TrackListView(IWindow *parent)
|
||||
: Window(parent) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
class TrackListView : public Window {
|
||||
public:
|
||||
TrackListView();
|
||||
TrackListView(IWindow *parent);
|
||||
~TrackListView();
|
||||
|
||||
private:
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
using musik::core::audio::Transport;
|
||||
|
||||
TransportWindow::TransportWindow(Transport& transport)
|
||||
: Window() {
|
||||
TransportWindow::TransportWindow(IWindow *parent, Transport& transport)
|
||||
: Window(parent) {
|
||||
this->SetContentColor(BOX_COLOR_BLACK_ON_GREEN);
|
||||
this->transport = &transport;
|
||||
this->paused = false;
|
||||
|
@ -9,7 +9,7 @@ using namespace musik::core::audio;
|
||||
|
||||
class TransportWindow : public Window {
|
||||
public:
|
||||
TransportWindow(Transport& transport);
|
||||
TransportWindow(IWindow *parent, Transport& transport);
|
||||
~TransportWindow();
|
||||
|
||||
virtual void Repaint();
|
||||
|
@ -3,14 +3,16 @@
|
||||
#include "stdafx.h"
|
||||
#include "Window.h"
|
||||
|
||||
Window::Window() {
|
||||
Window::Window(IWindow *parent) {
|
||||
this->frame = this->content = 0;
|
||||
this->parent = parent;
|
||||
this->height = 0;
|
||||
this->width = 0;
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->contentColor = -1;
|
||||
this->frameColor = -1;
|
||||
this->drawFrame = true;
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
@ -36,10 +38,18 @@ int Window::GetHeight() const {
|
||||
}
|
||||
|
||||
int Window::GetContentHeight() const {
|
||||
if (!this->drawFrame) {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
return this->height ? this->height - 2 : 0;
|
||||
}
|
||||
|
||||
int Window::GetContentWidth() const {
|
||||
if (!this->drawFrame) {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
return this->width ? this->width - 2 : 0;
|
||||
}
|
||||
|
||||
@ -63,7 +73,7 @@ void Window::SetContentColor(int color) {
|
||||
void Window::SetFrameColor(int color) {
|
||||
this->frameColor = color;
|
||||
|
||||
if (this->frameColor != -1 && this->frame) {
|
||||
if (this->drawFrame && this->frameColor != -1 && this->frame) {
|
||||
wbkgd(this->frame, COLOR_PAIR(this->frameColor));
|
||||
this->Repaint();
|
||||
}
|
||||
@ -80,27 +90,76 @@ WINDOW* Window::GetFrame() const {
|
||||
void Window::Create() {
|
||||
this->Destroy();
|
||||
|
||||
this->frame = newwin(this->height, this->width, this->y, this->x);
|
||||
box(this->frame, 0, 0);
|
||||
wrefresh(this->frame);
|
||||
this->frame = (this->parent == NULL)
|
||||
? newwin(
|
||||
this->height,
|
||||
this->width,
|
||||
this->y,
|
||||
this->x)
|
||||
: derwin(
|
||||
this->parent->GetFrame(),
|
||||
this->height,
|
||||
this->width,
|
||||
this->y,
|
||||
this->x);
|
||||
|
||||
this->content = derwin(
|
||||
this->frame,
|
||||
this->height - 2,
|
||||
this->width - 2,
|
||||
1,
|
||||
1);
|
||||
/* if we were asked not to draw a frame, we'll set the frame equal to
|
||||
the content view, and use the content views colors*/
|
||||
|
||||
if (this->contentColor != -1) {
|
||||
wbkgd(this->content, COLOR_PAIR(this->contentColor));
|
||||
if (!this->drawFrame) {
|
||||
this->content = this->frame;
|
||||
|
||||
if (this->contentColor != -1) {
|
||||
wbkgd(this->frame, COLOR_PAIR(this->contentColor));
|
||||
}
|
||||
|
||||
wrefresh(this->content);
|
||||
}
|
||||
|
||||
if (this->frameColor != -1) {
|
||||
wbkgd(this->frame, COLOR_PAIR(this->frameColor));
|
||||
}
|
||||
/* otherwise we'll draw a box around the frame, and create a content
|
||||
sub-window inside */
|
||||
|
||||
touchwin(this->content);
|
||||
wrefresh(this->content);
|
||||
else {
|
||||
box(this->frame, 0, 0);
|
||||
|
||||
this->content = derwin(
|
||||
this->frame,
|
||||
this->height - 2,
|
||||
this->width - 2,
|
||||
1,
|
||||
1);
|
||||
|
||||
if (this->frameColor != -1) {
|
||||
wbkgd(this->frame, COLOR_PAIR(this->frameColor));
|
||||
}
|
||||
|
||||
if (this->contentColor != -1) {
|
||||
wbkgd(this->content, COLOR_PAIR(this->contentColor));
|
||||
}
|
||||
|
||||
wrefresh(this->frame);
|
||||
touchwin(this->content);
|
||||
wrefresh(this->content);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::SetFrameVisible(bool enabled) {
|
||||
if (enabled != this->drawFrame) {
|
||||
this->drawFrame = enabled;
|
||||
|
||||
if (this->frame || this->content) {
|
||||
this->Destroy();
|
||||
this->Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Window::IsFrameVisible() {
|
||||
return this->drawFrame;
|
||||
}
|
||||
|
||||
IWindow* Window::GetParent() const {
|
||||
return this->parent;
|
||||
}
|
||||
|
||||
void Window::Clear() {
|
||||
@ -117,7 +176,11 @@ void Window::Repaint() {
|
||||
void Window::Destroy() {
|
||||
if (this->frame) {
|
||||
delwin(this->content);
|
||||
delwin(this->frame);
|
||||
|
||||
if (this->content != this->frame) {
|
||||
delwin(this->frame);
|
||||
}
|
||||
|
||||
this->frame = this->content = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,17 @@
|
||||
|
||||
class Window : public IWindow {
|
||||
public:
|
||||
Window();
|
||||
Window(IWindow* parent = NULL);
|
||||
virtual ~Window();
|
||||
|
||||
void Create();
|
||||
virtual void Create();
|
||||
void Destroy();
|
||||
|
||||
virtual void Repaint();
|
||||
|
||||
void SetFrameVisible(bool enabled);
|
||||
bool IsFrameVisible();
|
||||
|
||||
virtual void SetContentColor(int color);
|
||||
virtual void SetFrameColor(int color);
|
||||
virtual void SetSize(int width, int height);
|
||||
@ -29,10 +32,14 @@ class Window : public IWindow {
|
||||
virtual WINDOW* GetContent() const;
|
||||
|
||||
protected:
|
||||
IWindow* GetParent() const;
|
||||
|
||||
void Clear();
|
||||
|
||||
private:
|
||||
IWindow* parent;
|
||||
WINDOW* frame;
|
||||
WINDOW* content;
|
||||
bool drawFrame;
|
||||
int width, height, x, y, contentColor, frameColor;
|
||||
};
|
@ -117,6 +117,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CategoryListQuery.cpp" />
|
||||
<ClCompile Include="CategoryListView.cpp" />
|
||||
<ClCompile Include="LayoutBase.cpp" />
|
||||
<ClCompile Include="ListWindow.cpp" />
|
||||
<ClCompile Include="ScrollAdapterBase.cpp" />
|
||||
<ClCompile Include="LibraryLayout.cpp" />
|
||||
@ -146,6 +147,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CategoryListQuery.h" />
|
||||
<ClInclude Include="CategoryListView.h" />
|
||||
<ClInclude Include="LayoutBase.h" />
|
||||
<ClInclude Include="ScrollAdapterBase.h" />
|
||||
<ClInclude Include="IScrollable.h" />
|
||||
<ClInclude Include="LibraryLayout.h" />
|
||||
|
@ -69,6 +69,9 @@
|
||||
<ClCompile Include="ListWindow.cpp">
|
||||
<Filter>curses</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LayoutBase.cpp">
|
||||
<Filter>curses</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
@ -144,6 +147,9 @@
|
||||
<ClInclude Include="ListWindow.h">
|
||||
<Filter>curses</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LayoutBase.h">
|
||||
<Filter>curses</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="curses">
|
||||
|
Loading…
x
Reference in New Issue
Block a user