39 mCurrentTextureName = _texture;
44 mRectImage.
top = _coord.
top;
49 updateSelectIndex(mIndexSelect);
59 if (mIndexSelect ==
ITEM_NONE) mIndexSelect = 0;
62 updateSelectIndex(mIndexSelect);
68 mRectImage.
top = _coord.
top;
82 if (mIndexSelect ==
ITEM_NONE) mIndexSelect = 0;
85 updateSelectIndex(mIndexSelect);
90 mCurrentTextureName = _texture;
102 updateSelectIndex(mIndexSelect);
106 void ImageBox::recalcIndexes()
112 if ((mSizeTile.
width <= 0) || (mSizeTile.
height <= 0))
115 size_t count_h = (size_t)(mRectImage.
width() / mSizeTile.
width);
116 size_t count_v = (size_t)(mRectImage.
height() / mSizeTile.
height);
124 int pos_h = mRectImage.
left;
125 int pos_v = mRectImage.
top;
127 for (
size_t v = 0; v < count_v; ++v)
129 for (
size_t h = 0; h < count_h; ++h)
132 pos_h += mSizeTile.
width;
134 pos_v += mSizeTile.
height;
135 pos_h = mRectImage.
left;
139 void ImageBox::updateSelectIndex(
size_t _index)
141 mIndexSelect = _index;
143 if ((_index ==
ITEM_NONE) || (_index >= mItems.size()))
153 VectorImages::iterator iter = mItems.begin() + _index;
155 if (iter->images.size() < 2)
169 if ( ! iter->images.empty())
171 _setUVSet(iter->images.front());
179 mItems.erase(mItems.begin() + _index);
183 if (mItems.empty()) updateSelectIndex(
ITEM_NONE);
184 else if ((_index < mIndexSelect) || (mIndexSelect == mItems.size())) updateSelectIndex(mIndexSelect--);
197 if (_index ==
ITEM_NONE) _index = mItems.size();
199 VectorImages::iterator iter = mItems.insert(mItems.begin() + _index,
ImageItem());
203 if ((mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect)) updateSelectIndex(mIndexSelect++);
210 VectorImages::iterator iter = mItems.begin() + _index;
211 iter->images.clear();
214 if (_index == mIndexSelect) updateSelectIndex(mIndexSelect);
217 void ImageBox::frameEntered(
float _frame)
221 if (mItems.empty())
return;
222 VectorImages::iterator iter = mItems.begin() + mIndexSelect;
223 if ((iter->images.size() < 2) || (iter->frame_rate == 0))
return;
225 mCurrentTime += _frame;
227 while (mCurrentTime >= iter->frame_rate)
229 mCurrentTime -= iter->frame_rate;
231 if (mCurrentFrame >= (iter->images.size())) mCurrentFrame = 0;
234 _setUVSet(iter->images[mCurrentFrame]);
240 VectorImages::iterator iter = mItems.begin() + _index;
241 iter->images.clear();
247 VectorImages::iterator iter = mItems.begin() + _index;
254 VectorImages::iterator iter = mItems.begin() + _index;
255 iter->frame_rate = _rate;
261 VectorImages::const_iterator iter = mItems.begin() + _index;
262 return iter->frame_rate;
269 VectorImages::iterator iter = mItems.begin() + _index;
270 MYGUI_ASSERT_RANGE(_indexSourceFrame, iter->images.size(),
"ImageBox::addItemFrameDuplicate");
271 iter->images.push_back(iter->images[_indexSourceFrame]);
278 VectorImages::iterator iter = mItems.begin() + _index;
280 if (_indexFrame ==
ITEM_NONE) _indexFrame = iter->images.size() - 1;
282 iter->images.insert(iter->images.begin() + _indexFrame,
290 VectorImages::iterator iter = mItems.begin() + _index;
292 if (_indexFrame ==
ITEM_NONE) _indexFrame = iter->images.size() - 1;
294 MYGUI_ASSERT_RANGE(_indexSourceFrame, iter->images.size(),
"ImageBox::insertItemFrameDuplicate");
296 iter->images.insert(iter->images.begin() + _indexFrame, iter->images[_indexSourceFrame]);
303 VectorImages::iterator iter = mItems.begin() + _index;
313 VectorImages::iterator iter = mItems.begin() + _index;
315 if (_indexFrame ==
ITEM_NONE) _indexFrame = iter->images.size() - 1;
317 iter->images.erase(iter->images.begin() + _indexFrame);
322 mCurrentTextureName = _info.
texture;
327 if (_info.
frames.size() != 0)
329 std::vector<IntPoint>::const_iterator iter = _info.
frames.begin();
334 for (++iter; iter != _info.
frames.end(); ++iter)
342 updateSelectIndex(mIndexSelect);
349 return resource !=
nullptr;
354 if (mResource == _resource)
358 if (mResource ==
nullptr && _resource !=
nullptr)
360 if (mItemGroup.empty())
363 while (iter_group.
next())
365 mItemGroup = iter_group.
current().name;
366 if (mItemName.empty() && !iter_group.
current().indexes.empty())
368 mItemName = iter_group.
current().indexes[0].name;
373 else if (mItemName.empty())
376 while (iter_group.
next())
378 if (mItemGroup == iter_group.
current().name)
380 if (!iter_group.
current().indexes.empty())
382 mItemName = iter_group.
current().indexes[0].name;
390 mResource = _resource;
391 if (!mResource || mItemGroup.empty() || mItemName.empty()) updateSelectIndex(
ITEM_NONE);
397 if (mItemGroup == _group)
401 if (!mResource || mItemGroup.empty() || mItemName.empty()) updateSelectIndex(
ITEM_NONE);
407 if (mItemName == _name)
411 if (!mResource || mItemGroup.empty() || mItemName.empty()) updateSelectIndex(
ITEM_NONE);
417 mResource = _resource;
420 if (!mResource || mItemGroup.empty() || mItemName.empty()) updateSelectIndex(
ITEM_NONE);
424 void ImageBox::frameAdvise(
bool _advise)
428 if ( ! mFrameAdvise )
439 mFrameAdvise =
false;
461 if (mIndexSelect != _index) updateSelectIndex(_index);
464 void ImageBox::_setUVSet(
const FloatRect& _rect)
473 if (_key ==
"ImageTexture")
477 else if (_key ==
"ImageCoord")
481 else if (_key ==
"ImageTile")
485 else if (_key ==
"ImageIndex")
489 else if (_key ==
"ImageResource")
493 else if (_key ==
"ImageGroup")
497 else if (_key ==
"ImageName")
511 return mItems.size();
#define MYGUI_ASSERT_RANGE_INSERT(index, size, owner)
#define MYGUI_ASSERT_RANGE(index, size, owner)
#define MYGUI_LOG(level, text)
static FloatRect convertTextureCoord(const IntCoord &_coord, const IntSize &_textureSize)
T::const_reference current()
static Gui & getInstance()
EventHandle_FrameEventDelegate eventFrameStart
Type * castType(bool _throw=true)
void setItemFrame(size_t _index, size_t _indexFrame, const IntCoord &_item)
IntSize getImageSize() const
void setItemFrameRate(size_t _index, float _rate)
void setImageInfo(const std::string &_texture, const IntCoord &_coord, const IntSize &_tile)
void insertItemFrame(size_t _index, size_t _indexFrame, const IntCoord &_item)
void shutdownOverride() override
void deleteAllItemFrames(size_t _index)
void setPropertyOverride(const std::string &_key, const std::string &_value) override
void resetItemSelect()
Reset item selection.
void setItemName(const std::string &_value)
void setItemSelect(size_t _index)
Select specified _index.
void setImageTile(const IntSize &_value)
bool setItemResource(const std::string &_name)
void setImageTexture(const std::string &_value)
void setImageIndex(size_t _index)
void setItemResourcePtr(ResourceImageSetPtr _resource)
void setItemResourceInfo(const ImageIndexInfo &_info)
ResourceImageSetPtr getItemResource() const
void setImageCoord(const IntCoord &_value)
void insertItem(size_t _index, const IntCoord &_item)
Insert an item into a list at a specified position.
void insertItemFrameDuplicate(size_t _index, size_t _indexFrame, size_t _indexSourceFrame)
void deleteItemFrame(size_t _index, size_t _indexFrame)
size_t getItemCount() const
Get number of items.
float getItemFrameRate(size_t _index) const
void addItemFrameDuplicate(size_t _index, size_t _indexSourceFrame)
void deleteAllItems()
Delete all items.
void addItemFrame(size_t _index, const IntCoord &_item)
void setItemGroup(const std::string &_value)
size_t getItemSelect() const
Get index of selected item (ITEM_NONE if none selected)
void setImageRect(const IntRect &_value)
void deleteItem(size_t _index)
Delete item at a specified position.
void addItem(const IntCoord &_item)
Add an item to the end of a list.
void setItem(size_t _index, const IntCoord &_item)
Replace an item at a specified position.
size_t getImageIndex() const
ImageIndexInfo getIndexInfo(const std::string &_group, const std::string &_index) const
EnumeratorGroupImage getEnumerator() const
IResource * getByName(const std::string &_name, bool _throw=true) const
static ResourceManager & getInstance()
ISubWidgetRect * getSubWidgetMain() const
const std::string & _getTextureName() const
void _setTextureName(const std::string &_texture)
const IntSize & getTextureSize(const std::string &_texture, bool _cache=true)
const size_t IMAGE_MAX_INDEX
types::TCoord< int > IntCoord
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
types::TRect< float > FloatRect
const std::string & texture
const std::vector< IntPoint > & frames
std::string print() const
void set(T const &_left, T const &_top, T const &_right, T const &_bottom)
std::string print() const
void set(T const &_width, T const &_height)