Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8688 in orxonox.OLD


Ignore:
Timestamp:
Jun 21, 2006, 10:33:24 PM (18 years ago)
Author:
bensch
Message:

added image-button a speciality of glgui to display buttons, that on push show a new Image inside a ImageWidget

Location:
branches/gui/src
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/gui/gl/Makefile.am

    r8619 r8688  
    3131                glgui_cursor.cc \
    3232                \
    33                 specials/glgui_notifier.cc
     33                specials/glgui_notifier.cc \
     34                specials/glgui_imagebutton.cc
    3435
    3536
     
    5859                glgui_cursor.h \
    5960                \
    60                 specials/glgui_notifier.h
    61 
    62 
    63 
    64 
     61                specials/glgui_notifier.h \
     62                specials/glgui_imagebutton.h
    6563
    6664EXTRA_DIST =
    67 
  • branches/gui/src/lib/gui/gl/specials/glgui_imagebutton.cc

    r8686 r8688  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL
    1717
    18 #include "glgui_notifier.h"
     18#include "glgui_imagebutton.h"
    1919#include "multi_line_text.h"
    2020
     
    2424{
    2525
    26   /**
    27    * @brief standard constructor
    28    */
    29   GLGuiNotifier::GLGuiNotifier ()
    30   {
    31     this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier");
    3226
    33     // Element2D and generals
    34     this->lineSpacing = 0;
    35     this->linesProcessed = 0;
    36     this->_fadeAge = 3.0;
    37     this->setHideAge(4.0);
    38 
    39     this->setDisplayLineCount(10);
    40   }
    41 
    42   /**
    43    * @brief standard deconstructor
    44    */
    45   GLGuiNotifier::~GLGuiNotifier ()
    46   {
    47     // delete the displayable Buffers
    48     /*    while (!this->displayLines.empty())
    49         {
    50           delete this->displayLines.front().text;
    51           this->displayLines.pop_front();
    52         }
    53 
    54         while (!this->hiddenText.empty())
    55         {
    56           delete this->hiddenText.top();
    57           this->hiddenText.pop();
    58         }*/
    59   }
    60 
    61   /**
    62    * @brief push a message onto the notifier.
    63    * @param message the message to be pushed.
    64    *
    65    * @note it is not guaranteed, that the message is delivered instantaniously
    66    * The possibility may arise, that the DisplayLines are all in use, then one
    67    * has to wait until a line gets hidden, until a new one can be pushed to be
    68    * displayed.
    69    */
    70   void GLGuiNotifier::pushNotifyMessage(const std::string& message)
    71   {
    72     if (!this->hiddenText.empty())
    73     {
    74       DisplayLine dl; // put everything in here, and then display it
    75 
    76       // retrieve a Text.
    77       dl.text = this->hiddenText.top();
    78       this->hiddenText.pop();
    79 
    80       // setup Text
    81       dl.text->setBlending(1.0f);
    82       dl.text->setText(message);
    83       dl.text->setVisibility(true);
    84       dl.text->setRelCoor2D(this->calculateLinePosition(0));
    85 
    86       dl.age = 0.0f;
    87       this->displayLines.push_front(dl);
    88       this->repositionText();
    89     }
    90     else
    91     {
    92       // push it onto the List of messages we still need.
    93       this->inputBuffer.push_front(message);
    94     }
    95   }
    96 
    97 
    98   /**
    99    * @brief sets the Dipsplay Line Count of the Notifier.
    100    * @param coun the count of displayLines.
    101    */
    102   void GLGuiNotifier::setDisplayLineCount(unsigned int count)
    103   {
    104     unsigned int currentCount = displayLines.size() + hiddenText.size();
    105 
    106     for (unsigned int i = currentCount; i < count; ++i)
    107     {
    108       MultiLineText* text = new MultiLineText();
    109       this->applyTextSettings(text);
    110       this->hiddenText.push(text);
    111     }
    112     bufferDisplaySize = count;
    113   }
    114 
    115   void GLGuiNotifier::setFadeAge(float fadeAge)
    116   {
    117     this->_fadeAge = fadeAge;
    118     this->_transformAge = hideAge() - this->fadeAge();
    119   }
    120 
    121   void GLGuiNotifier::setHideAge(float hideAge)
    122   {
    123     this->_hideAge = hideAge;
    124     this->_transformAge = this->hideAge() - fadeAge();
    125   }
    126 
    127 
    128   /**
    129    * @brief repositiones all the Texts to their position.
    130    */
    131   void GLGuiNotifier::repositionText()
    132   {
    133     int linePos = -1;
    134     std::list<DisplayLine>::iterator textIt;
    135     for (textIt = this->displayLines.begin() ; textIt != this->displayLines.end(); ++textIt )
    136     {
    137       linePos += (*textIt).text->getLineCount();
    138       (*textIt).text->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8);
    139       //      printf("%f %f\n", (*textIt).text->getAbsCoor2D().x, (*textIt).text->getAbsCoor2D().y);
    140     }
    141   }
    142 
    143 
    144   /**
    145    * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier.
    146    * @param text the Text to apply the settings to.
    147    */
    148   void GLGuiNotifier::applyTextSettings(MultiLineText* text)
    149   {
    150     text->setSize(this->textSize());
    151     text->setLineWidth( 300 );
    152     text->setFont("fonts/final_frontier.ttf", (int)this->textSize());
    153 
    154     text->setColor(this->foregroundColor() );
    155     if (text->getParent2D() != this)
    156       text->setParent2D(this);
    157   }
    158 
    159 
    160   /**
    161    * @brief ticks the entire Notifier.
    162    * @param dt the time passed since the last Tick
    163    */
    164   void GLGuiNotifier::tick(float dt)
    165   {
    166     std::list<DisplayLine>::iterator line;
    167     for (line = this->displayLines.begin() ; line != this->displayLines.end(); ++line )
    168     {
    169       (*line).age+=dt;
    170       if ((*line).age > this->fadeAge())
    171       {
    172         (*line).text->setBlending((hideAge() - (*line).age)/_transformAge);
    173         if ((*line).age > hideAge())
    174         {
    175           std::list<DisplayLine>::iterator tmp = line;
    176           ++line;
    177 
    178           (*tmp).text->setVisibility(false);
    179           this->hiddenText.push((*tmp).text);
    180           this->displayLines.erase(tmp);
    181 
    182           if (!inputBuffer.empty())
    183           {
    184             this->pushNotifyMessage(inputBuffer.back());
    185             inputBuffer.pop_back();
    186           }
    187         }
    188       }
    189     }
    190   }
    191 
    192 
    193   /**
    194    * displays the GLGuiNotifier
    195    */
    196   void GLGuiNotifier::draw() const
    197   {
    198     // transform for alignment.
    199     // setting the Blending effects
    200     this->beginDraw();
    201 
    202     this->background().select();
    203     this->drawRect(this->backRect());
    204     this->endDraw();
    205   }
    206 
    207   ///////////////////////
    208   // HELPER FUNCTIONS  //
    209   ///////////////////////
    210 
    211   /**
    212    * @brief calculates the position of a Buffer-Display Line
    213    * @param lineNumber the lineNumber from the bottom to calculate the position from
    214    * @returns the Position of the Line.
    215    */
    216   Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber)
    217   {
    218     return Vector2D(0.0f, (float)(textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));
    219   }
    220 
    221 
    222   void GLGuiNotifier::resize()
    223   {}
    224 
    225   /**
    226    * @brief displays some nice output from the GLGuiNotifier
    227    */
    228   void GLGuiNotifier::debug() const
    229   {
    230     PRINT(3)("Debugging output to console (not this shell)\n");
    231 
    232     //   if (this->pressedKey != SDLK_FIRST)
    233     //     printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
    234   }
    23527}
  • branches/gui/src/lib/gui/gl/specials/glgui_imagebutton.h

    r8686 r8688  
    77 */
    88
    9 #ifndef _GLGUI_NOTIFIER_H
    10 #define _GLGUI_NOTIFIER_H
     9#ifndef _GLGUI_IMAGEBUTTON_H
     10#define _GLGUI_IMAGEBUTTON_H
    1111
    1212#include "glgui_widget.h"
     
    1515#include <stack>
    1616
    17 // FORWARD DECLARATION
    18 class MultiLineText;
    19 class Text;
    20 
    21 //! Namespace of the GLGuiNotifier of ORXONOX.
     17//! Namespace of the GLGuiImageButton of ORXONOX.
    2218namespace OrxGui
    2319{
    24   class GLGuiNotifier : public GLGuiWidget
     20  class GLGuiImageButton : public GLGuiWidget
    2521  {
    2622  public:
    27     GLGuiNotifier();
    28     virtual ~GLGuiNotifier();
    29 
    30     void pushNotifyMessage(const std::string& message);
    31 
    32     /// Setup
    33     void setDisplayLineCount(unsigned int count);
    34     void setFadeAge(float fadeAge);
    35     void setHideAge(float hideAge);
    36 
    37     /** @returns the beginning of the Hiding process */
    38     inline float fadeAge() const { return _fadeAge; };
    39     /** @returns at what age elements should be fully hidden */
    40     inline float hideAge() const { return _hideAge; };
    41 
    42     void clear();
    43 
    44     // Element2D-functions
    45     virtual void tick(float dt);
    46     virtual void draw() const;
     23    GLGuiImageButton();
     24    virtual ~GLGuiImageButton();
    4725
    4826    void debug() const;
     
    5230
    5331  private:
    54     void repositionText();
    55     void applyTextSettings(MultiLineText* text);
    56     void applySettings();
    57     // helpers //
    58     Vector2D calculateLinePosition(unsigned int lineNumber);
    59 
    60 
    6132
    6233  private:
    63     //! structure that defines a Displayed line.
    64     typedef struct
    65     {
    66       float             age;
    67       MultiLineText*    text;
    68 
    69     } DisplayLine;
    70 
    71 
    72     float                       _fadeAge;
    73     float                       _hideAge;
    74     float                       _transformAge;
    75 
    76     unsigned int                lineSpacing;            //!< The Spacing between lines.
    77 
    78     // BUFFER
    79     unsigned int                bufferDisplaySize;      //!< The Size of the Display-buffer, in lines (not in characters).
    80     std::list<DisplayLine>      displayLines;           //!< A list of stored bufferTexts for the display of the buffer.
    81 
    82     std::stack<MultiLineText*>  hiddenText;             //!< Text that is not shown, and not used is thrown in here
    83 
    84 
    85     unsigned long               linesProcessed;         //!< How many Lines have been processed so far.
    86     std::list<std::string>      inputBuffer;            //!< The input buffer for lines that were not yet printet out, because there is too much input.
    8734
    8835  };
     
    9037}
    9138
    92 #endif /* _GLGUI_NOTIFIER_H */
     39#endif /* _GLGUI_IMAGEBUTTON_H */
  • branches/gui/src/story_entities/game_menu.cc

    r8677 r8688  
    2525
    2626#include "util/loading/load_param.h"
    27 #include "fast_factory.h"
    2827#include "util/loading/factory.h"
    29 #include "loading/resource_manager.h"
    30 
    31 #include "world_entity.h"
    32 #include "elements/image_entity.h"
    33 #include "terrain.h"
     28#include "util/loading/resource_manager.h"
     29
     30#include "graphics_engine.h"
    3431#include "camera.h"
    35 
    36 #include "graphics_engine.h"
    37 #include "object_manager.h"
    3832#include "sound_engine.h"
     33
    3934#include "sound_source.h"
    40 
    41 #include "cd_engine.h"
    4235
    4336#include "glgui.h"
     
    136129
    137130  this->optionsBox = NULL;
     131  this->generalBox = NULL;
    138132  this->audioBox = NULL;
    139133  this->videoBox = NULL;
    140134  this->controlBox = NULL;
    141135  this->levelsBox = NULL;
     136
     137  this->currentlyOpened = NULL;
    142138
    143139  return GameWorld::loadData();
     
    174170}
    175171
     172
    176173void GameMenu::showCampaigns()
    177174{
    178 
    179175  if (this->levelsBox == NULL)
    180176  {
     
    206202  }
    207203
    208   this->levelsBox->showAll();
    209   this->levelsBox->setRelCoor2D(200, 100);
    210   this->mainMenuBox->setRelCoorSoft2D(50, 100, 5);
     204  this->showSecondLevelElement(this->levelsBox);
    211205
    212206}
    213207
    214208void GameMenu::showMultiPlayer()
    215 {
    216 
    217 }
     209{}
    218210
    219211void GameMenu::showOptionsMenu()
     
    241233    }
    242234  }
    243   this->optionsBox->showAll();
    244   this->optionsBox->setRelCoor2D(200, 100);
     235
     236  this->showSecondLevelElement(this->optionsBox);
     237}
     238
     239
     240void GameMenu::showSecondLevelElement(OrxGui::GLGuiBox* element)
     241{
     242  if (this->currentlyOpened != NULL && this->currentlyOpened != element)
     243    this->currentlyOpened->hideAll();
     244
     245  element->showAll();
     246  element->setRelCoor2D(200, 100);
     247
     248  this->currentlyOpened = element;
    245249
    246250  this->mainMenuBox->setRelCoorSoft2D(50, 100, 5);
    247 
    248 }
    249 
    250 
    251 
     251}
    252252
    253253
  • branches/gui/src/story_entities/game_menu.h

    r8677 r8688  
    4646    void showOptionsMenu();
    4747
     48
    4849    void quitMenu();
    4950
     
    5455
    5556  private:
     57    void showSecondLevelElement(OrxGui::GLGuiBox* element);
     58
     59
    5660    void animateScene(float dt);
    5761    void switchMenuLayer(int layer1, int layer2);
     
    6670
    6771    OrxGui::GLGuiBox*                 optionsBox;
     72    OrxGui::GLGuiBox*                 generalBox;
    6873    OrxGui::GLGuiBox*                 audioBox;
    6974    OrxGui::GLGuiBox*                 videoBox;
    7075    OrxGui::GLGuiBox*                 controlBox;
     76
     77    OrxGui::GLGuiBox*                 currentlyOpened;
    7178
    7279    Vector                            cameraVector;
Note: See TracChangeset for help on using the changeset viewer.