forked from teamnwah/openmw-tes3coop
Add properties for new widget classes to MyGUI plugin
This commit is contained in:
parent
2066097202
commit
6b65502557
15 changed files with 329 additions and 293 deletions
|
@ -32,7 +32,7 @@ add_openmw_dir (mwinput
|
|||
add_openmw_dir (mwgui
|
||||
textinput widgets race class birth review windowmanagerimp console dialogue
|
||||
windowbase statswindow messagebox journalwindow charactercreation
|
||||
mapwindow windowpinnablebase tooltips scrollwindow bookwindow list
|
||||
mapwindow windowpinnablebase tooltips scrollwindow bookwindow
|
||||
formatting inventorywindow container hud countdialog tradewindow settingswindow
|
||||
confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu
|
||||
itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <boost/bind.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <components/widgets/list.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/mechanicsmanager.hpp"
|
||||
|
@ -17,7 +19,6 @@
|
|||
#include "../mwdialogue/dialoguemanagerimp.hpp"
|
||||
|
||||
#include "widgets.hpp"
|
||||
#include "list.hpp"
|
||||
#include "tradewindow.hpp"
|
||||
#include "spellbuyingwindow.hpp"
|
||||
#include "travelwindow.hpp"
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
|
||||
#include "keywordsearch.hpp"
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class MWList;
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class WindowManager;
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
class MWList;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -169,7 +169,7 @@ namespace MWGui
|
|||
KeywordSearchT mKeywordSearch;
|
||||
|
||||
BookPage* mHistory;
|
||||
Widgets::MWList* mTopicsList;
|
||||
Gui::MWList* mTopicsList;
|
||||
MyGUI::ScrollBar* mScrollBar;
|
||||
MyGUI::Progress* mDispositionBar;
|
||||
MyGUI::EditBox* mDispositionText;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "../mwbase/soundmanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/journal.hpp"
|
||||
#include "list.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
|
@ -16,12 +15,12 @@
|
|||
#include "boost/lexical_cast.hpp"
|
||||
|
||||
#include <components/widgets/imagebutton.hpp>
|
||||
#include <components/widgets/list.hpp>
|
||||
|
||||
#include "bookpage.hpp"
|
||||
#include "windowbase.hpp"
|
||||
#include "journalviewmodel.hpp"
|
||||
#include "journalbooks.hpp"
|
||||
#include "list.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -111,10 +110,10 @@ namespace
|
|||
adviseButtonClick (ShowAllBTN, &JournalWindowImpl::notifyShowAll );
|
||||
adviseButtonClick (ShowActiveBTN, &JournalWindowImpl::notifyShowActive);
|
||||
|
||||
MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(QuestsList);
|
||||
Gui::MWList* list = getWidget<Gui::MWList>(QuestsList);
|
||||
list->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyQuestClicked);
|
||||
|
||||
MWGui::Widgets::MWList* topicsList = getWidget<MWGui::Widgets::MWList>(TopicsList);
|
||||
Gui::MWList* topicsList = getWidget<Gui::MWList>(TopicsList);
|
||||
topicsList->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyTopicSelected);
|
||||
|
||||
{
|
||||
|
@ -412,7 +411,7 @@ namespace
|
|||
setVisible (RightTopicIndex, false);
|
||||
setVisible (TopicsList, true);
|
||||
|
||||
MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(TopicsList);
|
||||
Gui::MWList* list = getWidget<Gui::MWList>(TopicsList);
|
||||
list->clear();
|
||||
|
||||
AddNamesToList add(list);
|
||||
|
@ -435,9 +434,9 @@ namespace
|
|||
|
||||
struct AddNamesToList
|
||||
{
|
||||
AddNamesToList(MWGui::Widgets::MWList* list) : mList(list) {}
|
||||
AddNamesToList(Gui::MWList* list) : mList(list) {}
|
||||
|
||||
MWGui::Widgets::MWList* mList;
|
||||
Gui::MWList* mList;
|
||||
void operator () (const std::string& name)
|
||||
{
|
||||
mList->addItem(name);
|
||||
|
@ -455,7 +454,7 @@ namespace
|
|||
setVisible (ShowAllBTN, !mAllQuests);
|
||||
setVisible (ShowActiveBTN, mAllQuests);
|
||||
|
||||
MWGui::Widgets::MWList* list = getWidget<MWGui::Widgets::MWList>(QuestsList);
|
||||
Gui::MWList* list = getWidget<Gui::MWList>(QuestsList);
|
||||
list->clear();
|
||||
|
||||
AddNamesToList add(list);
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
#include "list.hpp"
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_Button.h>
|
||||
#include <MyGUI_ImageBox.h>
|
||||
#include <MyGUI_ScrollBar.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
|
||||
MWList::MWList() :
|
||||
mClient(0)
|
||||
, mScrollView(0)
|
||||
, mItemHeight(0)
|
||||
{
|
||||
}
|
||||
|
||||
void MWList::initialiseOverride()
|
||||
{
|
||||
Base::initialiseOverride();
|
||||
|
||||
assignWidget(mClient, "Client");
|
||||
if (mClient == 0)
|
||||
mClient = this;
|
||||
|
||||
mScrollView = mClient->createWidgetReal<MyGUI::ScrollView>(
|
||||
"MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
|
||||
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
|
||||
}
|
||||
|
||||
void MWList::addItem(const std::string& name)
|
||||
{
|
||||
mItems.push_back(name);
|
||||
}
|
||||
|
||||
void MWList::addSeparator()
|
||||
{
|
||||
mItems.push_back("");
|
||||
}
|
||||
|
||||
void MWList::adjustSize()
|
||||
{
|
||||
redraw();
|
||||
}
|
||||
|
||||
void MWList::redraw(bool scrollbarShown)
|
||||
{
|
||||
const int _scrollBarWidth = 20; // fetch this from skin?
|
||||
const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0;
|
||||
const int spacing = 3;
|
||||
size_t viewPosition = -mScrollView->getViewOffset().top;
|
||||
|
||||
while (mScrollView->getChildCount())
|
||||
{
|
||||
MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));
|
||||
}
|
||||
|
||||
mItemHeight = 0;
|
||||
int i=0;
|
||||
for (std::vector<std::string>::const_iterator it=mItems.begin();
|
||||
it!=mItems.end(); ++it)
|
||||
{
|
||||
if (*it != "")
|
||||
{
|
||||
if (mListItemSkin.empty())
|
||||
throw std::runtime_error("MWList needs a ListItemSkin property");
|
||||
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
|
||||
mListItemSkin, MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
|
||||
button->setCaption((*it));
|
||||
button->getSubWidgetText()->setWordWrap(true);
|
||||
button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left);
|
||||
button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel);
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected);
|
||||
|
||||
int height = button->getTextSize().height;
|
||||
button->setSize(MyGUI::IntSize(button->getSize().width, height));
|
||||
button->setUserData(i);
|
||||
|
||||
mItemHeight += height + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
MyGUI::ImageBox* separator = mScrollView->createWidget<MyGUI::ImageBox>("MW_HLine",
|
||||
MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth() - scrollBarWidth - 4, 18),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
|
||||
separator->setNeedMouseFocus(false);
|
||||
|
||||
mItemHeight += 18 + spacing;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||
mScrollView->setVisibleVScroll(false);
|
||||
mScrollView->setCanvasSize(mClient->getSize().width, std::max(mItemHeight, mClient->getSize().height));
|
||||
mScrollView->setVisibleVScroll(true);
|
||||
|
||||
if (!scrollbarShown && mItemHeight > mClient->getSize().height)
|
||||
redraw(true);
|
||||
|
||||
size_t viewRange = mScrollView->getCanvasSize().height;
|
||||
if(viewPosition > viewRange)
|
||||
viewPosition = viewRange;
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, viewPosition * -1));
|
||||
}
|
||||
|
||||
void MWList::setPropertyOverride(const std::string &_key, const std::string &_value)
|
||||
{
|
||||
if (_key == "ListItemSkin")
|
||||
mListItemSkin = _value;
|
||||
else
|
||||
Base::setPropertyOverride(_key, _value);
|
||||
}
|
||||
|
||||
bool MWList::hasItem(const std::string& name)
|
||||
{
|
||||
return (std::find(mItems.begin(), mItems.end(), name) != mItems.end());
|
||||
}
|
||||
|
||||
unsigned int MWList::getItemCount()
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
std::string MWList::getItemNameAt(unsigned int at)
|
||||
{
|
||||
assert(at < mItems.size() && "List item out of bounds");
|
||||
return mItems[at];
|
||||
}
|
||||
|
||||
void MWList::removeItem(const std::string& name)
|
||||
{
|
||||
assert( std::find(mItems.begin(), mItems.end(), name) != mItems.end() );
|
||||
mItems.erase( std::find(mItems.begin(), mItems.end(), name) );
|
||||
}
|
||||
|
||||
void MWList::clear()
|
||||
{
|
||||
mItems.clear();
|
||||
}
|
||||
|
||||
void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||
{
|
||||
//NB view offset is negative
|
||||
if (mScrollView->getViewOffset().top + _rel*0.3 > 0)
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, mScrollView->getViewOffset().top + _rel*0.3));
|
||||
}
|
||||
|
||||
void MWList::onItemSelected(MyGUI::Widget* _sender)
|
||||
{
|
||||
std::string name = _sender->castType<MyGUI::Button>()->getCaption();
|
||||
int id = *_sender->getUserData<int>();
|
||||
eventItemSelected(name, id);
|
||||
eventWidgetSelected(_sender);
|
||||
}
|
||||
|
||||
MyGUI::Widget* MWList::getItemWidget(const std::string& name)
|
||||
{
|
||||
return mScrollView->findWidget (getName() + "_item_" + name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
#ifndef MWGUI_LIST_HPP
|
||||
#define MWGUI_LIST_HPP
|
||||
|
||||
#include <MyGUI_ScrollView.h>
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
namespace Widgets
|
||||
{
|
||||
/**
|
||||
* \brief a very simple list widget that supports word-wrapping entries
|
||||
* \note if the width or height of the list changes, you must call adjustSize() method
|
||||
*/
|
||||
class MWList : public MyGUI::Widget
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(MWList)
|
||||
public:
|
||||
MWList();
|
||||
|
||||
typedef MyGUI::delegates::CMultiDelegate2<const std::string&, int> EventHandle_StringInt;
|
||||
typedef MyGUI::delegates::CMultiDelegate1<MyGUI::Widget*> EventHandle_Widget;
|
||||
|
||||
/**
|
||||
* Event: Item selected with the mouse.
|
||||
* signature: void method(std::string itemName, int index)
|
||||
*/
|
||||
EventHandle_StringInt eventItemSelected;
|
||||
|
||||
/**
|
||||
* Event: Item selected with the mouse.
|
||||
* signature: void method(MyGUI::Widget* sender)
|
||||
*/
|
||||
EventHandle_Widget eventWidgetSelected;
|
||||
|
||||
|
||||
/**
|
||||
* Call after the size of the list changed, or items were inserted/removed
|
||||
*/
|
||||
void adjustSize();
|
||||
|
||||
void addItem(const std::string& name);
|
||||
void addSeparator(); ///< add a seperator between the current and the next item.
|
||||
void removeItem(const std::string& name);
|
||||
bool hasItem(const std::string& name);
|
||||
unsigned int getItemCount();
|
||||
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
|
||||
void clear();
|
||||
|
||||
MyGUI::Widget* getItemWidget(const std::string& name);
|
||||
///< get widget for an item name, useful to set up tooltip
|
||||
|
||||
virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
|
||||
|
||||
protected:
|
||||
void initialiseOverride();
|
||||
|
||||
void redraw(bool scrollbarShown = false);
|
||||
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
void onItemSelected(MyGUI::Widget* _sender);
|
||||
|
||||
private:
|
||||
MyGUI::ScrollView* mScrollView;
|
||||
MyGUI::Widget* mClient;
|
||||
std::string mListItemSkin;
|
||||
|
||||
std::vector<std::string> mItems;
|
||||
|
||||
int mItemHeight; // height of all items
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -522,7 +522,7 @@ namespace MWGui
|
|||
updateEffectsView ();
|
||||
}
|
||||
|
||||
void EffectEditorBase::setWidgets (Widgets::MWList *availableEffectsList, MyGUI::ScrollView *usedEffectsView)
|
||||
void EffectEditorBase::setWidgets (Gui::MWList *availableEffectsList, MyGUI::ScrollView *usedEffectsView)
|
||||
{
|
||||
mAvailableEffectsList = availableEffectsList;
|
||||
mUsedEffectsView = usedEffectsView;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#ifndef MWGUI_SPELLCREATION_H
|
||||
#define MWGUI_SPELLCREATION_H
|
||||
|
||||
#include <components/widgets/list.hpp>
|
||||
|
||||
#include "windowbase.hpp"
|
||||
#include "referenceinterface.hpp"
|
||||
#include "list.hpp"
|
||||
#include "widgets.hpp"
|
||||
|
||||
namespace MWGui
|
||||
|
@ -97,7 +98,7 @@ namespace MWGui
|
|||
protected:
|
||||
std::map<int, short> mButtonMapping; // maps button ID to effect ID
|
||||
|
||||
Widgets::MWList* mAvailableEffectsList;
|
||||
Gui::MWList* mAvailableEffectsList;
|
||||
MyGUI::ScrollView* mUsedEffectsView;
|
||||
|
||||
EditEffectDialog mAddEffectDialog;
|
||||
|
@ -124,7 +125,7 @@ namespace MWGui
|
|||
void updateEffectsView();
|
||||
|
||||
void startEditing();
|
||||
void setWidgets (Widgets::MWList* availableEffectsList, MyGUI::ScrollView* usedEffectsView);
|
||||
void setWidgets (Gui::MWList* availableEffectsList, MyGUI::ScrollView* usedEffectsView);
|
||||
|
||||
virtual void notifyEffectsChanged () {}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ namespace MWGui
|
|||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWEffectList>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpellEffect>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWDynamicStat>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWList>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::MWList>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::HBox>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::VBox>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedTextBox>("Widget");
|
||||
|
|
|
@ -96,7 +96,7 @@ add_component_dir (ogreinit
|
|||
)
|
||||
|
||||
add_component_dir (widgets
|
||||
box imagebutton tags
|
||||
box imagebutton tags list
|
||||
)
|
||||
|
||||
add_component_dir (fontloader
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Gui
|
|||
MyGUI::Widget * parent = w->getParent();
|
||||
if (parent != 0)
|
||||
{
|
||||
if (mExpandDirection == MyGUI::Align::Left)
|
||||
if (mExpandDirection.isLeft())
|
||||
{
|
||||
int hdiff = getRequestedSize ().width - w->getSize().width;
|
||||
w->setPosition(w->getPosition() - MyGUI::IntPoint(hdiff, 0));
|
||||
|
|
165
components/widgets/list.cpp
Normal file
165
components/widgets/list.cpp
Normal file
|
@ -0,0 +1,165 @@
|
|||
#include "list.hpp"
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_Button.h>
|
||||
#include <MyGUI_ImageBox.h>
|
||||
#include <MyGUI_ScrollBar.h>
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
||||
MWList::MWList() :
|
||||
mClient(0)
|
||||
, mScrollView(0)
|
||||
, mItemHeight(0)
|
||||
{
|
||||
}
|
||||
|
||||
void MWList::initialiseOverride()
|
||||
{
|
||||
Base::initialiseOverride();
|
||||
|
||||
assignWidget(mClient, "Client");
|
||||
if (mClient == 0)
|
||||
mClient = this;
|
||||
|
||||
mScrollView = mClient->createWidgetReal<MyGUI::ScrollView>(
|
||||
"MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0),
|
||||
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
|
||||
}
|
||||
|
||||
void MWList::addItem(const std::string& name)
|
||||
{
|
||||
mItems.push_back(name);
|
||||
}
|
||||
|
||||
void MWList::addSeparator()
|
||||
{
|
||||
mItems.push_back("");
|
||||
}
|
||||
|
||||
void MWList::adjustSize()
|
||||
{
|
||||
redraw();
|
||||
}
|
||||
|
||||
void MWList::redraw(bool scrollbarShown)
|
||||
{
|
||||
const int _scrollBarWidth = 20; // fetch this from skin?
|
||||
const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0;
|
||||
const int spacing = 3;
|
||||
size_t viewPosition = -mScrollView->getViewOffset().top;
|
||||
|
||||
while (mScrollView->getChildCount())
|
||||
{
|
||||
MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));
|
||||
}
|
||||
|
||||
mItemHeight = 0;
|
||||
int i=0;
|
||||
for (std::vector<std::string>::const_iterator it=mItems.begin();
|
||||
it!=mItems.end(); ++it)
|
||||
{
|
||||
if (*it != "")
|
||||
{
|
||||
if (mListItemSkin.empty())
|
||||
return;
|
||||
MyGUI::Button* button = mScrollView->createWidget<MyGUI::Button>(
|
||||
mListItemSkin, MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it));
|
||||
button->setCaption((*it));
|
||||
button->getSubWidgetText()->setWordWrap(true);
|
||||
button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left);
|
||||
button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel);
|
||||
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected);
|
||||
|
||||
int height = button->getTextSize().height;
|
||||
button->setSize(MyGUI::IntSize(button->getSize().width, height));
|
||||
button->setUserData(i);
|
||||
|
||||
mItemHeight += height + spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
MyGUI::ImageBox* separator = mScrollView->createWidget<MyGUI::ImageBox>("MW_HLine",
|
||||
MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth() - scrollBarWidth - 4, 18),
|
||||
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
|
||||
separator->setNeedMouseFocus(false);
|
||||
|
||||
mItemHeight += 18 + spacing;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||
mScrollView->setVisibleVScroll(false);
|
||||
mScrollView->setCanvasSize(mClient->getSize().width, std::max(mItemHeight, mClient->getSize().height));
|
||||
mScrollView->setVisibleVScroll(true);
|
||||
|
||||
if (!scrollbarShown && mItemHeight > mClient->getSize().height)
|
||||
redraw(true);
|
||||
|
||||
size_t viewRange = mScrollView->getCanvasSize().height;
|
||||
if(viewPosition > viewRange)
|
||||
viewPosition = viewRange;
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, viewPosition * -1));
|
||||
}
|
||||
|
||||
void MWList::setPropertyOverride(const std::string &_key, const std::string &_value)
|
||||
{
|
||||
if (_key == "ListItemSkin")
|
||||
mListItemSkin = _value;
|
||||
else
|
||||
Base::setPropertyOverride(_key, _value);
|
||||
}
|
||||
|
||||
bool MWList::hasItem(const std::string& name)
|
||||
{
|
||||
return (std::find(mItems.begin(), mItems.end(), name) != mItems.end());
|
||||
}
|
||||
|
||||
unsigned int MWList::getItemCount()
|
||||
{
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
std::string MWList::getItemNameAt(unsigned int at)
|
||||
{
|
||||
assert(at < mItems.size() && "List item out of bounds");
|
||||
return mItems[at];
|
||||
}
|
||||
|
||||
void MWList::removeItem(const std::string& name)
|
||||
{
|
||||
assert( std::find(mItems.begin(), mItems.end(), name) != mItems.end() );
|
||||
mItems.erase( std::find(mItems.begin(), mItems.end(), name) );
|
||||
}
|
||||
|
||||
void MWList::clear()
|
||||
{
|
||||
mItems.clear();
|
||||
}
|
||||
|
||||
void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel)
|
||||
{
|
||||
//NB view offset is negative
|
||||
if (mScrollView->getViewOffset().top + _rel*0.3 > 0)
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, mScrollView->getViewOffset().top + _rel*0.3));
|
||||
}
|
||||
|
||||
void MWList::onItemSelected(MyGUI::Widget* _sender)
|
||||
{
|
||||
std::string name = _sender->castType<MyGUI::Button>()->getCaption();
|
||||
int id = *_sender->getUserData<int>();
|
||||
eventItemSelected(name, id);
|
||||
eventWidgetSelected(_sender);
|
||||
}
|
||||
|
||||
MyGUI::Widget* MWList::getItemWidget(const std::string& name)
|
||||
{
|
||||
return mScrollView->findWidget (getName() + "_item_" + name);
|
||||
}
|
||||
|
||||
}
|
71
components/widgets/list.hpp
Normal file
71
components/widgets/list.hpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#ifndef MWGUI_LIST_HPP
|
||||
#define MWGUI_LIST_HPP
|
||||
|
||||
#include <MyGUI_ScrollView.h>
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
/**
|
||||
* \brief a very simple list widget that supports word-wrapping entries
|
||||
* \note if the width or height of the list changes, you must call adjustSize() method
|
||||
*/
|
||||
class MWList : public MyGUI::Widget
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(MWList)
|
||||
public:
|
||||
MWList();
|
||||
|
||||
typedef MyGUI::delegates::CMultiDelegate2<const std::string&, int> EventHandle_StringInt;
|
||||
typedef MyGUI::delegates::CMultiDelegate1<MyGUI::Widget*> EventHandle_Widget;
|
||||
|
||||
/**
|
||||
* Event: Item selected with the mouse.
|
||||
* signature: void method(std::string itemName, int index)
|
||||
*/
|
||||
EventHandle_StringInt eventItemSelected;
|
||||
|
||||
/**
|
||||
* Event: Item selected with the mouse.
|
||||
* signature: void method(MyGUI::Widget* sender)
|
||||
*/
|
||||
EventHandle_Widget eventWidgetSelected;
|
||||
|
||||
|
||||
/**
|
||||
* Call after the size of the list changed, or items were inserted/removed
|
||||
*/
|
||||
void adjustSize();
|
||||
|
||||
void addItem(const std::string& name);
|
||||
void addSeparator(); ///< add a seperator between the current and the next item.
|
||||
void removeItem(const std::string& name);
|
||||
bool hasItem(const std::string& name);
|
||||
unsigned int getItemCount();
|
||||
std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
|
||||
void clear();
|
||||
|
||||
MyGUI::Widget* getItemWidget(const std::string& name);
|
||||
///< get widget for an item name, useful to set up tooltip
|
||||
|
||||
virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
|
||||
|
||||
protected:
|
||||
void initialiseOverride();
|
||||
|
||||
void redraw(bool scrollbarShown = false);
|
||||
|
||||
void onMouseWheel(MyGUI::Widget* _sender, int _rel);
|
||||
void onItemSelected(MyGUI::Widget* _sender);
|
||||
|
||||
private:
|
||||
MyGUI::ScrollView* mScrollView;
|
||||
MyGUI::Widget* mClient;
|
||||
std::string mListItemSkin;
|
||||
|
||||
std::vector<std::string> mItems;
|
||||
|
||||
int mItemHeight; // height of all items
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,30 +1,70 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MyGUI>
|
||||
<MyGUI type="Widgets">
|
||||
<!-- New widget class definitions -->
|
||||
<Widget name="VBox">
|
||||
<Property key="DefaultSkin" value=""/>
|
||||
<Property key="Skin" value="" group="Plugin" name="VBox"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="Spacing" value="1 int"/>
|
||||
<Parameter key="Padding" value="1 int"/>
|
||||
<Parameter key="AutoResize" value="Bool"/>
|
||||
</Widget>
|
||||
<Widget name="HBox">
|
||||
<Property key="DefaultSkin" value=""/>
|
||||
<Property key="Skin" value="" group="Plugin" name="HBox"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="Spacing" value="1 int"/>
|
||||
<Parameter key="Padding" value="1 int"/>
|
||||
<Parameter key="AutoResize" value="Bool"/>
|
||||
</Widget>
|
||||
</MyGUI>
|
||||
<MyGUI type="Plugin">
|
||||
<Plugin>
|
||||
<Source>./Plugin_MyGUI_OpenMW_Resources</Source>
|
||||
<Source build="Debug">./Plugin_MyGUI_OpenMW_Resources_d</Source>
|
||||
</Plugin>
|
||||
</MyGUI>
|
||||
<MyGUI type="Widgets">
|
||||
<!-- New widget class definitions -->
|
||||
<Widget name="ImageButton">
|
||||
<Property key="DefaultSkin" value="ImageBox"/>
|
||||
<Property key="Skin" value="ImageBox" group="Plugin" name="ImageButton"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="ImageHighlighted" value="String"/>
|
||||
<Parameter key="ImagePushed" value="String"/>
|
||||
<Parameter key="ImageNormal" value="String"/>
|
||||
</Widget>
|
||||
<Widget name="VBox">
|
||||
<Property key="DefaultSkin" value=""/>
|
||||
<Property key="Skin" value="" group="Plugin" name="VBox"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="Spacing" value="1 int"/>
|
||||
<Parameter key="Padding" value="1 int"/>
|
||||
<Parameter key="AutoResize" value="Bool"/>
|
||||
</Widget>
|
||||
<Widget name="HBox">
|
||||
<Property key="DefaultSkin" value=""/>
|
||||
<Property key="Skin" value="" group="Plugin" name="HBox"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="Spacing" value="1 int"/>
|
||||
<Parameter key="Padding" value="1 int"/>
|
||||
<Parameter key="AutoResize" value="Bool"/>
|
||||
</Widget>
|
||||
<Widget name="AutoSizedButton">
|
||||
<Property key="Base" value="Button"/>
|
||||
<Property key="DefaultSkin" value="MW_Button"/>
|
||||
<Property key="Skin" value="MW_Button" group="Plugin" name="AutoSizedButton"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="ExpandDirection" value="Align"/>
|
||||
</Widget>
|
||||
<Widget name="AutoSizedTextBox">
|
||||
<Property key="Base" value="TextBox"/>
|
||||
<Property key="DefaultSkin" value="SandText"/>
|
||||
<Property key="Skin" value="SandText" group="Plugin" name="AutoSizedTextBox"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="ExpandDirection" value="Align"/>
|
||||
</Widget>
|
||||
<Widget name="AutoSizedEditBox">
|
||||
<Property key="Base" value="EditBox"/>
|
||||
<Property key="DefaultSkin" value="SandText"/>
|
||||
<Property key="Skin" value="SandText" group="Plugin" name="AutoSizedEditBox"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="ExpandDirection" value="Align"/>
|
||||
</Widget>
|
||||
<Widget name="MWList">
|
||||
<Property key="DefaultSkin" value="MW_SimpleList"/>
|
||||
<Property key="Skin" value="MW_SimpleList" group="Plugin" name="MWList"/>
|
||||
<Property key="Parent" value="true"/>
|
||||
<Property key="Child" value="true"/>
|
||||
<Parameter key="ListItemSkin" value="Skin"/>
|
||||
</Widget>
|
||||
</MyGUI>
|
||||
<MyGUI type="Plugin">
|
||||
<Plugin>
|
||||
<Source>./Plugin_MyGUI_OpenMW_Resources</Source>
|
||||
<Source build="Debug">./Plugin_MyGUI_OpenMW_Resources_d</Source>
|
||||
</Plugin>
|
||||
</MyGUI>
|
||||
</MyGUI>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <components/widgets/imagebutton.hpp>
|
||||
#include <components/widgets/box.hpp>
|
||||
#include <components/widgets/tags.hpp>
|
||||
#include <components/widgets/list.hpp>
|
||||
|
||||
#include <OgreTextureManager.h>
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
|
@ -142,6 +143,7 @@ namespace MyGUIPlugin
|
|||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedTextBox>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedEditBox>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedButton>("Widget");
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<Gui::MWList>("Widget");
|
||||
}
|
||||
|
||||
void ResourcePlugin::createTransparentBGTexture()
|
||||
|
|
Loading…
Reference in a new issue