NCBI C++ ToolKit
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CAttribMenu Class Reference

Search Toolkit Book for CAttribMenu

class CAttribMenuItem More...

#include <gui/widgets/gl/attrib_menu.hpp>

+ Inheritance diagram for CAttribMenu:
+ Collaboration diagram for CAttribMenu:

Public Member Functions

 CAttribMenu ()
 
 CAttribMenu (const std::string &name, void *user_value=NULL)
 
 ~CAttribMenu ()
 CAttribMenu. More...
 
void DrawMenu ()
 
bool KeyPress (int key_code)
 
bool AddItem (CAttribMenuItem *a)
 Returns true on success (if name is unique in this menu) More...
 
CAttribMenuAddSubMenuUnique (const std::string &name, void *user_value=NULL)
 Convienance function to add a submenu to this menu. More...
 
CAttribMenuAddSubMenu (const std::string &name, void *user_value=NULL)
 Convienance funcions to add new menu elements or submenus. More...
 
CAttribFloatMenuItemAddFloat (const std::string &name, float *user_value=NULL, float initial_value=0.5f, float min_value=0.0f, float max_value=1.0f, float stepsize=0.01f)
 
CAttribIntMenuItemAddInt (const std::string &name, int *user_value=NULL, int initial_value=50, int min_value=0, int max_value=100, int stepsize=1)
 
CAttribStringsMenuItemAddStrings (const std::string &name, std::string *user_value=NULL)
 
CAttribFloatMenuItemAddFloatReadOnly (const std::string &name, float *user_value)
 Add entries to the menu which display the users value but do not update it. More...
 
CAttribIntMenuItemAddIntReadOnly (const std::string &name, int *user_value)
 
CAttribStringsMenuItemAddStringsReadOnly (const std::string &name, std::string *user_value)
 
std::vector< CAttribMenuItem * > GetValue () const
 Return a copy of the items in this menu. More...
 
CAttribMenuItemFindItem (const std::string &name)
 Find a menu item in the current menu (do not search recursively) More...
 
CAttribMenuFindMenu (const std::string &name)
 
CAttribFloatMenuItemFindFloat (const std::string &name)
 
CAttribIntMenuItemFindInt (const std::string &name)
 
CAttribStringsMenuItemFindStrings (const std::string &name)
 
bool RemoveItem (const std::string &name)
 Remove an item from the menu with the specified name. More...
 
bool RemoveMenuR (const std::string &name, void *user_value=NULL)
 Search the menu(s) recursively for menu 'name' with the specified user data 'user_value'. More...
 
void SetKeys (int key_up, int key_down, int increment, int decrement)
 Set keys for menu up/down and previous/next value. More...
 
void SetOpenCloseKeys (int open_key, int close_key)
 Opening and closing menu will always work with numpad +/-. More...
 
virtual std::string GetText () const
 Add a '>' to name of menu for simple indicator of submenu. More...
 
virtual std::string GetTextValue () const
 The value is the part of the menu after the name, so here it's " >". More...
 
bool IsOpen () const
 Menus are either open or closed, based on user navigation. More...
 
void SetBackgroundColor (const CVect4< float > &c)
 Set/get menu background color. More...
 
CVect4< float > GetBackgroundColor () const
 
virtual void Inc ()
 Increment value is specialized for each subclass. More...
 
virtual void SynchToUserValue ()
 Recursively calls each menu item to set its menu value to the current user value (if not NULL). More...
 
virtual EAttribType GetType () const
 Return the subtype. More...
 
- Public Member Functions inherited from CAttribMenuItem
 CAttribMenuItem ()
 
 CAttribMenuItem (const std::string &name)
 
virtual ~CAttribMenuItem ()
 
void SetName (const std::string &name)
 Get and set the menu item name. More...
 
std::string GetName () const
 
void SetColor (const CVect3< float > &c)
 Set/get the color of the menu name text. More...
 
CVect3< float > GetColor () const
 
void SetDataColor (const CVect3< float > &c)
 Set/get the color of the menu value text. More...
 
CVect3< float > GetDataColor () const
 
void SetFontType (CGlBitmapFont::EFont ft)
 Set/get the font type for the menu item. More...
 
CGlBitmapFont::EFont GetFontType () const
 
void SetReadOnly (bool b)
 Set/get readonly paramater that determines if value is updated or not. More...
 
bool GetReadOnly () const
 
CVect2< float > Draw (CVect2< float > pos)
 Draw the menu item at the specified position. More...
 
CVect2< float > GetTextDim () const
 Get width and height of the text for this menu item. More...
 
virtual void Dec ()
 Decrement value is specialized for each subclass (except the menu type) More...
 

Protected Member Functions

bool x_HandleKey (int key_code)
 respond to key value More...
 
void x_DrawMenu (CVect2< float > pos)
 Draw submenu (called by toplevel draw) More...
 
void x_UpdateReadOnly ()
 Set read-only menu values to their variable value. More...
 

Protected Attributes

std::vector< CAttribMenuItem * > m_Value
 array of menuitems for this menu More...
 
void * m_UserValue
 Pointer used Only to identify this menu (to look it up later, for example in the dtor of an object so that it can be deleted. More...
 
CVect4< float > m_BackgroundColor
 menu (background) color More...
 
size_t m_CurrentItem
 Current active (focused) item in this submenu. More...
 
bool m_IsOpen
 True if menu is open (displayed). More...
 
int m_KeyUp
 Up to previous menu item. More...
 
int m_KeyDown
 Down to next menu item. More...
 
int m_KeyInc
 Increment value of current menu item. More...
 
int m_KeyDec
 Decrement value of current menu item. More...
 
int m_OpenKey
 key for opening a menu More...
 
int m_CloseKey
 key for closing a menu More...
 
- Protected Attributes inherited from CAttribMenuItem
std::string m_Name
 Item name that appears on the menu item. More...
 
CVect3< float > m_Color
 Color of the name text. More...
 
CVect3< float > m_DataColor
 Color of the value text. More...
 
bool m_ReadOnly
 If true, item is displayed but not updated. More...
 
CGlBitmapFont::EFont m_FontType
 Font used for the menu. More...
 

Detailed Description

class CAttribMenuItem

This is the primary class for displaying attribute menus, adding items to menus and getting values from menus. A program wanting to use attribute menus will:

get an instance to a base menu will add items to that menu: Add[Int/Float/Strings/SubMenu]() will route key events to the menus KeyPress() function will draw the menu from their drawing update: DrawMenu()

If you share a menu instance across multiple windows, e.g. via the singleton 'CAttribMenuInstance' class, then be careful to delete menu items that are not longer needed in class destructors. Also if multiple instances of a view might be open, then create a separate submenu for each instance of the class, and delete those menu instances in the view destructors. This is most important if you are passing your variables (user values) to the menu.

Definition at line 445 of file attrib_menu.hpp.

Constructor & Destructor Documentation

◆ CAttribMenu() [1/2]

CAttribMenu::CAttribMenu ( )
inline

Definition at line 448 of file attrib_menu.hpp.

Referenced by AddSubMenu().

◆ CAttribMenu() [2/2]

CAttribMenu::CAttribMenu ( const std::string name,
void *  user_value = NULL 
)
inline

Definition at line 459 of file attrib_menu.hpp.

◆ ~CAttribMenu()

CAttribMenu::~CAttribMenu ( )

CAttribMenu.

Definition at line 288 of file attrib_menu.cpp.

References i, and m_Value.

Member Function Documentation

◆ AddFloat()

CAttribFloatMenuItem * CAttribMenu::AddFloat ( const std::string name,
float *  user_value = NULL,
float  initial_value = 0.5f,
float  min_value = 0.0f,
float  max_value = 1.0f,
float  stepsize = 0.01f 
)

◆ AddFloatReadOnly()

CAttribFloatMenuItem * CAttribMenu::AddFloatReadOnly ( const std::string name,
float *  user_value 
)

◆ AddInt()

CAttribIntMenuItem * CAttribMenu::AddInt ( const std::string name,
int user_value = NULL,
int  initial_value = 50,
int  min_value = 0,
int  max_value = 100,
int  stepsize = 1 
)

Definition at line 613 of file attrib_menu.cpp.

References AddItem(), i, min_value, and NULL.

Referenced by CHistogramGlyph::SetAxisRange().

◆ AddIntReadOnly()

CAttribIntMenuItem * CAttribMenu::AddIntReadOnly ( const std::string name,
int user_value 
)

◆ AddItem()

bool CAttribMenu::AddItem ( CAttribMenuItem a)

Returns true on success (if name is unique in this menu)

Definition at line 548 of file attrib_menu.cpp.

References a, FindItem(), m_Value, and NULL.

Referenced by AddFloat(), AddFloatReadOnly(), AddInt(), AddIntReadOnly(), AddStrings(), AddStringsReadOnly(), and AddSubMenu().

◆ AddStrings()

CAttribStringsMenuItem * CAttribMenu::AddStrings ( const std::string name,
std::string user_value = NULL 
)

Definition at line 634 of file attrib_menu.cpp.

References AddItem(), and NULL.

Referenced by CSeqGraphicPane::CSeqGraphicPane().

◆ AddStringsReadOnly()

CAttribStringsMenuItem * CAttribMenu::AddStringsReadOnly ( const std::string name,
std::string user_value 
)

◆ AddSubMenu()

CAttribMenu * CAttribMenu::AddSubMenu ( const std::string name,
void *  user_value = NULL 
)

Convienance funcions to add new menu elements or submenus.

Only one element with a given name can be added to the same menu, even if the variable (user_value) is different.

Definition at line 577 of file attrib_menu.cpp.

References AddItem(), CAttribMenu(), m_CloseKey, m_KeyDec, m_KeyDown, m_KeyInc, m_KeyUp, m_OpenKey, NULL, SetKeys(), and SetOpenCloseKeys().

Referenced by AddSubMenuUnique(), and CHistogramGlyph::SetAxisRange().

◆ AddSubMenuUnique()

CAttribMenu * CAttribMenu::AddSubMenuUnique ( const std::string name,
void *  user_value = NULL 
)

Convienance function to add a submenu to this menu.

If the menu name is not unique, a number will be added to the name to make it unique.

Definition at line 558 of file attrib_menu.cpp.

References AddSubMenu(), buf, FindItem(), n, NULL, and string.

Referenced by CPhyloTreePS::CPhyloTreePS(), CPhyTreeView::CPhyTreeView(), CSeqGraphicPane::CSeqGraphicPane(), CTreeCollisionModel2D::CTreeCollisionModel2D(), CTreeGraphicsModel::CTreeGraphicsModel(), and IPhyloTreeRender::IPhyloTreeRender().

◆ DrawMenu()

void CAttribMenu::DrawMenu ( )

Definition at line 299 of file attrib_menu.cpp.

References x_DrawMenu().

Referenced by CSeqGraphicPane::x_Render(), and CPhyloTreePane::x_Render().

◆ FindFloat()

CAttribFloatMenuItem * CAttribMenu::FindFloat ( const std::string name)

Definition at line 739 of file attrib_menu.cpp.

References FindItem(), and NULL.

◆ FindInt()

CAttribIntMenuItem * CAttribMenu::FindInt ( const std::string name)

Definition at line 729 of file attrib_menu.cpp.

References FindItem(), and NULL.

◆ FindItem()

CAttribMenuItem * CAttribMenu::FindItem ( const std::string name)

Find a menu item in the current menu (do not search recursively)

Definition at line 702 of file attrib_menu.cpp.

References i, m_Value, NULL, string, and NStr::ToLower().

Referenced by AddItem(), AddSubMenuUnique(), FindFloat(), FindInt(), FindMenu(), and FindStrings().

◆ FindMenu()

CAttribMenu * CAttribMenu::FindMenu ( const std::string name)

Definition at line 719 of file attrib_menu.cpp.

References FindItem(), and NULL.

Referenced by CHistogramGlyph::SetAxisRange().

◆ FindStrings()

CAttribStringsMenuItem * CAttribMenu::FindStrings ( const std::string name)

Definition at line 749 of file attrib_menu.cpp.

References FindItem(), and NULL.

◆ GetBackgroundColor()

CVect4<float> CAttribMenu::GetBackgroundColor ( ) const
inline

Definition at line 555 of file attrib_menu.hpp.

References m_BackgroundColor.

◆ GetText()

virtual std::string CAttribMenu::GetText ( void  ) const
inlinevirtual

Add a '>' to name of menu for simple indicator of submenu.

Reimplemented from CAttribMenuItem.

Definition at line 546 of file attrib_menu.hpp.

References CAttribMenuItem::m_Name.

◆ GetTextValue()

virtual std::string CAttribMenu::GetTextValue ( ) const
inlinevirtual

The value is the part of the menu after the name, so here it's " >".

Reimplemented from CAttribMenuItem.

Definition at line 548 of file attrib_menu.hpp.

◆ GetType()

virtual EAttribType CAttribMenu::GetType ( void  ) const
inlinevirtual

Return the subtype.

Implements CAttribMenuItem.

Definition at line 568 of file attrib_menu.hpp.

References AttribMenuType.

Referenced by x_DrawMenu().

◆ GetValue()

std::vector<CAttribMenuItem*> CAttribMenu::GetValue ( void  ) const
inline

Return a copy of the items in this menu.

Definition at line 516 of file attrib_menu.hpp.

References m_Value.

◆ Inc()

void CAttribMenu::Inc ( )
virtual

Increment value is specialized for each subclass.

Reimplemented from CAttribMenuItem.

Definition at line 828 of file attrib_menu.cpp.

References IsOpen(), and m_IsOpen.

◆ IsOpen()

bool CAttribMenu::IsOpen ( void  ) const
inline

Menus are either open or closed, based on user navigation.

Definition at line 551 of file attrib_menu.hpp.

References m_IsOpen.

Referenced by Inc(), KeyPress(), x_DrawMenu(), and x_HandleKey().

◆ KeyPress()

bool CAttribMenu::KeyPress ( int  key_code)

Definition at line 525 of file attrib_menu.cpp.

References AttribMenuType, IsOpen(), KeyPress(), m_CurrentItem, m_IsOpen, m_Value, NULL, and x_HandleKey().

Referenced by KeyPress().

◆ RemoveItem()

bool CAttribMenu::RemoveItem ( const std::string name)

Remove an item from the menu with the specified name.

Definition at line 759 of file attrib_menu.cpp.

References m_Value, string, and NStr::ToLower().

◆ RemoveMenuR()

bool CAttribMenu::RemoveMenuR ( const std::string name,
void *  user_value = NULL 
)

Search the menu(s) recursively for menu 'name' with the specified user data 'user_value'.

If 'user_value' is NULL, delete first 'name' found. If user_value is not NULL, name only has to match the root of the menu name (to support AddSubMenuUnique)

Definition at line 780 of file attrib_menu.cpp.

References AttribMenuType, CAttribMenuItem::GetName(), m_UserValue, m_Value, NULL, RemoveMenuR(), string, and NStr::ToLower().

Referenced by RemoveMenuR(), CPhyloTreePS::~CPhyloTreePS(), CPhyTreeView::~CPhyTreeView(), CSeqGraphicPane::~CSeqGraphicPane(), CTreeCollisionModel2D::~CTreeCollisionModel2D(), CTreeGraphicsModel::~CTreeGraphicsModel(), and IPhyloTreeRender::~IPhyloTreeRender().

◆ SetBackgroundColor()

void CAttribMenu::SetBackgroundColor ( const CVect4< float > &  c)
inline

Set/get menu background color.

Definition at line 554 of file attrib_menu.hpp.

References m_BackgroundColor.

◆ SetKeys()

void CAttribMenu::SetKeys ( int  key_up,
int  key_down,
int  increment,
int  decrement 
)

Set keys for menu up/down and previous/next value.

Default is numpad arrow keys with capslock but you may want letters since laptops don't always have numpad.

Definition at line 437 of file attrib_menu.cpp.

References AttribMenuType, m_KeyDec, m_KeyDown, m_KeyInc, m_KeyUp, m_Value, and SetKeys().

Referenced by AddSubMenu(), and SetKeys().

◆ SetOpenCloseKeys()

void CAttribMenu::SetOpenCloseKeys ( int  open_key,
int  close_key 
)

Opening and closing menu will always work with numpad +/-.

By default char '+', '-' also work but you can use different chars (laptops don't support numpad)

Definition at line 455 of file attrib_menu.cpp.

References AttribMenuType, m_CloseKey, m_OpenKey, m_Value, and SetOpenCloseKeys().

Referenced by AddSubMenu(), CSeqGraphicPane::CSeqGraphicPane(), and SetOpenCloseKeys().

◆ SynchToUserValue()

void CAttribMenu::SynchToUserValue ( )
virtual

Recursively calls each menu item to set its menu value to the current user value (if not NULL).

Implements CAttribMenuItem.

Definition at line 834 of file attrib_menu.cpp.

References m_Value.

Referenced by CPhyloCircularCladogram::x_Layout(), and CPhyloForce::x_Layout().

◆ x_DrawMenu()

void CAttribMenu::x_DrawMenu ( CVect2< float >  pos)
protected

◆ x_HandleKey()

bool CAttribMenu::x_HandleKey ( int  key_code)
protected

respond to key value

Definition at line 471 of file attrib_menu.cpp.

References AttribMenuType, IsOpen(), m_CloseKey, m_CurrentItem, m_IsOpen, m_KeyDec, m_KeyDown, m_KeyInc, m_KeyUp, m_OpenKey, and m_Value.

Referenced by KeyPress().

◆ x_UpdateReadOnly()

void CAttribMenu::x_UpdateReadOnly ( )
protected

Set read-only menu values to their variable value.

Definition at line 843 of file attrib_menu.cpp.

References AttribMenuType, m_Value, and x_UpdateReadOnly().

Referenced by x_DrawMenu(), and x_UpdateReadOnly().

Member Data Documentation

◆ m_BackgroundColor

CVect4<float> CAttribMenu::m_BackgroundColor
protected

menu (background) color

Definition at line 587 of file attrib_menu.hpp.

Referenced by GetBackgroundColor(), SetBackgroundColor(), and x_DrawMenu().

◆ m_CloseKey

int CAttribMenu::m_CloseKey
protected

key for closing a menu

Definition at line 605 of file attrib_menu.hpp.

Referenced by AddSubMenu(), SetOpenCloseKeys(), and x_HandleKey().

◆ m_CurrentItem

size_t CAttribMenu::m_CurrentItem
protected

Current active (focused) item in this submenu.

Definition at line 589 of file attrib_menu.hpp.

Referenced by KeyPress(), x_DrawMenu(), and x_HandleKey().

◆ m_IsOpen

bool CAttribMenu::m_IsOpen
protected

True if menu is open (displayed).

Definition at line 591 of file attrib_menu.hpp.

Referenced by Inc(), IsOpen(), KeyPress(), x_DrawMenu(), and x_HandleKey().

◆ m_KeyDec

int CAttribMenu::m_KeyDec
protected

Decrement value of current menu item.

Definition at line 600 of file attrib_menu.hpp.

Referenced by AddSubMenu(), SetKeys(), and x_HandleKey().

◆ m_KeyDown

int CAttribMenu::m_KeyDown
protected

Down to next menu item.

Definition at line 596 of file attrib_menu.hpp.

Referenced by AddSubMenu(), SetKeys(), and x_HandleKey().

◆ m_KeyInc

int CAttribMenu::m_KeyInc
protected

Increment value of current menu item.

Definition at line 598 of file attrib_menu.hpp.

Referenced by AddSubMenu(), SetKeys(), and x_HandleKey().

◆ m_KeyUp

int CAttribMenu::m_KeyUp
protected

Up to previous menu item.

Definition at line 594 of file attrib_menu.hpp.

Referenced by AddSubMenu(), SetKeys(), and x_HandleKey().

◆ m_OpenKey

int CAttribMenu::m_OpenKey
protected

key for opening a menu

Definition at line 603 of file attrib_menu.hpp.

Referenced by AddSubMenu(), SetOpenCloseKeys(), and x_HandleKey().

◆ m_UserValue

void* CAttribMenu::m_UserValue
protected

Pointer used Only to identify this menu (to look it up later, for example in the dtor of an object so that it can be deleted.

Definition at line 584 of file attrib_menu.hpp.

Referenced by RemoveMenuR().

◆ m_Value

std::vector<CAttribMenuItem*> CAttribMenu::m_Value
protected

The documentation for this class was generated from the following files:
Modified on Sat Feb 24 07:46:10 2024 by modify_doxy.py rev. 669887