Skip to content

Commit

Permalink
refactoring ItemBox
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameco committed Sep 11, 2010
1 parent 375d587 commit cd49b64
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 31 deletions.
10 changes: 6 additions & 4 deletions Common/ItemBox/BaseCellView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@

namespace wraps
{

template<typename DataType>
class BaseCellView : public BaseLayout
class BaseCellView :
public BaseLayout
{
public:
typedef DataType Type;

protected:
BaseCellView(const std::string& _layout, MyGUI::Widget* _parent) : BaseLayout(_layout, _parent) { }

BaseCellView(const std::string& _layout, MyGUI::Widget* _parent) :
BaseLayout(_layout, _parent)
{
}
};

} // namespace wraps
Expand Down
28 changes: 16 additions & 12 deletions Common/ItemBox/BaseItemBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

namespace wraps
{

template<typename CellType>
class BaseItemBox : public BaseLayout
class BaseItemBox :
public BaseLayout
{
public:
typedef typename CellType::Type DataType;

public:
BaseItemBox(const std::string& _layout, MyGUI::Widget* _parent) : BaseLayout(_layout, _parent)
BaseItemBox(MyGUI::Widget* _parent) :
BaseLayout("", _parent)
{
mBoxItems = mMainWidget->castType<MyGUI::ItemBox>();
mBoxItems->setUserData(static_cast<BaseLayout*>(this));
Expand Down Expand Up @@ -61,7 +62,7 @@ namespace wraps
mListCellView.clear();
}

void addItem(DataType* _data)
void addItem(DataType _data)
{
mBoxItems->addItem(_data);
}
Expand All @@ -71,7 +72,12 @@ namespace wraps
mBoxItems->deleteItem(_index);
}

void setItemData(size_t _index, DataType* _data)
void removeAllItems()
{
mBoxItems->removeAllItems();
}

void setItemData(size_t _index, DataType _data)
{
mBoxItems->setItemDataAt(_index, _data);
}
Expand All @@ -98,7 +104,7 @@ namespace wraps
void requestUpdateWidgetItem(MyGUI::ItemBox* _sender, MyGUI::Widget* _item, const MyGUI::IBDrawItemInfo& _data)
{
CellType* cell = *_item->getUserData<CellType*>();
cell->update(_data, *mBoxItems->getItemDataAt<DataType*>(_data.index));
cell->update(_data, *mBoxItems->getItemDataAt<DataType>(_data.index));
}

void notifyStartDrop(MyGUI::DDContainer* _sender, const MyGUI::DDItemInfo& _info, bool& _result)
Expand Down Expand Up @@ -128,13 +134,12 @@ namespace wraps

void notifyToolTip(MyGUI::Widget* _sender, const MyGUI::ToolTipInfo& _info)
{
DataType* data = nullptr;
if (_info.type == MyGUI::ToolTipInfo::Show)
{
if (_info.index == MyGUI::ITEM_NONE) return;
data = *mBoxItems->getItemDataAt<DataType*>(_info.index);
if (_info.index == MyGUI::ITEM_NONE)
return;
}
eventToolTip(this, _info, data);
eventToolTip(this, _info, *mBoxItems->getItemDataAt<DataType>(_info.index));
}

public:
Expand All @@ -144,14 +149,13 @@ namespace wraps
MyGUI::delegates::CDelegate2<BaseLayout*, MyGUI::DDItemState> eventChangeDDState;
MyGUI::delegates::CDelegate2<BaseLayout*, const MyGUI::IBNotifyItemData& > eventNotifyItem;

MyGUI::delegates::CDelegate3<BaseLayout*, const MyGUI::ToolTipInfo&, DataType*> eventToolTip;
MyGUI::delegates::CDelegate3<BaseLayout*, const MyGUI::ToolTipInfo&, DataType> eventToolTip;

MyGUI::ItemBox* getItemBox()
{
return mBoxItems;
}


private:
typedef std::vector<CellType*> VectorCellView;
VectorCellView mListCellView;
Expand Down
2 changes: 0 additions & 2 deletions Common/ItemBox/ItemDropInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

namespace wraps
{

struct DDItemInfo
{

DDItemInfo(const MyGUI::DDItemInfo& _info) :
sender(*_info.sender->getUserData<wraps::BaseLayout*>()),
sender_index(_info.sender_index),
Expand Down
3 changes: 2 additions & 1 deletion Demos/Demo_Gui/ColourWindowBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace demo
{

ColourWindowBox::ColourWindowBox(MyGUI::Widget* _parent) : wraps::BaseItemBox<ColourWindowCellView>("", _parent)
ColourWindowBox::ColourWindowBox(MyGUI::Widget* _parent) :
wraps::BaseItemBox<ColourWindowCellView>(_parent)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Demos/Demo_Gui/ColourWindowBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace demo
{

class ColourWindowBox : public wraps::BaseItemBox<ColourWindowCellView>
class ColourWindowBox :
public wraps::BaseItemBox<ColourWindowCellView>
{
public:
ColourWindowBox(MyGUI::Widget* _parent);
Expand Down
2 changes: 1 addition & 1 deletion Demos/Demo_Gui/ColourWindowCellView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace demo
}

ColourWindowCellView::ColourWindowCellView(MyGUI::Widget* _parent) :
wraps::BaseCellView<ColourWindowCellData>("ColourWindowCellView.layout", _parent)
wraps::BaseCellView<ColourWindowCellData*>("ColourWindowCellView.layout", _parent)
{
mMainWidget->setCoord(0, 0, _parent->getWidth(), _parent->getHeight());
mMainWidget->setAlign(MyGUI::Align::Stretch);
Expand Down
6 changes: 2 additions & 4 deletions Demos/Demo_Gui/ColourWindowCellView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace demo
{

class ColourWindowCellView : public wraps::BaseCellView<ColourWindowCellData>
class ColourWindowCellView :
public wraps::BaseCellView<ColourWindowCellData*>
{
public:
ColourWindowCellView(MyGUI::Widget* _parent);
Expand All @@ -22,11 +22,9 @@ namespace demo
static void getCellDimension(MyGUI::Widget* _sender, MyGUI::IntCoord& _coord, bool _drop);

private:

MyGUI::StaticText* mText;
MyGUI::Widget* mColour;
MyGUI::RawRect* mRawColourView;

};

} // namespace demo
Expand Down
3 changes: 2 additions & 1 deletion Demos/Demo_ItemBox/CellView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace demo
else _coord.set(0, 0, 90, 74);
}

CellView::CellView(MyGUI::Widget* _parent) : wraps::BaseCellView<ItemData>("CellView.layout", _parent)
CellView::CellView(MyGUI::Widget* _parent) :
wraps::BaseCellView<ItemData*>("CellView.layout", _parent)
{
assignWidget(mImageBack, "image_Back");
assignWidget(mImageBorder, "image_Border");
Expand Down
5 changes: 2 additions & 3 deletions Demos/Demo_ItemBox/CellView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

namespace demo
{

class CellView : public wraps::BaseCellView<ItemData>
class CellView :
public wraps::BaseCellView<ItemData*>
{
public:
CellView(MyGUI::Widget* _parent);
Expand All @@ -27,7 +27,6 @@ namespace demo
MyGUI::StaticImage* mImageItem;
MyGUI::StaticText* mTextBack;
MyGUI::StaticText* mTextFront;

};

} // namespace demo
Expand Down
3 changes: 2 additions & 1 deletion Demos/Demo_ItemBox/ItemBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace demo
{

ItemBox::ItemBox(MyGUI::Widget* _parent) : wraps::BaseItemBox<CellView>("", _parent)
ItemBox::ItemBox(MyGUI::Widget* _parent) :
wraps::BaseItemBox<CellView>(_parent)
{
}

Expand Down

0 comments on commit cd49b64

Please sign in to comment.