00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021
00022
00024
00025
00027
00028 #ifndef MENULISTFIELD_H
00029 #define MENULISTFIELD_H
00030
00031 #include "Bitmapfont.hpp"
00032 #include <vector>
00033 #include <string>
00034 #include <cstdio>
00035 #include <SFML/Graphics.hpp>
00036
00037 static const unsigned MENU_DISPLAY_COUNT = 13;
00038
00040
00044 class CMenuListField
00045 {
00046 public:
00047
00048 CMenuListField();
00049 ~CMenuListField();
00050
00051
00052 void Init(CBitmapFont* BitMapFont, std::string ListSelectionName);
00053
00054
00055 void AddEntry(std::string Entry) { m_Entrys.push_back(Entry); }
00056
00057
00058 void SetPosition(float X, float Y)
00059 {
00060 m_X = X;
00061 m_Y = Y;
00062 }
00063
00064
00065 float GetXPosition() const { return m_X; }
00066 float GetYPosition() const { return m_Y; }
00067
00068
00069
00070 void SetSize(float SizeX, float SizeY)
00071 {
00072 m_SizeX = SizeX;
00073 m_SizeY = SizeY;
00074 }
00075
00076
00077 float GetXSize() { return m_SizeX; }
00078 float GetYSize() { return m_SizeY; }
00079
00080
00081 void SelectEntryWithScroll(std::size_t Index)
00082 {
00083 if(m_Scroll + Index >= m_Entrys.size())
00084 {
00085 return;
00086 }
00087
00088 m_CurSel = m_Scroll + Index;
00089 }
00090
00091
00092 void SelectEntryWithoutScroll(std::size_t Index)
00093 {
00094 if(Index >= m_Entrys.size())
00095 {
00096 return;
00097 }
00098
00099 m_CurSel = Index;
00100 }
00101
00102
00103 void Scroll(int Scroll)
00104 {
00105 if(m_Entrys.size() < MENU_DISPLAY_COUNT)
00106 {
00107 return;
00108 }
00109
00110 m_Scroll += Scroll;
00111
00112 SetScroll(m_Scroll);
00113 }
00114
00115
00116 void SetScroll(int Scroll)
00117 {
00118 if(m_Entrys.size() < MENU_DISPLAY_COUNT)
00119 {
00120 return;
00121 }
00122
00123 m_Scroll = Scroll;
00124
00125 if(m_Scroll < 0)
00126 {
00127 m_Scroll = 0;
00128 }
00129
00130 if(m_Scroll + MENU_DISPLAY_COUNT + 1 > m_Entrys.size())
00131 {
00132 m_Scroll = m_Entrys.size() - MENU_DISPLAY_COUNT - 1;
00133 }
00134 }
00135
00136
00137 bool CanScrollUp() const
00138 {
00139 return (m_Scroll > 0);
00140 }
00141
00142
00143 bool CanScrollDown() const
00144 {
00145 if(m_Scroll + MENU_DISPLAY_COUNT + 1 >= m_Entrys.size() || m_Entrys.size() < MENU_DISPLAY_COUNT)
00146 {
00147 return false;
00148 }
00149
00150 return true;
00151 }
00152
00153
00154 std::string GetCurEntry() const { return m_Entrys[m_CurSel]; }
00155
00156
00157 std::string GetEntry(std::size_t Index) const
00158 {
00159 if(Index >= m_Entrys.size())
00160 {
00161 return "";
00162 }
00163
00164 return m_Entrys[Index];
00165 }
00166
00167
00168
00169 int GetCurSelectIndex() const { return m_CurSel; }
00170
00171
00172 void Draw();
00173
00174
00175
00176 void Clear()
00177 {
00178 m_Entrys.clear();
00179 m_CurSel = 0;
00180 m_Scroll = 0;
00181 }
00182
00183
00184 std::size_t GetEntryCount() const { return m_Entrys.size(); }
00185 private:
00186 sf::Sprite m_ListSelectionSprite;
00187
00188 CBitmapFont* m_BitMapFont;
00189
00190 std::vector<std::string> m_Entrys;
00191 std::size_t m_CurSel;
00192 int m_Scroll;
00193
00194 float m_X;
00195 float m_Y;
00196
00197 float m_SizeX;
00198 float m_SizeY;
00199 };
00200 #endif
00201