widgets.h

Go to the documentation of this file.
00001 /*
00002  * widgets.h
00003  *
00004  *  Created on: Jan 8, 2013
00005  *      Author: sushil
00006  */
00007 
00008 #ifndef WIDGETS_H_
00009 #define WIDGETS_H_
00010 
00011 #include <OgreVector2.h>
00012 #include <OgreColourValue.h>
00013 #include <OgreOverlayManager.h>
00014 #include <OgreOverlayContainer.h>
00015 #include <OgreOverlayElement.h>
00016 #include <OgreTextAreaOverlayElement.h>
00017 #include <OISMouse.h>
00018 
00019 
00020 #include <inputHandlers.h>
00021 #include "commandFactory.h"
00022 #include "GraphicsInteractionManager.h"
00023 
00024 
00025 
00026 
00027 namespace OgreGFX
00028 {
00029 
00030 static std::string DEFAULT_PANEL_MATERIAL = "ECSLENT/navy/material/shipInfo/overlay";
00031 static Ogre::Vector2 DEFAULT_LABEL_SIZE = Ogre::Vector2(100, 20);
00032 
00033 enum Placement
00034 {
00035     Below = 0,
00036     Right = 1
00037 };
00038 
00039 class GraphicsInteractionManager;
00040 
00044 class Widget
00045 {
00046 public:
00047     Ogre::Vector2 pos; 
00048     Ogre::Vector2 size; 
00049     Widget *parent; 
00050     GraphicsInteractionManager *gfx; 
00051     Ogre::GuiMetricsMode mode;
00052     std::string desc; 
00064     Widget(GraphicsInteractionManager *gim, Widget *aParent = 0, Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X, Ogre::Vector2 defaultSize = Ogre::Vector2::NEGATIVE_UNIT_X, Ogre::GuiMetricsMode
00065     defaultMode = Ogre::GMM_RELATIVE);
00066     ~Widget();
00067 
00073     Ogre::Vector2 screenPos();
00074 
00081     bool cursonInMe(const Ogre::Vector2 &pos);
00082 
00087     virtual void posChanged()
00088     {
00089     };
00090 
00095     virtual void show()
00096     {
00097     };
00098 
00103     virtual void hide()
00104     {
00105     };
00106 
00111     virtual Ogre::OverlayElement* getOverlayElementToAdd()
00112     {
00113         return 0;
00114     };
00115 
00116 };
00117 
00118 class UIOutline : public Widget
00119 {
00120 public:
00121 
00122     Ogre::OverlayManager *overlayManagerPtr;
00123     Ogre::Overlay* overlay;
00124     virtual void show();
00125     virtual void hide();
00126 
00127     UIOutline(GraphicsInteractionManager *gim);
00128     ~UIOutline();
00129 
00130 };
00131 
00132 class FEProgressBar : public Widget
00133 {
00134 private:
00135 
00136 public:
00137     FEProgressBar(GraphicsInteractionManager *gim, std::string name = "FEProgressBar", Widget* aParent = 0,
00138             Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X, Ogre::Vector2 defaultSize = Ogre::Vector2::NEGATIVE_UNIT_X,
00139             std::string barMaterial = DEFAULT_PANEL_MATERIAL, std::string fillMaterial = DEFAULT_PANEL_MATERIAL, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE); //: Widget(gim) {};
00140     ~FEProgressBar();
00141 
00142     //Ogre::Overlay* overlayPtr;
00143     Ogre::OverlayManager* overlayManagerPtr;
00144     Ogre::OverlayContainer *progressBar;
00145     //Ogre::OverlayContainer *progressFill;
00146     std::string barMaterial; 
00147     std::string fillMaterial; 
00148     std::string name; 
00149     double percentFull;
00150     
00151     void UpdateFillPercent();
00152     virtual void show();
00153     virtual void hide();
00154     virtual void posChanged();
00155     virtual Ogre::OverlayElement* getOverlayElementToAdd();
00156 
00157 };
00158 
00162 class FEPanel : public Widget
00163 {
00164 private:
00165 
00166 public:
00178     FEPanel(GraphicsInteractionManager *gim, std::string name = "FEPanel", Widget* aParent = 0,
00179             Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X, Ogre::Vector2 defaultSize = Ogre::Vector2::NEGATIVE_UNIT_X,
00180             std::string material = DEFAULT_PANEL_MATERIAL, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE); //: Widget(gim) {};
00181     ~FEPanel();
00182 
00183     Ogre::Overlay* overlayPtr;
00184     Ogre::OverlayManager* overlayManagerPtr;
00185     Ogre::OverlayContainer *panel;
00186     //Ogre::TextAreaOverlayElement *textArea; /*! The visual element used to display text */
00187     std::string material; 
00188     std::string name; 
00189     Ogre::Vector2 belowPos; 
00190     Ogre::Vector2 rightPos; 
00191     Ogre::Vector2 gap; 
00192     std::list<Widget*> items; 
00193     std::list<Ogre::OverlayElement*> separators; 
00194     int separatorHeight; 
00197     virtual void show();
00198     virtual void hide();
00199     virtual void posChanged();
00200 
00207     void addItem(Widget *item, Placement placement = Below);
00208 
00209     //          void getItems();
00210     //          void getOverlayElementToAdd();
00211 
00212     void addSep(int separation);
00213 
00217     void adjustSeparators();
00222     Ogre::OverlayElement* makeSep();
00223 
00228     virtual Ogre::OverlayElement* getOverlayElementToAdd();
00229 
00230 };
00231 
00234 class FELabel : public Widget
00235 {
00236 public:
00248     FELabel(GraphicsInteractionManager *gim, std::string caption = "FELabel",
00249             Widget *aParent = 0, Ogre::ColourValue color = Ogre::ColourValue::Red,
00250             Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X, Ogre::Vector2 defaultSize = DEFAULT_LABEL_SIZE, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE);
00251     ~FELabel();
00252 
00253     Ogre::OverlayManager* overlayManagerPtr;
00254     std::string caption; 
00255     Ogre::ColourValue color; 
00256     Ogre::Vector2 offset; 
00257     Ogre::TextAreaOverlayElement* textArea; 
00264     virtual void setCaption(std::string val);
00265 
00266     virtual void show();
00267     virtual void hide();
00268     virtual void posChanged();
00269     virtual Ogre::OverlayElement* getOverlayElementToAdd();
00270 
00271 };
00272 
00273 class FELineWrapLabel : public FELabel
00274 {
00275 public:
00276     FELineWrapLabel(GraphicsInteractionManager *gim, std::string caption = "FELineWrapLabel",
00277             Widget *aParent = 0, Ogre::ColourValue color = Ogre::ColourValue::Red,
00278             Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X, Ogre::Vector2 defaultSize = DEFAULT_LABEL_SIZE, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE, double lines = 1);
00279             
00280     ~FELineWrapLabel();
00281     virtual void setCaption(std::string val);
00282     
00283     double lines;
00284     
00285 };
00286 
00293 class FEButton : public FEPanel, public MouseHandler, public KeyHandler
00294 {
00295 public:
00311     FEButton(GraphicsInteractionManager *gim, const OIS::KeyCode keyCode,
00312              const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00313              std::string name = "FEButton", FastEcslent::CommandFactory* command = NULL,
00314              Widget *aParent = 0,
00315              Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X,
00316              Ogre::Vector2 defaultSize = DEFAULT_LABEL_SIZE,std::string material = DEFAULT_PANEL_MATERIAL, std::string desc = "BLANK", Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE);
00317     ~FEButton();
00318 
00319     FastEcslent::CommandFactory* commandFactory; 
00320     bool pressed; 
00321     bool enabled; 
00328     virtual void handleMouseEvent(const OIS::MouseEvent &args);
00329     virtual void handleKeyEvent();
00330     virtual void show();
00331     virtual void hide();
00332     bool processButtonFirstEvent(bool buttonActivated);
00333     bool processButtonSecondEvent(bool buttonActivated);
00334 };
00335 
00337 // * a mouse click occurs inside its area. If a mouse event does occur in its area,
00338 // * a function associated with that button is called. Buttons consume the mouse click,
00339 // * so the mouse click doesn't get passed on to any units that might exist beneath the overlay. 
00340 // */
00341 //
00342 //class FEButton : public FEPanel, public MouseHandler
00343 //{
00344 //public:
00345 //    /*!
00346 //     * Constructor for a Button widget, which displays some text. Clicking on the text causes a function to be called to perform some task.
00347 //     * @param gim a pointer to the global Graphics Interaction Manager, to display widget.
00348 //     * @param modifierKeys Pointer to a configuration of keyboard keys that must all be pressed for the button handler to be called.
00349 //     * @param oisMouseButtonId The ID of the mouse button that must be pressed for the button handler to be called.
00350 //     * @param caption The text to display in the panel
00351 //     * @param aParent A pointer to the parent node, if any (null if this is a root element, or pointer to another widget if this is a child of that widget). Defaults to NULL.
00352 //     * @param color The color of the displayed text. Defaults to red
00353 //     * @param defaultPos Upper-right corner position of the widget, in absolute coordinates if this is a parent node, or relative to the parent node if this is a child node.
00354 //     * @param defaultSize length and height of the widget.
00355 //     * @param pClickFunction Pointer to a function, which is called when the button handler is called.
00356 //     * @see ~FEButton()
00357 //     */
00358 //    FEButton(GraphicsInteractionManager *gim,
00359 //             const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00360 //             std::string name = "FEButton",
00361 //             Widget *aParent = 0, Ogre::ColourValue color = Ogre::ColourValue::Red,
00362 //             Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X,
00363 //             Ogre::Vector2 defaultSize = DEFAULT_LABEL_SIZE, bool (*pClickFunction)() = NULL, std::string material = DEFAULT_PANEL_MATERIAL, std::string = "BLANK", Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE);
00364 //    ~FEButton();
00365 //
00366 //    bool (*pClickFunction)();
00367 //    bool pressed; /*! Stores if the button has been clicked since last update */
00368 //    bool enabled; /*! Stores if the button is available to be clicked or not. If false, clicking the button does not result in the associated function being called. */
00369 //    /*!
00370 //     * Mouse handler called when a mouse event occurs.
00371 //     * @param args Information about the mouse state (mouse button, cursor position, etc).
00372 //     * @return void
00373 //     */
00374 //    virtual void handleMouseEvent(const OIS::MouseEvent &args);
00375 //    virtual void show();
00376 //    virtual void hide();
00377 //};
00378 //
00380 // */
00381 //class FESCVButton : public FEButton
00382 //{
00383 //public:
00384 //    /*!
00385 //     * Constructor for a SCV button, which builds an SCV near the selected structure.
00386 //     * @param gim a pointer to the global Graphics Interaction Manager, to display widget.
00387 //     * @param modifierKeys Pointer to a configuration of keyboard keys that must all be pressed for the button handler to be called.
00388 //     * @param oisMouseButtonId The ID of the mouse button that must be pressed for the button handler to be called.
00389 //     * @param caption The text to display in the panel
00390 //     * @param aParent A pointer to the parent node, if any (null if this is a root element, or pointer to another widget if this is a child of that widget). Defaults to NULL.
00391 //     * @param color The color of the displayed text. Defaults to red
00392 //     * @param defaultPos Upper-right corner position of the widget, in absolute coordinates if this is a parent node, or relative to the parent node if this is a child node.
00393 //     * @param defaultSize length and height of the widget.
00394 //     * @see ~FESCVButton()
00395 //     */
00396 //    FESCVButton(GraphicsInteractionManager *gim,
00397 //                const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00398 //                std::string caption = "FEButton",
00399 //                Widget *aParent = 0, Ogre::ColourValue color = Ogre::ColourValue::Red,
00400 //                Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X,
00401 //                Ogre::Vector2 defaultSize = DEFAULT_LABEL_SIZE, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE);
00402 //    ~FESCVButton();
00403 //
00404 //    virtual void handleMouseEvent(const OIS::MouseEvent &args);
00405 //};
00406 //
00408 // */
00409 //class FEMarineButton : public FEButton
00410 //{
00411 //public:
00412 //    /*!
00413 //     * Constructor for a Marine button, which builds an Marine near the selected structure.
00414 //     * @param gim a pointer to the global Graphics Interaction Manager, to display widget.
00415 //     * @param modifierKeys Pointer to a configuration of keyboard keys that must all be pressed for the button handler to be called.
00416 //     * @param oisMouseButtonId The ID of the mouse button that must be pressed for the button handler to be called.
00417 //     * @param caption The text to display in the panel
00418 //     * @param aParent A pointer to the parent node, if any (null if this is a root element, or pointer to another widget if this is a child of that widget). Defaults to NULL.
00419 //     * @param color The color of the displayed text. Defaults to red
00420 //     * @param defaultPos Upper-right corner position of the widget, in absolute coordinates if this is a parent node, or relative to the parent node if this is a child node.
00421 //     * @param defaultSize length and height of the widget.
00422 //     * @see ~FEMarineButton()
00423 //     */
00424 //    FEMarineButton(GraphicsInteractionManager *gim,
00425 //                   const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00426 //                   std::string caption = "FEButton",
00427 //                   Widget *aParent = 0, Ogre::ColourValue color = Ogre::ColourValue::Red,
00428 //                   Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X,
00429 //                   Ogre::Vector2 defaultSize = DEFAULT_LABEL_SIZE, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE);
00430 //    ~FEMarineButton();
00431 //
00432 //    virtual void handleMouseEvent(const OIS::MouseEvent &args);
00433 //};
00434 
00438 class FELabelPair : public FEPanel
00439 {
00440 public:
00454     FELabelPair(GraphicsInteractionManager *gim, std::string caption1 = "Key", std::string caption2 = "Value",
00455                 Widget *aParent = 0, Ogre::ColourValue color = Ogre::ColourValue::Green,
00456                 Ogre::Vector2 defaultPos = Ogre::Vector2::NEGATIVE_UNIT_X,
00457                 Ogre::Vector2 defaultColumnWidths = Ogre::Vector2(100, 200), int columnHeight = DEFAULT_LABEL_SIZE.y,
00458                 std::string materialName = DEFAULT_PANEL_MATERIAL, Ogre::GuiMetricsMode defaultMode = Ogre::GMM_RELATIVE);
00459 
00460     /*dimensions/positions are in pixels */
00461     ~FELabelPair()
00462     {
00463     };
00464 
00465     FELabel *left, *right;
00466 
00467     virtual void show();
00468     virtual void hide();
00469 
00475     void setLeft(std::string val);
00476 
00482     void setRight(std::string val);
00483 
00484 };
00485 
00486 
00487 }
00488 
00489 
00490 #endif /* WIDGETS_H_ */

Generated on Fri Dec 13 14:54:16 2013 for FastECSLent by  doxygen 1.5.4