Added rudimentary support for resizing.

This commit is contained in:
Casey Langen 2016-05-27 21:54:46 -07:00
parent 0db50fc6b3
commit 306103c0e8
9 changed files with 125 additions and 26 deletions

View File

@ -253,7 +253,7 @@ int main(int argc, char* argv[])
kn += (char) getch();
}
//std::cerr << "keyname: " << kn << std::endl;
// std::cerr << "keyname: " << kn << std::endl;
// std::cerr << "ch: " << ch << std::endl;
if (ch == '\t') { /* tab */
@ -262,6 +262,11 @@ int main(int argc, char* argv[])
else if (kn == "^D") { /* ctrl+d quits */
quit = true;
}
else if (kn == "KEY_RESIZE") {
libraryLayout->Layout();
consoleLayout->Layout();
state.layout->Show();
}
else if (ch == KEY_F(1)) {
changeLayout(state, libraryLayout);
}

View File

@ -10,7 +10,7 @@
using namespace musik::core::library::constants;
#define CATEGORY_WIDTH 25
#define TRANSPORT_HEIGHT 3
#define TRANSPORT_HEIGHT 2
#define DEFAULT_CATEGORY constants::Track::ALBUM_ID
using namespace musik::core;
@ -35,16 +35,28 @@ void LibraryLayout::Layout() {
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->categoryList->SetPosition(0, 0);
this->categoryList->SetSize(CATEGORY_WIDTH, this->GetHeight() - TRANSPORT_HEIGHT);
this->categoryList->MoveAndResize(
0,
0,
CATEGORY_WIDTH,
this->GetHeight() - TRANSPORT_HEIGHT);
this->categoryList->SetFocusOrder(0);
this->trackList->SetPosition(CATEGORY_WIDTH, 0);
this->trackList->SetSize(this->GetWidth() - CATEGORY_WIDTH, this->GetHeight() - TRANSPORT_HEIGHT);
this->trackList->MoveAndResize(
CATEGORY_WIDTH,
0,
this->GetWidth() - CATEGORY_WIDTH,
this->GetHeight() - TRANSPORT_HEIGHT);
this->trackList->SetFocusOrder(1);
this->transportView->SetPosition(1, this->GetHeight() - TRANSPORT_HEIGHT);
this->transportView->SetSize(this->GetWidth() - 2, TRANSPORT_HEIGHT);
this->transportView->MoveAndResize(
1,
this->GetHeight() - TRANSPORT_HEIGHT,
this->GetWidth() - 2,
TRANSPORT_HEIGHT);
this->transportView->Update();
}

View File

@ -32,28 +32,47 @@ MainLayout::~MainLayout() {
void MainLayout::Layout() {
/* this layout */
this->SetSize(Screen::GetWidth(), Screen::GetHeight());
this->SetPosition(0, 0);
this->MoveAndResize(
0,
0,
Screen::GetWidth(),
Screen::GetHeight());
this->SetFrameVisible(false);
/* top left */
this->output->SetSize(Screen::GetWidth() / 2, Screen::GetHeight() - 3);
this->output->SetPosition(0, 0);
this->output->MoveAndResize(
0,
0,
Screen::GetWidth() / 2,
Screen::GetHeight() - 3);
this->output->SetFocusOrder(1);
/* bottom left */
this->commands->SetSize(Screen::GetWidth() / 2, 3);
this->commands->SetPosition(0, Screen::GetHeight() - 3);
this->commands->MoveAndResize(
0,
Screen::GetHeight() - 3,
Screen::GetWidth() / 2,
3);
this->commands->SetFocusOrder(0);
/* top right */
this->logs->SetSize(Screen::GetWidth() / 2, Screen::GetHeight() - 3);
this->logs->SetPosition(Screen::GetWidth() / 2, 0);
this->logs->MoveAndResize(
Screen::GetWidth() / 2,
0,
Screen::GetWidth() / 2,
Screen::GetHeight() - 3);
this->logs->SetFocusOrder(2);
/* bottom right */
this->resources->SetSize(Screen::GetWidth() / 2, 3);
this->resources->SetPosition(Screen::GetWidth() / 2, Screen::GetHeight() - 3);
this->resources->MoveAndResize(
Screen::GetWidth() / 2,
Screen::GetHeight() - 3,
Screen::GetWidth() / 2,
3);
}
void MainLayout::Show() {

View File

@ -91,7 +91,11 @@ void CommandWindow::Write(const std::string& key) {
this->buffer = "";
}
else {
this->buffer += key;
/* one character at a time. if it's more than one character, we're
dealing with an escape sequence and should not print it. */
if (u8len(key) == 1) {
this->buffer += key;
}
}
this->Clear();

View File

@ -21,6 +21,7 @@ namespace cursespp {
virtual void SetFrameColor(int64 color) = 0;
virtual void SetSize(int width, int height) = 0;
virtual void SetPosition(int x, int y) = 0;
virtual void MoveAndResize(int x, int y, int width, int height) = 0;
virtual int GetWidth() const = 0;
virtual int GetHeight() const = 0;
virtual int GetContentHeight() const = 0;

View File

@ -18,8 +18,8 @@ ScrollableWindow::ScrollableWindow(IWindow *parent)
ScrollableWindow::~ScrollableWindow() {
}
void ScrollableWindow::SetSize(int width, int height) {
Window::SetSize(width, height);
void ScrollableWindow::OnSizeChanged() {
Window::OnSizeChanged();
GetScrollAdapter().SetDisplaySize(GetContentWidth(), GetContentHeight());
}

View File

@ -13,7 +13,7 @@ namespace cursespp {
virtual ~ScrollableWindow();
virtual void Show();
virtual void SetSize(int width, int height);
virtual void OnSizeChanged();
virtual bool KeyPress(const std::string& key);

View File

@ -105,14 +105,62 @@ void Window::SetParent(IWindow* parent) {
}
}
void Window::MoveAndResize(int x, int y, int width, int height) {
bool sizeChanged = this->width != width || this->height != height;
bool positionChanged = this->x != x || this->y != y;
if (sizeChanged || positionChanged) {
this->width = width;
this->height = height;
this->x = x;
this->y = y;
if (this->frame) {
this->Recreate();
}
if (sizeChanged) {
this->OnSizeChanged();
}
if (positionChanged) {
this->OnPositionChanged();
}
}
}
void Window::SetSize(int width, int height) {
this->width = width;
this->height = height;
if (this->width != width || this->height != height) {
this->width = width;
this->height = height;
if (this->frame) {
this->Recreate();
}
this->OnSizeChanged();
}
}
void Window::SetPosition(int x, int y) {
this->x = x;
this->y = y;
if (this->x != x || this->y != y) {
this->x = x;
this->y = y;
if (this->frame) {
this->Recreate();
}
this->OnPositionChanged();
}
}
void Window::OnPositionChanged() {
/* for subclass use */
}
void Window::OnSizeChanged() {
/* for subclass use */
}
int Window::GetWidth() const {
@ -208,6 +256,11 @@ void Window::Show() {
}
}
void Window::Recreate() {
this->Destroy();
this->Create();
}
void Window::Create() {
/* if we have a parent, place the new window relative to the parent. */

View File

@ -26,6 +26,7 @@ namespace cursespp {
virtual void SetFrameColor(int64 color);
virtual void SetSize(int width, int height);
virtual void SetPosition(int x, int y);
virtual void MoveAndResize(int x, int y, int width, int height);
virtual int GetWidth() const;
virtual int GetHeight() const;
@ -56,8 +57,12 @@ namespace cursespp {
bool IsVisible();
void Create();
void Destroy();
void Recreate();
void Clear();
virtual void OnPositionChanged();
virtual void OnSizeChanged();
private:
IWindow* parent;
PANEL* framePanel;