From 35c51c6feef46c05d7c2a50db01387d51a2240c6 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 6 Jan 2016 14:39:18 -1000 Subject: [PATCH] Dedicated PathButtons class and horizontal ScrollView --- specter/CMakeLists.txt | 2 + specter/include/Specter/Control.hpp | 34 +++-- specter/include/Specter/FileBrowser.hpp | 34 ++--- specter/include/Specter/MessageWindow.hpp | 8 +- specter/include/Specter/PathButtons.hpp | 74 ++++++++++ specter/include/Specter/ScrollView.hpp | 61 ++++++++- specter/include/Specter/Space.hpp | 2 +- specter/include/Specter/Toolbar.hpp | 1 + specter/include/Specter/View.hpp | 48 +++++++ specter/include/Specter/ViewResources.hpp | 4 +- specter/lib/Button.cpp | 15 ++- specter/lib/FileBrowser.cpp | 49 ++----- specter/lib/PathButtons.cpp | 84 ++++++++++++ specter/lib/ScrollView.cpp | 157 +++++++++++++++++----- specter/lib/Space.cpp | 33 +++-- specter/lib/TextField.cpp | 4 +- specter/lib/View.cpp | 3 + 17 files changed, 475 insertions(+), 138 deletions(-) create mode 100644 specter/include/Specter/PathButtons.hpp create mode 100644 specter/lib/PathButtons.cpp diff --git a/specter/CMakeLists.txt b/specter/CMakeLists.txt index d38c350aa..a5c891a77 100644 --- a/specter/CMakeLists.txt +++ b/specter/CMakeLists.txt @@ -55,6 +55,7 @@ list(APPEND SPECTER_HEADERS include/Specter/Menu.hpp include/Specter/Node.hpp include/Specter/NodeSocket.hpp + include/Specter/PathButtons.hpp include/Specter/FileBrowser.hpp include/Specter/FontCache.hpp include/Specter/Translator.hpp) @@ -85,6 +86,7 @@ list(APPEND SPECTER_SOURCES lib/Menu.cpp lib/Node.cpp lib/NodeSocket.cpp + lib/PathButtons.cpp lib/FileBrowser.cpp lib/FontCache.cpp lib/Translator.cpp diff --git a/specter/include/Specter/Control.hpp b/specter/include/Specter/Control.hpp index 671921029..f71f32093 100644 --- a/specter/include/Specter/Control.hpp +++ b/specter/include/Specter/Control.hpp @@ -6,38 +6,46 @@ namespace Specter { +class Control; +class Button; struct IControlBinding { - virtual const char* name() const=0; - virtual const char* help() const {return nullptr;} + virtual const char* name(const Control* control) const=0; + virtual const char* help(const Control* control) const {return nullptr;} }; struct IButtonBinding : IControlBinding { /** Pressed/Released while Hovering action, * cancellable by holding the button and releasing outside */ - virtual void activated(const boo::SWindowCoord& coord)=0; + virtual void activated(const Button* button, const boo::SWindowCoord& coord) {} + + /** Pass-through down action */ + virtual void down(const Button* button, const boo::SWindowCoord& coord) {} + + /** Pass-through up action */ + virtual void up(const Button* button, const boo::SWindowCoord& coord) {} }; struct IFloatBinding : IControlBinding { - virtual float getDefault() const {return 0.0;} - virtual std::pair getBounds() const {return std::make_pair(FLT_MIN, FLT_MAX);} - virtual void changed(float val)=0; + virtual float getDefault(const Control* control) const {return 0.0;} + virtual std::pair getBounds(const Control* control) const {return std::make_pair(FLT_MIN, FLT_MAX);} + virtual void changed(const Control* control, float val)=0; }; struct IIntBinding : IControlBinding { - virtual int getDefault() const {return 0;} - virtual std::pair getBounds() const {return std::make_pair(INT_MIN, INT_MAX);} - virtual void changed(int val)=0; + virtual int getDefault(const Control* control) const {return 0;} + virtual std::pair getBounds(const Control* control) const {return std::make_pair(INT_MIN, INT_MAX);} + virtual void changed(const Control* control, int val)=0; }; struct IStringBinding : IControlBinding { - virtual std::string getDefault() const {return "";} - virtual void changed(const std::string& val)=0; + virtual std::string getDefault(const Control* control) const {return "";} + virtual void changed(const Control* control, const std::string& val)=0; }; struct CVarControlBinding : IControlBinding @@ -45,8 +53,8 @@ struct CVarControlBinding : IControlBinding HECL::CVar* m_cvar; CVarControlBinding(HECL::CVar* cvar) : m_cvar(cvar) {} - const char* name() const {return m_cvar->name().c_str();} - const char* help() const {return m_cvar->rawHelp().c_str();} + const char* name(const Control* control) const {return m_cvar->name().c_str();} + const char* help(const Control* control) const {return m_cvar->rawHelp().c_str();} }; class Control : public View diff --git a/specter/include/Specter/FileBrowser.hpp b/specter/include/Specter/FileBrowser.hpp index 475c5115f..117f9a480 100644 --- a/specter/include/Specter/FileBrowser.hpp +++ b/specter/include/Specter/FileBrowser.hpp @@ -10,12 +10,13 @@ #include "ViewResources.hpp" #include "IViewManager.hpp" #include "MessageWindow.hpp" +#include "PathButtons.hpp" #include namespace Specter { -class FileBrowser : public ModalWindow +class FileBrowser : public ModalWindow, public IPathButtonsBinding { public: enum class Type @@ -64,8 +65,8 @@ private: m_button.m_view.reset(new Button(res, fb, this, text, Button::Style::Block, RectangleConstraint(100 * res.pixelFactor(), -1, RectangleConstraint::Test::Minimum))); } - const char* name() const {return m_text.c_str();} - void activated(const boo::SWindowCoord&) {m_fb.okActivated(true);} + const char* name(const Control* control) const {return m_text.c_str();} + void activated(const Button* button, const boo::SWindowCoord&) {m_fb.okActivated(true);} } m_ok; void cancelActivated(); @@ -80,28 +81,12 @@ private: m_button.m_view.reset(new Button(res, fb, this, text, Button::Style::Block, RectangleConstraint(m_fb.m_ok.m_button.m_view->nominalWidth(), -1, RectangleConstraint::Test::Minimum))); } - const char* name() const {return m_text.c_str();} - void activated(const boo::SWindowCoord&) {m_fb.cancelActivated();} + const char* name(const Control* control) const {return m_text.c_str();} + void activated(const Button* button, const boo::SWindowCoord&) {m_fb.cancelActivated();} } m_cancel; - int m_pathButtonPending = -1; void pathButtonActivated(size_t idx); - struct PathButton : IButtonBinding - { - FileBrowser& m_fb; - size_t m_idx; - ViewChild> m_button; - PathButton(FileBrowser& fb, ViewResources& res, size_t idx, const HECL::SystemString& str) - : m_fb(fb), m_idx(idx) - { - HECL::SystemUTF8View utf8View(str); - m_button.m_view.reset(new Button(res, fb, this, utf8View)); - } - const char* name() const {return m_button.m_view->getText().c_str();} - void activated(const boo::SWindowCoord&) {m_fb.m_pathButtonPending = m_idx;} - }; - friend struct PathButton; - std::vector m_pathButtons; + ViewChild> m_pathButtons; ViewChild> m_fileField; struct FileFieldBind : IStringBinding @@ -110,8 +95,8 @@ private: std::string m_name; FileFieldBind(FileBrowser& browser, const IViewManager& vm) : m_browser(browser), m_name(vm.translateOr("file_name", "File Name")) {} - const char* name() const {return m_name.c_str();} - void changed(const std::string& val) + const char* name(const Control* control) const {return m_name.c_str();} + void changed(const Control* control, const std::string& val) { } } m_fileFieldBind; @@ -345,7 +330,6 @@ public: void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseMove(const boo::SWindowCoord&); - void mouseEnter(const boo::SWindowCoord&); void mouseLeave(const boo::SWindowCoord&); void scroll(const boo::SWindowCoord&, const boo::SScrollDelta&); void touchDown(const boo::STouchCoord&, uintptr_t); diff --git a/specter/include/Specter/MessageWindow.hpp b/specter/include/Specter/MessageWindow.hpp index ebbefe029..780a7c0cc 100644 --- a/specter/include/Specter/MessageWindow.hpp +++ b/specter/include/Specter/MessageWindow.hpp @@ -29,8 +29,8 @@ private: MessageWindow& m_mw; std::string m_name; OKBinding(MessageWindow& mw, std::string&& name) : m_mw(mw), m_name(std::move(name)) {} - const char* name() const {return m_name.c_str();} - void activated(const boo::SWindowCoord& coord) + const char* name(const Control* control) const {return m_name.c_str();} + void activated(const Button* button, const boo::SWindowCoord& coord) { m_mw.m_func(true); } @@ -42,8 +42,8 @@ private: MessageWindow& m_mw; std::string m_name; CancelBinding(MessageWindow& mw, std::string&& name) : m_mw(mw), m_name(std::move(name)) {} - const char* name() const {return m_name.c_str();} - void activated(const boo::SWindowCoord& coord) + const char* name(const Control* control) const {return m_name.c_str();} + void activated(const Button* button, const boo::SWindowCoord& coord) { m_mw.m_func(false); } diff --git a/specter/include/Specter/PathButtons.hpp b/specter/include/Specter/PathButtons.hpp new file mode 100644 index 000000000..5b5127dac --- /dev/null +++ b/specter/include/Specter/PathButtons.hpp @@ -0,0 +1,74 @@ +#ifndef SPECTER_PATHBUTTONS_HPP +#define SPECTER_PATHBUTTONS_HPP + +#include "Button.hpp" +#include "ScrollView.hpp" + +namespace Specter +{ + +struct IPathButtonsBinding +{ + virtual void pathButtonActivated(size_t idx)=0; +}; + +class PathButtons : public ScrollView +{ + struct ContentView : public View + { + PathButtons& m_pb; + boo::SWindowRect m_scissorRect; + + void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); + void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); + void mouseMove(const boo::SWindowCoord&); + void mouseLeave(const boo::SWindowCoord&); + + int nominalWidth() const + { + int ret = 0; + for (PathButton& b : m_pb.m_pathButtons) + ret += b.m_button.m_view->nominalWidth() + 2; + return ret; + } + int nominalHeight() const + { + return m_pb.m_pathButtons.size() ? m_pb.m_pathButtons[0].m_button.m_view->nominalHeight() : 0; + } + + void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub, const boo::SWindowRect& scissor); + void draw(boo::IGraphicsCommandQueue* gfxQ); + + ContentView(ViewResources& res, PathButtons& pb) + : View(res, pb), m_pb(pb) {} + }; + ViewChild> m_contentView; + + int m_pathButtonPending = -1; + IPathButtonsBinding& m_binding; + struct PathButton : IButtonBinding + { + PathButtons& m_pb; + size_t m_idx; + ViewChild> m_button; + PathButton(PathButtons& pb, ViewResources& res, size_t idx, const HECL::SystemString& str) + : m_pb(pb), m_idx(idx) + { + m_button.m_view.reset(new Button(res, pb, this, HECL::SystemUTF8View(str).str())); + } + const char* name(const Control* control) const {return m_button.m_view->getText().c_str();} + void activated(const Button* button, const boo::SWindowCoord&) {m_pb.m_pathButtonPending = m_idx;} + }; + friend struct PathButton; + std::vector m_pathButtons; + +public: + PathButtons(ViewResources& res, View& parentView, IPathButtonsBinding& binding); + + void setButtons(const std::vector& comps); + void setMultiplyColor(const Zeus::CColor& color); +}; + +} + +#endif // SPECTER_PATHBUTTONS_HPP diff --git a/specter/include/Specter/ScrollView.hpp b/specter/include/Specter/ScrollView.hpp index 80042b499..01d4943ac 100644 --- a/specter/include/Specter/ScrollView.hpp +++ b/specter/include/Specter/ScrollView.hpp @@ -2,6 +2,8 @@ #define SPECTER_SCROLLVIEW_HPP #include "View.hpp" +#include "Button.hpp" +#include "IViewManager.hpp" namespace Specter { @@ -13,12 +15,13 @@ public: enum class Style { Plain, - ThinIndicator + ThinIndicator, + SideButtons }; private: Style m_style; - View* m_contentView = nullptr; + ScissorViewChild m_contentView; int m_scroll[2] = {}; int m_targetScroll[2] = {}; @@ -26,18 +29,61 @@ private: double m_consecutiveScroll[16][2] = {}; bool m_drawInd = false; + bool m_drawSideButtons = false; SolidShaderVert m_verts[4]; boo::IGraphicsBufferD* m_vertsBuf = nullptr; boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */ boo::IShaderDataBinding* m_shaderBinding = nullptr; + enum class SideButtonState + { + None, + ScrollLeft, + ScrollRight + } m_sideButtonState = SideButtonState::None; + struct SideButtonBinding : IButtonBinding + { + ScrollView& m_sv; + std::string m_leftName, m_rightName; + SideButtonBinding(ScrollView& sv, IViewManager& vm) + : m_sv(sv), + m_leftName(vm.translateOr("scroll_left", "Scroll Left")), + m_rightName(vm.translateOr("scroll_right", "Scroll Right")) {} + const char* name(const Control* control) const + {return (control == m_sv.m_sideButtons[0].m_view.get()) ? m_leftName.c_str() : m_rightName.c_str();} + void down(const Button* button, const boo::SWindowCoord& coord) + { + if (button == m_sv.m_sideButtons[0].m_view.get()) + m_sv.m_sideButtonState = SideButtonState::ScrollRight; + else + m_sv.m_sideButtonState = SideButtonState::ScrollLeft; + } + void up(const Button* button, const boo::SWindowCoord& coord) + { + m_sv.m_sideButtonState = SideButtonState::None; + } + } m_sideButtonBind; + ViewChild> m_sideButtons[2]; + bool _scroll(const boo::SScrollDelta& scroll); + + int scrollAreaWidth() const + { + int ret = subRect().size[0]; + if (m_style == Style::SideButtons && m_drawSideButtons) + { + ret -= m_sideButtons[0].m_view->nominalWidth(); + ret -= m_sideButtons[1].m_view->nominalWidth(); + } + return std::max(0, ret); + } + public: ScrollView(ViewResources& res, View& parentView, Style style); void setContentView(View* v) { - m_contentView = v; + m_contentView.m_view = v; updateSize(); } @@ -56,8 +102,13 @@ public: void setMultiplyColor(const Zeus::CColor& color) { View::setMultiplyColor(color); - if (m_contentView) - m_contentView->setMultiplyColor(color); + if (m_style == Style::SideButtons) + { + m_sideButtons[0].m_view->setMultiplyColor(color); + m_sideButtons[1].m_view->setMultiplyColor(color); + } + if (m_contentView.m_view) + m_contentView.m_view->setMultiplyColor(color); } void think(); diff --git a/specter/include/Specter/Space.hpp b/specter/include/Specter/Space.hpp index 7fdd64462..18ed90bcd 100644 --- a/specter/include/Specter/Space.hpp +++ b/specter/include/Specter/Space.hpp @@ -19,7 +19,7 @@ class Space : public View public: Space(ViewResources& res, View& parentView, Toolbar::Position toolbarPos); View* setContentView(View* view); - Toolbar& toolbar() {return *m_toolbar;} + Toolbar* toolbar() {return m_toolbar.get();} void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseMove(const boo::SWindowCoord&); diff --git a/specter/include/Specter/Toolbar.hpp b/specter/include/Specter/Toolbar.hpp index e878c2fee..7824a53ec 100644 --- a/specter/include/Specter/Toolbar.hpp +++ b/specter/include/Specter/Toolbar.hpp @@ -20,6 +20,7 @@ public: enum class Position { + None, Bottom, Top }; diff --git a/specter/include/Specter/View.hpp b/specter/include/Specter/View.hpp index 8225122fc..9c278cd92 100644 --- a/specter/include/Specter/View.hpp +++ b/specter/include/Specter/View.hpp @@ -296,6 +296,54 @@ struct ViewChild } }; +template +struct ScissorViewChild : ViewChild +{ + using base = ViewChild; + boo::SWindowRect m_scissorRect; + + bool mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) + { + if (!base::m_view) + return false; + if (base::m_view->subRect().coordInRect(coord) && + m_scissorRect.coordInRect(coord)) + { + if ((base::m_mouseDown & 1 << int(button)) == 0) + { + base::m_view->mouseDown(coord, button, mod); + base::m_mouseDown |= 1 << int(button); + } + return true; + } + return false; + } + + void mouseMove(const boo::SWindowCoord& coord) + { + if (!base::m_view) + return; + if (base::m_view->subRect().coordInRect(coord) && + m_scissorRect.coordInRect(coord)) + { + if (!base::m_mouseIn) + { + base::m_view->mouseEnter(coord); + base::m_mouseIn = true; + } + base::m_view->mouseMove(coord); + } + else + { + if (base::m_mouseIn) + { + base::m_view->mouseLeave(coord); + base::m_mouseIn = false; + } + } + } +}; + } #endif // SPECTER_VIEW_HPP diff --git a/specter/include/Specter/ViewResources.hpp b/specter/include/Specter/ViewResources.hpp index 2ea1aacaf..3c9506d67 100644 --- a/specter/include/Specter/ViewResources.hpp +++ b/specter/include/Specter/ViewResources.hpp @@ -18,8 +18,9 @@ class ThemeData Zeus::CColor m_selectedFieldText = Zeus::CColor::skWhite; Zeus::CColor m_vpBg = {0.2, 0.2, 0.2, 1.0}; - Zeus::CColor m_tbBg = {0.4, 0.4, 0.4, 1.0}; + Zeus::CColor m_tbBg = {0.2, 0.2, 0.2, 0.9}; Zeus::CColor m_tooltipBg = {0.1, 0.1, 0.1, 0.85}; + Zeus::CColor m_spaceBg = {0.075, 0.075, 0.075, 0.85}; Zeus::CColor m_splashBg = {0.075, 0.075, 0.075, 0.85}; Zeus::CColor m_splashErrorBg = {0.1, 0.01, 0.01, 0.85}; @@ -59,6 +60,7 @@ public: virtual const Zeus::CColor& viewportBackground() const {return m_vpBg;} virtual const Zeus::CColor& toolbarBackground() const {return m_tbBg;} virtual const Zeus::CColor& tooltipBackground() const {return m_tooltipBg;} + virtual const Zeus::CColor& spaceBackground() const {return m_spaceBg;} virtual const Zeus::CColor& splashBackground() const {return m_splashBg;} virtual const Zeus::CColor& splashErrorBackground() const {return m_splashErrorBg;} diff --git a/specter/lib/Button.cpp b/specter/lib/Button.cpp index e20c745de..3729b7ea0 100644 --- a/specter/lib/Button.cpp +++ b/specter/lib/Button.cpp @@ -233,18 +233,25 @@ void Button::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, Control::mouseDown(coord, button, mod); m_pressed = true; setPressed(); + if (m_controlBinding && dynamic_cast(m_controlBinding)) + static_cast(*m_controlBinding).down(this, coord); } void Button::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) { Control::mouseUp(coord, button, mod); - if (m_pressed && m_hovered) + if (m_pressed) { - Log.report(LogVisor::Info, "button '%s' activated", m_textStr.c_str()); if (m_controlBinding && dynamic_cast(m_controlBinding)) - static_cast(*m_controlBinding).activated(coord); + static_cast(*m_controlBinding).up(this, coord); + if (m_hovered) + { + Log.report(LogVisor::Info, "button '%s' activated", m_textStr.c_str()); + if (m_controlBinding && dynamic_cast(m_controlBinding)) + static_cast(*m_controlBinding).activated(this, coord); + } + m_pressed = false; } - m_pressed = false; if (m_hovered) setHover(); else diff --git a/specter/lib/FileBrowser.cpp b/specter/lib/FileBrowser.cpp index 2901f4327..0e5bd06d4 100644 --- a/specter/lib/FileBrowser.cpp +++ b/specter/lib/FileBrowser.cpp @@ -64,6 +64,7 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, const std::string setBackground({0,0,0,0.5}); IViewManager& vm = rootView().viewManager(); + m_pathButtons.m_view.reset(new PathButtons(res, *this, *this)); m_fileField.m_view.reset(new TextField(res, *this, &m_fileFieldBind)); m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind, &m_fileListingBind, 3)); m_systemBookmarks.m_view.reset(new Table(res, *this, &m_systemBookmarkBind, &m_systemBookmarkBind, 1)); @@ -149,12 +150,7 @@ void FileBrowser::navigateToPath(const HECL::SystemString& path) m_fileListing.m_view->selectRow(-1); m_fileListing.m_view->updateData(); - m_pathButtons.clear(); - m_pathButtons.reserve(m_comps.size()); - size_t idx = 0; - ViewResources& res = rootView().viewRes(); - for (const HECL::SystemString& c : m_comps) - m_pathButtons.emplace_back(*this, res, idx++, c); + m_pathButtons.m_view->setButtons(m_comps); updateSize(); } @@ -163,8 +159,7 @@ void FileBrowser::updateContentOpacity(float opacity) { Zeus::CColor color = Zeus::CColor::lerp({1,1,1,0}, {1,1,1,1}, opacity); m_split.m_view->setMultiplyColor(color); - for (PathButton& b : m_pathButtons) - b.m_button.m_view->setMultiplyColor(color); + m_pathButtons.m_view->setMultiplyColor(color); m_fileField.m_view->setMultiplyColor(color); m_fileListing.m_view->setMultiplyColor(color); m_ok.m_button.m_view->setMultiplyColor(color); @@ -366,8 +361,7 @@ void FileBrowser::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton bu m_confirmWindow->mouseDown(coord, button, mod); m_split.mouseDown(coord, button, mod); - for (PathButton& b : m_pathButtons) - b.m_button.mouseDown(coord, button, mod); + m_pathButtons.mouseDown(coord, button, mod); m_fileField.mouseDown(coord, button, mod); m_fileListing.mouseDown(coord, button, mod); m_systemBookmarks.m_view->mouseDown(coord, button, mod); @@ -384,13 +378,7 @@ void FileBrowser::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton butt m_split.mouseUp(coord, button, mod); - for (PathButton& b : m_pathButtons) - b.m_button.mouseUp(coord, button, mod); - if (m_pathButtonPending >= 0) - { - pathButtonActivated(m_pathButtonPending); - m_pathButtonPending = -1; - } + m_pathButtons.mouseUp(coord, button, mod); m_fileField.mouseUp(coord, button, mod); m_fileListing.mouseUp(coord, button, mod); @@ -409,8 +397,7 @@ void FileBrowser::mouseMove(const boo::SWindowCoord& coord) if (closed()) return; m_split.mouseMove(coord); - for (PathButton& b : m_pathButtons) - b.m_button.mouseMove(coord); + m_pathButtons.mouseMove(coord); m_fileField.mouseMove(coord); m_fileListing.mouseMove(coord); m_systemBookmarks.m_view->mouseMove(coord); @@ -423,17 +410,12 @@ void FileBrowser::mouseMove(const boo::SWindowCoord& coord) m_confirmWindow->mouseMove(coord); } -void FileBrowser::mouseEnter(const boo::SWindowCoord& coord) -{ -} - void FileBrowser::mouseLeave(const boo::SWindowCoord& coord) { if (closed()) return; m_split.mouseLeave(coord); - for (PathButton& b : m_pathButtons) - b.m_button.mouseLeave(coord); + m_pathButtons.mouseLeave(coord); m_fileField.mouseLeave(coord); m_fileListing.mouseLeave(coord); m_ok.m_button.mouseLeave(coord); @@ -445,6 +427,7 @@ void FileBrowser::mouseLeave(const boo::SWindowCoord& coord) void FileBrowser::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll) { + m_pathButtons.scroll(coord, scroll); m_fileListing.scroll(coord, scroll); } @@ -536,18 +519,12 @@ void FileBrowser::RightSide::resized(const boo::SWindowRect& root, const boo::SW boo::SWindowRect pathRect = sub; pathRect.location[0] += BROWSER_MARGIN * pf; pathRect.location[1] += pathRect.size[1] - (BROWSER_MARGIN + 20) * pf; - for (PathButton& b : m_fb.m_pathButtons) - { - pathRect.size[0] = b.m_button.m_view->nominalWidth(); - pathRect.size[1] = b.m_button.m_view->nominalHeight(); - b.m_button.m_view->resized(root, pathRect); - pathRect.location[0] += pathRect.size[0] + 2; - } + pathRect.size[0] = sub.size[0] - m_fb.m_ok.m_button.m_view->nominalWidth() - 20 * pf; + pathRect.size[1] = m_fb.m_fileField.m_view->nominalHeight(); + m_fb.m_pathButtons.m_view->resized(root, pathRect); pathRect.location[0] = sub.location[0] + BROWSER_MARGIN * pf; pathRect.location[1] -= 25 * pf; - pathRect.size[0] = sub.size[0] - m_fb.m_ok.m_button.m_view->nominalWidth() - 20 * pf; - pathRect.size[1] = m_fb.m_fileField.m_view->nominalHeight(); m_fb.m_fileField.m_view->resized(root, pathRect); pathRect.location[1] = sub.location[1] + BROWSER_MARGIN * pf; @@ -570,6 +547,7 @@ void FileBrowser::think() ModalWindow::think(); if (m_fileListingBind.m_needsUpdate) navigateToPath(m_path); + m_pathButtons.m_view->think(); m_fileField.m_view->think(); m_fileListing.m_view->think(); m_systemBookmarks.m_view->think(); @@ -601,8 +579,7 @@ void FileBrowser::LeftSide::draw(boo::IGraphicsCommandQueue* gfxQ) void FileBrowser::RightSide::draw(boo::IGraphicsCommandQueue* gfxQ) { - for (PathButton& b : m_fb.m_pathButtons) - b.m_button.m_view->draw(gfxQ); + m_fb.m_pathButtons.m_view->draw(gfxQ); m_fb.m_fileListing.m_view->draw(gfxQ); m_fb.m_ok.m_button.m_view->draw(gfxQ); m_fb.m_cancel.m_button.m_view->draw(gfxQ); diff --git a/specter/lib/PathButtons.cpp b/specter/lib/PathButtons.cpp new file mode 100644 index 000000000..70c3fad21 --- /dev/null +++ b/specter/lib/PathButtons.cpp @@ -0,0 +1,84 @@ +#include "Specter/PathButtons.hpp" +#include "Specter/RootView.hpp" + +namespace Specter +{ + +PathButtons::PathButtons(ViewResources& res, View& parentView, IPathButtonsBinding& binding) +: ScrollView(res, parentView, ScrollView::Style::SideButtons), m_binding(binding) +{ + m_contentView.m_view.reset(new ContentView(res, *this)); + setContentView(m_contentView.m_view.get()); +} + +void PathButtons::setButtons(const std::vector& comps) +{ + m_pathButtons.clear(); + m_pathButtons.reserve(comps.size()); + size_t idx = 0; + ViewResources& res = rootView().viewRes(); + for (const HECL::SystemString& c : comps) + m_pathButtons.emplace_back(*this, res, idx++, c); +} + +void PathButtons::setMultiplyColor(const Zeus::CColor& color) +{ + ScrollView::setMultiplyColor(color); + for (PathButton& b : m_pathButtons) + b.m_button.m_view->setMultiplyColor(color); +} + +void PathButtons::ContentView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) +{ + for (PathButton& b : m_pb.m_pathButtons) + b.m_button.mouseDown(coord, button, mod); +} + +void PathButtons::ContentView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) +{ + for (PathButton& b : m_pb.m_pathButtons) + b.m_button.mouseUp(coord, button, mod); + if (m_pb.m_pathButtonPending >= 0) + { + m_pb.m_binding.pathButtonActivated(m_pb.m_pathButtonPending); + m_pb.m_pathButtonPending = -1; + } +} + +void PathButtons::ContentView::mouseMove(const boo::SWindowCoord& coord) +{ + for (PathButton& b : m_pb.m_pathButtons) + b.m_button.mouseMove(coord); +} + +void PathButtons::ContentView::mouseLeave(const boo::SWindowCoord& coord) +{ + for (PathButton& b : m_pb.m_pathButtons) + b.m_button.mouseLeave(coord); +} + +void PathButtons::ContentView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub, + const boo::SWindowRect& scissor) +{ + View::resized(root, sub); + m_scissorRect = scissor; + m_scissorRect.size[1] += 2; + boo::SWindowRect pathRect = sub; + for (PathButton& b : m_pb.m_pathButtons) + { + pathRect.size[0] = b.m_button.m_view->nominalWidth(); + pathRect.size[1] = b.m_button.m_view->nominalHeight(); + b.m_button.m_view->resized(root, pathRect); + pathRect.location[0] += pathRect.size[0] + 2; + } +} + +void PathButtons::ContentView::draw(boo::IGraphicsCommandQueue* gfxQ) +{ + gfxQ->setScissor(m_scissorRect); + for (PathButton& b : m_pb.m_pathButtons) + b.m_button.m_view->draw(gfxQ); + gfxQ->setScissor(rootView().subRect()); +} + +} diff --git a/specter/lib/ScrollView.cpp b/specter/lib/ScrollView.cpp index c54e74aaf..9f7169c09 100644 --- a/specter/lib/ScrollView.cpp +++ b/specter/lib/ScrollView.cpp @@ -7,7 +7,7 @@ namespace Specter #define MAX_SCROLL_SPEED 100 ScrollView::ScrollView(ViewResources& res, View& parentView, Style style) -: View(res, parentView), m_style(style) +: View(res, parentView), m_style(style), m_sideButtonBind(*this, rootView().viewManager()) { m_vertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), 4); @@ -33,39 +33,66 @@ ScrollView::ScrollView(ViewResources& res, View& parentView, Style style) nullptr, 1, bufs, 0, nullptr); } commitResources(res); + + if (style == Style::SideButtons) + { + m_sideButtons[0].m_view.reset(new Button(res, *this, &m_sideButtonBind, "<")); + m_sideButtons[1].m_view.reset(new Button(res, *this, &m_sideButtonBind, ">")); + } } bool ScrollView::_scroll(const boo::SScrollDelta& scroll) { - if (m_contentView) + if (m_contentView.m_view) { - float ratio = subRect().size[1] / float(m_contentView->nominalHeight()); - if (ratio >= 1.f) - { - m_scroll[0] = 0; - m_scroll[1] = 0; - m_targetScroll[0] = 0; - m_targetScroll[1] = 0; - return true; - } + float ratioX = subRect().size[0] / float(m_contentView.m_view->nominalWidth()); + float ratioY = subRect().size[1] / float(m_contentView.m_view->nominalHeight()); float pf = rootView().viewRes().pixelFactor(); double mult = 20.0 * pf; if (scroll.isFine) mult = 1.0 * pf; - //m_targetScroll[0] -= scroll.delta[0] * mult; - m_targetScroll[1] -= scroll.delta[1] * mult; - m_targetScroll[1] = std::max(m_targetScroll[1], 0); - int scrollHeight = m_contentView->nominalHeight() - subRect().size[1]; - m_targetScroll[1] = std::min(m_targetScroll[1], scrollHeight); + bool ret = false; + + if (ratioX >= 1.f) + { + m_scroll[0] = 0; + m_targetScroll[0] = 0; + m_drawSideButtons = false; + ret = true; + } + else + { + m_drawSideButtons = true; + m_targetScroll[0] += scroll.delta[0] * mult; + m_targetScroll[0] = std::min(m_targetScroll[0], 0); + int scrollWidth = m_contentView.m_view->nominalWidth() - scrollAreaWidth(); + m_targetScroll[0] = std::max(m_targetScroll[0], -scrollWidth); + } + + if (ratioY >= 1.f) + { + m_scroll[1] = 0; + m_targetScroll[1] = 0; + ret = true; + } + else + { + m_targetScroll[1] -= scroll.delta[1] * mult; + m_targetScroll[1] = std::max(m_targetScroll[1], 0); + int scrollHeight = m_contentView.m_view->nominalHeight() - subRect().size[1]; + m_targetScroll[1] = std::min(m_targetScroll[1], scrollHeight); + } if (scroll.isFine) { m_scroll[0] = m_targetScroll[0]; m_scroll[1] = m_targetScroll[1]; - return true; + ret = true; } + + return ret; } else { @@ -73,6 +100,7 @@ bool ScrollView::_scroll(const boo::SScrollDelta& scroll) m_scroll[1] = 0; m_targetScroll[0] = 0; m_targetScroll[1] = 0; + m_drawSideButtons = false; return true; } return false; @@ -80,32 +108,53 @@ bool ScrollView::_scroll(const boo::SScrollDelta& scroll) void ScrollView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) { - if (m_contentView) - m_contentView->mouseDown(coord, button, mod); + if (m_style == Style::SideButtons && m_drawSideButtons) + { + if (m_sideButtons[0].mouseDown(coord, button, mod) || + m_sideButtons[1].mouseDown(coord, button, mod)) + return; + } + m_contentView.mouseDown(coord, button, mod); } void ScrollView::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) { - if (m_contentView) - m_contentView->mouseUp(coord, button, mod); + if (m_style == Style::SideButtons) + { + m_sideButtons[0].mouseUp(coord, button, mod); + m_sideButtons[1].mouseUp(coord, button, mod); + } + m_contentView.mouseUp(coord, button, mod); } void ScrollView::mouseMove(const boo::SWindowCoord& coord) { - if (m_contentView) - m_contentView->mouseMove(coord); + if (m_style == Style::SideButtons && m_drawSideButtons) + { + m_sideButtons[0].mouseMove(coord); + m_sideButtons[1].mouseMove(coord); + } + m_contentView.mouseMove(coord); } void ScrollView::mouseEnter(const boo::SWindowCoord& coord) { - if (m_contentView) - m_contentView->mouseEnter(coord); + if (m_style == Style::SideButtons && m_drawSideButtons) + { + m_sideButtons[0].mouseEnter(coord); + m_sideButtons[1].mouseEnter(coord); + } + m_contentView.mouseEnter(coord); } void ScrollView::mouseLeave(const boo::SWindowCoord& coord) { - if (m_contentView) - m_contentView->mouseLeave(coord); + if (m_style == Style::SideButtons) + { + m_sideButtons[0].mouseLeave(coord); + m_sideButtons[1].mouseLeave(coord); + } + m_contentView.mouseLeave(coord); } void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll) @@ -136,6 +185,17 @@ void ScrollView::think() m_consecutiveScroll[m_consecutiveIdx][0] = 0.0; m_consecutiveScroll[m_consecutiveIdx][1] = 0.0; + if (m_sideButtonState != SideButtonState::None) + { + if (m_sideButtonState == SideButtonState::ScrollLeft) + m_targetScroll[0] -= 3; + else if (m_sideButtonState == SideButtonState::ScrollRight) + m_targetScroll[0] += 3; + m_targetScroll[0] = std::min(m_targetScroll[0], 0); + int scrollWidth = m_contentView.m_view->nominalWidth() - scrollAreaWidth(); + m_targetScroll[0] = std::max(m_targetScroll[0], -scrollWidth); + } + bool update = false; float pf = rootView().viewRes().pixelFactor(); @@ -171,14 +231,26 @@ void ScrollView::resized(const boo::SWindowRect& root, const boo::SWindowRect& s { View::resized(root, sub); _scroll({}); - if (m_contentView) + if (m_contentView.m_view) { boo::SWindowRect cRect = sub; cRect.location[0] += m_scroll[0]; - cRect.location[1] += sub.size[1] - m_contentView->nominalHeight() + m_scroll[1]; - cRect.size[0] = m_contentView->nominalWidth(); - cRect.size[1] = m_contentView->nominalHeight(); - m_contentView->resized(root, cRect, sub); + cRect.location[1] += sub.size[1] - m_contentView.m_view->nominalHeight() + m_scroll[1]; + cRect.size[0] = m_contentView.m_view->nominalWidth(); + cRect.size[1] = m_contentView.m_view->nominalHeight(); + m_contentView.m_scissorRect = sub; + if (m_style == Style::SideButtons && m_drawSideButtons) + { + int width0 = m_sideButtons[0].m_view->nominalWidth() + 2; + int width1 = m_sideButtons[1].m_view->nominalWidth(); + cRect.location[0] += width0; + cRect.size[0] -= (width0 + width1); + + m_contentView.m_scissorRect.location[0] += width0; + m_contentView.m_scissorRect.size[0] -= (width0 + width1); + } + m_contentView.m_view->resized(root, cRect, m_contentView.m_scissorRect); + if (m_style == Style::ThinIndicator) { @@ -202,14 +274,26 @@ void ScrollView::resized(const boo::SWindowRect& root, const boo::SWindowRect& s m_vertsBuf->load(m_verts, sizeof(m_verts)); } } + else if (m_style == Style::SideButtons && m_drawSideButtons) + { + boo::SWindowRect bRect = sub; + bRect.size[0] = m_sideButtons[0].m_view->nominalWidth(); + bRect.size[1] = m_sideButtons[0].m_view->nominalHeight(); + m_sideButtons[0].m_view->resized(root, bRect); + + bRect.size[0] = m_sideButtons[1].m_view->nominalWidth(); + bRect.size[1] = m_sideButtons[1].m_view->nominalHeight(); + bRect.location[0] += sub.size[0] - bRect.size[0]; + m_sideButtons[1].m_view->resized(root, bRect); + } } } void ScrollView::draw(boo::IGraphicsCommandQueue* gfxQ) { - if (m_contentView) + if (m_contentView.m_view) { - m_contentView->draw(gfxQ); + m_contentView.m_view->draw(gfxQ); if (m_style == Style::ThinIndicator && m_drawInd) { @@ -217,6 +301,11 @@ void ScrollView::draw(boo::IGraphicsCommandQueue* gfxQ) gfxQ->setDrawPrimitive(boo::Primitive::TriStrips); gfxQ->draw(0, 4); } + else if (m_style == Style::SideButtons && m_drawSideButtons) + { + m_sideButtons[0].m_view->draw(gfxQ); + m_sideButtons[1].m_view->draw(gfxQ); + } } } diff --git a/specter/lib/Space.cpp b/specter/lib/Space.cpp index b1dae9b95..98fc35dde 100644 --- a/specter/lib/Space.cpp +++ b/specter/lib/Space.cpp @@ -10,7 +10,9 @@ Space::Space(ViewResources& res, View& parentView, Toolbar::Position tbPos) : View(res, parentView), m_tbPos(tbPos) { commitResources(res); - m_toolbar.reset(new Toolbar(res, *this, tbPos)); + setBackground(res.themeData().spaceBackground()); + if (tbPos != Toolbar::Position::None) + m_toolbar.reset(new Toolbar(res, *this, tbPos)); } View* Space::setContentView(View* view) @@ -118,20 +120,24 @@ void Space::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) View::resized(root, sub); boo::SWindowRect tbRect = sub; - tbRect.size[1] = m_toolbar->nominalHeight(); - if (m_tbPos == Toolbar::Position::Top) - tbRect.location[1] += sub.size[1] - tbRect.size[1]; - m_toolbar->resized(root, tbRect); + if (m_toolbar) + { + tbRect.size[1] = m_toolbar->nominalHeight(); + if (m_tbPos == Toolbar::Position::Top) + tbRect.location[1] += sub.size[1] - tbRect.size[1]; + m_toolbar->resized(root, tbRect); + } + else + tbRect.size[1] = 0; if (m_contentView) { - if (m_tbPos == Toolbar::Position::Top) - tbRect.location[1] = sub.location[1]; - else - tbRect.location[1] += tbRect.size[1]; - tbRect.size[1] = sub.size[1] - tbRect.size[1]; - tbRect.size[1] = std::max(tbRect.size[1], 0); - m_contentView->resized(root, tbRect); + boo::SWindowRect contentRect = sub; + if (m_tbPos == Toolbar::Position::Bottom) + contentRect.location[1] += tbRect.size[1]; + contentRect.size[1] = sub.size[1] - tbRect.size[1]; + contentRect.size[1] = std::max(contentRect.size[1], 0); + m_contentView->resized(root, contentRect); } } @@ -140,7 +146,8 @@ void Space::draw(boo::IGraphicsCommandQueue* gfxQ) View::draw(gfxQ); if (m_contentView) m_contentView->draw(gfxQ); - m_toolbar->draw(gfxQ); + if (m_toolbar) + m_toolbar->draw(gfxQ); } } diff --git a/specter/lib/TextField.cpp b/specter/lib/TextField.cpp index e4df5d643..7301fa834 100644 --- a/specter/lib/TextField.cpp +++ b/specter/lib/TextField.cpp @@ -40,7 +40,7 @@ TextField::TextField(ViewResources& res, View& parentView, IStringBinding* strBi m_text.reset(new TextView(res, *this, res.m_mainFont, TextView::Alignment::Left, 1024)); if (strBind) - setText(strBind->getDefault()); + setText(strBind->getDefault(this)); } void TextField::_setText() @@ -52,7 +52,7 @@ void TextField::_setText() m_text->typesetGlyphs(m_textStr, m_error ? rootView().themeData().uiText() : rootView().themeData().fieldText()); if (m_controlBinding && dynamic_cast(m_controlBinding)) - static_cast(*m_controlBinding).changed(m_textStr); + static_cast(*m_controlBinding).changed(this, m_textStr); m_hasTextSet = false; if (m_deferredMarkStr.size()) m_hasMarkSet = true; diff --git a/specter/lib/View.cpp b/specter/lib/View.cpp index 0cf7692f8..230fa346a 100644 --- a/specter/lib/View.cpp +++ b/specter/lib/View.cpp @@ -4,6 +4,7 @@ namespace Specter { +static LogVisor::LogModule Log("Specter::View"); void View::Resources::init(boo::GLDataFactory* factory, const ThemeData& theme) { @@ -357,6 +358,8 @@ void View::draw(boo::IGraphicsCommandQueue* gfxQ) void View::commitResources(ViewResources& res) { + if (m_gfxData) + Log.report(LogVisor::FatalError, "multiple resource commits not allowed"); m_gfxData = res.m_factory->commit(); }