From 8a155673b8e5f9acfd68f29d3aaae97bc665014a Mon Sep 17 00:00:00 2001
From: Tamir Atias <engine.games@gmail.com>
Date: Tue, 10 Jan 2012 06:35:23 +0200
Subject: [PATCH] [Fix] Forgot to add ButtonGroup.h and ButtonGroup.cpp.

---
 src/libUnuk/ButtonGroup.cpp | 101 ++++++++++++++++++++++++++++++++++++
 src/libUnuk/ButtonGroup.h   |  35 +++++++++++++
 2 files changed, 136 insertions(+)
 create mode 100644 src/libUnuk/ButtonGroup.cpp
 create mode 100644 src/libUnuk/ButtonGroup.h

diff --git a/src/libUnuk/ButtonGroup.cpp b/src/libUnuk/ButtonGroup.cpp
new file mode 100644
index 0000000..e5ff3a6
--- /dev/null
+++ b/src/libUnuk/ButtonGroup.cpp
@@ -0,0 +1,101 @@
+#include "ButtonGroup.h"
+
+ButtonGroup::ButtonGroup(void) {
+  _selectedButton = -1;
+}
+
+ButtonGroup::~ButtonGroup(void) {
+  for(std::list<Button*>::iterator i = _buttons.begin(); i != _buttons.end(); ++i) {
+    Button* btn = (*i);
+    delete btn;
+  }
+}
+
+void ButtonGroup::CheckMouseOverDummy(void) {
+  for(std::list<Button*>::iterator i = _buttons.begin(); i != _buttons.end(); ++i) {
+    (*i)->CheckMouseOver();
+  }
+}
+
+int ButtonGroup::CheckMouseOver(void) {
+  int buttonIndex = 0;
+  for(std::list<Button*>::iterator i = _buttons.begin(); i != _buttons.end(); ++i) {
+    if((*i)->CheckMouseOver()) {
+      return buttonIndex;
+    }
+    buttonIndex++;
+  }
+  return -1;
+}
+
+void ButtonGroup::RenderLiteral(void) {
+  for(std::list<Button*>::iterator i = _buttons.begin(); i != _buttons.end(); ++i) {
+    (*i)->RenderLiteral();
+  }
+}
+
+void ButtonGroup::AddButton(Button* button) {
+  _buttons.push_back(button);
+}
+
+void ButtonGroup::RemoveButton(int index) {
+  int buttonsIndex = 0;
+  for(std::list<Button*>::iterator i = _buttons.begin(); i != _buttons.end(); ++i) {
+    if(buttonsIndex == index) {
+      _buttons.erase(i);
+      break;
+    }
+    buttonsIndex++;
+  }
+}
+
+void ButtonGroup::SelectNext(void) {
+  if(_selectedButton == -1) {
+    HighlightNewSelection(0);
+  } else {
+    HighlightNewSelection(_selectedButton + 1);
+  }
+}
+
+void ButtonGroup::SelectPrevious(void) {
+  if(_selectedButton == -1) {
+    HighlightNewSelection(0);
+  } else {
+    HighlightNewSelection(_selectedButton - 1);
+  }
+}
+
+void ButtonGroup::SetSelectedButton(int button) {
+  HighlightNewSelection(button);
+}
+
+void ButtonGroup::HighlightNewSelection(int newButton) {
+  if(_selectedButton != -1) {
+    // Turn of highlight for currently highlighted button
+    GetButton(_selectedButton)->SetHighlighted(false);
+  }
+
+  _selectedButton = newButton;
+
+  // If < 0 then up was pressed when first index was selected
+  // If > 0 then down was pressed when last index was selected
+  if(_selectedButton < 0) {
+    _selectedButton = _buttons.size() - 1;
+  } else if(_selectedButton >= (int)_buttons.size()) {
+    _selectedButton = 0;
+  }
+
+  // Highlight new selection
+  GetButton(_selectedButton)->SetHighlighted(true);
+}
+
+Button* ButtonGroup::GetButton(int index) {
+  int buttonsIndex = 0;
+  for(std::list<Button*>::iterator i = _buttons.begin(); i != _buttons.end(); ++i) {
+    if(buttonsIndex == index) {
+      return (*i);
+    }
+    buttonsIndex++;
+  }
+  return NULL;
+}
\ No newline at end of file
diff --git a/src/libUnuk/ButtonGroup.h b/src/libUnuk/ButtonGroup.h
new file mode 100644
index 0000000..faf1f1b
--- /dev/null
+++ b/src/libUnuk/ButtonGroup.h
@@ -0,0 +1,35 @@
+#ifndef _BUTTONGROUP_H_
+#define _BUTTONGROUP_H_
+#include <list>
+
+#include "Button.h"
+
+class ButtonGroup {
+public:
+  ButtonGroup(void);
+  ~ButtonGroup(void);
+
+  void  CheckMouseOverDummy(void);
+  int   CheckMouseOver(void);
+
+  void RenderLiteral(void);
+
+  void AddButton(Button* button);
+  void RemoveButton(int index);
+
+  void SelectNext(void);
+  void SelectPrevious(void);
+
+  int   GetSelectedButton(void)         { return _selectedButton; }
+  void  SetSelectedButton(int button);
+
+  Button* GetButton(int index);
+
+private:
+  void HighlightNewSelection(int newButton);
+
+  std::list<Button*> _buttons;
+  int _selectedButton;
+};
+
+#endif
\ No newline at end of file