widgets.cpp

Go to the documentation of this file.
00001 /*
00002  * widgets.cpp
00003  *
00004  *  Created on: Jan 8, 2013
00005  *      Author: sushil
00006  */
00007 
00008 #include <GraphicsInteractionManager.h>
00009 #include <widgets.h>
00010 
00011 #include <OgreOverlayElement.h>
00012 #include <OgreOverlayContainer.h>
00013 #include <iostream>
00014 #include "enums.h"
00015 #include "DEBUG.h"
00016 #include "commandHelp.h"
00017 
00018 OgreGFX::Widget::Widget(GraphicsInteractionManager *gim, Widget *aParent, Ogre::Vector2 defaultPos, Ogre::Vector2 defaultSize, Ogre::GuiMetricsMode
00019 defaultMode) {
00020 
00021         if (defaultPos == Ogre::Vector2::NEGATIVE_UNIT_X)
00022                 this->pos = Ogre::Vector2(0, 0);
00023         if (defaultSize == Ogre::Vector2::NEGATIVE_UNIT_X)
00024                 this->size = Ogre::Vector2(100, 30);
00025         if (!aParent)
00026                 this->parent = 0;
00027         
00028         this->desc = "";
00029         this->gfx = gim;
00030         this->parent = aParent;
00031         this->pos = defaultPos;
00032         this->size = defaultSize;
00033         this->mode = defaultMode;
00034 
00035 }
00036 
00037 OgreGFX::Widget::~Widget(){
00038 
00039 };
00040 
00041 Ogre::Vector2 OgreGFX::Widget::screenPos(){
00042         if (this->parent) {
00043                 return this->parent->screenPos() + this->pos;
00044         } else {
00045                 return this->pos;
00046         }
00047 }
00048 
00049 bool OgreGFX::Widget::cursonInMe(const Ogre::Vector2 &pos){
00050         Ogre::Vector2 myPos = screenPos();
00051         Ogre::Vector2 mySize = this->size;
00052         
00053         
00054         if(this->mode == Ogre::GMM_PIXELS)
00055         {                
00056         }
00057         else if(this->mode == Ogre::GMM_RELATIVE)
00058         {
00059             myPos.x *= this->gfx->mWindow->getWidth();        
00060             myPos.y *= this->gfx->mWindow->getHeight();
00061             mySize.x *= this->gfx->mWindow->getWidth();        
00062             mySize.y *= this->gfx->mWindow->getHeight();
00063             DEBUG(std::cout << "Adjusted pos/size: " << myPos.x << "," << myPos.y << "|" << mySize.x << "," << mySize.y <<  "|" << (pos.x >= myPos.x && pos.x <= myPos.x + mySize.x && pos.y >= myPos.y && pos.y <= myPos.y + mySize.y)  <<std::endl;)
00064         }
00065         return (pos.x >= myPos.x && pos.x <= myPos.x + mySize.x && pos.y >= myPos.y && pos.y <= myPos.y + mySize.y);
00066 }
00067 
00068 
00069 //--------------------------------------------------------------------------------------------------------------------------------
00070 
00071 OgreGFX::UIOutline::UIOutline(GraphicsInteractionManager *gim) : OgreGFX::Widget(gim) {
00072 
00073         this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00074         std::string nextId = gfx->widgetMgr->getNextId("OutlinePanel");
00075         this->overlay = this->overlayManagerPtr->create("UIOutline");
00076 
00077 
00078         Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*> (this->overlayManagerPtr->createOverlayElement("Panel", nextId));
00079 
00080 
00081         this->pos = Ogre::Vector2(0.0, 0.0);
00082         this->size = Ogre::Vector2(gfx->mWindow->getWidth(), gfx->mWindow->getHeight());
00083         this->size = Ogre::Vector2(1.0, 1.0);
00084         panel->setPosition(pos.x, pos.y);
00085         panel->setDimensions(size.x, size.y);
00086         panel->setMaterialName("ECSLENT/UI");
00087 
00088         this->overlay->add2D(static_cast<Ogre::OverlayContainer *> (panel));
00089         this->overlay->add2D(panel);
00090         DEBUG(std::cout << "Added OvelayContainer Panel" << std::endl;)
00091 
00092         overlay->show();
00093 
00094 }
00095 
00096 void OgreGFX::UIOutline::show() {
00097         this->overlay->show();
00098 }
00099 
00100 void OgreGFX::UIOutline::hide() {
00101         this->overlay->hide();
00102 }
00103 
00104 //--------------------------------------------------------------------------------------------------------------------------------
00105 //FEPanel(gim, caption1, aparent, apos, Ogre::Vector2(columnWidths.x + columnWidths.y, columnHeight), materialName)
00106 
00107 OgreGFX::FEPanel::FEPanel(GraphicsInteractionManager *gim, std::string name, Widget* iparent,
00108                 Ogre::Vector2 ipos, Ogre::Vector2 isize, std::string imaterial,Ogre::GuiMetricsMode defaultMode):
00109                 Widget(gim, iparent, ipos, isize,defaultMode) {
00110 
00111                 this->material = imaterial;
00112                 this->name = name;
00113                 this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00114                 this->panel = static_cast<Ogre::OverlayContainer*>(this->overlayManagerPtr->createOverlayElement("Panel", gfx->widgetMgr->getNextId(name)));
00115                 this->panel->setMetricsMode(this->mode);
00116                 this->panel->setPosition(pos.x, pos.y);
00117                 //size.y = 0; // or extra space when adding labels to this
00118                 this->panel->setDimensions(size.x, size.y);
00119                 this->panel->setMaterialName(material);
00120                 this->panel->show();
00121 
00122                 if (!this->parent){
00123                         DEBUG(std::cout << "Creating panel overlay" << std::endl;)
00124                         this->overlayPtr = this->overlayManagerPtr->create(gfx->widgetMgr->getNextId(name));
00125                         this->overlayPtr->add2D(this->panel);
00126                         this->overlayPtr->show();
00127                 }
00128 
00129                 this->belowPos = Ogre::Vector2(0.0, 0.0);
00130                 this->rightPos = Ogre::Vector2(0.0, 0.0);
00131                 this->gap      = Ogre::Vector2(0.0, 0.0);
00132                 this->separatorHeight = 1;
00133 
00134 };
00135 
00136 OgreGFX::FEPanel::~FEPanel(){
00137 
00138 }
00139 
00140 
00141 void OgreGFX::FEPanel::show(){
00142         if (this->parent){
00143                 this->overlayPtr->show();
00144         }
00145         this->panel->show();
00146         for(std::list<Widget*>::iterator it = this->items.begin(); it != this->items.end(); ++it){
00147                 (*it)->show();
00148         }
00149 }
00150 
00151 
00152 void OgreGFX::FEPanel::hide(){
00153         for(std::list<Widget*>::iterator it = this->items.begin(); it != this->items.end(); ++it){ // do I need this?
00154                 (*it)->hide();
00155         }
00156         this->panel->hide();
00157         if (this->parent){
00158                 this->overlayPtr->hide();
00159         }
00160 }
00161 
00162 Ogre::OverlayElement * OgreGFX::FEPanel::makeSep(){
00163 
00164         Ogre::OverlayElement *sep = this->overlayManagerPtr->createOverlayElement("Panel", gfx->widgetMgr->getNextId("lineSep"));
00165         sep->setMetricsMode(Ogre::GMM_PIXELS);
00166         sep->setPosition(0, 0);
00167         sep->setDimensions(this->pos.x, this->separatorHeight);
00168         sep->setMaterialName("ECSLENT/line");
00169         sep->show();
00170         return sep;
00171 }
00172 
00173 void OgreGFX::FEPanel::addSep(int separation){
00174         Ogre::OverlayElement *sep = makeSep();
00175         this->separators.push_back(sep);
00176         sep->setPosition(0, separation);
00177         sep->setDimensions(this->size.x, this->separatorHeight);
00178         this->panel->addChild(sep);
00179 }
00180 
00181 void OgreGFX::FEPanel::adjustSeparators(){
00182         for(std::list<Ogre::OverlayElement*>::iterator it = this->separators.begin(); it != this->separators.end(); ++it){
00183                 (*it)->setDimensions(this->size.x, this->separatorHeight);
00184         }
00185 }
00186 
00187 void OgreGFX::FEPanel::posChanged(){
00188         this->panel->setPosition(this->pos.x, this->pos.y);
00189         for(std::list<Widget*>::iterator it = this->items.begin(); it != this->items.end(); ++it){ // do I need this?
00190                 (*it)->posChanged();
00191         }
00192 
00193 }
00194 
00195 void OgreGFX::FEPanel::addItem(Widget *item, Placement placement){
00196         this->items.push_back(item);
00197         if (this->size.x < item->size.x){
00198                 this->size.x = item->size.x;
00199                 adjustSeparators();
00200         }
00201 
00202         if (placement == Below){
00203                 DEBUG(std::cout << "Adding below: " << std::endl;)
00204                 item->pos = this->belowPos;
00205                 item->posChanged();
00206                 this->rightPos = this->belowPos + Ogre::Vector2(item->size.x + this->gap.x, 0.0);
00207                 this->belowPos.y += item->size.y + this->gap.y;
00208                 DEBUG(std::cout << "Below Pos: " << belowPos.x << ", " << belowPos.y << std::endl;)
00209         } else if (placement == Right){
00210                 item->pos = this->rightPos;
00211                 item->posChanged();
00212                 this->rightPos.x += item->size.x + this->gap.x;
00213         }
00214 
00215         if (this->rightPos.x > this->size.x){
00216                 this->size.x = this->rightPos.x;
00217         }
00218         if (this->belowPos.y > this->size.y){
00219                 this->size.y = this->belowPos.y;
00220         }
00221 
00222 
00223         this->panel->addChild(item->getOverlayElementToAdd());
00224         this->panel->setDimensions(this->size.x, this->size.y);
00225         addSep(this->size.y);
00226 
00227 }
00228 
00229 Ogre::OverlayElement * OgreGFX::FEPanel::getOverlayElementToAdd(){
00230         return static_cast<Ogre::OverlayElement *>(this->panel);
00231 }
00232 
00233 //--------------------------------------------------------------------------------------------------------------------------------
00234 
00235 OgreGFX::FELabel::FELabel(GraphicsInteractionManager *gim,
00236                 std::string caption, Widget *aparent, Ogre::ColourValue acolor,
00237                 Ogre::Vector2 apos, Ogre::Vector2 asize,Ogre::GuiMetricsMode defaultMode):
00238                 Widget(gim, aparent, apos, asize,defaultMode) {
00239 
00240         this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00241         this->caption = caption;
00242         this->color = color;
00243         this->offset = Ogre::Vector2(5.0, 2.0);
00244         this->textArea = static_cast<Ogre::TextAreaOverlayElement*>(this->overlayManagerPtr->createOverlayElement("TextArea", gfx->widgetMgr->getNextId(caption)));
00245         this->textArea->setMetricsMode(this->mode);
00246         this->textArea->setCaption(caption);
00247         DEBUG(std::cout << "Label Size: " << size.x << ", " << size.y << std::endl;)
00248         this->textArea->setPosition(pos.x + offset.x, pos.y + offset.y);
00249         this->textArea->setDimensions(size.x, size.y);
00250         this->textArea->setFontName("SdkTrays/Value");
00251         this->textArea->setCharHeight(size.y);
00252         this->textArea->setColourBottom(Ogre::ColourValue(1.0, 1.0, 0.0, 1.0));
00253         this->textArea->setColourTop(color);
00254         this->textArea->show();
00255 }
00256 
00257 OgreGFX::FELabel::~FELabel(){
00258 
00259 }
00260 
00261 void OgreGFX::FELabel::setCaption(std::string val){
00262         this->caption = val;
00263         this->textArea->setCaption(val);
00264 }
00265 
00266 
00267 void OgreGFX::FELabel::show(){
00268         DEBUG(std::cout << "Showing label" << std::endl;)
00269         this->textArea->show();
00270 }
00271 
00272 void OgreGFX::FELabel::hide(){
00273         this->textArea->hide();
00274 }
00275 
00276 Ogre::OverlayElement* OgreGFX::FELabel::getOverlayElementToAdd(){
00277         return static_cast<Ogre::OverlayElement*>(this->textArea);
00278 }
00279 
00280 void OgreGFX::FELabel::posChanged(){
00281         this->textArea->setPosition(pos.x, pos.y);
00282 }
00283 //------------------------------------------------------------------------------
00284 OgreGFX::FELineWrapLabel::FELineWrapLabel(GraphicsInteractionManager *gim, std::string caption,
00285             Widget *aParent, Ogre::ColourValue color,
00286             Ogre::Vector2 defaultPos, Ogre::Vector2 defaultSize, Ogre::GuiMetricsMode defaultMode, double lines): 
00287             FELabel(gim,caption, aParent, color, defaultPos,defaultSize,defaultMode),lines(lines) 
00288 {
00289     this->textArea->setCharHeight(size.y / lines);
00290     this->setCaption(caption);
00291 }
00292 
00293 void OgreGFX::FELineWrapLabel::setCaption(std::string val){
00294     int charPerLine = 3*(this->textArea->getWidth() / this->textArea->getCharHeight());
00295     int linebreaks = val.size() / charPerLine;
00296     const int maxLineBreaks = lines -1; //to have x lines you need x-1 line breaks (last line doesnt have a line break)
00297     if(linebreaks > maxLineBreaks)
00298     {
00299         val.erase(val.begin()+(charPerLine*this->lines), val.end()); // truncates characters that wont fit in area
00300         linebreaks = maxLineBreaks;
00301     }
00302     for(int i = 1; i <= linebreaks; i++)
00303     {
00304         val.insert(val.begin()+(i*charPerLine), '\n');
00305     }
00306         this->caption = val;
00307         this->textArea->setCaption(val);
00308 }
00309 //--------------------------------------------------------------------------------------------------------------------------------
00310 
00311 OgreGFX::FEButton::FEButton(GraphicsInteractionManager *gim, const OIS::KeyCode keyCode,
00312                             const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00313                             std::string name, FastEcslent::CommandFactory* commandFactory, Widget *aparent,
00314                             Ogre::Vector2 apos, Ogre::Vector2 asize, std::string material, std::string desc, Ogre::GuiMetricsMode defaultMode) :
00315 FEPanel(gim,
00316         name, aparent,
00317         apos, asize,material,defaultMode), commandFactory(commandFactory),
00318 MouseHandler(gim, modifierKeys, oisMouseButtonId), KeyHandler(gim, modifierKeys, keyCode),
00319 pressed(false), enabled(false)//, desc(desc)
00320 {
00321     this->desc = desc;
00322 
00323 }
00324 
00325 OgreGFX::FEButton::~FEButton()
00326 {
00327     delete commandFactory;
00328 
00329 }
00330 
00331 void OgreGFX::FEButton::handleKeyEvent()
00332 {
00333     if (commandFactory != NULL)
00334     {
00335     bool firstEvent = processButtonFirstEvent(enabled); // if the key handler has been called, then we already know the keypresses match this event, but only run if the button is actually enabled
00336     processButtonSecondEvent(!firstEvent && enabled && commandFactory->requiredTarget == FastEcslent::None && this->gfx->uiMgr->buttonActive == NULL); //only activate the 2nd event for factories that dont need targets, and dont interrupt other active buttons
00337     }
00338 }
00339 
00340 bool OgreGFX::FEButton::processButtonFirstEvent(bool buttonActivated)
00341 {
00342     //bool buttonWasClicked = enabled && buttonActivated;
00343         //DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00344         if(buttonActivated && this->gfx->uiMgr->buttonActive == NULL && commandFactory->requiredTarget != FastEcslent::None) //need to wait for another mouse click
00345         {
00346             this->gfx->uiMgr->buttonActive = this;
00347             this->gfx->uiMgr->CreateGhostUnderMouse(commandFactory->previewMeshName);
00348             return true;
00349         }
00350         return false;
00351     
00352 }
00353 
00354 bool OgreGFX::FEButton::processButtonSecondEvent(bool buttonActivated)
00355 {
00356             if (buttonActivated) //Either we do not require an ent to be found on mouse-click, or we found an ent on mouse-click regardless
00357             {
00358                 std::deque<FastEcslent::Command*> ghostCommands = FastEcslent::addCommandForEnt(this->gfx->engine->selectionMgr->primarySelection, commandFactory, this->gfx->uiMgr->entIndexUnderMouse());
00359                 
00360                 this->gfx->uiMgr->buttonActive = NULL; //command fulfilled, button no longer needs to be active in UImgr
00361                 this->gfx->uiMgr->ChangeGhostTextureRBGA(this->gfx->uiMgr->ghostUnderMouse, Ogre::ColourValue(1.0,1.0,0,0.5));
00362                 this->gfx->uiMgr->waitingGhosts.push_back(std::pair<std::deque<FastEcslent::Command*>, Ogre::SceneNode*>(ghostCommands, this->gfx->uiMgr->ghostUnderMouse));
00363                 this->gfx->uiMgr->ghostUnderMouse = NULL;
00364             }
00365     
00366 }
00367 
00368 void OgreGFX::FEButton::handleMouseEvent(const OIS::MouseEvent &args)
00369 {
00370     if (commandFactory != NULL)
00371     {
00372         std::pair<int, Ogre::Vector3 > mouseTargets = this->gfx->uiMgr->entIndexUnderMouse(); //check for required data
00373         bool buttonWasClicked = enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs));
00374         //(this->gfx->uiMgr->buttonActive == this || (buttonWasClicked && commandFactory->requiredTarget == FastEcslent::None && this->gfx->uiMgr->buttonActive == NULL))
00375         bool firstEvent = processButtonFirstEvent(buttonWasClicked);
00376         //only process the 2nd event if the button was clicked and requires no info, OR if the button was active AND has all the target info it needs
00377         //processButtonSecondEvent(!firstEvent && enabled && ((buttonWasClicked && commandFactory->requiredTarget == FastEcslent::None && this->gfx->uiMgr->buttonActive == NULL) || (this->gfx->uiMgr->buttonActive == this && ((commandFactory->requiredTarget != FastEcslent::Both && commandFactory->requiredTarget != FastEcslent::TargetEntity) || mouseTargets.first != -1))));
00378         processButtonSecondEvent(!firstEvent && enabled && ((buttonWasClicked && commandFactory->requiredTarget == FastEcslent::None && this->gfx->uiMgr->buttonActive == NULL) || (this->gfx->uiMgr->buttonActive == this && ((commandFactory->requiredTarget != FastEcslent::Both && commandFactory->requiredTarget != FastEcslent::TargetEntity) || (mouseTargets.first != -1 && ( (commandFactory->targetEntityType == FastEcslent::NENTITYTYPES) || (commandFactory->targetEntityType==this->gfx->gfxNodes[mouseTargets.first].entType) )) ))));
00379     }
00380 }
00381 
00382 void OgreGFX::FEButton::show()
00383 {
00384     enabled = true;
00385     //posChanged();
00386     DEBUG(std::cout << "Name:" << this->name << std::endl;)
00387     //this->panel->show();
00388 //    this->textArea->show();
00389 }
00390 
00391 void OgreGFX::FEButton::hide()
00392 {
00393     enabled = false;
00394     //this->panel->hide();
00395     //this->textArea->hide();
00396 }
00397 //--------------------------------------------------------------------------------------------------------------------------------
00398 //--------------------------------------------------------------------------------------------------------------------------------
00399 
00400 //OgreGFX::FEButton::FEButton(GraphicsInteractionManager *gim,
00401 //                            const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00402 //                            std::string name, Widget *aparent, Ogre::ColourValue acolor,
00403 //                            Ogre::Vector2 apos, Ogre::Vector2 asize, bool (*pClickFunction)(), std::string material, std::string desc, Ogre::GuiMetricsMode defaultMode) :
00404 //FEPanel(gim,
00405 //        name, aparent,
00406 //        apos, asize,material,defaultMode), pClickFunction(pClickFunction),
00407 //MouseHandler(gim, modifierKeys, oisMouseButtonId),
00408 //pressed(false), enabled(false)//, desc(desc)
00409 //{
00410 //    this->desc = desc;
00411 //
00412 //}
00413 //
00414 //OgreGFX::FEButton::~FEButton()
00415 //{
00416 //
00417 //}
00418 //
00419 //void OgreGFX::FEButton::handleMouseEvent(const OIS::MouseEvent &args)
00420 //{
00421 //    DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00422 //    if (enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs)))
00423 //    {
00424 //        //this->color = Ogre::ColourValue(0.0, 0.0, 0.7, 0.0);
00425 //        DEBUG(std::cout << "Button pressed" << std::endl;)
00426 //        if (pClickFunction)
00427 //            pClickFunction();
00428 //    }
00429 //}
00430 //
00431 //void OgreGFX::FEButton::show()
00432 //{
00433 //    enabled = true;
00434 //    posChanged();
00435 //    DEBUG(std::cout << "Name:" << this->name << std::endl;)
00436 //    //this->panel->show();
00438 //}
00439 //
00440 //void OgreGFX::FEButton::hide()
00441 //{
00442 //    enabled = false;
00443 //    //this->panel->hide();
00444 //    //this->textArea->hide();
00445 //}
00447 //
00448 //OgreGFX::FESCVButton::FESCVButton(GraphicsInteractionManager *gim,
00449 //                                  const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00450 //                                  std::string name, Widget *aparent, Ogre::ColourValue acolor,
00451 //                                  Ogre::Vector2 apos, Ogre::Vector2 asize, Ogre::GuiMetricsMode defaultMode) :
00452 //FEButton(gim, modifierKeys, oisMouseButtonId,
00453 //         name, aparent, acolor,
00454 //         apos, asize, NULL,"Boats/SCV","SCV info",defaultMode)
00456 //{
00457 //
00458 //}
00459 //
00460 //OgreGFX::FESCVButton::~FESCVButton()
00461 //{
00462 //
00463 //}
00464 //
00465 //void OgreGFX::FESCVButton::handleMouseEvent(const OIS::MouseEvent &args)
00466 //{
00467 //    int rangex = 2000;
00468 //    int rangez = rangex;
00469 //    DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00470 //    if (enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs)))
00471 //    {
00472 //        Ogre::Vector3 spawnpos = gfx->engine->selectionMgr->primarySelection->pos;
00473 //        spawnpos.z = 500.0f;
00474 //        spawnpos.y = 0.0f;
00475 //        spawnpos.x = 500.0f;
00476 //
00477 //        FastEcslent::Entity* ent = gfx->engine->entityMgr->createEntityAfterTime(FastEcslent::SCV, Ogre::Vector3(0, 0, 0), 0.0f);
00478 //        ent->init();
00479 //        ent->pos = spawnpos;
00480 //        //z = rangez - random() % (2 * rangez);
00481 //        //x = rangex - random() % (2 * rangex);
00482 //        ent->heading = (random() % 180) * 0.0174532925;
00483 //        ent->yaw = ent->heading;
00484 //        ent->desiredHeading = ent->heading;
00485 //        ent->desiredSpeed = 0.0f;
00486 //        //std::cout << "SCVButton Manager: " << ent->uiname << std::endl;
00487 //        //        ent->print();
00488 //        //        gfx->engine->selectionMgr->primarySelection->print();
00489 //        gfx->makeNode(ent);
00490 //        gfx->nGFXNodes++;
00491 //
00492 //
00493 //        //this->color = Ogre::ColourValue(0.0, 0.0, 0.7, 0.0);
00494 //        //std::cout << "Button pressed" << std::endl;
00495 //        //if(pClickFunction)
00496 //        //    pClickFunction();
00497 //    }
00498 //}
00499 //
00501 //
00502 //OgreGFX::FEMarineButton::FEMarineButton(GraphicsInteractionManager *gim,
00503 //                                  const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00504 //                                  std::string name, Widget *aparent, Ogre::ColourValue acolor,
00505 //                                  Ogre::Vector2 apos, Ogre::Vector2 asize, Ogre::GuiMetricsMode defaultMode) :
00506 //FEButton(gim, modifierKeys, oisMouseButtonId,
00507 //         name, aparent, acolor,
00508 //         apos, asize, NULL,"Boats/MARINE", "Marine Info",defaultMode)
00510 //{
00511 //
00512 //}
00513 //
00514 //OgreGFX::FEMarineButton::~FEMarineButton()
00515 //{
00516 //
00517 //}
00518 //
00519 //void OgreGFX::FEMarineButton::handleMouseEvent(const OIS::MouseEvent &args)
00520 //{
00521 //    int rangex = 2000;
00522 //    int rangez = rangex;
00523 //    DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00524 //    if (enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs)))
00525 //    {
00526 //        Ogre::Vector3 spawnpos = gfx->engine->selectionMgr->primarySelection->pos;
00527 //        spawnpos.z = 500.0f;
00528 //        spawnpos.y = 0.0f;
00529 //        spawnpos.x = 0.0f;
00530 //
00531 //        FastEcslent::Entity* ent = gfx->engine->entityMgr->createEntityAfterTime(FastEcslent::MARINE, Ogre::Vector3(0, 0, 0), 0.0f);
00532 //        ent->init();
00533 //        ent->pos = spawnpos;
00534 //        //z = rangez - random() % (2 * rangez);
00535 //        //x = rangex - random() % (2 * rangex);
00536 //        ent->heading = (random() % 180) * 0.0174532925;
00537 //        ent->yaw = ent->heading;
00538 //        ent->desiredHeading = ent->heading;
00539 //        ent->desiredSpeed = 0.0f;
00540 //        //std::cout << "SCVButton Manager: " << ent->uiname << std::endl;
00541 //        //        ent->print();
00542 //        //        gfx->engine->selectionMgr->primarySelection->print();
00543 //        gfx->makeNode(ent);
00544 //        gfx->nGFXNodes++;
00545 //
00546 //
00547 //        //this->color = Ogre::ColourValue(0.0, 0.0, 0.7, 0.0);
00548 //        //std::cout << "Button pressed" << std::endl;
00549 //        //if(pClickFunction)
00550 //        //    pClickFunction();
00551 //    }
00552 //}
00553 
00554 //--------------------------------------------------------------------------------------------------------------------------------
00555 
00556 OgreGFX::FELabelPair::FELabelPair(GraphicsInteractionManager *gim, std::string caption1, std::string caption2, Widget *aparent,
00557                 Ogre::ColourValue color, Ogre::Vector2 apos, Ogre::Vector2 columnWidths, int columnHeight, std::string materialName, Ogre::GuiMetricsMode defaultMode):
00558                 OgreGFX::FEPanel(gim, caption1, aparent, apos, Ogre::Vector2(columnWidths.x + columnWidths.y, columnHeight), materialName, defaultMode) {
00559 
00560         this->left = new OgreGFX::FELabel(gim, caption1, this, color, apos, Ogre::Vector2(columnWidths.x, columnHeight), defaultMode);
00561         this->right = new OgreGFX::FELabel(gim, caption2, this, color, Ogre::Vector2(apos.x+columnWidths.x, apos.y), Ogre::Vector2(columnWidths.y, columnHeight),defaultMode);
00562         this->addItem(this->left, Below);
00563         this->addItem(this->right, Right);
00564 
00565 }
00566 
00567 void OgreGFX::FELabelPair::setLeft(std::string val){
00568         this->left->setCaption(val);
00569 }
00570 
00571 
00572 void OgreGFX::FELabelPair::setRight(std::string val){
00573 
00574         this->right->setCaption(val);
00575 }
00576 
00577 void OgreGFX::FELabelPair::show(){
00578         DEBUG(std::cout << "Showing labelpair" << std::endl;)
00579         this->panel->show();
00580         this->left->show();
00581         this->right->show();
00582 }
00583 
00584 void OgreGFX::FELabelPair::hide(){
00585         this->panel->hide();
00586         this->left->hide();
00587         this->right->hide();
00588 
00589 }
00590 
00591 /****************************/
00592 OgreGFX::FEProgressBar::FEProgressBar(GraphicsInteractionManager *gim, std::string name, Widget* iparent,
00593                 Ogre::Vector2 ipos, Ogre::Vector2 isize, std::string barMaterial, std::string fillMaterial,Ogre::GuiMetricsMode defaultMode):
00594                 Widget(gim, iparent, ipos, isize,defaultMode)
00595 {
00596                 this->barMaterial = barMaterial;
00597                 //this->fillMaterial = fillMaterial;
00598                 this->percentFull = 0.0f;
00599                 this->name = name;
00600                 this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00601                 this->progressBar = static_cast<Ogre::OverlayContainer*>(this->overlayManagerPtr->createOverlayElement("Panel", gfx->widgetMgr->getNextId(name)));
00602                 this->progressBar->setMetricsMode(this->mode);
00603                 this->progressBar->setPosition(pos.x, pos.y);
00604                 //size.y = 0; // or extra space when adding labels to this
00605                 this->progressBar->setDimensions(size.x, size.y);
00606                 this->progressBar->setMaterialName(barMaterial);
00607                 this->progressBar->show();
00608                 this->UpdateFillPercent();
00609 //                this->progressFill = static_cast<Ogre::OverlayContainer*>(this->overlayManagerPtr->createOverlayElement("Panel", gfx->widgetMgr->getNextId(name)));
00610 //              this->progressFill->setMetricsMode(this->mode);
00611 //              this->progressFill->setPosition(pos.x, pos.y);
00612 //              //size.y = 0; // or extra space when adding labels to this
00613 //              this->progressFill->setDimensions(size.x, size.y);
00614 //              this->progressFill->setMaterialName(fillMaterial);
00615 //              this->progressFill->show();
00616 
00617 
00618 }
00619 
00620 void OgreGFX::FEProgressBar::UpdateFillPercent()
00621 {
00622     //progressFill->setWidth(progressBar->getWidth() * percentFull);
00623     //progressBar->setWidth(this->size.x * percentFull);
00624     progressBar->setWidth(this->parent->size.x * percentFull);
00625 }
00626 
00627 void OgreGFX::FEProgressBar::show()
00628 {
00629     this->progressBar->show();
00630     //this->progressFill->show();
00631     
00632 }
00633 void OgreGFX::FEProgressBar::hide()
00634 {
00635     this->progressBar->hide();
00636     //this->progressFill->hide();    
00637 }
00638 void OgreGFX::FEProgressBar::posChanged()
00639 {
00640     this->progressBar->setPosition(this->pos.x, this->pos.y);
00641     //this->progressFill->setPosition(this->pos.x, this->pos.y);
00642 }
00643 
00644 Ogre::OverlayElement * OgreGFX::FEProgressBar::getOverlayElementToAdd(){
00645         return static_cast<Ogre::OverlayElement *>(this->progressBar);
00646 }

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