Drag&Drop: auto-hide windows that can't be drop targets on mouseover

actorid
scrawl 11 years ago
parent 3a5da7e6e8
commit 365ae15532

@ -373,8 +373,9 @@ namespace MWGui
// ------------------------------------------------------------------------------------------
MapWindow::MapWindow(const std::string& cacheDir)
: MWGui::WindowPinnableBase("openmw_map_window.layout")
MapWindow::MapWindow(DragAndDrop* drag, const std::string& cacheDir)
: WindowPinnableBase("openmw_map_window.layout")
, NoDrop(drag, mMainWidget)
, mGlobal(false)
, mGlobalMap(0)
, mGlobalMapRender(0)

@ -75,10 +75,10 @@ namespace MWGui
float mLastDirectionY;
};
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase
class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase, public NoDrop
{
public:
MapWindow(const std::string& cacheDir);
MapWindow(DragAndDrop* drag, const std::string& cacheDir);
virtual ~MapWindow();
void setCellName(const std::string& cellName);
@ -92,6 +92,8 @@ namespace MWGui
virtual void open();
void onFrame(float dt) { NoDrop::onFrame(dt); }
private:
void onDragStart(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void onMouseDrag(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);

@ -42,8 +42,9 @@ namespace
namespace MWGui
{
SpellWindow::SpellWindow()
SpellWindow::SpellWindow(DragAndDrop* drag)
: WindowPinnableBase("openmw_spell_window.layout")
, NoDrop(drag, mMainWidget)
, mHeight(0)
, mWidth(0)
{

@ -7,14 +7,16 @@ namespace MWGui
{
class SpellIcons;
class SpellWindow : public WindowPinnableBase
class SpellWindow : public WindowPinnableBase, public NoDrop
{
public:
SpellWindow();
SpellWindow(DragAndDrop* drag);
virtual ~SpellWindow();
void updateSpells();
void onFrame(float dt) { NoDrop::onFrame(dt); }
protected:
MyGUI::ScrollView* mSpellView;
MyGUI::Widget* mEffectBox;

@ -18,8 +18,9 @@ namespace MWGui
const int StatsWindow::sLineHeight = 18;
StatsWindow::StatsWindow ()
StatsWindow::StatsWindow (DragAndDrop* drag)
: WindowPinnableBase("openmw_stats_window.layout")
, NoDrop(drag, mMainWidget)
, mSkillView(NULL)
, mMajorSkills()
, mMinorSkills()
@ -219,11 +220,13 @@ namespace MWGui
updateSkillArea();
}
void StatsWindow::onFrame ()
void StatsWindow::onFrame (float dt)
{
if (!mMainWidget->getVisible())
return;
NoDrop::onFrame(dt);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const MWMechanics::NpcStats &PCstats = MWWorld::Class::get(player).getNpcStats(player);

@ -10,17 +10,17 @@ namespace MWGui
{
class WindowManager;
class StatsWindow : public WindowPinnableBase
class StatsWindow : public WindowPinnableBase, public NoDrop
{
public:
typedef std::map<std::string, int> FactionList;
typedef std::vector<int> SkillList;
StatsWindow();
StatsWindow(DragAndDrop* drag);
/// automatically updates all the data in the stats window, but only if it has changed.
void onFrame();
void onFrame(float dt);
void setBar(const std::string& name, const std::string& tname, int val, int max);
void setPlayerName(const std::string& playerName);

@ -1,6 +1,7 @@
#include "windowbase.hpp"
#include "../mwbase/windowmanager.hpp"
#include "container.hpp"
using namespace MWGui;
@ -50,3 +51,36 @@ void WindowModal::close()
{
MyGUI::InputManager::getInstance ().removeWidgetModal (mMainWidget);
}
NoDrop::NoDrop(DragAndDrop *drag, MyGUI::Widget *widget)
: mDrag(drag), mWidget(widget), mTransparent(false)
{
}
void NoDrop::onFrame(float dt)
{
MyGUI::IntPoint mousePos = MyGUI::InputManager::getInstance().getMousePosition();
if (mDrag->mIsOnDragAndDrop)
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getMouseFocusWidget();
while (focus && focus != mWidget)
focus = focus->getParent();
if (focus == mWidget)
mTransparent = true;
}
if (!mWidget->getAbsoluteCoord().inside(mousePos))
mTransparent = false;
if (mTransparent)
{
mWidget->setNeedMouseFocus(false); // Allow click-through
mWidget->setAlpha(std::max(0.13f, mWidget->getAlpha() - dt*5));
}
else
{
mWidget->setNeedMouseFocus(true);
mWidget->setAlpha(std::min(1.0f, mWidget->getAlpha() + dt*5));
}
}

@ -11,6 +11,7 @@ namespace MWBase
namespace MWGui
{
class WindowManager;
class DragAndDrop;
class WindowBase: public OEngine::GUI::Layout
{
@ -42,6 +43,21 @@ namespace MWGui
virtual void open();
virtual void close();
};
/// A window that cannot be the target of a drag&drop action.
/// When hovered with a drag item, the window will become transparent and allow click-through.
class NoDrop
{
public:
NoDrop(DragAndDrop* drag, MyGUI::Widget* widget);
void onFrame(float dt);
private:
MyGUI::Widget* mWidget;
DragAndDrop* mDrag;
bool mTransparent;
};
}
#endif

@ -200,9 +200,9 @@ namespace MWGui
mRecharge = new Recharge();
mMenu = new MainMenu(w,h);
mMap = new MapWindow("");
mMap = new MapWindow(mDragAndDrop, "");
trackWindow(mMap, "map");
mStatsWindow = new StatsWindow();
mStatsWindow = new StatsWindow(mDragAndDrop);
trackWindow(mStatsWindow, "stats");
mConsole = new Console(w,h, mConsoleOnlyScripts);
trackWindow(mConsole, "console");
@ -227,7 +227,7 @@ namespace MWGui
mConfirmationDialog = new ConfirmationDialog();
mAlchemyWindow = new AlchemyWindow();
trackWindow(mAlchemyWindow, "alchemy");
mSpellWindow = new SpellWindow();
mSpellWindow = new SpellWindow(mDragAndDrop);
trackWindow(mSpellWindow, "spells");
mQuickKeysMenu = new QuickKeysMenu();
mLevelupDialog = new LevelupDialog();
@ -709,7 +709,9 @@ namespace MWGui
mInventoryWindow->onFrame();
mStatsWindow->onFrame();
mStatsWindow->onFrame(frameDuration);
mMap->onFrame(frameDuration);
mSpellWindow->onFrame(frameDuration);
mWaitDialog->onFrame(frameDuration);

Loading…
Cancel
Save