[1092] | 1 | /************************************************************************
|
---|
| 2 | filename: CEGUIListboxItem.h
|
---|
| 3 | created: 8/6/2004
|
---|
| 4 | author: Paul D Turner
|
---|
| 5 |
|
---|
| 6 | purpose: Interface to base class for list items
|
---|
| 7 | *************************************************************************/
|
---|
| 8 | /*************************************************************************
|
---|
| 9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
| 10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
| 11 |
|
---|
| 12 | This library is free software; you can redistribute it and/or
|
---|
| 13 | modify it under the terms of the GNU Lesser General Public
|
---|
| 14 | License as published by the Free Software Foundation; either
|
---|
| 15 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 16 |
|
---|
| 17 | This library is distributed in the hope that it will be useful,
|
---|
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | Lesser General Public License for more details.
|
---|
| 21 |
|
---|
| 22 | You should have received a copy of the GNU Lesser General Public
|
---|
| 23 | License along with this library; if not, write to the Free Software
|
---|
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 25 | *************************************************************************/
|
---|
| 26 | #ifndef _CEGUIListboxItem_h_
|
---|
| 27 | #define _CEGUIListboxItem_h_
|
---|
| 28 |
|
---|
| 29 | #include "CEGUIBase.h"
|
---|
| 30 | #include "CEGUIString.h"
|
---|
| 31 | #include "CEGUIColourRect.h"
|
---|
| 32 |
|
---|
| 33 | // Start of CEGUI namespace section
|
---|
| 34 | namespace CEGUI
|
---|
| 35 | {
|
---|
| 36 | /*!
|
---|
| 37 | \brief
|
---|
| 38 | Base class for list box items
|
---|
| 39 | */
|
---|
| 40 | class CEGUIEXPORT ListboxItem
|
---|
| 41 | {
|
---|
| 42 | public:
|
---|
| 43 | /*************************************************************************
|
---|
| 44 | Constants
|
---|
| 45 | *************************************************************************/
|
---|
| 46 | static const colour DefaultSelectionColour; //!< Default selection brush colour.
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | /*************************************************************************
|
---|
| 50 | Construction and Destruction
|
---|
| 51 | *************************************************************************/
|
---|
| 52 | /*!
|
---|
| 53 | \brief
|
---|
| 54 | base class constructor
|
---|
| 55 | */
|
---|
| 56 | ListboxItem(const String& text, uint item_id = 0, void* item_data = NULL, bool disabled = false, bool auto_delete = true);
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | /*!
|
---|
| 60 | \brief
|
---|
| 61 | base class destructor
|
---|
| 62 | */
|
---|
| 63 | virtual ~ListboxItem(void) {}
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | /*************************************************************************
|
---|
| 67 | Accessors
|
---|
| 68 | *************************************************************************/
|
---|
| 69 | /*!
|
---|
| 70 | \brief
|
---|
| 71 | return the text string set for this list box item.
|
---|
| 72 |
|
---|
| 73 | Note that even if the item does not render text, the text string can still be useful, since it
|
---|
| 74 | is used for sorting list box items.
|
---|
| 75 |
|
---|
| 76 | \return
|
---|
| 77 | String object containing the current text for the list box item.
|
---|
| 78 | */
|
---|
| 79 | const String& getText(void) const {return d_itemText;}
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | /*!
|
---|
| 83 | \brief
|
---|
| 84 | Return the current ID assigned to this list box item.
|
---|
| 85 |
|
---|
| 86 | Note that the system does not make use of this value, client code can assign any meaning it
|
---|
| 87 | wishes to the ID.
|
---|
| 88 |
|
---|
| 89 | \return
|
---|
| 90 | ID code currently assigned to this list box item
|
---|
| 91 | */
|
---|
| 92 | uint getID(void) const {return d_itemID;}
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | /*!
|
---|
| 96 | \brief
|
---|
| 97 | Return the pointer to any client assigned user data attached to this lis box item.
|
---|
| 98 |
|
---|
| 99 | Note that the system does not make use of this data, client code can assign any meaning it
|
---|
| 100 | wishes to the attached data.
|
---|
| 101 |
|
---|
| 102 | \return
|
---|
| 103 | Pointer to the currently assigned user data.
|
---|
| 104 | */
|
---|
| 105 | void* getUserData(void) const {return d_itemData;}
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | /*!
|
---|
| 109 | \brief
|
---|
| 110 | return whether this item is selected.
|
---|
| 111 |
|
---|
| 112 | \return
|
---|
| 113 | true if the item is selected, false if the item is not selected.
|
---|
| 114 | */
|
---|
| 115 | bool isSelected(void) const {return d_selected;}
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /*!
|
---|
| 119 | \brief
|
---|
| 120 | return whether this item is disabled.
|
---|
| 121 |
|
---|
| 122 | \return
|
---|
| 123 | true if the item is disabled, false if the item is enabled.
|
---|
| 124 | */
|
---|
| 125 | bool isDisabled(void) const {return d_disabled;}
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | /*!
|
---|
| 129 | \brief
|
---|
| 130 | return whether this item will be automatically deleted when the list box it is attached to
|
---|
| 131 | is destroyed, or when the item is removed from the list box.
|
---|
| 132 |
|
---|
| 133 | \return
|
---|
| 134 | true if the item object will be deleted by the system when the list box it is attached to is
|
---|
| 135 | destroyed, or when the item is removed from the list. false if client code must destroy the
|
---|
| 136 | item after it is removed from the list.
|
---|
| 137 | */
|
---|
| 138 | bool isAutoDeleted(void) const {return d_autoDelete;}
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | /*!
|
---|
| 142 | \brief
|
---|
| 143 | Get the owner window for this ListboxItem.
|
---|
| 144 |
|
---|
| 145 | The owner of a ListboxItem is typically set by the list box widgets when an item is added or inserted.
|
---|
| 146 |
|
---|
| 147 | \return
|
---|
| 148 | Ponter to the window that is considered the owner of this ListboxItem.
|
---|
| 149 | */
|
---|
| 150 | const Window* getOwnerWindow(const Window* owner) {return d_owner;}
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | /*!
|
---|
| 154 | \brief
|
---|
| 155 | Return the current colours used for selection highlighting.
|
---|
| 156 |
|
---|
| 157 | \return
|
---|
| 158 | ColourRect object describing the currently set colours
|
---|
| 159 | */
|
---|
| 160 | ColourRect getSelectionColours(void) const {return d_selectCols;}
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | /*!
|
---|
| 164 | \brief
|
---|
| 165 | Return the current selection highlighting brush.
|
---|
| 166 |
|
---|
| 167 | \return
|
---|
| 168 | Pointer to the Image object currently used for selection highlighting.
|
---|
| 169 | */
|
---|
| 170 | const Image* getSelectionBrushImage(void) const {return d_selectBrush;}
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | /*************************************************************************
|
---|
| 174 | Manipulators
|
---|
| 175 | *************************************************************************/
|
---|
| 176 | /*!
|
---|
| 177 | \brief
|
---|
| 178 | set the text string for this list box item.
|
---|
| 179 |
|
---|
| 180 | Note that even if the item does not render text, the text string can still be useful, since it
|
---|
| 181 | is used for sorting list box items.
|
---|
| 182 |
|
---|
| 183 | \param text
|
---|
| 184 | String object containing the text to set for the list box item.
|
---|
| 185 |
|
---|
| 186 | \return
|
---|
| 187 | Nothing.
|
---|
| 188 | */
|
---|
| 189 | void setText(const String& text) {d_itemText = text;}
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | /*!
|
---|
| 193 | \brief
|
---|
| 194 | Set the ID assigned to this list box item.
|
---|
| 195 |
|
---|
| 196 | Note that the system does not make use of this value, client code can assign any meaning it
|
---|
| 197 | wishes to the ID.
|
---|
| 198 |
|
---|
| 199 | \param item_id
|
---|
| 200 | ID code to be assigned to this list box item
|
---|
| 201 |
|
---|
| 202 | \return
|
---|
| 203 | Nothing.
|
---|
| 204 | */
|
---|
| 205 | void setID(uint item_id) {d_itemID = item_id;}
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | /*!
|
---|
| 209 | \brief
|
---|
| 210 | Set the client assigned user data attached to this lis box item.
|
---|
| 211 |
|
---|
| 212 | Note that the system does not make use of this data, client code can assign any meaning it
|
---|
| 213 | wishes to the attached data.
|
---|
| 214 |
|
---|
| 215 | \param item_data
|
---|
| 216 | Pointer to the user data to attach to this list item.
|
---|
| 217 |
|
---|
| 218 | \return
|
---|
| 219 | Nothing.
|
---|
| 220 | */
|
---|
| 221 | void setUserData(void* item_data) {d_itemData = item_data;}
|
---|
| 222 |
|
---|
| 223 |
|
---|
| 224 | /*!
|
---|
| 225 | \brief
|
---|
| 226 | set whether this item is selected.
|
---|
| 227 |
|
---|
| 228 | \param setting
|
---|
| 229 | true if the item is selected, false if the item is not selected.
|
---|
| 230 |
|
---|
| 231 | \return
|
---|
| 232 | Nothing.
|
---|
| 233 | */
|
---|
| 234 | void setSelected(bool setting) {d_selected = setting;}
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 | /*!
|
---|
| 238 | \brief
|
---|
| 239 | set whether this item is disabled.
|
---|
| 240 |
|
---|
| 241 | \param setting
|
---|
| 242 | true if the item is disabled, false if the item is enabled.
|
---|
| 243 |
|
---|
| 244 | \return
|
---|
| 245 | Nothing.
|
---|
| 246 | */
|
---|
| 247 | void setDisabled(bool setting) {d_disabled = setting;}
|
---|
| 248 |
|
---|
| 249 | /*!
|
---|
| 250 | \brief
|
---|
| 251 | Set whether this item will be automatically deleted when the list box it is attached to
|
---|
| 252 | is destroyed, or when the item is removed from the list box.
|
---|
| 253 |
|
---|
| 254 | \param setting
|
---|
| 255 | true if the item object should be deleted by the system when the list box it is attached to is
|
---|
| 256 | destroyed, or when the item is removed from the list. false if client code will destroy the
|
---|
| 257 | item after it is removed from the list.
|
---|
| 258 |
|
---|
| 259 | \return
|
---|
| 260 | Nothing.
|
---|
| 261 | */
|
---|
| 262 | void setAutoDeleted(bool setting) {d_autoDelete = setting;}
|
---|
| 263 |
|
---|
| 264 |
|
---|
| 265 | /*!
|
---|
| 266 | \brief
|
---|
| 267 | Set the owner window for this ListboxItem. This is called by all the list box widgets when
|
---|
| 268 | an item is added or inserted.
|
---|
| 269 |
|
---|
| 270 | \param owner
|
---|
| 271 | Ponter to the window that should be considered the owner of this ListboxItem.
|
---|
| 272 |
|
---|
| 273 | \return
|
---|
| 274 | Nothing
|
---|
| 275 | */
|
---|
| 276 | void setOwnerWindow(const Window* owner) {d_owner = owner;}
|
---|
| 277 |
|
---|
| 278 |
|
---|
| 279 | /*!
|
---|
| 280 | \brief
|
---|
| 281 | Set the colours used for selection highlighting.
|
---|
| 282 |
|
---|
| 283 | \param cols
|
---|
| 284 | ColourRect object describing the colours to be used.
|
---|
| 285 |
|
---|
| 286 | \return
|
---|
| 287 | Nothing.
|
---|
| 288 | */
|
---|
| 289 | void setSelectionColours(const ColourRect& cols) {d_selectCols = cols;}
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | /*!
|
---|
| 293 | \brief
|
---|
| 294 | Set the colours used for selection highlighting.
|
---|
| 295 |
|
---|
| 296 | \param top_left_colour
|
---|
| 297 | Colour (as ARGB value) to be applied to the top-left corner of the selection area.
|
---|
| 298 |
|
---|
| 299 | \param top_right_colour
|
---|
| 300 | Colour (as ARGB value) to be applied to the top-right corner of the selection area.
|
---|
| 301 |
|
---|
| 302 | \param bottom_left_colour
|
---|
| 303 | Colour (as ARGB value) to be applied to the bottom-left corner of the selection area.
|
---|
| 304 |
|
---|
| 305 | \param bottom_right_colour
|
---|
| 306 | Colour (as ARGB value) to be applied to the bottom-right corner of the selection area.
|
---|
| 307 |
|
---|
| 308 | \return
|
---|
| 309 | Nothing.
|
---|
| 310 | */
|
---|
| 311 | void setSelectionColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour);
|
---|
| 312 |
|
---|
| 313 |
|
---|
| 314 | /*!
|
---|
| 315 | \brief
|
---|
| 316 | Set the colours used for selection highlighting.
|
---|
| 317 |
|
---|
| 318 | \param col
|
---|
| 319 | colour value to be used when rendering.
|
---|
| 320 |
|
---|
| 321 | \return
|
---|
| 322 | Nothing.
|
---|
| 323 | */
|
---|
| 324 | void setSelectionColours(colour col) {setSelectionColours(col, col, col, col);}
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 | /*!
|
---|
| 328 | \brief
|
---|
| 329 | Set the selection highlighting brush image.
|
---|
| 330 |
|
---|
| 331 | \param image
|
---|
| 332 | Pointer to the Image object to be used for selection highlighting.
|
---|
| 333 |
|
---|
| 334 | \return
|
---|
| 335 | Nothing.
|
---|
| 336 | */
|
---|
| 337 | void setSelectionBrushImage(const Image* image) {d_selectBrush = image;}
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | /*!
|
---|
| 341 | \brief
|
---|
| 342 | Set the selection highlighting brush image.
|
---|
| 343 |
|
---|
| 344 | \param imageset
|
---|
| 345 | Name of the imagest containing the image to be used.
|
---|
| 346 |
|
---|
| 347 | \param image
|
---|
| 348 | Name of the image to be used
|
---|
| 349 |
|
---|
| 350 | \return
|
---|
| 351 | Nothing.
|
---|
| 352 | */
|
---|
| 353 | void setSelectionBrushImage(const String& imageset, const String& image);
|
---|
| 354 |
|
---|
| 355 |
|
---|
| 356 | /*************************************************************************
|
---|
| 357 | Abstract portion of interface
|
---|
| 358 | *************************************************************************/
|
---|
| 359 | /*!
|
---|
| 360 | \brief
|
---|
| 361 | Return the rendered pixel size of this list box item.
|
---|
| 362 |
|
---|
| 363 | \return
|
---|
| 364 | Size object describing the size of the list box item in pixels.
|
---|
| 365 | */
|
---|
| 366 | virtual Size getPixelSize(void) const = 0;
|
---|
| 367 |
|
---|
| 368 |
|
---|
| 369 | /*!
|
---|
| 370 | \brief
|
---|
| 371 | Draw the list box item in its current state
|
---|
| 372 |
|
---|
| 373 | \param position
|
---|
| 374 | Vecor3 object describing the upper-left corner of area that should be rendered in to for the draw operation.
|
---|
| 375 |
|
---|
| 376 | \param alpha
|
---|
| 377 | Alpha value to be used when rendering the item (between 0.0f and 1.0f).
|
---|
| 378 |
|
---|
| 379 | \param clipper
|
---|
| 380 | Rect object describing the clipping rectangle for the draw operation.
|
---|
| 381 |
|
---|
| 382 | \return
|
---|
| 383 | Nothing.
|
---|
| 384 | */
|
---|
| 385 | virtual void draw(const Vector3& position, float alpha, const Rect& clipper) const = 0;
|
---|
| 386 |
|
---|
| 387 |
|
---|
| 388 | /*************************************************************************
|
---|
| 389 | Operators
|
---|
| 390 | *************************************************************************/
|
---|
| 391 | /*!
|
---|
| 392 | \brief
|
---|
| 393 | Less-than operator, compares item texts.
|
---|
| 394 | */
|
---|
| 395 | virtual bool operator<(const ListboxItem& rhs) const {return d_itemText < rhs.getText();}
|
---|
| 396 |
|
---|
| 397 |
|
---|
| 398 | /*!
|
---|
| 399 | \brief
|
---|
| 400 | Greater-than operator, compares item texts.
|
---|
| 401 | */
|
---|
| 402 | virtual bool operator>(const ListboxItem& rhs) const {return d_itemText > rhs.getText();}
|
---|
| 403 |
|
---|
| 404 |
|
---|
| 405 | protected:
|
---|
| 406 | /*************************************************************************
|
---|
| 407 | Implementation methods
|
---|
| 408 | *************************************************************************/
|
---|
| 409 | /*!
|
---|
| 410 | \brief
|
---|
| 411 | Return a ColourRect object describing the colours in \a cols after having their alpha
|
---|
| 412 | component modulated by the value \a alpha.
|
---|
| 413 | */
|
---|
| 414 | ColourRect getModulateAlphaColourRect(const ColourRect& cols, float alpha) const;
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 | /*!
|
---|
| 418 | \brief
|
---|
| 419 | Return a colour value describing the colour specified by \a col after having its alpha
|
---|
| 420 | component modulated by the value \a alpha.
|
---|
| 421 | */
|
---|
| 422 | colour calculateModulatedAlphaColour(colour col, float alpha) const;
|
---|
| 423 |
|
---|
| 424 |
|
---|
| 425 | /*************************************************************************
|
---|
| 426 | Implementation Data
|
---|
| 427 | *************************************************************************/
|
---|
| 428 | String d_itemText; //!< Text for this list box item. If not rendered, this is still used for list sorting.
|
---|
| 429 | uint d_itemID; //!< ID code assigned by client code. This has no meaning within the GUI system.
|
---|
| 430 | void* d_itemData; //!< Pointer to some client code data. This has no meaning within the GUI system.
|
---|
| 431 | bool d_selected; //!< true if this item is selected. false if the item is not selected.
|
---|
| 432 | bool d_disabled; //!< true if this item is disabled. false if the item is not disabled.
|
---|
| 433 | bool d_autoDelete; //!< true if the system should destroy this item, false if client code will destroy the item.
|
---|
| 434 | const Window* d_owner; //!< Pointer to the window that owns this item.
|
---|
| 435 | ColourRect d_selectCols; //!< Colours used for selection highlighting.
|
---|
| 436 | const Image* d_selectBrush; //!< Image used for rendering selection.
|
---|
| 437 | };
|
---|
| 438 |
|
---|
| 439 | } // End of CEGUI namespace section
|
---|
| 440 |
|
---|
| 441 |
|
---|
| 442 | #endif // end of guard _CEGUIListboxItem_h_
|
---|