00001
00002
00003
00004
00005
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
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
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){
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){
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;
00297 if(linebreaks > maxLineBreaks)
00298 {
00299 val.erase(val.begin()+(charPerLine*this->lines), val.end());
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)
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);
00336 processButtonSecondEvent(!firstEvent && enabled && commandFactory->requiredTarget == FastEcslent::None && this->gfx->uiMgr->buttonActive == NULL);
00337 }
00338 }
00339
00340 bool OgreGFX::FEButton::processButtonFirstEvent(bool buttonActivated)
00341 {
00342
00343
00344 if(buttonActivated && this->gfx->uiMgr->buttonActive == NULL && commandFactory->requiredTarget != FastEcslent::None)
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)
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;
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();
00373 bool buttonWasClicked = enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs));
00374
00375 bool firstEvent = processButtonFirstEvent(buttonWasClicked);
00376
00377
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
00386 DEBUG(std::cout << "Name:" << this->name << std::endl;)
00387
00388
00389 }
00390
00391 void OgreGFX::FEButton::hide()
00392 {
00393 enabled = false;
00394
00395
00396 }
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00438
00439
00440
00441
00442
00443
00444
00445
00447
00448
00449
00450
00451
00452
00453
00454
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00501
00502
00503
00504
00505
00506
00507
00508
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
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
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
00605 this->progressBar->setDimensions(size.x, size.y);
00606 this->progressBar->setMaterialName(barMaterial);
00607 this->progressBar->show();
00608 this->UpdateFillPercent();
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618 }
00619
00620 void OgreGFX::FEProgressBar::UpdateFillPercent()
00621 {
00622
00623
00624 progressBar->setWidth(this->parent->size.x * percentFull);
00625 }
00626
00627 void OgreGFX::FEProgressBar::show()
00628 {
00629 this->progressBar->show();
00630
00631
00632 }
00633 void OgreGFX::FEProgressBar::hide()
00634 {
00635 this->progressBar->hide();
00636
00637 }
00638 void OgreGFX::FEProgressBar::posChanged()
00639 {
00640 this->progressBar->setPosition(this->pos.x, this->pos.y);
00641
00642 }
00643
00644 Ogre::OverlayElement * OgreGFX::FEProgressBar::getOverlayElementToAdd(){
00645 return static_cast<Ogre::OverlayElement *>(this->progressBar);
00646 }