2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* ObjectLists.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2014-07-15 10:14:49 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../gui/CIntObject.h"
|
|
|
|
|
2023-01-18 17:32:57 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
2023-01-17 22:01:35 +02:00
|
|
|
class Rect;
|
2023-01-18 17:32:57 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2014-07-15 10:14:49 +03:00
|
|
|
class CAnimImage;
|
|
|
|
class CSlider;
|
|
|
|
class CLabel;
|
|
|
|
|
|
|
|
/// Used as base for Tabs and List classes
|
|
|
|
class CObjectList : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
2023-04-17 23:11:16 +02:00
|
|
|
using CreateFunc = std::function<std::shared_ptr<CIntObject>(size_t)>;
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
CreateFunc createObject;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
//Internal methods for safe creation of items (Children capturing and activation/deactivation if needed)
|
2018-04-07 13:34:11 +02:00
|
|
|
void deleteItem(std::shared_ptr<CIntObject> item);
|
|
|
|
std::shared_ptr<CIntObject> createItem(size_t index);
|
2014-07-15 10:14:49 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
CObjectList(CreateFunc create);
|
2014-07-15 10:14:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Window element with multiple tabs
|
|
|
|
class CTabbedInt : public CObjectList
|
|
|
|
{
|
|
|
|
private:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> activeTab;
|
2014-07-15 10:14:49 +03:00
|
|
|
size_t activeID;
|
|
|
|
|
|
|
|
public:
|
|
|
|
//CreateFunc, DestroyFunc - see CObjectList
|
|
|
|
//Pos - position of object, all tabs will be moved to this position
|
|
|
|
//ActiveID - ID of initially active tab
|
2018-04-07 13:34:11 +02:00
|
|
|
CTabbedInt(CreateFunc create, Point position=Point(), size_t ActiveID=0);
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
void setActive(size_t which);
|
2021-01-17 18:16:34 +02:00
|
|
|
size_t getActive() const;
|
2014-07-15 10:14:49 +03:00
|
|
|
//recreate active tab
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
//return currently active item
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> getItem();
|
2014-07-15 10:14:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// List of IntObjects with optional slider
|
|
|
|
class CListBox : public CObjectList
|
|
|
|
{
|
|
|
|
private:
|
2018-04-07 13:34:11 +02:00
|
|
|
std::list<std::shared_ptr<CIntObject>> items;
|
2014-07-15 10:14:49 +03:00
|
|
|
size_t first;
|
|
|
|
size_t totalSize;
|
|
|
|
|
|
|
|
Point itemOffset;
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CSlider> slider;
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
void updatePositions();
|
|
|
|
public:
|
|
|
|
//CreateFunc, DestroyFunc - see CObjectList
|
|
|
|
//Pos - position of first item
|
|
|
|
//ItemOffset - distance between items in the list
|
|
|
|
//VisibleSize - maximal number of displayable at once items
|
|
|
|
//TotalSize
|
2024-06-24 03:23:26 +02:00
|
|
|
//Slider - slider style, bit field: 1 = present(disabled), 2=horizontal(vertical), 4=blue(brown)
|
2014-07-15 10:14:49 +03:00
|
|
|
//SliderPos - position of slider, if present
|
2018-04-07 13:34:11 +02:00
|
|
|
CListBox(CreateFunc create, Point Pos, Point ItemOffset, size_t VisibleSize,
|
2014-07-15 10:14:49 +03:00
|
|
|
size_t TotalSize, size_t InitialPos=0, int Slider=0, Rect SliderPos=Rect() );
|
|
|
|
|
|
|
|
//recreate all visible items
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
//change or get total amount of items in the list
|
|
|
|
void resize(size_t newSize);
|
|
|
|
size_t size();
|
|
|
|
|
|
|
|
//return item with index which or null if not present
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<CIntObject> getItem(size_t which);
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
//return currently active items
|
2018-04-07 13:34:11 +02:00
|
|
|
const std::list<std::shared_ptr<CIntObject>> & getItems();
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
//get index of this item. -1 if not found
|
2018-04-07 13:34:11 +02:00
|
|
|
size_t getIndexOf(std::shared_ptr<CIntObject> item);
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
//scroll list to make item which visible
|
2023-07-17 18:42:55 +02:00
|
|
|
virtual void scrollTo(size_t which);
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
//scroll list to specified position
|
2023-07-17 18:42:55 +02:00
|
|
|
virtual void moveToPos(size_t which);
|
|
|
|
virtual void moveToNext();
|
|
|
|
virtual void moveToPrev();
|
2014-07-15 10:14:49 +03:00
|
|
|
|
|
|
|
size_t getPos();
|
|
|
|
};
|
2023-07-17 18:42:55 +02:00
|
|
|
|
|
|
|
class CListBoxWithCallback : public CListBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using MovedPosCallback = std::function<void(size_t)>;
|
|
|
|
|
|
|
|
CListBoxWithCallback(MovedPosCallback callback, CreateFunc create, Point pos, Point itemOffset, size_t visibleSize,
|
|
|
|
size_t totalSize, size_t initialPos = 0, int slider = 0, Rect sliderPos = Rect());
|
|
|
|
void scrollTo(size_t pos) override;
|
|
|
|
void moveToPos(size_t pos) override;
|
|
|
|
void moveToNext() override;
|
|
|
|
void moveToPrev() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MovedPosCallback movedPosCallback;
|
|
|
|
};
|