option.h

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software
00006 // and you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00019 #ifndef __OPTION_HEADER__
00020 #define __OPTION_HEADER__
00021 
00022 #include "defs.h"
00023 #include "utils.h"
00024 
00025 #include "gui.h"
00026 #include "system.h"
00027 
00028 namespace hoa_video {
00029 
00031 const int32 VIDEO_CURSOR_BLINK_RATE = 40;
00032 
00034 const int32 VIDEO_OPTION_SCROLL_TIME = 100;
00035 
00036 
00038 enum OptionBoxEvent {
00039   VIDEO_OPTION_INVALID          = -1,
00041   VIDEO_OPTION_SELECTION_CHANGE =  0,
00043   VIDEO_OPTION_CONFIRM          =  1,
00045   VIDEO_OPTION_CANCEL           =  2,
00047   VIDEO_OPTION_SWITCH           =  3,
00049   VIDEO_OPTION_BOUNDS_UP        =  4,
00051   VIDEO_OPTION_BOUNDS_DOWN      =  5,
00053   VIDEO_OPTION_BOUNDS_LEFT      =  6,
00055   VIDEO_OPTION_BOUNDS_RIGHT     =  7,
00056   VIDEO_OPTION_TOTAL            =  8
00057 };
00058 
00059 
00061 enum OptionElementType {
00062   VIDEO_OPTION_ELEMENT_INVALID      = -1,
00064   VIDEO_OPTION_ELEMENT_LEFT_ALIGN   =  0,
00066   VIDEO_OPTION_ELEMENT_CENTER_ALIGN =  1,
00068   VIDEO_OPTION_ELEMENT_RIGHT_ALIGN  =  2,
00070   VIDEO_OPTION_ELEMENT_POSITION     =  3,
00072   VIDEO_OPTION_ELEMENT_IMAGE        =  4,
00074   VIDEO_OPTION_ELEMENT_TEXT         =  5,
00075   VIDEO_OPTION_ELEMENT_TOTAL        =  6
00076 };
00077 
00078 
00080 enum CursorState {
00081   VIDEO_CURSOR_STATE_INVALID  = -1,
00083   VIDEO_CURSOR_STATE_HIDDEN   =  0,
00085   VIDEO_CURSOR_STATE_VISIBLE  =  1,
00087   VIDEO_CURSOR_STATE_BLINKING =  2,
00088   VIDEO_CURSOR_STATE_TOTAL    =  3
00089 };
00090 
00091 
00093 enum WrapMode {
00094   VIDEO_WRAP_MODE_INVALID  = -1,
00096   VIDEO_WRAP_MODE_NONE     =  0,
00098   VIDEO_WRAP_MODE_STRAIGHT =  1,
00100   VIDEO_WRAP_MODE_SHIFTED  =  2,
00101   VIDEO_WRAP_MODE_TOTAL    =  3
00102 };
00103 
00104 
00106 enum SelectMode
00107 {
00108   VIDEO_SELECT_INVALID = -1,
00110   VIDEO_SELECT_SINGLE  =  0,
00113   VIDEO_SELECT_DOUBLE  =  1,
00114   VIDEO_SELECT_TOTAL   =  2
00115 };
00116 
00117 namespace private_video {
00118 
00124 const uint16 OPEN_TAG     = static_cast<uint16>('<');
00125 const uint16 END_TAG      = static_cast<uint16>('>');
00126 const uint16 LEFT_TAG1    = static_cast<uint16>('l');
00127 const uint16 CENTER_TAG1  = static_cast<uint16>('c');
00128 const uint16 RIGHT_TAG1   = static_cast<uint16>('r');
00129 const uint16 LEFT_TAG2    = static_cast<uint16>('L');
00130 const uint16 CENTER_TAG2  = static_cast<uint16>('C');
00131 const uint16 RIGHT_TAG2   = static_cast<uint16>('R');
00133 
00143 class OptionElement {
00144 public:
00146   OptionElementType type;
00147 
00149   int32 value;
00150 };
00151 
00157 class OptionCellBounds {
00158 public:
00159 
00161   float y_top, y_center, y_bottom;
00162 
00164   float x_left, x_center, x_right;
00165 };
00166 
00181 class Option {
00182 public:
00184   std::vector<OptionElement> elements;
00185 
00187   std::vector<hoa_utils::ustring> text;
00188 
00191   std::vector<StillImage> images;
00192 
00194   bool disabled;
00195 };
00196 
00197 } // namespace private_video
00198 
00220 class OptionBox : public private_video::GUIControl {
00221 public:
00222   OptionBox();
00223 
00224   ~OptionBox();
00225 
00232   void Update(uint32 frame_time = hoa_system::SystemManager->GetUpdateTime());
00233 
00235   void Draw();
00236 
00238   void ClearOptions();
00239 
00248   bool SetOptions(const std::vector<hoa_utils::ustring>& option_text);
00249 
00254   bool AddOption(const hoa_utils::ustring &text);
00255 
00261   bool SetOptionText(int32 index, const hoa_utils::ustring &text);
00262 
00269   void SetSelection(int32 index);
00270 
00275   void EnableOption(int32 index, bool enable);
00276 
00281   bool IsInitialized(std::string& error_messages);
00282 
00287   void HandleUpKey();
00288   void HandleDownKey();
00289   void HandleLeftKey();
00290   void HandleRightKey();
00291   void HandleConfirmKey();
00292   void HandleCancelKey();
00294 
00296 
00297 
00301   void SetSize(int32 columns, int32 rows)
00302     { _number_columns = columns; _number_rows = rows; _initialized = IsInitialized(_initialization_errors); }
00303 
00308   void SetCellSize(float horz_spacing, float vert_spacing)
00309     { _horizontal_spacing = horz_spacing; _vertical_spacing = vert_spacing; _initialized = IsInitialized(_initialization_errors); }
00310 
00315   void SetOptionAlignment(int32 xalign, int32 yalign)
00316     { _option_xalign = xalign; _option_yalign = yalign; _initialized = IsInitialized(_initialization_errors); }
00317 
00321   void SetSelectMode(SelectMode mode)
00322     { _selection_mode = mode; _initialized = IsInitialized(_initialization_errors); }
00323 
00327   void SetVerticalWrapMode(WrapMode mode)
00328     { _vertical_wrap_mode = mode; }
00329 
00333   void SetHorizontalWrapMode(WrapMode mode)
00334     { _horizontal_wrap_mode = mode; }
00335 
00340   void SetSwitching(bool enable)
00341     { _switching = enable; }
00342 
00347   void SetCursorOffset(float x, float y)
00348     { _cursor_xoffset = x; _cursor_yoffset = y; }
00349 
00353   void SetFont(const std::string &font_name);
00354 
00358   void SetCursorState(CursorState state);
00359 
00363   bool IsScrolling() const
00364     { return _scrolling; }
00365 
00370   bool IsEnabled(int32 index) const
00371     { return !_options[index].disabled; }
00372 
00377   int32 GetEvent()
00378     { return _event; }
00379 
00383   int32 GetSelection() const
00384     { return _selection; }
00385 
00387   int32 GetNumberRows() const
00388     { return _number_rows; }
00389 
00391   int32 GetNumberColumns() const
00392     { return _number_columns; }
00393 
00395   int32 GetNumberOptions() const
00396     { return _number_options; }
00398 
00402   void TEMP_OverideScissorring(bool enable)
00403     { _TEMP_overide_scissorring = enable; }
00404 
00405 private:
00407   bool _initialized;
00408 
00414   std::vector<private_video::Option> _options;
00415 
00417 
00418 
00419   int32 _number_options;
00420 
00422   int32 _number_columns;
00423 
00425   int32 _number_rows;
00426 
00428   SelectMode _selection_mode;
00429 
00431   WrapMode _horizontal_wrap_mode;
00432 
00434   WrapMode _vertical_wrap_mode;
00435 
00437   std::string _font;
00438 
00440   bool _switching;
00442 
00444 
00445 
00446   float _cursor_xoffset, _cursor_yoffset;
00447 
00449   int32 _scroll_offset;
00450 
00452   float _horizontal_spacing;
00453 
00455   float _vertical_spacing;
00456 
00458   int32 _option_xalign;
00459 
00461   int32 _option_yalign;
00463 
00465 
00466 
00467   int32 _event;
00468 
00470   int32 _selection;
00471 
00475   int32 _first_selection;
00476 
00478   CursorState _cursor_state;
00479 
00481   bool _blink;
00482 
00484   int32 _blink_time;
00485 
00487   bool  _scrolling;
00488 
00490   int32 _scroll_time;
00491 
00493   int32 _scroll_direction;
00495 
00497   bool _TEMP_overide_scissorring;
00498 
00499   // ---------- Private methods
00500 
00506   bool _ConstructOption(const hoa_utils::ustring &formatString, private_video::Option &option);
00507 
00513   bool _ChangeSelection(int32 offset, bool horizontal);
00514 
00523   void _SetupAlignment(int32 xalign, int32 yalign, const private_video::OptionCellBounds& bounds, float& x, float& y);
00524 }; // class OptionBox : public private_video::GUIControl
00525 
00526 } // namespace hoa_video
00527 
00528 #endif  // __OPTION_HEADER__

Generated on Fri Jul 6 23:11:20 2007 for Hero of Allacrost by  doxygen 1.5.1