Initial RootView-hosted boundary action menu

This commit is contained in:
Jack Andersen 2016-01-28 18:30:04 -10:00
parent 08b288039d
commit a5954a9d7c
5 changed files with 100 additions and 15 deletions

View File

@ -54,6 +54,7 @@ list(APPEND SPECTER_HEADERS
include/Specter/TextField.hpp
include/Specter/NumericField.hpp
include/Specter/Menu.hpp
include/Specter/IMenuNode.hpp
include/Specter/Node.hpp
include/Specter/NodeSocket.hpp
include/Specter/PathButtons.hpp

View File

@ -0,0 +1,20 @@
#ifndef SPECTER_IMENUNODE_HPP
#define SPECTER_IMENUNODE_HPP
#include "View.hpp"
namespace Specter
{
struct IMenuNode
{
virtual boo::ITexture* icon() const {return nullptr;}
virtual const std::string* text() const {return nullptr;}
virtual size_t subNodeCount() const {return 0;}
virtual IMenuNode* subNode(size_t idx) {return nullptr;}
virtual void activated(const boo::SWindowCoord& coord) {}
};
}
#endif // SPECTER_IMENUNODE_HPP

View File

@ -4,19 +4,11 @@
#include "View.hpp"
#include "TextView.hpp"
#include "ScrollView.hpp"
#include "IMenuNode.hpp"
namespace Specter
{
struct IMenuNode
{
virtual boo::ITexture* icon() const {return nullptr;}
virtual const std::string* text() const {return nullptr;}
virtual size_t subNodeCount() const {return 0;}
virtual IMenuNode* subNode(size_t idx) {return nullptr;}
virtual void activated(const boo::SWindowCoord& coord) {}
};
class Menu : public View
{
IMenuNode* m_rootNode;

View File

@ -8,6 +8,7 @@
#include "SplitView.hpp"
#include "Tooltip.hpp"
#include "FontCache.hpp"
#include "IMenuNode.hpp"
#include "DeferredWindowEvents.hpp"
#include "IViewManager.hpp"
#include <boo/boo.hpp>
@ -29,7 +30,7 @@ class RootView : public View
Button* m_activeMenuButton = nullptr;
ViewChild<std::unique_ptr<View>> m_rightClickMenu;
boo::SWindowCoord m_rightClickMenuCoord;
boo::SWindowRect m_rightClickMenuRootAndLoc;
SplitView* m_hoverSplitDragView = nullptr;
bool m_activeSplitDragView = false;
@ -37,6 +38,48 @@ class RootView : public View
DeferredWindowEvents<RootView> m_events;
struct SplitMenuNode : IMenuNode
{
RootView& m_rv;
std::string m_text;
SplitView* m_splitView = nullptr;
SplitMenuNode(RootView& rv)
: m_rv(rv), m_text(rv.m_viewMan.translateOr("boundary_action", "Boundary Action")),
m_splitActionNode(*this), m_joinActionNode(*this) {}
const std::string* text() const {return &m_text;}
size_t subNodeCount() const {return 2;}
IMenuNode* subNode(size_t idx)
{
if (idx)
return &m_joinActionNode;
else
return &m_splitActionNode;
}
struct SplitActionNode : IMenuNode
{
SplitMenuNode& m_smn;
std::string m_text;
SplitActionNode(SplitMenuNode& smn)
: m_smn(smn), m_text(smn.m_rv.m_viewMan.translateOr("split", "Split")) {}
const std::string* text() const {return &m_text;}
void activated(const boo::SWindowCoord& coord)
{
}
} m_splitActionNode;
struct JoinActionNode : IMenuNode
{
SplitMenuNode& m_smn;
std::string m_text;
JoinActionNode(SplitMenuNode& smn)
: m_smn(smn), m_text(smn.m_rv.m_viewMan.translateOr("join", "Join")) {}
const std::string* text() const {return &m_text;}
void activated(const boo::SWindowCoord& coord)
{
}
} m_joinActionNode;
} m_splitMenuNode;
public:
RootView(IViewManager& viewMan, ViewResources& res, boo::IWindow* window);
@ -77,7 +120,10 @@ public:
void adoptRightClickMenu(std::unique_ptr<View>&& menu, const boo::SWindowCoord& coord)
{
m_rightClickMenu.m_view = std::move(menu);
m_rightClickMenuCoord = coord;
m_rightClickMenuRootAndLoc = subRect();
m_rightClickMenuRootAndLoc.location[0] = coord.pixel[0];
m_rightClickMenuRootAndLoc.location[1] = coord.pixel[1];
updateSize();
}
View* getRightClickMenu() {return m_rightClickMenu.m_view.get();}

View File

@ -1,13 +1,15 @@
#include "Specter/RootView.hpp"
#include "Specter/ViewResources.hpp"
#include "Specter/Space.hpp"
#include "Specter/Menu.hpp"
namespace Specter
{
static LogVisor::LogModule Log("Specter::RootView");
RootView::RootView(IViewManager& viewMan, ViewResources& res, boo::IWindow* window)
: View(res), m_window(window), m_viewMan(viewMan), m_viewRes(&res), m_events(*this)
: View(res), m_window(window), m_viewMan(viewMan), m_viewRes(&res), m_events(*this),
m_splitMenuNode(*this)
{
window->setCallback(&m_events);
boo::SWindowRect rect = window->getWindowFrame();
@ -31,6 +33,16 @@ void RootView::resized(const boo::SWindowRect& root, const boo::SWindowRect&)
v->resized(m_rootRect, m_rootRect);
if (m_tooltip)
m_tooltip->resized(m_rootRect, m_rootRect);
if (m_rightClickMenu.m_view)
{
float wr = root.size[0] / float(m_rightClickMenuRootAndLoc.size[0]);
float hr = root.size[1] / float(m_rightClickMenuRootAndLoc.size[1]);
m_rightClickMenuRootAndLoc.size[0] = root.size[0];
m_rightClickMenuRootAndLoc.size[1] = root.size[1];
m_rightClickMenuRootAndLoc.location[0] *= wr;
m_rightClickMenuRootAndLoc.location[1] *= hr;
m_rightClickMenu.m_view->resized(root, m_rightClickMenuRootAndLoc);
}
m_resizeRTDirty = true;
}
@ -53,8 +65,16 @@ void RootView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton butto
if (m_hoverSplitDragView)
{
m_activeSplitDragView = true;
m_hoverSplitDragView->startDragSplit(coord);
if (button == boo::EMouseButton::Primary)
{
m_activeSplitDragView = true;
m_hoverSplitDragView->startDragSplit(coord);
}
else if (button == boo::EMouseButton::Secondary)
{
m_splitMenuNode.m_splitView = m_hoverSplitDragView;
adoptRightClickMenu(std::make_unique<Specter::Menu>(*m_viewRes, *this, &m_splitMenuNode), coord);
}
return;
}
@ -114,12 +134,18 @@ void RootView::mouseMove(const boo::SWindowCoord& coord)
{
if (m_rightClickMenu.m_view)
{
m_hSplitHover = false;
m_vSplitHover = false;
_updateCursor();
m_rightClickMenu.mouseMove(coord);
return;
}
if (m_activeMenuButton)
{
m_hSplitHover = false;
m_vSplitHover = false;
_updateCursor();
ViewChild<std::unique_ptr<View>>& mv = m_activeMenuButton->getMenu();
mv.mouseMove(coord);
return;
@ -308,7 +334,7 @@ void RootView::displayTooltip(const std::string& name, const std::string& help)
}
void RootView::draw(boo::IGraphicsCommandQueue* gfxQ)
{
{
if (m_resizeRTDirty)
{
gfxQ->resizeRenderTexture(m_renderTex, m_rootRect.size[0], m_rootRect.size[1]);