Skip to content

Type enum and getter for MenuComponent #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions MenuSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ void Menu::render(MenuComponentRenderer const& renderer) const {
renderer.render_menu(*this);
}

MenuComponent::Type Menu::type() const {
return MenuComponent::TypeMenu;
}



// *********************************************************
// BackMenuItem
// *********************************************************
Expand All @@ -224,6 +230,10 @@ void BackMenuItem::render(MenuComponentRenderer const& renderer) const {
renderer.render_back_menu_item(*this);
}

MenuComponent::Type BackMenuItem::type() const {
return MenuComponent::TypeBackMenuItem;
}

// *********************************************************
// MenuItem
// *********************************************************
Expand Down Expand Up @@ -253,6 +263,10 @@ bool MenuItem::prev(bool loop) {
return false;
}

MenuComponent::Type MenuItem::type() const {
return MenuComponent::TypeMenuItem;
}

// *********************************************************
// NumericMenuItem
// *********************************************************
Expand Down Expand Up @@ -325,6 +339,15 @@ void NumericMenuItem::set_max_value(float value) {
_max_value = value;
}

float NumericMenuItem::get_increment() const {
return _increment;
}

void NumericMenuItem::set_increment(float increment) {
_increment = increment;
}


bool NumericMenuItem::next(bool loop) {
_value += _increment;
if (_value > _max_value) {
Expand All @@ -347,6 +370,10 @@ bool NumericMenuItem::prev(bool loop) {
return true;
}

MenuComponent::Type NumericMenuItem::type() const {
return MenuComponent::TypeNumericMenuItem;
}

// *********************************************************
// MenuSystem
// *********************************************************
Expand Down
13 changes: 13 additions & 0 deletions MenuSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ class MenuComponent {
//! selected.
void set_select_function(SelectFnPtr select_fn);

enum Type { TypeMenu, TypeMenuItem, TypeNumericMenuItem, TypeBackMenuItem };
//! \brief Returns the type of this item.
//!
//! Subclasses should reimplement this to return the correct type.
virtual Type type() const = 0;

protected:
//! \brief Processes the next action
//!
Expand Down Expand Up @@ -196,6 +202,7 @@ class MenuItem : public MenuComponent {

//! \copydoc MenuComponent::render
virtual void render(MenuComponentRenderer const& renderer) const;
virtual Type type() const;

protected:
//! \copydoc MenuComponent::next
Expand Down Expand Up @@ -226,6 +233,7 @@ class BackMenuItem : public MenuItem {

virtual void render(MenuComponentRenderer const& renderer) const;

virtual Type type() const;
protected:
virtual Menu* select();

Expand Down Expand Up @@ -269,15 +277,19 @@ class NumericMenuItem : public MenuItem {
float get_value() const;
float get_min_value() const;
float get_max_value() const;
float get_increment() const;

void set_value(float value);
void set_min_value(float value);
void set_max_value(float value);

void set_increment(float increment);

String get_formatted_value() const;

virtual void render(MenuComponentRenderer const& renderer) const;

virtual Type type() const;
protected:
virtual bool next(bool loop=false);
virtual bool prev(bool loop=false);
Expand Down Expand Up @@ -322,6 +334,7 @@ class Menu : public MenuComponent {
//! \copydoc MenuComponent::render
void render(MenuComponentRenderer const& renderer) const;

virtual Type type() const;
protected:
void set_parent(Menu* p_parent);
Menu const* get_parent() const;
Expand Down