Ticket #3354: gui_cleanup_2.patch

File gui_cleanup_2.patch, 269.8 KB (added by leper, 9 years ago)

Updated for r16909.

  • 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");
     
    6658    if (!GetGUI())
    6759        return;
    6860
    69     ENSURE(m_GeneratedTexts.size()==1);
     61    ENSURE(m_GeneratedTexts.size() == 1);
    7062
    7163    CStrW font;
    7264    if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
     
    7769    CGUIString caption;
    7870    GUI<CGUIString>::GetSetting(this, "caption", caption);
    7971
    80     float buffer_zone=0.f;
     72    float buffer_zone = 0.f;
    8173    GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
    8274    *m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this);
    8375
    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);
     
    9587{
    9688    float bz = GetBufferedZ();
    9789
    98     CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
     90    CGUISpriteInstance* sprite;
     91    CGUISpriteInstance* sprite_over;
     92    CGUISpriteInstance* sprite_pressed;
     93    CGUISpriteInstance* sprite_disabled;
    9994    int cell_id;
    10095
    10196    // Statically initialise some strings, so we don't have to do
    10297    // lots of allocation every time this function is called
    103     static CStr strSprite("sprite");
    104     static CStr strSpriteOver("sprite_over");
    105     static CStr strSpritePressed("sprite_pressed");
    106     static CStr strSpriteDisabled("sprite_disabled");
    107     static CStr strCellId("cell_id");
     98    static const CStr strSprite("sprite");
     99    static const CStr strSpriteOver("sprite_over");
     100    static const CStr strSpritePressed("sprite_pressed");
     101    static const CStr strSpriteDisabled("sprite_disabled");
     102    static const CStr strCellId("cell_id");
    108103
    109104    GUI<CGUISpriteInstance>::GetSettingPointer(this, strSprite, sprite);
    110105    GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteOver, sprite_over);
  • 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");
     
    7264    if (!GetGUI())
    7365        return;
    7466
    75     ENSURE(m_GeneratedTexts.size()==1);
     67    ENSURE(m_GeneratedTexts.size() == 1);
    7668
    7769    CStrW font;
    7870    if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
     
    8678    CGUIString caption;
    8779    GUI<CGUIString>::GetSetting(this, "caption", caption);
    8880
    89     float buffer_zone=0.f;
     81    float buffer_zone = 0.f;
    9082    GUI<float>::GetSetting(this, "buffer_zone", 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);
     
    120112    float bz = GetBufferedZ();
    121113    bool checked;
    122114    int cell_id;
    123     CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
     115    CGUISpriteInstance* sprite;
     116    CGUISpriteInstance* sprite_over;
     117    CGUISpriteInstance* sprite_pressed;
     118    CGUISpriteInstance* sprite_disabled;
    124119
    125120    GUI<bool>::GetSetting(this, "checked", checked);
    126121    GUI<int>::GetSetting(this, "cell_id", cell_id);
  • 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    }
     
    344335           
    345336                m_TimeOfLastInput = timer_Time();
    346337           
    347                 CGUIList *pList;
     338                CGUIList* pList;
    348339                GUI<CGUIList>::GetSettingPointer(this, "list", pList);
    349340                // let's look for the closest element
    350341                // basically it's alphabetic order and "as many letters as we can get".
    351342                int closest = -1;
    352343                int bestIndex = -1;
    353344                int difference = 1250;
    354                 for (int i=0; i<(int)pList->m_Items.size(); ++i)
     345                for (int i = 0; i < (int)pList->m_Items.size(); ++i)
    355346                {
    356347                    int indexOfDifference = 0;
    357348                    int diff = 0;
    358                     for (size_t j=0; j < m_InputBuffer.length(); ++j)
     349                    for (size_t j = 0; j < m_InputBuffer.length(); ++j)
    359350                    {
    360351                        diff = abs(pList->m_Items[i].GetOriginalString().LowerCase()[j] - (int)m_InputBuffer[j]);
    361352                        if (diff == 0)
     
    449440    GUI<float>::GetSetting(this, "dropdown_size", dropdown_size);
    450441    GUI<float>::GetSetting(this, "button_width", button_width);
    451442
    452     CGUISpriteInstance *sprite, *sprite2, *sprite2_second;
    453     int cell_id, selected=0;
     443    CGUISpriteInstance* sprite;
     444    CGUISpriteInstance* sprite2;
     445    CGUISpriteInstance* sprite2_second;
     446    int cell_id, selected = 0;
    454447    CColor color;
    455448
    456449    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
     
    501494        DrawText(selected, color, pos, bz+0.1f, cliparea);
    502495    }
    503496
    504     bool *scrollbar=NULL, old;
     497    bool* scrollbar = NULL;
     498    bool old;
    505499    GUI<bool>::GetSettingPointer(this, "scrollbar", scrollbar);
    506500
    507501    old = *scrollbar;
  • 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)
     
    119110    }
    120111
    121112    // Only one object can be hovered
    122     IGUIObject *pNearest = NULL;
     113    IGUIObject* pNearest = NULL;
    123114
    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
     
    310301        &IGUIObject::ScriptEvent, EventName.LowerCase());
    311302}
    312303
    313 //-------------------------------------------------------------------
    314 //  Constructor / Destructor
    315 //-------------------------------------------------------------------
    316 
    317 CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
     304CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
     305    : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
    318306{
    319307    m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime));
    320308    GuiScriptingInit(*m_ScriptInterface);
     
    331319        delete m_BaseObject;
    332320}
    333321
    334 //-------------------------------------------------------------------
    335 //  Functions
    336 //-------------------------------------------------------------------
    337 IGUIObject *CGUI::ConstructObject(const CStr& str)
     322IGUIObject* CGUI::ConstructObject(const CStr& str)
    338323{
    339324    if (m_ObjectTypes.count(str) > 0)
    340325        return (*m_ObjectTypes[str])();
     
    383368    }
    384369}
    385370
    386 void CGUI::DrawSprite(const CGUISpriteInstance& Sprite,
    387                       int CellID,
    388                       const float& Z,
    389                       const CRect& Rect,
    390                       const CRect& UNUSED(Clipping))
     371void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping))
    391372{
    392373    // If the sprite doesn't exist (name == ""), don't bother drawing anything
    393374    if (Sprite.IsEmpty())
     
    402383{
    403384    // We can use the map to delete all
    404385    //  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)
     386    for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects)
    406387    {
    407388        try
    408389        {
    409             it->second->Destroy();
     390            p.second->Destroy();
    410391        }
    411392        catch (PSERROR_GUI& e)
    412393        {
     
    415396            // TODO Gee: Handle
    416397        }
    417398
    418         delete it->second;
     399        delete p.second;
    419400    }
    420 
    421     // Clear all
    422401    m_pAllObjects.clear();
    423     for(std::map<CStr, CGUISprite*>::iterator it = m_Sprites.begin(); it != m_Sprites.end(); ++it)
    424         delete it->second;
     402
     403    for (const std::pair<CStr, CGUISprite*>& p : m_Sprites)
     404        delete p.second;
    425405    m_Sprites.clear();
    426406    m_Icons.clear();
    427407}
     
    429409void CGUI::UpdateResolution()
    430410{
    431411    // Update ALL cached
    432     GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize );
     412    GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize);
    433413}
    434414
    435415void CGUI::AddObject(IGUIObject* pObject)
     
    464444    try
    465445    {
    466446        // Fill freshly
    467         GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects );
     447        GUI<map_pObjects>::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects);
    468448    }
    469449    catch (PSERROR_GUI&)
    470450    {
     
    528508
    529509    // Some help functions
    530510    // TODO Gee: CRect => CPoint ?
    531     void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall,
     511    void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall,
    532512                         const float width, const float y,
    533                          const CSize &Size, const CStr& TextureName,
     513                         const CSize& Size, const CStr& TextureName,
    534514                         const float BufferZone, const int CellID)
    535515    {
    536516        // TODO Gee: Temp hardcoded values
     
    557537    }
    558538};
    559539
    560 SGUIText CGUI::GenerateText(const CGUIString &string,
    561                             const CStrW& FontW, const float &Width, const float &BufferZone,
    562                             const IGUIObject *pObject)
     540SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const float& Width, const float& BufferZone, const IGUIObject* pObject)
    563541{
    564542    SGUIText Text; // object we're generating
    565543
    566544    CStrIntern Font(FontW.ToUTF8());
    567545
    568     if (string.m_Words.size() == 0)
     546    if (string.m_Words.empty())
    569547        return Text;
    570548
    571     float x=BufferZone, y=BufferZone; // drawing pointer
    572     int from=0;
    573     bool done=false;
     549    float x = BufferZone, y = BufferZone; // drawing pointer
     550    int from = 0;
     551    bool done = false;
    574552
    575553    bool FirstLine = true;  // Necessary because text in the first line is shorter
    576554                            // (it doesn't count the line spacing)
    577555
    578556    // Images on the left or the right side.
    579557    std::vector<SGenerateTextImage> Images[2];
    580     int pos_last_img=-1;    // Position in the string where last img (either left or right) were encountered.
     558    int pos_last_img = -1;  // Position in the string where last img (either left or right) were encountered.
    581559                            //  in order to avoid duplicate processing.
    582560
    583561    // Easier to read.
     
    590568    GUI<EAlign>::GetSetting(pObject, "text_align", align);
    591569
    592570    // Go through string word by word
    593     for (int i=0; i<(int)string.m_Words.size()-1 && !done; ++i)
     571    for (int i = 0; i < (int)string.m_Words.size()-1 && !done; ++i)
    594572    {
    595573        // Pre-process each line one time, so we know which floating images
    596574        //  will be added for that line.
     
    599577        CGUIString::SFeedback Feedback;
    600578
    601579        // Preliminary line_height, used for word-wrapping with floating images.
    602         float prelim_line_height=0.f;
     580        float prelim_line_height = 0.f;
    603581
    604582        // Width and height of all text calls generated.
    605583        string.GenerateTextCall(this, Feedback, Font,
     
    613591        if (WordWrapping && i > pos_last_img)
    614592        {
    615593            // Loop left/right
    616             for (int j=0; j<2; ++j)
     594            for (int j = 0; j < 2; ++j)
    617595            {
    618                 for (std::vector<CStr>::const_iterator it = Feedback.m_Images[j].begin();
    619                     it != Feedback.m_Images[j].end();
    620                     ++it)
     596                for (const CStr& imgname : Feedback.m_Images[j])
    621597                {
    622598                    SGUIText::SSpriteCall SpriteCall;
    623599                    SGenerateTextImage Image;
     
    631607                        _y = y;
    632608
    633609                    // Get Size from Icon database
    634                     SGUIIcon icon = GetIcon(*it);
     610                    SGUIIcon icon = GetIcon(imgname);
    635611
    636612                    CSize size = icon.m_Size;
    637                     Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);
     613                    Image.SetupSpriteCall((j == CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);
    638614
    639615                    // Check if image is the lowest thing.
    640616                    Text.m_Size.cy = std::max(Text.m_Size.cy, Image.m_YTo);
     
    657633            int temp_from = from;
    658634            from = i;
    659635
    660             static const int From=0, To=1;
     636            static const int From = 0, To = 1;
    661637            //int width_from=0, width_to=width;
    662638            float width_range[2];
    663639            width_range[From] = BufferZone;
     
    674650                //  structures his text in a stylistically pure fashion. Even if not, it
    675651                //  is still quite unlikely it will happen.
    676652                // Loop through left and right side, from and to.
    677                 for (int j=0; j<2; ++j)
     653                for (int j = 0; j < 2; ++j)
    678654                {
    679                     for (std::vector<SGenerateTextImage>::const_iterator it = Images[j].begin();
    680                         it != Images[j].end();
    681                         ++it)
     655                    for (const SGenerateTextImage& img : Images[j])
    682656                    {
    683657                        // We're working with two intervals here, the image's and the line height's.
    684658                        //  let's find the union of these two.
    685659                        float union_from, union_to;
    686660
    687                         union_from = std::max(y, it->m_YFrom);
    688                         union_to = std::min(y+prelim_line_height, it->m_YTo);
     661                        union_from = std::max(y, img.m_YFrom);
     662                        union_to = std::min(y+prelim_line_height, img.m_YTo);
    689663                       
    690664                        // The union is not empty
    691665                        if (union_to > union_from)
    692666                        {
    693667                            if (j == From)
    694                                 width_range[From] = std::max(width_range[From], it->m_Indentation);
     668                                width_range[From] = std::max(width_range[From], img.m_Indentation);
    695669                            else
    696                                 width_range[To] = std::min(width_range[To], Width - it->m_Indentation);
     670                                width_range[To] = std::min(width_range[To], Width - img.m_Indentation);
    697671                        }
    698672                    }
    699673                }
     
    709683            //  because it didn't regard images, so we don't know
    710684            //  if all characters processed, will actually be involved
    711685            //  in that line.
    712             float line_height=0.f;
    713             float line_width=0.f;
    714             for (int j=temp_from; j<=i; ++j)
     686            float line_height = 0.f;
     687            float line_width = 0.f;
     688            for (int j = temp_from; j <= i; ++j)
    715689            {
    716690                // We don't want to use Feedback now, so we'll have to use
    717691                //  another.
     
    766740            y += line_height;
    767741
    768742            // Do the real processing now
    769             for (int j=temp_from; j<=i; ++j)
     743            for (int j = temp_from; j <= i; ++j)
    770744            {
    771745                // We don't want to use Feedback now, so we'll have to use
    772746                //  another one.
     
    781755                // Since X values are not set, we need to make an internal
    782756                //  iteration with an increment that will append the internal
    783757                //  x, that is what x_pointer is for.
    784                 float x_pointer=0.f;
     758                float x_pointer = 0.f;
    785759
    786                 std::vector<SGUIText::STextCall>::iterator it;
    787                 for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it)
     760                for (SGUIText::STextCall& tc : Feedback2.m_TextCalls)
    788761                {
    789                     it->m_Pos = CPos(dx + x + x_pointer, y);
     762                    tc.m_Pos = CPos(dx + x + x_pointer, y);
    790763
    791                     x_pointer += it->m_Size.cx;
     764                    x_pointer += tc.m_Size.cx;
    792765
    793                     if (it->m_pSpriteCall)
    794                     {
    795                         it->m_pSpriteCall->m_Area += it->m_Pos - CSize(0,it->m_pSpriteCall->m_Area.GetHeight());
    796                     }
     766                    if (tc.m_pSpriteCall)
     767                        tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize(0, tc.m_pSpriteCall->m_Area.GetHeight());
    797768                }
    798769
    799770                // Append X value.
     
    815786                        Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end());
    816787                        break;
    817788                    }
    818                     else
    819                     if (x > width_range[To] && j==temp_from)
     789                    else if (x > width_range[To] && j == temp_from)
    820790                    {
    821791                        from = j+1;
    822792                        // do not break, since we want it to be added to m_TextCalls
    823793                    }
    824                     else
    825                     if (x > width_range[To])
     794                    else if (x > width_range[To])
    826795                    {
    827796                        from = j;
    828797                        break;
     
    856825    return Text;
    857826}
    858827
    859 void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
    860                     const CPos &pos, const float &z, const CRect &clipping)
     828void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping)
    861829{
    862830    CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
    863831
     
    878846    textRenderer.SetClippingRect(clipping);
    879847    textRenderer.Translate(0.0f, 0.0f, z);
    880848
    881     for (std::vector<SGUIText::STextCall>::const_iterator it = Text.m_TextCalls.begin();
    882          it != Text.m_TextCalls.end();
    883          ++it)
     849    for (const SGUIText::STextCall& tc : Text.m_TextCalls)
    884850    {
    885851        // If this is just a placeholder for a sprite call, continue
    886         if (it->m_pSpriteCall)
     852        if (tc.m_pSpriteCall)
    887853            continue;
    888854
    889         CColor color = it->m_UseCustomColor ? it->m_Color : DefaultColor;
     855        CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor;
    890856
    891857        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);
     858        textRenderer.Font(tc.m_Font);
     859        textRenderer.Put((float)(int)(pos.x + tc.m_Pos.x), (float)(int)(pos.y + tc.m_Pos.y), &tc.m_String);
    894860    }
    895861
    896862    textRenderer.Render();
    897863
    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     }
     864    for (const SGUIText::SSpriteCall& sc : Text.m_SpriteCalls)
     865        DrawSprite(sc.m_Sprite, sc.m_CellID, z, sc.m_Area + pos);
    904866
    905867    if (isClipped)
    906868        glDisable(GL_SCISSOR_TEST);
     
    908870    tech->EndPass();
    909871}
    910872
    911 bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output)
     873bool CGUI::GetPreDefinedColor(const CStr& name, CColor& Output) const
    912874{
    913     if (m_PreDefinedColors.count(name) == 0)
    914     {
     875    std::map<CStr, CColor>::const_iterator cit = m_PreDefinedColors.find(name);
     876    if (cit == m_PreDefinedColors.end())
    915877        return false;
    916     }
    917     else
    918     {
    919         Output = m_PreDefinedColors[name];
    920         return true;
    921     }
     878
     879    Output = cit->second;
     880    return true;
    922881}
    923882
    924883/**
     
    941900
    942901    try
    943902    {
    944 
    945903        if (root_name == "objects")
    946904        {
    947905            Xeromyces_ReadRootObjects(node, &XeroFile, Paths);
     
    949907            // Re-cache all values so these gets cached too.
    950908            //UpdateResolution();
    951909        }
    952         else
    953         if (root_name == "sprites")
    954         {
     910        else if (root_name == "sprites")
    955911            Xeromyces_ReadRootSprites(node, &XeroFile);
    956         }
    957         else
    958         if (root_name == "styles")
    959         {
     912        else if (root_name == "styles")
    960913            Xeromyces_ReadRootStyles(node, &XeroFile);
    961         }
    962         else
    963         if (root_name == "setup")
    964         {
     914        else if (root_name == "setup")
    965915            Xeromyces_ReadRootSetup(node, &XeroFile);
    966         }
    967916        else
    968         {
    969917            debug_warn(L"CGUI::LoadXmlFile error");
    970             // TODO Gee: Output in log
    971         }
    972918    }
    973919    catch (PSERROR_GUI& e)
    974920    {
     
    1029975        CStr name(pFile->GetElementString(child.GetNodeName()));
    1030976
    1031977        if (name == "scrollbar")
    1032         {
    1033978            Xeromyces_ReadScrollBarStyle(child, pFile);
    1034         }
    1035         else
    1036         if (name == "icon")
    1037         {
     979        else if (name == "icon")
    1038980            Xeromyces_ReadIcon(child, pFile);
    1039         }
    1040         else
    1041         if (name == "tooltip")
    1042         {
     981        else if (name == "tooltip")
    1043982            Xeromyces_ReadTooltip(child, pFile);
    1044         }
    1045         else
    1046         if (name == "color")
    1047         {
     983        else if (name == "color")
    1048984            Xeromyces_ReadColor(child, pFile);
    1049         }
    1050985        else
    1051         {
    1052986            debug_warn(L"Invalid data - DTD shouldn't allow this");
    1053         }
    1054987    }
    1055988}
    1056989
    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)
     990void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
    1058991{
    1059992    ENSURE(pParent);
    1060993
    1061994    // Our object we are going to create
    1062     IGUIObject *object = NULL;
     995    IGUIObject* object = NULL;
    1063996
    1064997    XMBAttributeList attributes = Element.GetAttributes();
    1065998
    1066999    // Well first of all we need to determine the type
    1067     CStr type (attributes.GetNamedItem(pFile->GetAttributeID("type")));
     1000    CStr type(attributes.GetNamedItem(pFile->GetAttributeID("type")));
    10681001    if (type.empty())
    10691002        type = "empty";
    10701003
     
    11501083            CStr name(attr.Value);
    11511084
    11521085            // Apply the requested substitutions
    1153             for (size_t j = 0; j < NameSubst.size(); ++j)
    1154                 name.Replace(NameSubst[j].first, NameSubst[j].second);
     1086            for (const std::pair<CStr, CStr>& sub : NameSubst)
     1087                name.Replace(sub.first, sub.second);
    11551088
    11561089            object->SetName(name);
    11571090            NameSet = true;
     
    14151348    }
    14161349}
    14171350
    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)
     1351void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
    14191352{
    14201353    #define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
    14211354    #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
     
    14321365
    14331366    for (int n = 0; n < count; ++n)
    14341367    {
    1435         NameSubst.push_back(std::make_pair(var, "[" + CStr::FromInt(n) + "]"));
     1368        NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]");
    14361369
    14371370        XERO_ITER_EL(Element, child)
    14381371        {
     
    14481381void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
    14491382{
    14501383    // Check for a 'file' parameter
    1451     CStrW file(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file") ).FromUTF8());
     1384    CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8());
    14521385
    14531386    // If there is a file specified, open and execute it
    14541387    if (!file.empty())
     
    14651398    }
    14661399
    14671400    // If it has a directory attribute, read all JS files in that directory
    1468     CStrW directory(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("directory") ).FromUTF8());
     1401    CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8());
    14691402    if (!directory.empty())
    14701403    {
    14711404        VfsPaths pathnames;
     
    15131446    //
    15141447
    15151448    // Get name, we know it exists because of DTD requirements
    1516     name = Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("name") );
     1449    name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name"));
    15171450
    15181451    if (m_Sprites.find(name) != m_Sprites.end())
    15191452        LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str());
     
    15531486    // Apply the effects to every image (unless the image overrides it with
    15541487    // different effects)
    15551488    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
     1489        for (SGUIImage* const& img : Sprite->m_Images)
     1490            if (!img->m_Effects)
     1491                img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
    15591492
    15601493    delete effects;
    15611494
     
    15661499    m_Sprites[name] = Sprite;
    15671500}
    15681501
    1569 void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent)
     1502void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent)
    15701503{
    15711504
    15721505    // Image object we're adding
     
    15921525        {
    15931526            Image->m_TextureName = VfsPath("art/textures/ui") / attr_value;
    15941527        }
    1595         else
    1596         if (attr_name == "size")
     1528        else if (attr_name == "size")
    15971529        {
    15981530            CClientArea ca;
    15991531            if (!GUI<CClientArea>::ParseString(attr_value, ca))
    16001532                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1601             else Image->m_Size = ca;
     1533            else
     1534                Image->m_Size = ca;
    16021535        }
    1603         else
    1604         if (attr_name == "texture_size")
     1536        else if (attr_name == "texture_size")
    16051537        {
    16061538            CClientArea ca;
    16071539            if (!GUI<CClientArea>::ParseString(attr_value, ca))
    16081540                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1609             else Image->m_TextureSize = ca;
     1541            else
     1542                Image->m_TextureSize = ca;
    16101543        }
    1611         else
    1612         if (attr_name == "real_texture_placement")
     1544        else if (attr_name == "real_texture_placement")
    16131545        {
    16141546            CRect rect;
    16151547            if (!GUI<CRect>::ParseString(attr_value, rect))
    16161548                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1617             else Image->m_TexturePlacementInFile = rect;
     1549            else
     1550                Image->m_TexturePlacementInFile = rect;
    16181551        }
    1619         else
    1620         if (attr_name == "cell_size")
     1552        else if (attr_name == "cell_size")
    16211553        {
    16221554            CSize size;
    16231555            if (!GUI<CSize>::ParseString(attr_value, size))
    16241556                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1625             else Image->m_CellSize = size;
     1557            else
     1558                Image->m_CellSize = size;
    16261559        }
    1627         else
    1628         if (attr_name == "fixed_h_aspect_ratio")
     1560        else if (attr_name == "fixed_h_aspect_ratio")
    16291561        {
    16301562            float val;
    16311563            if (!GUI<float>::ParseString(attr_value, val))
    16321564                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1633             else Image->m_FixedHAspectRatio = val;
     1565            else
     1566                Image->m_FixedHAspectRatio = val;
    16341567        }
    1635         else
    1636         if (attr_name == "round_coordinates")
     1568        else if (attr_name == "round_coordinates")
    16371569        {
    16381570            bool b;
    16391571            if (!GUI<bool>::ParseString(attr_value, b))
    16401572                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1641             else Image->m_RoundCoordinates = b;
     1573            else
     1574                Image->m_RoundCoordinates = b;
    16421575        }
    1643         else
    1644         if (attr_name == "wrap_mode")
     1576        else if (attr_name == "wrap_mode")
    16451577        {
    16461578            if (attr_value == L"repeat")
    16471579                Image->m_WrapMode = GL_REPEAT;
     
    16521584            else
    16531585                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    16541586        }
    1655         else
    1656         if (attr_name == "z_level")
     1587        else if (attr_name == "z_level")
    16571588        {
    16581589            float z_level;
    16591590            if (!GUI<float>::ParseString(attr_value, z_level))
    16601591                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1661             else Image->m_DeltaZ = z_level/100.f;
     1592            else
     1593                Image->m_DeltaZ = z_level/100.f;
    16621594        }
    1663         else
    1664         if (attr_name == "backcolor")
     1595        else if (attr_name == "backcolor")
    16651596        {
    16661597            CColor color;
    16671598            if (!GUI<CColor>::ParseString(attr_value, color))
    16681599                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1669             else Image->m_BackColor = color;
     1600            else
     1601                Image->m_BackColor = color;
    16701602        }
    1671         else
    1672         if (attr_name == "bordercolor")
     1603        else if (attr_name == "bordercolor")
    16731604        {
    16741605            CColor color;
    16751606            if (!GUI<CColor>::ParseString(attr_value, color))
    16761607                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1677             else Image->m_BorderColor = color;
     1608            else
     1609                Image->m_BorderColor = color;
    16781610        }
    1679         else
    1680         if (attr_name == "border")
     1611        else if (attr_name == "border")
    16811612        {
    16821613            bool b;
    16831614            if (!GUI<bool>::ParseString(attr_value, b))
    16841615                LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
    1685             else Image->m_Border = b;
     1616            else
     1617                Image->m_Border = b;
    16861618        }
    16871619        else
    16881620        {
     
    17191651    parent.AddImage(Image);
    17201652}
    17211653
    1722 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)
     1654void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects)
    17231655{
    17241656    for (XMBAttribute attr : Element.GetAttributes())
    17251657    {
     
    18011733
    18021734        if (attr_name == "name")
    18031735            name = attr_value;
    1804         else
    1805         if (attr_name == "show_edge_buttons")
     1736        else if (attr_name == "show_edge_buttons")
    18061737        {
    18071738            bool b;
    18081739            if (!GUI<bool>::ParseString(attr_value.FromUTF8(), b))
     
    18101741            else
    18111742                scrollbar.m_UseEdgeButtons = b;
    18121743        }
    1813         if (attr_name == "width")
     1744        else if (attr_name == "width")
    18141745        {
    18151746            float f;
    18161747            if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
     
    18181749            else
    18191750                scrollbar.m_Width = f;
    18201751        }
    1821         else
    1822         if (attr_name == "minimum_bar_size")
     1752        else if (attr_name == "minimum_bar_size")
    18231753        {
    18241754            float f;
    18251755            if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
     
    18271757            else
    18281758                scrollbar.m_MinimumBarSize = f;
    18291759        }
    1830         else
    1831         if (attr_name == "maximum_bar_size")
     1760        else if (attr_name == "maximum_bar_size")
    18321761        {
    18331762            float f;
    18341763            if (!GUI<float>::ParseString(attr_value.FromUTF8(), f))
     
    18361765            else
    18371766                scrollbar.m_MaximumBarSize = f;
    18381767        }
    1839         else
    1840         if (attr_name == "sprite_button_top")
     1768        else if (attr_name == "sprite_button_top")
    18411769            scrollbar.m_SpriteButtonTop = attr_value;
    1842         else
    1843         if (attr_name == "sprite_button_top_pressed")
     1770        else if (attr_name == "sprite_button_top_pressed")
    18441771            scrollbar.m_SpriteButtonTopPressed = attr_value;
    1845         else
    1846         if (attr_name == "sprite_button_top_disabled")
     1772        else if (attr_name == "sprite_button_top_disabled")
    18471773            scrollbar.m_SpriteButtonTopDisabled = attr_value;
    1848         else
    1849         if (attr_name == "sprite_button_top_over")
     1774        else if (attr_name == "sprite_button_top_over")
    18501775            scrollbar.m_SpriteButtonTopOver = attr_value;
    1851         else
    1852         if (attr_name == "sprite_button_bottom")
     1776        else if (attr_name == "sprite_button_bottom")
    18531777            scrollbar.m_SpriteButtonBottom = attr_value;
    1854         else
    1855         if (attr_name == "sprite_button_bottom_pressed")
     1778        else if (attr_name == "sprite_button_bottom_pressed")
    18561779            scrollbar.m_SpriteButtonBottomPressed = attr_value;
    1857         else
    1858         if (attr_name == "sprite_button_bottom_disabled")
     1780        else if (attr_name == "sprite_button_bottom_disabled")
    18591781            scrollbar.m_SpriteButtonBottomDisabled = attr_value;
    1860         else
    1861         if (attr_name == "sprite_button_bottom_over")
     1782        else if (attr_name == "sprite_button_bottom_over")
    18621783            scrollbar.m_SpriteButtonBottomOver = attr_value;
    1863         else
    1864         if (attr_name == "sprite_back_vertical")
     1784        else if (attr_name == "sprite_back_vertical")
    18651785            scrollbar.m_SpriteBackVertical = attr_value;
    1866         else
    1867         if (attr_name == "sprite_bar_vertical")
     1786        else if (attr_name == "sprite_bar_vertical")
    18681787            scrollbar.m_SpriteBarVertical = attr_value;
    1869         else
    1870         if (attr_name == "sprite_bar_vertical_over")
     1788        else if (attr_name == "sprite_bar_vertical_over")
    18711789            scrollbar.m_SpriteBarVerticalOver = attr_value;
    1872         else
    1873         if (attr_name == "sprite_bar_vertical_pressed")
     1790        else if (attr_name == "sprite_bar_vertical_pressed")
    18741791            scrollbar.m_SpriteBarVerticalPressed = attr_value;
    18751792    }
    18761793
     
    19511868
    19521869    XMBAttributeList attributes = Element.GetAttributes();
    19531870
    1954     //IGUIObject* object = new CTooltip;
    19551871    CColor color;
    19561872    CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name"));
    19571873
    19581874    // Try parsing value
    19591875    CStr value(Element.GetText());
    1960     if (!value.empty())
     1876    if (value.empty())
     1877        return;
     1878
     1879    // Try setting color to value
     1880    if (!color.ParseString(value))
    19611881    {
    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         }
     1882        LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
     1883        return;
    19721884    }
     1885
     1886    // input color
     1887    m_PreDefinedColors[name] = color;
    19731888}
  • 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;
     
    7271        if (GetStyle()->m_UseEdgeButtons)
    7372        {
    7473            // Get Appropriate sprites
    75             const CGUISpriteInstance *button_top, *button_bottom;
     74            const CGUISpriteInstance* button_top;
     75            const CGUISpriteInstance* button_bottom;
    7676
    7777            // figure out what sprite to use for top button
    7878            if (m_ButtonMinusHovered)
     
    8282                else
    8383                    button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop);
    8484            }
    85             else button_top = &GetStyle()->m_SpriteButtonTop;
     85            else
     86                button_top = &GetStyle()->m_SpriteButtonTop;
    8687
    8788            // figure out what sprite to use for bottom button
    8889            if (m_ButtonPlusHovered)
     
    9293                else
    9394                    button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom);
    9495            }
    95             else button_bottom = &GetStyle()->m_SpriteButtonBottom;
     96            else
     97                button_bottom = &GetStyle()->m_SpriteButtonBottom;
    9698           
    9799            // Draw top button
    98100            GetGUI()->DrawSprite(*button_top,
     
    123125    }
    124126}
    125127
    126 void CGUIScrollBarVertical::HandleMessage(SGUIMessage &Message)
     128void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message)
    127129{
    128130    IGUIScrollBar::HandleMessage(Message);
    129131}
     
    167169    return ret;
    168170}
    169171
    170 bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos &mouse)
     172bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos& mouse)
    171173{
    172174    if (!GetStyle())
    173175        return false;
     
    180182            mouse.y <= m_Y + GetStyle()->m_Width);
    181183}
    182184
    183 bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos &mouse)
     185bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos& mouse)
    184186{
    185187    if (!GetStyle())
    186188        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();
     
    112107    else if (ev->ev.type == SDL_TEXTINPUT)
    113108    {
    114109        // Text has been committed, either single key presses or through an IME
    115         CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     110        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    116111        std::wstring text = wstring_from_utf8(ev->ev.text.text);
    117112
    118         m_WantedX=0.0f;
     113        m_WantedX = 0.0f;
    119114
    120115        if (SelectingText())
    121116            DeleteCurSelection();
     
    145140    {
    146141        // Text is being composed with an IME
    147142        // TODO: indicate this by e.g. underlining the uncommitted text
    148         CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    149         const char *rawText = ev->ev.edit.text;
     143        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     144        const char* rawText = ev->ev.edit.text;
    150145        int rawLength = strlen(rawText);
    151146        std::wstring wtext = wstring_from_utf8(rawText);
    152147
    153148        debug_printf("SDL_TEXTEDITING: text=%s, start=%d, length=%d\n", rawText, ev->ev.edit.start, ev->ev.edit.length);
    154         m_WantedX=0.0f;
     149        m_WantedX = 0.0f;
    155150
    156151        if (SelectingText())
    157152            DeleteCurSelection();
     
    195190        // Since the GUI framework doesn't handle to set settings
    196191        //  in Unicode (CStrW), we'll simply retrieve the actual
    197192        //  pointer and edit that.
    198         CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     193        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    199194        bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
    200195
    201196#if !SDL_VERSION_ATLEAST(2, 0, 0)
     
    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 );
     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;
    239213
    240                         --m_iBufferPos;
     214        case SDLK_BACKSPACE: // '\b'
     215            m_WantedX = 0.0f;
    241216
    242                         UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    243                     }
    244                 }
     217            if (SelectingText())
     218                DeleteCurSelection();
     219            else
     220            {
     221                m_iBufferPos_Tail = -1;
    245222
    246                 UpdateAutoScroll();
    247                 break;
     223                if (pCaption->empty() || m_iBufferPos == 0)
     224                    break;
    248225
    249             case SDLK_DELETE:
    250                 m_WantedX=0.0f;
    251                 // If selection:
    252                 if (SelectingText())
    253                 {
    254                     DeleteCurSelection();
    255                 }
     226                if (m_iBufferPos == (int)pCaption->length())
     227                    *pCaption = pCaption->Left((long)pCaption->length()-1);
    256228                else
    257                 {
    258                     if (pCaption->empty() || m_iBufferPos == (int)pCaption->length())
    259                     {
    260                         break;
    261                     }
    262                     else
    263                     {
    264                         *pCaption = pCaption->Left( m_iBufferPos ) +
    265                                     pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) );
     229                    *pCaption = pCaption->Left(m_iBufferPos-1) +
     230                                pCaption->Right((long)pCaption->length()-m_iBufferPos);
    266231
    267                         UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    268                     }
    269                 }
     232                --m_iBufferPos;
    270233
    271                 UpdateAutoScroll();
    272                 break;
     234                UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
    273235
    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;
    285                 }
    286 
    287                 m_iBufferPos = 0;
    288                 m_WantedX=0.0f;
    289 
    290                 UpdateAutoScroll();
    291                 break;
     236            }
    292237
    293             case SDLK_END:
    294                 // If there's not a selection, we should create one now
    295                 if (!shiftKeyPressed)
    296                 {
    297                     // Make sure a selection isn't created.
    298                     m_iBufferPos_Tail = -1;
    299                 }
    300                 else if (!SelectingText())
    301                 {
    302                     // Place tail at the current point:
    303                     m_iBufferPos_Tail = m_iBufferPos;
    304                 }
     238            UpdateAutoScroll();
     239            break;
    305240
    306                 m_iBufferPos = (long) pCaption->length();
    307                 m_WantedX=0.0f;
     241        case SDLK_DELETE:
     242            m_WantedX = 0.0f;
     243            // If selection:
     244            if (SelectingText())
     245                DeleteCurSelection();
     246            else
     247            {
     248                if (pCaption->empty() || m_iBufferPos == (int)pCaption->length())
     249                    break;
    308250
    309                 UpdateAutoScroll();
    310                 break;
     251                *pCaption = pCaption->Left(m_iBufferPos) +
     252                            pCaption->Right((long)pCaption->length()-(m_iBufferPos+1));
    311253
    312             /**
    313                 Conventions for Left/Right when text is selected:
     254                UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos);
     255            }
    314256
    315                 References:
     257            UpdateAutoScroll();
     258            break;
    316259
    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.
     260        case SDLK_HOME:
     261            // If there's not a selection, we should create one now
     262            if (!shiftKeyPressed)
     263            {
     264                // Make sure a selection isn't created.
     265                m_iBufferPos_Tail = -1;
     266            }
     267            else if (!SelectingText())
     268            {
     269                // Place tail at the current point:
     270                m_iBufferPos_Tail = m_iBufferPos;
     271            }
    324272
    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.
     273            m_iBufferPos = 0;
     274            m_WantedX = 0.0f;
    329275
    330                 I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN
    331                 Messenger.
     276            UpdateAutoScroll();
     277            break;
    332278
    333             **/
    334             case SDLK_LEFT:
    335                 m_WantedX=0.f;
     279        case SDLK_END:
     280            // If there's not a selection, we should create one now
     281            if (!shiftKeyPressed)
     282            {
     283                // Make sure a selection isn't created.
     284                m_iBufferPos_Tail = -1;
     285            }
     286            else if (!SelectingText())
     287            {
     288                // Place tail at the current point:
     289                m_iBufferPos_Tail = m_iBufferPos;
     290            }
    336291
    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                     }
     292            m_iBufferPos = (long)pCaption->length();
     293            m_WantedX = 0.0f;
    347294
    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;
     295            UpdateAutoScroll();
     296            break;
    355297
     298        /**
     299         * Conventions for Left/Right when text is selected:
     300         *
     301         * References:
     302         *
     303         * Visual Studio
     304         *  Visual Studio has the 'newer' approach, used by newer versions of
     305         * things, and in newer applications. A left press will always place
     306         * the pointer on the left edge of the selection, and then of course
     307         * remove the selection. Right will do the exact same thing.
     308         * If you have the pointer on the right edge and press right, it will
     309         * in other words just remove the selection.
     310         *
     311         * Windows (eg. Notepad)
     312         *  A left press always takes the pointer a step to the left and
     313         * removes the selection as if it were never there in the first place.
     314         * Right of course does the same thing but to the right.
     315         *
     316         * I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN
     317         * Messenger.
     318         */
     319        case SDLK_LEFT:
     320            m_WantedX = 0.f;
     321
     322            if (shiftKeyPressed || !SelectingText())
     323            {
     324                if (!shiftKeyPressed)
    356325                    m_iBufferPos_Tail = -1;
    357                 }
     326                else if (!SelectingText())
     327                    m_iBufferPos_Tail = m_iBufferPos;
    358328
    359                 UpdateAutoScroll();
    360                 break;
     329                if (m_iBufferPos > 0)
     330                    --m_iBufferPos;
     331            }
     332            else
     333            {
     334                if (m_iBufferPos_Tail < m_iBufferPos)
     335                    m_iBufferPos = m_iBufferPos_Tail;
    361336
    362             case SDLK_RIGHT:
    363                 m_WantedX=0.0f;
     337                m_iBufferPos_Tail = -1;
     338            }
    364339
    365                 if (shiftKeyPressed || !SelectingText())
    366                 {
    367                     if (!shiftKeyPressed)
    368                     {
    369                         m_iBufferPos_Tail = -1;
    370                     }
    371                     else if (!SelectingText())
    372                     {
    373                         m_iBufferPos_Tail = m_iBufferPos;
    374                     }
     340            UpdateAutoScroll();
     341            break;
    375342
    376                     if (m_iBufferPos < (int)pCaption->length())
    377                         ++m_iBufferPos;
    378                 }
    379                 else
    380                 {
    381                     if (m_iBufferPos_Tail > m_iBufferPos)
    382                         m_iBufferPos = m_iBufferPos_Tail;
     343        case SDLK_RIGHT:
     344            m_WantedX = 0.0f;
    383345
     346            if (shiftKeyPressed || !SelectingText())
     347            {
     348                if (!shiftKeyPressed)
    384349                    m_iBufferPos_Tail = -1;
    385                 }
    386 
    387                 UpdateAutoScroll();
    388                 break;
    389 
    390             /**
    391                 Conventions for Up/Down when text is selected:
     350                else if (!SelectingText())
     351                    m_iBufferPos_Tail = m_iBufferPos;
    392352
    393                 References:
     353                if (m_iBufferPos < (int)pCaption->length())
     354                    ++m_iBufferPos;
     355            }
     356            else
     357            {
     358                if (m_iBufferPos_Tail > m_iBufferPos)
     359                    m_iBufferPos = m_iBufferPos_Tail;
    394360
    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
     361                m_iBufferPos_Tail = -1;
     362            }
    401363
    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.
     364            UpdateAutoScroll();
     365            break;
    405366
    406                 I chose the Notepad convention even though I use the VS convention with
    407                 left/right.
     367        /**
     368         * Conventions for Up/Down when text is selected:
     369         *
     370         * References:
     371         *
     372         * Visual Studio
     373         *  Visual Studio has a very strange approach, down takes you below the
     374         * selection to the next row, and up to the one prior to the whole
     375         * selection. The weird part is that it is always aligned as the
     376         * 'pointer'. I decided this is to much work for something that is
     377         * a bit arbitrary
     378         *
     379         * Windows (eg. Notepad)
     380         *  Just like with left/right, the selection is destroyed and it moves
     381         * just as if there never were a selection.
     382         *
     383         * I chose the Notepad convention even though I use the VS convention with
     384         * left/right.
     385         */
     386        case SDLK_UP:
     387        {
     388            if (!shiftKeyPressed)
     389                m_iBufferPos_Tail = -1;
     390            else if (!SelectingText())
     391                m_iBufferPos_Tail = m_iBufferPos;
    408392
    409             **/
    410             case SDLK_UP:
     393            std::list<SRow>::iterator current = m_CharacterPositions.begin();
     394            while (current != m_CharacterPositions.end())
    411395            {
    412                 if (!shiftKeyPressed)
    413                 {
    414                     m_iBufferPos_Tail = -1;
    415                 }
    416                 else if (!SelectingText())
    417                 {
    418                     m_iBufferPos_Tail = m_iBufferPos;
    419                 }
     396                if (m_iBufferPos >= current->m_ListStart &&
     397                    m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
     398                    break;
    420399
    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;
     400                ++current;
     401            }
    427402
    428                     ++current;
    429                 }
     403            float pos_x;
    430404
    431                 float pos_x;
     405            if (m_iBufferPos-current->m_ListStart == 0)
     406                pos_x = 0.f;
     407            else
     408                pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1];
    432409
    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];
     410            if (m_WantedX > pos_x)
     411                pos_x = m_WantedX;
    437412
    438                 if (m_WantedX > pos_x)
    439                     pos_x = m_WantedX;
     413            // Now change row:
     414            if (current != m_CharacterPositions.begin())
     415            {
     416                --current;
    440417
    441                 // Now change row:
    442                 if (current != m_CharacterPositions.begin())
    443                 {
    444                     --current;
     418                // Find X-position:
     419                m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
     420            }
     421            // else we can't move up
    445422
    446                     // Find X-position:
    447                     m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
    448                 }
    449                 // else we can't move up
     423            UpdateAutoScroll();
     424            break;
     425        }
    450426
    451                 UpdateAutoScroll();
    452             }
    453                 break;
     427        case SDLK_DOWN:
     428        {
     429            if (!shiftKeyPressed)
     430                m_iBufferPos_Tail = -1;
     431            else if (!SelectingText())
     432                m_iBufferPos_Tail = m_iBufferPos;
    454433
    455             case SDLK_DOWN:
     434            std::list<SRow>::iterator current = m_CharacterPositions.begin();
     435            while (current != m_CharacterPositions.end())
    456436            {
    457                 if (!shiftKeyPressed)
    458                 {
    459                     m_iBufferPos_Tail = -1;
    460                 }
    461                 else if (!SelectingText())
    462                 {
    463                     m_iBufferPos_Tail = m_iBufferPos;
    464                 }
     437                if (m_iBufferPos >= current->m_ListStart &&
     438                    m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size())
     439                    break;
    465440
    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;
     441                ++current;
     442            }
    472443
    473                     ++current;
    474                 }
     444            float pos_x;
    475445
    476                 float pos_x;
     446            if (m_iBufferPos-current->m_ListStart == 0)
     447                pos_x = 0.f;
     448            else
     449                pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1];
    477450
    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];
     451            if (m_WantedX > pos_x)
     452                pos_x = m_WantedX;
    482453
    483                 if (m_WantedX > pos_x)
    484                     pos_x = m_WantedX;
     454            // Now change row:
     455            // Add first, so we can check if it's .end()
     456            ++current;
     457            if (current != m_CharacterPositions.end())
     458            {
     459                // Find X-position:
     460                m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX);
     461            }
     462            // else we can't move up
    485463
    486                 // Now change row:
    487                 // Add first, so we can check if it's .end()
    488                 ++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
     464            UpdateAutoScroll();
     465            break;
     466        }
    495467
    496                 UpdateAutoScroll();
    497             }
    498                 break;
     468        case SDLK_PAGEUP:
     469            GetScrollBar(0).ScrollMinusPlenty();
     470            break;
    499471
    500             case SDLK_PAGEUP:
    501                 GetScrollBar(0).ScrollMinusPlenty();
    502                 break;
     472        case SDLK_PAGEDOWN:
     473            GetScrollBar(0).ScrollPlusPlenty();
     474            break;
     475        /* END: Message History Lookup */
    503476
    504             case SDLK_PAGEDOWN:
    505                 GetScrollBar(0).ScrollPlusPlenty();
     477        case SDLK_KP_ENTER:
     478        case SDLK_RETURN:
     479            // 'Return' should do a Press event for single liners (e.g. submitting forms)
     480            //  otherwise a '\n' character will be added.
     481        {
     482            bool multiline;
     483            GUI<bool>::GetSetting(this, "multiline", multiline);
     484            if (!multiline)
     485            {
     486                SendEvent(GUIM_PRESSED, "press");
    506487                break;
    507             /* END: Message History Lookup */
    508 
    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                 }
     488            }
    521489
    522                 cooked = '\n'; // Change to '\n' and do default:
    523                 // NOTE: Fall-through
    524                 }
    525             default: //Insert a character
    526                 {
     490            cooked = '\n'; // Change to '\n' and do default:
     491            // NOTE: Fall-through
     492        }
     493        default: //Insert a character
     494        {
    527495#if !SDL_VERSION_ATLEAST(2, 0, 0)
    528                 if (cooked == 0)
    529                     return IN_PASS; // Important, because we didn't use any key
     496            if (cooked == 0)
     497                return IN_PASS; // Important, because we didn't use any key
    530498#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;
     499            // In SDL2, we no longer get Unicode wchars via SDL_Keysym
     500            // we use text input events instead and they provide UTF-8 chars
     501            if (ev->ev.type == SDL_KEYDOWN && cooked == 0)
     502                return IN_HANDLED;
    535503#endif
    536504
    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;
     505            // check max length
     506            int max_length;
     507            GUI<int>::GetSetting(this, "max_length", max_length);
     508            if (max_length != 0 && (int)pCaption->length() >= max_length)
     509                break;
    542510
    543                 m_WantedX=0.0f;
     511            m_WantedX = 0.0f;
    544512
    545                 if (SelectingText())
    546                     DeleteCurSelection();
    547                 m_iBufferPos_Tail = -1;
     513            if (SelectingText())
     514                DeleteCurSelection();
     515            m_iBufferPos_Tail = -1;
    548516
    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);
     517            if (m_iBufferPos == (int)pCaption->length())
     518                *pCaption += cooked;
     519            else
     520                *pCaption = pCaption->Left(m_iBufferPos) + cooked +
     521                            pCaption->Right((long) pCaption->length()-m_iBufferPos);
    554522
    555                 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
     523            UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1);
    556524
    557                 ++m_iBufferPos;
     525            ++m_iBufferPos;
    558526
    559                 UpdateAutoScroll();
    560                 }
    561                 break;
     527            UpdateAutoScroll();
     528            break;
     529        }
    562530        }
    563531
    564532        UpdateBufferPositionSetting();
     
    571539
    572540InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
    573541{
    574     CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     542    CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    575543    bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT];
    576544
    577545    std::string hotkey = static_cast<const char*>(ev->ev.user.data1);
    578546    if (hotkey == "paste")
    579547    {
    580         m_WantedX=0.0f;
     548        m_WantedX = 0.0f;
    581549
    582550        wchar_t* text = sys_clipboard_get();
    583551        if (text)
    584552        {
    585553            if (SelectingText())
    586             {
    587554                DeleteCurSelection();
    588             }
    589555
    590556            if (m_iBufferPos == (int)pCaption->length())
    591557                *pCaption += text;
     
    605571    }
    606572    else if (hotkey == "copy" || hotkey == "cut")
    607573    {
    608         m_WantedX=0.0f;
     574        m_WantedX = 0.0f;
    609575
    610576        if (SelectingText())
    611577        {
     
    637603    }
    638604    else if (hotkey == "text.delete.left")
    639605    {
    640         m_WantedX=0.0f;
     606        m_WantedX = 0.0f;
    641607
    642608        if (SelectingText())
    643609        {
     
    646612        if (!pCaption->empty() && m_iBufferPos != 0)
    647613        {
    648614            m_iBufferPos_Tail = m_iBufferPos;
    649             CStrW searchString = pCaption->Left( m_iBufferPos );
     615            CStrW searchString = pCaption->Left(m_iBufferPos);
    650616
    651617            // If we are starting in whitespace, adjust position until we get a non whitespace
    652618            while (m_iBufferPos > 0)
     
    679645    }
    680646    else if (hotkey == "text.delete.right")
    681647    {
    682         m_WantedX=0.0f;
     648        m_WantedX = 0.0f;
    683649
    684650        if (SelectingText())
    685651        {
     
    703669                if (!iswspace((*pCaption)[m_iBufferPos]))
    704670                    break;
    705671
    706                 m_iBufferPos++;
     672                ++m_iBufferPos;
    707673            }
    708674            UpdateBufferPositionSetting();
    709675            DeleteCurSelection();
     
    712678    }
    713679    else if (hotkey == "text.move.left")
    714680    {
    715         m_WantedX=0.0f;
     681        m_WantedX = 0.0f;
    716682
    717683        if (shiftKeyPressed || !SelectingText())
    718684        {
     
    727693
    728694            if (!pCaption->empty() && m_iBufferPos != 0)
    729695            {
    730                 CStrW searchString = pCaption->Left( m_iBufferPos );
     696                CStrW searchString = pCaption->Left(m_iBufferPos);
    731697
    732698                // If we are starting in whitespace, adjust position until we get a non whitespace
    733699                while (m_iBufferPos > 0)
     
    769735    }
    770736    else if (hotkey == "text.move.right")
    771737    {
    772         m_WantedX=0.0f;
     738        m_WantedX = 0.0f;
    773739
    774740        if (shiftKeyPressed || !SelectingText())
    775741        {
     
    799765                    if (!iswspace((*pCaption)[m_iBufferPos]))
    800766                        break;
    801767
    802                     m_iBufferPos++;
     768                    ++m_iBufferPos;
    803769                }
    804770            }
    805771        }
     
    823789}
    824790
    825791
    826 void CInput::HandleMessage(SGUIMessage &Message)
     792void CInput::HandleMessage(SGUIMessage& Message)
    827793{
    828     // TODO Gee:
    829794    IGUIScrollBarOwner::HandleMessage(Message);
    830795
    831796    switch (Message.type)
    832797    {
    833798    case GUIM_SETTINGS_UPDATED:
    834         {
     799    {
    835800        bool scrollbar;
    836801        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    837802
     
    886851
    887852            UpdateText();
    888853        }
    889 
    890         }break;
     854        break;
     855    }
    891856
    892857    case GUIM_MOUSE_PRESS_LEFT:
    893         // Check if we're selecting the scrollbar:
    894         {
     858    {
    895859        bool scrollbar, multiline;
    896860        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    897861        GUI<bool>::GetSetting(this, "multiline", multiline);
    898862
     863        // Check if we're selecting the scrollbar
    899864        if (GetScrollBar(0).GetStyle() && multiline)
    900865        {
    901866            if (GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width)
     
    921886
    922887        // If we immediately release the button it will just be seen as a click
    923888        //  for the user though.
    924 
    925         }break;
     889        break;
     890    }
    926891
    927892    case GUIM_MOUSE_DBLCLICK_LEFT:
    928         {
    929             if (m_ComposingText)
    930                 break;
     893    {
     894        if (m_ComposingText)
     895            break;
    931896
    932             CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     897        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    933898
    934             if (pCaption->length() == 0)
    935                 break;
     899        if (pCaption->empty())
     900            break;
    936901
    937             m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition();
     902        m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition();
    938903
    939             if (m_iBufferPos >= (int)pCaption->length())
    940                 m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1;
     904        if (m_iBufferPos >= (int)pCaption->length())
     905            m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1;
    941906
    942             // See if we are clicking over whitespace
    943             if (iswspace((*pCaption)[m_iBufferPos]))
     907        // See if we are clicking over whitespace
     908        if (iswspace((*pCaption)[m_iBufferPos]))
     909        {
     910            // see if we are in a section of whitespace greater than one character
     911            if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) ||
     912                (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1])))
    944913            {
    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])))
     914                //
     915                // We are clicking in an area with more than one whitespace character
     916                // so we select both the word to the left and then the word to the right
     917                //
     918                // [1] First the left
     919                // skip the whitespace
     920                while (m_iBufferPos > 0)
    948921                {
    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--;
     922                    if (!iswspace((*pCaption)[m_iBufferPos - 1]))
     923                        break;
    969924
    970                         if (iswpunct((*pCaption)[m_iBufferPos]))
    971                             break;
    972                     }
     925                    m_iBufferPos--;
     926                }
     927                // now go until we hit white space or punctuation
     928                while (m_iBufferPos > 0)
     929                {
     930                    if (iswspace((*pCaption)[m_iBufferPos - 1]))
     931                        break;
    973932
    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                     }
     933                    m_iBufferPos--;
    981934
    982                     if (m_iBufferPos_Tail == (int)pCaption->length())
     935                    if (iswpunct((*pCaption)[m_iBufferPos]))
    983936                        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                     }
    991937                }
    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                     }
    1000938
    1001                     if (m_iBufferPos_Tail == (int)pCaption->length())
     939                // [2] Then the right
     940                // go right until we are not in whitespace
     941                while (++m_iBufferPos_Tail < (int)pCaption->length())
     942                {
     943                    if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
    1002944                        break;
     945                }
    1003946
    1004                     // Don't include the leading whitespace
    1005                     m_iBufferPos = m_iBufferPos_Tail;
     947                if (m_iBufferPos_Tail == (int)pCaption->length())
     948                    break;
    1006949
    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                     }
     950                // now go to the right until we hit whitespace or punctuation
     951                while (++m_iBufferPos_Tail < (int)pCaption->length())
     952                {
     953                    if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     954                        break;
    1013955                }
    1014956            }
    1015957            else
    1016958            {
    1017                 // clicked on non-whitespace so select current word
    1018                 // go until we hit white space or punctuation
    1019                 while (m_iBufferPos > 0)
     959                // single whitespace so select word to the right
     960                while (++m_iBufferPos_Tail < (int)pCaption->length())
    1020961                {
    1021                     if (iswspace((*pCaption)[m_iBufferPos - 1]))
     962                    if (!iswspace((*pCaption)[m_iBufferPos_Tail]))
    1022963                        break;
     964                }
    1023965
    1024                     m_iBufferPos--;
     966                if (m_iBufferPos_Tail == (int)pCaption->length())
     967                    break;
    1025968
    1026                     if (iswpunct((*pCaption)[m_iBufferPos]))
    1027                         break;
    1028                 }
    1029                 // go to the right until we hit whitespace or punctuation
     969                // Don't include the leading whitespace
     970                m_iBufferPos = m_iBufferPos_Tail;
     971
     972                // now go to the right until we hit whitespace or punctuation
    1030973                while (++m_iBufferPos_Tail < (int)pCaption->length())
    1031974                {
    1032975                    if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     
    1034977                }
    1035978            }
    1036979        }
     980        else
     981        {
     982            // clicked on non-whitespace so select current word
     983            // go until we hit white space or punctuation
     984            while (m_iBufferPos > 0)
     985            {
     986                if (iswspace((*pCaption)[m_iBufferPos - 1]))
     987                    break;
     988
     989                m_iBufferPos--;
     990
     991                if (iswpunct((*pCaption)[m_iBufferPos]))
     992                    break;
     993            }
     994            // go to the right until we hit whitespace or punctuation
     995            while (++m_iBufferPos_Tail < (int)pCaption->length())
     996            {
     997                if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))
     998                    break;
     999            }
     1000        }
    10371001        break;
     1002    }
    10381003
    10391004    case GUIM_MOUSE_RELEASE_LEFT:
    10401005        if (m_SelectingText)
    1041         {
    10421006            m_SelectingText = false;
    1043         }
    10441007        break;
    10451008
    10461009    case GUIM_MOUSE_MOTION:
     
    10591022        break;
    10601023
    10611024    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 );
     1025    {
     1026        GetScrollBar(0).SetX(m_CachedActualSize.right);
     1027        GetScrollBar(0).SetY(m_CachedActualSize.top);
     1028        GetScrollBar(0).SetZ(GetBufferedZ());
     1029        GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
    10671030
    10681031        CStr scrollbar_style;
    10691032        GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
    1070         GetScrollBar(0).SetScrollBarStyle( scrollbar_style );
     1033        GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
    10711034
    10721035        UpdateText();
    1073         }
    10741036        break;
     1037    }
    10751038
    10761039    case GUIM_GOT_FOCUS:
    10771040        m_iBufferPos = 0;
     
    11641127    GUI<bool>::GetSetting(this, "mask", mask);
    11651128
    11661129    if (scrollbar && multiline)
    1167     {
    1168         // Draw scrollbar
    11691130        IGUIScrollBarOwner::Draw();
     1131
     1132    if (!GetGUI())
     1133        return;
     1134
     1135    CStrW font_name_w;
     1136    CColor color, color_selected;
     1137    GUI<CStrW>::GetSetting(this, "font", font_name_w);
     1138    GUI<CColor>::GetSetting(this, "textcolor", color);
     1139    GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected);
     1140    CStrIntern font_name(font_name_w.ToUTF8());
     1141
     1142    // Get pointer of caption, it might be very large, and we don't
     1143    //  want to copy it continuously.
     1144    CStrW* pCaption = NULL;
     1145    wchar_t mask_char = L'*';
     1146    if (mask)
     1147    {
     1148        CStrW maskStr;
     1149        GUI<CStrW>::GetSetting(this, "mask_char", maskStr);
     1150        if (maskStr.length() > 0)
     1151            mask_char = maskStr[0];
    11701152    }
     1153    else
     1154        pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     1155
     1156    CGUISpriteInstance* sprite = NULL;
     1157    CGUISpriteInstance* sprite_selectarea = NULL;
     1158    int cell_id;
     1159
     1160    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
     1161    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea);
    11711162
    1172     if (GetGUI())
     1163    GUI<int>::GetSetting(this, "cell_id", cell_id);
     1164
     1165    GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
     1166
     1167    float scroll = 0.f;
     1168    if (scrollbar && multiline)
     1169        scroll = GetScrollBar(0).GetPos();
     1170
     1171    CFontMetrics font(font_name);
     1172
     1173    // We'll have to setup clipping manually, since we're doing the rendering manually.
     1174    CRect cliparea(m_CachedActualSize);
     1175
     1176    // First we'll figure out the clipping area, which is the cached actual size
     1177    //  substracted by an optional scrollbar
     1178    if (scrollbar)
    11731179    {
    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());
     1180        scroll = GetScrollBar(0).GetPos();
    11811181
    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;
     1182        // substract scrollbar from cliparea
     1183        if (cliparea.right > GetScrollBar(0).GetOuterRect().left &&
     1184            cliparea.right <= GetScrollBar(0).GetOuterRect().right)
     1185            cliparea.right = GetScrollBar(0).GetOuterRect().left;
    11951186
    1196         CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL;
    1197         int cell_id;
     1187        if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
     1188            cliparea.left < GetScrollBar(0).GetOuterRect().right)
     1189            cliparea.left = GetScrollBar(0).GetOuterRect().right;
     1190    }
    11981191
    1199         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
    1200         GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea);
     1192    if (cliparea != CRect())
     1193    {
     1194        glEnable(GL_SCISSOR_TEST);
     1195        glScissor(
     1196            cliparea.left / g_GuiScale,
     1197            g_yres - cliparea.bottom / g_GuiScale,
     1198            cliparea.GetWidth() / g_GuiScale,
     1199            cliparea.GetHeight() / g_GuiScale);
     1200    }
    12011201
    1202         GUI<int>::GetSetting(this, "cell_id", cell_id);
     1202    // These are useful later.
     1203    int VirtualFrom, VirtualTo;
    12031204
    1204         GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
     1205    if (m_iBufferPos_Tail >= m_iBufferPos)
     1206    {
     1207        VirtualFrom = m_iBufferPos;
     1208        VirtualTo = m_iBufferPos_Tail;
     1209    }
     1210    else
     1211    {
     1212        VirtualFrom = m_iBufferPos_Tail;
     1213        VirtualTo = m_iBufferPos;
     1214    }
    12051215
    1206         float scroll=0.f;
    1207         if (scrollbar && multiline)
    1208         {
    1209             scroll = GetScrollBar(0).GetPos();
    1210         }
     1216    // Get the height of this font.
     1217    float h = (float)font.GetHeight();
     1218    float ls = (float)font.GetLineSpacing();
    12111219
    1212         CFontMetrics font(font_name);
     1220    CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text);
    12131221
    1214         // We'll have to setup clipping manually, since we're doing the rendering manually.
    1215         CRect cliparea(m_CachedActualSize);
     1222    CTextRenderer textRenderer(tech->GetShader());
     1223    textRenderer.Font(font_name);
    12161224
    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();
     1225    // Set the Z to somewhat more, so we can draw a selected area between the
     1226    //  the control and the text.
     1227    textRenderer.Translate(
     1228        (float)(int)(m_CachedActualSize.left) + buffer_zone,
     1229        (float)(int)(m_CachedActualSize.top+h) + buffer_zone,
     1230        bz+0.1f);
    12221231
    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;
     1232    // U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE
     1233    // (sort of like a | which is aligned to the left of most characters)
    12271234
    1228             if (cliparea.left >= GetScrollBar(0).GetOuterRect().left &&
    1229                 cliparea.left < GetScrollBar(0).GetOuterRect().right)
    1230                 cliparea.left = GetScrollBar(0).GetOuterRect().right;
    1231         }
     1235    float buffered_y = -scroll+buffer_zone;
    12321236
    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         }
     1237    // When selecting larger areas, we need to draw a rectangle box
     1238    //  around it, and this is to keep track of where the box
     1239    //  started, because we need to follow the iteration until we
     1240    //  reach the end, before we can actually draw it.
     1241    bool drawing_box = false;
     1242    float box_x = 0.f;
     1243
     1244    float x_pointer = 0.f;
     1245
     1246    // If we have a selecting box (i.e. when you have selected letters, not just when
     1247    //  the pointer is between two letters) we need to process all letters once
     1248    //  before we do it the second time and render all the text. We can't do it
     1249    //  in the same loop because text will have been drawn, so it will disappear when
     1250    //  drawn behind the text that has already been drawn. Confusing, well it's necessary
     1251    //  (I think).
     1252
     1253    if (SelectingText())
     1254    {
     1255        // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos,
     1256        //  just like you can select from right to left, as you can
     1257        //  left to right. Is there a difference? Yes, the pointer
     1258        //  be placed accordingly, so that if you select shift and
     1259        //  expand this selection, it will expand on appropriate side.
     1260        // Anyway, since the drawing procedure needs "To" to be
     1261        //  greater than from, we need virtual values that might switch
     1262        //  place.
    12421263
    1243         // These are useful later.
    12441264        int VirtualFrom, VirtualTo;
    12451265
    12461266        if (m_iBufferPos_Tail >= m_iBufferPos)
     
    12541274            VirtualTo = m_iBufferPos;
    12551275        }
    12561276
    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)
    12751277
    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;
    1286 
    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())
     1278        bool done = false;
     1279        for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
     1280             it != m_CharacterPositions.end();
     1281             ++it, buffered_y += ls, x_pointer = 0.f)
    12951282        {
    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)
    1308             {
    1309                 VirtualFrom = m_iBufferPos;
    1310                 VirtualTo = m_iBufferPos_Tail;
    1311             }
    1312             else
    1313             {
    1314                 VirtualFrom = m_iBufferPos_Tail;
    1315                 VirtualTo = m_iBufferPos;
    1316             }
    1317 
     1283            if (multiline
     1284                && buffered_y > m_CachedActualSize.GetHeight())
     1285                break;
    13181286
    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)
     1287            // We might as well use 'i' here to iterate, because we need it
     1288            // (often compared against ints, so don't make it size_t)
     1289            for (int i = 0; i < (int)it->m_ListOfX.size()+2; ++i)
    13231290            {
    1324                 if (multiline)
     1291                if (it->m_ListStart + i == VirtualFrom)
    13251292                {
    1326                     if (buffered_y > m_CachedActualSize.GetHeight())
    1327                         break;
     1293                    // we won't actually draw it now, because we don't
     1294                    //  know the width of each glyph to that position.
     1295                    //  we need to go along with the iteration, and
     1296                    //  make a mark where the box started:
     1297                    drawing_box = true; // will turn false when finally rendered.
     1298
     1299                    // Get current x position
     1300                    box_x = x_pointer;
    13281301                }
    13291302
    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!
     1303                // no else!
    13471304
    1348                     const bool at_end = (i == (int)it->m_ListOfX.size()+1);
     1305                const bool at_end = (i == (int)it->m_ListOfX.size()+1);
    13491306
    1350                     if (drawing_box == true &&
    1351                         (it->m_ListStart + i == VirtualTo || at_end))
     1307                if (drawing_box == true &&
     1308                    (it->m_ListStart + i == VirtualTo || at_end))
     1309                {
     1310                    // Depending on if it's just a row change, or if it's
     1311                    //  the end of the select box, do slightly different things.
     1312                    if (at_end)
    13521313                    {
    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)
     1314                        if (it->m_ListStart + i != VirtualFrom)
    13561315                        {
    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                             }
     1316                            // and actually add a white space! yes, this is done in any common input
     1317                            x_pointer += (float)font.GetCharacterWidth(L' ');
    13621318                        }
    1363                         else
    1364                         {
    1365                             drawing_box = false;
    1366                             done = true;
    1367                         }
    1368 
    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);
     1319                    }
     1320                    else
     1321                    {
     1322                        drawing_box = false;
     1323                        done = true;
     1324                    }
    13771325
    1378                             if (rect.bottom < m_CachedActualSize.top)
    1379                                 continue;
     1326                    CRect rect;
     1327                    // Set 'rect' depending on if it's a multiline control, or a one-line control
     1328                    if (multiline)
     1329                    {
     1330                        rect = CRect(m_CachedActualSize.left+box_x+buffer_zone,
     1331                                   m_CachedActualSize.top+buffered_y+(h-ls)/2,
     1332                                   m_CachedActualSize.left+x_pointer+buffer_zone,
     1333                                   m_CachedActualSize.top+buffered_y+(h+ls)/2);
    13801334
    1381                             if (rect.top < m_CachedActualSize.top)
    1382                                 rect.top = m_CachedActualSize.top;
     1335                        if (rect.bottom < m_CachedActualSize.top)
     1336                            continue;
    13831337
    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);
     1338                        if (rect.top < m_CachedActualSize.top)
     1339                            rect.top = m_CachedActualSize.top;
    13931340
    1394                             if (rect.left < m_CachedActualSize.left)
    1395                                 rect.left = m_CachedActualSize.left;
     1341                        if (rect.bottom > m_CachedActualSize.bottom)
     1342                            rect.bottom = m_CachedActualSize.bottom;
     1343                    }
     1344                    else // if one-line
     1345                    {
     1346                        rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll,
     1347                                   m_CachedActualSize.top+buffered_y+(h-ls)/2,
     1348                                   m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll,
     1349                                   m_CachedActualSize.top+buffered_y+(h+ls)/2);
    13961350
    1397                             if (rect.right > m_CachedActualSize.right)
    1398                                 rect.right = m_CachedActualSize.right;
    1399                         }
     1351                        if (rect.left < m_CachedActualSize.left)
     1352                            rect.left = m_CachedActualSize.left;
    14001353
    1401                         if (sprite_selectarea)
    1402                             GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect);
     1354                        if (rect.right > m_CachedActualSize.right)
     1355                            rect.right = m_CachedActualSize.right;
    14031356                    }
    14041357
    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                     }
     1358                    if (sprite_selectarea)
     1359                        GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect);
    14121360                }
    14131361
    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)
     1362                if (i < (int)it->m_ListOfX.size())
    14211363                {
    1422                     box_x = 0.f;
     1364                    if (!mask)
     1365                        x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]);
     1366                    else
     1367                        x_pointer += (float)font.GetCharacterWidth(mask_char);
    14231368                }
    14241369            }
     1370
     1371            if (done)
     1372                break;
     1373
     1374            // If we're about to draw a box, and all of a sudden changes
     1375            //  line, we need to draw that line's box, and then reset
     1376            //  the box drawing to the beginning of the new line.
     1377            if (drawing_box)
     1378                box_x = 0.f;
    14251379        }
     1380    }
    14261381
    1427         // Reset some from previous run
    1428         buffered_y = -scroll;
     1382    // Reset some from previous run
     1383    buffered_y = -scroll;
    14291384
    1430         // Setup initial color (then it might change and change back, when drawing selected area)
    1431         textRenderer.Color(color);
     1385    // Setup initial color (then it might change and change back, when drawing selected area)
     1386    textRenderer.Color(color);
    14321387
    1433         tech->BeginPass();
     1388    tech->BeginPass();
    14341389
    1435         bool using_selected_color = false;
     1390    bool using_selected_color = false;
    14361391
    1437         for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
    1438              it != m_CharacterPositions.end();
    1439              ++it, buffered_y += ls)
     1392    for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin();
     1393         it != m_CharacterPositions.end();
     1394         ++it, buffered_y += ls)
     1395    {
     1396        if (buffered_y + buffer_zone >= -ls || !multiline)
    14401397        {
    1441             if (buffered_y + buffer_zone >= -ls || !multiline)
    1442             {
    1443                 if (multiline)
    1444                 {
    1445                     if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight())
    1446                         break;
    1447                 }
     1398            if (multiline
     1399                && buffered_y + buffer_zone > m_CachedActualSize.GetHeight())
     1400                break;
    14481401
    1449                 CMatrix3D savedTransform = textRenderer.GetTransform();
     1402            CMatrix3D savedTransform = textRenderer.GetTransform();
    14501403
    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);
     1404            // Text must always be drawn in integer values. So we have to convert scroll
     1405            if (multiline)
     1406                textRenderer.Translate(0.f, -(float)(int)scroll, 0.f);
     1407            else
     1408                textRenderer.Translate(-(float)(int)m_HorizontalScroll, 0.f, 0.f);
    14561409
    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)
     1410            // We might as well use 'i' here, because we need it
     1411            // (often compared against ints, so don't make it size_t)
     1412            for (int i = 0; i < (int)it->m_ListOfX.size()+1; ++i)
     1413            {
     1414                if (!multiline && i < (int)it->m_ListOfX.size())
    14601415                {
    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())
     1416                    if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone)
    15021417                    {
    1503                         if (!mask)
    1504                             textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]);
     1418                        // We still need to translate the OpenGL matrix
     1419                        if (i == 0)
     1420                            textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f);
    15051421                        else
    1506                             textRenderer.PrintfAdvance(L"%lc", mask_char);
    1507                     }
     1422                            textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f);
    15081423
    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;
     1424                        continue;
    15141425                    }
    15151426                }
    15161427
    1517                 if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos)
     1428                // End of selected area, change back color
     1429                if (SelectingText() &&
     1430                    it->m_ListStart + i == VirtualTo)
    15181431                {
     1432                    using_selected_color = false;
    15191433                    textRenderer.Color(color);
    1520                     if (m_CursorVisState)
    1521                         textRenderer.PutAdvance(L"_");
     1434                }
    15221435
    1523                     if (using_selected_color)
    1524                     {
    1525                         textRenderer.Color(color_selected);
    1526                     }
     1436                // selecting only one, then we need only to draw a cursor.
     1437                if (i != (int)it->m_ListOfX.size()
     1438                    && it->m_ListStart + i == m_iBufferPos
     1439                    && m_CursorVisState)
     1440                    textRenderer.Put(0.0f, 0.0f, L"_");
     1441
     1442                // Drawing selected area
     1443                if (SelectingText() &&
     1444                    it->m_ListStart + i >= VirtualFrom &&
     1445                    it->m_ListStart + i < VirtualTo &&
     1446                    using_selected_color == false)
     1447                {
     1448                    using_selected_color = true;
     1449                    textRenderer.Color(color_selected);
     1450                }
     1451
     1452                if (i != (int)it->m_ListOfX.size())
     1453                {
     1454                    if (!mask)
     1455                        textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]);
     1456                    else
     1457                        textRenderer.PrintfAdvance(L"%lc", mask_char);
    15271458                }
    15281459
    1529                 textRenderer.SetTransform(savedTransform);
     1460                // check it's now outside a one-liner, then we'll break
     1461                if (!multiline && i < (int)it->m_ListOfX.size()
     1462                    && it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone)
     1463                    break;
    15301464            }
    15311465
    1532             textRenderer.Translate(0.f, ls, 0.f);
    1533         }
     1466            if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos)
     1467            {
     1468                textRenderer.Color(color);
     1469                if (m_CursorVisState)
     1470                    textRenderer.PutAdvance(L"_");
    15341471
    1535         textRenderer.Render();
     1472                if (using_selected_color)
     1473                    textRenderer.Color(color_selected);
     1474            }
    15361475
    1537         if (cliparea != CRect())
    1538             glDisable(GL_SCISSOR_TEST);
     1476            textRenderer.SetTransform(savedTransform);
     1477        }
    15391478
    1540         tech->EndPass();
     1479        textRenderer.Translate(0.f, ls, 0.f);
    15411480    }
     1481
     1482    textRenderer.Render();
     1483
     1484    if (cliparea != CRect())
     1485        glDisable(GL_SCISSOR_TEST);
     1486
     1487    tech->EndPass();
    15421488}
    15431489
    15441490void CInput::UpdateText(int from, int to_before, int to_after)
     
    16031549    {
    16041550        ENSURE(to_before != -1);
    16051551
    1606         std::list<SRow>::iterator destroy_row_from, destroy_row_to;
     1552        std::list<SRow>::iterator destroy_row_from;
     1553        std::list<SRow>::iterator destroy_row_to;
    16071554        // Used to check if the above has been set to anything,
    16081555        //  previously a comparison like:
    16091556        //  destroy_row_from == std::list<SRow>::iterator()
    16101557        // ... was used, but it didn't work with GCC.
    1611         bool destroy_row_from_used=false, destroy_row_to_used=false;
     1558        bool destroy_row_from_used = false;
     1559        bool destroy_row_to_used = false;
    16121560
    16131561        // Iterate, and remove everything between 'from' and 'to_before'
    16141562        //  actually remove the entire lines they are on, it'll all have
    16151563        //  to be redone. And when going along, we'll delete a row at a time
    16161564        //  when continuing to see how much more after 'to' we need to remake.
    1617         int i=0;
     1565        int i = 0;
    16181566        for (std::list<SRow>::iterator it = m_CharacterPositions.begin();
    1619              it != m_CharacterPositions.end(); ++it, ++i)
     1567             it != m_CharacterPositions.end();
     1568             ++it, ++i)
    16201569        {
    16211570            if (destroy_row_from_used == false &&
    16221571                it->m_ListStart > from)
     
    17051654        if (delta != 0)
    17061655        {
    17071656            for (std::list<SRow>::iterator it = current_line;
    1708                  it != m_CharacterPositions.end();
    1709                  ++it)
    1710             {
     1657                 it != m_CharacterPositions.end();
     1658                 ++it)
    17111659                it->m_ListStart += delta;
    1712             }
    17131660
    17141661            // Update our check point too!
    17151662            check_point_row_start += delta;
     
    17201667        }
    17211668    }
    17221669
    1723     int last_word_started=from;
    1724     //int last_list_start=-1;   // unused
     1670    int last_word_started = from;
    17251671    float x_pos = 0.f;
    17261672
    17271673    //if (to_before != -1)
    17281674    //  return;
    17291675
    1730     for (int i=from; i<to; ++i)
     1676    for (int i = from; i < to; ++i)
    17311677    {
    17321678        if (caption[i] == L'\n' && multiline)
    17331679        {
    1734             if (i==to-1 && to != (int)caption.length())
     1680            if (i == to-1 && to != (int)caption.length())
    17351681                break; // it will be added outside
    17361682
    1737             current_line = m_CharacterPositions.insert( current_line, row );
     1683            current_line = m_CharacterPositions.insert(current_line, row);
    17381684            ++current_line;
    17391685
    17401686
     
    17641710                {
    17651711                    last_word_started = i;
    17661712                    row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started));
    1767                     //row.m_ListOfX.push_back( x_pos );
     1713                    //row.m_ListOfX.push_back(x_pos);
    17681714                    //continue;
    17691715                }
    17701716                else
     
    17791725                //  rows. With automatic word-wrapping, that is not possible. Which
    17801726                //  is intuitively correct.
    17811727
    1782                 current_line = m_CharacterPositions.insert( current_line, row );
     1728                current_line = m_CharacterPositions.insert(current_line, row);
    17831729                ++current_line;
    17841730
    17851731                // Setup the next row:
    17861732                row.m_ListOfX.clear();
    17871733                row.m_ListStart = last_word_started;
    17881734
    1789                 i=last_word_started-1;
     1735                i = last_word_started-1;
    17901736
    17911737                x_pos = 0.f;
    17921738            }
    17931739            else
    17941740                // Get width of this character:
    1795                 row.m_ListOfX.push_back( x_pos );
     1741                row.m_ListOfX.push_back(x_pos);
    17961742        }
    17971743
    17981744        // Check if it's the last iteration, and we're not revising the whole string
     
    18031749            // check all rows and see if any existing
    18041750            if (row.m_ListStart != check_point_row_start)
    18051751            {
    1806                 std::list<SRow>::iterator destroy_row_from, destroy_row_to;
     1752                std::list<SRow>::iterator destroy_row_from;
     1753                std::list<SRow>::iterator destroy_row_to;
    18071754                // Are used to check if the above has been set to anything,
    18081755                //  previously a comparison like:
    18091756                //  destroy_row_from == std::list<SRow>::iterator()
    18101757                //  was used, but it didn't work with GCC.
    1811                 bool destroy_row_from_used=false, destroy_row_to_used=false;
     1758                bool destroy_row_from_used = false;
     1759                bool destroy_row_to_used = false;
    18121760
    18131761                // Iterate, and remove everything between 'from' and 'to_before'
    18141762                //  actually remove the entire lines they are on, it'll all have
    18151763                //  to be redone. And when going along, we'll delete a row at a time
    18161764                //  when continuing to see how much more after 'to' we need to remake.
    1817                 int i=0;
    1818                 for (std::list<SRow>::iterator it=m_CharacterPositions.begin();
    1819                     it!=m_CharacterPositions.end(); ++it, ++i)
     1765                int i = 0;
     1766                for (std::list<SRow>::iterator it = m_CharacterPositions.begin();
     1767                     it != m_CharacterPositions.end();
     1768                     ++it, ++i)
    18201769                {
    18211770                    if (destroy_row_from_used == false &&
    18221771                        it->m_ListStart > check_point_row_start)
     
    18431792                        //  have to continue.
    18441793                        // 'check_point_row_start' is where we store how the that
    18451794                        //  line looked.
    1846             //          if (destroy_row_to !=
    18471795                        if (destroy_row_to != m_CharacterPositions.end())
    18481796                        {
    18491797                            check_point_row_start = destroy_row_to->m_ListStart;
     
    18841832                //  in the coming erase.
    18851833                current_line = destroy_row_to;
    18861834
    1887                 std::list<SRow>::iterator temp = destroy_row_to;
    1888 
    1889                 --temp;
    1890 
    18911835                m_CharacterPositions.erase(destroy_row_from, destroy_row_to);
    18921836            }
    18931837            // else, the for loop will end naturally.
     
    19001844    if (current_line != m_CharacterPositions.end())
    19011845    {
    19021846        if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart)
    1903             row.m_ListOfX.resize( row.m_ListOfX.size()-1 );
     1847            row.m_ListOfX.resize(row.m_ListOfX.size()-1);
    19041848    }
    19051849
    19061850    // add the final row (even if empty)
     
    19411885        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    19421886        CStrIntern font_name(font_name_w.ToUTF8());
    19431887
    1944         float scroll=0.f;
     1888        float scroll = 0.f;
    19451889        if (scrollbar)
    1946         {
    19471890            scroll = GetScrollBar(0).GetPos();
    1948         }
    19491891
    19501892        // Pointer to caption, will come in handy
    1951         CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     1893        CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    19521894        UNUSED2(pCaption);
    19531895
    19541896        // Now get the height of the font.
     
    19751917        // TODO Gee (2004-11-21): Okay, I need a 'std::list' for some reasons, but I would really like to
    19761918        //  be able to get the specific element here. This is hopefully a temporary hack.
    19771919
    1978         for (int i=0; i<row; ++i)
     1920        for (int i = 0; i < row; ++i)
    19791921            ++current;
    19801922    }
    19811923    else
     
    19981940}
    19991941
    20001942// 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)
     1943int CInput::GetXTextPosition(const std::list<SRow>::iterator& current, const float& x, float& wanted)
    20021944{
    2003     int ret=0;
    2004     float previous=0.f;
    2005     int i=0;
     1945    int ret = 0;
     1946    float previous = 0.f;
     1947    int i = 0;
    20061948
    2007     for (std::vector<float>::iterator it=current->m_ListOfX.begin();
    2008             it!=current->m_ListOfX.end();
    2009             ++it, ++i)
     1949    for (std::vector<float>::iterator it = current->m_ListOfX.begin();
     1950         it != current->m_ListOfX.end();
     1951         ++it, ++i)
    20101952    {
    20111953        if (*it >= x)
    20121954        {
     
    20261968        ret += i;
    20271969        wanted = x;
    20281970    }
    2029     else wanted = 0.f;
     1971    else
     1972        wanted = 0.f;
    20301973
    20311974    return ret;
    20321975}
    20331976
    20341977void CInput::DeleteCurSelection()
    20351978{
    2036     CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
     1979    CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting;
    20371980
    20381981    int virtualFrom;
    20391982    int virtualTo;
     
    20491992        virtualTo = m_iBufferPos;
    20501993    }
    20511994
    2052     *pCaption = pCaption->Left( virtualFrom ) +
    2053                 pCaption->Right( (long) pCaption->length() - (virtualTo) );
     1995    *pCaption = pCaption->Left(virtualFrom) +
     1996                pCaption->Right((long)pCaption->length() - virtualTo);
    20541997
    20551998    UpdateText(virtualFrom, virtualTo, virtualFrom);
    20561999
     
    20952038        GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
    20962039        CStrIntern font_name(font_name_w.ToUTF8());
    20972040
    2098         float scroll=0.f;
     2041        float scroll = 0.f;
    20992042        if (!scrollbar)
    21002043            return;
    21012044
     
    21112054        //  be able to get the specific element here. This is hopefully a temporary hack.
    21122055
    21132056        std::list<SRow>::iterator current = m_CharacterPositions.begin();
    2114         int row=0;
     2057        int row = 0;
    21152058        while (current != m_CharacterPositions.end())
    21162059        {
    21172060            if (m_iBufferPos >= current->m_ListStart &&
     
    21282071            // Scroll so the selected row is shown completely, also with buffer_zone length to the edge.
    21292072            GetScrollBar(0).SetPos((float)(row+1) * spacing - m_CachedActualSize.GetHeight() + buffer_zone*2.f);
    21302073        }
    2131         else
    21322074        // If scrolling up
    2133         if (-scroll + (float)row * spacing < 0.f)
     2075        else if (-scroll + (float)row * spacing < 0.f)
    21342076        {
    21352077            // Scroll so the selected row is shown completely, also with buffer_zone length to the edge.
    21362078            GetScrollBar(0).SetPos((float)row * spacing);
     
    21532095                x_position = m_CharacterPositions.begin()->m_ListOfX[m_iBufferPos-1];
    21542096
    21552097            // Get complete length:
    2156             x_total = m_CharacterPositions.begin()->m_ListOfX[ m_CharacterPositions.begin()->m_ListOfX.size()-1 ];
     2098            x_total = m_CharacterPositions.begin()->m_ListOfX[m_CharacterPositions.begin()->m_ListOfX.size()-1];
    21572099        }
    21582100
    21592101        // Check if outside to the right
  • 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.
     
    11890     * appears, because then the word-wrapping won't change after
    11991     * that.
    12092     */
    121     void UpdateText(int from=0, int to_before=-1, int to_after=-1);
     93    void UpdateText(int from = 0, int to_before = -1, int to_after = -1);
    12294
    12395    /**
    12496     * Delete the current selection. Also places the pointer at the
     
    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();
     
    11399    if (scrollbar && GetScrollBar(0).GetStyle())
    114100        width -= GetScrollBar(0).GetStyle()->m_Width;
    115101
    116     float buffer_zone=0.f;
     102    float buffer_zone = 0.f;
    117103    GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
    118104
    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);
    211         float scroll=0.f;
     190        float scroll = 0.f;
    212191        if (scrollbar)
    213         {
    214192            scroll = GetScrollBar(0).GetPos();
    215         }
    216193
    217194        CRect rect = GetListRect();
    218195        CPos mouse = GetMousePos();
    219196        mouse.y += scroll;
    220         int set=-1;
    221         for (int i=0; i<(int)pList->m_Items.size(); ++i)
     197        int set = -1;
     198        for (int i = 0; i < (int)pList->m_Items.size(); ++i)
    222199        {
    223200            if (mouse.y >= rect.top + m_ItemsYPositions[i] &&
    224201                mouse.y < rect.top + m_ItemsYPositions[i+1] &&
     
    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
    352         float scroll=0.f;
     324        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;
     
    7776    // Cache width for other use
    7877    m_TotalAvalibleColumnWidth = width;
    7978
    80     float buffer_zone=0.f;
     79    float buffer_zone = 0.f;
    8180    GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
    8281
    8382    CStr defaultColumn;
    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);
    112             if (c==0)
     111            if (c == 0)
    113112                buffered_y += text->m_Size.cy;
    114113            AddText(text);
    115114        }
     
    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;
     72    CGUISpriteInstance* sprite_bar;
     73    int cell_id = 0;
     74    float value = 0;
     75    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background);
     76    GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar);
     77    GUI<float>::GetSetting(this, "caption", value);
    8578
     79    GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize);
    8680
    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     }
     81    // Get size of bar (notice it is drawn slightly closer, to appear above the background)
     82    CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
     83                   m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
     84    GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size);
    9285}
  • 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
     
    9286        width -= GetScrollBar(0).GetStyle()->m_Width;
    9387
    9488
    95     float buffer_zone=0.f;
     89    float buffer_zone = 0.f;
    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"
     
    6664    if (!GetGUI())
    6765        return;
    6866
    69     ENSURE(m_GeneratedTexts.size()==1);
     67    ENSURE(m_GeneratedTexts.size() == 1);
    7068
    7169    CStrW font;
    7270    if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
     
    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;
     
    3435    {
    3536    public:
    3637        virtual ~IGLState() {};
    37         virtual void Set(const CTexturePtr& tex)=0;
    38         virtual void Unset()=0;
     38        virtual void Set(const CTexturePtr& tex) = 0;
     39        virtual void Unset() = 0;
    3940    };
    4041
    4142    struct SDrawCall
     
    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
     
    339340                //  "ride this tail", it have to wait.
    340341                // Notice that this doesn't apply to when you go from one delay=0
    341342                //  to another delay=0
    342                 if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI)==0 &&
    343                     GetTooltipDelay(style, GUI)!=0)
     343                if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI) == 0 &&
     344                    GetTooltipDelay(style, GUI) != 0)
    344345                {
    345346                    HideTooltip(m_PreviousTooltipName, GUI);
    346347                    nextstate = ST_IN_MOTION;
  • 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

     
    4444    m_TextCalls.clear();
    4545    m_SpriteCalls.clear();
    4646    m_Size = CSize();
    47     m_NewLine=false;
     47    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            /**
     
    248248    struct SFeedback
    249249    {
    250250        // Constants
    251         static const int Left=0;
    252         static const int Right=1;
     251        static const int Left = 0;
     252        static const int Right = 1;
    253253
    254254        /**
    255255         * Reset all member data.
     
    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
    373     if (GUIinstance.m_Styles.count(StyleName)==1)
     344    if (GUIinstance.m_Styles.count(StyleName) == 1)
    374345    {
    375346        LoadStyle(GUIinstance.m_Styles[StyleName]);
    376347    }
     
    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.
     
    439409    CStr CodeName = GetName()+" "+Action;
    440410
    441411    // Generate a unique name
    442     static int x=0;
     412    static int x = 0;
    443413    char buf[64];
    444414    sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str());
    445415
     
    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    //--------------------------------------------------------
     
    255238     *
    256239     * @return PSRETURN (PSRETURN_OK if successful)
    257240     */
    258     PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage=false);
     241    PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage = false);
    259242
    260243    /**
    261244     * Retrieves the type of a named setting.
     
    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.
     
    326309     *          it'll probably only output in the Error log, and not
    327310     *          disrupt the whole GUI drawing.
    328311     */
    329     virtual void Draw()=0;
     312    virtual void Draw() = 0;
    330313
    331314    /**
    332315     * Some objects need to handle the SDL_Event_ manually.
     
    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        m_ButtonMinusPressed = false;
     168        m_ButtonPlusPressed = false;
     169        break;
     170
     171    case GUIM_MOUSE_WHEEL_UP:
     172    {
     173        ScrollMinus();
     174        // Since the scroll was changed, let's simulate a mouse movement
     175        //  to check if scrollbar now is hovered
     176        SGUIMessage msg(GUIM_MOUSE_MOTION);
     177        HandleMessage(msg);
     178        break;
     179    }
     180
     181    case GUIM_MOUSE_WHEEL_DOWN:
     182    {
     183        ScrollPlus();
     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;
     189    }
     190
     191    default:
     192        break;
    203193    }
    204194}
  • 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 *
     
    169162    /**
    170163     * Draw the scroll-bar
    171164     */
    172     virtual void Draw()=0;
     165    virtual void Draw() = 0;
    173166
    174167    /**
    175168     * If an object that contains a scrollbar has got messages, send
     
    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
     
    10085    /**
    10186     * Setup texts. Functions that sets up all texts when changes have been made.
    10287     */
    103     virtual void SetupText()=0;
     88    virtual void SetupText() = 0;
    10489
    10590    /**
    10691     * Whether the cached text is currently valid (if not then SetupText will be called by Draw)
     
    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/JSInterface_IGUIObject.cpp

     
    8888    // Use onWhatever to access event handlers
    8989    if (propName.substr(0, 2) == "on")
    9090    {
    91         CStr eventName (CStr(propName.substr(2)).LowerCase());
     91        CStr eventName(CStr(propName.substr(2)).LowerCase());
    9292        auto it = e->m_ScriptHandlers.find(eventName);
    9393        if (it == e->m_ScriptHandlers.end())
    9494            vp.setNull();
     
    135135        switch (Type)
    136136        {
    137137        case GUIST_bool:
    138             {
    139                 bool value;
    140                 GUI<bool>::GetSetting(e, propName, value);
    141                 vp.set(JS::BooleanValue(value));
    142                 break;
    143             }
     138        {
     139            bool value;
     140            GUI<bool>::GetSetting(e, propName, value);
     141            vp.set(JS::BooleanValue(value));
     142            break;
     143        }
    144144
    145145        case GUIST_int:
    146             {
    147                 int value;
    148                 GUI<int>::GetSetting(e, propName, value);
    149                 vp.set(JS::Int32Value(value));
    150                 break;
    151             }
     146        {
     147            int value;
     148            GUI<int>::GetSetting(e, propName, value);
     149            vp.set(JS::Int32Value(value));
     150            break;
     151        }
    152152
    153153        case GUIST_float:
    154             {
    155                 float value;
    156                 GUI<float>::GetSetting(e, propName, value);
    157                 // Create a garbage-collectable double
    158                 vp.set(JS::NumberValue(value));
    159                 return !vp.isNull();
    160             }
     154        {
     155            float value;
     156            GUI<float>::GetSetting(e, propName, value);
     157            // Create a garbage-collectable double
     158            vp.set(JS::NumberValue(value));
     159            return !vp.isNull();
     160        }
    161161
    162162        case GUIST_CColor:
    163             {
    164                 CColor color;
    165                 GUI<CColor>::GetSetting(e, propName, color);
    166                 JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor"));
    167                 vp.setObject(*obj);
    168                 JS::RootedValue c(cx);
    169                 // Attempt to minimise ugliness through macrosity
    170                 #define P(x) c = JS::NumberValue(color.x); \
    171                 if (c.isNull()) \
    172                     return false; \
    173                 JS_SetProperty(cx, obj, #x, c)
    174                     P(r);
    175                     P(g);
    176                     P(b);
    177                     P(a);
    178                 #undef P
    179 
    180                 break;
    181             }
     163        {
     164            CColor color;
     165            GUI<CColor>::GetSetting(e, propName, color);
     166            JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor"));
     167            vp.setObject(*obj);
     168            JS::RootedValue c(cx);
     169            // Attempt to minimise ugliness through macrosity
     170#define P(x) \
     171    c = JS::NumberValue(color.x); \
     172    if (c.isNull()) \
     173        return false; \
     174    JS_SetProperty(cx, obj, #x, c)
     175            P(r);
     176            P(g);
     177            P(b);
     178            P(a);
     179#undef P
     180            break;
     181        }
    182182
    183183        case GUIST_CClientArea:
    184             {
    185                 CClientArea area;
    186                 GUI<CClientArea>::GetSetting(e, propName, area);
    187 
    188                 JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize"));
    189                 vp.setObject(*obj);
    190                 try
    191                 {
    192                 #define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true)
    193                     P(pixel,    left,   left);
    194                     P(pixel,    top,    top);
    195                     P(pixel,    right,  right);
    196                     P(pixel,    bottom, bottom);
    197                     P(percent,  left,   rleft);
    198                     P(percent,  top,    rtop);
    199                     P(percent,  right,  rright);
    200                     P(percent,  bottom, rbottom);
    201                 #undef P
    202                 }
    203                 catch (PSERROR_Scripting_ConversionFailed&)
    204                 {
    205                     debug_warn(L"Error creating size object!");
    206                     break;
    207                 }
     184        {
     185            CClientArea area;
     186            GUI<CClientArea>::GetSetting(e, propName, area);
    208187
    209                 break;
     188            JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize"));
     189            vp.setObject(*obj);
     190            try
     191            {
     192#define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true)
     193                P(pixel,    left,   left);
     194                P(pixel,    top,    top);
     195                P(pixel,    right,  right);
     196                P(pixel,    bottom, bottom);
     197                P(percent,  left,   rleft);
     198                P(percent,  top,    rtop);
     199                P(percent,  right,  rright);
     200                P(percent,  bottom, rbottom);
     201#undef P
    210202            }
    211 
    212         case GUIST_CGUIString:
     203            catch (PSERROR_Scripting_ConversionFailed&)
    213204            {
    214                 CGUIString value;
    215                 GUI<CGUIString>::GetSetting(e, propName, value);
    216                 ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString());
     205                debug_warn(L"Error creating size object!");
    217206                break;
    218207            }
    219208
     209            break;
     210        }
     211
     212        case GUIST_CGUIString:
     213        {
     214            CGUIString value;
     215            GUI<CGUIString>::GetSetting(e, propName, value);
     216            ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString());
     217            break;
     218        }
     219
    220220        case GUIST_CStr:
    221             {
    222                 CStr value;
    223                 GUI<CStr>::GetSetting(e, propName, value);
    224                 ScriptInterface::ToJSVal(cx, vp, value);
    225                 break;
    226             }
     221        {
     222            CStr value;
     223            GUI<CStr>::GetSetting(e, propName, value);
     224            ScriptInterface::ToJSVal(cx, vp, value);
     225            break;
     226        }
    227227
    228228        case GUIST_CStrW:
    229             {
    230                 CStrW value;
    231                 GUI<CStrW>::GetSetting(e, propName, value);
    232                 ScriptInterface::ToJSVal(cx, vp, value);
    233                 break;
    234             }
     229        {
     230            CStrW value;
     231            GUI<CStrW>::GetSetting(e, propName, value);
     232            ScriptInterface::ToJSVal(cx, vp, value);
     233            break;
     234        }
    235235
    236236        case GUIST_CGUISpriteInstance:
    237             {
    238                 CGUISpriteInstance *value;
    239                 GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
    240                 ScriptInterface::ToJSVal(cx, vp, value->GetName());
    241                 break;
    242             }
     237        {
     238            CGUISpriteInstance *value;
     239            GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
     240            ScriptInterface::ToJSVal(cx, vp, value->GetName());
     241            break;
     242        }
    243243
    244244        case GUIST_EAlign:
     245        {
     246            EAlign value;
     247            GUI<EAlign>::GetSetting(e, propName, value);
     248            CStr word;
     249            switch (value)
    245250            {
    246                 EAlign value;
    247                 GUI<EAlign>::GetSetting(e, propName, value);
    248                 CStr word;
    249                 switch (value)
    250                 {
    251                 case EAlign_Left: word = "left"; break;
    252                 case EAlign_Right: word = "right"; break;
    253                 case EAlign_Center: word = "center"; break;
    254                 default: debug_warn(L"Invalid EAlign!"); word = "error"; break;
    255                 }
    256                 ScriptInterface::ToJSVal(cx, vp, word);
    257                 break;
     251            case EAlign_Left: word = "left"; break;
     252            case EAlign_Right: word = "right"; break;
     253            case EAlign_Center: word = "center"; break;
     254            default: debug_warn(L"Invalid EAlign!"); word = "error"; break;
    258255            }
     256            ScriptInterface::ToJSVal(cx, vp, word);
     257            break;
     258        }
    259259
    260260        case GUIST_EVAlign:
     261        {
     262            EVAlign value;
     263            GUI<EVAlign>::GetSetting(e, propName, value);
     264            CStr word;
     265            switch (value)
    261266            {
    262                 EVAlign value;
    263                 GUI<EVAlign>::GetSetting(e, propName, value);
    264                 CStr word;
    265                 switch (value)
    266                 {
    267                 case EVAlign_Top: word = "top"; break;
    268                 case EVAlign_Bottom: word = "bottom"; break;
    269                 case EVAlign_Center: word = "center"; break;
    270                 default: debug_warn(L"Invalid EVAlign!"); word = "error"; break;
    271                 }
    272                 ScriptInterface::ToJSVal(cx, vp, word);
    273                 break;
     267            case EVAlign_Top: word = "top"; break;
     268            case EVAlign_Bottom: word = "bottom"; break;
     269            case EVAlign_Center: word = "center"; break;
     270            default: debug_warn(L"Invalid EVAlign!"); word = "error"; break;
    274271            }
     272            ScriptInterface::ToJSVal(cx, vp, word);
     273            break;
     274        }
    275275
    276276        case GUIST_CGUIList:
    277             {
    278                 CGUIList value;
    279                 GUI<CGUIList>::GetSetting(e, propName, value);
    280 
    281                 JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
    282                 vp.setObject(*obj);
     277        {
     278            CGUIList value;
     279            GUI<CGUIList>::GetSetting(e, propName, value);
    283280
    284                 for (u32 i = 0; i < value.m_Items.size(); ++i)
    285                 {
    286                     JS::RootedValue val(cx);
    287                     ScriptInterface::ToJSVal(cx, &val, value.m_Items[i].GetOriginalString());
    288                     JS_SetElement(cx, obj, i, val);
    289                 }
     281            JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
     282            vp.setObject(*obj);
    290283
    291                 break;
     284            for (u32 i = 0; i < value.m_Items.size(); ++i)
     285            {
     286                JS::RootedValue val(cx);
     287                ScriptInterface::ToJSVal(cx, &val, value.m_Items[i].GetOriginalString());
     288                JS_SetElement(cx, obj, i, val);
    292289            }
    293290
     291            break;
     292        }
     293
    294294        default:
    295295            JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
    296296            DEBUG_WARN_ERR(ERR::LOGIC);
     
    338338            return false;
    339339        }
    340340
    341         CStr eventName (CStr(propName.substr(2)).LowerCase());
     341        CStr eventName(CStr(propName.substr(2)).LowerCase());
    342342        e->SetScriptHandler(eventName, vpObj);
    343343
    344344        return true;
     
    354354
    355355    switch (Type)
    356356    {
    357 
    358357    case GUIST_CStr:
    359         {
    360             std::string value;
    361             if (!ScriptInterface::FromJSVal(cx, vp, value))
    362                 return false;
     358    {
     359        std::string value;
     360        if (!ScriptInterface::FromJSVal(cx, vp, value))
     361            return false;
    363362
    364             GUI<CStr>::SetSetting(e, propName, value);
    365             break;
    366         }
     363        GUI<CStr>::SetSetting(e, propName, value);
     364        break;
     365    }
    367366
    368367    case GUIST_CStrW:
    369         {
    370             std::wstring value;
    371             if (!ScriptInterface::FromJSVal(cx, vp, value))
    372                 return false;
     368    {
     369        std::wstring value;
     370        if (!ScriptInterface::FromJSVal(cx, vp, value))
     371            return false;
    373372
    374             GUI<CStrW>::SetSetting(e, propName, value);
    375             break;
    376         }
     373        GUI<CStrW>::SetSetting(e, propName, value);
     374        break;
     375    }
    377376
    378377    case GUIST_CGUISpriteInstance:
    379         {
    380             std::string value;
    381             if (!ScriptInterface::FromJSVal(cx, vp, value))
    382                 return false;
     378    {
     379        std::string value;
     380        if (!ScriptInterface::FromJSVal(cx, vp, value))
     381            return false;
    383382
    384             GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value));
    385             break;
    386         }
     383        GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value));
     384        break;
     385    }
    387386
    388387    case GUIST_CGUIString:
    389         {
    390             std::wstring value;
    391             if (!ScriptInterface::FromJSVal(cx, vp, value))
    392                 return false;
     388    {
     389        std::wstring value;
     390        if (!ScriptInterface::FromJSVal(cx, vp, value))
     391            return false;
    393392
    394             CGUIString str;
    395             str.SetValue(value);
    396             GUI<CGUIString>::SetSetting(e, propName, str);
    397             break;
    398         }
     393        CGUIString str;
     394        str.SetValue(value);
     395        GUI<CGUIString>::SetSetting(e, propName, str);
     396        break;
     397    }
    399398
    400399    case GUIST_EAlign:
    401         {
    402             std::string value;
    403             if (!ScriptInterface::FromJSVal(cx, vp, value))
    404                 return false;
     400    {
     401        std::string value;
     402        if (!ScriptInterface::FromJSVal(cx, vp, value))
     403            return false;
    405404
    406             EAlign a;
    407             if (value == "left") a = EAlign_Left;
    408             else if (value == "right") a = EAlign_Right;
    409             else if (value == "center" || value == "centre") a = EAlign_Center;
    410             else
    411             {
    412                 JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')");
    413                 return false;
    414             }
    415             GUI<EAlign>::SetSetting(e, propName, a);
    416             break;
     405        EAlign a;
     406        if (value == "left") a = EAlign_Left;
     407        else if (value == "right") a = EAlign_Right;
     408        else if (value == "center" || value == "centre") a = EAlign_Center;
     409        else
     410        {
     411            JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')");
     412            return false;
    417413        }
     414        GUI<EAlign>::SetSetting(e, propName, a);
     415        break;
     416    }
    418417
    419418    case GUIST_EVAlign:
    420         {
    421             std::string value;
    422             if (!ScriptInterface::FromJSVal(cx, vp, value))
    423                 return false;
     419    {
     420        std::string value;
     421        if (!ScriptInterface::FromJSVal(cx, vp, value))
     422            return false;
    424423
    425             EVAlign a;
    426             if (value == "top") a = EVAlign_Top;
    427             else if (value == "bottom") a = EVAlign_Bottom;
    428             else if (value == "center" || value == "centre") a = EVAlign_Center;
    429             else
    430             {
    431                 JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')");
    432                 return false;
    433             }
    434             GUI<EVAlign>::SetSetting(e, propName, a);
    435             break;
     424        EVAlign a;
     425        if (value == "top") a = EVAlign_Top;
     426        else if (value == "bottom") a = EVAlign_Bottom;
     427        else if (value == "center" || value == "centre") a = EVAlign_Center;
     428        else
     429        {
     430            JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')");
     431            return false;
    436432        }
     433        GUI<EVAlign>::SetSetting(e, propName, a);
     434        break;
     435    }
    437436
    438437    case GUIST_int:
     438    {
     439        int value;
     440        if (ScriptInterface::FromJSVal(cx, vp, value))
     441            GUI<int>::SetSetting(e, propName, value);
     442        else
    439443        {
    440             int value;
    441             if (ScriptInterface::FromJSVal(cx, vp, value))
    442                 GUI<int>::SetSetting(e, propName, value);
    443             else
    444             {
    445                 JS_ReportError(cx, "Cannot convert value to int");
    446                 return false;
    447             }
    448             break;
     444            JS_ReportError(cx, "Cannot convert value to int");
     445            return false;
    449446        }
     447        break;
     448    }
    450449
    451450    case GUIST_float:
     451    {
     452        double value;
     453        if (JS::ToNumber(cx, vp, &value) == true)
     454            GUI<float>::SetSetting(e, propName, (float)value);
     455        else
    452456        {
    453             double value;
    454             if (JS::ToNumber(cx, vp, &value) == true)
    455                 GUI<float>::SetSetting(e, propName, (float)value);
    456             else
    457             {
    458                 JS_ReportError(cx, "Cannot convert value to float");
    459                 return false;
    460             }
    461             break;
     457            JS_ReportError(cx, "Cannot convert value to float");
     458            return false;
    462459        }
     460        break;
     461    }
    463462
    464463    case GUIST_bool:
    465         {
    466             bool value = JS::ToBoolean(vp);
    467             GUI<bool>::SetSetting(e, propName, value);
    468             break;
    469         }
     464    {
     465        bool value = JS::ToBoolean(vp);
     466        GUI<bool>::SetSetting(e, propName, value);
     467        break;
     468    }
    470469
    471470    case GUIST_CClientArea:
     471    {
     472        if (vp.isString())
    472473        {
    473             if (vp.isString())
    474             {
    475                 std::wstring value;
    476                 if (!ScriptInterface::FromJSVal(cx, vp, value))
    477                     return false;
    478 
    479                 if (e->SetSetting(propName, value) != PSRETURN_OK)
    480                 {
    481                     JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
    482                     return false;
    483                 }
    484             }
    485             else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL))
    486             {
    487                 CClientArea area;
    488                 GUI<CClientArea>::GetSetting(e, propName, area);
    489 
    490                 ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
    491                 #define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y)
    492                     P(pixel,    left,   left);
    493                     P(pixel,    top,    top);
    494                     P(pixel,    right,  right);
    495                     P(pixel,    bottom, bottom);
    496                     P(percent,  left,   rleft);
    497                     P(percent,  top,    rtop);
    498                     P(percent,  right,  rright);
    499                     P(percent,  bottom, rbottom);
    500                 #undef P
    501 
    502                 GUI<CClientArea>::SetSetting(e, propName, area);
    503             }
    504             else
     474            std::wstring value;
     475            if (!ScriptInterface::FromJSVal(cx, vp, value))
     476                return false;
     477
     478            if (e->SetSetting(propName, value) != PSRETURN_OK)
    505479            {
    506                 JS_ReportError(cx, "Size only accepts strings or GUISize objects");
     480                JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
    507481                return false;
    508482            }
    509             break;
    510483        }
     484        else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL))
     485        {
     486            CClientArea area;
     487            GUI<CClientArea>::GetSetting(e, propName, area);
     488
     489            ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface;
     490#define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y)
     491            P(pixel,    left,   left);
     492            P(pixel,    top,    top);
     493            P(pixel,    right,  right);
     494            P(pixel,    bottom, bottom);
     495            P(percent,  left,   rleft);
     496            P(percent,  top,    rtop);
     497            P(percent,  right,  rright);
     498            P(percent,  bottom, rbottom);
     499#undef P
     500
     501            GUI<CClientArea>::SetSetting(e, propName, area);
     502        }
     503        else
     504        {
     505            JS_ReportError(cx, "Size only accepts strings or GUISize objects");
     506            return false;
     507        }
     508        break;
     509    }
    511510
    512511    case GUIST_CColor:
     512    {
     513        if (vp.isString())
    513514        {
    514             if (vp.isString())
    515             {
    516                 std::wstring value;
    517                 if (!ScriptInterface::FromJSVal(cx, vp, value))
    518                     return false;
    519 
    520                 if (e->SetSetting(propName, value) != PSRETURN_OK)
    521                 {
    522                     JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
    523                     return false;
    524                 }
    525             }
    526             else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL))
    527             {
    528                 CColor color;
    529                 JS::RootedValue t(cx);
    530                 double s;
    531                 #define PROP(x) JS_GetProperty(cx, vpObj, #x, &t); \
    532                                 s = t.toDouble(); \
    533                                 color.x = (float)s
    534                 PROP(r); PROP(g); PROP(b); PROP(a);
    535                 #undef PROP
    536 
    537                 GUI<CColor>::SetSetting(e, propName, color);
    538             }
    539             else
     515            std::wstring value;
     516            if (!ScriptInterface::FromJSVal(cx, vp, value))
     517                return false;
     518
     519            if (e->SetSetting(propName, value) != PSRETURN_OK)
    540520            {
    541                 JS_ReportError(cx, "Color only accepts strings or GUIColor objects");
     521                JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
    542522                return false;
    543523            }
    544             break;
    545524        }
     525        else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL))
     526        {
     527            CColor color;
     528            JS::RootedValue t(cx);
     529            double s;
     530#define PROP(x) \
     531    JS_GetProperty(cx, vpObj, #x, &t); \
     532    s = t.toDouble(); \
     533    color.x = (float)s
     534            PROP(r);
     535            PROP(g);
     536            PROP(b);
     537            PROP(a);
     538#undef PROP
     539            GUI<CColor>::SetSetting(e, propName, color);
     540        }
     541        else
     542        {
     543            JS_ReportError(cx, "Color only accepts strings or GUIColor objects");
     544            return false;
     545        }
     546        break;
     547    }
    546548
    547549    case GUIST_CGUIList:
     550    {
     551        u32 length;
     552        if (!vp.isObject() || !JS_GetArrayLength(cx, vpObj, &length))
    548553        {
    549             u32 length;
    550             if (!vp.isObject() || !JS_GetArrayLength(cx, vpObj, &length))
    551             {
    552                 JS_ReportError(cx, "List only accepts a GUIList object");
    553                 return false;
    554             }
     554            JS_ReportError(cx, "List only accepts a GUIList object");
     555            return false;
     556        }
    555557
    556             CGUIList list;
     558        CGUIList list;
    557559
    558             for (u32 i=0; i<length; ++i)
     560        for (u32 i = 0; i < length; ++i)
     561        {
     562            JS::RootedValue element(cx);
     563            if (!JS_GetElement(cx, vpObj, i, &element))
    559564            {
    560                 JS::RootedValue element(cx);
    561                 if (!JS_GetElement(cx, vpObj, i, &element))
    562                 {
    563                     JS_ReportError(cx, "Failed to get list element");
    564                     return false;
    565                 }
    566 
    567                 std::wstring value;
    568                 if (!ScriptInterface::FromJSVal(cx, element, value))
    569                     return false;
     565                JS_ReportError(cx, "Failed to get list element");
     566                return false;
     567            }
    570568
    571                 CGUIString str;
    572                 str.SetValue(value);
     569            std::wstring value;
     570            if (!ScriptInterface::FromJSVal(cx, element, value))
     571                return false;
    573572
    574                 list.m_Items.push_back(str);
    575             }
     573            CGUIString str;
     574            str.SetValue(value);
    576575
    577             GUI<CGUIList>::SetSetting(e, propName, list);
    578             break;
     576            list.m_Items.push_back(str);
    579577        }
    580578
    581         // TODO Gee: (2004-09-01) EAlign and EVAlign too.
     579        GUI<CGUIList>::SetSetting(e, propName, list);
     580        break;
     581    }
    582582
    583583    default:
    584584        JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str());
     
    616616    scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL);
    617617}
    618618
    619 bool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)
     619bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), jsval* vp)
    620620{
    621     UNUSED2(argc);
    622621    JSAutoRequest rq(cx);
    623622    JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
    624623
     
    635634    return true;
    636635}
    637636
    638 bool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)
     637bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), jsval* vp)
    639638{
    640     UNUSED2(argc);
    641639    JSAutoRequest rq(cx);
    642640    JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
    643641
     
    653651    return true;
    654652}
    655653
    656 bool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)
     654bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), jsval* vp)
    657655{
    658     UNUSED2(argc);
    659656    JSAutoRequest rq(cx);
    660657    JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
    661658
     
    671668    return true;
    672669}
    673670
    674 bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp)
     671bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), jsval* vp)
    675672{
    676     UNUSED2(argc);
    677673    JSAutoRequest rq(cx);
    678674    JS::CallReceiver rec = JS::CallReceiverFromVp(vp);
    679675   
  • 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}