From 5603cb312cd6f00f06fe88597e5d2e202d53e292 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 27 Apr 2012 20:54:39 +0200 Subject: [PATCH] Objects can now be selected and follow mouse movements. --- apps/openmw/mwgui/container.cpp | 37 +++++++++++++++++++-------- apps/openmw/mwgui/container.hpp | 9 ++++--- apps/openmw/mwgui/inventorywindow.cpp | 4 +-- apps/openmw/mwgui/inventorywindow.hpp | 2 +- apps/openmw/mwgui/window_manager.cpp | 11 +++++--- files/mygui/openmw_layers.xml | 1 + 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index e3d7574f3..b3fe7adfb 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -17,15 +17,17 @@ #include "../mwworld/containerstore.hpp" #include #include "../mwworld/class.hpp" +#include "../mwinput/inputmanager.hpp" using namespace MWGui; using namespace Widgets; -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) : WindowBase("openmw_container_window_layout.xml", parWindowManager), - mEnvironment(environment) + mEnvironment(environment), + mDragAndDropWidget(dragAndDropWidget) { setText("_Main", "Name of Container"); @@ -43,17 +45,24 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("CloseButton","Close"); setText("TakeButton","Take All"); + + mIsOnDragAndDrop = false; + mDraggedWidget = 0; //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget,std::string guiFile) : WindowBase(guiFile, parWindowManager), - mEnvironment(environment) + mEnvironment(environment), + mDragAndDropWidget(dragAndDropWidget) { setText("_Main", "Name of Container"); //center(); adjustWindowCaption(); getWidget(mContainerWidget, "Items"); + + mIsOnDragAndDrop = false; + mDraggedWidget = 0; //getWidget(takeButton, "TakeButton"); //getWidget(closeButton, "CloseButton"); @@ -130,7 +139,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) MyGUI::ImageBox* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); - image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); + //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); x += 36; if(count % 20 == 0) { @@ -159,7 +168,12 @@ void ContainerWindow::open(MWWorld::Ptr& container) void ContainerWindow::Update() { - + if(mIsOnDragAndDrop) + { + if(mDraggedWidget) + mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + else mIsOnDragAndDrop = false; //If this happens, there is a bug. + } } void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) @@ -171,17 +185,20 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) { + mIsOnDragAndDrop = true; _sender->detachFromWidget(); - _sender->attachToWidget(mContainerWidget->getParent()->getParent()); - std::cout << mContainerWidget->getParent()->getParent()->getName(); + _sender->attachToWidget(mDragAndDropWidget); + //std::cout << mContainerWidget->getParent()->getParent()->getName(); _sender->setUserString("drag","on"); + mDraggedWidget = _sender; std::cout << "selected!"; } void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) { - if(_sender->getUserString("drag") == "on") + /*if(_sender->getUserString("drag") == "on") { _sender->setPosition(_left,_top); - } + + }*/ } \ No newline at end of file diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 6ac9a814f..2d1aa3ac0 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -35,8 +35,9 @@ namespace MWGui class ContainerWindow : public WindowBase { public: - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile); + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget, + std::string guiFile); void open(MWWorld::Ptr& container); @@ -52,7 +53,9 @@ namespace MWGui MyGUI::ButtonPtr takeButton; MyGUI::ButtonPtr closeButton; - + MyGUI::Widget* mDragAndDropWidget; + bool mIsOnDragAndDrop; + MyGUI::Widget* mDraggedWidget; void onByeClicked(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 188cc3796..efc9106e9 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -21,8 +21,8 @@ namespace MWGui { - InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) - :ContainerWindow(parWindowManager,environment,"openmw_inventory_window_layout.xml") + InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) + :ContainerWindow(parWindowManager,environment,dragAndDropWidget,"openmw_inventory_window_layout.xml") { } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index bf9be4375..c60889d73 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -24,7 +24,7 @@ namespace MWGui class InventoryWindow : public MWGui::ContainerWindow { public: - InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); + InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); void openInventory(); }; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index c15f7077d..f2adfe1e1 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -65,7 +65,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, logpath); gui = mGuiManager->getGui(); - + //Register own widgets with MyGUI MyGUI::FactoryManager::getInstance().registerFactory("Widget"); @@ -74,6 +74,9 @@ WindowManager::WindowManager(MWWorld::Environment& environment, int w = MyGUI::RenderManager::getInstance().getViewSize().width; int h = MyGUI::RenderManager::getInstance().getViewSize().height; + MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); + dragAndDropWidget->setVisible(false); + hud = new HUD(w,h, showFPSLevel); menu = new MainMenu(w,h); map = new MapWindow(*this); @@ -82,8 +85,8 @@ WindowManager::WindowManager(MWWorld::Environment& environment, mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); dialogueWindow = new DialogueWindow(*this,environment); - containerWindow = new ContainerWindow(*this,environment); - mInventoryWindow = new InventoryWindow(*this,environment); + containerWindow = new ContainerWindow(*this,environment,dragAndDropWidget); + mInventoryWindow = new InventoryWindow(*this,environment,dragAndDropWidget); // The HUD is always on hud->setVisible(true); @@ -422,6 +425,8 @@ void WindowManager::onDialogueWindowBye() void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); + mInventoryWindow->Update(); + containerWindow->Update(); } const ESMS::ESMStore& WindowManager::getStore() const diff --git a/files/mygui/openmw_layers.xml b/files/mygui/openmw_layers.xml index a83eb970a..81cd99fea 100644 --- a/files/mygui/openmw_layers.xml +++ b/files/mygui/openmw_layers.xml @@ -10,4 +10,5 @@ +