X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FMenu.h;h=decd99dac3bc423d23ac1717a8020a0ddc9d1764;hb=2ef82e057748751f795c60dcf826a001516b5ca0;hp=f35a2bed2ce370cc8d19d8717a1e4de17eb1b6d7;hpb=e462583cabc752b8f03b423e98e93bca5f5045d8;p=l2e.git diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index f35a2be..decd99d 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -14,7 +14,6 @@ #include "../geometry/Point.h" #include "../geometry/Vector.h" -#include #include #include @@ -29,7 +28,6 @@ class Menu { public: Menu(); Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap = 0, int cols = 1, int colGap = 0); - Menu(const Menu &); public: int Width() const; @@ -119,22 +117,6 @@ Menu::Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, } -template -Menu::Menu(const Menu &other) -: font(other.font) -, disabledFont(other.disabledFont) -, cursor(other.cursor) -, entries(other.entries) -, charsPerEntry(other.charsPerEntry) -, rows(other.rows) -, rowGap(other.rowGap) -, cols(other.cols) -, colGap(other.colGap) -, selected(other.selected) -, topRow(other.topRow) { - std::cout << "copied Menu" << std::endl; -} - template int Menu::Width() const { @@ -169,11 +151,10 @@ void Menu::PreviousRow() { template void Menu::SelectIndex(int index) { - if (index < 0 || int(entries.size()) < index) return; - std::cout << "selecting index " << index << std::endl; + if (index < 0 || int(entries.size()) <= index) return; selected = index; - if (GetRow(selected) - rows > topRow) { - topRow = GetRow(selected) - rows; + if (topRow <= GetRow(selected) - rows) { + topRow = GetRow(selected) - rows + 1; } else if (GetRow(selected) < topRow) { topRow = GetRow(selected); } @@ -183,9 +164,9 @@ void Menu::SelectIndex(int index) { template void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { int start(topRow * cols); - int slots((topRow + rows) * cols); + int slots(rows * cols); int items(entries.size() - start); - int end(items < slots ? items : slots); + int end(start + (items < slots ? items : slots)); for (int i(0), count(end - start); i < count; ++i) { geometry::Vector offset( (i % cols) * (ColWidth() + colGap), @@ -198,7 +179,7 @@ void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { } geometry::Vector cursorOffset( (selected % cols) * (ColWidth() + colGap) - cursor->Width(), - (selected / cols) * RowHeight()); + ((selected - start) / cols) * RowHeight()); cursor->Draw(dest, position + cursorOffset); }