Skip to content

Commit

Permalink
Added an action on a group being opened.
Browse files Browse the repository at this point in the history
  • Loading branch information
acaudwell committed Aug 15, 2012
1 parent 855f2c2 commit 24b7944
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ui/action.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef UI_ACTION_H
#define UI_ACTION_H

class UIElement;

class UIAction {
public:
UIAction() {};
Expand All @@ -9,4 +11,11 @@ class UIAction {
virtual void idle() {};
};

class UIElementAction : public UIAction {
protected:
UIElement* element;
public:
UIElementAction(UIElement* element) : element(element) {};
};

#endif
30 changes: 30 additions & 0 deletions ui/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ UIGroup::UIGroup(const std::string& groupname, bool minimized, bool resizable)

animation = 0.0f;
speed = 2.5f;

open_action = 0;
}

UIGroup::~UIGroup() {
Expand All @@ -39,6 +41,26 @@ void UIGroup::setTitle(const std::string& text) {
bar->setText(text);
}

void UIGroup::minimize() {
if(minimized) return;

minimized = true;
animation = 1.0f;

old_group_rect = rect;
old_label_rect = bar->rect;
}

void UIGroup::maximize() {
if(!minimized) return;

minimized = false;
animation = 1.0f;

old_group_rect = rect;
old_label_rect = bar->rect;
}

void UIGroup::toggle() {
if(!minimizable) return;

Expand All @@ -47,6 +69,14 @@ void UIGroup::toggle() {

old_group_rect = rect;
old_label_rect = bar->rect;

if(!minimized && open_action != 0) {
open_action->perform();
}
}

void UIGroup::setOpenAction(UIAction* action) {
open_action = action;
}

bool UIGroup::elementsByType(std::list<UIElement*>& found, int type) {
Expand Down
6 changes: 5 additions & 1 deletion ui/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UIGroup : public UIElement {

protected:
UILayout* layout;

UIAction* open_action;
float animation;
float speed;

Expand All @@ -36,13 +36,17 @@ class UIGroup : public UIElement {
bool elementsByType(std::list<UIElement*>& found, int type);
void elementsAt(const vec2& pos, std::list<UIElement*>& elements_found);

void setOpenAction(UIAction* action);

int getType() const { return UI_GROUP; };

UILayout* getLayout() { return layout; };

void setTitle(const std::string& text);

virtual void toggle();
virtual void minimize();
virtual void maximize();

void update(float dt);
void updatePos(const vec2& pos);
Expand Down

0 comments on commit 24b7944

Please sign in to comment.