1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 13 /* interface header */ 14 #include "HUDDialogStack.h" 15 16 /* local implementation headers */ 17 #include "playing.h" 18 #include "HUDui.h" 19 #include "HUDDialog.h" 20 21 HUDDialogStack HUDDialogStack::globalStack; 22 HUDDialogStack()23HUDDialogStack::HUDDialogStack() 24 { 25 // do nothing 26 } 27 ~HUDDialogStack()28HUDDialogStack::~HUDDialogStack() 29 { 30 if (getMainWindow()) 31 getMainWindow()->getWindow()->removeResizeCallback(resize, this); 32 } 33 get()34HUDDialogStack* HUDDialogStack::get() 35 { 36 return &globalStack; 37 } 38 isActive() const39bool HUDDialogStack::isActive() const 40 { 41 return !stack.empty(); 42 } 43 top() const44HUDDialog* HUDDialogStack::top() const 45 { 46 const int index = stack.size(); 47 if (index == 0) return NULL; 48 return stack[index - 1]; 49 } 50 push(HUDDialog * dialog)51void HUDDialogStack::push(HUDDialog* dialog) 52 { 53 if (!dialog) return; 54 if (isActive()) 55 { 56 const int index = stack.size() - 1; 57 stack[index]->setFocus(HUDui::getFocus()); 58 stack[index]->dismiss(); 59 } 60 else 61 getMainWindow()->getWindow()->addResizeCallback(resize, this); 62 stack.push_back(dialog); 63 HUDui::setDefaultKey(dialog->getDefaultKey()); 64 HUDui::setFocus(dialog->getFocus()); 65 dialog->resize(getMainWindow()->getWidth(), getMainWindow()->getHeight()); 66 dialog->show(); 67 } 68 pop()69void HUDDialogStack::pop() 70 { 71 if (isActive()) 72 { 73 const int index = stack.size() - 1; 74 stack[index]->setFocus(HUDui::getFocus()); 75 stack[index]->dismiss(); 76 std::vector<HUDDialog*>::iterator it = stack.begin(); 77 for (int i = 0; i < index; i++) 78 ++it; 79 stack.erase(it); 80 if (index > 0) 81 { 82 HUDDialog* dialog = stack[index - 1]; 83 HUDui::setDefaultKey(dialog->getDefaultKey()); 84 HUDui::setFocus(dialog->getFocus()); 85 dialog->resize(getMainWindow()->getWidth(), 86 getMainWindow()->getHeight()); 87 dialog->show(); 88 } 89 else 90 { 91 HUDui::setDefaultKey(NULL); 92 HUDui::setFocus(NULL); 93 getMainWindow()->getWindow()->removeResizeCallback(resize, this); 94 } 95 } 96 } 97 render()98void HUDDialogStack::render() 99 { 100 if (isActive()) 101 stack[stack.size() - 1]->render(); 102 } 103 resize(void * _self)104void HUDDialogStack::resize(void* _self) 105 { 106 HUDDialogStack* self = (HUDDialogStack*)_self; 107 if (self->isActive()) 108 self->top()->resize(getMainWindow()->getWidth(), 109 getMainWindow()->getHeight()); 110 } 111 setFailedMessage(const char * msg)112void HUDDialogStack::setFailedMessage(const char *msg) 113 { 114 if (isActive()) 115 stack[stack.size() - 1]->setFailedMessage(msg); 116 } 117 118 // Local Variables: *** 119 // mode: C++ *** 120 // tab-width: 4 *** 121 // c-basic-offset: 4 *** 122 // indent-tabs-mode: nil *** 123 // End: *** 124 // ex: shiftwidth=4 tabstop=4 125