[Fix] Forgot to add ButtonGroup.h and ButtonGroup.cpp.
This commit is contained in:
parent
3b54b1d28d
commit
8a155673b8
101
src/libUnuk/ButtonGroup.cpp
Normal file
101
src/libUnuk/ButtonGroup.cpp
Normal file
@ -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;
|
||||||
|
}
|
35
src/libUnuk/ButtonGroup.h
Normal file
35
src/libUnuk/ButtonGroup.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user