diff --git a/src/musikbox/CategoryListView.cpp b/src/musikbox/CategoryListView.cpp index 6f6e7cc8e..cfaa5ec92 100755 --- a/src/musikbox/CategoryListView.cpp +++ b/src/musikbox/CategoryListView.cpp @@ -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()); diff --git a/src/musikbox/CategoryListView.h b/src/musikbox/CategoryListView.h index 9e2c31017..7a8dc9d14 100755 --- a/src/musikbox/CategoryListView.h +++ b/src/musikbox/CategoryListView.h @@ -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(); diff --git a/src/musikbox/CommandWindow.cpp b/src/musikbox/CommandWindow.cpp index aa844ef33..8da22f8d3 100755 --- a/src/musikbox/CommandWindow.cpp +++ b/src/musikbox/CommandWindow.cpp @@ -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]; diff --git a/src/musikbox/CommandWindow.h b/src/musikbox/CommandWindow.h index e825e14dd..197a4f8aa 100755 --- a/src/musikbox/CommandWindow.h +++ b/src/musikbox/CommandWindow.h @@ -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); diff --git a/src/musikbox/LayoutBase.cpp b/src/musikbox/LayoutBase.cpp new file mode 100755 index 000000000..657b7155c --- /dev/null +++ b/src/musikbox/LayoutBase.cpp @@ -0,0 +1,2 @@ +#include "stdafx.h" +#include "LayoutBase.h" diff --git a/src/musikbox/LayoutBase.h b/src/musikbox/LayoutBase.h new file mode 100755 index 000000000..b9831afc2 --- /dev/null +++ b/src/musikbox/LayoutBase.h @@ -0,0 +1,15 @@ +#pragma once + +#include "ILayout.h" +#include "Window.h" + +#include + +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; +}; \ No newline at end of file diff --git a/src/musikbox/LibraryLayout.cpp b/src/musikbox/LibraryLayout.cpp index 7e0fba7b7..4415b8a78 100755 --- a/src/musikbox/LibraryLayout.cpp +++ b/src/musikbox/LibraryLayout.cpp @@ -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(); } diff --git a/src/musikbox/LibraryLayout.h b/src/musikbox/LibraryLayout.h index 947c14066..264cbb529 100755 --- a/src/musikbox/LibraryLayout.h +++ b/src/musikbox/LibraryLayout.h @@ -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 */ diff --git a/src/musikbox/ListWindow.cpp b/src/musikbox/ListWindow.cpp index ae2343a23..fd7eb4236 100755 --- a/src/musikbox/ListWindow.cpp +++ b/src/musikbox/ListWindow.cpp @@ -3,8 +3,8 @@ typedef IScrollAdapter::ScrollPosition ScrollPos; -ListWindow::ListWindow() -: ScrollableWindow() { +ListWindow::ListWindow(IWindow *parent) +: ScrollableWindow(parent) { this->selectedIndex = 0; } diff --git a/src/musikbox/ListWindow.h b/src/musikbox/ListWindow.h index cd566182b..8db87851a 100755 --- a/src/musikbox/ListWindow.h +++ b/src/musikbox/ListWindow.h @@ -6,7 +6,7 @@ class ListWindow : public ScrollableWindow { public: - ListWindow(); + ListWindow(IWindow *parent = NULL); virtual ~ListWindow(); virtual void ScrollToTop(); diff --git a/src/musikbox/LogWindow.cpp b/src/musikbox/LogWindow.cpp index 494a7e340..416df3e68 100755 --- a/src/musikbox/LogWindow.cpp +++ b/src/musikbox/LogWindow.cpp @@ -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(); diff --git a/src/musikbox/LogWindow.h b/src/musikbox/LogWindow.h index 3d8931df4..17c255c50 100755 --- a/src/musikbox/LogWindow.h +++ b/src/musikbox/LogWindow.h @@ -9,7 +9,7 @@ class LogWindow : public ScrollableWindow, public sigslot::has_slots<> { public: - LogWindow(); + LogWindow(IWindow *parent = NULL); ~LogWindow(); void Update(); diff --git a/src/musikbox/Main.cpp b/src/musikbox/Main.cpp index c6b222b7b..686e00a27 100644 --- a/src/musikbox/Main.cpp +++ b/src/musikbox/Main.cpp @@ -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(focused); IScrollable* scrollable = dynamic_cast(focused); diff --git a/src/musikbox/MainLayout.cpp b/src/musikbox/MainLayout.cpp index 9a777e2e5..a80a6289a 100755 --- a/src/musikbox/MainLayout.cpp +++ b/src/musikbox/MainLayout.cpp @@ -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()); diff --git a/src/musikbox/MainLayout.h b/src/musikbox/MainLayout.h index 5c5558851..5c03e2b72 100755 --- a/src/musikbox/MainLayout.h +++ b/src/musikbox/MainLayout.h @@ -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(); diff --git a/src/musikbox/OutputWindow.cpp b/src/musikbox/OutputWindow.cpp index 488078548..f88f4e07e 100755 --- a/src/musikbox/OutputWindow.cpp +++ b/src/musikbox/OutputWindow.cpp @@ -8,8 +8,8 @@ typedef IScrollAdapter::EntryPtr EntryPtr; -OutputWindow::OutputWindow() -: ScrollableWindow() +OutputWindow::OutputWindow(IWindow *parent) +: ScrollableWindow(parent) { this->SetContentColor(BOX_COLOR_BLACK_ON_GREY); diff --git a/src/musikbox/OutputWindow.h b/src/musikbox/OutputWindow.h index cee4e5a13..789a988fa 100755 --- a/src/musikbox/OutputWindow.h +++ b/src/musikbox/OutputWindow.h @@ -7,7 +7,7 @@ class OutputWindow : public ScrollableWindow { public: - OutputWindow(); + OutputWindow(IWindow *parent = NULL); ~OutputWindow(); void WriteLine(const std::string& line, int64 attrs = -1); diff --git a/src/musikbox/ResourcesWindow.cpp b/src/musikbox/ResourcesWindow.cpp index 0c274b632..fa30b269d 100755 --- a/src/musikbox/ResourcesWindow.cpp +++ b/src/musikbox/ResourcesWindow.cpp @@ -9,8 +9,8 @@ #include -ResourcesWindow::ResourcesWindow() -: Window() { +ResourcesWindow::ResourcesWindow(IWindow *parent) +: Window(parent) { this->systemInfo = SystemInfo::Create(); } diff --git a/src/musikbox/ResourcesWindow.h b/src/musikbox/ResourcesWindow.h index 6c482f1bc..12ffa04f2 100755 --- a/src/musikbox/ResourcesWindow.h +++ b/src/musikbox/ResourcesWindow.h @@ -6,7 +6,7 @@ class ResourcesWindow : public Window { public: - ResourcesWindow(); + ResourcesWindow(IWindow *parent = NULL); virtual ~ResourcesWindow(); virtual void Repaint(); diff --git a/src/musikbox/ScrollableWindow.cpp b/src/musikbox/ScrollableWindow.cpp index a29125052..cbb4cdbb2 100755 --- a/src/musikbox/ScrollableWindow.cpp +++ b/src/musikbox/ScrollableWindow.cpp @@ -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); diff --git a/src/musikbox/ScrollableWindow.h b/src/musikbox/ScrollableWindow.h index 8747bb7c5..59044a3f9 100755 --- a/src/musikbox/ScrollableWindow.h +++ b/src/musikbox/ScrollableWindow.h @@ -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(); diff --git a/src/musikbox/TrackListView.cpp b/src/musikbox/TrackListView.cpp index fc0782b53..19bd37fbe 100755 --- a/src/musikbox/TrackListView.cpp +++ b/src/musikbox/TrackListView.cpp @@ -3,8 +3,8 @@ #include "stdafx.h" #include "TrackListView.h" -TrackListView::TrackListView() -: Window() { +TrackListView::TrackListView(IWindow *parent) +: Window(parent) { } diff --git a/src/musikbox/TrackListView.h b/src/musikbox/TrackListView.h index 512ef7f72..8c2cdc9b7 100755 --- a/src/musikbox/TrackListView.h +++ b/src/musikbox/TrackListView.h @@ -5,7 +5,7 @@ class TrackListView : public Window { public: - TrackListView(); + TrackListView(IWindow *parent); ~TrackListView(); private: diff --git a/src/musikbox/TransportWindow.cpp b/src/musikbox/TransportWindow.cpp index 4fae76c2d..2783593be 100755 --- a/src/musikbox/TransportWindow.cpp +++ b/src/musikbox/TransportWindow.cpp @@ -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; diff --git a/src/musikbox/TransportWindow.h b/src/musikbox/TransportWindow.h index 70738d813..3d9bca4c4 100755 --- a/src/musikbox/TransportWindow.h +++ b/src/musikbox/TransportWindow.h @@ -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(); diff --git a/src/musikbox/Window.cpp b/src/musikbox/Window.cpp index e8a4019cc..087970109 100755 --- a/src/musikbox/Window.cpp +++ b/src/musikbox/Window.cpp @@ -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; } } diff --git a/src/musikbox/Window.h b/src/musikbox/Window.h index c1b83abcf..0cf4a9488 100755 --- a/src/musikbox/Window.h +++ b/src/musikbox/Window.h @@ -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; }; \ No newline at end of file diff --git a/src/musikbox/musikbox.vcxproj b/src/musikbox/musikbox.vcxproj index a9c2119a9..12d6fe2d4 100755 --- a/src/musikbox/musikbox.vcxproj +++ b/src/musikbox/musikbox.vcxproj @@ -117,6 +117,7 @@ + @@ -146,6 +147,7 @@ + diff --git a/src/musikbox/musikbox.vcxproj.filters b/src/musikbox/musikbox.vcxproj.filters index 3f6badc8c..4f21acffc 100755 --- a/src/musikbox/musikbox.vcxproj.filters +++ b/src/musikbox/musikbox.vcxproj.filters @@ -69,6 +69,9 @@ curses + + curses + @@ -144,6 +147,9 @@ curses + + curses +