cursespp and musikbox are compiling! not running though.

This commit is contained in:
Casey Langen 2016-05-25 23:31:15 -07:00
parent e33f9928fb
commit d12eae819d
53 changed files with 290 additions and 225 deletions

View File

@ -48,10 +48,11 @@ set (musikbox_LINK_LIBS
include_directories ( include_directories (
"${musikbox_SOURCE_DIR}/src" "${musikbox_SOURCE_DIR}/src"
"${musikbox_SOURCE_DIR}/src/core" "${musikbox_SOURCE_DIR}/src/core"
"${musikbox_SOURCE_DIR}/src/musikbox"
"${musikbox_SOURCE_DIR}/src/3rdparty/include" "${musikbox_SOURCE_DIR}/src/3rdparty/include"
) )
add_subdirectory(src/3rdparty) add_subdirectory(src/3rdparty)
add_subdirectory(src/core) add_subdirectory(src/core)
#add_subdirectory(src/contrib) #add_subdirectory(src/contrib)
#add_subdirectory(src/musikbox) add_subdirectory(src/musikbox)

View File

@ -1,20 +1,84 @@
set (SQUARE_SRCS set (BOX_SRCS
stdafx.cpp ./Main.cpp
player.cpp ./stdafx.cpp
DummyAudioEventHandler.cpp ./app/layout/LibraryLayout.cpp
ConsoleUI.cpp ./app/layout/MainLayout.cpp
./app/query/CategoryListViewQuery.cpp
./app/query/SingleTrackQuery.cpp
./app/query/TrackListViewQuery.cpp
./app/service/PlaybackService.cpp
./app/util/GlobalHotkeys.cpp
./app/util/SystemInfo.cpp
./app/util/Text.cpp
./app/window/CategoryListView.cpp
./app/window/CommandWindow.cpp
./app/window/LogWindow.cpp
./app/window/OutputWindow.cpp
./app/window/ResourcesWindow.cpp
./app/window/TrackListView.cpp
./app/window/TransportWindow.cpp
./cursespp/Colors.cpp
./cursespp/LayoutBase.cpp
./cursespp/LayoutStack.cpp
./cursespp/ListWindow.cpp
./cursespp/Message.cpp
./cursespp/MessageQueue.cpp
./cursespp/MultiLineEntry.cpp
./cursespp/Screen.cpp
./cursespp/ScrollableWindow.cpp
./cursespp/ScrollAdapterBase.cpp
./cursespp/SimpleScrollAdapter.cpp
./cursespp/SingleLineEntry.cpp
./cursespp/Window.cpp
./cursespp/WindowLayout.cpp
) )
set (SQUARE_HEADERS set (BOX_HEADERS
config.h ./stdafx.h
ConsoleUI.h ./app/layout/LibraryLayout.h
DummyAudioEventHandler.h ./app/layout/MainLayout.h
memtrace.h ./app/query/CategoryListViewQuery.h
stdafx.h ./app/query/SingleTrackQuery.h
./app/query/TrackListViewQuery.h
./app/service/PlaybackService.h
./app/util/GlobalHotkeys.h
./app/util/SystemInfo.h
./app/util/Text.h
./app/window/CategoryListView.h
./app/window/CommandWindow.h
./app/window/LogWindow.h
./app/window/OutputWindow.h
./app/window/ResourcesWindow.h
./app/window/TrackListView.h
./app/window/TransportWindow.h
./cursespp/Colors.h
./cursespp/curses_config.h
./cursespp/IDisplayable.h
./cursespp/IInput.h
./cursespp/IKeyHandler.h
./cursespp/ILayout.h
./cursespp/ILayoutStack.h
./cursespp/IMessage.h
./cursespp/IMessageTarget.h
./cursespp/IOrderable.h
./cursespp/IScrollable.h
./cursespp/IScrollAdapter.h
./cursespp/IWindow.h
./cursespp/IWindowGroup.h
./cursespp/LayoutBase.h
./cursespp/LayoutStack.h
./cursespp/ListWindow.h
./cursespp/Message.h
./cursespp/MessageQueue.h
./cursespp/MultiLineEntry.h
./cursespp/Screen.h
./cursespp/ScrollableWindow.h
./cursespp/ScrollAdapterBase.h
./cursespp/SimpleScrollAdapter.h
./cursespp/SingleLineEntry.h
./cursespp/Window.h
./cursespp/WindowLayout.h
) )
SOURCE_GROUP ("Source Files" FILES ${SQUARE_SRCS}) add_executable(musikbox ${BOX_SRCS} ${BOX_HEADERS})
SOURCE_GROUP ("Header Files" FILES ${SQUARE_HEADERS}) target_link_libraries(musikbox ${musikbox_LINK_LIBS} curses panel musikcore)
add_executable(square ${SQUARE_SRCS} ${SQUARE_HEADERS})
target_link_libraries(square ${musikCube_LINK_LIBS} musik)

View File

@ -3,31 +3,31 @@
// //
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met: // modification, are permitted provided that the following conditions are met:
// //
// * Redistributions of source code must retain the above copyright notice, // * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// * Redistributions in binary form must reproduce the above copyright // * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the // notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution. // documentation and/or other materials provided with the distribution.
// //
// * Neither the name of the author nor the names of other contributors may // * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software // be used to endorse or promote products derived from this software
// without specific prior written permission. // without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE. // POSSIBILITY OF SUCH DAMAGE.
// //
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -95,7 +95,7 @@ static void changeLayout(WindowState& current, ILayoutPtr newLayout) {
if (current.layout) { if (current.layout) {
current.layout->Hide(); current.layout->Hide();
current.layout = { 0 }; current.layout.reset();
} }
if (newLayout) { if (newLayout) {
@ -149,7 +149,7 @@ int main(int argc, char* argv[])
std::locale locale = std::locale(); std::locale locale = std::locale();
std::locale utf8Locale(locale, new boost::filesystem::detail::utf8_codecvt_facet); std::locale utf8Locale(locale, new boost::filesystem::detail::utf8_codecvt_facet);
boost::filesystem::path::imbue(utf8Locale); boost::filesystem::path::imbue(utf8Locale);
musik::debug::init(); musik::debug::init();
ttytype[0] = 30; /* min height */ ttytype[0] = 30; /* min height */
@ -184,14 +184,17 @@ int main(int argc, char* argv[])
GlobalHotkeys globalHotkeys(playback, library); GlobalHotkeys globalHotkeys(playback, library);
ILayoutPtr libraryLayout(new LibraryLayout(playback, library)); ILayoutPtr libraryLayout((ILayout *) new LibraryLayout(playback, library));
ILayoutPtr consoleLayout(new MainLayout(tp, library)); ILayoutPtr consoleLayout((ILayout *) new MainLayout(tp, library));
int64 ch; int64 ch;
timeout(IDLE_TIMEOUT_MS); timeout(IDLE_TIMEOUT_MS);
bool quit = false; bool quit = false;
WindowState state = { 0 }; WindowState state;
state.input = NULL;
state.keyHandler = NULL;
changeLayout(state, libraryLayout); changeLayout(state, libraryLayout);
while (!quit) { while (!quit) {
@ -249,4 +252,3 @@ int main(int argc, char* argv[])
return 0; return 0;
} }

View File

@ -136,4 +136,4 @@ bool LibraryLayout::KeyPress(int64 ch) {
} }
return LayoutBase::KeyPress(ch); return LayoutBase::KeyPress(ch);
} }

View File

@ -17,16 +17,16 @@ namespace musik {
class LibraryLayout : public cursespp::LayoutBase, public sigslot::has_slots<> { class LibraryLayout : public cursespp::LayoutBase, public sigslot::has_slots<> {
public: public:
LibraryLayout( LibraryLayout(
PlaybackService& playback, PlaybackService& playback,
musik::core::LibraryPtr library); musik::core::LibraryPtr library);
virtual ~LibraryLayout(); virtual ~LibraryLayout();
virtual void Layout(); virtual void Layout();
virtual void Show(); virtual void Show();
virtual bool LibraryLayout::KeyPress(int64 ch); virtual cursespp::IWindowPtr GetFocus();
virtual cursespp::IWindowPtr GetFocus(); virtual bool KeyPress(int64 ch);
private: private:
void InitializeWindows(); void InitializeWindows();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "MainLayout.h" #include "MainLayout.h"
#include <cursespp/Screen.h> #include <cursespp/Screen.h>
@ -73,4 +71,4 @@ void MainLayout::ProcessMessage(IMessage &message) {
void MainLayout::UpdateWindows() { void MainLayout::UpdateWindows() {
this->logs->Update(); this->logs->Update();
this->resources->Update(); this->resources->Update();
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "CategoryListViewQuery.h" #include "CategoryListViewQuery.h"
@ -17,7 +15,7 @@ using namespace musik::core::db;
using namespace musik::core::library::constants; using namespace musik::core::library::constants;
using namespace musik::box; using namespace musik::box;
#define reset(x) x.reset(new std::vector<std::shared_ptr<Result>>); #define reset(x) x.reset(new std::vector<std::shared_ptr<Result> >);
static const std::string ALBUM_QUERY = static const std::string ALBUM_QUERY =
"SELECT DISTINCT albums.id, albums.name " "SELECT DISTINCT albums.id, albums.name "
@ -41,9 +39,9 @@ static boost::mutex QUERY_MAP_MUTEX;
static std::map<std::string, std::string> FIELD_TO_QUERY_MAP; static std::map<std::string, std::string> FIELD_TO_QUERY_MAP;
static void initFieldToQueryMap() { static void initFieldToQueryMap() {
FIELD_TO_QUERY_MAP.emplace(Track::ALBUM_ID, ALBUM_QUERY); FIELD_TO_QUERY_MAP[Track::ALBUM_ID] = ALBUM_QUERY;
FIELD_TO_QUERY_MAP.emplace(Track::ARTIST_ID, ARTIST_QUERY); FIELD_TO_QUERY_MAP[Track::ARTIST_ID] = ARTIST_QUERY;
FIELD_TO_QUERY_MAP.emplace(Track::GENRE_ID, GENRE_QUERY); FIELD_TO_QUERY_MAP[Track::GENRE_ID] = GENRE_QUERY;
} }
CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) { CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) {
@ -77,7 +75,7 @@ bool CategoryListViewQuery::OnRun(Connection& db) {
std::string query = FIELD_TO_QUERY_MAP[this->trackField]; std::string query = FIELD_TO_QUERY_MAP[this->trackField];
Statement stmt(query.c_str(), db); Statement stmt(query.c_str(), db);
while (stmt.Step() == Row) { while (stmt.Step() == Row) {
std::shared_ptr<Result> row(new Result()); std::shared_ptr<Result> row(new Result());
row->id = stmt.ColumnInt64(0); row->id = stmt.ColumnInt64(0);
@ -86,4 +84,4 @@ bool CategoryListViewQuery::OnRun(Connection& db) {
} }
return true; return true;
} }

View File

@ -14,7 +14,7 @@ namespace musik {
}; };
typedef std::shared_ptr<std::vector< typedef std::shared_ptr<std::vector<
std::shared_ptr<Result>>> ResultList; std::shared_ptr<Result> > > ResultList;
CategoryListViewQuery(const std::string& trackField); CategoryListViewQuery(const std::string& trackField);
virtual ~CategoryListViewQuery(); virtual ~CategoryListViewQuery();
@ -30,4 +30,4 @@ namespace musik {
ResultList result; ResultList result;
}; };
} }
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "SingleTrackQuery.h" #include "SingleTrackQuery.h"
@ -32,4 +30,4 @@ bool SingleTrackQuery::OnRun(Connection& db) {
result.reset(new LibraryTrack()); result.reset(new LibraryTrack());
result->SetValue("filename", filename.c_str()); result->SetValue("filename", filename.c_str());
return LibraryTrack::Load(result.get(), db); return LibraryTrack::Load(result.get(), db);
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "TrackListViewQuery.h" #include "TrackListViewQuery.h"
@ -66,4 +64,4 @@ bool TrackListViewQuery::OnRun(Connection& db) {
} }
return true; return true;
} }

View File

@ -10,10 +10,10 @@ namespace musik {
class TrackListViewQuery : public musik::core::query::QueryBase { class TrackListViewQuery : public musik::core::query::QueryBase {
public: public:
typedef std::shared_ptr< typedef std::shared_ptr<
std::vector<musik::core::TrackPtr>> Result; std::vector<musik::core::TrackPtr> > Result;
TrackListViewQuery( TrackListViewQuery(
musik::core::LibraryPtr library, musik::core::LibraryPtr library,
const std::string& column, DBID id); const std::string& column, DBID id);
virtual ~TrackListViewQuery(); virtual ~TrackListViewQuery();

View File

@ -2,13 +2,14 @@
#include "SystemInfo.h" #include "SystemInfo.h"
using namespace musik::box;
#ifdef WIN32
#include "windows.h" #include "windows.h"
#include "psapi.h" #include "psapi.h"
#include "pdh.h" #include "pdh.h"
using namespace musik::box;
#ifdef WIN32
class WindowsSystemInfo : public SystemInfo { class WindowsSystemInfo : public SystemInfo {
public: public:
WindowsSystemInfo(); WindowsSystemInfo();
@ -125,15 +126,15 @@ double WindowsSystemInfo::GetCpuUsage() {
FILETIME ftime, fsys, fuser; FILETIME ftime, fsys, fuser;
ULARGE_INTEGER now, sys, user; ULARGE_INTEGER now, sys, user;
double percent; double percent;
GetSystemTimeAsFileTime(&ftime); GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME)); memcpy(&now, &ftime, sizeof(FILETIME));
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser); GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME)); memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME)); memcpy(&user, &fuser, sizeof(FILETIME));
percent = percent =
(double) (sys.QuadPart - lastSysCpu.QuadPart) + (double) (sys.QuadPart - lastSysCpu.QuadPart) +
(double) (user.QuadPart - lastUserCpu.QuadPart); (double) (user.QuadPart - lastUserCpu.QuadPart);
@ -142,11 +143,11 @@ double WindowsSystemInfo::GetCpuUsage() {
percent /= diff; percent /= diff;
percent /= processorCount; percent /= processorCount;
lastCpu = now; lastCpu = now;
lastUserCpu = user; lastUserCpu = user;
lastSysCpu = sys; lastSysCpu = sys;
return (percent * 100.0f); return (percent * 100.0f);
} }
#endif #endif

View File

@ -16,12 +16,13 @@ namespace musik {
size_t c = 0; size_t c = 0;
while (c < len && it != str.end()) { while (c < len && it != str.end()) {
try { try {
utf8::next(it++, end); utf8::next(it, end);
} }
catch (...) { catch (...) {
it++; /* invalid encoding, just treat as a single char */ /* invalid encoding, just treat as a single char */
} }
++it;
++c; ++c;
} }
@ -52,4 +53,4 @@ namespace musik {
} }
} }
} }
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include <cursespp/Colors.h> #include <cursespp/Colors.h>
@ -84,7 +82,7 @@ IScrollAdapter& CategoryListView::GetScrollAdapter() {
return *adapter; return *adapter;
} }
CategoryListView::Adapter::Adapter(CategoryListView &parent) CategoryListView::Adapter::Adapter(CategoryListView &parent)
: parent(parent) { : parent(parent) {
} }
@ -100,4 +98,4 @@ IScrollAdapter::EntryPtr CategoryListView::Adapter::GetEntry(size_t index) {
IScrollAdapter::EntryPtr entry(new SingleLineEntry(value)); IScrollAdapter::EntryPtr entry(new SingleLineEntry(value));
entry->SetAttrs(attrs); entry->SetAttrs(attrs);
return entry; return entry;
} }

View File

@ -20,7 +20,11 @@ using cursespp::ScrollAdapterBase;
namespace musik { namespace musik {
namespace box { namespace box {
class CategoryListView : public ListWindow, public sigslot::has_slots<> { class CategoryListView :
public ListWindow,
public std::enable_shared_from_this<CategoryListView>,
public sigslot::has_slots<>
{
public: public:
CategoryListView(LibraryPtr library, const std::string& fieldName); CategoryListView(LibraryPtr library, const std::string& fieldName);
virtual ~CategoryListView(); virtual ~CategoryListView();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include <cursespp/Screen.h> #include <cursespp/Screen.h>
@ -41,8 +39,8 @@ bool tostr(T& t, const std::string& s) {
CommandWindow::CommandWindow( CommandWindow::CommandWindow(
IWindow *parent, IWindow *parent,
Transport& transport, Transport& transport,
LibraryPtr library, LibraryPtr library,
OutputWindow& output) OutputWindow& output)
: Window(parent) { : Window(parent) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK); this->SetContentColor(BOX_COLOR_WHITE_ON_BLACK);
this->transport = &transport; this->transport = &transport;
@ -232,7 +230,7 @@ void CommandWindow::ListPlugins() const {
using musik::core::IPlugin; using musik::core::IPlugin;
using musik::core::PluginFactory; using musik::core::PluginFactory;
typedef std::vector<std::shared_ptr<IPlugin>> PluginList; typedef std::vector<std::shared_ptr<IPlugin> > PluginList;
typedef PluginFactory::NullDeleter<IPlugin> Deleter; typedef PluginFactory::NullDeleter<IPlugin> Deleter;
PluginList plugins = PluginFactory::Instance() PluginList plugins = PluginFactory::Instance()
@ -248,4 +246,4 @@ void CommandWindow::ListPlugins() const {
this->output->WriteLine(format, BOX_COLOR_RED_ON_BLUE); this->output->WriteLine(format, BOX_COLOR_RED_ON_BLUE);
} }
} }

View File

@ -9,10 +9,11 @@
namespace musik { namespace musik {
namespace box { namespace box {
class CommandWindow : class CommandWindow :
public cursespp::Window, public cursespp::Window,
public cursespp::IInput, public cursespp::IInput,
public sigslot::has_slots<> public std::enable_shared_from_this<CommandWindow>,
public sigslot::has_slots<>
{ {
public: public:
CommandWindow( CommandWindow(
@ -21,7 +22,7 @@ namespace musik {
musik::core::LibraryPtr library, musik::core::LibraryPtr library,
OutputWindow& output); OutputWindow& output);
~CommandWindow(); virtual ~CommandWindow();
virtual void WriteChar(int64 ch); virtual void WriteChar(int64 ch);
virtual void Focus(); virtual void Focus();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "LogWindow.h" #include "LogWindow.h"
@ -13,7 +11,7 @@ using namespace cursespp;
typedef IScrollAdapter::IEntry IEntry; typedef IScrollAdapter::IEntry IEntry;
LogWindow::LogWindow(IWindow *parent) LogWindow::LogWindow(IWindow *parent)
: ScrollableWindow(parent) { : ScrollableWindow(parent) {
this->SetContentColor(BOX_COLOR_WHITE_ON_BLUE); this->SetContentColor(BOX_COLOR_WHITE_ON_BLUE);
@ -81,4 +79,4 @@ void LogWindow::OnLogged( /* from a background thread */
entry->tag = tag; entry->tag = tag;
entry->message = message; entry->message = message;
pending.push_back(entry); pending.push_back(entry);
} }

View File

@ -11,10 +11,14 @@
namespace musik { namespace musik {
namespace box { namespace box {
class LogWindow : public cursespp::ScrollableWindow, public sigslot::has_slots<> { class LogWindow :
public cursespp::ScrollableWindow,
public std::enable_shared_from_this<LogWindow>,
public sigslot::has_slots<>
{
public: public:
LogWindow(cursespp::IWindow *parent = NULL); LogWindow(cursespp::IWindow *parent = NULL);
~LogWindow(); virtual ~LogWindow();
void Update(); void Update();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "OutputWindow.h" #include "OutputWindow.h"
@ -13,7 +11,7 @@ using namespace cursespp;
typedef IScrollAdapter::EntryPtr EntryPtr; typedef IScrollAdapter::EntryPtr EntryPtr;
OutputWindow::OutputWindow(IWindow *parent) OutputWindow::OutputWindow(IWindow *parent)
: ScrollableWindow(parent) { : ScrollableWindow(parent) {
this->SetContentColor(BOX_COLOR_BLACK_ON_GREY); this->SetContentColor(BOX_COLOR_BLACK_ON_GREY);
this->adapter = new SimpleScrollAdapter(); this->adapter = new SimpleScrollAdapter();
@ -32,4 +30,4 @@ IScrollAdapter& OutputWindow::GetScrollAdapter() {
void OutputWindow::WriteLine(const std::string& text, int64 attrs) { void OutputWindow::WriteLine(const std::string& text, int64 attrs) {
this->adapter->AddEntry(EntryPtr(new MultiLineEntry(text, attrs))); this->adapter->AddEntry(EntryPtr(new MultiLineEntry(text, attrs)));
this->OnAdapterChanged(); this->OnAdapterChanged();
} }

View File

@ -7,16 +7,19 @@
namespace musik { namespace musik {
namespace box { namespace box {
class OutputWindow : public cursespp::ScrollableWindow { class OutputWindow :
public: public cursespp::ScrollableWindow,
OutputWindow(cursespp::IWindow *parent = NULL); public std::enable_shared_from_this<OutputWindow>
~OutputWindow(); {
public:
OutputWindow(cursespp::IWindow *parent = NULL);
virtual ~OutputWindow();
void WriteLine(const std::string& line, int64 attrs = -1); void WriteLine(const std::string& line, int64 attrs = -1);
virtual cursespp::IScrollAdapter& GetScrollAdapter(); virtual cursespp::IScrollAdapter& GetScrollAdapter();
private: private:
cursespp::SimpleScrollAdapter* adapter; cursespp::SimpleScrollAdapter* adapter;
}; };
} }
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "ResourcesWindow.h" #include "ResourcesWindow.h"
@ -16,7 +14,7 @@ using namespace cursespp;
#define BYTES_PER_MEGABYTE 1048576.0f #define BYTES_PER_MEGABYTE 1048576.0f
ResourcesWindow::ResourcesWindow(IWindow *parent) ResourcesWindow::ResourcesWindow(IWindow *parent)
: Window(parent) { : Window(parent) {
this->systemInfo = SystemInfo::Create(); this->systemInfo = SystemInfo::Create();
} }
@ -33,11 +31,11 @@ void ResourcesWindow::Update() {
double cpuUsage = (double) systemInfo->GetCpuUsage(); double cpuUsage = (double) systemInfo->GetCpuUsage();
wprintw( wprintw(
this->GetContent(), this->GetContent(),
"cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)", "cpu %.2f%% - virt %.2f (mb) - phys %.2f (mb)",
cpuUsage, cpuUsage,
virtualMemoryUsed, virtualMemoryUsed,
physicalMemoryUsed); physicalMemoryUsed);
this->Repaint(); this->Repaint();
} }

View File

@ -7,7 +7,10 @@
namespace musik { namespace musik {
namespace box { namespace box {
class ResourcesWindow : public cursespp::Window { class ResourcesWindow :
public cursespp::Window,
public std::enable_shared_from_this<ResourcesWindow>
{
public: public:
ResourcesWindow(cursespp::IWindow *parent = NULL); ResourcesWindow(cursespp::IWindow *parent = NULL);
virtual ~ResourcesWindow(); virtual ~ResourcesWindow();

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include <cursespp/Colors.h> #include <cursespp/Colors.h>
@ -132,7 +130,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
duration = text::Duration(duration); duration = text::Duration(duration);
std::string text = boost::str( std::string text = boost::str(
boost::format("%s %s %s %s %s") boost::format("%s %s %s %s %s")
% group(setw(column0Width), setfill(' '), trackNum) % group(setw(column0Width), setfill(' '), trackNum)
% group(setw(column1Width), setiosflags(std::ios::left), setfill(' '), title) % group(setw(column1Width), setiosflags(std::ios::left), setfill(' '), title)
% group(setw(column2Width), setiosflags(std::ios::right), setfill(' '), duration) % group(setw(column2Width), setiosflags(std::ios::right), setfill(' '), duration)
@ -144,4 +142,4 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) {
entry->SetAttrs(attrs); entry->SetAttrs(attrs);
return entry; return entry;
} }

View File

@ -13,13 +13,17 @@
namespace musik { namespace musik {
namespace box { namespace box {
class TrackListView : public cursespp::ListWindow, public sigslot::has_slots<> { class TrackListView :
public cursespp::ListWindow,
public std::enable_shared_from_this<TrackListView>,
public sigslot::has_slots<>
{
public: public:
TrackListView( TrackListView(
PlaybackService& playback, PlaybackService& playback,
musik::core::LibraryPtr library); musik::core::LibraryPtr library);
~TrackListView(); virtual ~TrackListView();
virtual void ProcessMessage(cursespp::IMessage &message); virtual void ProcessMessage(cursespp::IMessage &message);
virtual bool KeyPress(int64 ch); virtual bool KeyPress(int64 ch);
@ -44,7 +48,7 @@ namespace musik {
private: private:
std::shared_ptr<TrackListViewQuery> query; std::shared_ptr<TrackListViewQuery> query;
std::shared_ptr<std::vector<TrackPtr>> metadata; std::shared_ptr<std::vector<TrackPtr> > metadata;
Adapter* adapter; Adapter* adapter;
PlaybackService& playback; PlaybackService& playback;
musik::core::LibraryPtr library; musik::core::LibraryPtr library;

View File

@ -1,5 +1,3 @@
#pragma once
#include "stdafx.h" #include "stdafx.h"
#include "TransportWindow.h" #include "TransportWindow.h"
@ -18,6 +16,8 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/chrono.hpp> #include <boost/chrono.hpp>
#include <algorithm>
using namespace musik::core; using namespace musik::core;
using namespace musik::core::audio; using namespace musik::core::audio;
using namespace musik::core::library; using namespace musik::core::library;
@ -56,9 +56,9 @@ void TransportWindow::Show() {
} }
void TransportWindow::ProcessMessage(IMessage &message) { void TransportWindow::ProcessMessage(IMessage &message) {
int type = message.Type(); int type = message.Type();
if (type == REFRESH_TRANSPORT_READOUT) { if (type == REFRESH_TRANSPORT_READOUT) {
this->Update(); this->Update();
DEBOUNCE_REFRESH(REFRESH_INTERVAL_MS) DEBOUNCE_REFRESH(REFRESH_INTERVAL_MS)
} }
@ -102,19 +102,19 @@ void TransportWindow::Update() {
WINDOW *c = this->GetContent(); WINDOW *c = this->GetContent();
bool paused = (transport->GetPlaybackState() == Transport::PlaybackPaused); bool paused = (transport->GetPlaybackState() == Transport::PlaybackPaused);
int64 gb = COLOR_PAIR(this->focused int64 gb = COLOR_PAIR(this->focused
? BOX_COLOR_RED_ON_BLACK ? BOX_COLOR_RED_ON_BLACK
: BOX_COLOR_GREEN_ON_BLACK); : BOX_COLOR_GREEN_ON_BLACK);
/* playing SONG TITLE from ALBUM NAME */ /* playing SONG TITLE from ALBUM NAME */
std::string duration = "0"; std::string duration = "0";
if (transport->GetPlaybackState() == Transport::PlaybackStopped) { if (transport->GetPlaybackState() == Transport::PlaybackStopped) {
wattron(c, gb); wattron(c, gb);
wprintw(c, "playback is stopped"); wprintw(c, "playback is stopped");
wattroff(c, gb); wattroff(c, gb);
} }
else { else {
std::string title, album; std::string title, album;
@ -144,9 +144,9 @@ void TransportWindow::Update() {
/* volume slider */ /* volume slider */
wprintw(c, "\n"); wprintw(c, "\n");
int volumePercent = (size_t) round(this->transport->Volume() * 100.0f) - 1; int volumePercent = (size_t) round(this->transport->Volume() * 100.0f) - 1;
int thumbOffset = min(9, (volumePercent * 10) / 100); int thumbOffset = std::min(9, (volumePercent * 10) / 100);
std::string volume = "vol "; std::string volume = "vol ";
@ -190,7 +190,7 @@ void TransportWindow::Update() {
if (secondsTotal) { if (secondsTotal) {
size_t progress = (secondsCurrent * 100) / secondsTotal; size_t progress = (secondsCurrent * 100) / secondsTotal;
thumbOffset = min(timerWidth - 1, (progress * timerWidth) / 100); thumbOffset = std::min(timerWidth - 1, (progress * timerWidth) / 100);
} }
std::string timerTrack = ""; std::string timerTrack = "";
@ -202,9 +202,9 @@ void TransportWindow::Update() {
wprintw(c, currentTime.c_str()); wprintw(c, currentTime.c_str());
wattroff(c, timerAttrs); wattroff(c, timerAttrs);
wprintw(c, " %s %s", wprintw(c, " %s %s",
timerTrack.c_str(), timerTrack.c_str(),
totalTime.c_str()); totalTime.c_str());
this->Repaint(); this->Repaint();
} }

View File

@ -10,10 +10,14 @@
namespace musik { namespace musik {
namespace box { namespace box {
class TransportWindow : public cursespp::Window, public sigslot::has_slots<> { class TransportWindow :
public cursespp::Window,
public std::enable_shared_from_this<TransportWindow>,
public sigslot::has_slots<>
{
public: public:
TransportWindow( TransportWindow(
musik::core::LibraryPtr library, musik::core::LibraryPtr library,
musik::core::audio::Transport& transport); musik::core::audio::Transport& transport);
~TransportWindow(); ~TransportWindow();

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "Colors.h" #include "Colors.h"
@ -20,4 +18,4 @@ void Colors::Init() {
init_pair(BOX_COLOR_RED_ON_GREY, COLOR_RED, COLOR_WHITE); init_pair(BOX_COLOR_RED_ON_GREY, COLOR_RED, COLOR_WHITE);
init_pair(BOX_COLOR_GREEN_ON_BLACK, COLOR_GREEN, COLOR_BLACK); init_pair(BOX_COLOR_GREEN_ON_BLACK, COLOR_GREEN, COLOR_BLACK);
init_pair(BOX_COLOR_BLACK_ON_BLACK, COLOR_BLACK, COLOR_BLACK); init_pair(BOX_COLOR_BLACK_ON_BLACK, COLOR_BLACK, COLOR_BLACK);
} }

View File

@ -3,9 +3,8 @@
namespace cursespp { namespace cursespp {
class IDisplayable { class IDisplayable {
public: public:
virtual ~IDisplayable() = 0 { } virtual ~IDisplayable() { }
virtual void Show() = 0; virtual void Show() = 0;
virtual void Hide() = 0; virtual void Hide() = 0;
}; };
} }

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IInput { class IInput {
public: public:
virtual ~IInput() = 0 { } virtual ~IInput() { }
virtual void WriteChar(int64 ch) = 0; virtual void WriteChar(int64 ch) = 0;
}; };
} }

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IKeyHandler { class IKeyHandler {
public: public:
virtual ~IKeyHandler() = 0 { } virtual ~IKeyHandler() { }
virtual bool KeyPress(int64 ch) = 0; virtual bool KeyPress(int64 ch) = 0;
}; };
} }

View File

@ -10,7 +10,7 @@ namespace cursespp {
class ILayout : public IWindowGroup, public IKeyHandler, public IOrderable, public IDisplayable { class ILayout : public IWindowGroup, public IKeyHandler, public IOrderable, public IDisplayable {
public: public:
virtual ~ILayout() = 0 { } virtual ~ILayout() { }
virtual IWindowPtr FocusNext() = 0; virtual IWindowPtr FocusNext() = 0;
virtual IWindowPtr FocusPrev() = 0; virtual IWindowPtr FocusPrev() = 0;
virtual IWindowPtr GetFocus() = 0; virtual IWindowPtr GetFocus() = 0;
@ -20,4 +20,4 @@ namespace cursespp {
}; };
typedef std::shared_ptr<ILayout> ILayoutPtr; typedef std::shared_ptr<ILayout> ILayoutPtr;
} }

View File

@ -6,10 +6,10 @@
namespace cursespp { namespace cursespp {
class ILayoutStack { class ILayoutStack {
public: public:
virtual ~ILayoutStack() = 0 { } virtual ~ILayoutStack() { }
virtual bool Push(ILayoutPtr layout) = 0; virtual bool Push(ILayoutPtr layout) = 0;
virtual bool Pop(ILayoutPtr layout) = 0; virtual bool Pop(ILayoutPtr layout) = 0;
virtual bool BringToTop(ILayoutPtr layout) = 0; virtual bool BringToTop(ILayoutPtr layout) = 0;
virtual bool SendToBottom(ILayoutPtr layout) = 0; virtual bool SendToBottom(ILayoutPtr layout) = 0;
}; };
} }

View File

@ -9,7 +9,7 @@ namespace cursespp {
class IMessage { class IMessage {
public: public:
virtual ~IMessage() = 0 { } virtual ~IMessage() { }
virtual IMessageTarget* Target() = 0; virtual IMessageTarget* Target() = 0;
virtual int Type() = 0; virtual int Type() = 0;
virtual int64 UserData1() = 0; virtual int64 UserData1() = 0;
@ -17,4 +17,4 @@ namespace cursespp {
}; };
typedef std::shared_ptr<IMessage> IMessagePtr; typedef std::shared_ptr<IMessage> IMessagePtr;
} }

View File

@ -5,7 +5,8 @@
namespace cursespp { namespace cursespp {
class IMessageTarget { class IMessageTarget {
public: public:
virtual ~IMessageTarget() { }
virtual bool IsAcceptingMessages() = 0; virtual bool IsAcceptingMessages() = 0;
virtual void ProcessMessage(IMessage &message) = 0; virtual void ProcessMessage(IMessage &message) = 0;
}; };
} }

View File

@ -3,8 +3,8 @@
namespace cursespp { namespace cursespp {
class IOrderable { class IOrderable {
public: public:
virtual ~IOrderable() = 0 { } virtual ~IOrderable() { }
virtual void BringToTop() = 0; virtual void BringToTop() = 0;
virtual void SendToBottom() = 0; virtual void SendToBottom() = 0;
}; };
} }

View File

@ -5,7 +5,7 @@
namespace cursespp { namespace cursespp {
class IScrollAdapter { class IScrollAdapter {
public: public:
virtual ~IScrollAdapter() = 0 { } virtual ~IScrollAdapter() { }
struct ScrollPosition { struct ScrollPosition {
ScrollPosition() { ScrollPosition() {
@ -25,7 +25,7 @@ namespace cursespp {
class IEntry { class IEntry {
public: public:
virtual ~IEntry() = 0 { } virtual ~IEntry() { }
virtual size_t GetLineCount() = 0; virtual size_t GetLineCount() = 0;
virtual std::string GetLine(size_t line) = 0; virtual std::string GetLine(size_t line) = 0;
virtual std::string GetValue() = 0; virtual std::string GetValue() = 0;
@ -42,4 +42,3 @@ namespace cursespp {
virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) = 0; virtual void DrawPage(WINDOW* window, size_t index, ScrollPosition *result = NULL) = 0;
}; };
} }

View File

@ -3,7 +3,7 @@
namespace cursespp { namespace cursespp {
class IScrollable { class IScrollable {
public: public:
virtual ~IScrollable() = 0 { } virtual ~IScrollable() { }
virtual void ScrollToTop() = 0; virtual void ScrollToTop() = 0;
virtual void ScrollToBottom() = 0; virtual void ScrollToBottom() = 0;
virtual void ScrollUp(int delta = 1) = 0; virtual void ScrollUp(int delta = 1) = 0;
@ -11,4 +11,4 @@ namespace cursespp {
virtual void PageUp() = 0; virtual void PageUp() = 0;
virtual void PageDown() = 0; virtual void PageDown() = 0;
}; };
} }

View File

@ -10,7 +10,7 @@ namespace cursespp {
class IWindow : public IOrderable, public IDisplayable, public IMessageTarget { class IWindow : public IOrderable, public IDisplayable, public IMessageTarget {
public: public:
virtual ~IWindow() = 0 { } virtual ~IWindow() { }
virtual void Repaint() = 0; virtual void Repaint() = 0;
virtual void SetParent(IWindow* parent) = 0; virtual void SetParent(IWindow* parent) = 0;
virtual void Show() = 0; virtual void Show() = 0;
@ -35,4 +35,4 @@ namespace cursespp {
}; };
typedef std::shared_ptr<IWindow> IWindowPtr; typedef std::shared_ptr<IWindow> IWindowPtr;
} }

View File

@ -5,10 +5,10 @@
namespace cursespp { namespace cursespp {
class IWindowGroup { class IWindowGroup {
public: public:
virtual ~IWindowGroup() = 0 { } virtual ~IWindowGroup() { }
virtual bool AddWindow(IWindowPtr window) = 0; virtual bool AddWindow(IWindowPtr window) = 0;
virtual bool RemoveWindow(IWindowPtr window) = 0; virtual bool RemoveWindow(IWindowPtr window) = 0;
virtual size_t GetWindowCount() = 0; virtual size_t GetWindowCount() = 0;
virtual IWindowPtr GetWindowAt(size_t position) = 0; virtual IWindowPtr GetWindowAt(size_t position) = 0;
}; };
} }

View File

@ -7,7 +7,7 @@ using namespace cursespp;
template <typename T> static int find(std::vector<T>& haystack, T& needle) { template <typename T> static int find(std::vector<T>& haystack, T& needle) {
int i = 0; int i = 0;
std::vector<T>::iterator it = haystack.begin(); typename std::vector<T>::iterator it = haystack.begin();
for (; it != haystack.end(); it++, i++) { for (; it != haystack.end(); it++, i++) {
if ((*it) == needle) { if ((*it) == needle) {
return i; return i;
@ -42,7 +42,7 @@ static inline IWindowPtr adjustFocus(IWindowPtr oldFocus, IWindowPtr newFocus) {
return newFocus; return newFocus;
} }
LayoutBase::LayoutBase(IWindow* parent) LayoutBase::LayoutBase(IWindow* parent)
: Window(parent) { : Window(parent) {
this->focused = -1; this->focused = -1;
this->layoutStack = 0; this->layoutStack = 0;
@ -229,4 +229,4 @@ ILayoutStack* LayoutBase::GetLayoutStack() {
void LayoutBase::SetLayoutStack(ILayoutStack* stack) { void LayoutBase::SetLayoutStack(ILayoutStack* stack) {
this->layoutStack = stack; this->layoutStack = stack;
} }

View File

@ -50,4 +50,4 @@ namespace cursespp {
std::vector<IWindowPtr> focusable; std::vector<IWindowPtr> focusable;
int focused; int focused;
}; };
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "LayoutStack.h" #include "LayoutStack.h"
@ -40,19 +38,19 @@ static inline bool erase(std::deque<ILayoutPtr>& group, ILayoutPtr ptr) {
} }
bool LayoutStack::AddWindow(IWindowPtr window) { bool LayoutStack::AddWindow(IWindowPtr window) {
throw std::exception("AddWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()");
} }
bool LayoutStack::RemoveWindow(IWindowPtr window) { bool LayoutStack::RemoveWindow(IWindowPtr window) {
throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()");
} }
size_t LayoutStack::GetWindowCount() { size_t LayoutStack::GetWindowCount() {
throw std::exception("GetWindowCount() not supported in LayoutStack."); throw std::runtime_error("GetWindowCount() not supported in LayoutStack.");
} }
IWindowPtr LayoutStack::GetWindowAt(size_t position) { IWindowPtr LayoutStack::GetWindowAt(size_t position) {
throw std::exception("GetWindowAt() not supported in LayoutStack."); throw std::runtime_error("GetWindowAt() not supported in LayoutStack.");
} }
ILayoutStack* LayoutStack::GetLayoutStack() { ILayoutStack* LayoutStack::GetLayoutStack() {

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include <stdafx.h>
#include <algorithm>
#include "ListWindow.h" #include "ListWindow.h"
using namespace cursespp; using namespace cursespp;
@ -7,7 +8,7 @@ typedef IScrollAdapter::ScrollPosition ScrollPos;
size_t ListWindow::NO_SELECTION = (size_t) -1; size_t ListWindow::NO_SELECTION = (size_t) -1;
ListWindow::ListWindow(IWindow *parent) ListWindow::ListWindow(IWindow *parent)
: ScrollableWindow(parent) { : ScrollableWindow(parent) {
this->selectedIndex = (size_t) -1; this->selectedIndex = (size_t) -1;
} }
@ -24,15 +25,15 @@ void ListWindow::ScrollToTop() {
void ListWindow::ScrollToBottom() { void ListWindow::ScrollToBottom() {
IScrollAdapter& adapter = this->GetScrollAdapter(); IScrollAdapter& adapter = this->GetScrollAdapter();
this->SetSelectedIndex(max(0, adapter.GetEntryCount() - 1)); this->SetSelectedIndex(std::max(0UL, adapter.GetEntryCount() - 1));
adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition); adapter.DrawPage(this->GetContent(), selectedIndex, &scrollPosition);
this->Repaint(); this->Repaint();
} }
void ListWindow::Focus() { void ListWindow::Focus() {
GetScrollAdapter().DrawPage( GetScrollAdapter().DrawPage(
this->GetContent(), this->GetContent(),
this->scrollPosition.firstVisibleEntryIndex, this->scrollPosition.firstVisibleEntryIndex,
&this->scrollPosition); &this->scrollPosition);
} }
@ -46,13 +47,13 @@ void ListWindow::ScrollUp(int delta) {
int minIndex = 0; int minIndex = 0;
int newIndex = this->selectedIndex - delta; int newIndex = this->selectedIndex - delta;
newIndex = max(newIndex, minIndex); newIndex = std::max(newIndex, minIndex);
if (newIndex < (int) first + 1) { if (newIndex < (int) first + 1) {
drawIndex = newIndex - 1; drawIndex = newIndex - 1;
} }
drawIndex = max(0, drawIndex); drawIndex = std::max(0, drawIndex);
this->SetSelectedIndex(newIndex); this->SetSelectedIndex(newIndex);
@ -75,7 +76,7 @@ void ListWindow::ScrollDown(int delta) {
size_t maxIndex = adapter.GetEntryCount() - 1; size_t maxIndex = adapter.GetEntryCount() - 1;
size_t newIndex = this->selectedIndex + delta; size_t newIndex = this->selectedIndex + delta;
newIndex = min(newIndex, maxIndex); newIndex = std::min(newIndex, maxIndex);
if (newIndex >= last - 1) { if (newIndex >= last - 1) {
drawIndex = drawIndex + delta; drawIndex = drawIndex + delta;
@ -92,7 +93,7 @@ void ListWindow::PageUp() {
IScrollAdapter &adapter = this->GetScrollAdapter(); IScrollAdapter &adapter = this->GetScrollAdapter();
ScrollPos spos = this->GetScrollPosition(); ScrollPos spos = this->GetScrollPosition();
int target = (int) this->GetPreviousPageEntryIndex(); int target = (int) this->GetPreviousPageEntryIndex();
/* if the target position is zero, let it be so the user can see /* if the target position is zero, let it be so the user can see
the top of the list. otherwise, scroll down by one to give indication the top of the list. otherwise, scroll down by one to give indication
there is more to see. */ there is more to see. */
@ -112,7 +113,7 @@ void ListWindow::PageDown() {
ScrollPos spos = this->GetScrollPosition(); ScrollPos spos = this->GetScrollPosition();
size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1; size_t lastVisible = spos.firstVisibleEntryIndex + spos.visibleEntryCount - 1;
this->SetSelectedIndex(min(adapter.GetEntryCount() - 1, lastVisible + 1)); this->SetSelectedIndex(std::min(adapter.GetEntryCount() - 1, lastVisible + 1));
adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition); adapter.DrawPage(this->GetContent(), lastVisible, &this->scrollPosition);
this->Repaint(); this->Repaint();
@ -160,4 +161,4 @@ void ListWindow::OnAdapterChanged() {
IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() { IScrollAdapter::ScrollPosition& ListWindow::GetScrollPosition() {
return this->scrollPosition; return this->scrollPosition;
} }

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include <stdafx.h>
#include <algorithm>
#include "MessageQueue.h" #include "MessageQueue.h"
using namespace boost::chrono; using namespace boost::chrono;
@ -81,7 +82,7 @@ void MessageQueue::Remove(IMessageTarget *target, int type) {
void MessageQueue::Post(IMessagePtr message, int64 delayMs) { void MessageQueue::Post(IMessagePtr message, int64 delayMs) {
boost::recursive_mutex::scoped_lock lock(this->queueMutex); boost::recursive_mutex::scoped_lock lock(this->queueMutex);
delayMs = max(0, delayMs); delayMs = std::max(0LL, delayMs);
milliseconds now = duration_cast<milliseconds>( milliseconds now = duration_cast<milliseconds>(
system_clock::now().time_since_epoch()); system_clock::now().time_since_epoch());

View File

@ -1,6 +1,8 @@
#include <stdafx.h> #include <stdafx.h>
#include "MultiLineEntry.h" #include <math.h>
#include <algorithm>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "MultiLineEntry.h"
using namespace cursespp; using namespace cursespp;
@ -12,7 +14,7 @@ MultiLineEntry::MultiLineEntry(const std::string& value, int64 attrs) {
} }
size_t MultiLineEntry::GetLineCount() { size_t MultiLineEntry::GetLineCount() {
return max(1, this->lines.size()); return std::max(1UL, this->lines.size());
} }
std::string MultiLineEntry::GetLine(size_t n) { std::string MultiLineEntry::GetLine(size_t n) {

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "Screen.h" #include "Screen.h"

View File

@ -1,6 +1,6 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include <algorithm>
#include "ScrollableWindow.h" #include "ScrollableWindow.h"
#include "Screen.h" #include "Screen.h"
#include "Colors.h" #include "Colors.h"
@ -52,8 +52,8 @@ void ScrollableWindow::OnAdapterChanged() {
ScrollPos &pos = this->GetScrollPosition(); ScrollPos &pos = this->GetScrollPosition();
adapter->DrawPage( adapter->DrawPage(
this->GetContent(), this->GetContent(),
pos.firstVisibleEntryIndex, pos.firstVisibleEntryIndex,
&pos); &pos);
this->Repaint(); this->Repaint();
@ -72,7 +72,7 @@ void ScrollableWindow::ScrollToTop() {
void ScrollableWindow::ScrollToBottom() { void ScrollableWindow::ScrollToBottom() {
GetScrollAdapter().DrawPage( GetScrollAdapter().DrawPage(
this->GetContent(), this->GetContent(),
GetScrollAdapter().GetEntryCount(), GetScrollAdapter().GetEntryCount(),
&this->GetScrollPosition()); &this->GetScrollPosition());
@ -122,7 +122,7 @@ size_t ScrollableWindow::GetPreviousPageEntryIndex() {
remaining -= count; remaining -= count;
} }
return max(0, i); return std::max(0, i);
} }
void ScrollableWindow::PageUp() { void ScrollableWindow::PageUp() {
@ -144,4 +144,4 @@ bool ScrollableWindow::IsLastItemVisible() {
size_t firstVisible = pos.firstVisibleEntryIndex; size_t firstVisible = pos.firstVisibleEntryIndex;
size_t lastVisible = firstVisible + pos.visibleEntryCount; size_t lastVisible = firstVisible + pos.visibleEntryCount;
return lastIndex >= firstVisible && lastIndex <= lastVisible; return lastIndex >= firstVisible && lastIndex <= lastVisible;
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "Window.h" #include "Window.h"
#include "IWindowGroup.h" #include "IWindowGroup.h"
@ -45,7 +43,7 @@ int Window::GetId() const {
} }
void Window::ProcessMessage(IMessage &message) { void Window::ProcessMessage(IMessage &message) {
} }
bool Window::IsAcceptingMessages() { bool Window::IsAcceptingMessages() {
@ -79,9 +77,9 @@ void Window::SendToBottom() {
void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay) { void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay) {
MessageQueue::Instance().Post( MessageQueue::Instance().Post(
Message::Create( Message::Create(
this, this,
messageType, messageType,
user1, user1,
user2), user2),
delay); delay);
} }
@ -215,14 +213,14 @@ void Window::Create() {
this->frame = (this->parent == NULL) this->frame = (this->parent == NULL)
? newwin( ? newwin(
this->height, this->height,
this->width, this->width,
this->y, this->y,
this->x) this->x)
: newwin( : newwin(
this->height, this->height,
this->width, this->width,
this->parent->GetY() + this->y, this->parent->GetY() + this->y,
this->parent->GetX() + this->x); this->parent->GetX() + this->x);
this->framePanel = new_panel(this->frame); this->framePanel = new_panel(this->frame);

View File

@ -71,4 +71,4 @@ namespace cursespp {
int64 contentColor, frameColor; int64 contentColor, frameColor;
int width, height, x, y; int width, height, x, y;
}; };
} }

View File

@ -1,5 +1,3 @@
#pragma once
#include <stdafx.h> #include <stdafx.h>
#include "WindowLayout.h" #include "WindowLayout.h"
#include "LayoutStack.h" #include "LayoutStack.h"
@ -15,19 +13,19 @@ WindowLayout::~WindowLayout() {
} }
bool WindowLayout::AddWindow(IWindowPtr window) { bool WindowLayout::AddWindow(IWindowPtr window) {
throw std::exception("AddWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("AddWindow() not supported in LayoutStack. Use Push()");
} }
bool WindowLayout::RemoveWindow(IWindowPtr window) { bool WindowLayout::RemoveWindow(IWindowPtr window) {
throw std::exception("RemoveWindow() not supported in LayoutStack. Use Push()"); throw std::runtime_error("RemoveWindow() not supported in LayoutStack. Use Push()");
} }
size_t WindowLayout::GetWindowCount() { size_t WindowLayout::GetWindowCount() {
throw std::exception("GetWindowCount() not supported in LayoutStack."); throw std::runtime_error("GetWindowCount() not supported in LayoutStack.");
} }
IWindowPtr WindowLayout::GetWindowAt(size_t position) { IWindowPtr WindowLayout::GetWindowAt(size_t position) {
throw std::exception("GetWindowAt() not supported in LayoutStack."); throw std::runtime_error("GetWindowAt() not supported in LayoutStack.");
} }
void WindowLayout::Show() { void WindowLayout::Show() {
@ -71,4 +69,4 @@ ILayoutStack* WindowLayout::GetLayoutStack() {
void WindowLayout::SetLayoutStack(ILayoutStack* stack) { void WindowLayout::SetLayoutStack(ILayoutStack* stack) {
this->stack = stack; this->stack = stack;
} }