From 15c50bf4b58c00bf6d080617e86099365258c823 Mon Sep 17 00:00:00 2001 From: Thomas Jentzsch Date: Mon, 13 Dec 2021 15:39:40 +0100 Subject: [PATCH] added the (usual) missing files :| --- src/gui/NavigationWidget.cxx | 119 +++++++++++++++++++++++++++++++++++ src/gui/NavigationWidget.hxx | 48 ++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 src/gui/NavigationWidget.cxx create mode 100644 src/gui/NavigationWidget.hxx diff --git a/src/gui/NavigationWidget.cxx b/src/gui/NavigationWidget.cxx new file mode 100644 index 000000000..890263411 --- /dev/null +++ b/src/gui/NavigationWidget.cxx @@ -0,0 +1,119 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "Command.hxx" +#include "Dialog.hxx" +#include "EditTextWidget.hxx" +#include "FileListWidget.hxx" +#include "Icons.hxx" +#include "OSystem.hxx" + +#include "NavigationWidget.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +NavigationWidget::NavigationWidget(GuiObject* boss, const GUI::Font& font, + int xpos, int ypos, int w, int h) + : Widget(boss, font, xpos, ypos, w, h) +{ + // Add some buttons and textfield to show current directory + const int lineHeight = _font.getLineHeight(); + const bool useMinimalUI = instance().settings().getBool("minimal_ui"); + + if(!useMinimalUI) + { + const int + fontHeight = _font.getFontHeight(), + fontWidth = _font.getMaxCharWidth(), + BTN_GAP = fontWidth / 4; + const bool smallIcon = lineHeight < 26; + const GUI::Icon& homeIcon = smallIcon ? GUI::icon_home_small : GUI::icon_home_large; + const GUI::Icon& prevIcon = smallIcon ? GUI::icon_prev_small : GUI::icon_prev_large; + const GUI::Icon& nextIcon = smallIcon ? GUI::icon_next_small : GUI::icon_next_large; + const GUI::Icon& upIcon = smallIcon ? GUI::icon_up_small : GUI::icon_up_large; + const int iconWidth = homeIcon.width(); + const int buttonWidth = iconWidth + ((fontWidth + 1) & ~0b1) - 1; // round up to next odd + const int buttonHeight = lineHeight + 2; + + myHomeButton = new ButtonWidget(boss, _font, xpos, ypos, + buttonWidth, buttonHeight, homeIcon, FileListWidget::kHomeDirCmd); + myHomeButton->setToolTip("Go back to initial directory."); + boss->addFocusWidget(myHomeButton); + xpos = myHomeButton->getRight() + BTN_GAP; + + myPrevButton = new ButtonWidget(boss, _font, xpos, ypos, + buttonWidth, buttonHeight, prevIcon, FileListWidget::kPrevDirCmd); + myPrevButton->setToolTip("Go back in directory history."); + boss->addFocusWidget(myPrevButton); + xpos = myPrevButton->getRight() + BTN_GAP; + + myNextButton = new ButtonWidget(boss, _font, xpos, ypos, + buttonWidth, buttonHeight, nextIcon, FileListWidget::kNextDirCmd); + myNextButton->setToolTip("Go forward in directory history."); + boss->addFocusWidget(myNextButton); + xpos = myNextButton->getRight() + BTN_GAP; + + myUpButton = new ButtonWidget(boss, _font, xpos, ypos, + buttonWidth, buttonHeight, upIcon, ListWidget::kParentDirCmd); + myUpButton->setToolTip("Go Up"); + boss->addFocusWidget(myUpButton); + xpos = myUpButton->getRight() + BTN_GAP; + } + myDir = new EditTextWidget(boss, _font, xpos, ypos, _w + _x - xpos, lineHeight, ""); + myDir->setEditable(false, true); + myDir->clearFlags(Widget::FLAG_RETAIN_FOCUS); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void NavigationWidget::setList(FileListWidget* list) +{ + myList = list; + + // Let the FileListWidget handle the button commands + if(myHomeButton) + myHomeButton->setTarget(myList); + if(myPrevButton) + myPrevButton->setTarget(myList); + if(myNextButton) + myNextButton->setTarget(myList); + if(myUpButton) + myUpButton->setTarget(myList); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void NavigationWidget::setWidth(int w) +{ + // Adjust path display accordingly too + myDir->setWidth(w - (myDir->getLeft() - _x)); + Widget::setWidth(w); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void NavigationWidget::updateUI() +{ + // Only enable the navigation buttons if function is available + if(myHomeButton) + myHomeButton->setEnabled(myList->hasPrevHistory()); + if(myPrevButton) + myPrevButton->setEnabled(myList->hasPrevHistory()); + if(myNextButton) + myNextButton->setEnabled(myList->hasNextHistory()); + if(myUpButton) + myUpButton->setEnabled(myList->currentDir().hasParent()); + + // Show current directory + myDir->setText(myList->currentDir().getShortPath()); +} diff --git a/src/gui/NavigationWidget.hxx b/src/gui/NavigationWidget.hxx new file mode 100644 index 000000000..a14fc20ac --- /dev/null +++ b/src/gui/NavigationWidget.hxx @@ -0,0 +1,48 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2021 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef NAVIGATION_WIDGET_HXX +#define NAVIGATION_WIDGET_HXX + +class EditTextWidget; +class FileListWidget; +class Font; + +#include "Widget.hxx" + +class NavigationWidget : public Widget +{ + public: + NavigationWidget(GuiObject* boss, const GUI::Font& font, + int x, int y, int w, int h); + ~NavigationWidget() = default; + + void setWidth(int w) override; + void setList(FileListWidget* list); + void updateUI(); + + private: + ButtonWidget* myHomeButton{nullptr}; + ButtonWidget* myPrevButton{nullptr}; + ButtonWidget* myNextButton{nullptr}; + ButtonWidget* myUpButton{nullptr}; + EditTextWidget* myDir{nullptr}; + + FileListWidget* myList{nullptr}; +}; + +#endif \ No newline at end of file