Ticket #3354: gui_cleanup.patch

File gui_cleanup.patch, 232.1 KB (added by leper, 9 years ago)
  • source/gui/CButton.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CButton
    20 */
    21 
    2218#include "precompiled.h"
    2319
    2420#include "CButton.h"
    2521
    2622#include "lib/ogl.h"
    2723
    28 
    29 //-------------------------------------------------------------------
    30 //  Constructor / Destructor
    31 //-------------------------------------------------------------------
    3224CButton::CButton()
    3325{
    3426    AddSetting(GUIST_float,                 "buffer_zone");
     
    8476    CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
    8577}
    8678
    87 void CButton::HandleMessage(SGUIMessage &Message)
     79void CButton::HandleMessage(SGUIMessage& Message)
    8880{
    8981    // Important
    9082    IGUIButtonBehavior::HandleMessage(Message);
  • source/gui/CButton.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Button
    20 
    21 --Overview--
    22 
    23     GUI Object representing a simple button
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CBUTTON
    3219#define INCLUDED_CBUTTON
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    39 //--------------------------------------------------------
    40 //  Macros
    41 //--------------------------------------------------------
    42 
    43 //--------------------------------------------------------
    44 //  Types
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Declarations
    49 //--------------------------------------------------------
    50 
    5123/**
    5224 * Button
    5325 *
     
    7042    /**
    7143     * @see IGUIObject#HandleMessage()
    7244     */
    73     virtual void HandleMessage(SGUIMessage &Message);
     45    virtual void HandleMessage(SGUIMessage& Message);
    7446
    7547    /**
    7648     * Draws the Button
     
    9062    CPos m_TextPos;
    9163};
    9264
    93 #endif
     65#endif // INCLUDED_CBUTTON
  • source/gui/CCheckBox.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CCheckBox
    20 */
    21 
    2218#include "precompiled.h"
    2319
    2420#include "CCheckBox.h"
    2521
     22#include "graphics/FontMetrics.h"
    2623#include "ps/CLogger.h"
    2724#include "ps/CStrIntern.h"
    28 #include "graphics/FontMetrics.h"
    29 
    3025
    31 //-------------------------------------------------------------------
    32 //  Constructor / Destructor
    33 //-------------------------------------------------------------------
    3426CCheckBox::CCheckBox()
    3527{
    3628    AddSetting(GUIST_float,                 "buffer_zone");
     
    9183    *m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth()-square_side, 0.f, this);
    9284}
    9385
    94 void CCheckBox::HandleMessage(SGUIMessage &Message)
     86void CCheckBox::HandleMessage(SGUIMessage& Message)
    9587{
    9688    // Important
    9789    IGUIButtonBehavior::HandleMessage(Message);
  • source/gui/CCheckBox.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Check box
    20 
    21 --Overview--
    22 
    23     GUI Object representing a check box
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CCHECKBOX
    3219#define INCLUDED_CCHECKBOX
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    39 //--------------------------------------------------------
    40 //  Macros
    41 //--------------------------------------------------------
    42 
    43 //--------------------------------------------------------
    44 //  Types
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Declarations
    49 //--------------------------------------------------------
    50 
    5123/**
    5224 * CheckBox
    5325 *
     
    7143    /**
    7244     * @see IGUIObject#HandleMessage()
    7345     */
    74     virtual void HandleMessage(SGUIMessage &Message);
     46    virtual void HandleMessage(SGUIMessage& Message);
    7547
    7648    /**
    7749     * Draws the control
     
    8658    void SetupText();
    8759};
    8860
    89 #endif
     61#endif // INCLUDED_CCHECKBOX
  • source/gui/CDropDown.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CDropDown
    20 */
    21 
    2218#include "precompiled.h"
    2319
    2420#include "CDropDown.h"
    2521
    26 #include "ps/CLogger.h"
    2722#include "lib/external_libraries/libsdl.h"
    2823#include "lib/ogl.h"
    2924#include "lib/timer.h"
     25#include "ps/CLogger.h"
    3026#include "soundmanager/ISoundManager.h"
    3127
    32 
    33 //-------------------------------------------------------------------
    34 //  Constructor / Destructor
    35 //-------------------------------------------------------------------
    36 CDropDown::CDropDown() : m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
     28CDropDown::CDropDown()
     29    : m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
    3730{
    3831    AddSetting(GUIST_float,                 "button_width");
    3932    AddSetting(GUIST_float,                 "dropdown_size");
     
    7265    CList::SetupText();
    7366}
    7467
    75 void CDropDown::HandleMessage(SGUIMessage &Message)
     68void CDropDown::HandleMessage(SGUIMessage& Message)
    7669{
    7770    // Important
    7871
     
    9689
    9790    case GUIM_MOUSE_MOTION:
    9891    {
    99         if (m_Open)
    100         {
    101             CPos mouse = GetMousePos();
     92        if (!m_Open)
     93            break;
    10294
    103             if (GetListRect().PointInside(mouse))
    104             {
    105                 bool scrollbar;
    106                 CGUIList *pList;
    107                 GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    108                 GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    109                 float scroll=0.f;
    110                 if (scrollbar)
    111                 {
    112                     scroll = GetScrollBar(0).GetPos();
    113                 }
     95        CPos mouse = GetMousePos();
    11496
    115                 CRect rect = GetListRect();
    116                 mouse.y += scroll;
    117                 int set=-1;
    118                 for (int i=0; i<(int)pList->m_Items.size(); ++i)
    119                 {
    120                     if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
    121                         mouse.y < rect.top + m_ItemsYPositions[i+1] &&
    122                         // mouse is not over scroll-bar
    123                         !(mouse.x >= GetScrollBar(0).GetOuterRect().left &&
    124                         mouse.x <= GetScrollBar(0).GetOuterRect().right))
    125                     {
    126                         set = i;
    127                     }
    128                 }
    129                
    130                 if (set != -1)
    131                 {
    132                     //GUI<int>::SetSetting(this, "selected", set);
    133                     m_ElementHighlight = set;
    134                     //UpdateAutoScroll();
    135                 }
     97        if (!GetListRect().PointInside(mouse))
     98            break;
     99
     100        bool scrollbar;
     101        CGUIList *pList;
     102        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
     103        GUI<CGUIList>::GetSettingPointer(this, "list", pList);
     104        float scroll=0.f;
     105        if (scrollbar)
     106            scroll = GetScrollBar(0).GetPos();
     107
     108        CRect rect = GetListRect();
     109        mouse.y += scroll;
     110        int set=-1;
     111        for (int i=0; i<(int)pList->m_Items.size(); ++i)
     112        {
     113            if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
     114                mouse.y < rect.top + m_ItemsYPositions[i+1] &&
     115                // mouse is not over scroll-bar
     116                !(mouse.x >= GetScrollBar(0).GetOuterRect().left &&
     117                mouse.x <= GetScrollBar(0).GetOuterRect().right))
     118            {
     119                set = i;
    136120            }
    137121        }
     122       
     123        if (set != -1)
     124        {
     125            //GUI<int>::SetSetting(this, "selected", set);
     126            m_ElementHighlight = set;
     127            //UpdateAutoScroll();
     128        }
    138129
    139130        break;
    140131    }
     
    143134    {
    144135        bool enabled;
    145136        GUI<bool>::GetSetting(this, "enabled", enabled);
    146         if (enabled)
    147         {
    148             CStrW soundPath;
    149             if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
    150                 g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    151         }
     137        if (!enabled)
     138            break;
     139
     140        CStrW soundPath;
     141        if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
     142            g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    152143        break;
    153144    }
    154145
     
    158149
    159150        bool enabled;
    160151        GUI<bool>::GetSetting(this, "enabled", enabled);
    161         if (enabled)
    162         {
    163             CStrW soundPath;
    164             if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
    165                 g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    166         }
     152        if (!enabled)
     153            break;
     154
     155        CStrW soundPath;
     156        if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
     157            g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    167158        break;
    168159    }
    169160
     
    183174
    184175        if (!m_Open)
    185176        {
    186             CGUIList *pList;
     177            CGUIList* pList;
    187178            GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    188179            if (pList->m_Items.empty())
    189180                return;
     
    193184            GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
    194185
    195186            // Start at the position of the selected item, if possible.
    196             GetScrollBar(0).SetPos( m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60);
     187            GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60);
    197188
    198189            CStrW soundPath;
    199190            if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty())
     
    242233        if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1)
    243234            break;
    244235
    245         m_ElementHighlight++;
     236        ++m_ElementHighlight;
    246237        GUI<int>::SetSetting(this, "selected", m_ElementHighlight);
    247238        break;
    248239    }
  • source/gui/CDropDown.h

     
    3333#ifndef INCLUDED_CDROPDOWN
    3434#define INCLUDED_CDROPDOWN
    3535
    36 //--------------------------------------------------------
    37 //  Includes / Compiler directives
    38 //--------------------------------------------------------
    3936#include "GUI.h"
    4037#include "CList.h"
    41 //class CList;
    42 
    43 //--------------------------------------------------------
    44 //  Macros
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Types
    49 //--------------------------------------------------------
    50 
    51 //--------------------------------------------------------
    52 //  Declarations
    53 //--------------------------------------------------------
    5438
    5539/**
    5640 * Drop Down
     
    7458    /**
    7559     * @see IGUIObject#HandleMessage()
    7660     */
    77     virtual void HandleMessage(SGUIMessage &Message);
     61    virtual void HandleMessage(SGUIMessage& Message);
    7862
    7963    /**
    8064     * Handle events manually to catch keyboard inputting.
     
    137121
    138122};
    139123
    140 #endif
     124#endif // INCLUDED_CDROPDOWN
  • source/gui/CGUI.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CGUI
    20 */
    21 
    2218#include "precompiled.h"
    2319
    24 #include <string>
    25 
    2620#include <stdarg.h>
     21#include <string>
    2722
    2823#include "GUI.h"
    2924
    3025// Types - when including them into the engine.
    3126#include "CButton.h"
    32 #include "CImage.h"
    33 #include "CText.h"
    3427#include "CCheckBox.h"
    35 #include "CRadioButton.h"
     28#include "CDropDown.h"
     29#include "CImage.h"
    3630#include "CInput.h"
    3731#include "CList.h"
    3832#include "COList.h"
    39 #include "CDropDown.h"
    4033#include "CProgressBar.h"
     34#include "CRadioButton.h"
     35#include "CText.h"
    4136#include "CTooltip.h"
    4237#include "MiniMap.h"
    43 #include "scripting/ScriptFunctions.h"
    4438
    4539#include "graphics/FontMetrics.h"
    4640#include "graphics/ShaderManager.h"
    4741#include "graphics/TextRenderer.h"
    48 #include "lib/input.h"
    49 #include "lib/bits.h"
    5042#include "i18n/L10n.h"
    51 #include "lib/timer.h"
     43#include "lib/bits.h"
     44#include "lib/input.h"
    5245#include "lib/sysdep/sysdep.h"
     46#include "lib/timer.h"
    5347#include "lib/utf8.h"
    5448#include "ps/CLogger.h"
    5549#include "ps/Filesystem.h"
    56 #include "ps/Hotkey.h"
    5750#include "ps/Globals.h"
     51#include "ps/Hotkey.h"
    5852#include "ps/Profile.h"
    5953#include "ps/Pyrogenesis.h"
    6054#include "ps/XML/Xeromyces.h"
    6155#include "renderer/Renderer.h"
     56#include "scripting/ScriptFunctions.h"
    6257#include "scriptinterface/ScriptInterface.h"
    6358
    6459extern int g_yres;
     
    7570        const char* hotkey = static_cast<const char*>(ev->ev.user.data1);
    7671        std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
    7772        if (it != m_HotkeyObjects.end())
    78         {
    79             for (size_t i = 0; i < it->second.size(); ++i)
    80             {
    81                 it->second[i]->SendEvent(GUIM_PRESSED, "press");
    82             }
    83         }
     73            for (IGUIObject* const& obj : it->second)
     74                obj->SendEvent(GUIM_PRESSED, "press");
    8475    }
    8576
    8677    else if (ev->ev.type == SDL_MOUSEMOTION)
     
    124115    // TODO Gee: (2004-09-08) Big TODO, don't do the below if the SDL_Event is something like a keypress!
    125116    try
    126117    {
    127         PROFILE( "mouse events" );
     118        PROFILE("mouse events");
    128119        // TODO Gee: Optimizations needed!
    129120        //  these two recursive function are quite overhead heavy.
    130121
     
    314305//  Constructor / Destructor
    315306//-------------------------------------------------------------------
    316307
    317 CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
     308CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
     309    : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
    318310{
    319311    m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime));
    320312    GuiScriptingInit(*m_ScriptInterface);
     
    383375    }
    384376}
    385377
    386 void CGUI::DrawSprite(const CGUISpriteInstance& Sprite,
    387                       int CellID,
    388                       const float& Z,
    389                       const CRect& Rect,
    390                       const CRect& UNUSED(Clipping))
     378void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping))
    391379{
    392380    // If the sprite doesn't exist (name == ""), don't bother drawing anything
    393381    if (Sprite.IsEmpty())
     
    402390{
    403391    // We can use the map to delete all
    404392    //  now we don't want to cancel all if one Destroy fails
    405     for (map_pObjects::iterator it = m_pAllObjects.begin(); it != m_pAllObjects.end(); ++it)
     393    for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects)
    406394    {
    407395        try
    408396        {
    409             it->second->Destroy();
     397            p.second->Destroy();
    410398        }
    411399        catch (PSERROR_GUI& e)
    412400        {
     
    415403            // TODO Gee: Handle
    416404        }
    417405
    418         delete it->second;
     406        delete p.second;
    419407    }
    420 
    421     // Clear all
    422408    m_pAllObjects.clear();
    423     for(std::map<CStr, CGUISprite*>::iterator it = m_Sprites.begin(); it != m_Sprites.end(); ++it)
    424         delete it->second;
     409
     410    for (const std::pair<CStr, CGUISprite*>& p : m_Sprites)
     411        delete p.second;
    425412    m_Sprites.clear();
    426413    m_Icons.clear();
    427414}
     
    429416void CGUI::UpdateResolution()
    430417{
    431418    // Update ALL cached
    432     GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize );
     419    GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize);
    433420}
    434421
    435422void CGUI::AddObject(IGUIObject* pObject)
     
    464451    try
    465452    {
    466453        // Fill freshly
    467         GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects );
     454        GUI<map_pObjects>::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects);
    468455    }
    469456    catch (PSERROR_GUI&)
    470457    {
     
    528515
    529516    // Some help functions
    530517    // TODO Gee: CRect => CPoint ?
    531     void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall,
     518    void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall,
    532519                         const float width, const float y,
    533                          const CSize &Size, const CStr& TextureName,
     520                         const CSize& Size, const CStr& TextureName,
    534521                         const float BufferZone, const int CellID)
    535522    {
    536523        // TODO Gee: Temp hardcoded values
     
    557544    }
    558545};
    559546
    560 SGUIText CGUI::GenerateText(const CGUIString &string,
    561                             const CStrW& FontW, const float &Width, const float &BufferZone,
    562                             const IGUIObject *pObject)
     547SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const float& Width, const float& BufferZone, const IGUIObject* pObject)
    563548{
    564549    SGUIText Text; // object we're generating
    565550
    566551    CStrIntern Font(FontW.ToUTF8());
    567552
    568     if (string.m_Words.size() == 0)
     553    if (string.m_Words.empty())
    569554        return Text;
    570555
    571556    float x=BufferZone, y=BufferZone; // drawing pointer
     
    615600            // Loop left/right
    616601            for (int j=0; j<2; ++j)
    617602            {
    618                 for (std::vector<CStr>::const_iterator it = Feedback.m_Images[j].begin();
    619                     it != Feedback.m_Images[j].end();
    620                     ++it)
     603                for (const CStr& imgname : Feedback.m_Images[j])
    621604                {
    622605                    SGUIText::SSpriteCall SpriteCall;
    623606                    SGenerateTextImage Image;
     
    631614                        _y = y;
    632615
    633616                    // Get Size from Icon database
    634                     SGUIIcon icon = GetIcon(*it);
     617                    SGUIIcon icon = GetIcon(imgname);
    635618
    636619                    CSize size = icon.m_Size;
    637620                    Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);
     
    676659                // Loop through left and right side, from and to.
    677660                for (int j=0; j<2; ++j)
    678661                {
    679                     for (std::vector<SGenerateTextImage>::const_iterator it = Images[j].begin();
    680                         it != Images[j].end();
    681                         ++it)
     662                    for (const SGenerateTextImage& img : Images[j])
    682663                    {
    683664                        // We're working with two intervals here, the image's and the line height's.
    684665                        //  let's find the union of these two.
    685666                        float union_from, union_to;
    686667
    687                         union_from = std::max(y, it->m_YFrom);
    688                         union_to = std::min(y+prelim_line_height, it->m_YTo);
     668                        union_from = std::max(y, img.m_YFrom);
     669                        union_to = std::min(y+prelim_line_height, img.m_YTo);
    689670                       
    690671                        // The union is not empty
    691672                        if (union_to > union_from)
    692673                        {
    693674                            if (j == From)
    694                                 width_range[From] = std::max(width_range[From], it->m_Indentation);
     675                                width_range[From] = std::max(width_range[From], img.m_Indentation);
    695676                            else
    696                                 width_range[To] = std::min(width_range[To], Width - it->m_Indentation);
     677                                width_range[To] = std::min(width_range[To], Width - img.m_Indentation);
    697678                        }
    698679                    }
    699680                }
     
    783764                //  x, that is what x_pointer is for.
    784765                float x_pointer=0.f;
    785766
    786                 std::vector<SGUIText::STextCall>::iterator it;
    787                 for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it)
     767                for (SGUIText::STextCall& tc : Feedback2.m_TextCalls)
    788768                {
    789                     it->m_Pos = CPos(dx + x + x_pointer, y);
     769                    tc.m_Pos = CPos(dx + x + x_pointer, y);
    790770
    791                     x_pointer += it->m_Size.cx;
     771                    x_pointer += tc.m_Size.cx;
    792772
    793                     if (it->m_pSpriteCall)
    794                     {
    795                         it->m_pSpriteCall->m_Area += it->m_Pos - CSize(0,it->m_pSpriteCall->m_Area.GetHeight());
    796                     }
     773                    if (tc.m_pSpriteCall)
     774                        tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize(0, tc.m_pSpriteCall->m_Area.GetHeight());
    797775                }
    798776
    799777                // Append X value.
     
    815793                        Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end());
    816794                        break;
    817795                    }
    818                     else
    819                     if (x > width_range[To] && j==temp_from)
     796                    else if (x > width_range[To] && j==temp_from)
    820797                    {
    821798                        from = j+1;
    822799                        // do not break, since we want it to be added to m_TextCalls
    823800                    }
    824                     else
    825                     if (x > width_range[To])
     801                    else if (x > width_range[To])
    826802                    {
    827803                        from = j;
    828804                        break;
     
    856832    return Text;
    857833}
    858834
    859 void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
    860                     const CPos &pos, const float &z, const CRect &clipping)
     835void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping)
    861836{
    862837    CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
    863838
     
    878853    textRenderer.SetClippingRect(clipping);
    879854    textRenderer.Translate(0.0f, 0.0f, z);
    880855
    881     for (std::vector<SGUIText::STextCall>::const_iterator it = Text.m_TextCalls.begin();
    882          it != Text.m_TextCalls.end();
    883          ++it)
     856    for (const SGUIText::STextCall& tc : Text.m_TextCalls)
    884857    {
    885858        // If this is just a placeholder for a sprite call, continue
    886         if (it->m_pSpriteCall)
     859        if (tc.m_pSpriteCall)
    887860            continue;
    888861
    889         CColor color = it->m_UseCustomColor ? it->m_Color : DefaultColor;
     862        CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor;
    890863
    891864        textRenderer.Color(color);
    892         textRenderer.Font(it->m_Font);
    893         textRenderer.Put((float)(int)(pos.x+it->m_Pos.x), (float)(int)(pos.y+it->m_Pos.y), &it->m_String);
     865        textRenderer.Font(tc.m_Font);
     866        textRenderer.Put((float)(int)(pos.x + tc.m_Pos.x), (float)(int)(pos.y + tc.m_Pos.y), &tc.m_String);
    894867    }
    895868
    896869    textRenderer.Render();
    897870
    898     for (std::list<SGUIText::SSpriteCall>::iterator it=Text.m_SpriteCalls.begin();
    899          it!=Text.m_SpriteCalls.end();
    900          ++it)
    901     {
    902         DrawSprite(it->m_Sprite, it->m_CellID, z, it->m_Area + pos);
    903     }
     871    for (const SGUIText::SSpriteCall& sc : Text.m_SpriteCalls)
     872        DrawSprite(sc.m_Sprite, sc.m_CellID, z, sc.m_Area + pos);
    904873
    905874    if (isClipped)
    906875        glDisable(GL_SCISSOR_TEST);
     
    908877    tech->EndPass();
    909878}
    910879
    911 bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output)
     880bool CGUI::GetPreDefinedColor(const CStr& name, CColor& Output) const
    912881{
    913     if (m_PreDefinedColors.count(name) == 0)
    914     {
     882    std::map<CStr, CColor>::const_iterator cit = m_PreDefinedColors.find(name);
     883    if (cit == m_PreDefinedColors.end())
    915884        return false;
    916     }
    917     else
    918     {
    919         Output = m_PreDefinedColors[name];
    920         return true;
    921     }
     885
     886    Output = cit->second;
     887    return true;
    922888}
    923889
    924890/**
     
    941907
    942908    try
    943909    {
    944 
    945910        if (root_name == "objects")
    946911        {
    947912            Xeromyces_ReadRootObjects(node, &XeroFile, Paths);
     
    949914            // Re-cache all values so these gets cached too.
    950915            //UpdateResolution();
    951916        }
    952         else
    953         if (root_name == "sprites")
    954         {
     917        else if (root_name == "sprites")
    955918            Xeromyces_ReadRootSprites(node, &XeroFile);
    956         }
    957         else
    958         if (root_name == "styles")
    959         {
     919        else if (root_name == "styles")
    960920            Xeromyces_ReadRootStyles(node, &XeroFile);
    961         }
    962         else
    963         if (root_name == "setup")
    964         {
     921        else if (root_name == "setup")
    965922            Xeromyces_ReadRootSetup(node, &XeroFile);
    966         }
    967923        else
    968         {
    969924            debug_warn(L"CGUI::LoadXmlFile error");
    970925            // TODO Gee: Output in log
    971         }
    972926    }
    973927    catch (PSERROR_GUI& e)
    974928    {
     
    1029983        CStr name(pFile->GetElementString(child.GetNodeName()));
    1030984
    1031985        if (name == "scrollbar")
    1032         {
    1033986            Xeromyces_ReadScrollBarStyle(child, pFile);
    1034         }
    1035         else
    1036         if (name == "icon")
    1037         {
     987        else if (name == "icon")
    1038988            Xeromyces_ReadIcon(child, pFile);
    1039         }
    1040         else
    1041         if (name == "tooltip")
    1042         {
     989        else if (name == "tooltip")
    1043990            Xeromyces_ReadTooltip(child, pFile);
    1044         }
    1045         else
    1046         if (name == "color")
    1047         {
     991        else if (name == "color")
    1048992            Xeromyces_ReadColor(child, pFile);
    1049         }
    1050993        else
    1051         {
    1052994            debug_warn(L"Invalid data - DTD shouldn't allow this");
    1053         }
    1054995    }
    1055996}
    1056997
    1057 void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
     998void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
    1058999{
    10591000    ENSURE(pParent);
    10601001
     
    10641005    XMBAttributeList attributes = Element.GetAttributes();
    10651006
    10661007    // Well first of all we need to determine the type
    1067     CStr type (attributes.GetNamedItem(pFile->GetAttributeID("type")));
     1008    CStr type(attributes.GetNamedItem(pFile->GetAttributeID("type")));
    10681009    if (type.empty())
    10691010        type = "empty";
    10701011
     
    11501091            CStr name(attr.Value);
    11511092
    11521093            // Apply the requested substitutions
    1153             for (size_t j = 0; j < NameSubst.size(); ++j)
    1154                 name.Replace(NameSubst[j].first, NameSubst[j].second);
     1094            for (const std::pair<CStr, CStr>& sub : NameSubst)
     1095                name.Replace(sub.first, sub.second);
    11551096
    11561097            object->SetName(name);
    11571098            NameSet = true;
     
    14151356    }
    14161357}
    14171358
    1418 void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
     1359void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
    14191360{
    14201361    #define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
    14211362    #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
     
    14321373
    14331374    for (int n = 0; n < count; ++n)
    14341375    {
    1435         NameSubst.push_back(std::make_pair(var, "[" + CStr::FromInt(n) + "]"));
     1376        NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]");
    14361377
    14371378        XERO_ITER_EL(Element, child)
    14381379        {
     
    14481389void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
    14491390{
    14501391    // Check for a 'file' parameter
    1451     CStrW file(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file") ).FromUTF8());
     1392    CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8());
    14521393
    14531394    // If there is a file specified, open and execute it
    14541395    if (!file.empty())
     
    14651406    }
    14661407
    14671408    // If it has a directory attribute, read all JS files in that directory
    1468     CStrW directory(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("directory") ).FromUTF8());
     1409    CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8());
    14691410    if (!directory.empty())
    14701411    {
    14711412        VfsPaths pathnames;
     
    15131454    //
    15141455
    15151456    // Get name, we know it exists because of DTD requirements
    1516     name = Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("name") );
     1457    name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name"));
    15171458
    15181459    if (m_Sprites.find(name) != m_Sprites.end())
    15191460        LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str());
     
    15531494    // Apply the effects to every image (unless the image overrides it with
    15541495    // different effects)
    15551496    if (effects)
    1556         for (std::vector<SGUIImage*>::iterator it = Sprite->m_Images.begin(); it != Sprite->m_Images.end(); ++it)
    1557             if (!(*it)->m_Effects)
    1558                 (*it)->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
     1497        for (SGUIImage* const& img : Sprite->m_Images)
     1498            if (!img->m_Effects)
     1499                img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
    15591500
    15601501    delete effects;
    15611502
     
    15661507    m_Sprites[name] = Sprite;
    15671508}
    15681509
    1569 void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent)
     1510void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent)
    15701511{
    15711512
    15721513    // Image object we're adding
     
    15921533        {
    15931534            Image->m_TextureName = VfsPath("art/textures/ui") / attr_value;
    15941535        }
    1595         else
    1596         if (attr_name == "size")
     1536        else if (attr_name == "size")
    15971537        {
    15981538            CClientArea ca;
    15991539            if (!GUI<CClientArea>::ParseString(attr_value, ca))
    16001540                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1601             else Image->m_Size = ca;
     1541            else
     1542                Image->m_Size = ca;
    16021543        }
    1603         else
    1604         if (attr_name == "texture_size")
     1544        else if (attr_name == "texture_size")
    16051545        {
    16061546            CClientArea ca;
    16071547            if (!GUI<CClientArea>::ParseString(attr_value, ca))
    16081548                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1609             else Image->m_TextureSize = ca;
     1549            else
     1550                Image->m_TextureSize = ca;
    16101551        }
    1611         else
    1612         if (attr_name == "real_texture_placement")
     1552        else if (attr_name == "real_texture_placement")
    16131553        {
    16141554            CRect rect;
    16151555            if (!GUI<CRect>::ParseString(attr_value, rect))
    16161556                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1617             else Image->m_TexturePlacementInFile = rect;
     1557            else
     1558                Image->m_TexturePlacementInFile = rect;
    16181559        }
    1619         else
    1620         if (attr_name == "cell_size")
     1560        else if (attr_name == "cell_size")
    16211561        {
    16221562            CSize size;
    16231563            if (!GUI<CSize>::ParseString(attr_value, size))
    16241564                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1625             else Image->m_CellSize = size;
     1565            else
     1566                Image->m_CellSize = size;
    16261567        }
    1627         else
    1628         if (attr_name == "fixed_h_aspect_ratio")
     1568        else if (attr_name == "fixed_h_aspect_ratio")
    16291569        {
    16301570            float val;
    16311571            if (!GUI<float>::ParseString(attr_value, val))
    16321572                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1633             else Image->m_FixedHAspectRatio = val;
     1573            else
     1574                Image->m_FixedHAspectRatio = val;
    16341575        }
    1635         else
    1636         if (attr_name == "round_coordinates")
     1576        else if (attr_name == "round_coordinates")
    16371577        {
    16381578            bool b;
    16391579            if (!GUI<bool>::ParseString(attr_value, b))
    16401580                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1641             else Image->m_RoundCoordinates = b;
     1581            else
     1582                Image->m_RoundCoordinates = b;
    16421583        }
    1643         else
    1644         if (attr_name == "wrap_mode")
     1584        else if (attr_name == "wrap_mode")
    16451585        {
    16461586            if (attr_value == L"repeat")
    16471587                Image->m_WrapMode = GL_REPEAT;
     
    16521592            else
    16531593                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    16541594        }
    1655         else
    1656         if (attr_name == "z_level")
     1595        else if (attr_name == "z_level")
    16571596        {
    16581597            float z_level;
    16591598            if (!GUI<float>::ParseString(attr_value, z_level))
    16601599                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1661             else Image->m_DeltaZ = z_level/100.f;
     1600            else
     1601                Image->m_DeltaZ = z_level/100.f;
    16621602        }
    1663         else
    1664         if (attr_name == "backcolor")
     1603        else if (attr_name == "backcolor")
    16651604        {
    16661605            CColor color;
    16671606            if (!GUI<CColor>::ParseString(attr_value, color))
    16681607                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1669             else Image->m_BackColor = color;
     1608            else
     1609                Image->m_BackColor = color;
    16701610        }
    1671         else
    1672         if (attr_name == "bordercolor")
     1611        else if (attr_name == "bordercolor")
    16731612        {
    16741613            CColor color;
    16751614            if (!GUI<CColor>::ParseString(attr_value, color))
    16761615                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1677             else Image->m_BorderColor = color;
     1616            else
     1617                Image->m_BorderColor = color;
    16781618        }
    1679         else
    1680         if (attr_name == "border")
     1619        else if (attr_name == "border")
    16811620        {
    16821621            bool b;
    16831622            if (!GUI<bool>::ParseString(attr_value, b))
    16841623                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1685             else Image->m_Border = b;
     1624            else
     1625                Image->m_Border = b;
    16861626        }
    16871627        else
    16881628        {
     
    17191659    parent.AddImage(Image);
    17201660}
    17211661
    1722 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)
     1662void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects)
    17231663{
    17241664    for (XMBAttribute attr : Element.GetAttributes())
    17251665    {
     
    18011741
    18021742        if (attr_name == "name")
    18031743            name = attr_value;
    1804         else
    1805         if (attr_name == "show_edge_buttons")
     1744        else if (attr_name == "show_edge_buttons")
    18061745        {
    18071746            bool b;
    18081747            if (!GUI<bool>::ParseString(attr_value.FromUTF8(), b))
     
    18101749            else
    18111750                scrollbar.m_UseEdgeButtons = b;
    18121751        }
    1813         if (attr_name == "width")
     1752        else if (attr_name == "width")
    18141753        {
    18151754            float f;
    18161755            if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
     
    18181757            else
    18191758                scrollbar.m_Width = f;
    18201759        }
    1821         else
    1822         if (attr_name == "minimum_bar_size")
     1760        else if (attr_name == "minimum_bar_size")
    18231761        {
    18241762            float f;
    18251763            if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
     
    18271765            else
    18281766                scrollbar.m_MinimumBarSize = f;
    18291767        }
    1830         else
    1831         if (attr_name == "maximum_bar_size")
     1768        else if (attr_name == "maximum_bar_size")
    18321769        {
    18331770            float f;
    18341771            if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
     
    18361773            else
    18371774                scrollbar.m_MaximumBarSize = f;
    18381775        }
    1839         else
    1840         if (attr_name == "sprite_button_top")
     1776        else if (attr_name == "sprite_button_top")
    18411777            scrollbar.m_SpriteButtonTop = attr_value;
    1842         else
    1843         if (attr_name == "sprite_button_top_pressed")
     1778        else if (attr_name == "sprite_button_top_pressed")
    18441779            scrollbar.m_SpriteButtonTopPressed = attr_value;
    1845         else
    1846         if (attr_name == "sprite_button_top_disabled")
     1780        else if (attr_name == "sprite_button_top_disabled")
    18471781            scrollbar.m_SpriteButtonTopDisabled = attr_value;
    1848         else
    1849         if (attr_name == "sprite_button_top_over")
     1782        else if (attr_name == "sprite_button_top_over")
    18501783            scrollbar.m_SpriteButtonTopOver = attr_value;
    1851         else
    1852         if (attr_name == "sprite_button_bottom")
     1784        else if (attr_name == "sprite_button_bottom")
    18531785            scrollbar.m_SpriteButtonBottom = attr_value;
    1854         else
    1855         if (attr_name == "sprite_button_bottom_pressed")
     1786        else if (attr_name == "sprite_button_bottom_pressed")
    18561787            scrollbar.m_SpriteButtonBottomPressed = attr_value;
    1857         else
    1858         if (attr_name == "sprite_button_bottom_disabled")
     1788        else if (attr_name == "sprite_button_bottom_disabled")
    18591789            scrollbar.m_SpriteButtonBottomDisabled = attr_value;
    1860         else
    1861         if (attr_name == "sprite_button_bottom_over")
     1790        else if (attr_name == "sprite_button_bottom_over")
    18621791            scrollbar.m_SpriteButtonBottomOver = attr_value;
    1863         else
    1864         if (attr_name == "sprite_back_vertical")
     1792        else if (attr_name == "sprite_back_vertical")
    18651793            scrollbar.m_SpriteBackVertical = attr_value;
    1866         else
    1867         if (attr_name == "sprite_bar_vertical")
     1794        else if (attr_name == "sprite_bar_vertical")
    18681795            scrollbar.m_SpriteBarVertical = attr_value;
    1869         else
    1870         if (attr_name == "sprite_bar_vertical_over")
     1796        else if (attr_name == "sprite_bar_vertical_over")
    18711797            scrollbar.m_SpriteBarVerticalOver = attr_value;
    1872         else
    1873         if (attr_name == "sprite_bar_vertical_pressed")
     1798        else if (attr_name == "sprite_bar_vertical_pressed")
    18741799            scrollbar.m_SpriteBarVerticalPressed = attr_value;
    18751800    }
    18761801
     
    19511876
    19521877    XMBAttributeList attributes = Element.GetAttributes();
    19531878
    1954     //IGUIObject* object = new CTooltip;
    19551879    CColor color;
    19561880    CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name"));
    19571881
    19581882    // Try parsing value
    19591883    CStr value(Element.GetText());
    1960     if (!value.empty())
     1884    if (value.empty())
     1885        return;
     1886
     1887    // Try setting color to value
     1888    if (!color.ParseString(value))
    19611889    {
    1962         // Try setting color to value
    1963         if (!color.ParseString(value))
    1964         {
    1965             LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
    1966         }
    1967         else
    1968         {
    1969             // input color
    1970             m_PreDefinedColors[name] = color;
    1971         }
     1890        LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
     1891        return;
    19721892    }
     1893
     1894    // input color
     1895    m_PreDefinedColors[name] = color;
    19731896}
  • source/gui/CGUI.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3232#ifndef INCLUDED_CGUI
    3333#define INCLUDED_CGUI
    3434
    35 //--------------------------------------------------------
    36 //  Includes / Compiler directives
    37 //--------------------------------------------------------
    38 // NOTE: GUI.h included at the bottom of this file (has to be after CGUI class
    39 // definition)
    40 
    4135#include "GUITooltip.h"
    4236#include "GUIbase.h"
    43 #include "scriptinterface/ScriptInterface.h"
    44 
    45 #include "ps/Shapes.h"
    4637
    4738#include "lib/input.h"
    48 
     39#include "ps/Shapes.h"
    4940#include "ps/XML/Xeromyces.h"
     41#include "scriptinterface/ScriptInterface.h"
    5042
    5143#include <boost/unordered_set.hpp>
    5244
    53 //--------------------------------------------------------
    54 //  Macros
    55 //--------------------------------------------------------
    56 
    57 //--------------------------------------------------------
    58 //  Types
    59 //--------------------------------------------------------
    60 
    61 //--------------------------------------------------------
    62 //  Error declarations
    63 //--------------------------------------------------------
    64 
    6545ERROR_TYPE(GUI, JSOpenFailed);
    6646
    67 //--------------------------------------------------------
    68 //  Declarations
    69 //--------------------------------------------------------
    70 
    7147/**
    7248 * Contains a list of values for new defaults to objects.
    7349 */
     
    145121     * @param Rect Position and Size
    146122     * @param Clipping The sprite shouldn't be drawn outside this rectangle
    147123     */
    148     void DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float &Z,
    149                     const CRect &Rect, const CRect &Clipping=CRect());
     124    void DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& Clipping=CRect());
    150125
    151126    /**
    152127     * Draw a SGUIText object
     
    157132     * @param z z value.
    158133     * @param clipping
    159134     */
    160     void DrawText(SGUIText &Text, const CColor &DefaultColor,
    161                   const CPos &pos, const float &z, const CRect &clipping);
     135    void DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping);
    162136
    163137    /**
    164138     * Clean up, call this to clean up all memory allocated
     
    252226     * @param pObject Optional parameter for error output. Used *only* if error parsing fails,
    253227     *        and we need to be able to output which object the error occured in to aid the user.
    254228     */
    255     SGUIText GenerateText(const CGUIString &Text, const CStrW& Font,
    256                           const float &Width, const float &BufferZone,
    257                           const IGUIObject *pObject=NULL);
     229    SGUIText GenerateText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone, const IGUIObject* pObject=NULL);
    258230
    259231
    260232    /**
     
    271243     * Get pre-defined color (if it exists)
    272244     * Returns false if it fails.
    273245     */
    274     bool GetPreDefinedColor(const CStr& name, CColor &Output);
     246    bool GetPreDefinedColor(const CStr& name, CColor& Output) const;
    275247   
    276248    shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; };
    277249    jsval GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); };
     
    307279     * @param str Name of object type
    308280     * @return Newly constructed IGUIObject (but constructed as a subclass)
    309281     */
    310     IGUIObject *ConstructObject(const CStr& str);
     282    IGUIObject* ConstructObject(const CStr& str);
    311283
    312284    /**
    313285     * Get Focused Object.
    314286     */
    315     IGUIObject *GetFocusedObject() { return m_FocusedObject; }
     287    IGUIObject* GetFocusedObject() { return m_FocusedObject; }
    316288
    317289public:
    318290    /**
     
    444416     *
    445417     * @see LoadXmlFile()
    446418     */
    447     void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
     419    void Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
    448420
    449421    /**
    450422     * Reads in the element \<repeat\>, which repeats its child \<object\>s
     
    452424     * 'var' enclosed in square brackets) in its descendants' names with "[0]",
    453425     * "[1]", etc.
    454426     */
    455     void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
     427    void Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth);
    456428
    457429    /**
    458430     * Reads in the element \<script\> (the XMBElement) and executes
     
    490462     *
    491463     * @see LoadXmlFile()
    492464     */
    493     void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent);
     465    void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent);
    494466
    495467    /**
    496468     * Reads in the element \<effect\> (the XMBElement) and stores the
     
    503475     *
    504476     * @see LoadXmlFile()
    505477     */
    506     void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects);
     478    void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects);
    507479
    508480    /**
    509481     * Reads in the element \<style\> (the XMBElement) and stores the
     
    671643    std::map<CStr, SGUIIcon> m_Icons;
    672644};
    673645
    674 #endif
     646#endif // INCLUDED_CGUI
  • source/gui/CGUIScrollBarVertical.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 IGUIScrollBar
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
     19
    2420#include "CGUIScrollBarVertical.h"
     21
     22#include "GUI.h"
     23
    2524#include "ps/CLogger.h"
    2625
    2726
     
    3332{
    3433}
    3534
    36 void CGUIScrollBarVertical::SetPosFromMousePos(const CPos &mouse)
     35void CGUIScrollBarVertical::SetPosFromMousePos(const CPos& mouse)
    3736{
    3837    if (!GetStyle())
    3938        return;
     
    8281                else
    8382                    button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop);
    8483            }
    85             else button_top = &GetStyle()->m_SpriteButtonTop;
     84            else
     85                button_top = &GetStyle()->m_SpriteButtonTop;
    8686
    8787            // figure out what sprite to use for bottom button
    8888            if (m_ButtonPlusHovered)
     
    9292                else
    9393                    button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom);
    9494            }
    95             else button_bottom = &GetStyle()->m_SpriteButtonBottom;
     95            else
     96                button_bottom = &GetStyle()->m_SpriteButtonBottom;
    9697           
    9798            // Draw top button
    9899            GetGUI()->DrawSprite(*button_top,
     
    123124    }
    124125}
    125126
    126 void CGUIScrollBarVertical::HandleMessage(SGUIMessage &Message)
     127void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message)
    127128{
    128129    IGUIScrollBar::HandleMessage(Message);
    129130}
     
    167168    return ret;
    168169}
    169170
    170 bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos &mouse)
     171bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos& mouse)
    171172{
    172173    if (!GetStyle())
    173174        return false;
     
    180181            mouse.y <= m_Y + GetStyle()->m_Width);
    181182}
    182183
    183 bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos &mouse)
     184bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos& mouse)
    184185{
    185186    if (!GetStyle())
    186187        return false;
  • source/gui/CGUIScrollBarVertical.h

     
    3737#ifndef INCLUDED_CGUISCROLLBARVERTICAL
    3838#define INCLUDED_CGUISCROLLBARVERTICAL
    3939
    40 //--------------------------------------------------------
    41 //  Includes / Compiler directives
    42 //--------------------------------------------------------
    4340#include "IGUIScrollBar.h"
    4441#include "GUI.h"
    4542
    46 //--------------------------------------------------------
    47 //  Declarations
    48 //--------------------------------------------------------
    49 
    5043/**
    5144 * Vertical implementation of IGUIScrollBar
    5245 *
    5346 * @see IGUIScrollBar
    5447 */
    55  class CGUIScrollBarVertical : public IGUIScrollBar
     48class CGUIScrollBarVertical : public IGUIScrollBar
    5649{
    5750public:
    5851    CGUIScrollBarVertical();
     
    7164     *
    7265     * @see IGUIObject#HandleMessage()
    7366     */
    74     virtual void HandleMessage(SGUIMessage &Message);
     67    virtual void HandleMessage(SGUIMessage& Message);
    7568
    7669    /**
    7770     * Set m_Pos with g_mouse_x/y input, i.e. when dragging.
    7871     */
    79     virtual void SetPosFromMousePos(const CPos &mouse);
     72    virtual void SetPosFromMousePos(const CPos& mouse);
    8073
    8174    /**
    8275     * @see IGUIScrollBar#HoveringButtonMinus
    8376     */
    84     virtual bool HoveringButtonMinus(const CPos &mouse);
     77    virtual bool HoveringButtonMinus(const CPos& mouse);
    8578
    8679    /**
    8780     * @see IGUIScrollBar#HoveringButtonPlus
    8881     */
    89     virtual bool HoveringButtonPlus(const CPos &mouse);
     82    virtual bool HoveringButtonPlus(const CPos& mouse);
    9083
    9184    /**
    9285     * Set Right Aligned
    9386     * @param align Alignment
    9487     */
    95     void SetRightAligned(const bool &align) { m_RightAligned = align; }
     88    void SetRightAligned(const bool& align) { m_RightAligned = align; }
    9689
    9790    /**
    9891     * Get the rectangle of the actual BAR.
     
    115108    bool m_RightAligned;
    116109};
    117110
    118 #endif
     111#endif // INCLUDED_CGUISCROLLBARVERTICAL
  • source/gui/CGUISprite.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1616 */
    1717
    1818#include "precompiled.h"
     19
    1920#include "CGUISprite.h"
    2021
    2122CGUISprite::~CGUISprite()
    2223{
    23     for (std::vector<SGUIImage*>::iterator it = m_Images.begin(); it != m_Images.end(); it++)
    24     {
    25         delete *it;
    26     }
     24    for (SGUIImage* const& img : m_Images)
     25        delete img;
    2726}
    2827
    2928void CGUISprite::AddImage(SGUIImage* image)
     
    3130    m_Images.push_back(image);
    3231}
    3332
    34 void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*> &Sprites, float Z) const
     33void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const
    3534{
    3635    if (m_CachedSize != Size || m_CachedCellID != CellID)
    3736    {
     
    5049
    5150bool CGUISpriteInstance::IsEmpty() const
    5251{
    53     return m_SpriteName=="";
     52    return m_SpriteName.empty();
    5453}
    5554
    5655// Plus a load of constructors / assignment operators, which don't copy the
     
    6766{
    6867}
    6968
    70 CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance &Sprite)
     69CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance& Sprite)
    7170    : m_SpriteName(Sprite.m_SpriteName), m_CachedCellID(-1)
    7271{
    7372}
    7473
    75 CGUISpriteInstance &CGUISpriteInstance::operator=(const CStr& SpriteName)
     74CGUISpriteInstance& CGUISpriteInstance::operator=(const CStr& SpriteName)
    7675{
    7776    m_SpriteName = SpriteName;
    7877    m_DrawCallCache.clear();
  • source/gui/CGUISprite.h

     
    3737#ifndef INCLUDED_CGUISPRITE
    3838#define INCLUDED_CGUISPRITE
    3939
    40 //--------------------------------------------------------
    41 //  Includes / Compiler directives
    42 //--------------------------------------------------------
    4340#include "GUIbase.h"
    4441
    4542#include "lib/res/graphics/ogl_tex.h"
    4643
    47 //--------------------------------------------------------
    48 //  Macros
    49 //--------------------------------------------------------
    50 
    51 //--------------------------------------------------------
    52 //  Types
    53 //--------------------------------------------------------
    54 
    55 //--------------------------------------------------------
    56 //  Error declarations
    57 //--------------------------------------------------------
    58 
    59 //--------------------------------------------------------
    60 //  Declarations
    61 //--------------------------------------------------------
    62 
    63 
    6444struct SGUIImageEffects
    6545{
    6646    SGUIImageEffects() : m_Greyscale(false) {}
     
    7454 */
    7555struct SGUIImage
    7656{
     57    NONCOPYABLE(SGUIImage);
     58public:
    7759    SGUIImage() :
    7860        m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT),
    7961        m_Effects(NULL), m_Border(false), m_DeltaZ(0.f)
     
    138120     * way of declaring delta-z.
    139121     */
    140122    float           m_DeltaZ;
    141 
    142     NONCOPYABLE(SGUIImage);
    143123};
    144124
    145125/**
     
    153133 */
    154134class CGUISprite
    155135{
     136    NONCOPYABLE(CGUISprite);
    156137public:
    157138    CGUISprite() {}
    158139    virtual ~CGUISprite();
     
    166147
    167148    /// List of images
    168149    std::vector<SGUIImage*> m_Images;
    169 
    170     NONCOPYABLE(CGUISprite);
    171150};
    172151
    173152#include "GUIRenderer.h"
     
    180159public:
    181160    CGUISpriteInstance();
    182161    CGUISpriteInstance(const CStr& SpriteName);
    183     CGUISpriteInstance(const CGUISpriteInstance &Sprite);
    184     CGUISpriteInstance &operator=(const CStr& SpriteName);
     162    CGUISpriteInstance(const CGUISpriteInstance& Sprite);
     163    CGUISpriteInstance& operator=(const CStr& SpriteName);
    185164    void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const;
    186165    void Invalidate();
    187166    bool IsEmpty() const;
     
    198177    mutable int m_CachedCellID;
    199178};
    200179
    201 #endif
     180#endif // INCLUDED_CGUISPRITE
  • source/gui/CImage.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CImage
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
     19
    2420#include "CImage.h"
    2521
    26 #include "lib/ogl.h"
     22#include "GUI.h"
    2723
     24#include "lib/ogl.h"
    2825
    29 //-------------------------------------------------------------------
    30 //  Constructor / Destructor
    31 //-------------------------------------------------------------------
    3226CImage::CImage()
    3327{
    3428    AddSetting(GUIST_CGUISpriteInstance,    "sprite");
     
    4337
    4438void CImage::Draw()
    4539{
    46     if (GetGUI())
    47     {
    48         float bz = GetBufferedZ();
     40    if (!GetGUI())
     41        return;
     42
     43    float bz = GetBufferedZ();
    4944
    50         CGUISpriteInstance *sprite;
    51         int cell_id;
    52         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
    53         GUI<int>::GetSetting(this, "cell_id", cell_id);
     45    CGUISpriteInstance* sprite;
     46    int cell_id;
     47    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
     48    GUI<int>::GetSetting(this, "cell_id", cell_id);
    5449
    55         GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
    56     }
     50    GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
    5751}
  • source/gui/CImage.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Image object
    20 
    21 --Overview--
    22 
    23     GUI Object for just drawing a sprite.
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CIMAGE
    3219#define INCLUDED_CIMAGE
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    39 //--------------------------------------------------------
    40 //  Macros
    41 //--------------------------------------------------------
    42 
    43 //--------------------------------------------------------
    44 //  Types
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Declarations
    49 //--------------------------------------------------------
    50 
    5123/**
    5224 * Object just for drawing a sprite. Like CText, without the
    5325 * possibility to draw text.
     
    7547    virtual void Draw();
    7648};
    7749
    78 #endif
     50#endif // INCLUDED_CIMAGE
  • source/gui/CInput.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CInput
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
     19
    2420#include "CInput.h"
     21
    2522#include "CGUIScrollBarVertical.h"
     23#include "GUI.h"
    2624
    2725#include "graphics/FontMetrics.h"
    2826#include "graphics/ShaderManager.h"
    2927#include "graphics/TextRenderer.h"
    30 #include "lib/ogl.h"
    3128#include "lib/external_libraries/libsdl.h"
     29#include "lib/ogl.h"
    3230#include "lib/sysdep/clipboard.h"
    3331#include "lib/timer.h"
    3432#include "lib/utf8.h"
     
    4240
    4341extern int g_yres;
    4442
    45 //-------------------------------------------------------------------
    46 //  Constructor / Destructor
    47 //-------------------------------------------------------------------
    4843CInput::CInput()
    4944    : m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
    5045    m_PrevTime(0.0), m_CursorVisState(true), m_CursorBlinkRate(0.5), m_ComposingText(false),
     
    7166    CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate);
    7267
    7368    // Add scroll-bar
    74     CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
     69    CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
    7570    bar->SetRightAligned(true);
    7671    AddScrollBar(bar);
    7772}
     
    8883
    8984void CInput::ClearComposedText()
    9085{
    91     CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     86    CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    9287    pCaption->erase(m_iInsertPos, m_iComposedLength);
    9388    m_iBufferPos = m_iInsertPos;
    9489    UpdateBufferPositionSetting();
     
    210205
    211206        switch (szChar)
    212207        {
    213             case SDLK_TAB: // '\t'
    214                 /* Auto Complete */
    215                 // We just send the tab event to JS and let it figure out autocomplete.
    216                 SendEvent(GUIM_TAB, "tab");
    217                 break;
    218 
    219             case SDLK_BACKSPACE: // '\b'
    220                 m_WantedX=0.0f;
    221 
    222                 if (SelectingText())
    223                     DeleteCurSelection();
    224                 else
    225                 {
    226                     m_iBufferPos_Tail = -1;
    227 
    228                     if (pCaption->empty() || m_iBufferPos == 0)
    229                     {
    230                         break;
    231                     }
    232                     else
    233                     {
    234                         if (m_iBufferPos == (int)pCaption->length())
    235                             *pCaption = pCaption->Left( (long) pCaption->length()-1);
    236                         else
    237                             *pCaption = pCaption->Left( m_iBufferPos-1 ) +
    238                                         pCaption->Right( (long) pCaption->length()-m_iBufferPos );
    239 
    240                         --m_iBufferPos;
     208        case SDLK_TAB: // '\t'
     209            /* Auto Complete */
     210            // We just send the tab event to JS and let it figure out autocomplete.
     211            SendEvent(GUIM_TAB, "tab");
     212            break;
    241213
    242                         UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    243                     }
    244                 }
     214        case SDLK_BACKSPACE: // '\b'
     215            m_WantedX=0.0f;
    245216
    246                 UpdateAutoScroll();
    247                 break;
     217            if (SelectingText())
     218                DeleteCurSelection();
     219            else
     220            {
     221                m_iBufferPos_Tail = -1;
    248222
    249             case SDLK_DELETE:
    250                 m_WantedX=0.0f;
    251                 // If selection:
    252                 if (SelectingText())
     223                if (pCaption->empty() || m_iBufferPos == 0)
    253224                {
    254                     DeleteCurSelection();
     225                    break;
    255226                }
    256227                else
    257228                {
    258                     if (pCaption->empty() || m_iBufferPos == (int)pCaption->length())
    259                     {
    260                         break;
    261                     }
     229                    if (m_iBufferPos == (int)pCaption->length())
     230                        *pCaption = pCaption->Left((long)pCaption->length()-1);
    262231                    else
    263                     {
    264                         *pCaption = pCaption->Left( m_iBufferPos ) +
    265                                     pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) );
    266 
    267                         UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    268                     }
    269                 }
     232                        *pCaption = pCaption->Left(m_iBufferPos-1) +
     233                                    pCaption->Right((long)pCaption->length()-m_iBufferPos);
    270234
    271                 UpdateAutoScroll();
    272                 break;
     235                    --m_iBufferPos;
    273236
    274             case SDLK_HOME:
    275                 // If there's not a selection, we should create one now
    276                 if (!shiftKeyPressed)
    277                 {
    278                     // Make sure a selection isn't created.
    279                     m_iBufferPos_Tail = -1;
    280                 }
    281                 else if (!SelectingText())
    282                 {
    283                     // Place tail at the current point:
    284                     m_iBufferPos_Tail = m_iBufferPos;
     237                    UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    285238                }
     239            }
    286240
    287                 m_iBufferPos = 0;
    288                 m_WantedX=0.0f;
    289 
    290                 UpdateAutoScroll();
    291                 break;
     241            UpdateAutoScroll();
     242            break;
    292243
    293             case SDLK_END:
    294                 // If there's not a selection, we should create one now
    295                 if (!shiftKeyPressed)
     244        case SDLK_DELETE:
     245            m_WantedX=0.0f;
     246            // If selection:
     247            if (SelectingText())
     248            {
     249                DeleteCurSelection();
     250            }
     251            else
     252            {
     253                if (pCaption->empty() || m_iBufferPos == (int)pCaption->length())
    296254                {
    297                     // Make sure a selection isn't created.
    298                     m_iBufferPos_Tail = -1;
     255                    break;
    299256                }
    300                 else if (!SelectingText())
     257                else
    301258                {
    302                     // Place tail at the current point:
    303                     m_iBufferPos_Tail = m_iBufferPos;
     259                    *pCaption = pCaption->Left(m_iBufferPos) +
     260                                pCaption->Right((long)pCaption->length()-(m_iBufferPos+1));
     261
     262                    UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    304263                }
     264            }
    305265
    306                 m_iBufferPos = (long) pCaption->length();
    307                 m_WantedX=0.0f;
     266            UpdateAutoScroll();
     267            break;
    308268
    309                 UpdateAutoScroll();
    310                 break;
     269        case SDLK_HOME:
     270            // If there's not a selection, we should create one now
     271            if (!shiftKeyPressed)
     272            {
     273                // Make sure a selection isn't created.
     274                m_iBufferPos_Tail = -1;
     275            }
     276            else if (!SelectingText())
     277            {
     278                // Place tail at the current point:
     279                m_iBufferPos_Tail = m_iBufferPos;
     280            }
    311281
    312             /**
    313                 Conventions for Left/Right when text is selected:
     282            m_iBufferPos = 0;
     283            m_WantedX=0.0f;
    314284
    315                 References:
     285            UpdateAutoScroll();
     286            break;
    316287
    317                 Visual Studio
    318                     Visual Studio has the 'newer' approach, used by newer versions of
    319                     things, and in newer applications. A left press will always place
    320                     the pointer on the left edge of the selection, and then of course
    321                     remove the selection. Right will do the exakt same thing.
    322                     If you have the pointer on the right edge and press right, it will
    323                     in other words just remove the selection.
     288        case SDLK_END:
     289            // If there's not a selection, we should create one now
     290            if (!shiftKeyPressed)
     291            {
     292                // Make sure a selection isn't created.
     293                m_iBufferPos_Tail = -1;
     294            }
     295            else if (!SelectingText())
     296            {
     297                // Place tail at the current point:
     298                m_iBufferPos_Tail = m_iBufferPos;
     299            }
    324300
    325                 Windows (eg. Notepad)
    326                     A left press always takes the pointer a step to the left and
    327                     removes the selection as if it were never there in the first place.
    328                     Right of course does the same thing but to the right.
     301            m_iBufferPos = (long) pCaption->length();
     302            m_WantedX=0.0f;
    329303
    330                 I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN
    331                 Messenger.
     304            UpdateAutoScroll();
     305            break;
    332306
    333             **/
    334             case SDLK_LEFT:
    335                 m_WantedX=0.f;
     307        /**
     308            Conventions for Left/Right when text is selected:
    336309
    337                 if (shiftKeyPressed || !SelectingText())
    338                 {
    339                     if (!shiftKeyPressed)
    340                     {
    341                         m_iBufferPos_Tail = -1;
    342                     }
    343                     else if (!SelectingText())
    344                     {
    345                         m_iBufferPos_Tail = m_iBufferPos;
    346                     }
     310            References:
    347311
    348                     if (m_iBufferPos > 0)
    349                         --m_iBufferPos;
    350                 }
    351                 else
    352                 {
    353                     if (m_iBufferPos_Tail < m_iBufferPos)
    354                         m_iBufferPos = m_iBufferPos_Tail;
     312            Visual Studio
     313                Visual Studio has the 'newer' approach, used by newer versions of
     314                things, and in newer applications. A left press will always place
     315                the pointer on the left edge of the selection, and then of course
     316                remove the selection. Right will do the exakt same thing.
     317                If you have the pointer on the right edge and press right, it will
     318                in other words just remove the selection.
    355319
    356                     m_iBufferPos_Tail = -1;
    357                 }
     320            Windows (eg. Notepad)
     321                A left press always takes the pointer a step to the left and
     322                removes the selection as if it were never there in the first place.
     323                Right of course does the same thing but to the right.
    358324
    359                 UpdateAutoScroll();
    360                 break;
     325            I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN
     326            Messenger.
    361327
    362             case SDLK_RIGHT:
    363                 m_WantedX=0.0f;
     328        **/
     329        case SDLK_LEFT:
     330            m_WantedX=0.f;
    364331
    365                 if (shiftKeyPressed || !SelectingText())
     332            if (shiftKeyPressed || !SelectingText())
     333            {
     334                if (!shiftKeyPressed)
    366335                {
    367                     if (!shiftKeyPressed)
    368                     {
    369                         m_iBufferPos_Tail = -1;
    370                     }
    371                     else if (!SelectingText())
    372                     {
    373                         m_iBufferPos_Tail = m_iBufferPos;
    374                     }
    375 
    376                     if (m_iBufferPos < (int)pCaption->length())
    377                         ++m_iBufferPos;
     336                    m_iBufferPos_Tail = -1;
    378337                }
    379                 else
     338                else if (!SelectingText())
    380339                {
    381                     if (m_iBufferPos_Tail > m_iBufferPos)
    382                         m_iBufferPos = m_iBufferPos_Tail;
    383 
    384                     m_iBufferPos_Tail = -1;
     340                    m_iBufferPos_Tail = m_iBufferPos;
    385341                }
    386342
    387                 UpdateAutoScroll();
    388                 break;
    389 
    390             /**
    391                 Conventions for Up/Down when text is selected:
    392 
    393                 References:
     343                if (m_iBufferPos > 0)
     344                    --m_iBufferPos;
     345            }
     346            else
     347            {
     348                if (m_iBufferPos_Tail < m_iBufferPos)
     349                    m_iBufferPos = m_iBufferPos_Tail;
    394350
    395                 Visual Studio
    396                     Visual Studio has a very strange approach, down takes you below the
    397                     selection to the next row, and up to the one prior to the whole
    398                     selection. The weird part is that it is always aligned as the
    399                     'pointer'. I decided this is to much work for something that is
    400                     a bit arbitrary
     351                m_iBufferPos_Tail = -1;
     352            }
    401353
    402                 Windows (eg. Notepad)
    403                     Just like with left/right, the selection is destroyed and it moves
    404                     just as if there never were a selection.
     354            UpdateAutoScroll();
     355            break;
    405356
    406                 I chose the Notepad convention even though I use the VS convention with
    407                 left/right.
     357        case SDLK_RIGHT:
     358            m_WantedX=0.0f;
    408359
    409             **/
    410             case SDLK_UP:
     360            if (shiftKeyPressed || !SelectingText())
    411361            {
    412362                if (!shiftKeyPressed)
    413363                {
     
    418368                    m_iBufferPos_Tail = m_iBufferPos;
    419369                }
    420370
    421                 std::list<SRow>::iterator current = m_CharacterPositions.begin();
    422                 while (current != m_CharacterPositions.end())
    423                 {
    424                     if (m_iBufferPos >= current->m_ListStart &&
    425                         m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
    426                         break;
     371                if (m_iBufferPos < (int)pCaption->length())
     372                    ++m_iBufferPos;
     373            }
     374            else
     375            {
     376                if (m_iBufferPos_Tail > m_iBufferPos)
     377                    m_iBufferPos = m_iBufferPos_Tail;
    427378
    428                     ++current;
    429                 }
     379                m_iBufferPos_Tail = -1;
     380            }
     381
     382            UpdateAutoScroll();
     383            break;
    430384
    431                 float pos_x;
     385        /**
     386            Conventions for Up/Down when text is selected:
    432387
    433                 if (m_iBufferPos-current->m_ListStart == 0)
    434                     pos_x = 0.f;
    435                 else
    436                     pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1];
     388            References:
    437389
    438                 if (m_WantedX > pos_x)
    439                     pos_x = m_WantedX;
     390            Visual Studio
     391                Visual Studio has a very strange approach, down takes you below the
     392                selection to the next row, and up to the one prior to the whole
     393                selection. The weird part is that it is always aligned as the
     394                'pointer'. I decided this is to much work for something that is
     395                a bit arbitrary
    440396
    441                 // Now change row:
    442                 if (current != m_CharacterPositions.begin())
    443                 {
    444                     --current;
     397            Windows (eg. Notepad)
     398                Just like with left/right, the selection is destroyed and it moves
     399                just as if there never were a selection.
    445400
    446                     // Find X-position:
    447                     m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
    448                 }
    449                 // else we can't move up
     401            I chose the Notepad convention even though I use the VS convention with
     402            left/right.
    450403
    451                 UpdateAutoScroll();
     404        **/
     405        case SDLK_UP:
     406        {
     407            if (!shiftKeyPressed)
     408            {
     409                m_iBufferPos_Tail = -1;
     410            }
     411            else if (!SelectingText())
     412            {
     413                m_iBufferPos_Tail = m_iBufferPos;
    452414            }
    453                 break;
    454415
    455             case SDLK_DOWN:
     416            std::list<SRow>::iterator current = m_CharacterPositions.begin();
     417            while (current != m_CharacterPositions.end())
    456418            {
    457                 if (!shiftKeyPressed)
    458                 {
    459                     m_iBufferPos_Tail = -1;
    460                 }
    461                 else if (!SelectingText())
    462                 {
    463                     m_iBufferPos_Tail = m_iBufferPos;
    464                 }
     419                if (m_iBufferPos >= current->m_ListStart &&
     420                    m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
     421                    break;
    465422
    466                 std::list<SRow>::iterator current = m_CharacterPositions.begin();
    467                 while (current != m_CharacterPositions.end())
    468                 {
    469                     if (m_iBufferPos >= current->m_ListStart &&
    470                         m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
    471                         break;
     423                ++current;
     424            }
    472425
    473                     ++current;
    474                 }
     426            float pos_x;
     427
     428            if (m_iBufferPos-current->m_ListStart == 0)
     429                pos_x = 0.f;
     430            else
     431                pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1];
    475432
    476                 float pos_x;
     433            if (m_WantedX > pos_x)
     434                pos_x = m_WantedX;
    477435
    478                 if (m_iBufferPos-current->m_ListStart == 0)
    479                     pos_x = 0.f;
    480                 else
    481                     pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1];
     436            // Now change row:
     437            if (current != m_CharacterPositions.begin())
     438            {
     439                --current;
     440
     441                // Find X-position:
     442                m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
     443            }
     444            // else we can't move up
    482445
    483                 if (m_WantedX > pos_x)
    484                     pos_x = m_WantedX;
     446            UpdateAutoScroll();
     447            break;
     448        }
     449
     450        case SDLK_DOWN:
     451        {
     452            if (!shiftKeyPressed)
     453            {
     454                m_iBufferPos_Tail = -1;
     455            }
     456            else if (!SelectingText())
     457            {
     458                m_iBufferPos_Tail = m_iBufferPos;
     459            }
     460
     461            std::list<SRow>::iterator current = m_CharacterPositions.begin();
     462            while (current != m_CharacterPositions.end())
     463            {
     464                if (m_iBufferPos >= current->m_ListStart &&
     465                    m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
     466                    break;
    485467
    486                 // Now change row:
    487                 // Add first, so we can check if it's .end()
    488468                ++current;
    489                 if (current != m_CharacterPositions.end())
    490                 {
    491                     // Find X-position:
    492                     m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
    493                 }
    494                 // else we can't move up
     469            }
     470
     471            float pos_x;
     472
     473            if (m_iBufferPos-current->m_ListStart == 0)
     474                pos_x = 0.f;
     475            else
     476                pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1];
    495477
    496                 UpdateAutoScroll();
     478            if (m_WantedX > pos_x)
     479                pos_x = m_WantedX;
     480
     481            // Now change row:
     482            // Add first, so we can check if it's .end()
     483            ++current;
     484            if (current != m_CharacterPositions.end())
     485            {
     486                // Find X-position:
     487                m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
    497488            }
    498                 break;
     489            // else we can't move up
    499490
    500             case SDLK_PAGEUP:
    501                 GetScrollBar(0).ScrollMinusPlenty();
    502                 break;
     491            UpdateAutoScroll();
     492            break;
     493        }
    503494
    504             case SDLK_PAGEDOWN:
    505                 GetScrollBar(0).ScrollPlusPlenty();
    506                 break;
    507             /* END: Message History Lookup */
     495        case SDLK_PAGEUP:
     496            GetScrollBar(0).ScrollMinusPlenty();
     497            break;
    508498
    509             case SDLK_KP_ENTER:
    510             case SDLK_RETURN:
    511                 // 'Return' should do a Press event for single liners (e.g. submitting forms)
    512                 //  otherwise a '\n' character will be added.
    513                 {
    514                 bool multiline;
    515                 GUI<bool>::GetSetting(this, "multiline", multiline);
    516                 if (!multiline)
    517                 {
    518                     SendEvent(GUIM_PRESSED, "press");
    519                     break;
    520                 }
     499        case SDLK_PAGEDOWN:
     500            GetScrollBar(0).ScrollPlusPlenty();
     501            break;
     502        /* END: Message History Lookup */
    521503
    522                 cooked = '\n'; // Change to '\n' and do default:
    523                 // NOTE: Fall-through
    524                 }
    525             default: //Insert a character
    526                 {
     504        case SDLK_KP_ENTER:
     505        case SDLK_RETURN:
     506            // 'Return' should do a Press event for single liners (e.g. submitting forms)
     507            //  otherwise a '\n' character will be added.
     508        {
     509            bool multiline;
     510            GUI<bool>::GetSetting(this, "multiline", multiline);
     511            if (!multiline)
     512            {
     513                SendEvent(GUIM_PRESSED, "press");
     514                break;
     515            }
     516
     517            cooked = '\n'; // Change to '\n' and do default:
     518            // NOTE: Fall-through
     519        }
     520        default: //Insert a character
     521        {
    527522#if !SDL_VERSION_ATLEAST(2, 0, 0)
    528                 if (cooked == 0)
    529                     return IN_PASS; // Important, because we didn't use any key
     523            if (cooked == 0)
     524                return IN_PASS; // Important, because we didn't use any key
    530525#else // SDL2
    531                 // In SDL2, we no longer get Unicode wchars via SDL_Keysym
    532                 // we use text input events instead and they provide UTF-8 chars
    533                 if (ev->ev.type == SDL_KEYDOWN && cooked == 0)
    534                     return IN_HANDLED;
     526            // In SDL2, we no longer get Unicode wchars via SDL_Keysym
     527            // we use text input events instead and they provide UTF-8 chars
     528            if (ev->ev.type == SDL_KEYDOWN && cooked == 0)
     529                return IN_HANDLED;
    535530#endif
    536531
    537                 // check max length
    538                 int max_length;
    539                 GUI<int>::GetSetting(this, "max_length", max_length);
    540                 if (max_length != 0 && (int)pCaption->length() >= max_length)
    541                     break;
     532            // check max length
     533            int max_length;
     534            GUI<int>::GetSetting(this, "max_length", max_length);
     535            if (max_length != 0 && (int)pCaption->length() >= max_length)
     536                break;
    542537
    543                 m_WantedX=0.0f;
     538            m_WantedX=0.0f;
    544539
    545                 if (SelectingText())
    546                     DeleteCurSelection();
    547                 m_iBufferPos_Tail = -1;
     540            if (SelectingText())
     541                DeleteCurSelection();
     542            m_iBufferPos_Tail = -1;
    548543
    549                 if (m_iBufferPos == (int)pCaption->length())
    550                     *pCaption += cooked;
    551                 else
    552                     *pCaption = pCaption->Left(m_iBufferPos) + cooked +
    553                                 pCaption->Right((long) pCaption->length()-m_iBufferPos);
     544            if (m_iBufferPos == (int)pCaption->length())
     545                *pCaption += cooked;
     546            else
     547                *pCaption = pCaption->Left(m_iBufferPos) + cooked +
     548                            pCaption->Right((long) pCaption->length()-m_iBufferPos);
    554549
    555                 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
     550            UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    556551
    557                 ++m_iBufferPos;
     552            ++m_iBufferPos;
    558553
    559                 UpdateAutoScroll();
    560                 }
    561                 break;
     554            UpdateAutoScroll();
     555            break;
     556        }
    562557        }
    563558
    564559        UpdateBufferPositionSetting();
     
    571566
    572567InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
    573568{
    574     CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     569    CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    575570    bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
    576571
    577572    std::string hotkey = static_cast<const char*>(ev->ev.user.data1);
     
    583578        if (text)
    584579        {
    585580            if (SelectingText())
    586             {
    587581                DeleteCurSelection();
    588             }
    589582
    590583            if (m_iBufferPos == (int)pCaption->length())
    591584                *pCaption += text;
     
    646639        if (!pCaption->empty() && m_iBufferPos != 0)
    647640        {
    648641            m_iBufferPos_Tail = m_iBufferPos;
    649             CStrW searchString = pCaption->Left( m_iBufferPos );
     642            CStrW searchString = pCaption->Left(m_iBufferPos);
    650643
    651644            // If we are starting in whitespace, adjust position until we get a non whitespace
    652645            while (m_iBufferPos > 0)
     
    703696                if (!iswspace((*pCaption)[m_iBufferPos]))
    704697                    break;
    705698
    706                 m_iBufferPos++;
     699                ++m_iBufferPos;
    707700            }
    708701            UpdateBufferPositionSetting();
    709702            DeleteCurSelection();
     
    727720
    728721            if (!pCaption->empty() && m_iBufferPos != 0)
    729722            {
    730                 CStrW searchString = pCaption->Left( m_iBufferPos );
     723                CStrW searchString = pCaption->Left(m_iBufferPos);
    731724
    732725                // If we are starting in whitespace, adjust position until we get a non whitespace
    733726                while (m_iBufferPos > 0)
     
    799792                    if (!iswspace((*pCaption)[m_iBufferPos]))
    800793                        break;
    801794
    802                     m_iBufferPos++;
     795                    ++m_iBufferPos;
    803796                }
    804797            }
    805798        }
     
    823816}
    824817
    825818
    826 void CInput::HandleMessage(SGUIMessage &Message)
     819void CInput::HandleMessage(SGUIMessage& Message)
    827820{
    828     // TODO Gee:
    829821    IGUIScrollBarOwner::HandleMessage(Message);
    830822
    831823    switch (Message.type)
    832824    {
    833825    case GUIM_SETTINGS_UPDATED:
    834         {
     826    {
    835827        bool scrollbar;
    836828        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    837829
     
    886878
    887879            UpdateText();
    888880        }
    889 
    890         }break;
     881        break;
     882    }
    891883
    892884    case GUIM_MOUSE_PRESS_LEFT:
    893885        // Check if we're selecting the scrollbar:
    894         {
     886    {
    895887        bool scrollbar, multiline;
    896888        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    897889        GUI<bool>::GetSetting(this, "multiline", multiline);
     
    921913
    922914        // If we immediately release the button it will just be seen as a click
    923915        //  for the user though.
    924 
    925         }break;
     916        break;
     917    }
    926918
    927919    case GUIM_MOUSE_DBLCLICK_LEFT:
    928         {
    929             if (m_ComposingText)
    930                 break;
     920    {
     921        if (m_ComposingText)
     922            break;
    931923
    932             CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     924        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    933925
    934             if (pCaption->length() == 0)
    935                 break;
     926        if (pCaption->empty())
     927            break;
    936928
    937             m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition();
     929        m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition();
    938930
    939             if (m_iBufferPos >= (int)pCaption->length())
    940                 m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1;
     931        if (m_iBufferPos >= (int)pCaption->length())
     932            m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1;
    941933
    942             // See if we are clicking over whitespace
    943             if (iswspace((*pCaption)[m_iBufferPos]))
     934        // See if we are clicking over whitespace
     935        if (iswspace((*pCaption)[m_iBufferPos]))
     936        {
     937            // see if we are in a section of whitespace greater than one character
     938            if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) ||
     939                (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1])))
    944940            {
    945                 // see if we are in a section of whitespace greater than one character
    946                 if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) ||
    947                     (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1])))
     941                //
     942                // We are clicking in an area with more than one whitespace character
     943                // so we select both the word to the left and then the word to the right
     944                //
     945                // [1] First the left
     946                // skip the whitespace
     947                while (m_iBufferPos > 0)
    948948                {
    949                     //
    950                     // We are clicking in an area with more than one whitespace character
    951                     // so we select both the word to the left and then the word to the right
    952                     //
    953                     // [1] First the left
    954                     // skip the whitespace
    955                     while (m_iBufferPos > 0)
    956                     {
    957                         if (!iswspace((*pCaption)[m_iBufferPos - 1]))
    958                             break;
    959 
    960                         m_iBufferPos--;
    961                     }
    962                     // now go until we hit white space or punctuation
    963                     while (m_iBufferPos > 0)
    964                     {
    965                         if (iswspace((*pCaption)[m_iBufferPos - 1]))
    966                             break;
    967 
    968                         m_iBufferPos--;
     949                    if (!iswspace((*pCaption)[m_iBufferPos - 1]))
     950                        break;
    969951
    970                         if (iswpunct((*pCaption)[m_iBufferPos]))
    971                             break;
    972                     }
     952                    m_iBufferPos--;
     953                }
     954                // now go until we hit white space or punctuation
     955                while (m_iBufferPos > 0)
     956                {
     957                    if (iswspace((*pCaption)[m_iBufferPos - 1]))
     958                        break;
    973959
    974                     // [2] Then the right
    975                     // go right until we are not in whitespace
    976                     while (++m_iBufferPos_Tail < (int)pCaption->length())
    977                     {
    978                         if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
    979                             break;
    980                     }
     960                    m_iBufferPos--;
    981961
    982                     if (m_iBufferPos_Tail == (int)pCaption->length())
     962                    if (iswpunct((*pCaption)[m_iBufferPos]))
    983963                        break;
    984 
    985                     // now go to the right until we hit whitespace or punctuation
    986                     while (++m_iBufferPos_Tail < (int)pCaption->length())
    987                     {
    988                         if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
    989                             break;
    990                     }
    991964                }
    992                 else
    993                 {
    994                     // single whitespace so select word to the right
    995                     while (++m_iBufferPos_Tail < (int)pCaption->length())
    996                     {
    997                         if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
    998                             break;
    999                     }
    1000965
    1001                     if (m_iBufferPos_Tail == (int)pCaption->length())
     966                // [2] Then the right
     967                // go right until we are not in whitespace
     968                while (++m_iBufferPos_Tail < (int)pCaption->length())
     969                {
     970                    if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
    1002971                        break;
     972                }
    1003973
    1004                     // Don't include the leading whitespace
    1005                     m_iBufferPos = m_iBufferPos_Tail;
     974                if (m_iBufferPos_Tail == (int)pCaption->length())
     975                    break;
    1006976
    1007                     // now go to the right until we hit whitespace or punctuation
    1008                     while (++m_iBufferPos_Tail < (int)pCaption->length())
    1009                     {
    1010                         if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
    1011                             break;
    1012                     }
     977                // now go to the right until we hit whitespace or punctuation
     978                while (++m_iBufferPos_Tail < (int)pCaption->length())
     979                {
     980                    if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     981                        break;
    1013982                }
    1014983            }
    1015984            else
    1016985            {
    1017                 // clicked on non-whitespace so select current word
    1018                 // go until we hit white space or punctuation
    1019                 while (m_iBufferPos > 0)
     986                // single whitespace so select word to the right
     987                while (++m_iBufferPos_Tail < (int)pCaption->length())
    1020988                {
    1021                     if (iswspace((*pCaption)[m_iBufferPos - 1]))
     989                    if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
    1022990                        break;
     991                }
    1023992
    1024                     m_iBufferPos--;
     993                if (m_iBufferPos_Tail == (int)pCaption->length())
     994                    break;
    1025995
    1026                     if (iswpunct((*pCaption)[m_iBufferPos]))
    1027                         break;
    1028                 }
    1029                 // go to the right until we hit whitespace or punctuation
     996                // Don't include the leading whitespace
     997                m_iBufferPos = m_iBufferPos_Tail;
     998
     999                // now go to the right until we hit whitespace or punctuation
    10301000                while (++m_iBufferPos_Tail < (int)pCaption->length())
    10311001                {
    10321002                    if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     
    10341004                }
    10351005            }
    10361006        }
     1007        else
     1008        {
     1009            // clicked on non-whitespace so select current word
     1010            // go until we hit white space or punctuation
     1011            while (m_iBufferPos > 0)
     1012            {
     1013                if (iswspace((*pCaption)[m_iBufferPos - 1]))
     1014                    break;
     1015
     1016                m_iBufferPos--;
     1017
     1018                if (iswpunct((*pCaption)[m_iBufferPos]))
     1019                    break;
     1020            }
     1021            // go to the right until we hit whitespace or punctuation
     1022            while (++m_iBufferPos_Tail < (int)pCaption->length())
     1023            {
     1024                if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     1025                    break;
     1026            }
     1027        }
    10371028        break;
     1029    }
    10381030
    10391031    case GUIM_MOUSE_RELEASE_LEFT:
    10401032        if (m_SelectingText)
    1041         {
    10421033            m_SelectingText = false;
    1043         }
    10441034        break;
    10451035
    10461036    case GUIM_MOUSE_MOTION:
     
    10591049        break;
    10601050
    10611051    case GUIM_LOAD:
    1062         {
    1063         GetScrollBar(0).SetX( m_CachedActualSize.right );
    1064         GetScrollBar(0).SetY( m_CachedActualSize.top );
    1065         GetScrollBar(0).SetZ( GetBufferedZ() );
    1066         GetScrollBar(0).SetLength( m_CachedActualSize.bottom - m_CachedActualSize.top );
     1052    {
     1053        GetScrollBar(0).SetX(m_CachedActualSize.right);
     1054        GetScrollBar(0).SetY(m_CachedActualSize.top);
     1055        GetScrollBar(0).SetZ(GetBufferedZ());
     1056        GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
    10671057
    10681058        CStr scrollbar_style;
    10691059        GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
    1070         GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
     1060        GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    10711061
    10721062        UpdateText();
    1073         }
    10741063        break;
     1064    }
    10751065
    10761066    case GUIM_GOT_FOCUS:
    10771067        m_iBufferPos = 0;
     
    11641154    GUI<bool>::GetSetting(this, "mask", mask);
    11651155
    11661156    if (scrollbar && multiline)
    1167     {
    1168         // Draw scrollbar
    11691157        IGUIScrollBarOwner::Draw();
     1158
     1159    if (!GetGUI())
     1160        return;
     1161
     1162    CStrW font_name_w;
     1163    CColor color, color_selected;
     1164    //CStrW caption;
     1165    GUI<CStrW>::GetSetting(this, "font", font_name_w);
     1166    GUI<CColor>::GetSetting(this, "textcolor", color);
     1167    GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected);
     1168    CStrIntern font_name(font_name_w.ToUTF8());
     1169
     1170    // Get pointer of caption, it might be very large, and we don't
     1171    //  want to copy it continuously.
     1172    CStrW* pCaption = NULL;
     1173    wchar_t mask_char = L'*';
     1174    if (mask)
     1175    {
     1176        CStrW maskStr;
     1177        GUI<CStrW>::GetSetting(this, "mask_char", maskStr);
     1178        if (maskStr.length() > 0)
     1179            mask_char = maskStr[0];
    11701180    }
     1181    else
     1182        pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     1183
     1184    CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
     1185    int cell_id;
     1186
     1187    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
     1188    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea);
     1189
     1190    GUI<int>::GetSetting(this, "cell_id", cell_id);
     1191
     1192    GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
     1193
     1194    float scroll=0.f;
     1195    if (scrollbar && multiline)
     1196        scroll = GetScrollBar(0).GetPos();
     1197
     1198    CFontMetrics font(font_name);
     1199
     1200    // We'll have to setup clipping manually, since we're doing the rendering manually.
     1201    CRect cliparea(m_CachedActualSize);
    11711202
    1172     if (GetGUI())
     1203    // First we'll figure out the clipping area, which is the cached actual size
     1204    //  substracted by an optional scrollbar
     1205    if (scrollbar)
    11731206    {
    1174         CStrW font_name_w;
    1175         CColor color, color_selected;
    1176         //CStrW caption;
    1177         GUI<CStrW>::GetSetting(this, "font", font_name_w);
    1178         GUI<CColor>::GetSetting(this, "textcolor", color);
    1179         GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected);
    1180         CStrIntern font_name(font_name_w.ToUTF8());
     1207        scroll = GetScrollBar(0).GetPos();
    11811208
    1182         // Get pointer of caption, it might be very large, and we don't
    1183         //  want to copy it continuously.
    1184         CStrW *pCaption = NULL;
    1185         wchar_t mask_char = L'*';
    1186         if (mask)
    1187         {
    1188             CStrW maskStr;
    1189             GUI<CStrW>::GetSetting(this, "mask_char", maskStr);
    1190             if (maskStr.length() > 0)
    1191                 mask_char = maskStr[0];
    1192         }
    1193         else
    1194             pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     1209        // substract scrollbar from cliparea
     1210        if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
     1211            cliparea.right <= GetScrollBar(0).GetOuterRect().right)
     1212            cliparea.right = GetScrollBar(0).GetOuterRect().left;
    11951213
    1196         CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
    1197         int cell_id;
     1214        if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
     1215            cliparea.left < GetScrollBar(0).GetOuterRect().right)
     1216            cliparea.left = GetScrollBar(0).GetOuterRect().right;
     1217    }
     1218
     1219    if (cliparea != CRect())
     1220    {
     1221        glEnable(GL_SCISSOR_TEST);
     1222        glScissor(
     1223            cliparea.left / g_GuiScale,
     1224            g_yres - cliparea.bottom / g_GuiScale,
     1225            cliparea.GetWidth() / g_GuiScale,
     1226            cliparea.GetHeight() / g_GuiScale);
     1227    }
     1228
     1229    // These are useful later.
     1230    int VirtualFrom, VirtualTo;
     1231
     1232    if (m_iBufferPos_Tail >= m_iBufferPos)
     1233    {
     1234        VirtualFrom = m_iBufferPos;
     1235        VirtualTo = m_iBufferPos_Tail;
     1236    }
     1237    else
     1238    {
     1239        VirtualFrom = m_iBufferPos_Tail;
     1240        VirtualTo = m_iBufferPos;
     1241    }
    11981242
    1199         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
    1200         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea);
     1243    // Get the height of this font.
     1244    float h = (float)font.GetHeight();
     1245    float ls = (float)font.GetLineSpacing();
    12011246
    1202         GUI<int>::GetSetting(this, "cell_id", cell_id);
     1247    CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
    12031248
    1204         GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
     1249    CTextRenderer textRenderer(tech->GetShader());
     1250    textRenderer.Font(font_name);
    12051251
    1206         float scroll=0.f;
    1207         if (scrollbar && multiline)
    1208         {
    1209             scroll = GetScrollBar(0).GetPos();
    1210         }
     1252    // Set the Z to somewhat more, so we can draw a selected area between the
     1253    //  the control and the text.
     1254    textRenderer.Translate(
     1255        (float)(int)(m_CachedActualSize.left) + buffer_zone,
     1256        (float)(int)(m_CachedActualSize.top+h) + buffer_zone,
     1257        bz+0.1f);
    12111258
    1212         CFontMetrics font(font_name);
     1259    // U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE
     1260    // (sort of like a | which is aligned to the left of most characters)
    12131261
    1214         // We'll have to setup clipping manually, since we're doing the rendering manually.
    1215         CRect cliparea(m_CachedActualSize);
     1262    float buffered_y = -scroll+buffer_zone;
    12161263
    1217         // First we'll figure out the clipping area, which is the cached actual size
    1218         //  substracted by an optional scrollbar
    1219         if (scrollbar)
    1220         {
    1221             scroll = GetScrollBar(0).GetPos();
     1264    // When selecting larger areas, we need to draw a rectangle box
     1265    //  around it, and this is to keep track of where the box
     1266    //  started, because we need to follow the iteration until we
     1267    //  reach the end, before we can actually draw it.
     1268    bool drawing_box = false;
     1269    float box_x=0.f;
    12221270
    1223             // substract scrollbar from cliparea
    1224             if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
    1225                 cliparea.right <= GetScrollBar(0).GetOuterRect().right)
    1226                 cliparea.right = GetScrollBar(0).GetOuterRect().left;
     1271    float x_pointer=0.f;
    12271272
    1228             if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
    1229                 cliparea.left < GetScrollBar(0).GetOuterRect().right)
    1230                 cliparea.left = GetScrollBar(0).GetOuterRect().right;
    1231         }
     1273    // If we have a selecting box (i.e. when you have selected letters, not just when
     1274    //  the pointer is between two letters) we need to process all letters once
     1275    //  before we do it the second time and render all the text. We can't do it
     1276    //  in the same loop because text will have been drawn, so it will disappear when
     1277    //  drawn behind the text that has already been drawn. Confusing, well it's necessary
     1278    //  (I think).
    12321279
    1233         if (cliparea != CRect())
    1234         {
    1235             glEnable(GL_SCISSOR_TEST);
    1236             glScissor(
    1237                 cliparea.left / g_GuiScale,
    1238                 g_yres - cliparea.bottom / g_GuiScale,
    1239                 cliparea.GetWidth() / g_GuiScale,
    1240                 cliparea.GetHeight() / g_GuiScale);
    1241         }
     1280    if (SelectingText())
     1281    {
     1282        // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos,
     1283        //  just like you can select from right to left, as you can
     1284        //  left to right. Is there a difference? Yes, the pointer
     1285        //  be placed accordingly, so that if you select shift and
     1286        //  expand this selection, it will expand on appropriate side.
     1287        // Anyway, since the drawing procedure needs "To" to be
     1288        //  greater than from, we need virtual values that might switch
     1289        //  place.
    12421290
    1243         // These are useful later.
    12441291        int VirtualFrom, VirtualTo;
    12451292
    12461293        if (m_iBufferPos_Tail >= m_iBufferPos)
     
    12541301            VirtualTo = m_iBufferPos;
    12551302        }
    12561303
    1257         // Get the height of this font.
    1258         float h = (float)font.GetHeight();
    1259         float ls = (float)font.GetLineSpacing();
    1260 
    1261         CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
    1262 
    1263         CTextRenderer textRenderer(tech->GetShader());
    1264         textRenderer.Font(font_name);
    1265 
    1266         // Set the Z to somewhat more, so we can draw a selected area between the
    1267         //  the control and the text.
    1268         textRenderer.Translate(
    1269             (float)(int)(m_CachedActualSize.left) + buffer_zone,
    1270             (float)(int)(m_CachedActualSize.top+h) + buffer_zone,
    1271             bz+0.1f);
    1272 
    1273         // U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE
    1274         // (sort of like a | which is aligned to the left of most characters)
    1275 
    1276         float buffered_y = -scroll+buffer_zone;
    1277 
    1278         // When selecting larger areas, we need to draw a rectangle box
    1279         //  around it, and this is to keep track of where the box
    1280         //  started, because we need to follow the iteration until we
    1281         //  reach the end, before we can actually draw it.
    1282         bool drawing_box = false;
    1283         float box_x=0.f;
    1284 
    1285         float x_pointer=0.f;
    12861304
    1287         // If we have a selecting box (i.e. when you have selected letters, not just when
    1288         //  the pointer is between two letters) we need to process all letters once
    1289         //  before we do it the second time and render all the text. We can't do it
    1290         //  in the same loop because text will have been drawn, so it will disappear when
    1291         //  drawn behind the text that has already been drawn. Confusing, well it's necessary
    1292         //  (I think).
    1293 
    1294         if (SelectingText())
     1305        bool done = false;
     1306        for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
     1307            it != m_CharacterPositions.end();
     1308            ++it, buffered_y += ls, x_pointer = 0.f)
    12951309        {
    1296             // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos,
    1297             //  just like you can select from right to left, as you can
    1298             //  left to right. Is there a difference? Yes, the pointer
    1299             //  be placed accordingly, so that if you select shift and
    1300             //  expand this selection, it will expand on appropriate side.
    1301             // Anyway, since the drawing procedure needs "To" to be
    1302             //  greater than from, we need virtual values that might switch
    1303             //  place.
    1304 
    1305             int VirtualFrom, VirtualTo;
    1306 
    1307             if (m_iBufferPos_Tail >= m_iBufferPos)
     1310            if (multiline)
    13081311            {
    1309                 VirtualFrom = m_iBufferPos;
    1310                 VirtualTo = m_iBufferPos_Tail;
    1311             }
    1312             else
    1313             {
    1314                 VirtualFrom = m_iBufferPos_Tail;
    1315                 VirtualTo = m_iBufferPos;
     1312                if (buffered_y > m_CachedActualSize.GetHeight())
     1313                    break;
    13161314            }
    13171315
    1318 
    1319             bool done = false;
    1320             for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
    1321                 it != m_CharacterPositions.end();
    1322                 ++it, buffered_y += ls, x_pointer = 0.f)
     1316            // We might as well use 'i' here to iterate, because we need it
     1317            // (often compared against ints, so don't make it size_t)
     1318            for (int i=0; i < (int)it->m_ListOfX.size()+2; ++i)
    13231319            {
    1324                 if (multiline)
     1320                if (it->m_ListStart + i == VirtualFrom)
    13251321                {
    1326                     if (buffered_y > m_CachedActualSize.GetHeight())
    1327                         break;
     1322                    // we won't actually draw it now, because we don't
     1323                    //  know the width of each glyph to that position.
     1324                    //  we need to go along with the iteration, and
     1325                    //  make a mark where the box started:
     1326                    drawing_box = true; // will turn false when finally rendered.
     1327
     1328                    // Get current x position
     1329                    box_x = x_pointer;
    13281330                }
    13291331
    1330                 // We might as well use 'i' here to iterate, because we need it
    1331                 // (often compared against ints, so don't make it size_t)
    1332                 for (int i=0; i < (int)it->m_ListOfX.size()+2; ++i)
    1333                 {
    1334                     if (it->m_ListStart + i == VirtualFrom)
    1335                     {
    1336                         // we won't actually draw it now, because we don't
    1337                         //  know the width of each glyph to that position.
    1338                         //  we need to go along with the iteration, and
    1339                         //  make a mark where the box started:
    1340                         drawing_box = true; // will turn false when finally rendered.
    1341 
    1342                         // Get current x position
    1343                         box_x = x_pointer;
    1344                     }
    1345 
    1346                     // no else!
     1332                // no else!
    13471333
    1348                     const bool at_end = (i == (int)it->m_ListOfX.size()+1);
     1334                const bool at_end = (i == (int)it->m_ListOfX.size()+1);
    13491335
    1350                     if (drawing_box == true &&
    1351                         (it->m_ListStart + i == VirtualTo || at_end))
     1336                if (drawing_box == true &&
     1337                    (it->m_ListStart + i == VirtualTo || at_end))
     1338                {
     1339                    // Depending on if it's just a row change, or if it's
     1340                    //  the end of the select box, do slightly different things.
     1341                    if (at_end)
    13521342                    {
    1353                         // Depending on if it's just a row change, or if it's
    1354                         //  the end of the select box, do slightly different things.
    1355                         if (at_end)
    1356                         {
    1357                             if (it->m_ListStart + i != VirtualFrom)
    1358                             {
    1359                                 // and actually add a white space! yes, this is done in any common input
    1360                                 x_pointer += (float)font.GetCharacterWidth(L' ');
    1361                             }
    1362                         }
    1363                         else
     1343                        if (it->m_ListStart + i != VirtualFrom)
    13641344                        {
    1365                             drawing_box = false;
    1366                             done = true;
     1345                            // and actually add a white space! yes, this is done in any common input
     1346                            x_pointer += (float)font.GetCharacterWidth(L' ');
    13671347                        }
     1348                    }
     1349                    else
     1350                    {
     1351                        drawing_box = false;
     1352                        done = true;
     1353                    }
    13681354
    1369                         CRect rect;
    1370                         // Set 'rect' depending on if it's a multiline control, or a one-line control
    1371                         if (multiline)
    1372                         {
    1373                             rect = CRect(m_CachedActualSize.left+box_x+buffer_zone,
    1374                                        m_CachedActualSize.top+buffered_y+(h-ls)/2,
    1375                                        m_CachedActualSize.left+x_pointer+buffer_zone,
    1376                                        m_CachedActualSize.top+buffered_y+(h+ls)/2);
    1377 
    1378                             if (rect.bottom < m_CachedActualSize.top)
    1379                                 continue;
     1355                    CRect rect;
     1356                    // Set 'rect' depending on if it's a multiline control, or a one-line control
     1357                    if (multiline)
     1358                    {
     1359                        rect = CRect(m_CachedActualSize.left+box_x+buffer_zone,
     1360                                   m_CachedActualSize.top+buffered_y+(h-ls)/2,
     1361                                   m_CachedActualSize.left+x_pointer+buffer_zone,
     1362                                   m_CachedActualSize.top+buffered_y+(h+ls)/2);
    13801363
    1381                             if (rect.top < m_CachedActualSize.top)
    1382                                 rect.top = m_CachedActualSize.top;
     1364                        if (rect.bottom < m_CachedActualSize.top)
     1365                            continue;
    13831366
    1384                             if (rect.bottom > m_CachedActualSize.bottom)
    1385                                 rect.bottom = m_CachedActualSize.bottom;
    1386                         }
    1387                         else // if one-line
    1388                         {
    1389                             rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll,
    1390                                        m_CachedActualSize.top+buffered_y+(h-ls)/2,
    1391                                        m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll,
    1392                                        m_CachedActualSize.top+buffered_y+(h+ls)/2);
     1367                        if (rect.top < m_CachedActualSize.top)
     1368                            rect.top = m_CachedActualSize.top;
    13931369
    1394                             if (rect.left < m_CachedActualSize.left)
    1395                                 rect.left = m_CachedActualSize.left;
     1370                        if (rect.bottom > m_CachedActualSize.bottom)
     1371                            rect.bottom = m_CachedActualSize.bottom;
     1372                    }
     1373                    else // if one-line
     1374                    {
     1375                        rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll,
     1376                                   m_CachedActualSize.top+buffered_y+(h-ls)/2,
     1377                                   m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll,
     1378                                   m_CachedActualSize.top+buffered_y+(h+ls)/2);
    13961379
    1397                             if (rect.right > m_CachedActualSize.right)
    1398                                 rect.right = m_CachedActualSize.right;
    1399                         }
     1380                        if (rect.left < m_CachedActualSize.left)
     1381                            rect.left = m_CachedActualSize.left;
    14001382
    1401                         if (sprite_selectarea)
    1402                             GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect);
     1383                        if (rect.right > m_CachedActualSize.right)
     1384                            rect.right = m_CachedActualSize.right;
    14031385                    }
    14041386
    1405                     if (i < (int)it->m_ListOfX.size())
    1406                     {
    1407                         if (!mask)
    1408                             x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]);
    1409                         else
    1410                             x_pointer += (float)font.GetCharacterWidth(mask_char);
    1411                     }
     1387                    if (sprite_selectarea)
     1388                        GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect);
    14121389                }
    14131390
    1414                 if (done)
    1415                     break;
    1416 
    1417                 // If we're about to draw a box, and all of a sudden changes
    1418                 //  line, we need to draw that line's box, and then reset
    1419                 //  the box drawing to the beginning of the new line.
    1420                 if (drawing_box)
     1391                if (i < (int)it->m_ListOfX.size())
    14211392                {
    1422                     box_x = 0.f;
     1393                    if (!mask)
     1394                        x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]);
     1395                    else
     1396                        x_pointer += (float)font.GetCharacterWidth(mask_char);
    14231397                }
    14241398            }
     1399
     1400            if (done)
     1401                break;
     1402
     1403            // If we're about to draw a box, and all of a sudden changes
     1404            //  line, we need to draw that line's box, and then reset
     1405            //  the box drawing to the beginning of the new line.
     1406            if (drawing_box)
     1407            {
     1408                box_x = 0.f;
     1409            }
    14251410        }
     1411    }
    14261412
    1427         // Reset some from previous run
    1428         buffered_y = -scroll;
     1413    // Reset some from previous run
     1414    buffered_y = -scroll;
    14291415
    1430         // Setup initial color (then it might change and change back, when drawing selected area)
    1431         textRenderer.Color(color);
     1416    // Setup initial color (then it might change and change back, when drawing selected area)
     1417    textRenderer.Color(color);
    14321418
    1433         tech->BeginPass();
     1419    tech->BeginPass();
    14341420
    1435         bool using_selected_color = false;
     1421    bool using_selected_color = false;
    14361422
    1437         for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
    1438              it != m_CharacterPositions.end();
    1439              ++it, buffered_y += ls)
     1423    for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
     1424         it != m_CharacterPositions.end();
     1425         ++it, buffered_y += ls)
     1426    {
     1427        if (buffered_y + buffer_zone >= -ls || !multiline)
    14401428        {
    1441             if (buffered_y + buffer_zone >= -ls || !multiline)
     1429            if (multiline)
    14421430            {
    1443                 if (multiline)
    1444                 {
    1445                     if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight())
    1446                         break;
    1447                 }
     1431                if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight())
     1432                    break;
     1433            }
    14481434
    1449                 CMatrix3D savedTransform = textRenderer.GetTransform();
     1435            CMatrix3D savedTransform = textRenderer.GetTransform();
    14501436
    1451                 // Text must always be drawn in integer values. So we have to convert scroll
    1452                 if (multiline)
    1453                     textRenderer.Translate(0.f, -(float)(int)scroll, 0.f);
    1454                 else
    1455                     textRenderer.Translate(-(float)(int)m_HorizontalScroll, 0.f, 0.f);
     1437            // Text must always be drawn in integer values. So we have to convert scroll
     1438            if (multiline)
     1439                textRenderer.Translate(0.f, -(float)(int)scroll, 0.f);
     1440            else
     1441                textRenderer.Translate(-(float)(int)m_HorizontalScroll, 0.f, 0.f);
    14561442
    1457                 // We might as well use 'i' here, because we need it
    1458                 // (often compared against ints, so don't make it size_t)
    1459                 for (int i=0; i < (int)it->m_ListOfX.size()+1; ++i)
     1443            // We might as well use 'i' here, because we need it
     1444            // (often compared against ints, so don't make it size_t)
     1445            for (int i=0; i < (int)it->m_ListOfX.size()+1; ++i)
     1446            {
     1447                if (!multiline && i < (int)it->m_ListOfX.size())
    14601448                {
    1461                     if (!multiline && i < (int)it->m_ListOfX.size())
    1462                     {
    1463                         if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone)
    1464                         {
    1465                             // We still need to translate the OpenGL matrix
    1466                             if (i == 0)
    1467                                 textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f);
    1468                             else
    1469                                 textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f);
    1470 
    1471                             continue;
    1472                         }
    1473                     }
    1474 
    1475                     // End of selected area, change back color
    1476                     if (SelectingText() &&
    1477                         it->m_ListStart + i == VirtualTo)
    1478                     {
    1479                         using_selected_color = false;
    1480                         textRenderer.Color(color);
    1481                     }
    1482 
    1483                     if (i != (int)it->m_ListOfX.size() &&
    1484                         it->m_ListStart + i == m_iBufferPos)
    1485                     {
    1486                         // selecting only one, then we need only to draw a cursor.
    1487                         if (m_CursorVisState)
    1488                             textRenderer.Put(0.0f, 0.0f, L"_");
    1489                     }
    1490 
    1491                     // Drawing selected area
    1492                     if (SelectingText() &&
    1493                         it->m_ListStart + i >= VirtualFrom &&
    1494                         it->m_ListStart + i < VirtualTo &&
    1495                         using_selected_color == false)
    1496                     {
    1497                         using_selected_color = true;
    1498                         textRenderer.Color(color_selected);
    1499                     }
    1500 
    1501                     if (i != (int)it->m_ListOfX.size())
     1449                    if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone)
    15021450                    {
    1503                         if (!mask)
    1504                             textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]);
     1451                        // We still need to translate the OpenGL matrix
     1452                        if (i == 0)
     1453                            textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f);
    15051454                        else
    1506                             textRenderer.PrintfAdvance(L"%lc", mask_char);
    1507                     }
     1455                            textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f);
    15081456
    1509                     // check it's now outside a one-liner, then we'll break
    1510                     if (!multiline && i < (int)it->m_ListOfX.size())
    1511                     {
    1512                         if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone)
    1513                             break;
     1457                        continue;
    15141458                    }
    15151459                }
    15161460
    1517                 if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos)
     1461                // End of selected area, change back color
     1462                if (SelectingText() &&
     1463                    it->m_ListStart + i == VirtualTo)
    15181464                {
     1465                    using_selected_color = false;
    15191466                    textRenderer.Color(color);
     1467                }
     1468
     1469                if (i != (int)it->m_ListOfX.size() &&
     1470                    it->m_ListStart + i == m_iBufferPos)
     1471                {
     1472                    // selecting only one, then we need only to draw a cursor.
    15201473                    if (m_CursorVisState)
    1521                         textRenderer.PutAdvance(L"_");
     1474                        textRenderer.Put(0.0f, 0.0f, L"_");
     1475                }
    15221476
    1523                     if (using_selected_color)
    1524                     {
    1525                         textRenderer.Color(color_selected);
    1526                     }
     1477                // Drawing selected area
     1478                if (SelectingText() &&
     1479                    it->m_ListStart + i >= VirtualFrom &&
     1480                    it->m_ListStart + i < VirtualTo &&
     1481                    using_selected_color == false)
     1482                {
     1483                    using_selected_color = true;
     1484                    textRenderer.Color(color_selected);
     1485                }
     1486
     1487                if (i != (int)it->m_ListOfX.size())
     1488                {
     1489                    if (!mask)
     1490                        textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]);
     1491                    else
     1492                        textRenderer.PrintfAdvance(L"%lc", mask_char);
    15271493                }
    15281494
    1529                 textRenderer.SetTransform(savedTransform);
     1495                // check it's now outside a one-liner, then we'll break
     1496                if (!multiline && i < (int)it->m_ListOfX.size())
     1497                {
     1498                    if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone)
     1499                        break;
     1500                }
    15301501            }
    15311502
    1532             textRenderer.Translate(0.f, ls, 0.f);
    1533         }
     1503            if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos)
     1504            {
     1505                textRenderer.Color(color);
     1506                if (m_CursorVisState)
     1507                    textRenderer.PutAdvance(L"_");
    15341508
    1535         textRenderer.Render();
     1509                if (using_selected_color)
     1510                {
     1511                    textRenderer.Color(color_selected);
     1512                }
     1513            }
    15361514
    1537         if (cliparea != CRect())
    1538             glDisable(GL_SCISSOR_TEST);
     1515            textRenderer.SetTransform(savedTransform);
     1516        }
    15391517
    1540         tech->EndPass();
     1518        textRenderer.Translate(0.f, ls, 0.f);
    15411519    }
     1520
     1521    textRenderer.Render();
     1522
     1523    if (cliparea != CRect())
     1524        glDisable(GL_SCISSOR_TEST);
     1525
     1526    tech->EndPass();
    15421527}
    15431528
    15441529void CInput::UpdateText(int from, int to_before, int to_after)
     
    17341719            if (i==to-1 && to != (int)caption.length())
    17351720                break; // it will be added outside
    17361721
    1737             current_line = m_CharacterPositions.insert( current_line, row );
     1722            current_line = m_CharacterPositions.insert(current_line, row);
    17381723            ++current_line;
    17391724
    17401725
     
    17641749                {
    17651750                    last_word_started = i;
    17661751                    row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started));
    1767                     //row.m_ListOfX.push_back( x_pos );
     1752                    //row.m_ListOfX.push_back(x_pos);
    17681753                    //continue;
    17691754                }
    17701755                else
     
    17791764                //  rows. With automatic word-wrapping, that is not possible. Which
    17801765                //  is intuitively correct.
    17811766
    1782                 current_line = m_CharacterPositions.insert( current_line, row );
     1767                current_line = m_CharacterPositions.insert(current_line, row);
    17831768                ++current_line;
    17841769
    17851770                // Setup the next row:
     
    17921777            }
    17931778            else
    17941779                // Get width of this character:
    1795                 row.m_ListOfX.push_back( x_pos );
     1780                row.m_ListOfX.push_back(x_pos);
    17961781        }
    17971782
    17981783        // Check if it's the last iteration, and we're not revising the whole string
     
    18431828                        //  have to continue.
    18441829                        // 'check_point_row_start' is where we store how the that
    18451830                        //  line looked.
    1846             //          if (destroy_row_to !=
    18471831                        if (destroy_row_to != m_CharacterPositions.end())
    18481832                        {
    18491833                            check_point_row_start = destroy_row_to->m_ListStart;
     
    19001884    if (current_line != m_CharacterPositions.end())
    19011885    {
    19021886        if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart)
    1903             row.m_ListOfX.resize( row.m_ListOfX.size()-1 );
     1887            row.m_ListOfX.resize(row.m_ListOfX.size()-1);
    19041888    }
    19051889
    19061890    // add the final row (even if empty)
     
    19431927
    19441928        float scroll=0.f;
    19451929        if (scrollbar)
    1946         {
    19471930            scroll = GetScrollBar(0).GetPos();
    1948         }
    19491931
    19501932        // Pointer to caption, will come in handy
    1951         CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     1933        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    19521934        UNUSED2(pCaption);
    19531935
    19541936        // Now get the height of the font.
     
    19981980}
    19991981
    20001982// Does not process horizontal scrolling, 'x' must be modified before inputted.
    2001 int CInput::GetXTextPosition(const std::list<SRow>::iterator &current, const float &x, float &wanted)
     1983int CInput::GetXTextPosition(const std::list<SRow>::iterator& current, const float& x, float& wanted)
    20021984{
    20031985    int ret=0;
    20041986    float previous=0.f;
     
    20262008        ret += i;
    20272009        wanted = x;
    20282010    }
    2029     else wanted = 0.f;
     2011    else
     2012        wanted = 0.f;
    20302013
    20312014    return ret;
    20322015}
    20332016
    20342017void CInput::DeleteCurSelection()
    20352018{
    2036     CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     2019    CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    20372020
    20382021    int virtualFrom;
    20392022    int virtualTo;
     
    20492032        virtualTo = m_iBufferPos;
    20502033    }
    20512034
    2052     *pCaption = pCaption->Left( virtualFrom ) +
    2053                 pCaption->Right( (long) pCaption->length() - (virtualTo) );
     2035    *pCaption = pCaption->Left(virtualFrom) +
     2036                pCaption->Right((long)pCaption->length() - virtualTo);
    20542037
    20552038    UpdateText(virtualFrom, virtualTo, virtualFrom);
    20562039
     
    21282111            // Scroll so the selected row is shown completely, also with buffer_zone length to the edge.
    21292112            GetScrollBar(0).SetPos((float)(row+1) * spacing - m_CachedActualSize.GetHeight() + buffer_zone*2.f);
    21302113        }
    2131         else
    21322114        // If scrolling up
    2133         if (-scroll + (float)row * spacing < 0.f)
     2115        else if (-scroll + (float)row * spacing < 0.f)
    21342116        {
    21352117            // Scroll so the selected row is shown completely, also with buffer_zone length to the edge.
    21362118            GetScrollBar(0).SetPos((float)row * spacing);
  • source/gui/CInput.h

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Input [box]
    20 
    21 --Overview--
    22 
    23     GUI Object representing a text field you can edit.
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CINPUT
    3219#define INCLUDED_CINPUT
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    39 //--------------------------------------------------------
    40 //  Macros
    41 //--------------------------------------------------------
    42 
    43 //--------------------------------------------------------
    44 //  Types
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Declarations
    49 //--------------------------------------------------------
    50 
    5123/**
    5224 * Text field where you can input and edit the text.
    5325 *
     
    8052
    8153    // Same as above, but only on one row in X, and a given value, not the mouse's
    8254    //  wanted is filled with x if the row didn't extend as far as we
    83     int GetXTextPosition(const std::list<SRow>::iterator &c, const float &x, float &wanted);
     55    int GetXTextPosition(const std::list<SRow>::iterator& c, const float& x, float& wanted);
    8456
    8557protected:
    8658    /**
    8759     * @see IGUIObject#HandleMessage()
    8860     */
    89     virtual void HandleMessage(SGUIMessage &Message);
     61    virtual void HandleMessage(SGUIMessage& Message);
    9062
    9163    /**
    9264     * Handle events manually to catch keyboard inputting.
     
    172144     * List of rows to ease changing its size, so iterators stay valid.
    173145     * For one-liners only one row is used.
    174146     */
    175     std::list< SRow > m_CharacterPositions;
     147    std::list<SRow> m_CharacterPositions;
    176148
    177149    // *** Things for a multi-lined input control *** //
    178150
     
    205177    bool m_CursorVisState;
    206178};
    207179
    208 #endif
     180#endif // INCLUDED_CINPUT
  • source/gui/CList.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CList
    20 */
    21 
    2218#include "precompiled.h"
    2319
    2420#include "CList.h"
     
    3026#include "soundmanager/ISoundManager.h"
    3127
    3228
    33 //-------------------------------------------------------------------
    34 //  Constructor / Destructor
    35 //-------------------------------------------------------------------
    36 CList::CList() :
    37     m_Modified(false)
     29CList::CList()
     30    : m_Modified(false)
    3831{
    3932    // Add sprite_disabled! TODO
    4033
    4134    AddSetting(GUIST_float,                 "buffer_zone");
    42     //AddSetting(GUIST_CGUIString,          "caption"); will it break removing this? If I know my system, then no, but test just in case TODO (Gee).
    4335    AddSetting(GUIST_CStrW,                 "font");
    4436    AddSetting(GUIST_bool,                  "scrollbar");
    4537    AddSetting(GUIST_CStr,                  "scrollbar_style");
     
    6456    GUI<int>::SetSetting(this, "selected", -1);
    6557
    6658    // Add scroll-bar
    67     CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
     59    CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
    6860    bar->SetRightAligned(true);
    6961    AddScrollBar(bar);
    7062}
     
    7971        return;
    8072
    8173    m_Modified = true;
    82     CGUIList *pList;
     74    CGUIList* pList;
    8375    GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    8476
    8577    //ENSURE(m_GeneratedTexts.size()>=1);
    8678
    87     m_ItemsYPositions.resize( pList->m_Items.size()+1 );
     79    m_ItemsYPositions.resize(pList->m_Items.size()+1);
    8880
    8981    // Delete all generated texts. Some could probably be saved,
    9082    //  but this is easier, and this function will never be called
    9183    //  continuously, or even often, so it'll probably be okay.
    92     std::vector<SGUIText*>::iterator it;
    93     for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
    94     {
    95         if (*it)
    96             delete *it;
    97     }
     84    for (SGUIText* const& t : m_GeneratedTexts)
     85        delete t;
    9886    m_GeneratedTexts.clear();
    9987
    10088    CStrW font;
     
    10391        // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style.
    10492        font = L"default";
    10593
    106     //CGUIString caption;
    10794    bool scrollbar;
    108     //GUI<CGUIString>::GetSetting(this, "caption", caption);
    10995    GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    11096
    11197    float width = GetListRect().GetWidth();
     
    119105    // Generate texts
    120106    float buffered_y = 0.f;
    121107   
    122     for (int i=0; i<(int)pList->m_Items.size(); ++i)
     108    for (size_t i=0; i < pList->m_Items.size(); ++i)
    123109    {
    124110        // Create a new SGUIText. Later on, input it using AddText()
    125         SGUIText *text = new SGUIText();
     111        SGUIText* text = new SGUIText();
    126112
    127113        *text = GetGUI()->GenerateText(pList->m_Items[i], font, width, buffer_zone, this);
    128114
     
    134120
    135121    m_ItemsYPositions[pList->m_Items.size()] = buffered_y;
    136122   
    137     //if (! scrollbar)
    138     //  CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
    139 
    140123    // Setup scrollbar
    141124    if (scrollbar)
    142125    {
    143         GetScrollBar(0).SetScrollRange( m_ItemsYPositions.back() );
    144         GetScrollBar(0).SetScrollSpace( GetListRect().GetHeight() );
     126        GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
     127        GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight());
    145128
    146129        CRect rect = GetListRect();
    147         GetScrollBar(0).SetX( rect.right );
    148         GetScrollBar(0).SetY( rect.top );
    149         GetScrollBar(0).SetZ( GetBufferedZ() );
    150         GetScrollBar(0).SetLength( rect.bottom - rect.top );
     130        GetScrollBar(0).SetX(rect.right);
     131        GetScrollBar(0).SetY(rect.top);
     132        GetScrollBar(0).SetZ(GetBufferedZ());
     133        GetScrollBar(0).SetLength(rect.bottom - rect.top);
    151134    }
    152135}
    153136
    154 void CList::HandleMessage(SGUIMessage &Message)
     137void CList::HandleMessage(SGUIMessage& Message)
    155138{
    156139    IGUIScrollBarOwner::HandleMessage(Message);
    157140    //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
     
    161144    {
    162145    case GUIM_SETTINGS_UPDATED:
    163146        if (Message.value == "list")
    164         {
    165147            SetupText();
    166         }
    167148
    168149        // If selected is changed, call "SelectionChange"
    169150        if (Message.value == "selected")
     
    175156        }
    176157
    177158        if (Message.value == "scrollbar")
    178         {
    179159            SetupText();
    180         }
    181160
    182161        // Update scrollbar
    183162        if (Message.value == "scrollbar_style")
     
    185164            CStr scrollbar_style;
    186165            GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
    187166
    188             GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
     167            GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    189168
    190169            SetupText();
    191170        }
     
    205184        }
    206185
    207186        bool scrollbar;
    208         CGUIList *pList;
     187        CGUIList* pList;
    209188        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    210189        GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    211190        float scroll=0.f;
    212191        if (scrollbar)
    213         {
    214192            scroll = GetScrollBar(0).GetPos();
    215         }
    216193
    217194        CRect rect = GetListRect();
    218195        CPos mouse = GetMousePos();
     
    243220    }
    244221
    245222    case GUIM_LOAD:
    246         {
     223    {
    247224        CStr scrollbar_style;
    248225        GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
    249         GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
    250         }
     226        GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    251227        break;
     228    }
    252229
    253230    default:
    254231        break;
     
    317294    DrawList(selected, "sprite", "sprite_selectarea", "textcolor");
    318295}
    319296
    320 void CList::DrawList(const int &selected,
    321                      const CStr& _sprite,
    322                      const CStr& _sprite_selected,
    323                      const CStr& _textcolor)
     297void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor)
    324298{
    325299    float bz = GetBufferedZ();
    326300
     
    329303    GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    330304
    331305    if (scrollbar)
    332     {
    333         // Draw scrollbar
    334306        IGUIScrollBarOwner::Draw();
    335     }
    336307
    337308    if (GetGUI())
    338309    {
    339310        CRect rect = GetListRect();
    340311
    341         CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
     312        CGUISpriteInstance* sprite = NULL;
     313        CGUISpriteInstance* sprite_selectarea = NULL;
    342314        int cell_id;
    343315        GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite);
    344316        GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea);
    345317        GUI<int>::GetSetting(this, "cell_id", cell_id);
    346318
    347         CGUIList *pList;
     319        CGUIList* pList;
    348320        GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    349321
    350322        GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
    351323
    352324        float scroll=0.f;
    353325        if (scrollbar)
    354         {
    355326            scroll = GetScrollBar(0).GetPos();
    356         }
    357327
    358328        if (selected != -1)
    359329        {
     
    390360        CColor color;
    391361        GUI<CColor>::GetSetting(this, _textcolor, color);
    392362
    393         for (int i=0; i<(int)pList->m_Items.size(); ++i)
     363        for (size_t i=0; i < pList->m_Items.size(); ++i)
    394364        {
    395365            if (m_ItemsYPositions[i+1] - scroll < 0 ||
    396366                m_ItemsYPositions[i] - scroll > rect.GetHeight())
     
    417387
    418388void CList::AddItem(const CStrW& str, const CStrW& data)
    419389{
    420     CGUIList *pList, *pListData;
     390    CGUIList* pList;
     391    CGUIList* pListData;
    421392    GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    422393    GUI<CGUIList>::GetSettingPointer(this, "list_data", pListData);
    423394
    424395    CGUIString gui_string;
    425396    gui_string.SetValue(str);
    426     pList->m_Items.push_back( gui_string );
     397    pList->m_Items.push_back(gui_string);
    427398
    428399    CGUIString data_string;
    429400    data_string.SetValue(data);
    430     pListData->m_Items.push_back( data_string );
     401    pListData->m_Items.push_back(data_string);
    431402
    432403    // TODO Temp
    433404    SetupText();
     
    454425    int selected;
    455426    GUI<int>::GetSetting(this, "selected", selected);
    456427
    457     CGUIList *pList;
     428    CGUIList* pList;
    458429    GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    459430
    460431    if (selected != (int)pList->m_Items.size()-1)
     
    490461    GUI<int>::GetSetting(this, "selected", selected);
    491462
    492463    if (selected >= 0)
    493     {
    494464        GUI<int>::SetSetting(this, "selected", 0);
    495     }
    496465}
    497466   
    498467void CList::SelectLastElement()
     
    500469    int selected;
    501470    GUI<int>::GetSetting(this, "selected", selected);
    502471
    503     CGUIList *pList;
     472    CGUIList* pList;
    504473    GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    505474
    506475    if (selected != (int)pList->m_Items.size()-1)
    507     {
    508476        GUI<int>::SetSetting(this, "selected", (int)pList->m_Items.size()-1);
    509     }
    510477}
    511478
    512479void CList::UpdateAutoScroll()
     
    535502
    536503    // Check lower boundary
    537504    if (m_ItemsYPositions[selected+1]-rect.GetHeight() > scroll)
    538     {
    539505        GetScrollBar(0).SetPos(m_ItemsYPositions[selected+1]-rect.GetHeight());
    540     }
    541506}
  • source/gui/CList.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - List [box]
    20 
    21 --Overview--
    22 
    23     GUI Object for creating lists of information, wherein one
    24      of the elements can be selected. A scroll-bar will aid
    25      when there's too much information to be displayed at once.
    26 
    27 --More info--
    28 
    29     Check GUI.h
    30 
    31 */
    32 
    3318#ifndef INCLUDED_CLIST
    3419#define INCLUDED_CLIST
    3520
    36 //--------------------------------------------------------
    37 //  Includes / Compiler directives
    38 //--------------------------------------------------------
    39 
    4021#include "IGUIScrollBar.h"
    4122
    42 //--------------------------------------------------------
    43 //  Macros
    44 //--------------------------------------------------------
    45 
    46 //--------------------------------------------------------
    47 //  Types
    48 //--------------------------------------------------------
    49 
    50 //--------------------------------------------------------
    51 //  Declarations
    52 //--------------------------------------------------------
    53 
    54 
    5523/**
    5624 * Create a list of elements, where one can be selected
    5725 * by the user. The control will use a pre-processed
     
    5927 * by the IGUITextOwner structure.
    6028 *
    6129 * A scroll-bar will appear when needed. This will be
    62  * achieve with the IGUIScrollBarOwner structure.
    63  *
     30 * achieved with the IGUIScrollBarOwner structure.
    6431 */
    65 
    6632class CList : public IGUIScrollBarOwner, public IGUITextOwner
    6733{
    6834    GUI_OBJECT(CList)
     
    9157    /**
    9258     * @see IGUIObject#HandleMessage()
    9359     */
    94     virtual void HandleMessage(SGUIMessage &Message);
     60    virtual void HandleMessage(SGUIMessage& Message);
    9561
    9662    /**
    9763     * Handle events manually to catch keyboard inputting.
     
    12187
    12288    // Extended drawing interface, this is so that classes built on the this one
    12389    //  can use other sprite names.
    124     virtual void DrawList(const int &selected, const CStr& _sprite,
    125                   const CStr& _sprite_selected, const CStr& _textcolor);
     90    virtual void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor);
    12691
    12792    // Get the area of the list. This is so that it can easily be changed, like in CDropDown
    12893    //  where the area is not equal to m_CachedActualSize.
     
    13297    // (and thus whether list items have possibly changed).
    13398    virtual bool GetModified() const { return m_Modified; }
    13499
    135     // List of items.
    136     //CGUIList m_List;
    137 
    138100    /**
    139101     * List of each element's relative y position. Will be
    140102     * one larger than m_Items, because it will end with the
     
    148110    bool m_Modified;
    149111};
    150112
    151 #endif
     113#endif // INCLUDED_CLIST
  • source/gui/COList.cpp

     
    1414 * You should have received a copy of the GNU General Public License
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
     17
    1718#include "precompiled.h"
     19
    1820#include "COList.h"
    19 #include "i18n/L10n.h"
    2021
     22#include "i18n/L10n.h"
    2123#include "ps/CLogger.h"
    2224#include "soundmanager/ISoundManager.h"
    2325
    24 COList::COList() : CList(),m_HeadingHeight(30.f),m_SelectedDef(-1),m_SelectedColumnOrder(1)
     26COList::COList()
     27    : CList(), m_HeadingHeight(30.f), m_SelectedDef(-1), m_SelectedColumnOrder(1)
    2528{
    2629    AddSetting(GUIST_CGUISpriteInstance,    "sprite_heading");
    2730    AddSetting(GUIST_bool,                  "sortable"); // The actual sorting is done in JS for more versatility
     
    4447    if (!GetGUI())
    4548        return;
    4649
    47     CGUIList *pList;
     50    CGUIList* pList;
    4851    GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
    4952
    50     m_ItemsYPositions.resize( pList->m_Items.size()+1 );
     53    m_ItemsYPositions.resize(pList->m_Items.size() + 1);
    5154
    5255    // Delete all generated texts. Some could probably be saved,
    5356    //  but this is easier, and this function will never be called
    5457    //  continuously, or even often, so it'll probably be okay.
    55     std::vector<SGUIText*>::iterator it;
    56     for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
    57     {
    58         if (*it)
    59             delete *it;
    60     }
     58    for (SGUIText* const& t : m_GeneratedTexts)
     59        delete t;
    6160    m_GeneratedTexts.clear();
    6261
    6362    CStrW font;
     
    8483    GUI<CStr>::GetSetting(this, "default_column", defaultColumn);
    8584    defaultColumn = "list_" + defaultColumn;
    8685
    87     for (unsigned int c=0; c<m_ObjectsDefs.size(); ++c)
     86    for (size_t c=0; c < m_ObjectsDefs.size(); ++c)
    8887    {
    89         SGUIText *text = new SGUIText();
     88        SGUIText* text = new SGUIText();
    9089        CGUIString gui_string;
    9190        gui_string.SetValue(m_ObjectsDefs[c].m_Heading);
    9291        *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this);
    9392        AddText(text);
    9493
    95         if (m_SelectedDef == -1 && defaultColumn == m_ObjectsDefs[c].m_Id)
     94        if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id)
    9695            m_SelectedDef = c;
    9796    }
    9897
     
    10099    // Generate texts
    101100    float buffered_y = 0.f;
    102101
    103     for (int i=0; i<(int)pList->m_Items.size(); ++i)
     102    for (size_t i=0; i < pList->m_Items.size(); ++i)
    104103    {
    105104        m_ItemsYPositions[i] = buffered_y;
    106         for (unsigned int c=0; c<m_ObjectsDefs.size(); ++c)
     105        for (size_t c=0; c < m_ObjectsDefs.size(); ++c)
    107106        {
    108             CGUIList * pList_c;
     107            CGUIList* pList_c;
    109108            GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c);
    110             SGUIText *text = new SGUIText();
     109            SGUIText* text = new SGUIText();
    111110            *text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this);
    112111            if (c==0)
    113112                buffered_y += text->m_Size.cy;
     
    120119    // Setup scrollbar
    121120    if (scrollbar)
    122121    {
    123         GetScrollBar(0).SetScrollRange( m_ItemsYPositions.back() );
    124         GetScrollBar(0).SetScrollSpace( GetListRect().GetHeight() );
     122        GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back());
     123        GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight());
    125124
    126125        CRect rect = GetListRect();
    127         GetScrollBar(0).SetX( rect.right );
    128         GetScrollBar(0).SetY( rect.top );
    129         GetScrollBar(0).SetZ( GetBufferedZ() );
    130         GetScrollBar(0).SetLength( rect.bottom - rect.top );
     126        GetScrollBar(0).SetX(rect.right);
     127        GetScrollBar(0).SetY(rect.top);
     128        GetScrollBar(0).SetZ(GetBufferedZ());
     129        GetScrollBar(0).SetLength(rect.bottom - rect.top);
    131130    }
    132131}
    133132
     
    136135    return m_CachedActualSize + CRect(0, m_HeadingHeight, 0, 0);
    137136}
    138137
    139 void COList::HandleMessage(SGUIMessage &Message)
     138void COList::HandleMessage(SGUIMessage& Message)
    140139{
    141140    CList::HandleMessage(Message);
    142141
     
    155154            return;
    156155       
    157156        float xpos = 0;
    158         for (unsigned int def = 0; def < m_ObjectsDefs.size(); ++def)
     157        for (size_t def = 0; def < m_ObjectsDefs.size(); ++def)
    159158        {
    160159            float width = m_ObjectsDefs[def].m_Width;
    161160            // Check if it's a decimal value, and if so, assume relative positioning.
     
    166165                mouse.x < leftTopCorner.x + width &&
    167166                mouse.y < leftTopCorner.y + m_HeadingHeight)
    168167            {
    169                 if (static_cast<int> (def) != m_SelectedDef)
     168                if (def != m_SelectedDef)
    170169                {
    171170                    m_SelectedColumnOrder = 1;
    172171                    m_SelectedDef = def;
     
    198197    #define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
    199198    #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
    200199    ELMT(item);
    201     ELMT(heading);
    202200    ELMT(def);
    203201    ELMT(translatableAttribute);
    204202    ATTR(id);
     
    209207        AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8());
    210208        return true;
    211209    }
    212     else if (child.GetNodeName() == elmt_heading)
    213     {
    214         CStrW text (child.GetText().FromUTF8());
    215 
    216         return true;
    217     }
    218210    else if (child.GetNodeName() == elmt_def)
    219211    {
    220212        ObjectDef oDef;
    221213
    222214        for (XMBAttribute attr : child.GetAttributes())
    223215        {
    224             CStr attr_name (pFile->GetAttributeString(attr.Name));
    225             CStr attr_value (attr.Value);
     216            CStr attr_name(pFile->GetAttributeString(attr.Name));
     217            CStr attr_value(attr.Value);
    226218
    227219            if (attr_name == "color")
    228220            {
     
    244236                {
    245237                    // Check if it's a relative value, and save as decimal if so.
    246238                    if (attr_value.find("%") != std::string::npos)
    247                     {
    248239                        width = width / 100.f;
    249                     }
    250240                    oDef.m_Width = width;
    251241                }
    252242            }
     
    254244            {
    255245                oDef.m_Heading = attr_value.FromUTF8();
    256246            }
    257 
    258247        }
    259248
    260249        for (XMBElement grandchild : child.GetChildNodes())
    261250        {
    262             if (grandchild.GetNodeName() == elmt_translatableAttribute)
     251            if (grandchild.GetNodeName() != elmt_translatableAttribute)
     252                continue;
     253
     254            CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id));
     255            // only the heading is translatable for list defs
     256            if (attributeName.empty() || attributeName != "heading")
    263257            {
    264                 CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id));
    265                 // only the heading is translatable for list defs
    266                 if (!attributeName.empty() && attributeName == "heading")
    267                 {
    268                     CStr value(grandchild.GetText());
    269                     if (!value.empty())
    270                     {
    271                         CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
    272                         if (!context.empty())
    273                         {
    274                             CStr translatedValue(g_L10n.TranslateWithContext(context, value));
    275                             oDef.m_Heading = translatedValue.FromUTF8();
    276                         }
    277                         else
    278                         {
    279                             CStr translatedValue(g_L10n.Translate(value));
    280                             oDef.m_Heading = translatedValue.FromUTF8();
    281                         }
    282                     }
    283                 }
    284                 else // Ignore.
    285                 {
    286                     LOGERROR("GUI: translatable attribute in olist def that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
    287                 }
     258                LOGERROR("GUI: translatable attribute in olist def that isn't a heading. (object: %s)", this->GetPresentableName().c_str());
     259                continue;
     260            }
     261
     262            CStr value(grandchild.GetText());
     263            if (value.empty())
     264                continue;
     265
     266            CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any.
     267            if (!context.empty())
     268            {
     269                CStr translatedValue(g_L10n.TranslateWithContext(context, value));
     270                oDef.m_Heading = translatedValue.FromUTF8();
     271            }
     272            else
     273            {
     274                CStr translatedValue(g_L10n.Translate(value));
     275                oDef.m_Heading = translatedValue.FromUTF8();
    288276            }
    289277        }
    290278
     
    301289    }
    302290}
    303291
    304 void COList::DrawList(const int &selected,
    305                      const CStr& _sprite,
    306                      const CStr& _sprite_selected,
    307                      const CStr& _textcolor)
     292void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor)
    308293{
    309294    float bz = GetBufferedZ();
    310295
     
    313298    GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    314299
    315300    if (scrollbar)
    316     {
    317         // Draw scrollbar
    318301        IGUIScrollBarOwner::Draw();
    319     }
    320302
    321     if (GetGUI())
    322     {
    323         CRect rect = GetListRect();
     303    if (!GetGUI())
     304        return;
    324305
    325         CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
    326         int cell_id;
    327         GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite);
    328         GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea);
    329         GUI<int>::GetSetting(this, "cell_id", cell_id);
     306    CRect rect = GetListRect();
    330307
    331         CGUIList *pList;
    332         GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
     308    CGUISpriteInstance* sprite=NULL;
     309    CGUISpriteInstance* sprite_selectarea=NULL;
     310    int cell_id;
     311    GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite);
     312    GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea);
     313    GUI<int>::GetSetting(this, "cell_id", cell_id);
    333314
    334         GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
     315    CGUIList* pList;
     316    GUI<CGUIList>::GetSettingPointer(this, "list_name", pList);
    335317
    336         float scroll=0.f;
    337         if (scrollbar)
    338         {
    339             scroll = GetScrollBar(0).GetPos();
    340         }
     318    GetGUI()->DrawSprite(*sprite, cell_id, bz, rect);
    341319
    342         if (selected != -1)
    343         {
    344             ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size());
     320    float scroll=0.f;
     321    if (scrollbar)
     322        scroll = GetScrollBar(0).GetPos();
    345323
    346             // Get rectangle of selection:
    347             CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll,
    348                                  rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll);
     324    if (selected != -1)
     325    {
     326        ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size());
    349327
    350             if (rect_sel.top <= rect.bottom &&
    351                 rect_sel.bottom >= rect.top)
    352             {
    353                 if (rect_sel.bottom > rect.bottom)
    354                     rect_sel.bottom = rect.bottom;
    355                 if (rect_sel.top < rect.top)
    356                     rect_sel.top = rect.top;
     328        // Get rectangle of selection:
     329        CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll,
     330                       rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll);
    357331
    358                 if (scrollbar)
    359                 {
    360                     // Remove any overlapping area of the scrollbar.
    361                     if (rect_sel.right > GetScrollBar(0).GetOuterRect().left &&
    362                         rect_sel.right <= GetScrollBar(0).GetOuterRect().right)
    363                         rect_sel.right = GetScrollBar(0).GetOuterRect().left;
    364 
    365                     if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left &&
    366                         rect_sel.left < GetScrollBar(0).GetOuterRect().right)
    367                         rect_sel.left = GetScrollBar(0).GetOuterRect().right;
    368                 }
     332        if (rect_sel.top <= rect.bottom &&
     333            rect_sel.bottom >= rect.top)
     334        {
     335            if (rect_sel.bottom > rect.bottom)
     336                rect_sel.bottom = rect.bottom;
     337            if (rect_sel.top < rect.top)
     338                rect_sel.top = rect.top;
    369339
    370                 GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel);
     340            if (scrollbar)
     341            {
     342                // Remove any overlapping area of the scrollbar.
     343                if (rect_sel.right > GetScrollBar(0).GetOuterRect().left &&
     344                    rect_sel.right <= GetScrollBar(0).GetOuterRect().right)
     345                    rect_sel.right = GetScrollBar(0).GetOuterRect().left;
     346
     347                if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left &&
     348                    rect_sel.left < GetScrollBar(0).GetOuterRect().right)
     349                    rect_sel.left = GetScrollBar(0).GetOuterRect().right;
    371350            }
     351
     352            GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel);
    372353        }
     354    }
    373355
    374         CColor color;
    375         GUI<CColor>::GetSetting(this, _textcolor, color);
     356    CColor color;
     357    GUI<CColor>::GetSetting(this, _textcolor, color);
     358
     359    CGUISpriteInstance* sprite_heading=NULL;
     360    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading);
     361    CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right,
     362                                    m_CachedActualSize.top + m_HeadingHeight);
     363    GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head);
     364   
     365    CGUISpriteInstance* sprite_order;
     366    CGUISpriteInstance* sprite_not_sorted;
     367    if (m_SelectedColumnOrder != -1)
     368        GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
     369    else
     370        GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order);
     371    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
    376372
    377         CGUISpriteInstance *sprite_heading=NULL;
    378         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_heading", sprite_heading);
    379         CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right,
    380                                         m_CachedActualSize.top + m_HeadingHeight);
    381         GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head);
    382        
    383         CGUISpriteInstance *sprite_order, *sprite_not_sorted;
    384         if (m_SelectedColumnOrder != -1)
    385             GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_asc", sprite_order);
     373    float xpos = 0;
     374    for (size_t def=0; def < m_ObjectsDefs.size(); ++def)
     375    {
     376        // Check if it's a decimal value, and if so, assume relative positioning.
     377        float width = m_ObjectsDefs[def].m_Width;
     378        if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
     379            width *= m_TotalAvalibleColumnWidth;
     380
     381        CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
     382        CGUISpriteInstance *sprite;
     383        // If the list sorted by current column
     384        if (m_SelectedDef == def)
     385            sprite = sprite_order;
    386386        else
    387             GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_desc", sprite_order);
    388         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_not_sorted", sprite_not_sorted);
    389 
    390         float xpos = 0;
    391         for (unsigned int def=0; def< m_ObjectsDefs.size(); ++def)
    392         {
    393             // Check if it's a decimal value, and if so, assume relative positioning.
    394             float width = m_ObjectsDefs[def].m_Width;
    395             if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
    396                 width *= m_TotalAvalibleColumnWidth;
    397 
    398             CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0);
    399             CGUISpriteInstance *sprite;
    400             // If the list sorted by current column
    401             if (m_SelectedDef == static_cast<int> (def))
    402                 sprite = sprite_order;
    403             else
    404                 sprite = sprite_not_sorted;
    405             GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16)));
     387            sprite = sprite_not_sorted;
     388        GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - 16, 0), leftTopCorner + CPos(width, 16)));
    406389
    407             DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
    408             xpos += width;
    409         }
     390        DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);
     391        xpos += width;
     392    }
    410393
    411         const unsigned int objectsCount = m_ObjectsDefs.size();
    412         for (int i=0; i<(int)pList->m_Items.size(); ++i)
    413         {
    414             if (m_ItemsYPositions[i+1] - scroll < 0 ||
    415                 m_ItemsYPositions[i] - scroll > rect.GetHeight())
    416                 continue;
     394    const size_t objectsCount = m_ObjectsDefs.size();
     395    for (size_t i=0; i < pList->m_Items.size(); ++i)
     396    {
     397        if (m_ItemsYPositions[i+1] - scroll < 0 ||
     398            m_ItemsYPositions[i] - scroll > rect.GetHeight())
     399            continue;
    417400
    418             const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i];
     401        const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i];
    419402
    420             // Clipping area (we'll have to substract the scrollbar)
    421             CRect cliparea = GetListRect();
     403        // Clipping area (we'll have to substract the scrollbar)
     404        CRect cliparea = GetListRect();
    422405
    423             if (scrollbar)
    424             {
    425                 if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
    426                     cliparea.right <= GetScrollBar(0).GetOuterRect().right)
    427                     cliparea.right = GetScrollBar(0).GetOuterRect().left;
     406        if (scrollbar)
     407        {
     408            if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
     409                cliparea.right <= GetScrollBar(0).GetOuterRect().right)
     410                cliparea.right = GetScrollBar(0).GetOuterRect().left;
    428411
    429                 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
    430                     cliparea.left < GetScrollBar(0).GetOuterRect().right)
    431                     cliparea.left = GetScrollBar(0).GetOuterRect().right;
    432             }
     412            if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
     413                cliparea.left < GetScrollBar(0).GetOuterRect().right)
     414                cliparea.left = GetScrollBar(0).GetOuterRect().right;
     415        }
    433416
    434             xpos = 0;
    435             for (unsigned int def=0; def < objectsCount; ++def)
    436             {
    437                 // Determine text position and width
    438                 const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
     417        xpos = 0;
     418        for (size_t def=0; def < objectsCount; ++def)
     419        {
     420            // Determine text position and width
     421            const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]);
    439422
    440                 float width = m_ObjectsDefs[def].m_Width;;
    441                 // Check if it's a decimal value, and if so, assume relative positioning.
    442                 if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
    443                     width *= m_TotalAvalibleColumnWidth;
     423            float width = m_ObjectsDefs[def].m_Width;;
     424            // Check if it's a decimal value, and if so, assume relative positioning.
     425            if (m_ObjectsDefs[def].m_Width < 1 && m_ObjectsDefs[def].m_Width > 0)
     426                width *= m_TotalAvalibleColumnWidth;
    444427
    445                 // Clip text to the column (to prevent drawing text into the neighboring column)
    446                 CRect cliparea2 = cliparea;
    447                 cliparea2.right = std::min(cliparea2.right, textPos.x + width);
    448                 cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
     428            // Clip text to the column (to prevent drawing text into the neighboring column)
     429            CRect cliparea2 = cliparea;
     430            cliparea2.right = std::min(cliparea2.right, textPos.x + width);
     431            cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight);
    449432
    450                 DrawText(objectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
    451                 xpos += width;
    452             }
     433            DrawText(objectsCount * (i+/*Heading*/1) + def, m_ObjectsDefs[def].m_TextColor, textPos, bz+0.1f, cliparea2);
     434            xpos += width;
    453435        }
    454436    }
    455437}
  • source/gui/COList.h

     
    1717#ifndef INCLUDED_COLIST
    1818#define INCLUDED_COLIST
    1919
    20 //--------------------------------------------------------
    21 //  Includes / Compiler directives
    22 //--------------------------------------------------------
    2320#include "GUI.h"
    2421#include "CList.h"
    2522
    26 //--------------------------------------------------------
    27 //  Macros
    28 //--------------------------------------------------------
    29 
    30 //--------------------------------------------------------
    31 //  Types
    32 //--------------------------------------------------------
    33 
    34 //--------------------------------------------------------
    35 //  Declarations
    36 //--------------------------------------------------------
    37 
    3823struct ObjectDef
    3924{
    4025  CColor m_TextColor;
     
    4530};
    4631
    4732/**
    48  *  Todo : add description
    49  *
     33 * Multi-column list. One row can be selected by the user.
     34 * Individual cells are clipped if the contained text is too long.
     35 *
     36 * The list can be sorted dynamically by JS code when a
     37 * heading is ckicked.
     38 * A scroll-bar will appear when needed.
    5039 */
    5140class COList : public CList
    5241{
     
    5746
    5847protected:
    5948    void SetupText();
    60     void HandleMessage(SGUIMessage &Message);
     49    void HandleMessage(SGUIMessage& Message);
    6150
    6251    /**
    6352     * Handle the \<item\> tag.
    6453     */
    6554    virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile);
    6655
    67     void DrawList(const int &selected, const CStr& _sprite,
    68                     const CStr& _sprite_selected, const CStr& _textcolor);
     56    void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor);
    6957
    7058    virtual CRect GetListRect() const;
    7159
    7260    std::vector<ObjectDef> m_ObjectsDefs;
    73     int m_SelectedDef;
     61    size_t m_SelectedDef;
    7462    int m_SelectedColumnOrder;
    7563
    7664private:
  • source/gui/CProgressBar.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CProgressBar
    20 */
    21 
    2218#include "precompiled.h"
     19
    2320#include "GUI.h"
    2421#include "CProgressBar.h"
    2522
    2623#include "lib/ogl.h"
    2724
    28 
    29 //-------------------------------------------------------------------
    30 //  Constructor / Destructor
    31 //-------------------------------------------------------------------
    3225CProgressBar::CProgressBar()
    3326{
    3427    AddSetting(GUIST_CGUISpriteInstance,    "sprite_background");
     
    4235{
    4336}
    4437
    45 void CProgressBar::HandleMessage(SGUIMessage &Message)
     38void CProgressBar::HandleMessage(SGUIMessage& Message)
    4639{
    4740    // Important
    4841    IGUIObject::HandleMessage(Message);
     
    7063
    7164void CProgressBar::Draw()
    7265{
    73     if (GetGUI())
    74     {
    75         float bz = GetBufferedZ();
     66    if (!GetGUI())
     67        return;
    7668
    77         CGUISpriteInstance *sprite_background, *sprite_bar;
    78         int cell_id = 0;
    79         float value = 0;
    80         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
    81         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
    82         GUI<float>::GetSetting(this, "caption", value);
     69    float bz = GetBufferedZ();
    8370
    84         GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
     71    CGUISpriteInstance *sprite_background, *sprite_bar;
     72    int cell_id = 0;
     73    float value = 0;
     74    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
     75    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
     76    GUI<float>::GetSetting(this, "caption", value);
    8577
     78    GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
    8679
    87         // Get size of bar (notice it is drawn slightly closer, to appear above the background)
    88         CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
    89                        m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
    90         GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
    91     }
     80    // Get size of bar (notice it is drawn slightly closer, to appear above the background)
     81    CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
     82                   m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
     83    GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
    9284}
  • source/gui/CProgressBar.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Progress bar
    20 
    21 --Overview--
    22 
    23     GUI Object to show progress or a value visually.
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CPROGRESSBAR
    3219#define INCLUDED_CPROGRESSBAR
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    39 //--------------------------------------------------------
    40 //  Macros
    41 //--------------------------------------------------------
    42 
    43 //--------------------------------------------------------
    44 //  Types
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Declarations
    49 //--------------------------------------------------------
    50 
    5123/**
    52  * Object used to draw a value from 0 to 100 visually.
     24 * Object used to draw a value (e.g. progress) from 0 to 100 visually.
    5325 *
    5426 * @see IGUIObject
    5527 */
     
    7143    /**
    7244     * @see IGUIObject#HandleMessage()
    7345     */
    74     void HandleMessage(SGUIMessage &Message);
     46    void HandleMessage(SGUIMessage& Message);
    7547};
    7648
    77 #endif
     49#endif // INCLUDED_CPROGRESSBAR
  • source/gui/CRadioButton.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CCheckBox
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
     19
    2420#include "CRadioButton.h"
    2521
     22#include "GUI.h"
    2623
    27 void CRadioButton::HandleMessage(SGUIMessage &Message)
     24void CRadioButton::HandleMessage(SGUIMessage& Message)
    2825{
    2926    // Important
    3027    IGUIButtonBehavior::HandleMessage(Message);
     
    3330    switch (Message.type)
    3431    {
    3532    case GUIM_PRESSED:
     33        for (IGUIObject* const& obj : *GetParent())
    3634        {
    37             for (vector_pObjects::iterator it = GetParent()->ChildrenItBegin(); it != GetParent()->ChildrenItEnd(); ++it)
    38             {
    39                 // Notice, if you use other objects within the parent object that has got
    40                 //  the setting "checked", it too will change. Hence NO OTHER OBJECTS THAN
    41                 //  RADIO BUTTONS SHOULD BE WITHIN IT!
    42                 GUI<bool>::SetSetting((*it), "checked", false);
    43             }
    44 
    45             GUI<bool>::SetSetting(this, "checked", true);
    46             break;
     35            // Notice, if you use other objects within the parent object that has got
     36            //  the setting "checked", it too will change. Hence NO OTHER OBJECTS THAN
     37            //  RADIO BUTTONS SHOULD BE WITHIN IT!
     38            GUI<bool>::SetSetting(obj, "checked", false);
    4739        }
    4840
     41        GUI<bool>::SetSetting(this, "checked", true);
     42        break;
     43
    4944    default:
    5045        break;
    5146    }
  • source/gui/CRadioButton.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Radio Button
    20 
    21 --Overview--
    22 
    23     GUI Object representing a radio button
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CRADIOBUTTON
    3219#define INCLUDED_CRADIOBUTTON
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822#include "CCheckBox.h"
    3923
     
    5135    /**
    5236     * @see IGUIObject#HandleMessage()
    5337     */
    54     virtual void HandleMessage(SGUIMessage &Message);
     38    virtual void HandleMessage(SGUIMessage& Message);
    5539};
    5640
    57 #endif
     41#endif // INCLUDED_CRADIOBUTTON
  • source/gui/CText.cpp

     
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 CText
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
     19
    2420#include "CText.h"
     21
    2522#include "CGUIScrollBarVertical.h"
     23#include "GUI.h"
    2624
    2725#include "lib/ogl.h"
    2826
    29 
    30 //-------------------------------------------------------------------
    31 //  Constructor / Destructor
    32 //-------------------------------------------------------------------
    3327CText::CText()
    3428{
    3529    AddSetting(GUIST_float,                 "buffer_zone");
     
    5650    GUI<bool>::SetSetting(this, "clip", true);
    5751
    5852    // Add scroll-bar
    59     CGUIScrollBarVertical * bar = new CGUIScrollBarVertical();
     53    CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
    6054    bar->SetRightAligned(true);
    6155    AddScrollBar(bar);
    6256
     
    9690    GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
    9791    *m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, width, buffer_zone, this);
    9892
    99     if (! scrollbar)
     93    if (!scrollbar)
    10094        CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);
    10195
    10296    // Setup scrollbar
     
    126120    }
    127121}
    128122
    129 void CText::HandleMessage(SGUIMessage &Message)
     123void CText::HandleMessage(SGUIMessage& Message)
    130124{
    131125    IGUIScrollBarOwner::HandleMessage(Message);
    132126    //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
     
    135129    {
    136130    case GUIM_SETTINGS_UPDATED:
    137131        if (Message.value == "scrollbar")
    138         {
    139132            SetupText();
    140         }
    141133
    142134        // Update scrollbar
    143135        if (Message.value == "scrollbar_style")
     
    145137            CStr scrollbar_style;
    146138            GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
    147139
    148             GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
     140            GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    149141
    150142            SetupText();
    151143        }
     
    153145        break;
    154146
    155147    case GUIM_MOUSE_WHEEL_DOWN:
    156         {
     148    {
    157149        GetScrollBar(0).ScrollPlus();
    158150        // Since the scroll was changed, let's simulate a mouse movement
    159151        //  to check if scrollbar now is hovered
    160152        SGUIMessage msg(GUIM_MOUSE_MOTION);
    161153        HandleMessage(msg);
    162154        break;
    163         }
     155    }
    164156    case GUIM_MOUSE_WHEEL_UP:
    165         {
     157    {
    166158        GetScrollBar(0).ScrollMinus();
    167159        // Since the scroll was changed, let's simulate a mouse movement
    168160        //  to check if scrollbar now is hovered
    169161        SGUIMessage msg(GUIM_MOUSE_MOTION);
    170162        HandleMessage(msg);
    171163        break;
    172         }
     164    }
    173165    case GUIM_LOAD:
    174         {
    175         GetScrollBar(0).SetX( m_CachedActualSize.right );
    176         GetScrollBar(0).SetY( m_CachedActualSize.top );
    177         GetScrollBar(0).SetZ( GetBufferedZ() );
    178         GetScrollBar(0).SetLength( m_CachedActualSize.bottom - m_CachedActualSize.top );
     166    {
     167        GetScrollBar(0).SetX(m_CachedActualSize.right);
     168        GetScrollBar(0).SetY(m_CachedActualSize.top);
     169        GetScrollBar(0).SetZ(GetBufferedZ());
     170        GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
    179171
    180172        CStr scrollbar_style;
    181173        GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
    182         GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
    183         }
     174        GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    184175        break;
     176    }
    185177
    186178    default:
    187179        break;
     
    199191    GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    200192
    201193    if (scrollbar)
    202     {
    203194        // Draw scrollbar
    204195        IGUIScrollBarOwner::Draw();
    205     }
    206 
    207     if (GetGUI())
    208     {
    209         CGUISpriteInstance *sprite;
    210         int cell_id;
    211         bool clip;
    212         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
    213         GUI<int>::GetSetting(this, "cell_id", cell_id);
    214         GUI<bool>::GetSetting(this, "clip", clip);
    215196
    216         GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
     197    if (!GetGUI())
     198        return;
    217199
    218         float scroll=0.f;
    219         if (scrollbar)
    220         {
    221             scroll = GetScrollBar(0).GetPos();
    222         }
     200    CGUISpriteInstance* sprite;
     201    int cell_id;
     202    bool clip;
     203    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
     204    GUI<int>::GetSetting(this, "cell_id", cell_id);
     205    GUI<bool>::GetSetting(this, "clip", clip);
    223206
    224         // Clipping area (we'll have to subtract the scrollbar)
    225         CRect cliparea;
    226         if (clip)
    227         {
    228             cliparea = m_CachedActualSize;
     207    GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
    229208
    230             if (scrollbar)
    231             {
    232                 // subtract scrollbar from cliparea
    233                 if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
    234                     cliparea.right <= GetScrollBar(0).GetOuterRect().right)
    235                     cliparea.right = GetScrollBar(0).GetOuterRect().left;
    236 
    237                 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
    238                     cliparea.left < GetScrollBar(0).GetOuterRect().right)
    239                     cliparea.left = GetScrollBar(0).GetOuterRect().right;
    240             }
    241         }
     209    float scroll=0.f;
     210    if (scrollbar)
     211        scroll = GetScrollBar(0).GetPos();
    242212
    243         CColor color;
    244         GUI<CColor>::GetSetting(this, "textcolor", color);
     213    // Clipping area (we'll have to subtract the scrollbar)
     214    CRect cliparea;
     215    if (clip)
     216    {
     217        cliparea = m_CachedActualSize;
    245218
    246219        if (scrollbar)
    247             DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz+0.1f, cliparea);
    248         else
    249             DrawText(0, color, m_TextPos, bz+0.1f, cliparea);
     220        {
     221            // subtract scrollbar from cliparea
     222            if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
     223                cliparea.right <= GetScrollBar(0).GetOuterRect().right)
     224                cliparea.right = GetScrollBar(0).GetOuterRect().left;
     225
     226            if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
     227                cliparea.left < GetScrollBar(0).GetOuterRect().right)
     228                cliparea.left = GetScrollBar(0).GetOuterRect().right;
     229        }
    250230    }
     231
     232    CColor color;
     233    GUI<CColor>::GetSetting(this, "textcolor", color);
     234
     235    if (scrollbar)
     236        DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz+0.1f, cliparea);
     237    else
     238        DrawText(0, color, m_TextPos, bz+0.1f, cliparea);
    251239}
    252240
    253241bool CText::MouseOverIcon()
    254242{
    255     std::vector<SGUIText*>::iterator text_it;
    256     std::list<SGUIText::SSpriteCall>::iterator sprite_it;
    257 
    258     for (text_it=m_GeneratedTexts.begin(); text_it!=m_GeneratedTexts.end(); ++text_it)
    259     {
    260         SGUIText* guitext = *text_it;
    261 
    262         for (sprite_it=guitext->m_SpriteCalls.begin(); sprite_it!=guitext->m_SpriteCalls.end(); ++sprite_it)
     243    for (SGUIText* const& guitext : m_GeneratedTexts)
     244        for (const SGUIText::SSpriteCall& spritecall : guitext->m_SpriteCalls)
    263245        {
    264             //Check mouse over sprite
    265             SGUIText::SSpriteCall spritecall = *sprite_it;
     246            // Check mouse over sprite
     247            if (!spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft()))
     248                continue;
    266249
    267             if (spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft()))
     250            // If tooltip exists, set the property
     251            if (!spritecall.m_Tooltip.empty())
    268252            {
    269                 //If tooltip exists, set the property
    270                 if(!spritecall.m_Tooltip.empty())
    271                 {
    272                     SetSetting("_icon_tooltip_style", spritecall.m_TooltipStyle);
    273                     SetSetting("_icon_tooltip", spritecall.m_Tooltip);
    274                 }
    275 
    276                 return true;
     253                SetSetting("_icon_tooltip_style", spritecall.m_TooltipStyle);
     254                SetSetting("_icon_tooltip", spritecall.m_Tooltip);
    277255            }
     256
     257            return true;
    278258        }
    279     }
    280259
    281260    return false;
    282261}
  • source/gui/CText.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Text [field]
    20 
    21 --Overview--
    22 
    23     GUI Object representing a text field
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_CTEXT
    3219#define INCLUDED_CTEXT
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    39 // TODO Gee: Remove
    40 class IGUIScrollBar;
    41 
    42 //--------------------------------------------------------
    43 //  Macros
    44 //--------------------------------------------------------
    45 
    46 //--------------------------------------------------------
    47 //  Types
    48 //--------------------------------------------------------
    49 
    50 //--------------------------------------------------------
    51 //  Declarations
    52 //--------------------------------------------------------
    53 
    5423/**
    5524 * Text field that just displays static text.
    5625 *
     
    8453    /**
    8554     * @see IGUIObject#HandleMessage()
    8655     */
    87     virtual void HandleMessage(SGUIMessage &Message);
     56    virtual void HandleMessage(SGUIMessage& Message);
    8857
    8958    /**
    9059     * Draws the Text
     
    9766    CPos m_TextPos;
    9867};
    9968
    100 #endif
     69#endif // INCLUDED_CTEXT
  • source/gui/CTooltip.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 // CTooltip: GUI object used for tooltips
    19 
    2018#include "precompiled.h"
    2119
    2220#include "CTooltip.h"
     
    144142    GUI<CClientArea>::SetSetting(this, "size", size);
    145143}
    146144
    147 void CTooltip::HandleMessage(SGUIMessage &Message)
     145void CTooltip::HandleMessage(SGUIMessage& Message)
    148146{
    149147    IGUITextOwner::HandleMessage(Message);
    150148}
    151149
    152150void CTooltip::Draw()
    153151{
     152    if (!GetGUI())
     153        return;
     154
    154155    float z = 900.f; // TODO: Find a nicer way of putting the tooltip on top of everything else
    155156
    156     if (GetGUI())
    157     {
    158         CGUISpriteInstance *sprite;
    159         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
     157    CGUISpriteInstance* sprite;
     158    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
    160159
    161         // Normally IGUITextOwner will handle this updating but since SetupText can modify the position
    162         // we need to call it now *before* we do the rest of the drawing
    163         if (!m_GeneratedTextsValid)
    164         {
    165             SetupText();
    166             m_GeneratedTextsValid = true;
    167         }
     160    // Normally IGUITextOwner will handle this updating but since SetupText can modify the position
     161    // we need to call it now *before* we do the rest of the drawing
     162    if (!m_GeneratedTextsValid)
     163    {
     164        SetupText();
     165        m_GeneratedTextsValid = true;
     166    }
    168167
    169         GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize);
     168    GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize);
    170169
    171         CColor color;
    172         GUI<CColor>::GetSetting(this, "textcolor", color);
     170    CColor color;
     171    GUI<CColor>::GetSetting(this, "textcolor", color);
    173172
    174         DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
    175     }
     173    DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
    176174}
  • source/gui/CTooltip.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object - Tooltip
    20 
    21 --Overview--
    22 
    23 Mostly like CText, but intended for dynamic tooltips
    24 
    25 */
    26 
    2718#ifndef INCLUDED_CTOOLTIP
    2819#define INCLUDED_CTOOLTIP
    2920
    3021#include "IGUITextOwner.h"
    3122
     23/**
     24 * Dynamic tooltips. Similar to CText.
     25 */
    3226class CTooltip : public IGUITextOwner
    3327{
    3428    GUI_OBJECT(CTooltip)
     
    4337    /**
    4438     * @see IGUIObject#HandleMessage()
    4539     */
    46     virtual void HandleMessage(SGUIMessage &Message);
     40    virtual void HandleMessage(SGUIMessage& Message);
    4741
    4842    virtual void Draw();
    4943};
    5044
    51 #endif
     45#endif // INCLUDED_CTOOLTIP
  • source/gui/GUI.h

     
    3232#ifndef INCLUDED_GUI
    3333#define INCLUDED_GUI
    3434
    35 //--------------------------------------------------------
    36 //  Includes
    37 //--------------------------------------------------------
    3835#include <map>
     36#include <stddef.h>
    3937#include <string>
    4038#include <vector>
    41 #include <stddef.h>
    4239
    4340#include "ps/CStr.h"
    4441
     42#include "CGUIList.h"
    4543#include "GUIbase.h"
    46 #include "GUIutil.h"
    4744#include "GUItext.h"
    48 #include "CGUIList.h"
    49 #include "IGUIObject.h"
     45#include "GUIutil.h"
    5046#include "IGUIButtonBehavior.h"
    51 #include "IGUIScrollBarOwner.h"
    52 #include "IGUITextOwner.h"
     47#include "IGUIObject.h"
     48#include "IGUIScrollBarOwner.h" // Required by IGUIScrollBar
    5349#include "IGUIScrollBar.h"
     50#include "IGUITextOwner.h"
    5451
    55 #endif
     52#endif // INCLUDED_GUI
  • source/gui/GUIManager.cpp

     
    277277
    278278Status CGUIManager::ReloadChangedFile(const VfsPath& path)
    279279{
    280     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
    281     {
    282         if (it->inputs.count(path))
     280    for (SGUIPage& p : m_PageStack)
     281        if (p.inputs.count(path))
    283282        {
    284             LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(it->name));
    285             LoadPage(*it);
     283            LOGMESSAGE("GUI file '%s' changed - reloading page '%s'", path.string8(), utf8_from_wstring(p.name));
     284            LoadPage(p);
    286285            // TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators
    287286        }
    288     }
    289287
    290288    return INFO::OK;
    291289}
     
    293291Status CGUIManager::ReloadAllPages()
    294292{
    295293    // TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators
    296     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
    297         LoadPage(*it);
     294    for (SGUIPage& p : m_PageStack)
     295        LoadPage(p);
    298296
    299297    return INFO::OK;
    300298}
     
    367365}
    368366
    369367
    370 bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output)
     368bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) const
    371369{
    372370    return top()->GetPreDefinedColor(name, output);
    373371}
     
    382380        return top()->FindObjectByName(name);
    383381}
    384382
    385 void CGUIManager::SendEventToAll(const CStr& eventName)
     383void CGUIManager::SendEventToAll(const CStr& eventName) const
    386384{
    387385    top()->SendEventToAll(eventName);
    388386}
     
    398396    // Save an immutable copy so iterators aren't invalidated by tick handlers
    399397    PageStackType pageStack = m_PageStack;
    400398
    401     for (PageStackType::iterator it = pageStack.begin(); it != pageStack.end(); ++it)
     399    for (const SGUIPage& p : pageStack)
    402400    {
    403         m_CurrentGUI = it->gui;
    404         it->gui->TickObjects();
     401        m_CurrentGUI = p.gui;
     402        p.gui->TickObjects();
    405403    }
    406404    m_CurrentGUI.reset();
    407405}
     
    410408{
    411409    PROFILE3_GPU("gui");
    412410
    413     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
    414         it->gui->Draw();
     411    for (const SGUIPage& p : m_PageStack)
     412        p.gui->Draw();
    415413}
    416414
    417415void CGUIManager::UpdateResolution()
    418416{
    419     for (PageStackType::iterator it = m_PageStack.begin(); it != m_PageStack.end(); ++it)
    420         it->gui->UpdateResolution();
     417    for (const SGUIPage& p : m_PageStack)
     418        p.gui->UpdateResolution();
    421419}
    422420
    423 bool CGUIManager::TemplateExists(const std::string& templateName)
     421bool CGUIManager::TemplateExists(const std::string& templateName) const
    424422{
    425423    return m_TemplateLoader.TemplateExists(templateName);
    426424}
  • source/gui/GUIManager.h

     
    1919#define INCLUDED_GUIMANAGER
    2020
    2121#include <boost/unordered_set.hpp>
     22#include <set>
    2223
    2324#include "lib/input.h"
    2425#include "lib/file/vfs/vfs_path.h"
     
    2829#include "scriptinterface/ScriptVal.h"
    2930#include "scriptinterface/ScriptInterface.h"
    3031
    31 #include <set>
    32 
    3332class CGUI;
    3433class JSObject;
    3534class IGUIObject;
     
    106105    /**
    107106     * See CGUI::GetPreDefinedColor; applies to the currently active page.
    108107     */
    109     bool GetPreDefinedColor(const CStr& name, CColor& output);
     108    bool GetPreDefinedColor(const CStr& name, CColor& output) const;
    110109
    111110    /**
    112111     * See CGUI::FindObjectByName; applies to the currently active page.
     
    116115    /**
    117116     * See CGUI::SendEventToAll; applies to the currently active page.
    118117     */
    119     void SendEventToAll(const CStr& eventName);
     118    void SendEventToAll(const CStr& eventName) const;
    120119
    121120    /**
    122121     * See CGUI::TickObjects; applies to @em all loaded pages.
     
    143142    /**
    144143     * Check if a template with this name exists
    145144     */
    146     bool TemplateExists(const std::string& templateName);
     145    bool TemplateExists(const std::string& templateName) const;
    147146
    148147    /**
    149148     * Retrieve the requested template, used for displaying faction specificities.
  • source/gui/GUIRenderer.cpp

     
    5757}
    5858
    5959
    60 void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName, const CRect &Size, int CellID, std::map<CStr, CGUISprite*> &Sprites)
     60void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites)
    6161{
    6262    // This is called only when something has changed (like the size of the
    6363    // sprite), so it doesn't need to be particularly efficient.
     
    7272        return;
    7373
    7474
    75     std::map<CStr, CGUISprite*>::iterator it (Sprites.find(SpriteName));
     75    std::map<CStr, CGUISprite*>::iterator it(Sprites.find(SpriteName));
    7676    if (it == Sprites.end())
    7777    {
    7878        // Sprite not found. Check whether this a special sprite:
     
    263263    float TexHeight = m_Texture->GetHeight();
    264264
    265265    if (!TexWidth || !TexHeight)
    266     {
    267266        return CRect(0, 0, 1, 1);
    268     }
    269267
    270268    // Textures are positioned by defining a rectangular block of the
    271269    // texture (usually the whole texture), and a rectangular block on
     
    329327    return TexCoords;
    330328}
    331329
    332 void GUIRenderer::Draw(DrawCalls &Calls, float Z)
     330void GUIRenderer::Draw(DrawCalls& Calls, float Z)
    333331{
    334332    // Called every frame, to draw the object (based on cached calculations)
    335333
  • source/gui/GUIRenderer.h

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 #ifndef GUIRenderer_h
    19 #define GUIRenderer_h
     18#ifndef INCLUDED_GUIRENDERER
     19#define INCLUDED_GUIRENDERER
    2020
    2121#include "graphics/ShaderTechnique.h"
    2222#include "graphics/Texture.h"
    2323#include "lib/res/handle.h"
    2424#include "ps/CStr.h"
    2525#include "ps/Shapes.h"
     26
    2627#include <vector>
    2728
    2829struct SGUIImageEffects;
     
    7778
    7879namespace GUIRenderer
    7980{
    80     void UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*> &Sprites);
     81    void UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites);
    8182
    82     void Draw(DrawCalls &Calls, float Z);
     83    void Draw(DrawCalls& Calls, float Z);
    8384}
    8485
    85 #endif // GUIRenderer_h
     86#endif // INCLUDED_GUIRENDERER
  • source/gui/GUITooltip.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1818#include "precompiled.h"
    1919
    2020#include "GUITooltip.h"
    21 #include "lib/timer.h"
    22 #include "IGUIObject.h"
     21
    2322#include "CGUI.h"
    2423#include "GUIutil.h"
     24#include "IGUIObject.h"
    2525
     26#include "lib/timer.h"
    2627#include "ps/CLogger.h"
    2728
    2829/*
     
    137138    return false;
    138139}
    139140
    140 void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui)
     141void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI* gui)
    141142{
    142143    ENSURE(obj);
    143144
     
    147148
    148149    // Get the object referenced by 'tooltip_style'
    149150    IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
    150     if (! tooltipobj)
     151    if (!tooltipobj)
    151152    {
    152153        LOGERROR("Cannot find tooltip named '%s'", style.c_str());
    153154        return;
     
    160161        && !usedObjectName.empty())
    161162    {
    162163        usedobj = gui->FindObjectByName(usedObjectName);
    163         if (! usedobj)
     164        if (!usedobj)
    164165        {
    165166            LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str());
    166167            return;
     
    211212        return;
    212213
    213214    IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
    214     if (! tooltipobj)
     215    if (!tooltipobj)
    215216    {
    216217        LOGERROR("Cannot find tooltip named '%s'", style.c_str());
    217218        return;
     
    222223        && !usedObjectName.empty())
    223224    {
    224225        IGUIObject* usedobj = gui->FindObjectByName(usedObjectName);
    225         if (! usedobj)
     226        if (!usedobj)
    226227        {
    227228            LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str());
    228229            return;
     
    247248
    248249}
    249250
    250 static int GetTooltipDelay(CStr& style, CGUI* gui)
     251static int GetTooltipDelay(const CStr& style, CGUI* gui)
    251252{
    252253    int delay = 500; // default value (in msec)
    253254
    254255    IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
    255     if (! tooltipobj)
     256    if (!tooltipobj)
    256257    {
    257258        LOGERROR("Cannot find tooltip object named '%s'", style.c_str());
    258259        return delay;
     
    261262    return delay;
    262263}
    263264
    264 void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
     265void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI)
    265266{
    266267    // Called once per frame, so efficiency isn't vital
    267268
  • source/gui/GUITooltip.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2828{
    2929public:
    3030    GUITooltip();
    31     void Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI);
     31    void Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI);
    3232
    3333private:
    3434
    35     void ShowTooltip(IGUIObject* obj, CPos pos, const CStr& style, CGUI* gui);
     35    void ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI* gui);
    3636    void HideTooltip(const CStr& style, CGUI* gui);
    3737    bool GetTooltip(IGUIObject* obj, CStr& style);
    3838
  • source/gui/GUIbase.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI base
    20 */
    21 
    2218#include "precompiled.h"
    2319
    24 #include "ps/CLogger.h"
    2520#include "GUI.h"
    2621
    27 //--------------------------------------------------------
    28 //  Help Classes/Structs for the GUI implementation
    29 //--------------------------------------------------------
     22#include "ps/CLogger.h"
    3023
    3124CClientArea::CClientArea() : pixel(0.f,0.f,0.f,0.f), percent(0.f,0.f,0.f,0.f)
    3225{
     
    4235{
    4336}
    4437
    45 CRect CClientArea::GetClientArea(const CRect &parent) const
     38CRect CClientArea::GetClientArea(const CRect& parent) const
    4639{
    4740    // If it's a 0 0 100% 100% we need no calculations
    4841    if (percent == CRect(0.f,0.f,100.f,100.f) && pixel == CRect(0.f,0.f,0.f,0.f))
     
    7871    unsigned int coord = 0;
    7972    float pixels[4] = {0, 0, 0, 0};
    8073    float percents[4] = {0, 0, 0, 0};
    81     for (unsigned int i = 0; i < Value.length(); i++)
     74    for (unsigned int i = 0; i < Value.length(); ++i)
    8275    {
    8376        switch (input[i])
    8477        {
     
    110103        case ' ':
    111104            pixels[coord] += buffer.ToFloat();
    112105            buffer = "";
    113             coord++;
     106            ++coord;
    114107            break;
    115108        default:
    116109            LOGWARNING("ClientArea definitions may only contain numerics. Your input: '%s'", Value.c_str());
     
    143136    percent.bottom =    percents[3];
    144137    return true;
    145138}
    146 
    147 
    148 
    149 //--------------------------------------------------------
    150 //  Error definitions
    151 //--------------------------------------------------------
  • source/gui/GUIbase.h

     
    3232#ifndef INCLUDED_GUIBASE
    3333#define INCLUDED_GUIBASE
    3434
    35 
    36 //--------------------------------------------------------
    37 //  Includes / Compiler directives
    38 //--------------------------------------------------------
    3935#include <map>
    4036#include <vector>
    4137
     38#include "ps/CStr.h"
     39#include "ps/Errors.h"
    4240// I would like to just forward declare CSize, but it doesn't
    4341//  seem to be defined anywhere in the predefined header.
    4442#include "ps/Shapes.h"
    4543
    46 #include "ps/CStr.h"
    47 
    48 #include "ps/Errors.h"
    49 
    50 //--------------------------------------------------------
    51 //  Forward declarations
    52 //--------------------------------------------------------
    5344class IGUIObject;
    5445
    55 //--------------------------------------------------------
    56 //  Macros
    57 //--------------------------------------------------------
    58 
    5946// Object settings setups
    60 
    6147// Setup an object's ConstructObject function
    6248#define GUI_OBJECT(obj)                                                 \
    6349public:                                                                 \
    64     static IGUIObject *ConstructObject() { return new obj(); }
     50    static IGUIObject* ConstructObject() { return new obj(); }
    6551
    6652
    67 //--------------------------------------------------------
    68 //  Types
    69 //--------------------------------------------------------
    70 
    7153/**
    7254 * Message types.
    7355 * @see SGUIMessage
     
    193175    /**
    194176     * Get client area rectangle when the parent is given
    195177     */
    196     CRect GetClientArea(const CRect &parent) const;
     178    CRect GetClientArea(const CRect& parent) const;
    197179
    198180    /**
    199181     * The ClientArea can be set from a string looking like:
     
    217199    }
    218200};
    219201
    220 //--------------------------------------------------------
    221 //  Error declarations
    222 //--------------------------------------------------------
     202
    223203ERROR_GROUP(GUI);
    224204
    225205ERROR_TYPE(GUI, NullObjectProvided);
     
    228208ERROR_TYPE(GUI, NameAmbiguity);
    229209ERROR_TYPE(GUI, ObjectNeedsName);
    230210
    231 #endif
     211#endif // INCLUDED_GUIBASE
  • source/gui/GUItext.cpp

     
    4747    m_NewLine=false;
    4848}
    4949
    50 void CGUIString::GenerateTextCall(const CGUI* pGUI,
    51                                   SFeedback& Feedback,
    52                                   CStrIntern DefaultFont,
    53                                   const int& from, const int& to,
    54                                   const bool FirstLine,
    55                                   const IGUIObject* pObject) const
     50void CGUIString::GenerateTextCall(const CGUI* pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject) const
    5651{
    5752    // Reset width and height, because they will be determined with incrementation
    5853    //  or comparisons.
     
    247242    return true;
    248243}
    249244
    250 CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype)
     245CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype) const
    251246{
    252247    if (tagtype == L"color")
    253248        return TAG_COLOR;
     
    473468    if (m_Words.size() <= 2)
    474469        return;
    475470
    476     std::vector<int>::iterator it;
    477     int last_word = -1;
    478     for (it = m_Words.begin(); it != m_Words.end(); )
    479     {
    480         if (last_word == *it)
    481         {
    482             it = m_Words.erase(it);
    483         }
    484         else
    485         {
    486             last_word = *it;
    487             ++it;
    488         }
    489     }
     471    m_Words.erase(std::unique(m_Words.begin(), m_Words.end()), m_Words.end());
    490472}
  • source/gui/GUItext.h

     
    210210             * @return True if m_TagType was set.
    211211             */
    212212            bool SetTagType(const CStrW& tagtype);
    213             TagType GetTagType(const CStrW& tagtype);
     213            TagType GetTagType(const CStrW& tagtype) const;
    214214
    215215
    216216            /**
     
    309309     *        to make several GenerateTextCall in different phases,
    310310     *        it avoids duplicates.
    311311     */
    312     void GenerateTextCall(const CGUI* pGUI,
    313                           SFeedback& Feedback,
    314                           CStrIntern DefaultFont,
    315                           const int& from, const int& to,
    316                           const bool FirstLine,
    317                           const IGUIObject* pObject = NULL) const;
     312    void GenerateTextCall(const CGUI* pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject = NULL) const;
    318313
    319314    /**
    320315     * Words
     
    338333    CStrW m_OriginalString;
    339334};
    340335
    341 #endif
     336#endif // INCLUDED_GUITEXT
  • source/gui/GUIutil.cpp

     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI utilities
    20 */
    21 
    2218#include "precompiled.h"
     19
    2320#include "GUI.h"
    2421#include "GUIManager.h"
    25 #include "maths/Matrix3D.h"
    26 
    27 extern int g_xres, g_yres;
    2822
     23#include "maths/Matrix3D.h"
    2924#include "ps/CLogger.h"
    3025
     26extern int g_xres, g_yres;
    3127
    3228template <>
    33 bool __ParseString<bool>(const CStrW& Value, bool &Output)
     29bool __ParseString<bool>(const CStrW& Value, bool& Output)
    3430{
    3531    if (Value == L"true")
    3632        Output = true;
    37     else
    38     if (Value == L"false")
     33    else if (Value == L"false")
    3934        Output = false;
    4035    else
    4136        return false;
     
    4439}
    4540
    4641template <>
    47 bool __ParseString<int>(const CStrW& Value, int &Output)
     42bool __ParseString<int>(const CStrW& Value, int& Output)
    4843{
    4944    Output = Value.ToInt();
    5045    return true;
    5146}
    5247
    5348template <>
    54 bool __ParseString<float>(const CStrW& Value, float &Output)
     49bool __ParseString<float>(const CStrW& Value, float& Output)
    5550{
    5651    Output = Value.ToFloat();
    5752    return true;
    5853}
    5954
    6055template <>
    61 bool __ParseString<CRect>(const CStrW& Value, CRect &Output)
     56bool __ParseString<CRect>(const CStrW& Value, CRect& Output)
    6257{
    6358    const unsigned int NUM_COORDS = 4;
    6459    float coords[NUM_COORDS];
    6560    std::wstringstream stream;
    6661    stream.str(Value);
    6762    // Parse each coordinate
    68     for (unsigned int i = 0; i < NUM_COORDS; i++)
     63    for (unsigned int i = 0; i < NUM_COORDS; ++i)
    6964    {
    7065        if (stream.eof())
    7166        {
     
    9388}
    9489
    9590template <>
    96 bool __ParseString<CClientArea>(const CStrW& Value, CClientArea &Output)
     91bool __ParseString<CClientArea>(const CStrW& Value, CClientArea& Output)
    9792{
    9893    return Output.SetClientArea(Value.ToUTF8());
    9994}
    10095
    10196template <>
    102 bool GUI<int>::ParseColor(const CStrW& Value, CColor &Output, int DefaultAlpha)
     97bool GUI<int>::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha)
    10398{
    10499    // First, check our database in g_GUI for pre-defined colors
    105100    //  If we find anything, we'll ignore DefaultAlpha
     
    112107
    113108
    114109template <>
    115 bool __ParseString<CColor>(const CStrW& Value, CColor &Output)
     110bool __ParseString<CColor>(const CStrW& Value, CColor& Output)
    116111{
    117112    // First, check our database in g_GUI for pre-defined colors
    118113    // If it fails, it won't do anything with Output
     
    123118}
    124119
    125120template <>
    126 bool __ParseString<CSize>(const CStrW& Value, CSize &Output)
     121bool __ParseString<CSize>(const CStrW& Value, CSize& Output)
    127122{
    128123    const unsigned int NUM_COORDS = 2;
    129124    float coords[NUM_COORDS];
    130125    std::wstringstream stream;
    131126    stream.str(Value);
    132127    // Parse each coordinate
    133     for (unsigned int i = 0; i < NUM_COORDS; i++)
     128    for (unsigned int i = 0; i < NUM_COORDS; ++i)
    134129    {
    135130        if (stream.eof())
    136131        {
     
    158153}
    159154
    160155template <>
    161 bool __ParseString<CPos>(const CStrW& Value, CPos &Output)
     156bool __ParseString<CPos>(const CStrW& Value, CPos& Output)
    162157{
    163158    const unsigned int NUM_COORDS = 2;
    164159    float coords[NUM_COORDS];
    165160    std::wstringstream stream;
    166161    stream.str(Value);
    167162    // Parse each coordinate
    168     for (unsigned int i = 0; i < NUM_COORDS; i++)
     163    for (unsigned int i = 0; i < NUM_COORDS; ++i)
    169164    {
    170165        if (stream.eof())
    171166        {
     
    193188}
    194189
    195190template <>
    196 bool __ParseString<EAlign>(const CStrW& Value, EAlign &Output)
     191bool __ParseString<EAlign>(const CStrW& Value, EAlign& Output)
    197192{
    198193    if (Value == L"left")
    199194        Output = EAlign_Left;
    200     else
    201     if (Value == L"center")
     195    else if (Value == L"center")
    202196        Output = EAlign_Center;
    203     else
    204     if (Value == L"right")
     197    else if (Value == L"right")
    205198        Output = EAlign_Right;
    206199    else
    207200        return false;
     
    210203}
    211204
    212205template <>
    213 bool __ParseString<EVAlign>(const CStrW& Value, EVAlign &Output)
     206bool __ParseString<EVAlign>(const CStrW& Value, EVAlign& Output)
    214207{
    215208    if (Value == L"top")
    216209        Output = EVAlign_Top;
    217     else
    218     if (Value == L"center")
     210    else if (Value == L"center")
    219211        Output = EVAlign_Center;
    220     else
    221     if (Value == L"bottom")
     212    else if (Value == L"bottom")
    222213        Output = EVAlign_Bottom;
    223214    else
    224215        return false;
     
    227218}
    228219
    229220template <>
    230 bool __ParseString<CGUIString>(const CStrW& Value, CGUIString &Output)
     221bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output)
    231222{
    232     // TODO: i18n: Might want to translate the Value perhaps
    233 
    234223    Output.SetValue(Value);
    235224    return true;
    236225}
     
    246235template <>
    247236bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output)
    248237{
    249     // TODO: i18n: Might want to translate the Value perhaps
    250 
    251238    Output = Value;
    252239    return true;
    253240}
    254241
    255242template <>
    256 bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance &Output)
     243bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance& Output)
    257244{
    258245    Output = CGUISpriteInstance(Value.ToUTF8());
    259246    return true;
     
    288275//--------------------------------------------------------
    289276//  Utilities implementation
    290277//--------------------------------------------------------
    291 IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(CGUI &GUIinstance, const CStr& Object)
     278IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(CGUI& GUIinstance, const CStr& Object)
    292279{
    293280//  if (!GUIinstance.ObjectExists(Object))
    294281//      return NULL;
     
    296283    return GUIinstance.m_pAllObjects.find(Object)->second;
    297284}
    298285
    299 const IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(const CGUI &GUIinstance, const CStr& Object)
     286const IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(const CGUI& GUIinstance, const CStr& Object)
    300287{
    301288//  if (!GUIinstance.ObjectExists(Object))
    302289//      return NULL;
     
    304291    return GUIinstance.m_pAllObjects.find(Object)->second;
    305292}
    306293
    307 void CInternalCGUIAccessorBase::QueryResetting(IGUIObject *pObject)
     294void CInternalCGUIAccessorBase::QueryResetting(IGUIObject* pObject)
    308295{
    309296    GUI<>::RecurseObject(0, pObject, &IGUIObject::ResetStates);
    310297}
    311298
    312 void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, SGUIMessage &message)
     299void CInternalCGUIAccessorBase::HandleMessage(IGUIObject* pObject, SGUIMessage& message)
    313300{
    314301    pObject->HandleMessage(message);
    315302}
     
    335322//--------------------------------------------------------------------
    336323
    337324template <typename T>
    338 PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)
     325PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value)
    339326{
    340327    ENSURE(pObject != NULL);
    341328
     
    362349}
    363350
    364351template <typename T>
    365 PSRETURN GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value)
     352PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value)
    366353{
    367354    T* v = NULL;
    368355    PSRETURN ret = GetSettingPointer(pObject, Setting, v);
     
    384371}
    385372
    386373template <typename T>
    387 PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting,
    388                              const T &Value, const bool& SkipMessage)
     374PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage)
    389375{
    390376    ENSURE(pObject != NULL);
    391377
     
    413399    {
    414400        RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
    415401    }
    416     else
    417     if (Setting == "hidden")
     402    else if (Setting == "hidden")
    418403    {
    419404        // Hiding an object requires us to reset it and all children
    420405        if (IsBoolTrue(Value))
     
    432417
    433418// Instantiate templated functions:
    434419#define TYPE(T) \
    435     template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \
    436     template PSRETURN GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \
    437     template PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value, const bool& SkipMessage);
     420    template PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \
     421    template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \
     422    template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage);
    438423#define GUITYPE_IGNORE_CGUISpriteInstance
    439424#include "GUItypes.h"
    440425#undef GUITYPE_IGNORE_CGUISpriteInstance
     
    444429// you attempt to retrieve a sprite using GetSetting, since that copies the sprite
    445430// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer
    446431// instead. (This is mainly useful to stop me accidentally using the wrong function.)
    447 template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, CGUISpriteInstance* &Value);
    448 template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value, const bool& SkipMessage);
     432template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value);
     433template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, const CGUISpriteInstance& Value, const bool& SkipMessage);
  • source/gui/GUIutil.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3232#ifndef INCLUDED_GUIUTIL
    3333#define INCLUDED_GUIUTIL
    3434
    35 
    36 //--------------------------------------------------------
    37 //  Includes / Compiler directives
    38 //--------------------------------------------------------
    39 #include "GUIbase.h"
    40 // TODO Gee: New
    4135#include "CGUI.h"
    4236#include "CGUISprite.h"
     37#include "GUIbase.h"
    4338#include "IGUIObject.h"
    4439
    45 //--------------------------------------------------------
    46 //  Help Classes/Structs for the GUI
    47 //--------------------------------------------------------
    48 
    4940class CClientArea;
    5041class CGUIString;
    5142class CMatrix3D;
    5243
    5344template <typename T>
    54 bool __ParseString(const CStrW& Value, T &tOutput);
     45bool __ParseString(const CStrW& Value, T& tOutput);
    5546
    5647// Model-view-projection matrix with (0,0) in top-left of screen
    5748CMatrix3D GetDefaultGuiMatrix();
    5849
    59 //--------------------------------------------------------
    60 //  Forward declarations
    61 //--------------------------------------------------------
    6250struct SGUIMessage;
    6351
    6452/**
     
    7260{
    7361protected:
    7462    /// Get object pointer
    75     static IGUIObject * GetObjectPointer(CGUI &GUIinstance, const CStr& Object);
     63    static IGUIObject* GetObjectPointer(CGUI& GUIinstance, const CStr& Object);
    7664   
    7765    /// const version
    78     static const IGUIObject * GetObjectPointer(const CGUI &GUIinstance, const CStr& Object);
     66    static const IGUIObject* GetObjectPointer(const CGUI& GUIinstance, const CStr& Object);
    7967
    8068    /// Wrapper for ResetStates
    81     static void QueryResetting(IGUIObject *pObject);
     69    static void QueryResetting(IGUIObject* pObject);
    8270
    83     static void HandleMessage(IGUIObject *pObject, SGUIMessage &message);
     71    static void HandleMessage(IGUIObject* pObject, SGUIMessage& message);
    8472};
    8573
    8674
     
    10997
    11098    // Like GetSetting (below), but doesn't make a copy of the value
    11199    // (so it can be modified later)
    112     static PSRETURN GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value);
     100    static PSRETURN GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value);
    113101
    114102    /**
    115103     * Retrieves a setting by name from object pointer
     
    118106     * @param Setting Setting by name
    119107     * @param Value Stores value here, note type T!
    120108     */
    121     static PSRETURN GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value);
     109    static PSRETURN GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value);
    122110
    123111    /**
    124112     * Sets a value by name using a real datatype as input.
     
    131119     * @param Value Sets value to this, note type T!
    132120     * @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true
    133121     */
    134     static PSRETURN SetSetting(IGUIObject *pObject, const CStr& Setting,
    135                                 const T &Value, const bool &SkipMessage=false);
     122    static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage=false);
    136123
    137124    /**
    138125     * Retrieves a setting by settings name and object name
     
    142129     * @param Setting Setting by name
    143130     * @param Value Stores value here, note type T!
    144131     */
    145     static PSRETURN GetSetting(
    146         const CGUI &GUIinstance, const CStr& Object,
    147         const CStr& Setting, T &Value)
     132    static PSRETURN GetSetting(const CGUI& GUIinstance, const CStr& Object, const CStr& Setting, T& Value)
    148133    {
    149134        if (!GUIinstance.ObjectExists(Object))
    150135            return PSRETURN_GUI_NullObjectProvided;
    151136
    152137        // Retrieve pointer and call sibling function
    153         const IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
     138        const IGUIObject* pObject = GetObjectPointer(GUIinstance, Object);
    154139
    155140        return GetSetting(pObject, Setting, Value);
    156141    }
     
    168153     * @param Value Sets value to this, note type T!
    169154     * @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true
    170155     */
    171     static PSRETURN SetSetting(
    172         CGUI &GUIinstance, const CStr& Object,
    173         const CStr& Setting, const T &Value,
    174         const bool& SkipMessage=false)
     156    static PSRETURN SetSetting(CGUI& GUIinstance, const CStr& Object, const CStr& Setting, const T& Value, const bool& SkipMessage=false)
    175157    {
    176158        if (!GUIinstance.ObjectExists(Object))
    177159            return PSRETURN_GUI_NullObjectProvided;
     
    181163        // Important, we don't want to use this T, we want
    182164        //  to use the standard T, since that will be the
    183165        //  one with the friend relationship
    184         IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);
     166        IGUIObject* pObject = GetObjectPointer(GUIinstance, Object);
    185167
    186168        return SetSetting(pObject, Setting, Value, SkipMessage);
    187169    }
     
    195177     * @param sec Secondary sprite if Primary should fail
    196178     * @return Resulting string
    197179     */
    198     static const CGUISpriteInstance& FallBackSprite(
    199                                     const CGUISpriteInstance& prim,
    200                                     const CGUISpriteInstance& sec)
     180    static const CGUISpriteInstance& FallBackSprite(const CGUISpriteInstance& prim, const CGUISpriteInstance& sec)
    201181    {
    202182        return (prim.IsEmpty() ? sec : prim);
    203183    }
     
    210190     * @return Resulting color
    211191     * @see FallBackSprite
    212192     */
    213     static CColor FallBackColor(const CColor &prim, const CColor &sec)
     193    static CColor FallBackColor(const CColor& prim, const CColor& sec)
    214194    {
    215195        // CColor() == null.
    216196        return ((prim!=CColor())?(prim):(sec));
     
    229209     *
    230210     * @see __ParseString()
    231211     */
    232     static bool ParseString(const CStrW& Value, T &tOutput)
     212    static bool ParseString(const CStrW& Value, T& tOutput)
    233213    {
    234214        return __ParseString<T>(Value, tOutput);
    235215    }
    236216
    237     static bool ParseColor(const CStrW& Value, CColor &tOutput, int DefaultAlpha);
     217    static bool ParseColor(const CStrW& Value, CColor& tOutput, int DefaultAlpha);
    238218
    239219private:
    240220
    241221    // templated typedef of function pointer
    242     typedef void (IGUIObject::*void_Object_pFunction_argT)(const T &arg);
    243     typedef void (IGUIObject::*void_Object_pFunction_argRefT)(T &arg);
     222    typedef void (IGUIObject::*void_Object_pFunction_argT)(const T& arg);
     223    typedef void (IGUIObject::*void_Object_pFunction_argRefT)(T& arg);
    244224    typedef void (IGUIObject::*void_Object_pFunction)();
    245225
    246226    /**
     
    269249     * @throws PSERROR Depends on what pFunc might throw. PSERROR is standard.
    270250     *          Itself doesn't throw anything.
    271251    */
    272     static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction_argT pFunc, const T &Argument)
     252    static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction_argT pFunc, const T& Argument)
    273253    {
    274254        // TODO Gee: Don't run this for the base object.
    275255        if (CheckIfRestricted(RR, pObject))
     
    278258        (pObject->*pFunc)(Argument);
    279259       
    280260        // Iterate children
    281         vector_pObjects::iterator it;
    282         for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
    283         {
    284             RecurseObject(RR, *it, pFunc, Argument);
    285         }
     261        for (IGUIObject* const& obj : *pObject)
     262            RecurseObject(RR, obj, pFunc, Argument);
    286263    }
    287264
    288265    /**
     
    290267     *
    291268     * @see RecurseObject()
    292269     */
    293     static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction_argRefT pFunc, T &Argument)
     270    static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction_argRefT pFunc, T& Argument)
    294271    {
    295272        if (CheckIfRestricted(RR, pObject))
    296273            return;
     
    298275        (pObject->*pFunc)(Argument);
    299276       
    300277        // Iterate children
    301         vector_pObjects::iterator it;
    302         for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
    303         {
    304             RecurseObject(RR, *it, pFunc, Argument);
    305         }
     278        for (IGUIObject* const& obj : *pObject)
     279            RecurseObject(RR, obj, pFunc, Argument);
    306280    }
    307281
    308282    /**
     
    310284     *
    311285     * @see RecurseObject()
    312286     */
    313     static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction pFunc)
     287    static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction pFunc)
    314288    {
    315289        if (CheckIfRestricted(RR, pObject))
    316290            return;
     
    318292        (pObject->*pFunc)();
    319293
    320294        // Iterate children
    321         vector_pObjects::iterator it;
    322         for (it = pObject->ChildrenItBegin(); it != pObject->ChildrenItEnd(); ++it)
    323         {
    324             RecurseObject(RR, *it, pFunc);
    325         }
     295        for (IGUIObject* const& obj : *pObject)
     296            RecurseObject(RR, obj, pFunc);
    326297    }
    327298
    328299private:
     
    336307     * @param pObject Object
    337308     * @return true if restricted
    338309     */
    339     static bool CheckIfRestricted(int RR, IGUIObject *pObject)
     310    static bool CheckIfRestricted(int RR, IGUIObject* pObject)
    340311    {
    341312        // Statically initialise some strings, so we don't have to do
    342313        // lots of allocation every time this function is called
    343         static CStr strHidden("hidden");
    344         static CStr strEnabled("enabled");
    345         static CStr strGhost("ghost");
     314        static const CStr strHidden("hidden");
     315        static const CStr strEnabled("enabled");
     316        static const CStr strGhost("ghost");
    346317
    347318        if (RR & GUIRR_HIDDEN)
    348319        {
     
    374345    }
    375346};
    376347
    377 #endif
     348#endif // INCLUDED_GUIUTIL
  • source/gui/IGUIButtonBehavior.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 IGUIButtonBehavior
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "ps/CLogger.h"
     19
    2420#include "GUI.h"
    2521
     22#include "ps/CLogger.h"
    2623#include "soundmanager/ISoundManager.h"
    2724
    28 //-------------------------------------------------------------------
    29 //  Constructor / Destructor
    30 //-------------------------------------------------------------------
    3125IGUIButtonBehavior::IGUIButtonBehavior() : m_Pressed(false)
    3226{
    3327}
     
    3630{
    3731}
    3832
    39 void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
     33void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
    4034{
    4135    bool enabled;
    4236    GUI<bool>::GetSetting(this, "enabled", enabled);
     
    4539    switch (Message.type)
    4640    {
    4741    case GUIM_MOUSE_ENTER:
    48     {
    4942        if (!enabled)
    5043            break;
    5144
    5245        if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
    5346            g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    5447        break;
    55     }
    5648
    5749    case GUIM_MOUSE_LEAVE:
    58     {
    5950        if (!enabled)
    6051            break;
    6152
    6253        if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
    6354            g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    6455        break;
    65     }
    6656
    6757    case GUIM_MOUSE_DBLCLICK_LEFT:
    68     {
    6958        if (!enabled)
    7059            break;
    7160
     
    7362        // doubleclick event, we let it handle playing sounds.
    7463        SendEvent(GUIM_DOUBLE_PRESSED, "doublepress");
    7564        break;
    76     }
    7765
    7866    case GUIM_MOUSE_PRESS_LEFT:
    79     {
    8067        if (!enabled)
    8168        {
    8269            if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty())
     
    9077        SendEvent(GUIM_PRESSED, "press");
    9178        m_Pressed = true;
    9279        break;
    93     }
    9480
    9581    case GUIM_MOUSE_DBLCLICK_RIGHT:
    96     {
    9782        if (!enabled)
    9883            break;
    9984
     
    10186        // doubleclick event, we let it handle playing sounds.
    10287        SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright");
    10388        break;
    104     }
     89
    10590    case GUIM_MOUSE_PRESS_RIGHT:
    106     {
    10791        if (!enabled)
    10892        {
    10993            if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty())
     
    117101        SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright");
    118102        m_PressedRight = true;
    119103        break;
    120     }
    121104
    122105    case GUIM_MOUSE_RELEASE_RIGHT:
    123     {
    124106        if (!enabled)
    125107            break;
    126108
     
    131113                g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    132114        }
    133115        break;
    134     }
    135116
    136117    case GUIM_MOUSE_RELEASE_LEFT:
    137     {
    138118        if (!enabled)
    139119            break;
    140120
     
    145125                g_SoundManager->PlayAsUI(soundPath.c_str(), false);
    146126        }
    147127        break;
    148     }
    149128
    150129    default:
    151130        break;
     
    167146        GUI<CColor>::GetSetting(this, "textcolor_disabled", color2);
    168147        return GUI<>::FallBackColor(color2, color);
    169148    }
    170     else
    171     if (m_MouseHovering)
     149    else if (m_MouseHovering)
    172150    {
    173151        if (m_Pressed)
    174152        {
     
    181159            return GUI<>::FallBackColor(color2, color);
    182160        }
    183161    }
    184     else return color;
     162    else
     163        return color;
    185164}
    186165
    187 void IGUIButtonBehavior::DrawButton(const CRect &rect,
    188                                     const float &z,
    189                                     CGUISpriteInstance& sprite,
    190                                     CGUISpriteInstance& sprite_over,
    191                                     CGUISpriteInstance& sprite_pressed,
    192                                     CGUISpriteInstance& sprite_disabled,
    193                                     int cell_id)
     166void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id)
    194167{
    195     if (GetGUI())
    196     {
    197         bool enabled;
    198         GUI<bool>::GetSetting(this, "enabled", enabled);
     168    if (!GetGUI())
     169        return;
    199170
    200         if (!enabled)
    201             GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
    202         else if (m_MouseHovering)
    203         {
    204             if (m_Pressed)
    205                 GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
    206             else
    207                 GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
    208         }
     171    bool enabled;
     172    GUI<bool>::GetSetting(this, "enabled", enabled);
     173
     174    if (!enabled)
     175        GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
     176    else if (m_MouseHovering)
     177    {
     178        if (m_Pressed)
     179            GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
    209180        else
    210             GetGUI()->DrawSprite(sprite, cell_id, z, rect);
     181            GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
    211182    }
     183    else
     184        GetGUI()->DrawSprite(sprite, cell_id, z, rect);
    212185}
  • source/gui/IGUIButtonBehavior.h

     
    3535#ifndef INCLUDED_IGUIBUTTONBEHAVIOR
    3636#define INCLUDED_IGUIBUTTONBEHAVIOR
    3737
    38 //--------------------------------------------------------
    39 //  Includes / Compiler directives
    40 //--------------------------------------------------------
    4138#include "GUI.h"
    4239
    4340class CGUISpriteInstance;
    4441
    45 //--------------------------------------------------------
    46 //  Macros
    47 //--------------------------------------------------------
    48 
    49 //--------------------------------------------------------
    50 //  Types
    51 //--------------------------------------------------------
    52 
    53 //--------------------------------------------------------
    54 //  Declarations
    55 //--------------------------------------------------------
    56 
    5742/**
    5843 * Appends button behaviours to the IGUIObject.
    5944 * Can be used with multiple inheritance alongside
     
    7055    /**
    7156     * @see IGUIObject#HandleMessage()
    7257     */
    73     virtual void HandleMessage(SGUIMessage &Message);
     58    virtual void HandleMessage(SGUIMessage& Message);
    7459
    7560    /**
    7661     * This is a function that lets a button being drawn,
     
    8974     * @param cell_id Identifies the icon to be used (if the sprite contains
    9075     *                cell-using images)
    9176     */
    92     void DrawButton(const CRect &rect,
    93                     const float &z,
    94                     CGUISpriteInstance& sprite,
    95                     CGUISpriteInstance& sprite_over,
    96                     CGUISpriteInstance& sprite_pressed,
    97                     CGUISpriteInstance& sprite_disabled,
    98                     int cell_id);
     77    void DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id);
    9978
    10079    /**
    10180     * Choosing which color of the following according to object enabled/hovered/pressed status:
     
    129108    bool                            m_PressedRight;
    130109};
    131110
    132 #endif
     111#endif // INCLUDED_IGUIBUTTONBEHAVIOR
  • source/gui/IGUIObject.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 IGUIObject
    20 */
    21 
    2218#include "precompiled.h"
     19
    2320#include "GUI.h"
    2421
    25 #include "gui/scripting/JSInterface_IGUIObject.h"
    2622#include "gui/scripting/JSInterface_GUITypes.h"
    27 #include "scriptinterface/ScriptInterface.h"
    28 
     23#include "gui/scripting/JSInterface_IGUIObject.h"
    2924#include "ps/CLogger.h"
     25#include "scriptinterface/ScriptInterface.h"
    3026
    3127
    32 //-------------------------------------------------------------------
    33 //  Implementation Macros
    34 //-------------------------------------------------------------------
    35 
    36 //-------------------------------------------------------------------
    37 //  Constructor / Destructor
    38 //-------------------------------------------------------------------
    39 IGUIObject::IGUIObject() :
    40     m_pGUI(NULL),
    41     m_pParent(NULL),
    42     m_MouseHovering(false)
     28IGUIObject::IGUIObject()
     29    : m_pGUI(NULL), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime()
    4330{
    4431    AddSetting(GUIST_bool,          "enabled");
    4532    AddSetting(GUIST_bool,          "hidden");
     
    5845    GUI<bool>::SetSetting(this, "ghost", false);
    5946    GUI<bool>::SetSetting(this, "enabled", true);
    6047    GUI<bool>::SetSetting(this, "absolute", true);
    61 
    62 
    63     for (int i=0; i<6; i++)
    64         m_LastClickTime[i]=0;
    6548}
    6649
    6750IGUIObject::~IGUIObject()
    6851{
    69     {
    70         std::map<CStr, SGUISetting>::iterator it;
    71         for (it = m_Settings.begin(); it != m_Settings.end(); ++it)
     52    for (const std::pair<CStr, SGUISetting>& p : m_Settings)
     53        switch (p.second.m_Type)
    7254        {
    73             switch (it->second.m_Type)
    74             {
    75                 // delete() needs to know the type of the variable - never delete a void*
    76 #define TYPE(t) case GUIST_##t: delete (t*)it->second.m_pSetting; break;
     55            // delete() needs to know the type of the variable - never delete a void*
     56#define TYPE(t) case GUIST_##t: delete (t*)p.second.m_pSetting; break;
    7757#include "GUItypes.h"
    7858#undef TYPE
    7959        default:
    8060            debug_warn(L"Invalid setting type");
    81             }
    8261        }
    83     }
    8462
    8563    if (m_pGUI)
    8664        JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
     
    8967//-------------------------------------------------------------------
    9068//  Functions
    9169//-------------------------------------------------------------------
    92 void IGUIObject::SetGUI(CGUI * const &pGUI)
     70void IGUIObject::SetGUI(CGUI* const& pGUI)
    9371{
    9472    if (!m_pGUI)
    9573        JS_AddExtraGCRootsTracer(pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
    9674    m_pGUI = pGUI;
    9775}
    9876
    99 void IGUIObject::AddChild(IGUIObject *pChild)
     77void IGUIObject::AddChild(IGUIObject* pChild)
    10078{
    101     //
    10279//  ENSURE(pChild);
    10380
    10481    pChild->SetParent(this);
     
    12299        {
    123100            // If anything went wrong, reverse what we did and throw
    124101            //  an exception telling it never added a child
    125             m_Children.erase( m_Children.end()-1 );
     102            m_Children.erase(m_Children.end()-1);
    126103           
    127104            throw;
    128105        }
     
    130107    // else do nothing
    131108}
    132109
    133 void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap)
     110void IGUIObject::AddToPointersMap(map_pObjects& ObjectMap)
    134111{
    135112    // Just don't do anything about the top node
    136113    if (m_pParent == NULL)
     
    164141        m_Settings[Name].m_pSetting = new type();   \
    165142        break;
    166143
    167 void IGUIObject::AddSetting(const EGUISettingType &Type, const CStr& Name)
     144void IGUIObject::AddSetting(const EGUISettingType& Type, const CStr& Name)
    168145{
    169146    // Is name already taken?
    170147    if (m_Settings.count(Name) >= 1)
     
    188165
    189166bool IGUIObject::MouseOver()
    190167{
    191     if(!GetGUI())
     168    if (!GetGUI())
    192169        throw PSERROR_GUI_OperationNeedsGUIObject();
    193170
    194171    return m_CachedActualSize.PointInside(GetMousePos());
     
    204181    return ((GetGUI())?(GetGUI()->m_MousePos):CPos());
    205182}
    206183
    207 void IGUIObject::UpdateMouseOver(IGUIObject * const &pMouseOver)
     184void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver)
    208185{
    209186    // Check if this is the object being hovered.
    210187    if (pMouseOver == this)
     
    255232PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage)
    256233{
    257234    if (!SettingExists(Setting))
    258     {
    259235        return PSRETURN_GUI_InvalidSetting;
    260     }
    261236
    262237    // Get setting
    263238    SGUISetting set = m_Settings[Setting];
     
    277252#undef TYPE
    278253
    279254
    280 PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const
     255PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType& Type) const
    281256{
    282257    if (!SettingExists(Setting))
    283     {
    284258        return LogInvalidSettings(Setting);
    285     }
    286259
    287260    if (m_Settings.find(Setting) == m_Settings.end())
    288     {
    289261        return LogInvalidSettings(Setting);
    290     }
    291262
    292263    Type = m_Settings.find(Setting)->second.m_Type;
    293264
     
    295266}
    296267
    297268
    298 void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)
     269void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject)
    299270{
    300     if (MouseOver())
     271    if (!MouseOver())
     272        return;
     273
     274    // Check if we've got competition at all
     275    if (pObject == NULL)
    301276    {
    302         // Check if we've got competition at all
    303         if (pObject == NULL)
    304         {
    305             pObject = this;
    306             return;
    307         }
     277        pObject = this;
     278        return;
     279    }
    308280
    309         // Or if it's closer
    310         if (GetBufferedZ() >= pObject->GetBufferedZ())
    311         {
    312             pObject = this;
    313             return;
    314         }
     281    // Or if it's closer
     282    if (GetBufferedZ() >= pObject->GetBufferedZ())
     283    {
     284        pObject = this;
     285        return;
    315286    }
    316287}
    317288
    318 IGUIObject *IGUIObject::GetParent() const
     289IGUIObject* IGUIObject::GetParent() const
    319290{
    320291    // Important, we're not using GetParent() for these
    321292    //  checks, that could screw it up
     
    367338    }
    368339}
    369340
    370 void IGUIObject::LoadStyle(CGUI &GUIinstance, const CStr& StyleName)
     341void IGUIObject::LoadStyle(CGUI& GUIinstance, const CStr& StyleName)
    371342{
    372343    // Fetch style
    373344    if (GUIinstance.m_Styles.count(StyleName)==1)
     
    380351    }
    381352}
    382353
    383 void IGUIObject::LoadStyle(const SGUIStyle &Style)
     354void IGUIObject::LoadStyle(const SGUIStyle& Style)
    384355{
    385356    // Iterate settings, it won't be able to set them all probably, but that doesn't matter
    386     std::map<CStr, CStrW>::const_iterator cit;
    387     for (cit = Style.m_SettingsDefaults.begin(); cit != Style.m_SettingsDefaults.end(); ++cit)
     357    for (const std::pair<CStr, CStrW>& p : Style.m_SettingsDefaults)
    388358    {
    389359        // Try set setting in object
    390         SetSetting(cit->first, cit->second);
     360        SetSetting(p.first, p.second);
    391361
    392362        // It doesn't matter if it fail, it's not suppose to be able to set every setting.
    393363        //  since it's generic.
     
    571541    return (GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject);
    572542}
    573543
    574 void IGUIObject::TraceMember(JSTracer *trc)
     544void IGUIObject::TraceMember(JSTracer* trc)
    575545{
    576546    for (auto& handler : m_ScriptHandlers)
    577547        JS_CallHeapObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers");
    578548}
    579549
    580 PSRETURN IGUIObject::LogInvalidSettings(const CStr8 &Setting) const
     550PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const
    581551{
    582552    LOGWARNING("IGUIObject: setting %s was not found on an object",
    583553        Setting.c_str());
  • source/gui/IGUIObject.h

     
    4343#ifndef INCLUDED_IGUIOBJECT
    4444#define INCLUDED_IGUIOBJECT
    4545
    46 //--------------------------------------------------------
    47 //  Includes / Compiler directives
    48 //--------------------------------------------------------
    4946#include "GUIbase.h"
    5047#include "GUItext.h"
    51 #include <string>
    52 #include <vector>
    53 #include "lib/input.h" // just for IN_PASS
    5448
     49#include "gui/scripting/JSInterface_IGUIObject.h"
     50#include "lib/input.h" // just for IN_PASS
    5551#include "ps/XML/Xeromyces.h"
    5652
    57 #include "gui/scripting/JSInterface_IGUIObject.h"
     53#include <string>
     54#include <vector>
    5855
    5956struct SGUISetting;
    6057struct SGUIStyle;
    6158class CGUI;
    6259
    63 //--------------------------------------------------------
    64 //  Macros
    65 //--------------------------------------------------------
    66 
    67 //--------------------------------------------------------
    68 //  Types
    69 //--------------------------------------------------------
    70 
    7160class JSObject;
    7261
    73 //--------------------------------------------------------
    74 //  Error declarations
    75 //--------------------------------------------------------
    76 
    7762ERROR_TYPE(GUI, UnableToParse);
    7863
    79 //--------------------------------------------------------
    80 //  Declarations
    81 //--------------------------------------------------------
    82 
    8364/**
    8465 * Setting Type
    8566 * @see SGUISetting
     
    192173     * @throws PSERROR_GUI_ObjectNeedsName Name is missing
    193174     * @throws PSERROR_GUI_NameAmbiguity Name is already taken
    194175     */
    195     void AddToPointersMap(map_pObjects &ObjectMap);
     176    void AddToPointersMap(map_pObjects& ObjectMap);
    196177
    197178    /**
    198179     * Notice nothing will be returned or thrown if the child hasn't
     
    210191     *
    211192     * @throws PSERROR_GUI from CGUI::UpdateObjects().
    212193     */
    213     void AddChild(IGUIObject *pChild);
     194    void AddChild(IGUIObject* pChild);
    214195
    215196    //@}
    216197    //--------------------------------------------------------
    217     /** @name Iterate */
     198    /** @name Iterate
     199     * Used to iterate over all children of this object.
     200     */
    218201    //--------------------------------------------------------
    219202    //@{
    220203
    221     vector_pObjects::iterator ChildrenItBegin() { return m_Children.begin(); }
    222     vector_pObjects::iterator ChildrenItEnd()   { return m_Children.end(); }
     204    vector_pObjects::iterator begin() { return m_Children.begin(); }
     205    vector_pObjects::iterator end() { return m_Children.end(); }
    223206
    224207    //@}
    225208    //--------------------------------------------------------
     
    264247     * @param Type Stores an EGUISettingType
    265248     * @return PSRETURN (PSRETURN_OK if successful)
    266249     */
    267     PSRETURN GetSettingType(const CStr& Setting, EGUISettingType &Type) const;
     250    PSRETURN GetSettingType(const CStr& Setting, EGUISettingType& Type) const;
    268251
    269252    /**
    270253     * Set the script handler for a particular object-specific action
     
    300283     * @param Type Setting type
    301284     * @param Name Setting reference name
    302285     */
    303     void AddSetting(const EGUISettingType &Type, const CStr& Name);
     286    void AddSetting(const EGUISettingType& Type, const CStr& Name);
    304287
    305288    /**
    306289     * Calls Destroy on all children, and deallocates all memory.
     
    346329     * @param GUIinstance Reference to the GUI
    347330     * @param StyleName Style by name
    348331     */
    349     void LoadStyle(CGUI &GUIinstance, const CStr& StyleName);
     332    void LoadStyle(CGUI& GUIinstance, const CStr& StyleName);
    350333
    351334    /**
    352335     * Loads a style.
    353336     *
    354337     * @param Style The style object.
    355338     */
    356     void LoadStyle(const SGUIStyle &Style);
     339    void LoadStyle(const SGUIStyle& Style);
    357340
    358341    /**
    359342     * Returns not the Z value, but the actual buffered Z value, i.e. if it's
     
    364347     */
    365348    virtual float GetBufferedZ() const;
    366349
    367     void SetGUI(CGUI * const &pGUI);
     350    void SetGUI(CGUI* const& pGUI);
    368351
    369352    /**
    370353     * Set parent of this object
    371354     */
    372     void SetParent(IGUIObject *pParent) { m_pParent = pParent; }
     355    void SetParent(IGUIObject* pParent) { m_pParent = pParent; }
    373356   
    374357    /**
    375358     * Reset internal state of this object
     
    381364    }
    382365
    383366public:
    384     CGUI *GetGUI() { return m_pGUI; }
    385     const CGUI *GetGUI() const { return m_pGUI; }
     367    CGUI* GetGUI() { return m_pGUI; }
     368    const CGUI* GetGUI() const { return m_pGUI; }
    386369
    387370    /**
    388371     * Take focus!
     
    404387     *
    405388     * @return Pointer to parent
    406389     */
    407     IGUIObject *GetParent() const;
     390    IGUIObject* GetParent() const;
    408391
    409392    /**
    410393     * Get Mouse from CGUI.
     
    419402     * Notice 'false' is default, because an object not using this function, should not
    420403     * have any additional children (and this function should never be called).
    421404     */
    422     virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child),
    423                                             CXeromyces* UNUSED(pFile)) { return false; }
     405    virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child), CXeromyces* UNUSED(pFile))
     406    {
     407        return false;
     408    }
    424409
    425410    /**
    426411     * Cached size, real size m_Size is actually dependent on resolution
     
    466451     * @param pMouseOver    Object that is currently hovered,
    467452     *                      can OF COURSE be NULL too!
    468453     */
    469     void UpdateMouseOver(IGUIObject * const &pMouseOver);
     454    void UpdateMouseOver(IGUIObject* const& pMouseOver);
    470455
    471456    //@}
    472457private:
     
    487472     * @param pObject   Object pointer, can be either the old one, or
    488473     *                  the new one.
    489474     */
    490     void ChooseMouseOverAndClosest(IGUIObject* &pObject);
     475    void ChooseMouseOverAndClosest(IGUIObject*& pObject);
    491476
    492477    // Is the object a Root object, in philosophy, this means it
    493478    //  has got no parent, and technically, it's got the m_BaseObject
     
    501486     */
    502487    PSRETURN LogInvalidSettings(const CStr8& Setting) const;
    503488
    504     static void Trace(JSTracer *trc, void *data)
     489    static void Trace(JSTracer* trc, void* data)
    505490    {
    506491        reinterpret_cast<IGUIObject*>(data)->TraceMember(trc);
    507492    }
    508493
    509     void TraceMember(JSTracer *trc);
     494    void TraceMember(JSTracer* trc);
    510495
    511496    // Variables
    512497
     
    579564    virtual bool MouseOver() { return false; }
    580565};
    581566
    582 #endif
     567#endif // INCLUDED_IGUIOBJECT
  • source/gui/IGUIScrollBar.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 IGUIScrollBar
    20 */
    21 
    2218#include "precompiled.h"
     19
    2320#include "GUI.h"
    2421#include "maths/MathUtil.h"
    2522
    26 //-------------------------------------------------------------------
    27 //  IGUIScrollBar
    28 //-------------------------------------------------------------------
    2923IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL),
    3024                                 m_X(300.f), m_Y(300.f),
    3125                                 m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division.
     
    4842{
    4943    if (!GetStyle())
    5044        return;
     45
    5146    float min = GetStyle()->m_MinimumBarSize;
    5247    float max = GetStyle()->m_MaximumBarSize;
    5348    float length = m_Length;
     
    6661    m_BarSize = clamp(length * std::min((float)m_ScrollSpace / (float)m_ScrollRange, 1.f), min, max);
    6762}
    6863
    69 const SGUIScrollBarStyle *IGUIScrollBar::GetStyle() const
     64const SGUIScrollBarStyle* IGUIScrollBar::GetStyle() const
    7065{
    7166    if (!m_pHostObject)
    7267        return NULL;
     
    7469    return m_pHostObject->GetScrollBarStyle(m_ScrollBarStyle);
    7570}
    7671
    77 CGUI *IGUIScrollBar::GetGUI() const
     72CGUI* IGUIScrollBar::GetGUI() const
    7873{
    7974    if (!m_pHostObject)
    8075        return NULL;
     
    8782    if (m_Pos < 0.f ||
    8883        m_ScrollRange < m_ScrollSpace) // <= scrolling not applicable
    8984        m_Pos = 0.f;
    90     else
    91     if (m_Pos > GetMaxPos())
     85    else if (m_Pos > GetMaxPos())
    9286        m_Pos = GetMaxPos();
    9387}
    9488
    95 void IGUIScrollBar::HandleMessage(SGUIMessage &Message)
     89void IGUIScrollBar::HandleMessage(SGUIMessage& Message)
    9690{
    9791    switch (Message.type)
    9892    {
    99         case GUIM_MOUSE_MOTION:
    100         {
    101             // TODO Gee: Optimizations needed!
    102 
    103             CPos mouse = m_pHostObject->GetMousePos();
    104 
    105                 // If bar is being dragged
    106             if (m_BarPressed)
    107             {
    108                 SetPosFromMousePos(mouse);
    109                 UpdatePosBoundaries();
    110             }
    111 
    112             // check if components are being hovered
    113             m_BarHovered = GetBarRect().PointInside(mouse);
    114             m_ButtonMinusHovered = HoveringButtonMinus(mouse);
    115             m_ButtonPlusHovered =  HoveringButtonPlus(mouse);
     93    case GUIM_MOUSE_MOTION:
     94    {
     95        // TODO Gee: Optimizations needed!
    11696
    117             if (!m_ButtonMinusHovered)
    118                 m_ButtonMinusPressed = false;
     97        CPos mouse = m_pHostObject->GetMousePos();
    11998
    120             if (!m_ButtonPlusHovered)
    121                 m_ButtonPlusPressed = false;
    122             break;
     99            // If bar is being dragged
     100        if (m_BarPressed)
     101        {
     102            SetPosFromMousePos(mouse);
     103            UpdatePosBoundaries();
    123104        }
    124105
    125         case GUIM_MOUSE_PRESS_LEFT:
    126         {
    127             if (!m_pHostObject)
    128                 break;
     106        // check if components are being hovered
     107        m_BarHovered = GetBarRect().PointInside(mouse);
     108        m_ButtonMinusHovered = HoveringButtonMinus(mouse);
     109        m_ButtonPlusHovered =  HoveringButtonPlus(mouse);
    129110
    130             CPos mouse = m_pHostObject->GetMousePos();
     111        if (!m_ButtonMinusHovered)
     112            m_ButtonMinusPressed = false;
    131113
    132             // if bar is pressed
    133             if (GetBarRect().PointInside(mouse))
    134             {
    135                 m_BarPressed = true;
    136                 m_BarPressedAtPos = mouse;
    137                 m_PosWhenPressed = m_Pos;
    138             }
    139             else
    140             // if button-minus is pressed
    141             if (m_ButtonMinusHovered)
    142             {
    143                 m_ButtonMinusPressed = true;
    144                 ScrollMinus();
    145             }
    146             else
    147             // if button-plus is pressed
    148             if (m_ButtonPlusHovered)
    149             {
    150                 m_ButtonPlusPressed = true;
    151                 ScrollPlus();
    152             }
    153             else
    154             // Pressing the background of the bar, to scroll
    155             //  notice the if-sentence alone does not admit that,
    156             //  it must be after the above if/elses
    157             {
    158                 if (GetOuterRect().PointInside(mouse))
    159                 {
    160                     // Scroll plus or minus a lot, this might change, it doesn't
    161                     //  have to be fancy though.
    162                     if (mouse.y < GetBarRect().top)
    163                         ScrollMinusPlenty();
    164                     else
    165                         ScrollPlusPlenty();
    166                         // Simulate mouse movement to see if bar now is hovered
    167                     SGUIMessage msg(GUIM_MOUSE_MOTION);
    168                     HandleMessage(msg);
    169                 }
    170             }
     114        if (!m_ButtonPlusHovered)
     115            m_ButtonPlusPressed = false;
     116        break;
     117    }
     118
     119    case GUIM_MOUSE_PRESS_LEFT:
     120    {
     121        if (!m_pHostObject)
    171122            break;
    172         }
    173123
    174         case GUIM_MOUSE_RELEASE_LEFT:
     124        CPos mouse = m_pHostObject->GetMousePos();
     125
     126        // if bar is pressed
     127        if (GetBarRect().PointInside(mouse))
    175128        {
    176             m_ButtonMinusPressed = false;
    177             m_ButtonPlusPressed = false;
    178             break;
     129            m_BarPressed = true;
     130            m_BarPressedAtPos = mouse;
     131            m_PosWhenPressed = m_Pos;
    179132        }
    180 
    181         case GUIM_MOUSE_WHEEL_UP:
     133        // if button-minus is pressed
     134        else if (m_ButtonMinusHovered)
    182135        {
     136            m_ButtonMinusPressed = true;
    183137            ScrollMinus();
    184             // Since the scroll was changed, let's simulate a mouse movement
    185             //  to check if scrollbar now is hovered
    186             SGUIMessage msg(GUIM_MOUSE_MOTION);
    187             HandleMessage(msg);
    188             break;
    189138        }
    190 
    191         case GUIM_MOUSE_WHEEL_DOWN:
     139        // if button-plus is pressed
     140        else if (m_ButtonPlusHovered)
    192141        {
     142            m_ButtonPlusPressed = true;
    193143            ScrollPlus();
    194             // Since the scroll was changed, let's simulate a mouse movement
    195             //  to check if scrollbar now is hovered
    196             SGUIMessage msg(GUIM_MOUSE_MOTION);
    197             HandleMessage(msg);
    198             break;
    199144        }
     145        else
     146        // Pressing the background of the bar, to scroll
     147        //  notice the if-sentence alone does not admit that,
     148        //  it must be after the above if/elses
     149        {
     150            if (GetOuterRect().PointInside(mouse))
     151            {
     152                // Scroll plus or minus a lot, this might change, it doesn't
     153                //  have to be fancy though.
     154                if (mouse.y < GetBarRect().top)
     155                    ScrollMinusPlenty();
     156                else
     157                    ScrollPlusPlenty();
     158                    // Simulate mouse movement to see if bar now is hovered
     159                SGUIMessage msg(GUIM_MOUSE_MOTION);
     160                HandleMessage(msg);
     161            }
     162        }
     163        break;
     164    }
    200165
    201         default:
    202             break;
     166    case GUIM_MOUSE_RELEASE_LEFT:
     167    {
     168        m_ButtonMinusPressed = false;
     169        m_ButtonPlusPressed = false;
     170        break;
     171    }
     172
     173    case GUIM_MOUSE_WHEEL_UP:
     174    {
     175        ScrollMinus();
     176        // Since the scroll was changed, let's simulate a mouse movement
     177        //  to check if scrollbar now is hovered
     178        SGUIMessage msg(GUIM_MOUSE_MOTION);
     179        HandleMessage(msg);
     180        break;
     181    }
     182
     183    case GUIM_MOUSE_WHEEL_DOWN:
     184    {
     185        ScrollPlus();
     186        // Since the scroll was changed, let's simulate a mouse movement
     187        //  to check if scrollbar now is hovered
     188        SGUIMessage msg(GUIM_MOUSE_MOTION);
     189        HandleMessage(msg);
     190        break;
     191    }
     192
     193    default:
     194        break;
    203195    }
    204196}
  • source/gui/IGUIScrollBar.h

     
    3737#ifndef INCLUDED_IGUISCROLLBAR
    3838#define INCLUDED_IGUISCROLLBAR
    3939
    40 //--------------------------------------------------------
    41 //  Includes / Compiler directives
    42 //--------------------------------------------------------
    4340#include "GUI.h"
    4441
    45 //--------------------------------------------------------
    46 //  Declarations
    47 //--------------------------------------------------------
    48 
    4942/**
    5043 * The GUI Scroll-bar style. Tells us how scroll-bars look and feel.
    5144 *
     
    178171     *
    179172     * @see IGUIObject#HandleMessage()
    180173     */
    181     virtual void HandleMessage(SGUIMessage &Message)=0;
     174    virtual void HandleMessage(SGUIMessage& Message)=0;
    182175
    183176    /**
    184177     * Set m_Pos with g_mouse_x/y input, i.e. when draggin.
    185178     */
    186     virtual void SetPosFromMousePos(const CPos &mouse)=0;
     179    virtual void SetPosFromMousePos(const CPos& mouse)=0;
    187180
    188181    /**
    189182     * Hovering the scroll minus button
     
    240233     * Set host object, must be done almost at creation of scroll bar.
    241234     * @param pOwner Pointer to host object.
    242235     */
    243     void SetHostObject(IGUIScrollBarOwner * pOwner) { m_pHostObject = pOwner; }
     236    void SetHostObject(IGUIScrollBarOwner* pOwner) { m_pHostObject = pOwner; }
    244237
    245238    /**
    246239     * Get GUI pointer
    247240     * @return CGUI pointer
    248241     */
    249     CGUI *GetGUI() const;
     242    CGUI* GetGUI() const;
    250243
    251244    /**
    252245     * Set GUI pointer
    253246     * @param pGUI pointer to CGUI object.
    254247     */
    255     void SetGUI(CGUI *pGUI) { m_pGUI = pGUI; }
     248    void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; }
    256249
    257250    /**
    258251     * Set Width
     
    312305     * Get style used by the scrollbar
    313306     * @return Scroll bar style struct.
    314307     */
    315     const SGUIScrollBarStyle * GetStyle() const;
     308    const SGUIScrollBarStyle* GetStyle() const;
    316309
    317310    /**
    318311     * Get the rectangle of the actual BAR. not the whole scroll-bar.
     
    451444    //@}
    452445};
    453446
    454 #endif
     447#endif // INCLUDED_IGUISCROLLBAR
  • source/gui/IGUIScrollBarOwner.cpp

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 IGUIScrollBarOwner
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
    2419
     20#include "GUI.h"
    2521
    26 //-------------------------------------------------------------------
    27 //  Constructor / Destructor
    28 //-------------------------------------------------------------------
    2922IGUIScrollBarOwner::IGUIScrollBarOwner()
    3023{
    3124}
    3225
    3326IGUIScrollBarOwner::~IGUIScrollBarOwner()
    3427{
    35     // Delete scroll-bars
    36     std::vector<IGUIScrollBar*>::iterator it;
    37     for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
    38     {
    39         delete *it;
    40     }
     28    for (IGUIScrollBar* const& sb : m_ScrollBars)
     29        delete sb;
    4130}
    4231
    4332void IGUIScrollBarOwner::ResetStates()
    4433{
    4534    IGUIObject::ResetStates();
    46    
    47     std::vector<IGUIScrollBar*>::iterator it;
    48     for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
    49     {
    50         (*it)->SetBarPressed(false);
    51     }
     35
     36    for (IGUIScrollBar* const& sb : m_ScrollBars)
     37        sb->SetBarPressed(false);
    5238}
    5339
    54 void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar * scrollbar)
     40void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar* scrollbar)
    5541{
    5642    scrollbar->SetHostObject(this);
    5743    scrollbar->SetGUI(GetGUI());
    5844    m_ScrollBars.push_back(scrollbar);
    5945}
    6046
    61 const SGUIScrollBarStyle * IGUIScrollBarOwner::GetScrollBarStyle(const CStr& style) const
     47const SGUIScrollBarStyle* IGUIScrollBarOwner::GetScrollBarStyle(const CStr& style) const
    6248{
    6349    if (!GetGUI())
    6450    {
     
    7662    return &it->second;
    7763}
    7864
    79 void IGUIScrollBarOwner::HandleMessage(SGUIMessage &Message)
     65void IGUIScrollBarOwner::HandleMessage(SGUIMessage& msg)
    8066{
    81     std::vector<IGUIScrollBar*>::iterator it;
    82     for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
    83     {
    84         (*it)->HandleMessage(Message);
    85     }
     67    for (IGUIScrollBar* const& sb : m_ScrollBars)
     68        sb->HandleMessage(msg);
    8669}
    8770
    8871void IGUIScrollBarOwner::Draw()
    8972{
    90     std::vector<IGUIScrollBar*>::iterator it;
    91     for (it=m_ScrollBars.begin(); it!=m_ScrollBars.end(); ++it)
    92     {
    93         (*it)->Draw();
    94     }
     73    for (IGUIScrollBar* const& sb : m_ScrollBars)
     74        sb->Draw();
    9575}
  • source/gui/IGUIScrollBarOwner.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 GUI Object Base - Scroll-bar owner
    20 
    21 --Overview--
    22 
    23     Base-class this if you want scroll-bars in an object.
    24 
    25 --More info--
    26 
    27     Check GUI.h
    28 
    29 */
    30 
    3118#ifndef INCLUDED_IGUISCROLLBAROWNER
    3219#define INCLUDED_IGUISCROLLBAROWNER
    3320
    34 //--------------------------------------------------------
    35 //  Includes / Compiler directives
    36 //--------------------------------------------------------
    3721#include "GUI.h"
    3822
    3923struct SGUIScrollBarStyle;
    4024class IGUIScrollBar;
    4125
    42 //--------------------------------------------------------
    43 //  Macros
    44 //--------------------------------------------------------
    45 
    46 //--------------------------------------------------------
    47 //  Types
    48 //--------------------------------------------------------
    49 
    50 //--------------------------------------------------------
    51 //  Declarations
    52 //--------------------------------------------------------
    53 
    5426/**
    5527 * Base-class this if you want an object to contain
    5628 * one, or several, scroll-bars.
     
    7143    /**
    7244     * @see IGUIObject#HandleMessage()
    7345     */
    74     virtual void HandleMessage(SGUIMessage &Message);
     46    virtual void HandleMessage(SGUIMessage& Message);
    7547
    7648    /**
    7749     * @see IGUIObject#ResetStates()
     
    8153    /**
    8254     * Interface for the m_ScrollBar to use.
    8355     */
    84     virtual const SGUIScrollBarStyle *GetScrollBarStyle(const CStr& style) const;
     56    virtual const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const;
    8557
    8658    /**
    8759     * Add a scroll-bar
    8860     */
    89     virtual void AddScrollBar(IGUIScrollBar * scrollbar);
     61    virtual void AddScrollBar(IGUIScrollBar* scrollbar);
    9062
    9163    /**
    9264     * Get Scroll Bar reference (it should be transparent it's actually
    9365     * pointers).
    9466     */
    95     virtual IGUIScrollBar & GetScrollBar(const int &index)
     67    virtual IGUIScrollBar& GetScrollBar(const int& index)
    9668    {
    9769        return *m_ScrollBars[index];
    9870    }
     
    10678    std::vector<IGUIScrollBar*> m_ScrollBars;
    10779};
    10880
    109 #endif
     81#endif // INCLUDED_IGUISCROLLBAROWNER
  • source/gui/IGUITextOwner.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    1515 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    1717
    18 /*
    19 IGUITextOwner
    20 */
    21 
    2218#include "precompiled.h"
    23 #include "GUI.h"
    2419
     20#include "GUI.h"
    2521
    26 //-------------------------------------------------------------------
    27 //  Constructor / Destructor
    28 //-------------------------------------------------------------------
    2922IGUITextOwner::IGUITextOwner() : m_GeneratedTextsValid(false)
    3023{
    3124}
    3225
    3326IGUITextOwner::~IGUITextOwner()
    3427{
    35     // Delete all generated texts.
    36     std::vector<SGUIText*>::iterator it;
    37     for (it=m_GeneratedTexts.begin(); it!=m_GeneratedTexts.end(); ++it)
    38     {
    39         delete *it;
    40     }
     28    for (SGUIText* const& t : m_GeneratedTexts)
     29        delete t;
    4130}
    4231
    43 void IGUITextOwner::AddText(SGUIText * text)
     32void IGUITextOwner::AddText(SGUIText* text)
    4433{
    4534    m_GeneratedTexts.push_back(text);
    4635}
    4736
    48 void IGUITextOwner::HandleMessage(SGUIMessage &Message)
     37void IGUITextOwner::HandleMessage(SGUIMessage& Message)
    4938{
    5039    switch (Message.type)
    5140    {
     
    7867    m_GeneratedTextsValid = false;
    7968}
    8069
    81 void IGUITextOwner::DrawText(int index, const CColor& color, const CPos& pos, float z, const CRect& clipping)
     70void IGUITextOwner::DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping)
    8271{
    8372    if (!m_GeneratedTextsValid)
    8473    {
     
    8675        m_GeneratedTextsValid = true;
    8776    }
    8877
    89     if (index < 0 || index >= (int)m_GeneratedTexts.size())
    90     {
    91         debug_warn(L"Trying to draw a Text Index within a IGUITextOwner that doesn't exist");
    92         return;
    93     }
     78    ENSURE(index < m_GeneratedTexts.size() && "Trying to draw a Text Index within a IGUITextOwner that doesn't exist");
    9479
    9580    if (GetGUI())
    96     {
    9781        GetGUI()->DrawText(*m_GeneratedTexts[index], color, pos, z, clipping);
    98     }
    9982}
    10083
    101 void IGUITextOwner::CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text)
     84void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text)
    10285{
    10386    EVAlign valign;
    10487    GUI<EVAlign>::GetSetting(this, "text_valign", valign);
  • source/gui/IGUITextOwner.h

     
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3535#ifndef INCLUDED_IGUITEXTOWNER
    3636#define INCLUDED_IGUITEXTOWNER
    3737
    38 //--------------------------------------------------------
    39 //  Includes / Compiler directives
    40 //--------------------------------------------------------
    4138#include "GUI.h"
    4239
    43 //--------------------------------------------------------
    44 //  Macros
    45 //--------------------------------------------------------
    46 
    47 //--------------------------------------------------------
    48 //  Types
    49 //--------------------------------------------------------
    50 
    51 //--------------------------------------------------------
    52 //  Declarations
    53 //--------------------------------------------------------
    54 
    5540/**
    5641 * Framework for handling Output text.
    5742 *
     
    6651    /**
    6752     * Adds a text object.
    6853     */
    69     void AddText(SGUIText * text);
     54    void AddText(SGUIText* text);
    7055
    7156    /**
    7257     * @see IGUIObject#HandleMessage()
    7358     */
    74     virtual void HandleMessage(SGUIMessage &Message);
     59    virtual void HandleMessage(SGUIMessage& Message);
    7560
    7661    /**
    7762     * @see IGUIObject#UpdateCachedSize()
     
    8873     * @param clipping Clipping rectangle, don't even add a parameter
    8974     *        to get no clipping.
    9075     */
    91     virtual void DrawText(int index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect());
     76    virtual void DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect());
    9277
    9378    /**
    9479     * Test if mouse position is over an icon
     
    115100    /**
    116101     * Calculate the position for the text, based on the alignment.
    117102     */
    118     void CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text);
     103    void CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text);
    119104};
    120105
    121 #endif
     106#endif // INCLUDED_IGUITEXTOWNER
  • source/gui/MiniMap.cpp

     
    3030#include "graphics/TerritoryTexture.h"
    3131#include "gui/GUI.h"
    3232#include "gui/GUIManager.h"
    33 #include "lib/ogl.h"
    34 #include "lib/external_libraries/libsdl.h"
    3533#include "lib/bits.h"
     34#include "lib/external_libraries/libsdl.h"
     35#include "lib/ogl.h"
    3636#include "lib/timer.h"
    3737#include "ps/ConfigDB.h"
    3838#include "ps/Game.h"
     
    105105
    106106    VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>();
    107107    VertexArrayIterator<u8[4]> attrColor = m_AttributeColor.GetIterator<u8[4]>();
    108     for (u16 i = 0; i < MAX_ENTITIES_DRAWN; i++)
     108    for (u16 i = 0; i < MAX_ENTITIES_DRAWN; ++i)
    109109    {
    110110        (*attrColor)[0] = 0;
    111111        (*attrColor)[1] = 0;
     
    137137    Destroy();
    138138}
    139139
    140 void CMiniMap::HandleMessage(SGUIMessage &Message)
     140void CMiniMap::HandleMessage(SGUIMessage& Message)
    141141{
    142     switch(Message.type)
     142    switch (Message.type)
    143143    {
    144144    case GUIM_MOUSE_PRESS_LEFT:
     145        if (m_MouseHovering)
    145146        {
    146             if (m_MouseHovering)
    147             {
    148                 SetCameraPos();
    149                 m_Clicking = true;
    150             }
    151             break;
     147            SetCameraPos();
     148            m_Clicking = true;
    152149        }
     150        break;
    153151    case GUIM_MOUSE_RELEASE_LEFT:
    154         {
    155             if(m_MouseHovering && m_Clicking)
    156                 SetCameraPos();
    157             m_Clicking = false;
    158             break;
    159         }
     152        if(m_MouseHovering && m_Clicking)
     153            SetCameraPos();
     154        m_Clicking = false;
     155        break;
    160156    case GUIM_MOUSE_DBLCLICK_LEFT:
    161         {
    162             if(m_MouseHovering && m_Clicking)
    163                 SetCameraPos();
    164             m_Clicking = false;
    165             break;
    166         }
     157        if(m_MouseHovering && m_Clicking)
     158            SetCameraPos();
     159        m_Clicking = false;
     160        break;
    167161    case GUIM_MOUSE_ENTER:
    168         {
    169             m_MouseHovering = true;
    170             break;
    171         }
     162        m_MouseHovering = true;
     163        break;
    172164    case GUIM_MOUSE_LEAVE:
    173         {
    174             m_Clicking = false;
    175             m_MouseHovering = false;
    176             break;
    177         }
     165        m_Clicking = false;
     166        m_MouseHovering = false;
     167        break;
    178168    case GUIM_MOUSE_RELEASE_RIGHT:
    179         {
    180             CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
    181             break;
    182         }
     169        CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 1);
     170        break;
    183171    case GUIM_MOUSE_DBLCLICK_RIGHT:
    184         {
    185             CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
    186             break;
    187         }
     172        CMiniMap::FireWorldClickEvent(SDL_BUTTON_RIGHT, 2);
     173        break;
    188174    case GUIM_MOUSE_MOTION:
    189         {
    190             if (m_MouseHovering && m_Clicking)
    191                 SetCameraPos();
    192             break;
    193         }
     175        if (m_MouseHovering && m_Clicking)
     176            SetCameraPos();
     177        break;
    194178    case GUIM_MOUSE_WHEEL_DOWN:
    195179    case GUIM_MOUSE_WHEEL_UP:
    196180        Message.Skip();
     
    198182
    199183    default:
    200184        break;
    201     }   // switch
     185    }
    202186}
    203187
    204188bool CMiniMap::MouseOver()
     
    248232    return -atan2(cameraIn.X, cameraIn.Z);
    249233}
    250234
    251 void CMiniMap::FireWorldClickEvent(int button, int clicks)
     235void CMiniMap::FireWorldClickEvent(int UNUSED(button), int UNUSED(clicks))
    252236{
    253237    JSContext* cx = g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext();
    254238    JSAutoRequest rq(cx);
     
    261245    g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "x", x, false);
    262246    g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "z", z, false);
    263247    ScriptEvent("worldclick", coords);
    264 
    265     UNUSED2(button);
    266     UNUSED2(clicks);
    267248}
    268249
    269250// This sets up and draws the rectangle on the minimap
     
    284265    hitPt[3] = m_Camera->GetWorldCoordinates(0, 0, h);
    285266
    286267    float ViewRect[4][2];
    287     for (int i = 0; i < 4; i++) {
     268    for (int i = 0; i < 4; ++i)
     269    {
    288270        // convert to minimap space
    289271        ViewRect[i][0] = (width * hitPt[i].X * invTileMapSize);
    290272        ViewRect[i][1] = (height * hitPt[i].Z * invTileMapSize);
     
    465447    CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture();
    466448
    467449    shader->BindTexture(str_baseTex, territoryTexture.GetTexture());
    468     const CMatrix3D *territoryTransform = territoryTexture.GetMinimapTextureMatrix();
     450    const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix();
    469451    shader->Uniform(str_transform, baseTransform);
    470452    shader->Uniform(str_textureTransform, *territoryTransform);
    471453
     
    484466
    485467    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    486468
    487     const CMatrix3D *losTransform = losTexture.GetMinimapTextureMatrix();
     469    const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix();
    488470    shader->Uniform(str_transform, baseTransform);
    489471    shader->Uniform(str_textureTransform, *losTransform);
    490472
     
    658640
    659641    m_TerrainDirty = false;
    660642
    661     for(u32 j = 0; j < h; j++)
     643    for (u32 j = 0; j < h; ++j)
    662644    {
    663         u32 *dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
    664         for(u32 i = 0; i < w; i++)
     645        u32* dataPtr = m_TerrainData + ((y + j) * (m_MapSize - 1)) + x;
     646        for(u32 i = 0; i < w; ++i)
    665647        {
    666648            float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j)
    667649                    + m_Terrain->GetVertexGroundLevel((int)i+1, (int)j)
     
    686668
    687669                u32 color = 0xFFFFFFFF;
    688670
    689                 CMiniPatch *mp = m_Terrain->GetTile(x + i, y + j);
    690                 if(mp)
     671                CMiniPatch* mp = m_Terrain->GetTile(x + i, y + j);
     672                if (mp)
    691673                {
    692                     CTerrainTextureEntry *tex = mp->GetTextureEntry();
    693                     if(tex)
     674                    CTerrainTextureEntry* tex = mp->GetTextureEntry();
     675                    if (tex)
    694676                    {
    695677                        // If the texture can't be loaded yet, set the dirty flags
    696678                        // so we'll try regenerating the terrain texture again soon
     
    713695
    714696void CMiniMap::Destroy()
    715697{
    716     if(m_TerrainTexture)
     698    if (m_TerrainTexture)
    717699    {
    718700        glDeleteTextures(1, &m_TerrainTexture);
    719701        m_TerrainTexture = 0;
    720702    }
    721703
    722     delete[] m_TerrainData;
    723     m_TerrainData = 0;
     704    SAFE_ARRAY_DELETE(m_TerrainData);
    724705}
  • source/gui/MiniMap.h

     
    3737    /**
    3838     * @see IGUIObject#HandleMessage()
    3939     */
    40     virtual void HandleMessage(SGUIMessage &Message);
     40    virtual void HandleMessage(SGUIMessage& Message);
    4141
    4242    /**
    4343     * @see IGUIObject#MouseOver()
     
    109109    bool m_BlinkState;
    110110};
    111111
    112 #endif
     112#endif // INCLUDED_MINIMAP
  • source/gui/scripting/JSInterface_GUITypes.cpp

     
    8989    if (per == 0)
    9090        return CStr::FromDouble(pix);
    9191    else
    92         return CStr::FromDouble(per)+"%"+( pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix) );
     92        return CStr::FromDouble(per)+"%"+(pix == 0.0 ? CStr() : pix > 0.0 ? CStr("+")+CStr::FromDouble(pix) : CStr::FromDouble(pix));
    9393}
    9494
    9595bool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp)
  • source/gui/scripting/ScriptFunctions.cpp

     
    716716    }
    717717    g_Game->m_Paused = pause;
    718718#if CONFIG2_AUDIO
    719     if ( g_SoundManager )
     719    if (g_SoundManager)
    720720        g_SoundManager->Pause(pause);
    721721#endif
    722722}