IMS2  Pre-Alpha
An Orbiter add-on to allow on-runtime construction of spacecraft from predefined modules
GUI_ListBox Class Reference

A box diplaying a scrollable list of text elements. Can be set up as just a list without selection, a select box or a multi-select box. More...

Inheritance diagram for GUI_ListBox:
GUI_BaseElement

Public Member Functions

 GUI_ListBox (RECT _mRect, int _id, GUI_ElementStyle *_style, GUI_ElementStyle *_scrollbarstyle=NULL, bool _selectBox=false, bool _noSelect=false)
 
void AddElement (string element, bool hilight=false)
 Adds a new text element to the list. More...
 
int GetSelected ()
 
std::string GetSelectedText ()
 
void clear ()
 Deletes all items in the list.
 
void SetSelected (int _selected)
 Sets a new (or additional) selected element. More...
 
void Draw (SURFHANDLE surf, RECT &drawablerect, int xoffset=0, int yoffset=0)
 Draws the element and its children to a SURFHANDLE. More...
 
void SetListJustification (GUI_TEXT_POS tpos)
 Sets the justification of the text inside the list. More...
 
int NumEntries ()
 
bool IsHighlight (UINT index)
 Used to check whether an element is selected in multi-select boxes. More...
 
- Public Member Functions inherited from GUI_BaseElement
 GUI_BaseElement (RECT _rect, int _id, GUI_ElementStyle *_style)
 
virtual bool Update ()
 Checks if this element or any of its children need to be redrawn. More...
 
int ProcessMouse (GUI_MOUSE_EVENT _event, int _x, int _y)
 Checks if the element or any of its children have been clicked. More...
 
virtual void AddChild (GUI_BaseElement *child)
 Adds a child to this element. More...
 
void GetRect (RECT &mRect)
 Copies the elements rect to the passed reference. More...
 
GUI_ElementStyleGetStyle ()
 
int GetWidth ()
 
int GetHeight ()
 
int GetId ()
 
GUI_ELEMENT_TYPE GetType ()
 
virtual void SetVisible (bool _visible)
 Sets if the elements and its children are drawn or not. More...
 
bool GetVisible ()
 
virtual void SetFixed (bool fixed)
 
bool GetFixed ()
 
virtual void SetNoBlit (bool noblit)
 
bool GetNoBlit ()
 
SURFHANDLE GetSurface ()
 
void AddPlugin (GUIplugin *plugin)
 Adds a GUIplugin as a child of this element. More...
 
void RemovePlugin (GUIplugin *plugin)
 Unplugs a plugin from this element. More...
 

Static Public Member Functions

static int GetNeededListBoxHeight (int numlines, GUI_STYLE styleid)
 

Private Member Functions

bool ProcessMe (GUI_MOUSE_EVENT _event, int _x, int _y)
 Processes events for this element. More...
 
void createListBox (GUI_ElementStyle *scrollbarstyle)
 Draws the ListBox and its scrollbar to its source surface. More...
 

Private Attributes

int nLines
 Stores the number of lines The listbox can display without scrolling.
 
int selected
 Stores the primary selected element (in a multi-select box, the last item to be selected).
 
int lineSpace
 The spacing between the lines of the ListBox, in pixel.
 
int scrlBarWidth
 THe width of the scrollbar in pixel.
 
int scrlBarHeight
 The height of the scrollbar in pixel.
 
vector< std::string > entries
 List of the elements in this ListBox.
 
bool selectBox
 Stores whether this is a multi-select box.
 
bool noSelect
 Stores whether elements of this ListBox can be selected at all.
 
GUI_ScrollBarscrollbar
 Pointer to the ListBox's scrollbar element.
 
vector< UINT > hilights
 List of indices of all selected items in a multi-select box.
 
GUI_TEXT_POS listJustification
 Stores the justification of the list text.
 

Additional Inherited Members

- Protected Member Functions inherited from GUI_BaseElement
virtual void DrawChildren (SURFHANDLE _tgt, RECT &drawablerect, int xoffset=0, int yoffset=0)
 Draws all direct children of this element, and tells them to draw theirs. More...
 
virtual void DrawMe (SURFHANDLE _tgt, int xoffset, int yoffset, RECT &drawablerect)
 Draws this element. More...
 
virtual int ProcessChildren (GUI_MOUSE_EVENT _event, int _x, int _y)
 Forwards event to its children. More...
 
virtual bool updateMe ()
 used for checking whether this element needs a redraw although it didn't have any user input More...
 
virtual bool updateChildren ()
 checks if any of the children need a redraw More...
 
void calculateBlitData (int xoffset, int yoffset, RECT &drawablerect, BLITDATA &OUT_blitdata)
 Calculates the positional and dimensional data needed for blitting, both for source as well as target surface. More...
 
void calculateMyDrawableRect (RECT &drawablerect_parent, int xoffset, int yoffset, RECT &OUT_mydrawablerect)
 calculates the real drawable rect of this element considering the drawable rect of the parent. More...
 
- Protected Attributes inherited from GUI_BaseElement
GUI_ELEMENT_TYPE type
 The type of this element.
 
RECT rect
 Rect the element should draw on, relative to parent.
 
int width
 The width of the element.
 
int height
 The height of the element.
 
int id
 The locally unique identifier of the element.
 
SURFHANDLE src = NULL
 Source surface to draw the element on. When the element is drawn on the panel, it will be blitted from this surface.
 
bool noBlitting = false
 Some elements might not have to blit themselves because they are static part of the background. This is not the same as !visible, as the element still processes events and still draws children, it just doesn't draw itself.
 
vector< GUI_BaseElement * > children
 List containing all direct children of this element.
 
vector< GUIplugin * > plugins
 List containing all GUIplugins currently pluged into this element.
 
GUI_fontfont
 The font used by this element.
 
GUI_ElementStylestyle
 The style used by this element.
 
bool visible
 Whether the element is visible or not (if false, element and any of its children will neither draw nor process events)
 
bool isfixed = false
 Whether the element retains a fixed position in a scrolling frame.
 

Detailed Description

A box diplaying a scrollable list of text elements. Can be set up as just a list without selection, a select box or a multi-select box.

Constructor & Destructor Documentation

GUI_ListBox::GUI_ListBox ( RECT  _mRect,
int  _id,
GUI_ElementStyle _style,
GUI_ElementStyle _scrollbarstyle = NULL,
bool  _selectBox = false,
bool  _noSelect = false 
)
Parameters
_mRectParent-relative position and dimensions
_idIdentifier of the element, locally unique to the containing GUIentity
_styleThe style to render the element in
_scrollbarstyleAlternate style to render the scrollbar
_selectBoxPass true to make this a multi-select box
_noSelectPass true to disable selection by the user

Member Function Documentation

void GUI_ListBox::AddElement ( string  element,
bool  hilight = false 
)

Adds a new text element to the list.

Parameters
elementThe text of the item to be added to the list
hilightPass true to immediately mark the new element as selected
void GUI_ListBox::createListBox ( GUI_ElementStyle scrollbarstyle)
private

Draws the ListBox and its scrollbar to its source surface.

Parameters
scrollbarstyleThe style in which the scrollbar should be drawn
void GUI_ListBox::Draw ( SURFHANDLE  _tgt,
RECT &  drawablerect,
int  xoffset = 0,
int  yoffset = 0 
)
virtual

Draws the element and its children to a SURFHANDLE.

Parameters
_tgtThe SURFHANDLE to draw to
drawablerectThe drawable rect of the parent element (serves as clipping rect)
xoffsetThe x-coordinate of the left edge of this elements rect, relative to the panel
yoffsetThe y-coordinate of the top edge of this elements rect, relative to the panel

Reimplemented from GUI_BaseElement.

int GUI_ListBox::GetNeededListBoxHeight ( int  numlines,
GUI_STYLE  styleid 
)
static
Returns
The height a GUI_ListBox needs to have to display a certain number of lines in a certain style
Parameters
numlinesHow many lines the listbox should be able to display
styleidId of the style the listbox would use
int GUI_ListBox::GetSelected ( )
Returns
The index of the FIRST selected element in the list. -1 if no item is selected.
std::string GUI_ListBox::GetSelectedText ( )
Returns
The text of the first selected element in the list. "" if no element is selected.
bool GUI_ListBox::IsHighlight ( UINT  index)

Used to check whether an element is selected in multi-select boxes.

Parameters
indexThe index of the element you want to know about.
Returns
True if the element at the passed index is selected, false otherwise.
int GUI_ListBox::NumEntries ( )
Returns
How many elements there are in the list
bool GUI_ListBox::ProcessMe ( GUI_MOUSE_EVENT  _event,
int  _x,
int  _y 
)
privatevirtual

Processes events for this element.

Separated from ProcessChildren() so either can be freely overloaded without the other

Parameters
_eventThe mouse event that triggered the call
_xthe x coordinate of the click, relative to the panel
_ythe y coordinate of the click, relative to the panel
Returns
True if this element has consumed the event

Reimplemented from GUI_BaseElement.

void GUI_ListBox::SetListJustification ( GUI_TEXT_POS  tpos)

Sets the justification of the text inside the list.

Parameters
tposCan be T_RIGHT, T_LEFT or T_CENTER
void GUI_ListBox::SetSelected ( int  _selected)

Sets a new (or additional) selected element.

Parameters
_selectedThe index of the element to select.

The documentation for this class was generated from the following files: