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
00017 OgreGFX::Widget::Widget(GraphicsInteractionManager *gim, Widget *aParent, Ogre::Vector2 defaultPos, Ogre::Vector2 defaultSize, Ogre::GuiMetricsMode
00018 defaultMode) {
00019
00020 if (defaultPos == Ogre::Vector2::NEGATIVE_UNIT_X)
00021 this->pos = Ogre::Vector2(0, 0);
00022 if (defaultSize == Ogre::Vector2::NEGATIVE_UNIT_X)
00023 this->size = Ogre::Vector2(100, 30);
00024 if (!aParent)
00025 this->parent = 0;
00026
00027 this->desc = "";
00028 this->gfx = gim;
00029 this->parent = aParent;
00030 this->pos = defaultPos;
00031 this->size = defaultSize;
00032 this->mode = defaultMode;
00033
00034 }
00035
00036 OgreGFX::Widget::~Widget(){
00037
00038 };
00039
00040 Ogre::Vector2 OgreGFX::Widget::screenPos(){
00041 if (this->parent) {
00042 return this->parent->screenPos() + this->pos;
00043 } else {
00044 return this->pos;
00045 }
00046 }
00047
00048 bool OgreGFX::Widget::cursonInMe(const Ogre::Vector2 &pos){
00049 Ogre::Vector2 myPos = screenPos();
00050 Ogre::Vector2 mySize = this->size;
00051
00052
00053 if(this->mode == Ogre::GMM_PIXELS)
00054 {
00055 }
00056 else if(this->mode == Ogre::GMM_RELATIVE)
00057 {
00058 myPos.x *= this->gfx->mWindow->getWidth();
00059 myPos.y *= this->gfx->mWindow->getHeight();
00060 mySize.x *= this->gfx->mWindow->getWidth();
00061 mySize.y *= this->gfx->mWindow->getHeight();
00062 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;)
00063 }
00064 return (pos.x >= myPos.x && pos.x <= myPos.x + mySize.x && pos.y >= myPos.y && pos.y <= myPos.y + mySize.y);
00065 }
00066
00067
00068
00069
00070 OgreGFX::UIOutline::UIOutline(GraphicsInteractionManager *gim) : OgreGFX::Widget(gim) {
00071
00072 this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00073 std::string nextId = gfx->widgetMgr->getNextId("OutlinePanel");
00074 this->overlay = this->overlayManagerPtr->create("UIOutline");
00075
00076
00077 Ogre::OverlayContainer* panel = static_cast<Ogre::OverlayContainer*> (this->overlayManagerPtr->createOverlayElement("Panel", nextId));
00078
00079
00080 this->pos = Ogre::Vector2(0.0, 0.0);
00081 this->size = Ogre::Vector2(gfx->mWindow->getWidth(), gfx->mWindow->getHeight());
00082 this->size = Ogre::Vector2(1.0, 1.0);
00083 panel->setPosition(pos.x, pos.y);
00084 panel->setDimensions(size.x, size.y);
00085 panel->setMaterialName("ECSLENT/UI");
00086
00087 this->overlay->add2D(static_cast<Ogre::OverlayContainer *> (panel));
00088 this->overlay->add2D(panel);
00089 DEBUG(std::cout << "Added OvelayContainer Panel" << std::endl;)
00090
00091 overlay->show();
00092
00093 }
00094
00095 void OgreGFX::UIOutline::show() {
00096 this->overlay->show();
00097 }
00098
00099 void OgreGFX::UIOutline::hide() {
00100 this->overlay->hide();
00101 }
00102
00103
00104
00105
00106 OgreGFX::FEPanel::FEPanel(GraphicsInteractionManager *gim, std::string name, Widget* iparent,
00107 Ogre::Vector2 ipos, Ogre::Vector2 isize, std::string imaterial,Ogre::GuiMetricsMode defaultMode):
00108 Widget(gim, iparent, ipos, isize,defaultMode) {
00109
00110 this->material = imaterial;
00111 this->name = name;
00112 this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00113 this->panel = static_cast<Ogre::OverlayContainer*>(this->overlayManagerPtr->createOverlayElement("Panel", gfx->widgetMgr->getNextId(name)));
00114 this->panel->setMetricsMode(this->mode);
00115 this->panel->setPosition(pos.x, pos.y);
00116
00117 this->panel->setDimensions(size.x, size.y);
00118 this->panel->setMaterialName(material);
00119 this->panel->show();
00120
00121 if (!this->parent){
00122 DEBUG(std::cout << "Creating panel overlay" << std::endl;)
00123 this->overlayPtr = this->overlayManagerPtr->create(gfx->widgetMgr->getNextId(name));
00124 this->overlayPtr->add2D(this->panel);
00125 this->overlayPtr->show();
00126 }
00127
00128 this->belowPos = Ogre::Vector2(0.0, 0.0);
00129 this->rightPos = Ogre::Vector2(0.0, 0.0);
00130 this->gap = Ogre::Vector2(0.0, 0.0);
00131 this->separatorHeight = 1;
00132
00133 };
00134
00135 OgreGFX::FEPanel::~FEPanel(){
00136
00137 }
00138
00139
00140 void OgreGFX::FEPanel::show(){
00141 if (this->parent){
00142 this->overlayPtr->show();
00143 }
00144 this->panel->show();
00145 for(std::list<Widget*>::iterator it = this->items.begin(); it != this->items.end(); ++it){
00146 (*it)->show();
00147 }
00148 }
00149
00150
00151 void OgreGFX::FEPanel::hide(){
00152 for(std::list<Widget*>::iterator it = this->items.begin(); it != this->items.end(); ++it){
00153 (*it)->hide();
00154 }
00155 this->panel->hide();
00156 if (this->parent){
00157 this->overlayPtr->hide();
00158 }
00159 }
00160
00161 Ogre::OverlayElement * OgreGFX::FEPanel::makeSep(){
00162
00163 Ogre::OverlayElement *sep = this->overlayManagerPtr->createOverlayElement("Panel", gfx->widgetMgr->getNextId("lineSep"));
00164 sep->setMetricsMode(Ogre::GMM_PIXELS);
00165 sep->setPosition(0, 0);
00166 sep->setDimensions(this->pos.x, this->separatorHeight);
00167 sep->setMaterialName("ECSLENT/line");
00168 sep->show();
00169 return sep;
00170 }
00171
00172 void OgreGFX::FEPanel::addSep(int separation){
00173 Ogre::OverlayElement *sep = makeSep();
00174 this->separators.push_back(sep);
00175 sep->setPosition(0, separation);
00176 sep->setDimensions(this->size.x, this->separatorHeight);
00177 this->panel->addChild(sep);
00178 }
00179
00180 void OgreGFX::FEPanel::adjustSeparators(){
00181 for(std::list<Ogre::OverlayElement*>::iterator it = this->separators.begin(); it != this->separators.end(); ++it){
00182 (*it)->setDimensions(this->size.x, this->separatorHeight);
00183 }
00184 }
00185
00186 void OgreGFX::FEPanel::posChanged(){
00187 this->panel->setPosition(this->pos.x, this->pos.y);
00188 for(std::list<Widget*>::iterator it = this->items.begin(); it != this->items.end(); ++it){
00189 (*it)->posChanged();
00190 }
00191
00192 }
00193
00194 void OgreGFX::FEPanel::addItem(Widget *item, Placement placement){
00195 this->items.push_back(item);
00196 if (this->size.x < item->size.x){
00197 this->size.x = item->size.x;
00198 adjustSeparators();
00199 }
00200
00201 if (placement == Below){
00202 DEBUG(std::cout << "Adding below: " << std::endl;)
00203 item->pos = this->belowPos;
00204 item->posChanged();
00205 this->rightPos = this->belowPos + Ogre::Vector2(item->size.x + this->gap.x, 0.0);
00206 this->belowPos.y += item->size.y + this->gap.y;
00207 DEBUG(std::cout << "Below Pos: " << belowPos.x << ", " << belowPos.y << std::endl;)
00208 } else if (placement == Right){
00209 item->pos = this->rightPos;
00210 item->posChanged();
00211 this->rightPos.x += item->size.x + this->gap.x;
00212 }
00213
00214 if (this->rightPos.x > this->size.x){
00215 this->size.x = this->rightPos.x;
00216 }
00217 if (this->belowPos.y > this->size.y){
00218 this->size.y = this->belowPos.y;
00219 }
00220
00221
00222 this->panel->addChild(item->getOverlayElementToAdd());
00223 this->panel->setDimensions(this->size.x, this->size.y);
00224 addSep(this->size.y);
00225
00226 }
00227
00228 Ogre::OverlayElement * OgreGFX::FEPanel::getOverlayElementToAdd(){
00229 return static_cast<Ogre::OverlayElement *>(this->panel);
00230 }
00231
00232
00233
00234 OgreGFX::FELabel::FELabel(GraphicsInteractionManager *gim,
00235 std::string caption, Widget *aparent, Ogre::ColourValue acolor,
00236 Ogre::Vector2 apos, Ogre::Vector2 asize,Ogre::GuiMetricsMode defaultMode):
00237 Widget(gim, aparent, apos, asize,defaultMode) {
00238
00239 this->overlayManagerPtr = Ogre::OverlayManager::getSingletonPtr();
00240 this->caption = caption;
00241 this->color = color;
00242 this->offset = Ogre::Vector2(5.0, 2.0);
00243 this->textArea = static_cast<Ogre::TextAreaOverlayElement*>(this->overlayManagerPtr->createOverlayElement("TextArea", gfx->widgetMgr->getNextId(caption)));
00244 this->textArea->setMetricsMode(this->mode);
00245 this->textArea->setCaption(caption);
00246 DEBUG(std::cout << "Label Size: " << size.x << ", " << size.y << std::endl;)
00247 this->textArea->setPosition(pos.x + offset.x, pos.y + offset.y);
00248 this->textArea->setDimensions(size.x, size.y);
00249 this->textArea->setFontName("SdkTrays/Value");
00250 this->textArea->setCharHeight(size.y);
00251 this->textArea->setColourBottom(Ogre::ColourValue(1.0, 1.0, 0.0, 1.0));
00252 this->textArea->setColourTop(color);
00253 this->textArea->show();
00254 }
00255
00256 OgreGFX::FELabel::~FELabel(){
00257
00258 }
00259
00260 void OgreGFX::FELabel::setCaption(std::string val){
00261 this->caption = val;
00262 this->textArea->setCaption(val);
00263 }
00264
00265
00266 void OgreGFX::FELabel::show(){
00267 DEBUG(std::cout << "Showing label" << std::endl;)
00268 this->textArea->show();
00269 }
00270
00271 void OgreGFX::FELabel::hide(){
00272 this->textArea->hide();
00273 }
00274
00275 Ogre::OverlayElement* OgreGFX::FELabel::getOverlayElementToAdd(){
00276 return static_cast<Ogre::OverlayElement*>(this->textArea);
00277 }
00278
00279 void OgreGFX::FELabel::posChanged(){
00280 this->textArea->setPosition(pos.x, pos.y);
00281 }
00282
00283
00284
00285 OgreGFX::FEButton::FEButton(GraphicsInteractionManager *gim,
00286 const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00287 std::string name, Widget *aparent, Ogre::ColourValue acolor,
00288 Ogre::Vector2 apos, Ogre::Vector2 asize, bool (*pClickFunction)(), std::string material, std::string desc, Ogre::GuiMetricsMode defaultMode) :
00289 FEPanel(gim,
00290 name, aparent,
00291 apos, asize,material,defaultMode), pClickFunction(pClickFunction),
00292 MouseHandler(gim, modifierKeys, oisMouseButtonId),
00293 pressed(false), enabled(false)
00294 {
00295 this->desc = desc;
00296
00297 }
00298
00299 OgreGFX::FEButton::~FEButton()
00300 {
00301
00302 }
00303
00304 void OgreGFX::FEButton::handleMouseEvent(const OIS::MouseEvent &args)
00305 {
00306 DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00307 if (enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs)))
00308 {
00309
00310 DEBUG(std::cout << "Button pressed" << std::endl;)
00311 if (pClickFunction)
00312 pClickFunction();
00313 }
00314 }
00315
00316 void OgreGFX::FEButton::show()
00317 {
00318 enabled = true;
00319 posChanged();
00320 DEBUG(std::cout << "Name:" << this->name << std::endl;)
00321
00322
00323 }
00324
00325 void OgreGFX::FEButton::hide()
00326 {
00327 enabled = false;
00328
00329
00330 }
00331
00332
00333 OgreGFX::FESCVButton::FESCVButton(GraphicsInteractionManager *gim,
00334 const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00335 std::string name, Widget *aparent, Ogre::ColourValue acolor,
00336 Ogre::Vector2 apos, Ogre::Vector2 asize, Ogre::GuiMetricsMode defaultMode) :
00337 FEButton(gim, modifierKeys, oisMouseButtonId,
00338 name, aparent, acolor,
00339 apos, asize, NULL,"Boats/SCV","SCV info",defaultMode)
00340
00341 {
00342
00343 }
00344
00345 OgreGFX::FESCVButton::~FESCVButton()
00346 {
00347
00348 }
00349
00350 void OgreGFX::FESCVButton::handleMouseEvent(const OIS::MouseEvent &args)
00351 {
00352 int rangex = 2000;
00353 int rangez = rangex;
00354 DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00355 if (enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs)))
00356 {
00357 Ogre::Vector3 spawnpos = gfx->engine->selectionMgr->primarySelection->pos;
00358 spawnpos.z = 500.0f;
00359 spawnpos.y = 0.0f;
00360 spawnpos.x = 500.0f;
00361
00362 FastEcslent::Entity* ent = gfx->engine->entityMgr->createEntityAfterTime(FastEcslent::SCV, Ogre::Vector3(0, 0, 0), 0.0f);
00363 ent->init();
00364 ent->pos = spawnpos;
00365
00366
00367 ent->heading = (random() % 180) * 0.0174532925;
00368 ent->yaw = ent->heading;
00369 ent->desiredHeading = ent->heading;
00370 ent->desiredSpeed = 0.0f;
00371
00372
00373
00374 gfx->makeNode(ent);
00375 gfx->nGFXNodes++;
00376
00377
00378
00379
00380
00381
00382 }
00383 }
00384
00385
00386
00387 OgreGFX::FEMarineButton::FEMarineButton(GraphicsInteractionManager *gim,
00388 const std::set<OIS::KeyCode> *modifierKeys, const OIS::MouseButtonID oisMouseButtonId,
00389 std::string name, Widget *aparent, Ogre::ColourValue acolor,
00390 Ogre::Vector2 apos, Ogre::Vector2 asize, Ogre::GuiMetricsMode defaultMode) :
00391 FEButton(gim, modifierKeys, oisMouseButtonId,
00392 name, aparent, acolor,
00393 apos, asize, NULL,"Boats/MARINE", "Marine Info",defaultMode)
00394
00395 {
00396
00397 }
00398
00399 OgreGFX::FEMarineButton::~FEMarineButton()
00400 {
00401
00402 }
00403
00404 void OgreGFX::FEMarineButton::handleMouseEvent(const OIS::MouseEvent &args)
00405 {
00406 int rangex = 2000;
00407 int rangez = rangex;
00408 DEBUG(std::cout << "Button checking:" << args.state.X.abs << "," << args.state.Y.abs << "|" << this->pos.x << "," << this->pos.y << std::endl;)
00409 if (enabled && cursonInMe(Ogre::Vector2(args.state.X.abs, args.state.Y.abs)))
00410 {
00411 Ogre::Vector3 spawnpos = gfx->engine->selectionMgr->primarySelection->pos;
00412 spawnpos.z = 500.0f;
00413 spawnpos.y = 0.0f;
00414 spawnpos.x = 0.0f;
00415
00416 FastEcslent::Entity* ent = gfx->engine->entityMgr->createEntityAfterTime(FastEcslent::MARINE, Ogre::Vector3(0, 0, 0), 0.0f);
00417 ent->init();
00418 ent->pos = spawnpos;
00419
00420
00421 ent->heading = (random() % 180) * 0.0174532925;
00422 ent->yaw = ent->heading;
00423 ent->desiredHeading = ent->heading;
00424 ent->desiredSpeed = 0.0f;
00425
00426
00427
00428 gfx->makeNode(ent);
00429 gfx->nGFXNodes++;
00430
00431
00432
00433
00434
00435
00436 }
00437 }
00438
00439
00440
00441 OgreGFX::FELabelPair::FELabelPair(GraphicsInteractionManager *gim, std::string caption1, std::string caption2, Widget *aparent,
00442 Ogre::ColourValue color, Ogre::Vector2 apos, Ogre::Vector2 columnWidths, int columnHeight, std::string materialName, Ogre::GuiMetricsMode defaultMode):
00443 OgreGFX::FEPanel(gim, caption1, aparent, apos, Ogre::Vector2(columnWidths.x + columnWidths.y, columnHeight), materialName, defaultMode) {
00444
00445 this->left = new OgreGFX::FELabel(gim, caption1, this, color, apos, Ogre::Vector2(columnWidths.x, columnHeight), defaultMode);
00446 this->right = new OgreGFX::FELabel(gim, caption2, this, color, Ogre::Vector2(apos.x+columnWidths.x, apos.y), Ogre::Vector2(columnWidths.y, columnHeight),defaultMode);
00447 this->addItem(this->left, Below);
00448 this->addItem(this->right, Right);
00449
00450 }
00451
00452 void OgreGFX::FELabelPair::setLeft(std::string val){
00453 this->left->setCaption(val);
00454 }
00455
00456
00457 void OgreGFX::FELabelPair::setRight(std::string val){
00458
00459 this->right->setCaption(val);
00460 }
00461
00462 void OgreGFX::FELabelPair::show(){
00463 DEBUG(std::cout << "Showing labelpair" << std::endl;)
00464 this->panel->show();
00465 this->left->show();
00466 this->right->show();
00467 }
00468
00469 void OgreGFX::FELabelPair::hide(){
00470 this->panel->hide();
00471 this->left->hide();
00472 this->right->hide();
00473
00474 }
00475