src/gui/list_box.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Liste de choix.
00020  *****************************************************************************/
00021 
00022 #ifndef LIST_BOX_H
00023 #define LIST_BOX_H
00024 
00025 #include <string>
00026 #include <vector>
00027 #include <SDL.h>
00028 #include "widget.h"
00029 #include "button.h"
00030 #include "label.h"
00031 #include "../include/base.h"
00032 
00033 class ListBoxItem : public Label
00034 {
00035 private:
00036   std::string value;
00037   bool enabled;
00038 public:
00039   ListBoxItem(const std::string& _label, Font& _font, const std::string& value,
00040               bool enabled);
00041 
00042   const std::string& GetLabel() const;
00043   const std::string& GetValue() const;
00044   const bool IsEnabled() const;
00045 };
00046 
00047 class ListBox : public Widget
00048 {
00049 private:
00050   bool always_one_selected;
00051 
00052 protected:
00053   // for the placement
00054   uint nb_visible_items, nb_visible_items_max;
00055   uint height_item;
00056 
00057   // what are the items ?
00058   uint first_visible_item;
00059   int selected_item;
00060   std::vector<ListBoxItem*> m_items;
00061 
00062   // Buttons
00063   Button *m_up, *m_down;
00064 
00065 public:
00066   ListBox (const Rectanglei &rect, bool always_one_selected_b = true);
00067   ~ListBox();
00068 
00069   void Draw(const Point2i &mousePosition, Surface& surf) const;
00070   Widget* Clic(const Point2i &mousePosition, uint button);
00071   void SetSizePosition(const Rectanglei &rect);
00072 
00073   void AddItem(bool selected, const std::string &label,
00074                 const std::string &value, bool enabled = true);
00075   void Sort();
00076 
00077   int MouseIsOnWhichItem(const Point2i &mousePosition) const;
00078 
00079   void Select(uint index);
00080   void Select(const std::string& val);
00081   int GetSelectedItem() const;
00082   void Deselect();
00083   void RemoveSelected();
00084   const std::string& ReadLabel() const;
00085   const std::string& ReadValue() const;
00086   const std::string& ReadValue(int index) const;
00087 
00088   uint Size() const;
00089 };
00090 
00091 #endif

Generated on Mon Jan 1 13:10:57 2007 for Wormux by  doxygen 1.4.7