Ticket #3354: gui_cleanup.patch
File gui_cleanup.patch, 232.1 KB (added by , 9 years ago) |
---|
-
source/gui/CButton.cpp
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CButton20 */21 22 18 #include "precompiled.h" 23 19 24 20 #include "CButton.h" 25 21 26 22 #include "lib/ogl.h" 27 23 28 29 //-------------------------------------------------------------------30 // Constructor / Destructor31 //-------------------------------------------------------------------32 24 CButton::CButton() 33 25 { 34 26 AddSetting(GUIST_float, "buffer_zone"); … … 84 76 CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]); 85 77 } 86 78 87 void CButton::HandleMessage(SGUIMessage &Message)79 void CButton::HandleMessage(SGUIMessage& Message) 88 80 { 89 81 // Important 90 82 IGUIButtonBehavior::HandleMessage(Message); -
source/gui/CButton.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Button20 21 --Overview--22 23 GUI Object representing a simple button24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_CBUTTON 32 19 #define INCLUDED_CBUTTON 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 //--------------------------------------------------------40 // Macros41 //--------------------------------------------------------42 43 //--------------------------------------------------------44 // Types45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Declarations49 //--------------------------------------------------------50 51 23 /** 52 24 * Button 53 25 * … … 70 42 /** 71 43 * @see IGUIObject#HandleMessage() 72 44 */ 73 virtual void HandleMessage(SGUIMessage &Message);45 virtual void HandleMessage(SGUIMessage& Message); 74 46 75 47 /** 76 48 * Draws the Button … … 90 62 CPos m_TextPos; 91 63 }; 92 64 93 #endif 65 #endif // INCLUDED_CBUTTON -
source/gui/CCheckBox.cpp
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CCheckBox20 */21 22 18 #include "precompiled.h" 23 19 24 20 #include "CCheckBox.h" 25 21 22 #include "graphics/FontMetrics.h" 26 23 #include "ps/CLogger.h" 27 24 #include "ps/CStrIntern.h" 28 #include "graphics/FontMetrics.h"29 30 25 31 //-------------------------------------------------------------------32 // Constructor / Destructor33 //-------------------------------------------------------------------34 26 CCheckBox::CCheckBox() 35 27 { 36 28 AddSetting(GUIST_float, "buffer_zone"); … … 91 83 *m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth()-square_side, 0.f, this); 92 84 } 93 85 94 void CCheckBox::HandleMessage(SGUIMessage &Message)86 void CCheckBox::HandleMessage(SGUIMessage& Message) 95 87 { 96 88 // Important 97 89 IGUIButtonBehavior::HandleMessage(Message); -
source/gui/CCheckBox.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Check box20 21 --Overview--22 23 GUI Object representing a check box24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_CCHECKBOX 32 19 #define INCLUDED_CCHECKBOX 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 //--------------------------------------------------------40 // Macros41 //--------------------------------------------------------42 43 //--------------------------------------------------------44 // Types45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Declarations49 //--------------------------------------------------------50 51 23 /** 52 24 * CheckBox 53 25 * … … 71 43 /** 72 44 * @see IGUIObject#HandleMessage() 73 45 */ 74 virtual void HandleMessage(SGUIMessage &Message);46 virtual void HandleMessage(SGUIMessage& Message); 75 47 76 48 /** 77 49 * Draws the control … … 86 58 void SetupText(); 87 59 }; 88 60 89 #endif 61 #endif // INCLUDED_CCHECKBOX -
source/gui/CDropDown.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CDropDown20 */21 22 18 #include "precompiled.h" 23 19 24 20 #include "CDropDown.h" 25 21 26 #include "ps/CLogger.h"27 22 #include "lib/external_libraries/libsdl.h" 28 23 #include "lib/ogl.h" 29 24 #include "lib/timer.h" 25 #include "ps/CLogger.h" 30 26 #include "soundmanager/ISoundManager.h" 31 27 32 33 //------------------------------------------------------------------- 34 // Constructor / Destructor 35 //------------------------------------------------------------------- 36 CDropDown::CDropDown() : m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1) 28 CDropDown::CDropDown() 29 : m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1) 37 30 { 38 31 AddSetting(GUIST_float, "button_width"); 39 32 AddSetting(GUIST_float, "dropdown_size"); … … 72 65 CList::SetupText(); 73 66 } 74 67 75 void CDropDown::HandleMessage(SGUIMessage &Message)68 void CDropDown::HandleMessage(SGUIMessage& Message) 76 69 { 77 70 // Important 78 71 … … 96 89 97 90 case GUIM_MOUSE_MOTION: 98 91 { 99 if (m_Open) 100 { 101 CPos mouse = GetMousePos(); 92 if (!m_Open) 93 break; 102 94 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(); 114 96 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; 136 120 } 137 121 } 122 123 if (set != -1) 124 { 125 //GUI<int>::SetSetting(this, "selected", set); 126 m_ElementHighlight = set; 127 //UpdateAutoScroll(); 128 } 138 129 139 130 break; 140 131 } … … 143 134 { 144 135 bool enabled; 145 136 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); 152 143 break; 153 144 } 154 145 … … 158 149 159 150 bool enabled; 160 151 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); 167 158 break; 168 159 } 169 160 … … 183 174 184 175 if (!m_Open) 185 176 { 186 CGUIList *pList;177 CGUIList* pList; 187 178 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 188 179 if (pList->m_Items.empty()) 189 180 return; … … 193 184 GUI<int>::GetSetting(this, "selected", m_ElementHighlight); 194 185 195 186 // Start at the position of the selected item, if possible. 196 GetScrollBar(0).SetPos( 187 GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); 197 188 198 189 CStrW soundPath; 199 190 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty()) … … 242 233 if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1) 243 234 break; 244 235 245 m_ElementHighlight++;236 ++m_ElementHighlight; 246 237 GUI<int>::SetSetting(this, "selected", m_ElementHighlight); 247 238 break; 248 239 } -
source/gui/CDropDown.h
33 33 #ifndef INCLUDED_CDROPDOWN 34 34 #define INCLUDED_CDROPDOWN 35 35 36 //--------------------------------------------------------37 // Includes / Compiler directives38 //--------------------------------------------------------39 36 #include "GUI.h" 40 37 #include "CList.h" 41 //class CList;42 43 //--------------------------------------------------------44 // Macros45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Types49 //--------------------------------------------------------50 51 //--------------------------------------------------------52 // Declarations53 //--------------------------------------------------------54 38 55 39 /** 56 40 * Drop Down … … 74 58 /** 75 59 * @see IGUIObject#HandleMessage() 76 60 */ 77 virtual void HandleMessage(SGUIMessage &Message);61 virtual void HandleMessage(SGUIMessage& Message); 78 62 79 63 /** 80 64 * Handle events manually to catch keyboard inputting. … … 137 121 138 122 }; 139 123 140 #endif 124 #endif // INCLUDED_CDROPDOWN -
source/gui/CGUI.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CGUI20 */21 22 18 #include "precompiled.h" 23 19 24 #include <string>25 26 20 #include <stdarg.h> 21 #include <string> 27 22 28 23 #include "GUI.h" 29 24 30 25 // Types - when including them into the engine. 31 26 #include "CButton.h" 32 #include "CImage.h"33 #include "CText.h"34 27 #include "CCheckBox.h" 35 #include "CRadioButton.h" 28 #include "CDropDown.h" 29 #include "CImage.h" 36 30 #include "CInput.h" 37 31 #include "CList.h" 38 32 #include "COList.h" 39 #include "CDropDown.h"40 33 #include "CProgressBar.h" 34 #include "CRadioButton.h" 35 #include "CText.h" 41 36 #include "CTooltip.h" 42 37 #include "MiniMap.h" 43 #include "scripting/ScriptFunctions.h"44 38 45 39 #include "graphics/FontMetrics.h" 46 40 #include "graphics/ShaderManager.h" 47 41 #include "graphics/TextRenderer.h" 48 #include "lib/input.h"49 #include "lib/bits.h"50 42 #include "i18n/L10n.h" 51 #include "lib/timer.h" 43 #include "lib/bits.h" 44 #include "lib/input.h" 52 45 #include "lib/sysdep/sysdep.h" 46 #include "lib/timer.h" 53 47 #include "lib/utf8.h" 54 48 #include "ps/CLogger.h" 55 49 #include "ps/Filesystem.h" 56 #include "ps/Hotkey.h"57 50 #include "ps/Globals.h" 51 #include "ps/Hotkey.h" 58 52 #include "ps/Profile.h" 59 53 #include "ps/Pyrogenesis.h" 60 54 #include "ps/XML/Xeromyces.h" 61 55 #include "renderer/Renderer.h" 56 #include "scripting/ScriptFunctions.h" 62 57 #include "scriptinterface/ScriptInterface.h" 63 58 64 59 extern int g_yres; … … 75 70 const char* hotkey = static_cast<const char*>(ev->ev.user.data1); 76 71 std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey); 77 72 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"); 84 75 } 85 76 86 77 else if (ev->ev.type == SDL_MOUSEMOTION) … … 124 115 // TODO Gee: (2004-09-08) Big TODO, don't do the below if the SDL_Event is something like a keypress! 125 116 try 126 117 { 127 PROFILE( "mouse events");118 PROFILE("mouse events"); 128 119 // TODO Gee: Optimizations needed! 129 120 // these two recursive function are quite overhead heavy. 130 121 … … 314 305 // Constructor / Destructor 315 306 //------------------------------------------------------------------- 316 307 317 CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0) 308 CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) 309 : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0) 318 310 { 319 311 m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime)); 320 312 GuiScriptingInit(*m_ScriptInterface); … … 383 375 } 384 376 } 385 377 386 void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, 387 int CellID, 388 const float& Z, 389 const CRect& Rect, 390 const CRect& UNUSED(Clipping)) 378 void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping)) 391 379 { 392 380 // If the sprite doesn't exist (name == ""), don't bother drawing anything 393 381 if (Sprite.IsEmpty()) … … 402 390 { 403 391 // We can use the map to delete all 404 392 // now we don't want to cancel all if one Destroy fails 405 for ( map_pObjects::iterator it = m_pAllObjects.begin(); it != m_pAllObjects.end(); ++it)393 for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects) 406 394 { 407 395 try 408 396 { 409 it->second->Destroy();397 p.second->Destroy(); 410 398 } 411 399 catch (PSERROR_GUI& e) 412 400 { … … 415 403 // TODO Gee: Handle 416 404 } 417 405 418 delete it->second;406 delete p.second; 419 407 } 420 421 // Clear all422 408 m_pAllObjects.clear(); 423 for(std::map<CStr, CGUISprite*>::iterator it = m_Sprites.begin(); it != m_Sprites.end(); ++it) 424 delete it->second; 409 410 for (const std::pair<CStr, CGUISprite*>& p : m_Sprites) 411 delete p.second; 425 412 m_Sprites.clear(); 426 413 m_Icons.clear(); 427 414 } … … 429 416 void CGUI::UpdateResolution() 430 417 { 431 418 // Update ALL cached 432 GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize 419 GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize); 433 420 } 434 421 435 422 void CGUI::AddObject(IGUIObject* pObject) … … 464 451 try 465 452 { 466 453 // Fill freshly 467 GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects);454 GUI<map_pObjects>::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects); 468 455 } 469 456 catch (PSERROR_GUI&) 470 457 { … … 528 515 529 516 // Some help functions 530 517 // TODO Gee: CRect => CPoint ? 531 void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall,518 void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall, 532 519 const float width, const float y, 533 const CSize &Size, const CStr& TextureName,520 const CSize& Size, const CStr& TextureName, 534 521 const float BufferZone, const int CellID) 535 522 { 536 523 // TODO Gee: Temp hardcoded values … … 557 544 } 558 545 }; 559 546 560 SGUIText CGUI::GenerateText(const CGUIString &string, 561 const CStrW& FontW, const float &Width, const float &BufferZone, 562 const IGUIObject *pObject) 547 SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const float& Width, const float& BufferZone, const IGUIObject* pObject) 563 548 { 564 549 SGUIText Text; // object we're generating 565 550 566 551 CStrIntern Font(FontW.ToUTF8()); 567 552 568 if (string.m_Words. size() == 0)553 if (string.m_Words.empty()) 569 554 return Text; 570 555 571 556 float x=BufferZone, y=BufferZone; // drawing pointer … … 615 600 // Loop left/right 616 601 for (int j=0; j<2; ++j) 617 602 { 618 for (std::vector<CStr>::const_iterator it = Feedback.m_Images[j].begin(); 619 it != Feedback.m_Images[j].end(); 620 ++it) 603 for (const CStr& imgname : Feedback.m_Images[j]) 621 604 { 622 605 SGUIText::SSpriteCall SpriteCall; 623 606 SGenerateTextImage Image; … … 631 614 _y = y; 632 615 633 616 // Get Size from Icon database 634 SGUIIcon icon = GetIcon( *it);617 SGUIIcon icon = GetIcon(imgname); 635 618 636 619 CSize size = icon.m_Size; 637 620 Image.SetupSpriteCall((j==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID); … … 676 659 // Loop through left and right side, from and to. 677 660 for (int j=0; j<2; ++j) 678 661 { 679 for (std::vector<SGenerateTextImage>::const_iterator it = Images[j].begin(); 680 it != Images[j].end(); 681 ++it) 662 for (const SGenerateTextImage& img : Images[j]) 682 663 { 683 664 // We're working with two intervals here, the image's and the line height's. 684 665 // let's find the union of these two. 685 666 float union_from, union_to; 686 667 687 union_from = std::max(y, i t->m_YFrom);688 union_to = std::min(y+prelim_line_height, i t->m_YTo);668 union_from = std::max(y, img.m_YFrom); 669 union_to = std::min(y+prelim_line_height, img.m_YTo); 689 670 690 671 // The union is not empty 691 672 if (union_to > union_from) 692 673 { 693 674 if (j == From) 694 width_range[From] = std::max(width_range[From], i t->m_Indentation);675 width_range[From] = std::max(width_range[From], img.m_Indentation); 695 676 else 696 width_range[To] = std::min(width_range[To], Width - i t->m_Indentation);677 width_range[To] = std::min(width_range[To], Width - img.m_Indentation); 697 678 } 698 679 } 699 680 } … … 783 764 // x, that is what x_pointer is for. 784 765 float x_pointer=0.f; 785 766 786 std::vector<SGUIText::STextCall>::iterator it; 787 for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it) 767 for (SGUIText::STextCall& tc : Feedback2.m_TextCalls) 788 768 { 789 it->m_Pos = CPos(dx + x + x_pointer, y);769 tc.m_Pos = CPos(dx + x + x_pointer, y); 790 770 791 x_pointer += it->m_Size.cx;771 x_pointer += tc.m_Size.cx; 792 772 793 if (it->m_pSpriteCall) 794 { 795 it->m_pSpriteCall->m_Area += it->m_Pos - CSize(0,it->m_pSpriteCall->m_Area.GetHeight()); 796 } 773 if (tc.m_pSpriteCall) 774 tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize(0, tc.m_pSpriteCall->m_Area.GetHeight()); 797 775 } 798 776 799 777 // Append X value. … … 815 793 Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end()); 816 794 break; 817 795 } 818 else 819 if (x > width_range[To] && j==temp_from) 796 else if (x > width_range[To] && j==temp_from) 820 797 { 821 798 from = j+1; 822 799 // do not break, since we want it to be added to m_TextCalls 823 800 } 824 else 825 if (x > width_range[To]) 801 else if (x > width_range[To]) 826 802 { 827 803 from = j; 828 804 break; … … 856 832 return Text; 857 833 } 858 834 859 void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor, 860 const CPos &pos, const float &z, const CRect &clipping) 835 void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping) 861 836 { 862 837 CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); 863 838 … … 878 853 textRenderer.SetClippingRect(clipping); 879 854 textRenderer.Translate(0.0f, 0.0f, z); 880 855 881 for (std::vector<SGUIText::STextCall>::const_iterator it = Text.m_TextCalls.begin(); 882 it != Text.m_TextCalls.end(); 883 ++it) 856 for (const SGUIText::STextCall& tc : Text.m_TextCalls) 884 857 { 885 858 // If this is just a placeholder for a sprite call, continue 886 if ( it->m_pSpriteCall)859 if (tc.m_pSpriteCall) 887 860 continue; 888 861 889 CColor color = it->m_UseCustomColor ? it->m_Color : DefaultColor;862 CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor; 890 863 891 864 textRenderer.Color(color); 892 textRenderer.Font( it->m_Font);893 textRenderer.Put((float)(int)(pos.x +it->m_Pos.x), (float)(int)(pos.y+it->m_Pos.y), &it->m_String);865 textRenderer.Font(tc.m_Font); 866 textRenderer.Put((float)(int)(pos.x + tc.m_Pos.x), (float)(int)(pos.y + tc.m_Pos.y), &tc.m_String); 894 867 } 895 868 896 869 textRenderer.Render(); 897 870 898 for (std::list<SGUIText::SSpriteCall>::iterator it=Text.m_SpriteCalls.begin(); 899 it!=Text.m_SpriteCalls.end(); 900 ++it) 901 { 902 DrawSprite(it->m_Sprite, it->m_CellID, z, it->m_Area + pos); 903 } 871 for (const SGUIText::SSpriteCall& sc : Text.m_SpriteCalls) 872 DrawSprite(sc.m_Sprite, sc.m_CellID, z, sc.m_Area + pos); 904 873 905 874 if (isClipped) 906 875 glDisable(GL_SCISSOR_TEST); … … 908 877 tech->EndPass(); 909 878 } 910 879 911 bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output)880 bool CGUI::GetPreDefinedColor(const CStr& name, CColor& Output) const 912 881 { 913 if (m_PreDefinedColors.count(name) == 0)914 {882 std::map<CStr, CColor>::const_iterator cit = m_PreDefinedColors.find(name); 883 if (cit == m_PreDefinedColors.end()) 915 884 return false; 916 } 917 else 918 { 919 Output = m_PreDefinedColors[name]; 920 return true; 921 } 885 886 Output = cit->second; 887 return true; 922 888 } 923 889 924 890 /** … … 941 907 942 908 try 943 909 { 944 945 910 if (root_name == "objects") 946 911 { 947 912 Xeromyces_ReadRootObjects(node, &XeroFile, Paths); … … 949 914 // Re-cache all values so these gets cached too. 950 915 //UpdateResolution(); 951 916 } 952 else 953 if (root_name == "sprites") 954 { 917 else if (root_name == "sprites") 955 918 Xeromyces_ReadRootSprites(node, &XeroFile); 956 } 957 else 958 if (root_name == "styles") 959 { 919 else if (root_name == "styles") 960 920 Xeromyces_ReadRootStyles(node, &XeroFile); 961 } 962 else 963 if (root_name == "setup") 964 { 921 else if (root_name == "setup") 965 922 Xeromyces_ReadRootSetup(node, &XeroFile); 966 }967 923 else 968 {969 924 debug_warn(L"CGUI::LoadXmlFile error"); 970 925 // TODO Gee: Output in log 971 }972 926 } 973 927 catch (PSERROR_GUI& e) 974 928 { … … 1029 983 CStr name(pFile->GetElementString(child.GetNodeName())); 1030 984 1031 985 if (name == "scrollbar") 1032 {1033 986 Xeromyces_ReadScrollBarStyle(child, pFile); 1034 } 1035 else 1036 if (name == "icon") 1037 { 987 else if (name == "icon") 1038 988 Xeromyces_ReadIcon(child, pFile); 1039 } 1040 else 1041 if (name == "tooltip") 1042 { 989 else if (name == "tooltip") 1043 990 Xeromyces_ReadTooltip(child, pFile); 1044 } 1045 else 1046 if (name == "color") 1047 { 991 else if (name == "color") 1048 992 Xeromyces_ReadColor(child, pFile); 1049 }1050 993 else 1051 {1052 994 debug_warn(L"Invalid data - DTD shouldn't allow this"); 1053 }1054 995 } 1055 996 } 1056 997 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)998 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) 1058 999 { 1059 1000 ENSURE(pParent); 1060 1001 … … 1064 1005 XMBAttributeList attributes = Element.GetAttributes(); 1065 1006 1066 1007 // Well first of all we need to determine the type 1067 CStr type 1008 CStr type(attributes.GetNamedItem(pFile->GetAttributeID("type"))); 1068 1009 if (type.empty()) 1069 1010 type = "empty"; 1070 1011 … … 1150 1091 CStr name(attr.Value); 1151 1092 1152 1093 // Apply the requested substitutions 1153 for ( size_t j = 0; j < NameSubst.size(); ++j)1154 name.Replace( NameSubst[j].first, NameSubst[j].second);1094 for (const std::pair<CStr, CStr>& sub : NameSubst) 1095 name.Replace(sub.first, sub.second); 1155 1096 1156 1097 object->SetName(name); 1157 1098 NameSet = true; … … 1415 1356 } 1416 1357 } 1417 1358 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)1359 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) 1419 1360 { 1420 1361 #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) 1421 1362 #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) … … 1432 1373 1433 1374 for (int n = 0; n < count; ++n) 1434 1375 { 1435 NameSubst. push_back(std::make_pair(var, "[" + CStr::FromInt(n) + "]"));1376 NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]"); 1436 1377 1437 1378 XERO_ITER_EL(Element, child) 1438 1379 { … … 1448 1389 void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths) 1449 1390 { 1450 1391 // Check for a 'file' parameter 1451 CStrW file(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file")).FromUTF8());1392 CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8()); 1452 1393 1453 1394 // If there is a file specified, open and execute it 1454 1395 if (!file.empty()) … … 1465 1406 } 1466 1407 1467 1408 // If it has a directory attribute, read all JS files in that directory 1468 CStrW directory(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("directory")).FromUTF8());1409 CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8()); 1469 1410 if (!directory.empty()) 1470 1411 { 1471 1412 VfsPaths pathnames; … … 1513 1454 // 1514 1455 1515 1456 // Get name, we know it exists because of DTD requirements 1516 name = Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("name"));1457 name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name")); 1517 1458 1518 1459 if (m_Sprites.find(name) != m_Sprites.end()) 1519 1460 LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str()); … … 1553 1494 // Apply the effects to every image (unless the image overrides it with 1554 1495 // different effects) 1555 1496 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 later1497 for (SGUIImage* const& img : Sprite->m_Images) 1498 if (!img->m_Effects) 1499 img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later 1559 1500 1560 1501 delete effects; 1561 1502 … … 1566 1507 m_Sprites[name] = Sprite; 1567 1508 } 1568 1509 1569 void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent)1510 void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent) 1570 1511 { 1571 1512 1572 1513 // Image object we're adding … … 1592 1533 { 1593 1534 Image->m_TextureName = VfsPath("art/textures/ui") / attr_value; 1594 1535 } 1595 else 1596 if (attr_name == "size") 1536 else if (attr_name == "size") 1597 1537 { 1598 1538 CClientArea ca; 1599 1539 if (!GUI<CClientArea>::ParseString(attr_value, ca)) 1600 1540 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1601 else Image->m_Size = ca; 1541 else 1542 Image->m_Size = ca; 1602 1543 } 1603 else 1604 if (attr_name == "texture_size") 1544 else if (attr_name == "texture_size") 1605 1545 { 1606 1546 CClientArea ca; 1607 1547 if (!GUI<CClientArea>::ParseString(attr_value, ca)) 1608 1548 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1609 else Image->m_TextureSize = ca; 1549 else 1550 Image->m_TextureSize = ca; 1610 1551 } 1611 else 1612 if (attr_name == "real_texture_placement") 1552 else if (attr_name == "real_texture_placement") 1613 1553 { 1614 1554 CRect rect; 1615 1555 if (!GUI<CRect>::ParseString(attr_value, rect)) 1616 1556 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1617 else Image->m_TexturePlacementInFile = rect; 1557 else 1558 Image->m_TexturePlacementInFile = rect; 1618 1559 } 1619 else 1620 if (attr_name == "cell_size") 1560 else if (attr_name == "cell_size") 1621 1561 { 1622 1562 CSize size; 1623 1563 if (!GUI<CSize>::ParseString(attr_value, size)) 1624 1564 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1625 else Image->m_CellSize = size; 1565 else 1566 Image->m_CellSize = size; 1626 1567 } 1627 else 1628 if (attr_name == "fixed_h_aspect_ratio") 1568 else if (attr_name == "fixed_h_aspect_ratio") 1629 1569 { 1630 1570 float val; 1631 1571 if (!GUI<float>::ParseString(attr_value, val)) 1632 1572 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1633 else Image->m_FixedHAspectRatio = val; 1573 else 1574 Image->m_FixedHAspectRatio = val; 1634 1575 } 1635 else 1636 if (attr_name == "round_coordinates") 1576 else if (attr_name == "round_coordinates") 1637 1577 { 1638 1578 bool b; 1639 1579 if (!GUI<bool>::ParseString(attr_value, b)) 1640 1580 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1641 else Image->m_RoundCoordinates = b; 1581 else 1582 Image->m_RoundCoordinates = b; 1642 1583 } 1643 else 1644 if (attr_name == "wrap_mode") 1584 else if (attr_name == "wrap_mode") 1645 1585 { 1646 1586 if (attr_value == L"repeat") 1647 1587 Image->m_WrapMode = GL_REPEAT; … … 1652 1592 else 1653 1593 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1654 1594 } 1655 else 1656 if (attr_name == "z_level") 1595 else if (attr_name == "z_level") 1657 1596 { 1658 1597 float z_level; 1659 1598 if (!GUI<float>::ParseString(attr_value, z_level)) 1660 1599 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1661 else Image->m_DeltaZ = z_level/100.f; 1600 else 1601 Image->m_DeltaZ = z_level/100.f; 1662 1602 } 1663 else 1664 if (attr_name == "backcolor") 1603 else if (attr_name == "backcolor") 1665 1604 { 1666 1605 CColor color; 1667 1606 if (!GUI<CColor>::ParseString(attr_value, color)) 1668 1607 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1669 else Image->m_BackColor = color; 1608 else 1609 Image->m_BackColor = color; 1670 1610 } 1671 else 1672 if (attr_name == "bordercolor") 1611 else if (attr_name == "bordercolor") 1673 1612 { 1674 1613 CColor color; 1675 1614 if (!GUI<CColor>::ParseString(attr_value, color)) 1676 1615 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1677 else Image->m_BorderColor = color; 1616 else 1617 Image->m_BorderColor = color; 1678 1618 } 1679 else 1680 if (attr_name == "border") 1619 else if (attr_name == "border") 1681 1620 { 1682 1621 bool b; 1683 1622 if (!GUI<bool>::ParseString(attr_value, b)) 1684 1623 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1685 else Image->m_Border = b; 1624 else 1625 Image->m_Border = b; 1686 1626 } 1687 1627 else 1688 1628 { … … 1719 1659 parent.AddImage(Image); 1720 1660 } 1721 1661 1722 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)1662 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects) 1723 1663 { 1724 1664 for (XMBAttribute attr : Element.GetAttributes()) 1725 1665 { … … 1801 1741 1802 1742 if (attr_name == "name") 1803 1743 name = attr_value; 1804 else 1805 if (attr_name == "show_edge_buttons") 1744 else if (attr_name == "show_edge_buttons") 1806 1745 { 1807 1746 bool b; 1808 1747 if (!GUI<bool>::ParseString(attr_value.FromUTF8(), b)) … … 1810 1749 else 1811 1750 scrollbar.m_UseEdgeButtons = b; 1812 1751 } 1813 if (attr_name == "width")1752 else if (attr_name == "width") 1814 1753 { 1815 1754 float f; 1816 1755 if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) … … 1818 1757 else 1819 1758 scrollbar.m_Width = f; 1820 1759 } 1821 else 1822 if (attr_name == "minimum_bar_size") 1760 else if (attr_name == "minimum_bar_size") 1823 1761 { 1824 1762 float f; 1825 1763 if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) … … 1827 1765 else 1828 1766 scrollbar.m_MinimumBarSize = f; 1829 1767 } 1830 else 1831 if (attr_name == "maximum_bar_size") 1768 else if (attr_name == "maximum_bar_size") 1832 1769 { 1833 1770 float f; 1834 1771 if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) … … 1836 1773 else 1837 1774 scrollbar.m_MaximumBarSize = f; 1838 1775 } 1839 else 1840 if (attr_name == "sprite_button_top") 1776 else if (attr_name == "sprite_button_top") 1841 1777 scrollbar.m_SpriteButtonTop = attr_value; 1842 else 1843 if (attr_name == "sprite_button_top_pressed") 1778 else if (attr_name == "sprite_button_top_pressed") 1844 1779 scrollbar.m_SpriteButtonTopPressed = attr_value; 1845 else 1846 if (attr_name == "sprite_button_top_disabled") 1780 else if (attr_name == "sprite_button_top_disabled") 1847 1781 scrollbar.m_SpriteButtonTopDisabled = attr_value; 1848 else 1849 if (attr_name == "sprite_button_top_over") 1782 else if (attr_name == "sprite_button_top_over") 1850 1783 scrollbar.m_SpriteButtonTopOver = attr_value; 1851 else 1852 if (attr_name == "sprite_button_bottom") 1784 else if (attr_name == "sprite_button_bottom") 1853 1785 scrollbar.m_SpriteButtonBottom = attr_value; 1854 else 1855 if (attr_name == "sprite_button_bottom_pressed") 1786 else if (attr_name == "sprite_button_bottom_pressed") 1856 1787 scrollbar.m_SpriteButtonBottomPressed = attr_value; 1857 else 1858 if (attr_name == "sprite_button_bottom_disabled") 1788 else if (attr_name == "sprite_button_bottom_disabled") 1859 1789 scrollbar.m_SpriteButtonBottomDisabled = attr_value; 1860 else 1861 if (attr_name == "sprite_button_bottom_over") 1790 else if (attr_name == "sprite_button_bottom_over") 1862 1791 scrollbar.m_SpriteButtonBottomOver = attr_value; 1863 else 1864 if (attr_name == "sprite_back_vertical") 1792 else if (attr_name == "sprite_back_vertical") 1865 1793 scrollbar.m_SpriteBackVertical = attr_value; 1866 else 1867 if (attr_name == "sprite_bar_vertical") 1794 else if (attr_name == "sprite_bar_vertical") 1868 1795 scrollbar.m_SpriteBarVertical = attr_value; 1869 else 1870 if (attr_name == "sprite_bar_vertical_over") 1796 else if (attr_name == "sprite_bar_vertical_over") 1871 1797 scrollbar.m_SpriteBarVerticalOver = attr_value; 1872 else 1873 if (attr_name == "sprite_bar_vertical_pressed") 1798 else if (attr_name == "sprite_bar_vertical_pressed") 1874 1799 scrollbar.m_SpriteBarVerticalPressed = attr_value; 1875 1800 } 1876 1801 … … 1951 1876 1952 1877 XMBAttributeList attributes = Element.GetAttributes(); 1953 1878 1954 //IGUIObject* object = new CTooltip;1955 1879 CColor color; 1956 1880 CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name")); 1957 1881 1958 1882 // Try parsing value 1959 1883 CStr value(Element.GetText()); 1960 if (!value.empty()) 1884 if (value.empty()) 1885 return; 1886 1887 // Try setting color to value 1888 if (!color.ParseString(value)) 1961 1889 { 1962 // Try setting color to value 1963 if (!color.ParseString(value)) 1964 { 1965 LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str()); 1966 } 1967 else 1968 { 1969 // input color 1970 m_PreDefinedColors[name] = color; 1971 } 1890 LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str()); 1891 return; 1972 1892 } 1893 1894 // input color 1895 m_PreDefinedColors[name] = color; 1973 1896 } -
source/gui/CGUI.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 32 32 #ifndef INCLUDED_CGUI 33 33 #define INCLUDED_CGUI 34 34 35 //--------------------------------------------------------36 // Includes / Compiler directives37 //--------------------------------------------------------38 // NOTE: GUI.h included at the bottom of this file (has to be after CGUI class39 // definition)40 41 35 #include "GUITooltip.h" 42 36 #include "GUIbase.h" 43 #include "scriptinterface/ScriptInterface.h"44 45 #include "ps/Shapes.h"46 37 47 38 #include "lib/input.h" 48 39 #include "ps/Shapes.h" 49 40 #include "ps/XML/Xeromyces.h" 41 #include "scriptinterface/ScriptInterface.h" 50 42 51 43 #include <boost/unordered_set.hpp> 52 44 53 //--------------------------------------------------------54 // Macros55 //--------------------------------------------------------56 57 //--------------------------------------------------------58 // Types59 //--------------------------------------------------------60 61 //--------------------------------------------------------62 // Error declarations63 //--------------------------------------------------------64 65 45 ERROR_TYPE(GUI, JSOpenFailed); 66 46 67 //--------------------------------------------------------68 // Declarations69 //--------------------------------------------------------70 71 47 /** 72 48 * Contains a list of values for new defaults to objects. 73 49 */ … … 145 121 * @param Rect Position and Size 146 122 * @param Clipping The sprite shouldn't be drawn outside this rectangle 147 123 */ 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()); 150 125 151 126 /** 152 127 * Draw a SGUIText object … … 157 132 * @param z z value. 158 133 * @param clipping 159 134 */ 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); 162 136 163 137 /** 164 138 * Clean up, call this to clean up all memory allocated … … 252 226 * @param pObject Optional parameter for error output. Used *only* if error parsing fails, 253 227 * and we need to be able to output which object the error occured in to aid the user. 254 228 */ 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); 258 230 259 231 260 232 /** … … 271 243 * Get pre-defined color (if it exists) 272 244 * Returns false if it fails. 273 245 */ 274 bool GetPreDefinedColor(const CStr& name, CColor &Output);246 bool GetPreDefinedColor(const CStr& name, CColor& Output) const; 275 247 276 248 shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; }; 277 249 jsval GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); }; … … 307 279 * @param str Name of object type 308 280 * @return Newly constructed IGUIObject (but constructed as a subclass) 309 281 */ 310 IGUIObject *ConstructObject(const CStr& str);282 IGUIObject* ConstructObject(const CStr& str); 311 283 312 284 /** 313 285 * Get Focused Object. 314 286 */ 315 IGUIObject *GetFocusedObject() { return m_FocusedObject; }287 IGUIObject* GetFocusedObject() { return m_FocusedObject; } 316 288 317 289 public: 318 290 /** … … 444 416 * 445 417 * @see LoadXmlFile() 446 418 */ 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); 448 420 449 421 /** 450 422 * Reads in the element \<repeat\>, which repeats its child \<object\>s … … 452 424 * 'var' enclosed in square brackets) in its descendants' names with "[0]", 453 425 * "[1]", etc. 454 426 */ 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); 456 428 457 429 /** 458 430 * Reads in the element \<script\> (the XMBElement) and executes … … 490 462 * 491 463 * @see LoadXmlFile() 492 464 */ 493 void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent);465 void Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent); 494 466 495 467 /** 496 468 * Reads in the element \<effect\> (the XMBElement) and stores the … … 503 475 * 504 476 * @see LoadXmlFile() 505 477 */ 506 void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects);478 void Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects); 507 479 508 480 /** 509 481 * Reads in the element \<style\> (the XMBElement) and stores the … … 671 643 std::map<CStr, SGUIIcon> m_Icons; 672 644 }; 673 645 674 #endif 646 #endif // INCLUDED_CGUI -
source/gui/CGUIScrollBarVertical.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 IGUIScrollBar20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h" 19 24 20 #include "CGUIScrollBarVertical.h" 21 22 #include "GUI.h" 23 25 24 #include "ps/CLogger.h" 26 25 27 26 … … 33 32 { 34 33 } 35 34 36 void CGUIScrollBarVertical::SetPosFromMousePos(const CPos &mouse)35 void CGUIScrollBarVertical::SetPosFromMousePos(const CPos& mouse) 37 36 { 38 37 if (!GetStyle()) 39 38 return; … … 82 81 else 83 82 button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop); 84 83 } 85 else button_top = &GetStyle()->m_SpriteButtonTop; 84 else 85 button_top = &GetStyle()->m_SpriteButtonTop; 86 86 87 87 // figure out what sprite to use for bottom button 88 88 if (m_ButtonPlusHovered) … … 92 92 else 93 93 button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom); 94 94 } 95 else button_bottom = &GetStyle()->m_SpriteButtonBottom; 95 else 96 button_bottom = &GetStyle()->m_SpriteButtonBottom; 96 97 97 98 // Draw top button 98 99 GetGUI()->DrawSprite(*button_top, … … 123 124 } 124 125 } 125 126 126 void CGUIScrollBarVertical::HandleMessage(SGUIMessage &Message)127 void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message) 127 128 { 128 129 IGUIScrollBar::HandleMessage(Message); 129 130 } … … 167 168 return ret; 168 169 } 169 170 170 bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos &mouse)171 bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos& mouse) 171 172 { 172 173 if (!GetStyle()) 173 174 return false; … … 180 181 mouse.y <= m_Y + GetStyle()->m_Width); 181 182 } 182 183 183 bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos &mouse)184 bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos& mouse) 184 185 { 185 186 if (!GetStyle()) 186 187 return false; -
source/gui/CGUIScrollBarVertical.h
37 37 #ifndef INCLUDED_CGUISCROLLBARVERTICAL 38 38 #define INCLUDED_CGUISCROLLBARVERTICAL 39 39 40 //--------------------------------------------------------41 // Includes / Compiler directives42 //--------------------------------------------------------43 40 #include "IGUIScrollBar.h" 44 41 #include "GUI.h" 45 42 46 //--------------------------------------------------------47 // Declarations48 //--------------------------------------------------------49 50 43 /** 51 44 * Vertical implementation of IGUIScrollBar 52 45 * 53 46 * @see IGUIScrollBar 54 47 */ 55 48 class CGUIScrollBarVertical : public IGUIScrollBar 56 49 { 57 50 public: 58 51 CGUIScrollBarVertical(); … … 71 64 * 72 65 * @see IGUIObject#HandleMessage() 73 66 */ 74 virtual void HandleMessage(SGUIMessage &Message);67 virtual void HandleMessage(SGUIMessage& Message); 75 68 76 69 /** 77 70 * Set m_Pos with g_mouse_x/y input, i.e. when dragging. 78 71 */ 79 virtual void SetPosFromMousePos(const CPos &mouse);72 virtual void SetPosFromMousePos(const CPos& mouse); 80 73 81 74 /** 82 75 * @see IGUIScrollBar#HoveringButtonMinus 83 76 */ 84 virtual bool HoveringButtonMinus(const CPos &mouse);77 virtual bool HoveringButtonMinus(const CPos& mouse); 85 78 86 79 /** 87 80 * @see IGUIScrollBar#HoveringButtonPlus 88 81 */ 89 virtual bool HoveringButtonPlus(const CPos &mouse);82 virtual bool HoveringButtonPlus(const CPos& mouse); 90 83 91 84 /** 92 85 * Set Right Aligned 93 86 * @param align Alignment 94 87 */ 95 void SetRightAligned(const bool &align) { m_RightAligned = align; }88 void SetRightAligned(const bool& align) { m_RightAligned = align; } 96 89 97 90 /** 98 91 * Get the rectangle of the actual BAR. … … 115 108 bool m_RightAligned; 116 109 }; 117 110 118 #endif 111 #endif // INCLUDED_CGUISCROLLBARVERTICAL -
source/gui/CGUISprite.cpp
1 /* Copyright (C) 20 09 Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 16 16 */ 17 17 18 18 #include "precompiled.h" 19 19 20 #include "CGUISprite.h" 20 21 21 22 CGUISprite::~CGUISprite() 22 23 { 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; 27 26 } 28 27 29 28 void CGUISprite::AddImage(SGUIImage* image) … … 31 30 m_Images.push_back(image); 32 31 } 33 32 34 void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*> &Sprites, float Z) const33 void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const 35 34 { 36 35 if (m_CachedSize != Size || m_CachedCellID != CellID) 37 36 { … … 50 49 51 50 bool CGUISpriteInstance::IsEmpty() const 52 51 { 53 return m_SpriteName =="";52 return m_SpriteName.empty(); 54 53 } 55 54 56 55 // Plus a load of constructors / assignment operators, which don't copy the … … 67 66 { 68 67 } 69 68 70 CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance &Sprite)69 CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance& Sprite) 71 70 : m_SpriteName(Sprite.m_SpriteName), m_CachedCellID(-1) 72 71 { 73 72 } 74 73 75 CGUISpriteInstance &CGUISpriteInstance::operator=(const CStr& SpriteName)74 CGUISpriteInstance& CGUISpriteInstance::operator=(const CStr& SpriteName) 76 75 { 77 76 m_SpriteName = SpriteName; 78 77 m_DrawCallCache.clear(); -
source/gui/CGUISprite.h
37 37 #ifndef INCLUDED_CGUISPRITE 38 38 #define INCLUDED_CGUISPRITE 39 39 40 //--------------------------------------------------------41 // Includes / Compiler directives42 //--------------------------------------------------------43 40 #include "GUIbase.h" 44 41 45 42 #include "lib/res/graphics/ogl_tex.h" 46 43 47 //--------------------------------------------------------48 // Macros49 //--------------------------------------------------------50 51 //--------------------------------------------------------52 // Types53 //--------------------------------------------------------54 55 //--------------------------------------------------------56 // Error declarations57 //--------------------------------------------------------58 59 //--------------------------------------------------------60 // Declarations61 //--------------------------------------------------------62 63 64 44 struct SGUIImageEffects 65 45 { 66 46 SGUIImageEffects() : m_Greyscale(false) {} … … 74 54 */ 75 55 struct SGUIImage 76 56 { 57 NONCOPYABLE(SGUIImage); 58 public: 77 59 SGUIImage() : 78 60 m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT), 79 61 m_Effects(NULL), m_Border(false), m_DeltaZ(0.f) … … 138 120 * way of declaring delta-z. 139 121 */ 140 122 float m_DeltaZ; 141 142 NONCOPYABLE(SGUIImage);143 123 }; 144 124 145 125 /** … … 153 133 */ 154 134 class CGUISprite 155 135 { 136 NONCOPYABLE(CGUISprite); 156 137 public: 157 138 CGUISprite() {} 158 139 virtual ~CGUISprite(); … … 166 147 167 148 /// List of images 168 149 std::vector<SGUIImage*> m_Images; 169 170 NONCOPYABLE(CGUISprite);171 150 }; 172 151 173 152 #include "GUIRenderer.h" … … 180 159 public: 181 160 CGUISpriteInstance(); 182 161 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); 185 164 void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const; 186 165 void Invalidate(); 187 166 bool IsEmpty() const; … … 198 177 mutable int m_CachedCellID; 199 178 }; 200 179 201 #endif 180 #endif // INCLUDED_CGUISPRITE -
source/gui/CImage.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CImage20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h" 19 24 20 #include "CImage.h" 25 21 26 #include " lib/ogl.h"22 #include "GUI.h" 27 23 24 #include "lib/ogl.h" 28 25 29 //-------------------------------------------------------------------30 // Constructor / Destructor31 //-------------------------------------------------------------------32 26 CImage::CImage() 33 27 { 34 28 AddSetting(GUIST_CGUISpriteInstance, "sprite"); … … 43 37 44 38 void CImage::Draw() 45 39 { 46 if (GetGUI()) 47 { 48 float bz = GetBufferedZ(); 40 if (!GetGUI()) 41 return; 42 43 float bz = GetBufferedZ(); 49 44 50 CGUISpriteInstance *sprite;51 52 53 45 CGUISpriteInstance* sprite; 46 int cell_id; 47 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 48 GUI<int>::GetSetting(this, "cell_id", cell_id); 54 49 55 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 56 } 50 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 57 51 } -
source/gui/CImage.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Image object20 21 --Overview--22 23 GUI Object for just drawing a sprite.24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_CIMAGE 32 19 #define INCLUDED_CIMAGE 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 //--------------------------------------------------------40 // Macros41 //--------------------------------------------------------42 43 //--------------------------------------------------------44 // Types45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Declarations49 //--------------------------------------------------------50 51 23 /** 52 24 * Object just for drawing a sprite. Like CText, without the 53 25 * possibility to draw text. … … 75 47 virtual void Draw(); 76 48 }; 77 49 78 #endif 50 #endif // INCLUDED_CIMAGE -
source/gui/CInput.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CInput20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h" 19 24 20 #include "CInput.h" 21 25 22 #include "CGUIScrollBarVertical.h" 23 #include "GUI.h" 26 24 27 25 #include "graphics/FontMetrics.h" 28 26 #include "graphics/ShaderManager.h" 29 27 #include "graphics/TextRenderer.h" 30 #include "lib/ogl.h"31 28 #include "lib/external_libraries/libsdl.h" 29 #include "lib/ogl.h" 32 30 #include "lib/sysdep/clipboard.h" 33 31 #include "lib/timer.h" 34 32 #include "lib/utf8.h" … … 42 40 43 41 extern int g_yres; 44 42 45 //-------------------------------------------------------------------46 // Constructor / Destructor47 //-------------------------------------------------------------------48 43 CInput::CInput() 49 44 : m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f), 50 45 m_PrevTime(0.0), m_CursorVisState(true), m_CursorBlinkRate(0.5), m_ComposingText(false), … … 71 66 CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); 72 67 73 68 // Add scroll-bar 74 CGUIScrollBarVertical 69 CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(); 75 70 bar->SetRightAligned(true); 76 71 AddScrollBar(bar); 77 72 } … … 88 83 89 84 void CInput::ClearComposedText() 90 85 { 91 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;86 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 92 87 pCaption->erase(m_iInsertPos, m_iComposedLength); 93 88 m_iBufferPos = m_iInsertPos; 94 89 UpdateBufferPositionSetting(); … … 210 205 211 206 switch (szChar) 212 207 { 213 case SDLK_TAB: // '\t' 214 /* Auto Complete */ 215 // We just send the tab event to JS and let it figure out autocomplete. 216 SendEvent(GUIM_TAB, "tab"); 217 break; 218 219 case SDLK_BACKSPACE: // '\b' 220 m_WantedX=0.0f; 221 222 if (SelectingText()) 223 DeleteCurSelection(); 224 else 225 { 226 m_iBufferPos_Tail = -1; 227 228 if (pCaption->empty() || m_iBufferPos == 0) 229 { 230 break; 231 } 232 else 233 { 234 if (m_iBufferPos == (int)pCaption->length()) 235 *pCaption = pCaption->Left( (long) pCaption->length()-1); 236 else 237 *pCaption = pCaption->Left( m_iBufferPos-1 ) + 238 pCaption->Right( (long) pCaption->length()-m_iBufferPos ); 239 240 --m_iBufferPos; 208 case SDLK_TAB: // '\t' 209 /* Auto Complete */ 210 // We just send the tab event to JS and let it figure out autocomplete. 211 SendEvent(GUIM_TAB, "tab"); 212 break; 241 213 242 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 243 } 244 } 214 case SDLK_BACKSPACE: // '\b' 215 m_WantedX=0.0f; 245 216 246 UpdateAutoScroll(); 247 break; 217 if (SelectingText()) 218 DeleteCurSelection(); 219 else 220 { 221 m_iBufferPos_Tail = -1; 248 222 249 case SDLK_DELETE: 250 m_WantedX=0.0f; 251 // If selection: 252 if (SelectingText()) 223 if (pCaption->empty() || m_iBufferPos == 0) 253 224 { 254 DeleteCurSelection();225 break; 255 226 } 256 227 else 257 228 { 258 if (pCaption->empty() || m_iBufferPos == (int)pCaption->length()) 259 { 260 break; 261 } 229 if (m_iBufferPos == (int)pCaption->length()) 230 *pCaption = pCaption->Left((long)pCaption->length()-1); 262 231 else 263 { 264 *pCaption = pCaption->Left( m_iBufferPos ) + 265 pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) ); 266 267 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 268 } 269 } 232 *pCaption = pCaption->Left(m_iBufferPos-1) + 233 pCaption->Right((long)pCaption->length()-m_iBufferPos); 270 234 271 UpdateAutoScroll(); 272 break; 235 --m_iBufferPos; 273 236 274 case SDLK_HOME: 275 // If there's not a selection, we should create one now 276 if (!shiftKeyPressed) 277 { 278 // Make sure a selection isn't created. 279 m_iBufferPos_Tail = -1; 280 } 281 else if (!SelectingText()) 282 { 283 // Place tail at the current point: 284 m_iBufferPos_Tail = m_iBufferPos; 237 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 285 238 } 239 } 286 240 287 m_iBufferPos = 0; 288 m_WantedX=0.0f; 289 290 UpdateAutoScroll(); 291 break; 241 UpdateAutoScroll(); 242 break; 292 243 293 case SDLK_END: 294 // If there's not a selection, we should create one now 295 if (!shiftKeyPressed) 244 case SDLK_DELETE: 245 m_WantedX=0.0f; 246 // If selection: 247 if (SelectingText()) 248 { 249 DeleteCurSelection(); 250 } 251 else 252 { 253 if (pCaption->empty() || m_iBufferPos == (int)pCaption->length()) 296 254 { 297 // Make sure a selection isn't created. 298 m_iBufferPos_Tail = -1; 255 break; 299 256 } 300 else if (!SelectingText())257 else 301 258 { 302 // Place tail at the current point: 303 m_iBufferPos_Tail = m_iBufferPos; 259 *pCaption = pCaption->Left(m_iBufferPos) + 260 pCaption->Right((long)pCaption->length()-(m_iBufferPos+1)); 261 262 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 304 263 } 264 } 305 265 306 m_iBufferPos = (long) pCaption->length();307 m_WantedX=0.0f;266 UpdateAutoScroll(); 267 break; 308 268 309 UpdateAutoScroll(); 310 break; 269 case SDLK_HOME: 270 // If there's not a selection, we should create one now 271 if (!shiftKeyPressed) 272 { 273 // Make sure a selection isn't created. 274 m_iBufferPos_Tail = -1; 275 } 276 else if (!SelectingText()) 277 { 278 // Place tail at the current point: 279 m_iBufferPos_Tail = m_iBufferPos; 280 } 311 281 312 /**313 Conventions for Left/Right when text is selected:282 m_iBufferPos = 0; 283 m_WantedX=0.0f; 314 284 315 References: 285 UpdateAutoScroll(); 286 break; 316 287 317 Visual Studio 318 Visual Studio has the 'newer' approach, used by newer versions of 319 things, and in newer applications. A left press will always place 320 the pointer on the left edge of the selection, and then of course 321 remove the selection. Right will do the exakt same thing. 322 If you have the pointer on the right edge and press right, it will 323 in other words just remove the selection. 288 case SDLK_END: 289 // If there's not a selection, we should create one now 290 if (!shiftKeyPressed) 291 { 292 // Make sure a selection isn't created. 293 m_iBufferPos_Tail = -1; 294 } 295 else if (!SelectingText()) 296 { 297 // Place tail at the current point: 298 m_iBufferPos_Tail = m_iBufferPos; 299 } 324 300 325 Windows (eg. Notepad) 326 A left press always takes the pointer a step to the left and 327 removes the selection as if it were never there in the first place. 328 Right of course does the same thing but to the right. 301 m_iBufferPos = (long) pCaption->length(); 302 m_WantedX=0.0f; 329 303 330 I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN331 Messenger.304 UpdateAutoScroll(); 305 break; 332 306 333 **/ 334 case SDLK_LEFT: 335 m_WantedX=0.f; 307 /** 308 Conventions for Left/Right when text is selected: 336 309 337 if (shiftKeyPressed || !SelectingText()) 338 { 339 if (!shiftKeyPressed) 340 { 341 m_iBufferPos_Tail = -1; 342 } 343 else if (!SelectingText()) 344 { 345 m_iBufferPos_Tail = m_iBufferPos; 346 } 310 References: 347 311 348 if (m_iBufferPos > 0)349 --m_iBufferPos;350 }351 else352 {353 if (m_iBufferPos_Tail < m_iBufferPos)354 m_iBufferPos = m_iBufferPos_Tail;312 Visual Studio 313 Visual Studio has the 'newer' approach, used by newer versions of 314 things, and in newer applications. A left press will always place 315 the pointer on the left edge of the selection, and then of course 316 remove the selection. Right will do the exakt same thing. 317 If you have the pointer on the right edge and press right, it will 318 in other words just remove the selection. 355 319 356 m_iBufferPos_Tail = -1; 357 } 320 Windows (eg. Notepad) 321 A left press always takes the pointer a step to the left and 322 removes the selection as if it were never there in the first place. 323 Right of course does the same thing but to the right. 358 324 359 UpdateAutoScroll();360 break;325 I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN 326 Messenger. 361 327 362 case SDLK_RIGHT: 363 m_WantedX=0.0f; 328 **/ 329 case SDLK_LEFT: 330 m_WantedX=0.f; 364 331 365 if (shiftKeyPressed || !SelectingText()) 332 if (shiftKeyPressed || !SelectingText()) 333 { 334 if (!shiftKeyPressed) 366 335 { 367 if (!shiftKeyPressed) 368 { 369 m_iBufferPos_Tail = -1; 370 } 371 else if (!SelectingText()) 372 { 373 m_iBufferPos_Tail = m_iBufferPos; 374 } 375 376 if (m_iBufferPos < (int)pCaption->length()) 377 ++m_iBufferPos; 336 m_iBufferPos_Tail = -1; 378 337 } 379 else 338 else if (!SelectingText()) 380 339 { 381 if (m_iBufferPos_Tail > m_iBufferPos) 382 m_iBufferPos = m_iBufferPos_Tail; 383 384 m_iBufferPos_Tail = -1; 340 m_iBufferPos_Tail = m_iBufferPos; 385 341 } 386 342 387 UpdateAutoScroll();388 break;389 390 /**391 Conventions for Up/Down when text is selected:392 393 References:343 if (m_iBufferPos > 0) 344 --m_iBufferPos; 345 } 346 else 347 { 348 if (m_iBufferPos_Tail < m_iBufferPos) 349 m_iBufferPos = m_iBufferPos_Tail; 394 350 395 Visual Studio 396 Visual Studio has a very strange approach, down takes you below the 397 selection to the next row, and up to the one prior to the whole 398 selection. The weird part is that it is always aligned as the 399 'pointer'. I decided this is to much work for something that is 400 a bit arbitrary 351 m_iBufferPos_Tail = -1; 352 } 401 353 402 Windows (eg. Notepad) 403 Just like with left/right, the selection is destroyed and it moves 404 just as if there never were a selection. 354 UpdateAutoScroll(); 355 break; 405 356 406 I chose the Notepad convention even though I use the VS convention with407 left/right.357 case SDLK_RIGHT: 358 m_WantedX=0.0f; 408 359 409 **/ 410 case SDLK_UP: 360 if (shiftKeyPressed || !SelectingText()) 411 361 { 412 362 if (!shiftKeyPressed) 413 363 { … … 418 368 m_iBufferPos_Tail = m_iBufferPos; 419 369 } 420 370 421 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 422 while (current != m_CharacterPositions.end()) 423 { 424 if (m_iBufferPos >= current->m_ListStart && 425 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 426 break; 371 if (m_iBufferPos < (int)pCaption->length()) 372 ++m_iBufferPos; 373 } 374 else 375 { 376 if (m_iBufferPos_Tail > m_iBufferPos) 377 m_iBufferPos = m_iBufferPos_Tail; 427 378 428 ++current; 429 } 379 m_iBufferPos_Tail = -1; 380 } 381 382 UpdateAutoScroll(); 383 break; 430 384 431 float pos_x; 385 /** 386 Conventions for Up/Down when text is selected: 432 387 433 if (m_iBufferPos-current->m_ListStart == 0) 434 pos_x = 0.f; 435 else 436 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 388 References: 437 389 438 if (m_WantedX > pos_x) 439 pos_x = m_WantedX; 390 Visual Studio 391 Visual Studio has a very strange approach, down takes you below the 392 selection to the next row, and up to the one prior to the whole 393 selection. The weird part is that it is always aligned as the 394 'pointer'. I decided this is to much work for something that is 395 a bit arbitrary 440 396 441 // Now change row: 442 if (current != m_CharacterPositions.begin()) 443 { 444 --current; 397 Windows (eg. Notepad) 398 Just like with left/right, the selection is destroyed and it moves 399 just as if there never were a selection. 445 400 446 // Find X-position: 447 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 448 } 449 // else we can't move up 401 I chose the Notepad convention even though I use the VS convention with 402 left/right. 450 403 451 UpdateAutoScroll(); 404 **/ 405 case SDLK_UP: 406 { 407 if (!shiftKeyPressed) 408 { 409 m_iBufferPos_Tail = -1; 410 } 411 else if (!SelectingText()) 412 { 413 m_iBufferPos_Tail = m_iBufferPos; 452 414 } 453 break;454 415 455 case SDLK_DOWN: 416 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 417 while (current != m_CharacterPositions.end()) 456 418 { 457 if (!shiftKeyPressed) 458 { 459 m_iBufferPos_Tail = -1; 460 } 461 else if (!SelectingText()) 462 { 463 m_iBufferPos_Tail = m_iBufferPos; 464 } 419 if (m_iBufferPos >= current->m_ListStart && 420 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 421 break; 465 422 466 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 467 while (current != m_CharacterPositions.end()) 468 { 469 if (m_iBufferPos >= current->m_ListStart && 470 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 471 break; 423 ++current; 424 } 472 425 473 ++current; 474 } 426 float pos_x; 427 428 if (m_iBufferPos-current->m_ListStart == 0) 429 pos_x = 0.f; 430 else 431 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 475 432 476 float pos_x; 433 if (m_WantedX > pos_x) 434 pos_x = m_WantedX; 477 435 478 if (m_iBufferPos-current->m_ListStart == 0) 479 pos_x = 0.f; 480 else 481 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 436 // Now change row: 437 if (current != m_CharacterPositions.begin()) 438 { 439 --current; 440 441 // Find X-position: 442 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 443 } 444 // else we can't move up 482 445 483 if (m_WantedX > pos_x) 484 pos_x = m_WantedX; 446 UpdateAutoScroll(); 447 break; 448 } 449 450 case SDLK_DOWN: 451 { 452 if (!shiftKeyPressed) 453 { 454 m_iBufferPos_Tail = -1; 455 } 456 else if (!SelectingText()) 457 { 458 m_iBufferPos_Tail = m_iBufferPos; 459 } 460 461 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 462 while (current != m_CharacterPositions.end()) 463 { 464 if (m_iBufferPos >= current->m_ListStart && 465 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 466 break; 485 467 486 // Now change row:487 // Add first, so we can check if it's .end()488 468 ++current; 489 if (current != m_CharacterPositions.end()) 490 { 491 // Find X-position: 492 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 493 } 494 // else we can't move up 469 } 470 471 float pos_x; 472 473 if (m_iBufferPos-current->m_ListStart == 0) 474 pos_x = 0.f; 475 else 476 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 495 477 496 UpdateAutoScroll(); 478 if (m_WantedX > pos_x) 479 pos_x = m_WantedX; 480 481 // Now change row: 482 // Add first, so we can check if it's .end() 483 ++current; 484 if (current != m_CharacterPositions.end()) 485 { 486 // Find X-position: 487 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 497 488 } 498 break;489 // else we can't move up 499 490 500 case SDLK_PAGEUP:501 GetScrollBar(0).ScrollMinusPlenty();502 break;491 UpdateAutoScroll(); 492 break; 493 } 503 494 504 case SDLK_PAGEDOWN: 505 GetScrollBar(0).ScrollPlusPlenty(); 506 break; 507 /* END: Message History Lookup */ 495 case SDLK_PAGEUP: 496 GetScrollBar(0).ScrollMinusPlenty(); 497 break; 508 498 509 case SDLK_KP_ENTER: 510 case SDLK_RETURN: 511 // 'Return' should do a Press event for single liners (e.g. submitting forms) 512 // otherwise a '\n' character will be added. 513 { 514 bool multiline; 515 GUI<bool>::GetSetting(this, "multiline", multiline); 516 if (!multiline) 517 { 518 SendEvent(GUIM_PRESSED, "press"); 519 break; 520 } 499 case SDLK_PAGEDOWN: 500 GetScrollBar(0).ScrollPlusPlenty(); 501 break; 502 /* END: Message History Lookup */ 521 503 522 cooked = '\n'; // Change to '\n' and do default: 523 // NOTE: Fall-through 524 } 525 default: //Insert a character 526 { 504 case SDLK_KP_ENTER: 505 case SDLK_RETURN: 506 // 'Return' should do a Press event for single liners (e.g. submitting forms) 507 // otherwise a '\n' character will be added. 508 { 509 bool multiline; 510 GUI<bool>::GetSetting(this, "multiline", multiline); 511 if (!multiline) 512 { 513 SendEvent(GUIM_PRESSED, "press"); 514 break; 515 } 516 517 cooked = '\n'; // Change to '\n' and do default: 518 // NOTE: Fall-through 519 } 520 default: //Insert a character 521 { 527 522 #if !SDL_VERSION_ATLEAST(2, 0, 0) 528 529 523 if (cooked == 0) 524 return IN_PASS; // Important, because we didn't use any key 530 525 #else // SDL2 531 532 533 534 526 // In SDL2, we no longer get Unicode wchars via SDL_Keysym 527 // we use text input events instead and they provide UTF-8 chars 528 if (ev->ev.type == SDL_KEYDOWN && cooked == 0) 529 return IN_HANDLED; 535 530 #endif 536 531 537 538 539 540 541 532 // check max length 533 int max_length; 534 GUI<int>::GetSetting(this, "max_length", max_length); 535 if (max_length != 0 && (int)pCaption->length() >= max_length) 536 break; 542 537 543 538 m_WantedX=0.0f; 544 539 545 546 547 540 if (SelectingText()) 541 DeleteCurSelection(); 542 m_iBufferPos_Tail = -1; 548 543 549 550 551 552 553 544 if (m_iBufferPos == (int)pCaption->length()) 545 *pCaption += cooked; 546 else 547 *pCaption = pCaption->Left(m_iBufferPos) + cooked + 548 pCaption->Right((long) pCaption->length()-m_iBufferPos); 554 549 555 550 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); 556 551 557 552 ++m_iBufferPos; 558 553 559 560 }561 break;554 UpdateAutoScroll(); 555 break; 556 } 562 557 } 563 558 564 559 UpdateBufferPositionSetting(); … … 571 566 572 567 InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) 573 568 { 574 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;569 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 575 570 bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT]; 576 571 577 572 std::string hotkey = static_cast<const char*>(ev->ev.user.data1); … … 583 578 if (text) 584 579 { 585 580 if (SelectingText()) 586 {587 581 DeleteCurSelection(); 588 }589 582 590 583 if (m_iBufferPos == (int)pCaption->length()) 591 584 *pCaption += text; … … 646 639 if (!pCaption->empty() && m_iBufferPos != 0) 647 640 { 648 641 m_iBufferPos_Tail = m_iBufferPos; 649 CStrW searchString = pCaption->Left( m_iBufferPos);642 CStrW searchString = pCaption->Left(m_iBufferPos); 650 643 651 644 // If we are starting in whitespace, adjust position until we get a non whitespace 652 645 while (m_iBufferPos > 0) … … 703 696 if (!iswspace((*pCaption)[m_iBufferPos])) 704 697 break; 705 698 706 m_iBufferPos++;699 ++m_iBufferPos; 707 700 } 708 701 UpdateBufferPositionSetting(); 709 702 DeleteCurSelection(); … … 727 720 728 721 if (!pCaption->empty() && m_iBufferPos != 0) 729 722 { 730 CStrW searchString = pCaption->Left( m_iBufferPos);723 CStrW searchString = pCaption->Left(m_iBufferPos); 731 724 732 725 // If we are starting in whitespace, adjust position until we get a non whitespace 733 726 while (m_iBufferPos > 0) … … 799 792 if (!iswspace((*pCaption)[m_iBufferPos])) 800 793 break; 801 794 802 m_iBufferPos++;795 ++m_iBufferPos; 803 796 } 804 797 } 805 798 } … … 823 816 } 824 817 825 818 826 void CInput::HandleMessage(SGUIMessage &Message)819 void CInput::HandleMessage(SGUIMessage& Message) 827 820 { 828 // TODO Gee:829 821 IGUIScrollBarOwner::HandleMessage(Message); 830 822 831 823 switch (Message.type) 832 824 { 833 825 case GUIM_SETTINGS_UPDATED: 834 826 { 835 827 bool scrollbar; 836 828 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 837 829 … … 886 878 887 879 UpdateText(); 888 880 } 889 890 }break;881 break; 882 } 891 883 892 884 case GUIM_MOUSE_PRESS_LEFT: 893 885 // Check if we're selecting the scrollbar: 894 886 { 895 887 bool scrollbar, multiline; 896 888 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 897 889 GUI<bool>::GetSetting(this, "multiline", multiline); … … 921 913 922 914 // If we immediately release the button it will just be seen as a click 923 915 // for the user though. 924 925 }break;916 break; 917 } 926 918 927 919 case GUIM_MOUSE_DBLCLICK_LEFT: 928 929 930 920 { 921 if (m_ComposingText) 922 break; 931 923 932 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;924 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 933 925 934 if (pCaption->length() == 0)935 926 if (pCaption->empty()) 927 break; 936 928 937 929 m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition(); 938 930 939 940 931 if (m_iBufferPos >= (int)pCaption->length()) 932 m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1; 941 933 942 // See if we are clicking over whitespace 943 if (iswspace((*pCaption)[m_iBufferPos])) 934 // See if we are clicking over whitespace 935 if (iswspace((*pCaption)[m_iBufferPos])) 936 { 937 // see if we are in a section of whitespace greater than one character 938 if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) || 939 (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1]))) 944 940 { 945 // see if we are in a section of whitespace greater than one character 946 if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) || 947 (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1]))) 941 // 942 // We are clicking in an area with more than one whitespace character 943 // so we select both the word to the left and then the word to the right 944 // 945 // [1] First the left 946 // skip the whitespace 947 while (m_iBufferPos > 0) 948 948 { 949 // 950 // We are clicking in an area with more than one whitespace character 951 // so we select both the word to the left and then the word to the right 952 // 953 // [1] First the left 954 // skip the whitespace 955 while (m_iBufferPos > 0) 956 { 957 if (!iswspace((*pCaption)[m_iBufferPos - 1])) 958 break; 959 960 m_iBufferPos--; 961 } 962 // now go until we hit white space or punctuation 963 while (m_iBufferPos > 0) 964 { 965 if (iswspace((*pCaption)[m_iBufferPos - 1])) 966 break; 967 968 m_iBufferPos--; 949 if (!iswspace((*pCaption)[m_iBufferPos - 1])) 950 break; 969 951 970 if (iswpunct((*pCaption)[m_iBufferPos])) 971 break; 972 } 952 m_iBufferPos--; 953 } 954 // now go until we hit white space or punctuation 955 while (m_iBufferPos > 0) 956 { 957 if (iswspace((*pCaption)[m_iBufferPos - 1])) 958 break; 973 959 974 // [2] Then the right 975 // go right until we are not in whitespace 976 while (++m_iBufferPos_Tail < (int)pCaption->length()) 977 { 978 if (!iswspace((*pCaption)[m_iBufferPos_Tail])) 979 break; 980 } 960 m_iBufferPos--; 981 961 982 if ( m_iBufferPos_Tail == (int)pCaption->length())962 if (iswpunct((*pCaption)[m_iBufferPos])) 983 963 break; 984 985 // now go to the right until we hit whitespace or punctuation986 while (++m_iBufferPos_Tail < (int)pCaption->length())987 {988 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail]))989 break;990 }991 964 } 992 else993 {994 // single whitespace so select word to the right995 while (++m_iBufferPos_Tail < (int)pCaption->length())996 {997 if (!iswspace((*pCaption)[m_iBufferPos_Tail]))998 break;999 }1000 965 1001 if (m_iBufferPos_Tail == (int)pCaption->length()) 966 // [2] Then the right 967 // go right until we are not in whitespace 968 while (++m_iBufferPos_Tail < (int)pCaption->length()) 969 { 970 if (!iswspace((*pCaption)[m_iBufferPos_Tail])) 1002 971 break; 972 } 1003 973 1004 // Don't include the leading whitespace1005 m_iBufferPos = m_iBufferPos_Tail;974 if (m_iBufferPos_Tail == (int)pCaption->length()) 975 break; 1006 976 1007 // now go to the right until we hit whitespace or punctuation 1008 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1009 { 1010 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) 1011 break; 1012 } 977 // now go to the right until we hit whitespace or punctuation 978 while (++m_iBufferPos_Tail < (int)pCaption->length()) 979 { 980 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) 981 break; 1013 982 } 1014 983 } 1015 984 else 1016 985 { 1017 // clicked on non-whitespace so select current word 1018 // go until we hit white space or punctuation 1019 while (m_iBufferPos > 0) 986 // single whitespace so select word to the right 987 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1020 988 { 1021 if ( iswspace((*pCaption)[m_iBufferPos - 1]))989 if (!iswspace((*pCaption)[m_iBufferPos_Tail])) 1022 990 break; 991 } 1023 992 1024 m_iBufferPos--; 993 if (m_iBufferPos_Tail == (int)pCaption->length()) 994 break; 1025 995 1026 if (iswpunct((*pCaption)[m_iBufferPos]))1027 break;1028 } 1029 // go to the right until we hit whitespace or punctuation996 // Don't include the leading whitespace 997 m_iBufferPos = m_iBufferPos_Tail; 998 999 // now go to the right until we hit whitespace or punctuation 1030 1000 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1031 1001 { 1032 1002 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) … … 1034 1004 } 1035 1005 } 1036 1006 } 1007 else 1008 { 1009 // clicked on non-whitespace so select current word 1010 // go until we hit white space or punctuation 1011 while (m_iBufferPos > 0) 1012 { 1013 if (iswspace((*pCaption)[m_iBufferPos - 1])) 1014 break; 1015 1016 m_iBufferPos--; 1017 1018 if (iswpunct((*pCaption)[m_iBufferPos])) 1019 break; 1020 } 1021 // go to the right until we hit whitespace or punctuation 1022 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1023 { 1024 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) 1025 break; 1026 } 1027 } 1037 1028 break; 1029 } 1038 1030 1039 1031 case GUIM_MOUSE_RELEASE_LEFT: 1040 1032 if (m_SelectingText) 1041 {1042 1033 m_SelectingText = false; 1043 }1044 1034 break; 1045 1035 1046 1036 case GUIM_MOUSE_MOTION: … … 1059 1049 break; 1060 1050 1061 1051 case GUIM_LOAD: 1062 1063 GetScrollBar(0).SetX( m_CachedActualSize.right);1064 GetScrollBar(0).SetY( m_CachedActualSize.top);1065 GetScrollBar(0).SetZ( GetBufferedZ());1066 GetScrollBar(0).SetLength( m_CachedActualSize.bottom - m_CachedActualSize.top);1052 { 1053 GetScrollBar(0).SetX(m_CachedActualSize.right); 1054 GetScrollBar(0).SetY(m_CachedActualSize.top); 1055 GetScrollBar(0).SetZ(GetBufferedZ()); 1056 GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); 1067 1057 1068 1058 CStr scrollbar_style; 1069 1059 GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); 1070 GetScrollBar(0).SetScrollBarStyle( scrollbar_style);1060 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 1071 1061 1072 1062 UpdateText(); 1073 }1074 1063 break; 1064 } 1075 1065 1076 1066 case GUIM_GOT_FOCUS: 1077 1067 m_iBufferPos = 0; … … 1164 1154 GUI<bool>::GetSetting(this, "mask", mask); 1165 1155 1166 1156 if (scrollbar && multiline) 1167 {1168 // Draw scrollbar1169 1157 IGUIScrollBarOwner::Draw(); 1158 1159 if (!GetGUI()) 1160 return; 1161 1162 CStrW font_name_w; 1163 CColor color, color_selected; 1164 //CStrW caption; 1165 GUI<CStrW>::GetSetting(this, "font", font_name_w); 1166 GUI<CColor>::GetSetting(this, "textcolor", color); 1167 GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected); 1168 CStrIntern font_name(font_name_w.ToUTF8()); 1169 1170 // Get pointer of caption, it might be very large, and we don't 1171 // want to copy it continuously. 1172 CStrW* pCaption = NULL; 1173 wchar_t mask_char = L'*'; 1174 if (mask) 1175 { 1176 CStrW maskStr; 1177 GUI<CStrW>::GetSetting(this, "mask_char", maskStr); 1178 if (maskStr.length() > 0) 1179 mask_char = maskStr[0]; 1170 1180 } 1181 else 1182 pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 1183 1184 CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL; 1185 int cell_id; 1186 1187 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 1188 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea); 1189 1190 GUI<int>::GetSetting(this, "cell_id", cell_id); 1191 1192 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 1193 1194 float scroll=0.f; 1195 if (scrollbar && multiline) 1196 scroll = GetScrollBar(0).GetPos(); 1197 1198 CFontMetrics font(font_name); 1199 1200 // We'll have to setup clipping manually, since we're doing the rendering manually. 1201 CRect cliparea(m_CachedActualSize); 1171 1202 1172 if (GetGUI()) 1203 // First we'll figure out the clipping area, which is the cached actual size 1204 // substracted by an optional scrollbar 1205 if (scrollbar) 1173 1206 { 1174 CStrW font_name_w; 1175 CColor color, color_selected; 1176 //CStrW caption; 1177 GUI<CStrW>::GetSetting(this, "font", font_name_w); 1178 GUI<CColor>::GetSetting(this, "textcolor", color); 1179 GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected); 1180 CStrIntern font_name(font_name_w.ToUTF8()); 1207 scroll = GetScrollBar(0).GetPos(); 1181 1208 1182 // Get pointer of caption, it might be very large, and we don't 1183 // want to copy it continuously. 1184 CStrW *pCaption = NULL; 1185 wchar_t mask_char = L'*'; 1186 if (mask) 1187 { 1188 CStrW maskStr; 1189 GUI<CStrW>::GetSetting(this, "mask_char", maskStr); 1190 if (maskStr.length() > 0) 1191 mask_char = maskStr[0]; 1192 } 1193 else 1194 pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 1209 // substract scrollbar from cliparea 1210 if (cliparea.right > GetScrollBar(0).GetOuterRect().left && 1211 cliparea.right <= GetScrollBar(0).GetOuterRect().right) 1212 cliparea.right = GetScrollBar(0).GetOuterRect().left; 1195 1213 1196 CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL; 1197 int cell_id; 1214 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && 1215 cliparea.left < GetScrollBar(0).GetOuterRect().right) 1216 cliparea.left = GetScrollBar(0).GetOuterRect().right; 1217 } 1218 1219 if (cliparea != CRect()) 1220 { 1221 glEnable(GL_SCISSOR_TEST); 1222 glScissor( 1223 cliparea.left / g_GuiScale, 1224 g_yres - cliparea.bottom / g_GuiScale, 1225 cliparea.GetWidth() / g_GuiScale, 1226 cliparea.GetHeight() / g_GuiScale); 1227 } 1228 1229 // These are useful later. 1230 int VirtualFrom, VirtualTo; 1231 1232 if (m_iBufferPos_Tail >= m_iBufferPos) 1233 { 1234 VirtualFrom = m_iBufferPos; 1235 VirtualTo = m_iBufferPos_Tail; 1236 } 1237 else 1238 { 1239 VirtualFrom = m_iBufferPos_Tail; 1240 VirtualTo = m_iBufferPos; 1241 } 1198 1242 1199 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 1200 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea); 1243 // Get the height of this font. 1244 float h = (float)font.GetHeight(); 1245 float ls = (float)font.GetLineSpacing(); 1201 1246 1202 GUI<int>::GetSetting(this, "cell_id", cell_id);1247 CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); 1203 1248 1204 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 1249 CTextRenderer textRenderer(tech->GetShader()); 1250 textRenderer.Font(font_name); 1205 1251 1206 float scroll=0.f; 1207 if (scrollbar && multiline) 1208 { 1209 scroll = GetScrollBar(0).GetPos(); 1210 } 1252 // Set the Z to somewhat more, so we can draw a selected area between the 1253 // the control and the text. 1254 textRenderer.Translate( 1255 (float)(int)(m_CachedActualSize.left) + buffer_zone, 1256 (float)(int)(m_CachedActualSize.top+h) + buffer_zone, 1257 bz+0.1f); 1211 1258 1212 CFontMetrics font(font_name); 1259 // U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE 1260 // (sort of like a | which is aligned to the left of most characters) 1213 1261 1214 // We'll have to setup clipping manually, since we're doing the rendering manually. 1215 CRect cliparea(m_CachedActualSize); 1262 float buffered_y = -scroll+buffer_zone; 1216 1263 1217 // First we'll figure out the clipping area, which is the cached actual size 1218 // substracted by an optional scrollbar 1219 if (scrollbar) 1220 { 1221 scroll = GetScrollBar(0).GetPos(); 1264 // When selecting larger areas, we need to draw a rectangle box 1265 // around it, and this is to keep track of where the box 1266 // started, because we need to follow the iteration until we 1267 // reach the end, before we can actually draw it. 1268 bool drawing_box = false; 1269 float box_x=0.f; 1222 1270 1223 // substract scrollbar from cliparea 1224 if (cliparea.right > GetScrollBar(0).GetOuterRect().left && 1225 cliparea.right <= GetScrollBar(0).GetOuterRect().right) 1226 cliparea.right = GetScrollBar(0).GetOuterRect().left; 1271 float x_pointer=0.f; 1227 1272 1228 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && 1229 cliparea.left < GetScrollBar(0).GetOuterRect().right) 1230 cliparea.left = GetScrollBar(0).GetOuterRect().right; 1231 } 1273 // If we have a selecting box (i.e. when you have selected letters, not just when 1274 // the pointer is between two letters) we need to process all letters once 1275 // before we do it the second time and render all the text. We can't do it 1276 // in the same loop because text will have been drawn, so it will disappear when 1277 // drawn behind the text that has already been drawn. Confusing, well it's necessary 1278 // (I think). 1232 1279 1233 if (cliparea != CRect()) 1234 { 1235 glEnable(GL_SCISSOR_TEST); 1236 glScissor( 1237 cliparea.left / g_GuiScale, 1238 g_yres - cliparea.bottom / g_GuiScale, 1239 cliparea.GetWidth() / g_GuiScale, 1240 cliparea.GetHeight() / g_GuiScale); 1241 } 1280 if (SelectingText()) 1281 { 1282 // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos, 1283 // just like you can select from right to left, as you can 1284 // left to right. Is there a difference? Yes, the pointer 1285 // be placed accordingly, so that if you select shift and 1286 // expand this selection, it will expand on appropriate side. 1287 // Anyway, since the drawing procedure needs "To" to be 1288 // greater than from, we need virtual values that might switch 1289 // place. 1242 1290 1243 // These are useful later.1244 1291 int VirtualFrom, VirtualTo; 1245 1292 1246 1293 if (m_iBufferPos_Tail >= m_iBufferPos) … … 1254 1301 VirtualTo = m_iBufferPos; 1255 1302 } 1256 1303 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 the1267 // 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 LINE1274 // (sort of like a | which is aligned to the left of most characters)1275 1276 float buffered_y = -scroll+buffer_zone;1277 1278 // When selecting larger areas, we need to draw a rectangle box1279 // around it, and this is to keep track of where the box1280 // started, because we need to follow the iteration until we1281 // 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 1304 1287 // If we have a selecting box (i.e. when you have selected letters, not just when 1288 // the pointer is between two letters) we need to process all letters once 1289 // before we do it the second time and render all the text. We can't do it 1290 // in the same loop because text will have been drawn, so it will disappear when 1291 // drawn behind the text that has already been drawn. Confusing, well it's necessary 1292 // (I think). 1293 1294 if (SelectingText()) 1305 bool done = false; 1306 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1307 it != m_CharacterPositions.end(); 1308 ++it, buffered_y += ls, x_pointer = 0.f) 1295 1309 { 1296 // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos, 1297 // just like you can select from right to left, as you can 1298 // left to right. Is there a difference? Yes, the pointer 1299 // be placed accordingly, so that if you select shift and 1300 // expand this selection, it will expand on appropriate side. 1301 // Anyway, since the drawing procedure needs "To" to be 1302 // greater than from, we need virtual values that might switch 1303 // place. 1304 1305 int VirtualFrom, VirtualTo; 1306 1307 if (m_iBufferPos_Tail >= m_iBufferPos) 1310 if (multiline) 1308 1311 { 1309 VirtualFrom = m_iBufferPos; 1310 VirtualTo = m_iBufferPos_Tail; 1311 } 1312 else 1313 { 1314 VirtualFrom = m_iBufferPos_Tail; 1315 VirtualTo = m_iBufferPos; 1312 if (buffered_y > m_CachedActualSize.GetHeight()) 1313 break; 1316 1314 } 1317 1315 1318 1319 bool done = false; 1320 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1321 it != m_CharacterPositions.end(); 1322 ++it, buffered_y += ls, x_pointer = 0.f) 1316 // We might as well use 'i' here to iterate, because we need it 1317 // (often compared against ints, so don't make it size_t) 1318 for (int i=0; i < (int)it->m_ListOfX.size()+2; ++i) 1323 1319 { 1324 if ( multiline)1320 if (it->m_ListStart + i == VirtualFrom) 1325 1321 { 1326 if (buffered_y > m_CachedActualSize.GetHeight()) 1327 break; 1322 // we won't actually draw it now, because we don't 1323 // know the width of each glyph to that position. 1324 // we need to go along with the iteration, and 1325 // make a mark where the box started: 1326 drawing_box = true; // will turn false when finally rendered. 1327 1328 // Get current x position 1329 box_x = x_pointer; 1328 1330 } 1329 1331 1330 // We might as well use 'i' here to iterate, because we need it 1331 // (often compared against ints, so don't make it size_t) 1332 for (int i=0; i < (int)it->m_ListOfX.size()+2; ++i) 1333 { 1334 if (it->m_ListStart + i == VirtualFrom) 1335 { 1336 // we won't actually draw it now, because we don't 1337 // know the width of each glyph to that position. 1338 // we need to go along with the iteration, and 1339 // make a mark where the box started: 1340 drawing_box = true; // will turn false when finally rendered. 1341 1342 // Get current x position 1343 box_x = x_pointer; 1344 } 1345 1346 // no else! 1332 // no else! 1347 1333 1348 1334 const bool at_end = (i == (int)it->m_ListOfX.size()+1); 1349 1335 1350 if (drawing_box == true && 1351 (it->m_ListStart + i == VirtualTo || at_end)) 1336 if (drawing_box == true && 1337 (it->m_ListStart + i == VirtualTo || at_end)) 1338 { 1339 // Depending on if it's just a row change, or if it's 1340 // the end of the select box, do slightly different things. 1341 if (at_end) 1352 1342 { 1353 // Depending on if it's just a row change, or if it's 1354 // the end of the select box, do slightly different things. 1355 if (at_end) 1356 { 1357 if (it->m_ListStart + i != VirtualFrom) 1358 { 1359 // and actually add a white space! yes, this is done in any common input 1360 x_pointer += (float)font.GetCharacterWidth(L' '); 1361 } 1362 } 1363 else 1343 if (it->m_ListStart + i != VirtualFrom) 1364 1344 { 1365 drawing_box = false;1366 done = true;1345 // and actually add a white space! yes, this is done in any common input 1346 x_pointer += (float)font.GetCharacterWidth(L' '); 1367 1347 } 1348 } 1349 else 1350 { 1351 drawing_box = false; 1352 done = true; 1353 } 1368 1354 1369 CRect rect; 1370 // Set 'rect' depending on if it's a multiline control, or a one-line control 1371 if (multiline) 1372 { 1373 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone, 1374 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1375 m_CachedActualSize.left+x_pointer+buffer_zone, 1376 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1377 1378 if (rect.bottom < m_CachedActualSize.top) 1379 continue; 1355 CRect rect; 1356 // Set 'rect' depending on if it's a multiline control, or a one-line control 1357 if (multiline) 1358 { 1359 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone, 1360 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1361 m_CachedActualSize.left+x_pointer+buffer_zone, 1362 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1380 1363 1381 if (rect.top< m_CachedActualSize.top)1382 rect.top = m_CachedActualSize.top;1364 if (rect.bottom < m_CachedActualSize.top) 1365 continue; 1383 1366 1384 if (rect.bottom > m_CachedActualSize.bottom) 1385 rect.bottom = m_CachedActualSize.bottom; 1386 } 1387 else // if one-line 1388 { 1389 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll, 1390 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1391 m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll, 1392 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1367 if (rect.top < m_CachedActualSize.top) 1368 rect.top = m_CachedActualSize.top; 1393 1369 1394 if (rect.left < m_CachedActualSize.left) 1395 rect.left = m_CachedActualSize.left; 1370 if (rect.bottom > m_CachedActualSize.bottom) 1371 rect.bottom = m_CachedActualSize.bottom; 1372 } 1373 else // if one-line 1374 { 1375 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll, 1376 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1377 m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll, 1378 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1396 1379 1397 if (rect.right > m_CachedActualSize.right) 1398 rect.right = m_CachedActualSize.right; 1399 } 1380 if (rect.left < m_CachedActualSize.left) 1381 rect.left = m_CachedActualSize.left; 1400 1382 1401 if ( sprite_selectarea)1402 GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect);1383 if (rect.right > m_CachedActualSize.right) 1384 rect.right = m_CachedActualSize.right; 1403 1385 } 1404 1386 1405 if (i < (int)it->m_ListOfX.size()) 1406 { 1407 if (!mask) 1408 x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]); 1409 else 1410 x_pointer += (float)font.GetCharacterWidth(mask_char); 1411 } 1387 if (sprite_selectarea) 1388 GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect); 1412 1389 } 1413 1390 1414 if (done) 1415 break; 1416 1417 // If we're about to draw a box, and all of a sudden changes 1418 // line, we need to draw that line's box, and then reset 1419 // the box drawing to the beginning of the new line. 1420 if (drawing_box) 1391 if (i < (int)it->m_ListOfX.size()) 1421 1392 { 1422 box_x = 0.f; 1393 if (!mask) 1394 x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]); 1395 else 1396 x_pointer += (float)font.GetCharacterWidth(mask_char); 1423 1397 } 1424 1398 } 1399 1400 if (done) 1401 break; 1402 1403 // If we're about to draw a box, and all of a sudden changes 1404 // line, we need to draw that line's box, and then reset 1405 // the box drawing to the beginning of the new line. 1406 if (drawing_box) 1407 { 1408 box_x = 0.f; 1409 } 1425 1410 } 1411 } 1426 1412 1427 1428 1413 // Reset some from previous run 1414 buffered_y = -scroll; 1429 1415 1430 1431 1416 // Setup initial color (then it might change and change back, when drawing selected area) 1417 textRenderer.Color(color); 1432 1418 1433 1419 tech->BeginPass(); 1434 1420 1435 1421 bool using_selected_color = false; 1436 1422 1437 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1438 it != m_CharacterPositions.end(); 1439 ++it, buffered_y += ls) 1423 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1424 it != m_CharacterPositions.end(); 1425 ++it, buffered_y += ls) 1426 { 1427 if (buffered_y + buffer_zone >= -ls || !multiline) 1440 1428 { 1441 if ( buffered_y + buffer_zone >= -ls || !multiline)1429 if (multiline) 1442 1430 { 1443 if (multiline) 1444 { 1445 if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight()) 1446 break; 1447 } 1431 if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight()) 1432 break; 1433 } 1448 1434 1449 1435 CMatrix3D savedTransform = textRenderer.GetTransform(); 1450 1436 1451 1452 1453 1454 1455 1437 // Text must always be drawn in integer values. So we have to convert scroll 1438 if (multiline) 1439 textRenderer.Translate(0.f, -(float)(int)scroll, 0.f); 1440 else 1441 textRenderer.Translate(-(float)(int)m_HorizontalScroll, 0.f, 0.f); 1456 1442 1457 // We might as well use 'i' here, because we need it 1458 // (often compared against ints, so don't make it size_t) 1459 for (int i=0; i < (int)it->m_ListOfX.size()+1; ++i) 1443 // We might as well use 'i' here, because we need it 1444 // (often compared against ints, so don't make it size_t) 1445 for (int i=0; i < (int)it->m_ListOfX.size()+1; ++i) 1446 { 1447 if (!multiline && i < (int)it->m_ListOfX.size()) 1460 1448 { 1461 if (!multiline && i < (int)it->m_ListOfX.size()) 1462 { 1463 if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone) 1464 { 1465 // We still need to translate the OpenGL matrix 1466 if (i == 0) 1467 textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f); 1468 else 1469 textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f); 1470 1471 continue; 1472 } 1473 } 1474 1475 // End of selected area, change back color 1476 if (SelectingText() && 1477 it->m_ListStart + i == VirtualTo) 1478 { 1479 using_selected_color = false; 1480 textRenderer.Color(color); 1481 } 1482 1483 if (i != (int)it->m_ListOfX.size() && 1484 it->m_ListStart + i == m_iBufferPos) 1485 { 1486 // selecting only one, then we need only to draw a cursor. 1487 if (m_CursorVisState) 1488 textRenderer.Put(0.0f, 0.0f, L"_"); 1489 } 1490 1491 // Drawing selected area 1492 if (SelectingText() && 1493 it->m_ListStart + i >= VirtualFrom && 1494 it->m_ListStart + i < VirtualTo && 1495 using_selected_color == false) 1496 { 1497 using_selected_color = true; 1498 textRenderer.Color(color_selected); 1499 } 1500 1501 if (i != (int)it->m_ListOfX.size()) 1449 if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone) 1502 1450 { 1503 if (!mask) 1504 textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]); 1451 // We still need to translate the OpenGL matrix 1452 if (i == 0) 1453 textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f); 1505 1454 else 1506 textRenderer.PrintfAdvance(L"%lc", mask_char); 1507 } 1455 textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f); 1508 1456 1509 // check it's now outside a one-liner, then we'll break 1510 if (!multiline && i < (int)it->m_ListOfX.size()) 1511 { 1512 if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone) 1513 break; 1457 continue; 1514 1458 } 1515 1459 } 1516 1460 1517 if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos) 1461 // End of selected area, change back color 1462 if (SelectingText() && 1463 it->m_ListStart + i == VirtualTo) 1518 1464 { 1465 using_selected_color = false; 1519 1466 textRenderer.Color(color); 1467 } 1468 1469 if (i != (int)it->m_ListOfX.size() && 1470 it->m_ListStart + i == m_iBufferPos) 1471 { 1472 // selecting only one, then we need only to draw a cursor. 1520 1473 if (m_CursorVisState) 1521 textRenderer.PutAdvance(L"_"); 1474 textRenderer.Put(0.0f, 0.0f, L"_"); 1475 } 1522 1476 1523 if (using_selected_color) 1524 { 1525 textRenderer.Color(color_selected); 1526 } 1477 // Drawing selected area 1478 if (SelectingText() && 1479 it->m_ListStart + i >= VirtualFrom && 1480 it->m_ListStart + i < VirtualTo && 1481 using_selected_color == false) 1482 { 1483 using_selected_color = true; 1484 textRenderer.Color(color_selected); 1485 } 1486 1487 if (i != (int)it->m_ListOfX.size()) 1488 { 1489 if (!mask) 1490 textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]); 1491 else 1492 textRenderer.PrintfAdvance(L"%lc", mask_char); 1527 1493 } 1528 1494 1529 textRenderer.SetTransform(savedTransform); 1495 // check it's now outside a one-liner, then we'll break 1496 if (!multiline && i < (int)it->m_ListOfX.size()) 1497 { 1498 if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone) 1499 break; 1500 } 1530 1501 } 1531 1502 1532 textRenderer.Translate(0.f, ls, 0.f); 1533 } 1503 if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos) 1504 { 1505 textRenderer.Color(color); 1506 if (m_CursorVisState) 1507 textRenderer.PutAdvance(L"_"); 1534 1508 1535 textRenderer.Render(); 1509 if (using_selected_color) 1510 { 1511 textRenderer.Color(color_selected); 1512 } 1513 } 1536 1514 1537 if (cliparea != CRect())1538 glDisable(GL_SCISSOR_TEST);1515 textRenderer.SetTransform(savedTransform); 1516 } 1539 1517 1540 te ch->EndPass();1518 textRenderer.Translate(0.f, ls, 0.f); 1541 1519 } 1520 1521 textRenderer.Render(); 1522 1523 if (cliparea != CRect()) 1524 glDisable(GL_SCISSOR_TEST); 1525 1526 tech->EndPass(); 1542 1527 } 1543 1528 1544 1529 void CInput::UpdateText(int from, int to_before, int to_after) … … 1734 1719 if (i==to-1 && to != (int)caption.length()) 1735 1720 break; // it will be added outside 1736 1721 1737 current_line = m_CharacterPositions.insert( current_line, row);1722 current_line = m_CharacterPositions.insert(current_line, row); 1738 1723 ++current_line; 1739 1724 1740 1725 … … 1764 1749 { 1765 1750 last_word_started = i; 1766 1751 row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started)); 1767 //row.m_ListOfX.push_back( x_pos);1752 //row.m_ListOfX.push_back(x_pos); 1768 1753 //continue; 1769 1754 } 1770 1755 else … … 1779 1764 // rows. With automatic word-wrapping, that is not possible. Which 1780 1765 // is intuitively correct. 1781 1766 1782 current_line = m_CharacterPositions.insert( current_line, row);1767 current_line = m_CharacterPositions.insert(current_line, row); 1783 1768 ++current_line; 1784 1769 1785 1770 // Setup the next row: … … 1792 1777 } 1793 1778 else 1794 1779 // Get width of this character: 1795 row.m_ListOfX.push_back( x_pos);1780 row.m_ListOfX.push_back(x_pos); 1796 1781 } 1797 1782 1798 1783 // Check if it's the last iteration, and we're not revising the whole string … … 1843 1828 // have to continue. 1844 1829 // 'check_point_row_start' is where we store how the that 1845 1830 // line looked. 1846 // if (destroy_row_to !=1847 1831 if (destroy_row_to != m_CharacterPositions.end()) 1848 1832 { 1849 1833 check_point_row_start = destroy_row_to->m_ListStart; … … 1900 1884 if (current_line != m_CharacterPositions.end()) 1901 1885 { 1902 1886 if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart) 1903 row.m_ListOfX.resize( row.m_ListOfX.size()-1);1887 row.m_ListOfX.resize(row.m_ListOfX.size()-1); 1904 1888 } 1905 1889 1906 1890 // add the final row (even if empty) … … 1943 1927 1944 1928 float scroll=0.f; 1945 1929 if (scrollbar) 1946 {1947 1930 scroll = GetScrollBar(0).GetPos(); 1948 }1949 1931 1950 1932 // Pointer to caption, will come in handy 1951 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;1933 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 1952 1934 UNUSED2(pCaption); 1953 1935 1954 1936 // Now get the height of the font. … … 1998 1980 } 1999 1981 2000 1982 // Does not process horizontal scrolling, 'x' must be modified before inputted. 2001 int CInput::GetXTextPosition(const std::list<SRow>::iterator ¤t, const float &x, float &wanted)1983 int CInput::GetXTextPosition(const std::list<SRow>::iterator& current, const float& x, float& wanted) 2002 1984 { 2003 1985 int ret=0; 2004 1986 float previous=0.f; … … 2026 2008 ret += i; 2027 2009 wanted = x; 2028 2010 } 2029 else wanted = 0.f; 2011 else 2012 wanted = 0.f; 2030 2013 2031 2014 return ret; 2032 2015 } 2033 2016 2034 2017 void CInput::DeleteCurSelection() 2035 2018 { 2036 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;2019 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 2037 2020 2038 2021 int virtualFrom; 2039 2022 int virtualTo; … … 2049 2032 virtualTo = m_iBufferPos; 2050 2033 } 2051 2034 2052 *pCaption = pCaption->Left( virtualFrom) +2053 pCaption->Right( (long) pCaption->length() - (virtualTo));2035 *pCaption = pCaption->Left(virtualFrom) + 2036 pCaption->Right((long)pCaption->length() - virtualTo); 2054 2037 2055 2038 UpdateText(virtualFrom, virtualTo, virtualFrom); 2056 2039 … … 2128 2111 // Scroll so the selected row is shown completely, also with buffer_zone length to the edge. 2129 2112 GetScrollBar(0).SetPos((float)(row+1) * spacing - m_CachedActualSize.GetHeight() + buffer_zone*2.f); 2130 2113 } 2131 else2132 2114 // If scrolling up 2133 if (-scroll + (float)row * spacing < 0.f)2115 else if (-scroll + (float)row * spacing < 0.f) 2134 2116 { 2135 2117 // Scroll so the selected row is shown completely, also with buffer_zone length to the edge. 2136 2118 GetScrollBar(0).SetPos((float)row * spacing); -
source/gui/CInput.h
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 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.h28 29 */30 31 18 #ifndef INCLUDED_CINPUT 32 19 #define INCLUDED_CINPUT 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 //--------------------------------------------------------40 // Macros41 //--------------------------------------------------------42 43 //--------------------------------------------------------44 // Types45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Declarations49 //--------------------------------------------------------50 51 23 /** 52 24 * Text field where you can input and edit the text. 53 25 * … … 80 52 81 53 // Same as above, but only on one row in X, and a given value, not the mouse's 82 54 // 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); 84 56 85 57 protected: 86 58 /** 87 59 * @see IGUIObject#HandleMessage() 88 60 */ 89 virtual void HandleMessage(SGUIMessage &Message);61 virtual void HandleMessage(SGUIMessage& Message); 90 62 91 63 /** 92 64 * Handle events manually to catch keyboard inputting. … … 172 144 * List of rows to ease changing its size, so iterators stay valid. 173 145 * For one-liners only one row is used. 174 146 */ 175 std::list< SRow> m_CharacterPositions;147 std::list<SRow> m_CharacterPositions; 176 148 177 149 // *** Things for a multi-lined input control *** // 178 150 … … 205 177 bool m_CursorVisState; 206 178 }; 207 179 208 #endif 180 #endif // INCLUDED_CINPUT -
source/gui/CList.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CList20 */21 22 18 #include "precompiled.h" 23 19 24 20 #include "CList.h" … … 30 26 #include "soundmanager/ISoundManager.h" 31 27 32 28 33 //------------------------------------------------------------------- 34 // Constructor / Destructor 35 //------------------------------------------------------------------- 36 CList::CList() : 37 m_Modified(false) 29 CList::CList() 30 : m_Modified(false) 38 31 { 39 32 // Add sprite_disabled! TODO 40 33 41 34 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).43 35 AddSetting(GUIST_CStrW, "font"); 44 36 AddSetting(GUIST_bool, "scrollbar"); 45 37 AddSetting(GUIST_CStr, "scrollbar_style"); … … 64 56 GUI<int>::SetSetting(this, "selected", -1); 65 57 66 58 // Add scroll-bar 67 CGUIScrollBarVertical 59 CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(); 68 60 bar->SetRightAligned(true); 69 61 AddScrollBar(bar); 70 62 } … … 79 71 return; 80 72 81 73 m_Modified = true; 82 CGUIList *pList;74 CGUIList* pList; 83 75 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 84 76 85 77 //ENSURE(m_GeneratedTexts.size()>=1); 86 78 87 m_ItemsYPositions.resize( pList->m_Items.size()+1);79 m_ItemsYPositions.resize(pList->m_Items.size()+1); 88 80 89 81 // Delete all generated texts. Some could probably be saved, 90 82 // but this is easier, and this function will never be called 91 83 // 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; 98 86 m_GeneratedTexts.clear(); 99 87 100 88 CStrW font; … … 103 91 // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style. 104 92 font = L"default"; 105 93 106 //CGUIString caption;107 94 bool scrollbar; 108 //GUI<CGUIString>::GetSetting(this, "caption", caption);109 95 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 110 96 111 97 float width = GetListRect().GetWidth(); … … 119 105 // Generate texts 120 106 float buffered_y = 0.f; 121 107 122 for ( int i=0; i<(int)pList->m_Items.size(); ++i)108 for (size_t i=0; i < pList->m_Items.size(); ++i) 123 109 { 124 110 // Create a new SGUIText. Later on, input it using AddText() 125 SGUIText *text = new SGUIText();111 SGUIText* text = new SGUIText(); 126 112 127 113 *text = GetGUI()->GenerateText(pList->m_Items[i], font, width, buffer_zone, this); 128 114 … … 134 120 135 121 m_ItemsYPositions[pList->m_Items.size()] = buffered_y; 136 122 137 //if (! scrollbar)138 // CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]);139 140 123 // Setup scrollbar 141 124 if (scrollbar) 142 125 { 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()); 145 128 146 129 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); 151 134 } 152 135 } 153 136 154 void CList::HandleMessage(SGUIMessage &Message)137 void CList::HandleMessage(SGUIMessage& Message) 155 138 { 156 139 IGUIScrollBarOwner::HandleMessage(Message); 157 140 //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! … … 161 144 { 162 145 case GUIM_SETTINGS_UPDATED: 163 146 if (Message.value == "list") 164 {165 147 SetupText(); 166 }167 148 168 149 // If selected is changed, call "SelectionChange" 169 150 if (Message.value == "selected") … … 175 156 } 176 157 177 158 if (Message.value == "scrollbar") 178 {179 159 SetupText(); 180 }181 160 182 161 // Update scrollbar 183 162 if (Message.value == "scrollbar_style") … … 185 164 CStr scrollbar_style; 186 165 GUI<CStr>::GetSetting(this, Message.value, scrollbar_style); 187 166 188 GetScrollBar(0).SetScrollBarStyle( scrollbar_style);167 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 189 168 190 169 SetupText(); 191 170 } … … 205 184 } 206 185 207 186 bool scrollbar; 208 CGUIList *pList;187 CGUIList* pList; 209 188 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 210 189 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 211 190 float scroll=0.f; 212 191 if (scrollbar) 213 {214 192 scroll = GetScrollBar(0).GetPos(); 215 }216 193 217 194 CRect rect = GetListRect(); 218 195 CPos mouse = GetMousePos(); … … 243 220 } 244 221 245 222 case GUIM_LOAD: 246 223 { 247 224 CStr scrollbar_style; 248 225 GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); 249 GetScrollBar(0).SetScrollBarStyle( scrollbar_style ); 250 } 226 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 251 227 break; 228 } 252 229 253 230 default: 254 231 break; … … 317 294 DrawList(selected, "sprite", "sprite_selectarea", "textcolor"); 318 295 } 319 296 320 void CList::DrawList(const int &selected, 321 const CStr& _sprite, 322 const CStr& _sprite_selected, 323 const CStr& _textcolor) 297 void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) 324 298 { 325 299 float bz = GetBufferedZ(); 326 300 … … 329 303 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 330 304 331 305 if (scrollbar) 332 {333 // Draw scrollbar334 306 IGUIScrollBarOwner::Draw(); 335 }336 307 337 308 if (GetGUI()) 338 309 { 339 310 CRect rect = GetListRect(); 340 311 341 CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL; 312 CGUISpriteInstance* sprite = NULL; 313 CGUISpriteInstance* sprite_selectarea = NULL; 342 314 int cell_id; 343 315 GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite); 344 316 GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea); 345 317 GUI<int>::GetSetting(this, "cell_id", cell_id); 346 318 347 CGUIList *pList;319 CGUIList* pList; 348 320 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 349 321 350 322 GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); 351 323 352 324 float scroll=0.f; 353 325 if (scrollbar) 354 {355 326 scroll = GetScrollBar(0).GetPos(); 356 }357 327 358 328 if (selected != -1) 359 329 { … … 390 360 CColor color; 391 361 GUI<CColor>::GetSetting(this, _textcolor, color); 392 362 393 for ( int i=0; i<(int)pList->m_Items.size(); ++i)363 for (size_t i=0; i < pList->m_Items.size(); ++i) 394 364 { 395 365 if (m_ItemsYPositions[i+1] - scroll < 0 || 396 366 m_ItemsYPositions[i] - scroll > rect.GetHeight()) … … 417 387 418 388 void CList::AddItem(const CStrW& str, const CStrW& data) 419 389 { 420 CGUIList *pList, *pListData; 390 CGUIList* pList; 391 CGUIList* pListData; 421 392 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 422 393 GUI<CGUIList>::GetSettingPointer(this, "list_data", pListData); 423 394 424 395 CGUIString gui_string; 425 396 gui_string.SetValue(str); 426 pList->m_Items.push_back( gui_string);397 pList->m_Items.push_back(gui_string); 427 398 428 399 CGUIString data_string; 429 400 data_string.SetValue(data); 430 pListData->m_Items.push_back( data_string);401 pListData->m_Items.push_back(data_string); 431 402 432 403 // TODO Temp 433 404 SetupText(); … … 454 425 int selected; 455 426 GUI<int>::GetSetting(this, "selected", selected); 456 427 457 CGUIList *pList;428 CGUIList* pList; 458 429 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 459 430 460 431 if (selected != (int)pList->m_Items.size()-1) … … 490 461 GUI<int>::GetSetting(this, "selected", selected); 491 462 492 463 if (selected >= 0) 493 {494 464 GUI<int>::SetSetting(this, "selected", 0); 495 }496 465 } 497 466 498 467 void CList::SelectLastElement() … … 500 469 int selected; 501 470 GUI<int>::GetSetting(this, "selected", selected); 502 471 503 CGUIList *pList;472 CGUIList* pList; 504 473 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 505 474 506 475 if (selected != (int)pList->m_Items.size()-1) 507 {508 476 GUI<int>::SetSetting(this, "selected", (int)pList->m_Items.size()-1); 509 }510 477 } 511 478 512 479 void CList::UpdateAutoScroll() … … 535 502 536 503 // Check lower boundary 537 504 if (m_ItemsYPositions[selected+1]-rect.GetHeight() > scroll) 538 {539 505 GetScrollBar(0).SetPos(m_ItemsYPositions[selected+1]-rect.GetHeight()); 540 }541 506 } -
source/gui/CList.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - List [box]20 21 --Overview--22 23 GUI Object for creating lists of information, wherein one24 of the elements can be selected. A scroll-bar will aid25 when there's too much information to be displayed at once.26 27 --More info--28 29 Check GUI.h30 31 */32 33 18 #ifndef INCLUDED_CLIST 34 19 #define INCLUDED_CLIST 35 20 36 //--------------------------------------------------------37 // Includes / Compiler directives38 //--------------------------------------------------------39 40 21 #include "IGUIScrollBar.h" 41 22 42 //--------------------------------------------------------43 // Macros44 //--------------------------------------------------------45 46 //--------------------------------------------------------47 // Types48 //--------------------------------------------------------49 50 //--------------------------------------------------------51 // Declarations52 //--------------------------------------------------------53 54 55 23 /** 56 24 * Create a list of elements, where one can be selected 57 25 * by the user. The control will use a pre-processed … … 59 27 * by the IGUITextOwner structure. 60 28 * 61 29 * A scroll-bar will appear when needed. This will be 62 * achieve with the IGUIScrollBarOwner structure. 63 * 30 * achieved with the IGUIScrollBarOwner structure. 64 31 */ 65 66 32 class CList : public IGUIScrollBarOwner, public IGUITextOwner 67 33 { 68 34 GUI_OBJECT(CList) … … 91 57 /** 92 58 * @see IGUIObject#HandleMessage() 93 59 */ 94 virtual void HandleMessage(SGUIMessage &Message);60 virtual void HandleMessage(SGUIMessage& Message); 95 61 96 62 /** 97 63 * Handle events manually to catch keyboard inputting. … … 121 87 122 88 // Extended drawing interface, this is so that classes built on the this one 123 89 // 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); 126 91 127 92 // Get the area of the list. This is so that it can easily be changed, like in CDropDown 128 93 // where the area is not equal to m_CachedActualSize. … … 132 97 // (and thus whether list items have possibly changed). 133 98 virtual bool GetModified() const { return m_Modified; } 134 99 135 // List of items.136 //CGUIList m_List;137 138 100 /** 139 101 * List of each element's relative y position. Will be 140 102 * one larger than m_Items, because it will end with the … … 148 110 bool m_Modified; 149 111 }; 150 112 151 #endif 113 #endif // INCLUDED_CLIST -
source/gui/COList.cpp
14 14 * You should have received a copy of the GNU General Public License 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 #include "precompiled.h" 19 18 20 #include "COList.h" 19 #include "i18n/L10n.h"20 21 22 #include "i18n/L10n.h" 21 23 #include "ps/CLogger.h" 22 24 #include "soundmanager/ISoundManager.h" 23 25 24 COList::COList() : CList(),m_HeadingHeight(30.f),m_SelectedDef(-1),m_SelectedColumnOrder(1) 26 COList::COList() 27 : CList(), m_HeadingHeight(30.f), m_SelectedDef(-1), m_SelectedColumnOrder(1) 25 28 { 26 29 AddSetting(GUIST_CGUISpriteInstance, "sprite_heading"); 27 30 AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility … … 44 47 if (!GetGUI()) 45 48 return; 46 49 47 CGUIList *pList;50 CGUIList* pList; 48 51 GUI<CGUIList>::GetSettingPointer(this, "list_name", pList); 49 52 50 m_ItemsYPositions.resize( pList->m_Items.size()+1);53 m_ItemsYPositions.resize(pList->m_Items.size() + 1); 51 54 52 55 // Delete all generated texts. Some could probably be saved, 53 56 // but this is easier, and this function will never be called 54 57 // 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; 61 60 m_GeneratedTexts.clear(); 62 61 63 62 CStrW font; … … 84 83 GUI<CStr>::GetSetting(this, "default_column", defaultColumn); 85 84 defaultColumn = "list_" + defaultColumn; 86 85 87 for ( unsigned int c=0; c<m_ObjectsDefs.size(); ++c)86 for (size_t c=0; c < m_ObjectsDefs.size(); ++c) 88 87 { 89 SGUIText *text = new SGUIText();88 SGUIText* text = new SGUIText(); 90 89 CGUIString gui_string; 91 90 gui_string.SetValue(m_ObjectsDefs[c].m_Heading); 92 91 *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this); 93 92 AddText(text); 94 93 95 if (m_SelectedDef == -1 && defaultColumn == m_ObjectsDefs[c].m_Id)94 if (m_SelectedDef == (size_t)-1 && defaultColumn == m_ObjectsDefs[c].m_Id) 96 95 m_SelectedDef = c; 97 96 } 98 97 … … 100 99 // Generate texts 101 100 float buffered_y = 0.f; 102 101 103 for ( int i=0; i<(int)pList->m_Items.size(); ++i)102 for (size_t i=0; i < pList->m_Items.size(); ++i) 104 103 { 105 104 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) 107 106 { 108 CGUIList 107 CGUIList* pList_c; 109 108 GUI<CGUIList>::GetSettingPointer(this, m_ObjectsDefs[c].m_Id, pList_c); 110 SGUIText *text = new SGUIText();109 SGUIText* text = new SGUIText(); 111 110 *text = GetGUI()->GenerateText(pList_c->m_Items[i], font, width, buffer_zone, this); 112 111 if (c==0) 113 112 buffered_y += text->m_Size.cy; … … 120 119 // Setup scrollbar 121 120 if (scrollbar) 122 121 { 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()); 125 124 126 125 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); 131 130 } 132 131 } 133 132 … … 136 135 return m_CachedActualSize + CRect(0, m_HeadingHeight, 0, 0); 137 136 } 138 137 139 void COList::HandleMessage(SGUIMessage &Message)138 void COList::HandleMessage(SGUIMessage& Message) 140 139 { 141 140 CList::HandleMessage(Message); 142 141 … … 155 154 return; 156 155 157 156 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) 159 158 { 160 159 float width = m_ObjectsDefs[def].m_Width; 161 160 // Check if it's a decimal value, and if so, assume relative positioning. … … 166 165 mouse.x < leftTopCorner.x + width && 167 166 mouse.y < leftTopCorner.y + m_HeadingHeight) 168 167 { 169 if ( static_cast<int> (def)!= m_SelectedDef)168 if (def != m_SelectedDef) 170 169 { 171 170 m_SelectedColumnOrder = 1; 172 171 m_SelectedDef = def; … … 198 197 #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) 199 198 #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) 200 199 ELMT(item); 201 ELMT(heading);202 200 ELMT(def); 203 201 ELMT(translatableAttribute); 204 202 ATTR(id); … … 209 207 AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); 210 208 return true; 211 209 } 212 else if (child.GetNodeName() == elmt_heading)213 {214 CStrW text (child.GetText().FromUTF8());215 216 return true;217 }218 210 else if (child.GetNodeName() == elmt_def) 219 211 { 220 212 ObjectDef oDef; 221 213 222 214 for (XMBAttribute attr : child.GetAttributes()) 223 215 { 224 CStr attr_name 225 CStr attr_value 216 CStr attr_name(pFile->GetAttributeString(attr.Name)); 217 CStr attr_value(attr.Value); 226 218 227 219 if (attr_name == "color") 228 220 { … … 244 236 { 245 237 // Check if it's a relative value, and save as decimal if so. 246 238 if (attr_value.find("%") != std::string::npos) 247 {248 239 width = width / 100.f; 249 }250 240 oDef.m_Width = width; 251 241 } 252 242 } … … 254 244 { 255 245 oDef.m_Heading = attr_value.FromUTF8(); 256 246 } 257 258 247 } 259 248 260 249 for (XMBElement grandchild : child.GetChildNodes()) 261 250 { 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") 263 257 { 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(); 288 276 } 289 277 } 290 278 … … 301 289 } 302 290 } 303 291 304 void COList::DrawList(const int &selected, 305 const CStr& _sprite, 306 const CStr& _sprite_selected, 307 const CStr& _textcolor) 292 void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) 308 293 { 309 294 float bz = GetBufferedZ(); 310 295 … … 313 298 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 314 299 315 300 if (scrollbar) 316 {317 // Draw scrollbar318 301 IGUIScrollBarOwner::Draw(); 319 }320 302 321 if (GetGUI()) 322 { 323 CRect rect = GetListRect(); 303 if (!GetGUI()) 304 return; 324 305 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(); 330 307 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); 333 314 334 GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); 315 CGUIList* pList; 316 GUI<CGUIList>::GetSettingPointer(this, "list_name", pList); 335 317 336 float scroll=0.f; 337 if (scrollbar) 338 { 339 scroll = GetScrollBar(0).GetPos(); 340 } 318 GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); 341 319 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(); 345 323 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()); 349 327 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); 357 331 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; 369 339 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; 371 350 } 351 352 GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel); 372 353 } 354 } 373 355 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); 376 372 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; 386 386 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))); 406 389 407 408 409 390 DrawText(def, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head); 391 xpos += width; 392 } 410 393 411 const unsigned int objectsCount = m_ObjectsDefs.size();412 for (int i=0; i<(int)pList->m_Items.size(); ++i)413 414 415 416 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; 417 400 418 401 const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i]; 419 402 420 421 403 // Clipping area (we'll have to substract the scrollbar) 404 CRect cliparea = GetListRect(); 422 405 423 424 425 426 427 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; 428 411 429 430 431 432 412 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && 413 cliparea.left < GetScrollBar(0).GetOuterRect().right) 414 cliparea.left = GetScrollBar(0).GetOuterRect().right; 415 } 433 416 434 435 for (unsigned int def=0; def < objectsCount; ++def)436 437 438 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]); 439 422 440 441 442 443 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; 444 427 445 446 447 448 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); 449 432 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; 453 435 } 454 436 } 455 437 } -
source/gui/COList.h
17 17 #ifndef INCLUDED_COLIST 18 18 #define INCLUDED_COLIST 19 19 20 //--------------------------------------------------------21 // Includes / Compiler directives22 //--------------------------------------------------------23 20 #include "GUI.h" 24 21 #include "CList.h" 25 22 26 //--------------------------------------------------------27 // Macros28 //--------------------------------------------------------29 30 //--------------------------------------------------------31 // Types32 //--------------------------------------------------------33 34 //--------------------------------------------------------35 // Declarations36 //--------------------------------------------------------37 38 23 struct ObjectDef 39 24 { 40 25 CColor m_TextColor; … … 45 30 }; 46 31 47 32 /** 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. 50 39 */ 51 40 class COList : public CList 52 41 { … … 57 46 58 47 protected: 59 48 void SetupText(); 60 void HandleMessage(SGUIMessage &Message);49 void HandleMessage(SGUIMessage& Message); 61 50 62 51 /** 63 52 * Handle the \<item\> tag. 64 53 */ 65 54 virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile); 66 55 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); 69 57 70 58 virtual CRect GetListRect() const; 71 59 72 60 std::vector<ObjectDef> m_ObjectsDefs; 73 int m_SelectedDef;61 size_t m_SelectedDef; 74 62 int m_SelectedColumnOrder; 75 63 76 64 private: -
source/gui/CProgressBar.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CProgressBar20 */21 22 18 #include "precompiled.h" 19 23 20 #include "GUI.h" 24 21 #include "CProgressBar.h" 25 22 26 23 #include "lib/ogl.h" 27 24 28 29 //-------------------------------------------------------------------30 // Constructor / Destructor31 //-------------------------------------------------------------------32 25 CProgressBar::CProgressBar() 33 26 { 34 27 AddSetting(GUIST_CGUISpriteInstance, "sprite_background"); … … 42 35 { 43 36 } 44 37 45 void CProgressBar::HandleMessage(SGUIMessage &Message)38 void CProgressBar::HandleMessage(SGUIMessage& Message) 46 39 { 47 40 // Important 48 41 IGUIObject::HandleMessage(Message); … … 70 63 71 64 void CProgressBar::Draw() 72 65 { 73 if (GetGUI()) 74 { 75 float bz = GetBufferedZ(); 66 if (!GetGUI()) 67 return; 76 68 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(); 83 70 84 GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize); 71 CGUISpriteInstance *sprite_background, *sprite_bar; 72 int cell_id = 0; 73 float value = 0; 74 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background); 75 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar); 76 GUI<float>::GetSetting(this, "caption", value); 85 77 78 GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize); 86 79 87 // Get size of bar (notice it is drawn slightly closer, to appear above the background) 88 CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, 89 m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); 90 GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size); 91 } 80 // Get size of bar (notice it is drawn slightly closer, to appear above the background) 81 CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, 82 m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); 83 GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size); 92 84 } -
source/gui/CProgressBar.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Progress bar20 21 --Overview--22 23 GUI Object to show progress or a value visually.24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_CPROGRESSBAR 32 19 #define INCLUDED_CPROGRESSBAR 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 //--------------------------------------------------------40 // Macros41 //--------------------------------------------------------42 43 //--------------------------------------------------------44 // Types45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Declarations49 //--------------------------------------------------------50 51 23 /** 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. 53 25 * 54 26 * @see IGUIObject 55 27 */ … … 71 43 /** 72 44 * @see IGUIObject#HandleMessage() 73 45 */ 74 void HandleMessage(SGUIMessage &Message);46 void HandleMessage(SGUIMessage& Message); 75 47 }; 76 48 77 #endif 49 #endif // INCLUDED_CPROGRESSBAR -
source/gui/CRadioButton.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CCheckBox20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h" 19 24 20 #include "CRadioButton.h" 25 21 22 #include "GUI.h" 26 23 27 void CRadioButton::HandleMessage(SGUIMessage &Message)24 void CRadioButton::HandleMessage(SGUIMessage& Message) 28 25 { 29 26 // Important 30 27 IGUIButtonBehavior::HandleMessage(Message); … … 33 30 switch (Message.type) 34 31 { 35 32 case GUIM_PRESSED: 33 for (IGUIObject* const& obj : *GetParent()) 36 34 { 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); 47 39 } 48 40 41 GUI<bool>::SetSetting(this, "checked", true); 42 break; 43 49 44 default: 50 45 break; 51 46 } -
source/gui/CRadioButton.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Radio Button20 21 --Overview--22 23 GUI Object representing a radio button24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_CRADIOBUTTON 32 19 #define INCLUDED_CRADIOBUTTON 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 #include "CCheckBox.h" 39 23 … … 51 35 /** 52 36 * @see IGUIObject#HandleMessage() 53 37 */ 54 virtual void HandleMessage(SGUIMessage &Message);38 virtual void HandleMessage(SGUIMessage& Message); 55 39 }; 56 40 57 #endif 41 #endif // INCLUDED_CRADIOBUTTON -
source/gui/CText.cpp
1 /* Copyright (C) 201 0Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 CText20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h" 19 24 20 #include "CText.h" 21 25 22 #include "CGUIScrollBarVertical.h" 23 #include "GUI.h" 26 24 27 25 #include "lib/ogl.h" 28 26 29 30 //-------------------------------------------------------------------31 // Constructor / Destructor32 //-------------------------------------------------------------------33 27 CText::CText() 34 28 { 35 29 AddSetting(GUIST_float, "buffer_zone"); … … 56 50 GUI<bool>::SetSetting(this, "clip", true); 57 51 58 52 // Add scroll-bar 59 CGUIScrollBarVertical 53 CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(); 60 54 bar->SetRightAligned(true); 61 55 AddScrollBar(bar); 62 56 … … 96 90 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 97 91 *m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, width, buffer_zone, this); 98 92 99 if (! 93 if (!scrollbar) 100 94 CalculateTextPosition(m_CachedActualSize, m_TextPos, *m_GeneratedTexts[0]); 101 95 102 96 // Setup scrollbar … … 126 120 } 127 121 } 128 122 129 void CText::HandleMessage(SGUIMessage &Message)123 void CText::HandleMessage(SGUIMessage& Message) 130 124 { 131 125 IGUIScrollBarOwner::HandleMessage(Message); 132 126 //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! … … 135 129 { 136 130 case GUIM_SETTINGS_UPDATED: 137 131 if (Message.value == "scrollbar") 138 {139 132 SetupText(); 140 }141 133 142 134 // Update scrollbar 143 135 if (Message.value == "scrollbar_style") … … 145 137 CStr scrollbar_style; 146 138 GUI<CStr>::GetSetting(this, Message.value, scrollbar_style); 147 139 148 GetScrollBar(0).SetScrollBarStyle( scrollbar_style);140 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 149 141 150 142 SetupText(); 151 143 } … … 153 145 break; 154 146 155 147 case GUIM_MOUSE_WHEEL_DOWN: 156 148 { 157 149 GetScrollBar(0).ScrollPlus(); 158 150 // Since the scroll was changed, let's simulate a mouse movement 159 151 // to check if scrollbar now is hovered 160 152 SGUIMessage msg(GUIM_MOUSE_MOTION); 161 153 HandleMessage(msg); 162 154 break; 163 155 } 164 156 case GUIM_MOUSE_WHEEL_UP: 165 157 { 166 158 GetScrollBar(0).ScrollMinus(); 167 159 // Since the scroll was changed, let's simulate a mouse movement 168 160 // to check if scrollbar now is hovered 169 161 SGUIMessage msg(GUIM_MOUSE_MOTION); 170 162 HandleMessage(msg); 171 163 break; 172 164 } 173 165 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); 179 171 180 172 CStr scrollbar_style; 181 173 GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); 182 GetScrollBar(0).SetScrollBarStyle( scrollbar_style ); 183 } 174 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 184 175 break; 176 } 185 177 186 178 default: 187 179 break; … … 199 191 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 200 192 201 193 if (scrollbar) 202 {203 194 // Draw scrollbar 204 195 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);215 196 216 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 197 if (!GetGUI()) 198 return; 217 199 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); 223 206 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); 229 208 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(); 242 212 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; 245 218 246 219 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 } 250 230 } 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); 251 239 } 252 240 253 241 bool CText::MouseOverIcon() 254 242 { 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) 263 245 { 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; 266 249 267 if (spritecall.m_Area.PointInside(GetMousePos() - m_CachedActualSize.TopLeft())) 250 // If tooltip exists, set the property 251 if (!spritecall.m_Tooltip.empty()) 268 252 { 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); 277 255 } 256 257 return true; 278 258 } 279 }280 259 281 260 return false; 282 261 } -
source/gui/CText.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Text [field]20 21 --Overview--22 23 GUI Object representing a text field24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_CTEXT 32 19 #define INCLUDED_CTEXT 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 // TODO Gee: Remove40 class IGUIScrollBar;41 42 //--------------------------------------------------------43 // Macros44 //--------------------------------------------------------45 46 //--------------------------------------------------------47 // Types48 //--------------------------------------------------------49 50 //--------------------------------------------------------51 // Declarations52 //--------------------------------------------------------53 54 23 /** 55 24 * Text field that just displays static text. 56 25 * … … 84 53 /** 85 54 * @see IGUIObject#HandleMessage() 86 55 */ 87 virtual void HandleMessage(SGUIMessage &Message);56 virtual void HandleMessage(SGUIMessage& Message); 88 57 89 58 /** 90 59 * Draws the Text … … 97 66 CPos m_TextPos; 98 67 }; 99 68 100 #endif 69 #endif // INCLUDED_CTEXT -
source/gui/CTooltip.cpp
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 // CTooltip: GUI object used for tooltips19 20 18 #include "precompiled.h" 21 19 22 20 #include "CTooltip.h" … … 144 142 GUI<CClientArea>::SetSetting(this, "size", size); 145 143 } 146 144 147 void CTooltip::HandleMessage(SGUIMessage &Message)145 void CTooltip::HandleMessage(SGUIMessage& Message) 148 146 { 149 147 IGUITextOwner::HandleMessage(Message); 150 148 } 151 149 152 150 void CTooltip::Draw() 153 151 { 152 if (!GetGUI()) 153 return; 154 154 155 float z = 900.f; // TODO: Find a nicer way of putting the tooltip on top of everything else 155 156 156 if (GetGUI()) 157 { 158 CGUISpriteInstance *sprite; 159 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 157 CGUISpriteInstance* sprite; 158 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 160 159 161 162 163 164 165 166 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 } 168 167 169 168 GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize); 170 169 171 172 170 CColor color; 171 GUI<CColor>::GetSetting(this, "textcolor", color); 173 172 174 DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f); 175 } 173 DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f); 176 174 } -
source/gui/CTooltip.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object - Tooltip20 21 --Overview--22 23 Mostly like CText, but intended for dynamic tooltips24 25 */26 27 18 #ifndef INCLUDED_CTOOLTIP 28 19 #define INCLUDED_CTOOLTIP 29 20 30 21 #include "IGUITextOwner.h" 31 22 23 /** 24 * Dynamic tooltips. Similar to CText. 25 */ 32 26 class CTooltip : public IGUITextOwner 33 27 { 34 28 GUI_OBJECT(CTooltip) … … 43 37 /** 44 38 * @see IGUIObject#HandleMessage() 45 39 */ 46 virtual void HandleMessage(SGUIMessage &Message);40 virtual void HandleMessage(SGUIMessage& Message); 47 41 48 42 virtual void Draw(); 49 43 }; 50 44 51 #endif 45 #endif // INCLUDED_CTOOLTIP -
source/gui/GUI.h
32 32 #ifndef INCLUDED_GUI 33 33 #define INCLUDED_GUI 34 34 35 //--------------------------------------------------------36 // Includes37 //--------------------------------------------------------38 35 #include <map> 36 #include <stddef.h> 39 37 #include <string> 40 38 #include <vector> 41 #include <stddef.h>42 39 43 40 #include "ps/CStr.h" 44 41 42 #include "CGUIList.h" 45 43 #include "GUIbase.h" 46 #include "GUIutil.h"47 44 #include "GUItext.h" 48 #include "CGUIList.h" 49 #include "IGUIObject.h" 45 #include "GUIutil.h" 50 46 #include "IGUIButtonBehavior.h" 51 #include "IGUI ScrollBarOwner.h"52 #include "IGUI TextOwner.h"47 #include "IGUIObject.h" 48 #include "IGUIScrollBarOwner.h" // Required by IGUIScrollBar 53 49 #include "IGUIScrollBar.h" 50 #include "IGUITextOwner.h" 54 51 55 #endif 52 #endif // INCLUDED_GUI -
source/gui/GUIManager.cpp
277 277 278 278 Status CGUIManager::ReloadChangedFile(const VfsPath& path) 279 279 { 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)) 283 282 { 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); 286 285 // TODO: this can crash if LoadPage runs an init script which modifies the page stack and breaks our iterators 287 286 } 288 }289 287 290 288 return INFO::OK; 291 289 } … … 293 291 Status CGUIManager::ReloadAllPages() 294 292 { 295 293 // 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); 298 296 299 297 return INFO::OK; 300 298 } … … 367 365 } 368 366 369 367 370 bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) 368 bool CGUIManager::GetPreDefinedColor(const CStr& name, CColor& output) const 371 369 { 372 370 return top()->GetPreDefinedColor(name, output); 373 371 } … … 382 380 return top()->FindObjectByName(name); 383 381 } 384 382 385 void CGUIManager::SendEventToAll(const CStr& eventName) 383 void CGUIManager::SendEventToAll(const CStr& eventName) const 386 384 { 387 385 top()->SendEventToAll(eventName); 388 386 } … … 398 396 // Save an immutable copy so iterators aren't invalidated by tick handlers 399 397 PageStackType pageStack = m_PageStack; 400 398 401 for ( PageStackType::iterator it = pageStack.begin(); it != pageStack.end(); ++it)399 for (const SGUIPage& p : pageStack) 402 400 { 403 m_CurrentGUI = it->gui;404 it->gui->TickObjects();401 m_CurrentGUI = p.gui; 402 p.gui->TickObjects(); 405 403 } 406 404 m_CurrentGUI.reset(); 407 405 } … … 410 408 { 411 409 PROFILE3_GPU("gui"); 412 410 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(); 415 413 } 416 414 417 415 void CGUIManager::UpdateResolution() 418 416 { 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(); 421 419 } 422 420 423 bool CGUIManager::TemplateExists(const std::string& templateName) 421 bool CGUIManager::TemplateExists(const std::string& templateName) const 424 422 { 425 423 return m_TemplateLoader.TemplateExists(templateName); 426 424 } -
source/gui/GUIManager.h
19 19 #define INCLUDED_GUIMANAGER 20 20 21 21 #include <boost/unordered_set.hpp> 22 #include <set> 22 23 23 24 #include "lib/input.h" 24 25 #include "lib/file/vfs/vfs_path.h" … … 28 29 #include "scriptinterface/ScriptVal.h" 29 30 #include "scriptinterface/ScriptInterface.h" 30 31 31 #include <set>32 33 32 class CGUI; 34 33 class JSObject; 35 34 class IGUIObject; … … 106 105 /** 107 106 * See CGUI::GetPreDefinedColor; applies to the currently active page. 108 107 */ 109 bool GetPreDefinedColor(const CStr& name, CColor& output) ;108 bool GetPreDefinedColor(const CStr& name, CColor& output) const; 110 109 111 110 /** 112 111 * See CGUI::FindObjectByName; applies to the currently active page. … … 116 115 /** 117 116 * See CGUI::SendEventToAll; applies to the currently active page. 118 117 */ 119 void SendEventToAll(const CStr& eventName) ;118 void SendEventToAll(const CStr& eventName) const; 120 119 121 120 /** 122 121 * See CGUI::TickObjects; applies to @em all loaded pages. … … 143 142 /** 144 143 * Check if a template with this name exists 145 144 */ 146 bool TemplateExists(const std::string& templateName) ;145 bool TemplateExists(const std::string& templateName) const; 147 146 148 147 /** 149 148 * Retrieve the requested template, used for displaying faction specificities. -
source/gui/GUIRenderer.cpp
57 57 } 58 58 59 59 60 void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, const CStr& SpriteName, const CRect &Size, int CellID, std::map<CStr, CGUISprite*> &Sprites)60 void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites) 61 61 { 62 62 // This is called only when something has changed (like the size of the 63 63 // sprite), so it doesn't need to be particularly efficient. … … 72 72 return; 73 73 74 74 75 std::map<CStr, CGUISprite*>::iterator it 75 std::map<CStr, CGUISprite*>::iterator it(Sprites.find(SpriteName)); 76 76 if (it == Sprites.end()) 77 77 { 78 78 // Sprite not found. Check whether this a special sprite: … … 263 263 float TexHeight = m_Texture->GetHeight(); 264 264 265 265 if (!TexWidth || !TexHeight) 266 {267 266 return CRect(0, 0, 1, 1); 268 }269 267 270 268 // Textures are positioned by defining a rectangular block of the 271 269 // texture (usually the whole texture), and a rectangular block on … … 329 327 return TexCoords; 330 328 } 331 329 332 void GUIRenderer::Draw(DrawCalls &Calls, float Z)330 void GUIRenderer::Draw(DrawCalls& Calls, float Z) 333 331 { 334 332 // Called every frame, to draw the object (based on cached calculations) 335 333 -
source/gui/GUIRenderer.h
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 #ifndef GUIRenderer_h19 #define GUIRenderer_h18 #ifndef INCLUDED_GUIRENDERER 19 #define INCLUDED_GUIRENDERER 20 20 21 21 #include "graphics/ShaderTechnique.h" 22 22 #include "graphics/Texture.h" 23 23 #include "lib/res/handle.h" 24 24 #include "ps/CStr.h" 25 25 #include "ps/Shapes.h" 26 26 27 #include <vector> 27 28 28 29 struct SGUIImageEffects; … … 77 78 78 79 namespace GUIRenderer 79 80 { 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); 81 82 82 void Draw(DrawCalls &Calls, float Z);83 void Draw(DrawCalls& Calls, float Z); 83 84 } 84 85 85 #endif // GUIRenderer_h86 #endif // INCLUDED_GUIRENDERER -
source/gui/GUITooltip.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 18 18 #include "precompiled.h" 19 19 20 20 #include "GUITooltip.h" 21 #include "lib/timer.h" 22 #include "IGUIObject.h" 21 23 22 #include "CGUI.h" 24 23 #include "GUIutil.h" 24 #include "IGUIObject.h" 25 25 26 #include "lib/timer.h" 26 27 #include "ps/CLogger.h" 27 28 28 29 /* … … 137 138 return false; 138 139 } 139 140 140 void GUITooltip::ShowTooltip(IGUIObject* obj, CPospos, const CStr& style, CGUI* gui)141 void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI* gui) 141 142 { 142 143 ENSURE(obj); 143 144 … … 147 148 148 149 // Get the object referenced by 'tooltip_style' 149 150 IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style); 150 if (! 151 if (!tooltipobj) 151 152 { 152 153 LOGERROR("Cannot find tooltip named '%s'", style.c_str()); 153 154 return; … … 160 161 && !usedObjectName.empty()) 161 162 { 162 163 usedobj = gui->FindObjectByName(usedObjectName); 163 if (! 164 if (!usedobj) 164 165 { 165 166 LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); 166 167 return; … … 211 212 return; 212 213 213 214 IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style); 214 if (! 215 if (!tooltipobj) 215 216 { 216 217 LOGERROR("Cannot find tooltip named '%s'", style.c_str()); 217 218 return; … … 222 223 && !usedObjectName.empty()) 223 224 { 224 225 IGUIObject* usedobj = gui->FindObjectByName(usedObjectName); 225 if (! 226 if (!usedobj) 226 227 { 227 228 LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); 228 229 return; … … 247 248 248 249 } 249 250 250 static int GetTooltipDelay( CStr& style, CGUI* gui)251 static int GetTooltipDelay(const CStr& style, CGUI* gui) 251 252 { 252 253 int delay = 500; // default value (in msec) 253 254 254 255 IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style); 255 if (! 256 if (!tooltipobj) 256 257 { 257 258 LOGERROR("Cannot find tooltip object named '%s'", style.c_str()); 258 259 return delay; … … 261 262 return delay; 262 263 } 263 264 264 void GUITooltip::Update(IGUIObject* Nearest, CPosMousePos, CGUI* GUI)265 void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI) 265 266 { 266 267 // Called once per frame, so efficiency isn't vital 267 268 -
source/gui/GUITooltip.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 28 28 { 29 29 public: 30 30 GUITooltip(); 31 void Update(IGUIObject* Nearest, CPosMousePos, CGUI* GUI);31 void Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI); 32 32 33 33 private: 34 34 35 void ShowTooltip(IGUIObject* obj, CPospos, const CStr& style, CGUI* gui);35 void ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI* gui); 36 36 void HideTooltip(const CStr& style, CGUI* gui); 37 37 bool GetTooltip(IGUIObject* obj, CStr& style); 38 38 -
source/gui/GUIbase.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI base20 */21 22 18 #include "precompiled.h" 23 19 24 #include "ps/CLogger.h"25 20 #include "GUI.h" 26 21 27 //-------------------------------------------------------- 28 // Help Classes/Structs for the GUI implementation 29 //-------------------------------------------------------- 22 #include "ps/CLogger.h" 30 23 31 24 CClientArea::CClientArea() : pixel(0.f,0.f,0.f,0.f), percent(0.f,0.f,0.f,0.f) 32 25 { … … 42 35 { 43 36 } 44 37 45 CRect CClientArea::GetClientArea(const CRect &parent) const38 CRect CClientArea::GetClientArea(const CRect& parent) const 46 39 { 47 40 // If it's a 0 0 100% 100% we need no calculations 48 41 if (percent == CRect(0.f,0.f,100.f,100.f) && pixel == CRect(0.f,0.f,0.f,0.f)) … … 78 71 unsigned int coord = 0; 79 72 float pixels[4] = {0, 0, 0, 0}; 80 73 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) 82 75 { 83 76 switch (input[i]) 84 77 { … … 110 103 case ' ': 111 104 pixels[coord] += buffer.ToFloat(); 112 105 buffer = ""; 113 coord++;106 ++coord; 114 107 break; 115 108 default: 116 109 LOGWARNING("ClientArea definitions may only contain numerics. Your input: '%s'", Value.c_str()); … … 143 136 percent.bottom = percents[3]; 144 137 return true; 145 138 } 146 147 148 149 //--------------------------------------------------------150 // Error definitions151 //-------------------------------------------------------- -
source/gui/GUIbase.h
32 32 #ifndef INCLUDED_GUIBASE 33 33 #define INCLUDED_GUIBASE 34 34 35 36 //--------------------------------------------------------37 // Includes / Compiler directives38 //--------------------------------------------------------39 35 #include <map> 40 36 #include <vector> 41 37 38 #include "ps/CStr.h" 39 #include "ps/Errors.h" 42 40 // I would like to just forward declare CSize, but it doesn't 43 41 // seem to be defined anywhere in the predefined header. 44 42 #include "ps/Shapes.h" 45 43 46 #include "ps/CStr.h"47 48 #include "ps/Errors.h"49 50 //--------------------------------------------------------51 // Forward declarations52 //--------------------------------------------------------53 44 class IGUIObject; 54 45 55 //--------------------------------------------------------56 // Macros57 //--------------------------------------------------------58 59 46 // Object settings setups 60 61 47 // Setup an object's ConstructObject function 62 48 #define GUI_OBJECT(obj) \ 63 49 public: \ 64 static IGUIObject *ConstructObject() { return new obj(); }50 static IGUIObject* ConstructObject() { return new obj(); } 65 51 66 52 67 //--------------------------------------------------------68 // Types69 //--------------------------------------------------------70 71 53 /** 72 54 * Message types. 73 55 * @see SGUIMessage … … 193 175 /** 194 176 * Get client area rectangle when the parent is given 195 177 */ 196 CRect GetClientArea(const CRect &parent) const;178 CRect GetClientArea(const CRect& parent) const; 197 179 198 180 /** 199 181 * The ClientArea can be set from a string looking like: … … 217 199 } 218 200 }; 219 201 220 //-------------------------------------------------------- 221 // Error declarations 222 //-------------------------------------------------------- 202 223 203 ERROR_GROUP(GUI); 224 204 225 205 ERROR_TYPE(GUI, NullObjectProvided); … … 228 208 ERROR_TYPE(GUI, NameAmbiguity); 229 209 ERROR_TYPE(GUI, ObjectNeedsName); 230 210 231 #endif 211 #endif // INCLUDED_GUIBASE -
source/gui/GUItext.cpp
47 47 m_NewLine=false; 48 48 } 49 49 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 50 void CGUIString::GenerateTextCall(const CGUI* pGUI, SFeedback& Feedback, CStrIntern DefaultFont, const int& from, const int& to, const bool FirstLine, const IGUIObject* pObject) const 56 51 { 57 52 // Reset width and height, because they will be determined with incrementation 58 53 // or comparisons. … … 247 242 return true; 248 243 } 249 244 250 CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype) 245 CGUIString::TextChunk::Tag::TagType CGUIString::TextChunk::Tag::GetTagType(const CStrW& tagtype) const 251 246 { 252 247 if (tagtype == L"color") 253 248 return TAG_COLOR; … … 473 468 if (m_Words.size() <= 2) 474 469 return; 475 470 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()); 490 472 } -
source/gui/GUItext.h
210 210 * @return True if m_TagType was set. 211 211 */ 212 212 bool SetTagType(const CStrW& tagtype); 213 TagType GetTagType(const CStrW& tagtype) ;213 TagType GetTagType(const CStrW& tagtype) const; 214 214 215 215 216 216 /** … … 309 309 * to make several GenerateTextCall in different phases, 310 310 * it avoids duplicates. 311 311 */ 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; 318 313 319 314 /** 320 315 * Words … … 338 333 CStrW m_OriginalString; 339 334 }; 340 335 341 #endif 336 #endif // INCLUDED_GUITEXT -
source/gui/GUIutil.cpp
15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI utilities20 */21 22 18 #include "precompiled.h" 19 23 20 #include "GUI.h" 24 21 #include "GUIManager.h" 25 #include "maths/Matrix3D.h"26 27 extern int g_xres, g_yres;28 22 23 #include "maths/Matrix3D.h" 29 24 #include "ps/CLogger.h" 30 25 26 extern int g_xres, g_yres; 31 27 32 28 template <> 33 bool __ParseString<bool>(const CStrW& Value, bool &Output)29 bool __ParseString<bool>(const CStrW& Value, bool& Output) 34 30 { 35 31 if (Value == L"true") 36 32 Output = true; 37 else 38 if (Value == L"false") 33 else if (Value == L"false") 39 34 Output = false; 40 35 else 41 36 return false; … … 44 39 } 45 40 46 41 template <> 47 bool __ParseString<int>(const CStrW& Value, int &Output)42 bool __ParseString<int>(const CStrW& Value, int& Output) 48 43 { 49 44 Output = Value.ToInt(); 50 45 return true; 51 46 } 52 47 53 48 template <> 54 bool __ParseString<float>(const CStrW& Value, float &Output)49 bool __ParseString<float>(const CStrW& Value, float& Output) 55 50 { 56 51 Output = Value.ToFloat(); 57 52 return true; 58 53 } 59 54 60 55 template <> 61 bool __ParseString<CRect>(const CStrW& Value, CRect &Output)56 bool __ParseString<CRect>(const CStrW& Value, CRect& Output) 62 57 { 63 58 const unsigned int NUM_COORDS = 4; 64 59 float coords[NUM_COORDS]; 65 60 std::wstringstream stream; 66 61 stream.str(Value); 67 62 // Parse each coordinate 68 for (unsigned int i = 0; i < NUM_COORDS; i++)63 for (unsigned int i = 0; i < NUM_COORDS; ++i) 69 64 { 70 65 if (stream.eof()) 71 66 { … … 93 88 } 94 89 95 90 template <> 96 bool __ParseString<CClientArea>(const CStrW& Value, CClientArea &Output)91 bool __ParseString<CClientArea>(const CStrW& Value, CClientArea& Output) 97 92 { 98 93 return Output.SetClientArea(Value.ToUTF8()); 99 94 } 100 95 101 96 template <> 102 bool GUI<int>::ParseColor(const CStrW& Value, CColor &Output, int DefaultAlpha)97 bool GUI<int>::ParseColor(const CStrW& Value, CColor& Output, int DefaultAlpha) 103 98 { 104 99 // First, check our database in g_GUI for pre-defined colors 105 100 // If we find anything, we'll ignore DefaultAlpha … … 112 107 113 108 114 109 template <> 115 bool __ParseString<CColor>(const CStrW& Value, CColor &Output)110 bool __ParseString<CColor>(const CStrW& Value, CColor& Output) 116 111 { 117 112 // First, check our database in g_GUI for pre-defined colors 118 113 // If it fails, it won't do anything with Output … … 123 118 } 124 119 125 120 template <> 126 bool __ParseString<CSize>(const CStrW& Value, CSize &Output)121 bool __ParseString<CSize>(const CStrW& Value, CSize& Output) 127 122 { 128 123 const unsigned int NUM_COORDS = 2; 129 124 float coords[NUM_COORDS]; 130 125 std::wstringstream stream; 131 126 stream.str(Value); 132 127 // Parse each coordinate 133 for (unsigned int i = 0; i < NUM_COORDS; i++)128 for (unsigned int i = 0; i < NUM_COORDS; ++i) 134 129 { 135 130 if (stream.eof()) 136 131 { … … 158 153 } 159 154 160 155 template <> 161 bool __ParseString<CPos>(const CStrW& Value, CPos &Output)156 bool __ParseString<CPos>(const CStrW& Value, CPos& Output) 162 157 { 163 158 const unsigned int NUM_COORDS = 2; 164 159 float coords[NUM_COORDS]; 165 160 std::wstringstream stream; 166 161 stream.str(Value); 167 162 // Parse each coordinate 168 for (unsigned int i = 0; i < NUM_COORDS; i++)163 for (unsigned int i = 0; i < NUM_COORDS; ++i) 169 164 { 170 165 if (stream.eof()) 171 166 { … … 193 188 } 194 189 195 190 template <> 196 bool __ParseString<EAlign>(const CStrW& Value, EAlign &Output)191 bool __ParseString<EAlign>(const CStrW& Value, EAlign& Output) 197 192 { 198 193 if (Value == L"left") 199 194 Output = EAlign_Left; 200 else 201 if (Value == L"center") 195 else if (Value == L"center") 202 196 Output = EAlign_Center; 203 else 204 if (Value == L"right") 197 else if (Value == L"right") 205 198 Output = EAlign_Right; 206 199 else 207 200 return false; … … 210 203 } 211 204 212 205 template <> 213 bool __ParseString<EVAlign>(const CStrW& Value, EVAlign &Output)206 bool __ParseString<EVAlign>(const CStrW& Value, EVAlign& Output) 214 207 { 215 208 if (Value == L"top") 216 209 Output = EVAlign_Top; 217 else 218 if (Value == L"center") 210 else if (Value == L"center") 219 211 Output = EVAlign_Center; 220 else 221 if (Value == L"bottom") 212 else if (Value == L"bottom") 222 213 Output = EVAlign_Bottom; 223 214 else 224 215 return false; … … 227 218 } 228 219 229 220 template <> 230 bool __ParseString<CGUIString>(const CStrW& Value, CGUIString &Output)221 bool __ParseString<CGUIString>(const CStrW& Value, CGUIString& Output) 231 222 { 232 // TODO: i18n: Might want to translate the Value perhaps233 234 223 Output.SetValue(Value); 235 224 return true; 236 225 } … … 246 235 template <> 247 236 bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output) 248 237 { 249 // TODO: i18n: Might want to translate the Value perhaps250 251 238 Output = Value; 252 239 return true; 253 240 } 254 241 255 242 template <> 256 bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance &Output)243 bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance& Output) 257 244 { 258 245 Output = CGUISpriteInstance(Value.ToUTF8()); 259 246 return true; … … 288 275 //-------------------------------------------------------- 289 276 // Utilities implementation 290 277 //-------------------------------------------------------- 291 IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(CGUI &GUIinstance, const CStr& Object)278 IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(CGUI& GUIinstance, const CStr& Object) 292 279 { 293 280 // if (!GUIinstance.ObjectExists(Object)) 294 281 // return NULL; … … 296 283 return GUIinstance.m_pAllObjects.find(Object)->second; 297 284 } 298 285 299 const IGUIObject * CInternalCGUIAccessorBase::GetObjectPointer(const CGUI &GUIinstance, const CStr& Object)286 const IGUIObject* CInternalCGUIAccessorBase::GetObjectPointer(const CGUI& GUIinstance, const CStr& Object) 300 287 { 301 288 // if (!GUIinstance.ObjectExists(Object)) 302 289 // return NULL; … … 304 291 return GUIinstance.m_pAllObjects.find(Object)->second; 305 292 } 306 293 307 void CInternalCGUIAccessorBase::QueryResetting(IGUIObject *pObject)294 void CInternalCGUIAccessorBase::QueryResetting(IGUIObject* pObject) 308 295 { 309 296 GUI<>::RecurseObject(0, pObject, &IGUIObject::ResetStates); 310 297 } 311 298 312 void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, SGUIMessage &message)299 void CInternalCGUIAccessorBase::HandleMessage(IGUIObject* pObject, SGUIMessage& message) 313 300 { 314 301 pObject->HandleMessage(message); 315 302 } … … 335 322 //-------------------------------------------------------------------- 336 323 337 324 template <typename T> 338 PSRETURN GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)325 PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value) 339 326 { 340 327 ENSURE(pObject != NULL); 341 328 … … 362 349 } 363 350 364 351 template <typename T> 365 PSRETURN GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value)352 PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value) 366 353 { 367 354 T* v = NULL; 368 355 PSRETURN ret = GetSettingPointer(pObject, Setting, v); … … 384 371 } 385 372 386 373 template <typename T> 387 PSRETURN GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, 388 const T &Value, const bool& SkipMessage) 374 PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage) 389 375 { 390 376 ENSURE(pObject != NULL); 391 377 … … 413 399 { 414 400 RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize); 415 401 } 416 else 417 if (Setting == "hidden") 402 else if (Setting == "hidden") 418 403 { 419 404 // Hiding an object requires us to reset it and all children 420 405 if (IsBoolTrue(Value)) … … 432 417 433 418 // Instantiate templated functions: 434 419 #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); 438 423 #define GUITYPE_IGNORE_CGUISpriteInstance 439 424 #include "GUItypes.h" 440 425 #undef GUITYPE_IGNORE_CGUISpriteInstance … … 444 429 // you attempt to retrieve a sprite using GetSetting, since that copies the sprite 445 430 // and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer 446 431 // 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);432 template PSRETURN GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, CGUISpriteInstance*& Value); 433 template PSRETURN GUI<CGUISpriteInstance>::SetSetting(IGUIObject* pObject, const CStr& Setting, const CGUISpriteInstance& Value, const bool& SkipMessage); -
source/gui/GUIutil.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 32 32 #ifndef INCLUDED_GUIUTIL 33 33 #define INCLUDED_GUIUTIL 34 34 35 36 //--------------------------------------------------------37 // Includes / Compiler directives38 //--------------------------------------------------------39 #include "GUIbase.h"40 // TODO Gee: New41 35 #include "CGUI.h" 42 36 #include "CGUISprite.h" 37 #include "GUIbase.h" 43 38 #include "IGUIObject.h" 44 39 45 //--------------------------------------------------------46 // Help Classes/Structs for the GUI47 //--------------------------------------------------------48 49 40 class CClientArea; 50 41 class CGUIString; 51 42 class CMatrix3D; 52 43 53 44 template <typename T> 54 bool __ParseString(const CStrW& Value, T &tOutput);45 bool __ParseString(const CStrW& Value, T& tOutput); 55 46 56 47 // Model-view-projection matrix with (0,0) in top-left of screen 57 48 CMatrix3D GetDefaultGuiMatrix(); 58 49 59 //--------------------------------------------------------60 // Forward declarations61 //--------------------------------------------------------62 50 struct SGUIMessage; 63 51 64 52 /** … … 72 60 { 73 61 protected: 74 62 /// Get object pointer 75 static IGUIObject * GetObjectPointer(CGUI &GUIinstance, const CStr& Object);63 static IGUIObject* GetObjectPointer(CGUI& GUIinstance, const CStr& Object); 76 64 77 65 /// const version 78 static const IGUIObject * GetObjectPointer(const CGUI &GUIinstance, const CStr& Object);66 static const IGUIObject* GetObjectPointer(const CGUI& GUIinstance, const CStr& Object); 79 67 80 68 /// Wrapper for ResetStates 81 static void QueryResetting(IGUIObject *pObject);69 static void QueryResetting(IGUIObject* pObject); 82 70 83 static void HandleMessage(IGUIObject *pObject, SGUIMessage &message);71 static void HandleMessage(IGUIObject* pObject, SGUIMessage& message); 84 72 }; 85 73 86 74 … … 109 97 110 98 // Like GetSetting (below), but doesn't make a copy of the value 111 99 // (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); 113 101 114 102 /** 115 103 * Retrieves a setting by name from object pointer … … 118 106 * @param Setting Setting by name 119 107 * @param Value Stores value here, note type T! 120 108 */ 121 static PSRETURN GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value);109 static PSRETURN GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); 122 110 123 111 /** 124 112 * Sets a value by name using a real datatype as input. … … 131 119 * @param Value Sets value to this, note type T! 132 120 * @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true 133 121 */ 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); 136 123 137 124 /** 138 125 * Retrieves a setting by settings name and object name … … 142 129 * @param Setting Setting by name 143 130 * @param Value Stores value here, note type T! 144 131 */ 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) 148 133 { 149 134 if (!GUIinstance.ObjectExists(Object)) 150 135 return PSRETURN_GUI_NullObjectProvided; 151 136 152 137 // Retrieve pointer and call sibling function 153 const IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);138 const IGUIObject* pObject = GetObjectPointer(GUIinstance, Object); 154 139 155 140 return GetSetting(pObject, Setting, Value); 156 141 } … … 168 153 * @param Value Sets value to this, note type T! 169 154 * @param SkipMessage Does not send a GUIM_SETTINGS_UPDATED if true 170 155 */ 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) 175 157 { 176 158 if (!GUIinstance.ObjectExists(Object)) 177 159 return PSRETURN_GUI_NullObjectProvided; … … 181 163 // Important, we don't want to use this T, we want 182 164 // to use the standard T, since that will be the 183 165 // one with the friend relationship 184 IGUIObject *pObject = GetObjectPointer(GUIinstance, Object);166 IGUIObject* pObject = GetObjectPointer(GUIinstance, Object); 185 167 186 168 return SetSetting(pObject, Setting, Value, SkipMessage); 187 169 } … … 195 177 * @param sec Secondary sprite if Primary should fail 196 178 * @return Resulting string 197 179 */ 198 static const CGUISpriteInstance& FallBackSprite( 199 const CGUISpriteInstance& prim, 200 const CGUISpriteInstance& sec) 180 static const CGUISpriteInstance& FallBackSprite(const CGUISpriteInstance& prim, const CGUISpriteInstance& sec) 201 181 { 202 182 return (prim.IsEmpty() ? sec : prim); 203 183 } … … 210 190 * @return Resulting color 211 191 * @see FallBackSprite 212 192 */ 213 static CColor FallBackColor(const CColor &prim, const CColor &sec)193 static CColor FallBackColor(const CColor& prim, const CColor& sec) 214 194 { 215 195 // CColor() == null. 216 196 return ((prim!=CColor())?(prim):(sec)); … … 229 209 * 230 210 * @see __ParseString() 231 211 */ 232 static bool ParseString(const CStrW& Value, T &tOutput)212 static bool ParseString(const CStrW& Value, T& tOutput) 233 213 { 234 214 return __ParseString<T>(Value, tOutput); 235 215 } 236 216 237 static bool ParseColor(const CStrW& Value, CColor &tOutput, int DefaultAlpha);217 static bool ParseColor(const CStrW& Value, CColor& tOutput, int DefaultAlpha); 238 218 239 219 private: 240 220 241 221 // 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); 244 224 typedef void (IGUIObject::*void_Object_pFunction)(); 245 225 246 226 /** … … 269 249 * @throws PSERROR Depends on what pFunc might throw. PSERROR is standard. 270 250 * Itself doesn't throw anything. 271 251 */ 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) 273 253 { 274 254 // TODO Gee: Don't run this for the base object. 275 255 if (CheckIfRestricted(RR, pObject)) … … 278 258 (pObject->*pFunc)(Argument); 279 259 280 260 // 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); 286 263 } 287 264 288 265 /** … … 290 267 * 291 268 * @see RecurseObject() 292 269 */ 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) 294 271 { 295 272 if (CheckIfRestricted(RR, pObject)) 296 273 return; … … 298 275 (pObject->*pFunc)(Argument); 299 276 300 277 // 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); 306 280 } 307 281 308 282 /** … … 310 284 * 311 285 * @see RecurseObject() 312 286 */ 313 static void RecurseObject(int RR, IGUIObject *pObject, void_Object_pFunction pFunc)287 static void RecurseObject(int RR, IGUIObject* pObject, void_Object_pFunction pFunc) 314 288 { 315 289 if (CheckIfRestricted(RR, pObject)) 316 290 return; … … 318 292 (pObject->*pFunc)(); 319 293 320 294 // 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); 326 297 } 327 298 328 299 private: … … 336 307 * @param pObject Object 337 308 * @return true if restricted 338 309 */ 339 static bool CheckIfRestricted(int RR, IGUIObject *pObject)310 static bool CheckIfRestricted(int RR, IGUIObject* pObject) 340 311 { 341 312 // Statically initialise some strings, so we don't have to do 342 313 // 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"); 346 317 347 318 if (RR & GUIRR_HIDDEN) 348 319 { … … 374 345 } 375 346 }; 376 347 377 #endif 348 #endif // INCLUDED_GUIUTIL -
source/gui/IGUIButtonBehavior.cpp
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 IGUIButtonBehavior20 */21 22 18 #include "precompiled.h" 23 #include "ps/CLogger.h" 19 24 20 #include "GUI.h" 25 21 22 #include "ps/CLogger.h" 26 23 #include "soundmanager/ISoundManager.h" 27 24 28 //-------------------------------------------------------------------29 // Constructor / Destructor30 //-------------------------------------------------------------------31 25 IGUIButtonBehavior::IGUIButtonBehavior() : m_Pressed(false) 32 26 { 33 27 } … … 36 30 { 37 31 } 38 32 39 void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)33 void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) 40 34 { 41 35 bool enabled; 42 36 GUI<bool>::GetSetting(this, "enabled", enabled); … … 45 39 switch (Message.type) 46 40 { 47 41 case GUIM_MOUSE_ENTER: 48 {49 42 if (!enabled) 50 43 break; 51 44 52 45 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) 53 46 g_SoundManager->PlayAsUI(soundPath.c_str(), false); 54 47 break; 55 }56 48 57 49 case GUIM_MOUSE_LEAVE: 58 {59 50 if (!enabled) 60 51 break; 61 52 62 53 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) 63 54 g_SoundManager->PlayAsUI(soundPath.c_str(), false); 64 55 break; 65 }66 56 67 57 case GUIM_MOUSE_DBLCLICK_LEFT: 68 {69 58 if (!enabled) 70 59 break; 71 60 … … 73 62 // doubleclick event, we let it handle playing sounds. 74 63 SendEvent(GUIM_DOUBLE_PRESSED, "doublepress"); 75 64 break; 76 }77 65 78 66 case GUIM_MOUSE_PRESS_LEFT: 79 {80 67 if (!enabled) 81 68 { 82 69 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) … … 90 77 SendEvent(GUIM_PRESSED, "press"); 91 78 m_Pressed = true; 92 79 break; 93 }94 80 95 81 case GUIM_MOUSE_DBLCLICK_RIGHT: 96 {97 82 if (!enabled) 98 83 break; 99 84 … … 101 86 // doubleclick event, we let it handle playing sounds. 102 87 SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright"); 103 88 break; 104 } 89 105 90 case GUIM_MOUSE_PRESS_RIGHT: 106 {107 91 if (!enabled) 108 92 { 109 93 if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) … … 117 101 SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright"); 118 102 m_PressedRight = true; 119 103 break; 120 }121 104 122 105 case GUIM_MOUSE_RELEASE_RIGHT: 123 {124 106 if (!enabled) 125 107 break; 126 108 … … 131 113 g_SoundManager->PlayAsUI(soundPath.c_str(), false); 132 114 } 133 115 break; 134 }135 116 136 117 case GUIM_MOUSE_RELEASE_LEFT: 137 {138 118 if (!enabled) 139 119 break; 140 120 … … 145 125 g_SoundManager->PlayAsUI(soundPath.c_str(), false); 146 126 } 147 127 break; 148 }149 128 150 129 default: 151 130 break; … … 167 146 GUI<CColor>::GetSetting(this, "textcolor_disabled", color2); 168 147 return GUI<>::FallBackColor(color2, color); 169 148 } 170 else 171 if (m_MouseHovering) 149 else if (m_MouseHovering) 172 150 { 173 151 if (m_Pressed) 174 152 { … … 181 159 return GUI<>::FallBackColor(color2, color); 182 160 } 183 161 } 184 else return color; 162 else 163 return color; 185 164 } 186 165 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) 166 void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id) 194 167 { 195 if (GetGUI()) 196 { 197 bool enabled; 198 GUI<bool>::GetSetting(this, "enabled", enabled); 168 if (!GetGUI()) 169 return; 199 170 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 else207 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); 209 180 else 210 GetGUI()->DrawSprite( sprite, cell_id, z, rect);181 GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect); 211 182 } 183 else 184 GetGUI()->DrawSprite(sprite, cell_id, z, rect); 212 185 } -
source/gui/IGUIButtonBehavior.h
35 35 #ifndef INCLUDED_IGUIBUTTONBEHAVIOR 36 36 #define INCLUDED_IGUIBUTTONBEHAVIOR 37 37 38 //--------------------------------------------------------39 // Includes / Compiler directives40 //--------------------------------------------------------41 38 #include "GUI.h" 42 39 43 40 class CGUISpriteInstance; 44 41 45 //--------------------------------------------------------46 // Macros47 //--------------------------------------------------------48 49 //--------------------------------------------------------50 // Types51 //--------------------------------------------------------52 53 //--------------------------------------------------------54 // Declarations55 //--------------------------------------------------------56 57 42 /** 58 43 * Appends button behaviours to the IGUIObject. 59 44 * Can be used with multiple inheritance alongside … … 70 55 /** 71 56 * @see IGUIObject#HandleMessage() 72 57 */ 73 virtual void HandleMessage(SGUIMessage &Message);58 virtual void HandleMessage(SGUIMessage& Message); 74 59 75 60 /** 76 61 * This is a function that lets a button being drawn, … … 89 74 * @param cell_id Identifies the icon to be used (if the sprite contains 90 75 * cell-using images) 91 76 */ 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); 99 78 100 79 /** 101 80 * Choosing which color of the following according to object enabled/hovered/pressed status: … … 129 108 bool m_PressedRight; 130 109 }; 131 110 132 #endif 111 #endif // INCLUDED_IGUIBUTTONBEHAVIOR -
source/gui/IGUIObject.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 IGUIObject20 */21 22 18 #include "precompiled.h" 19 23 20 #include "GUI.h" 24 21 25 #include "gui/scripting/JSInterface_IGUIObject.h"26 22 #include "gui/scripting/JSInterface_GUITypes.h" 27 #include "scriptinterface/ScriptInterface.h" 28 23 #include "gui/scripting/JSInterface_IGUIObject.h" 29 24 #include "ps/CLogger.h" 25 #include "scriptinterface/ScriptInterface.h" 30 26 31 27 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) 28 IGUIObject::IGUIObject() 29 : m_pGUI(NULL), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime() 43 30 { 44 31 AddSetting(GUIST_bool, "enabled"); 45 32 AddSetting(GUIST_bool, "hidden"); … … 58 45 GUI<bool>::SetSetting(this, "ghost", false); 59 46 GUI<bool>::SetSetting(this, "enabled", true); 60 47 GUI<bool>::SetSetting(this, "absolute", true); 61 62 63 for (int i=0; i<6; i++)64 m_LastClickTime[i]=0;65 48 } 66 49 67 50 IGUIObject::~IGUIObject() 68 51 { 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) 72 54 { 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; 77 57 #include "GUItypes.h" 78 58 #undef TYPE 79 59 default: 80 60 debug_warn(L"Invalid setting type"); 81 }82 61 } 83 }84 62 85 63 if (m_pGUI) 86 64 JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this); … … 89 67 //------------------------------------------------------------------- 90 68 // Functions 91 69 //------------------------------------------------------------------- 92 void IGUIObject::SetGUI(CGUI * const &pGUI)70 void IGUIObject::SetGUI(CGUI* const& pGUI) 93 71 { 94 72 if (!m_pGUI) 95 73 JS_AddExtraGCRootsTracer(pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this); 96 74 m_pGUI = pGUI; 97 75 } 98 76 99 void IGUIObject::AddChild(IGUIObject *pChild)77 void IGUIObject::AddChild(IGUIObject* pChild) 100 78 { 101 //102 79 // ENSURE(pChild); 103 80 104 81 pChild->SetParent(this); … … 122 99 { 123 100 // If anything went wrong, reverse what we did and throw 124 101 // an exception telling it never added a child 125 m_Children.erase( m_Children.end()-1);102 m_Children.erase(m_Children.end()-1); 126 103 127 104 throw; 128 105 } … … 130 107 // else do nothing 131 108 } 132 109 133 void IGUIObject::AddToPointersMap(map_pObjects &ObjectMap)110 void IGUIObject::AddToPointersMap(map_pObjects& ObjectMap) 134 111 { 135 112 // Just don't do anything about the top node 136 113 if (m_pParent == NULL) … … 164 141 m_Settings[Name].m_pSetting = new type(); \ 165 142 break; 166 143 167 void IGUIObject::AddSetting(const EGUISettingType &Type, const CStr& Name)144 void IGUIObject::AddSetting(const EGUISettingType& Type, const CStr& Name) 168 145 { 169 146 // Is name already taken? 170 147 if (m_Settings.count(Name) >= 1) … … 188 165 189 166 bool IGUIObject::MouseOver() 190 167 { 191 if (!GetGUI())168 if (!GetGUI()) 192 169 throw PSERROR_GUI_OperationNeedsGUIObject(); 193 170 194 171 return m_CachedActualSize.PointInside(GetMousePos()); … … 204 181 return ((GetGUI())?(GetGUI()->m_MousePos):CPos()); 205 182 } 206 183 207 void IGUIObject::UpdateMouseOver(IGUIObject * const &pMouseOver)184 void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver) 208 185 { 209 186 // Check if this is the object being hovered. 210 187 if (pMouseOver == this) … … 255 232 PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage) 256 233 { 257 234 if (!SettingExists(Setting)) 258 {259 235 return PSRETURN_GUI_InvalidSetting; 260 }261 236 262 237 // Get setting 263 238 SGUISetting set = m_Settings[Setting]; … … 277 252 #undef TYPE 278 253 279 254 280 PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const255 PSRETURN IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType& Type) const 281 256 { 282 257 if (!SettingExists(Setting)) 283 {284 258 return LogInvalidSettings(Setting); 285 }286 259 287 260 if (m_Settings.find(Setting) == m_Settings.end()) 288 {289 261 return LogInvalidSettings(Setting); 290 }291 262 292 263 Type = m_Settings.find(Setting)->second.m_Type; 293 264 … … 295 266 } 296 267 297 268 298 void IGUIObject::ChooseMouseOverAndClosest(IGUIObject* &pObject)269 void IGUIObject::ChooseMouseOverAndClosest(IGUIObject*& pObject) 299 270 { 300 if (MouseOver()) 271 if (!MouseOver()) 272 return; 273 274 // Check if we've got competition at all 275 if (pObject == NULL) 301 276 { 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 } 308 280 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; 315 286 } 316 287 } 317 288 318 IGUIObject *IGUIObject::GetParent() const289 IGUIObject* IGUIObject::GetParent() const 319 290 { 320 291 // Important, we're not using GetParent() for these 321 292 // checks, that could screw it up … … 367 338 } 368 339 } 369 340 370 void IGUIObject::LoadStyle(CGUI &GUIinstance, const CStr& StyleName)341 void IGUIObject::LoadStyle(CGUI& GUIinstance, const CStr& StyleName) 371 342 { 372 343 // Fetch style 373 344 if (GUIinstance.m_Styles.count(StyleName)==1) … … 380 351 } 381 352 } 382 353 383 void IGUIObject::LoadStyle(const SGUIStyle &Style)354 void IGUIObject::LoadStyle(const SGUIStyle& Style) 384 355 { 385 356 // 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) 388 358 { 389 359 // Try set setting in object 390 SetSetting( cit->first, cit->second);360 SetSetting(p.first, p.second); 391 361 392 362 // It doesn't matter if it fail, it's not suppose to be able to set every setting. 393 363 // since it's generic. … … 571 541 return (GetGUI() != 0 && m_pParent == GetGUI()->m_BaseObject); 572 542 } 573 543 574 void IGUIObject::TraceMember(JSTracer *trc)544 void IGUIObject::TraceMember(JSTracer* trc) 575 545 { 576 546 for (auto& handler : m_ScriptHandlers) 577 547 JS_CallHeapObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); 578 548 } 579 549 580 PSRETURN IGUIObject::LogInvalidSettings(const CStr8 &Setting) const550 PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const 581 551 { 582 552 LOGWARNING("IGUIObject: setting %s was not found on an object", 583 553 Setting.c_str()); -
source/gui/IGUIObject.h
43 43 #ifndef INCLUDED_IGUIOBJECT 44 44 #define INCLUDED_IGUIOBJECT 45 45 46 //--------------------------------------------------------47 // Includes / Compiler directives48 //--------------------------------------------------------49 46 #include "GUIbase.h" 50 47 #include "GUItext.h" 51 #include <string>52 #include <vector>53 #include "lib/input.h" // just for IN_PASS54 48 49 #include "gui/scripting/JSInterface_IGUIObject.h" 50 #include "lib/input.h" // just for IN_PASS 55 51 #include "ps/XML/Xeromyces.h" 56 52 57 #include "gui/scripting/JSInterface_IGUIObject.h" 53 #include <string> 54 #include <vector> 58 55 59 56 struct SGUISetting; 60 57 struct SGUIStyle; 61 58 class CGUI; 62 59 63 //--------------------------------------------------------64 // Macros65 //--------------------------------------------------------66 67 //--------------------------------------------------------68 // Types69 //--------------------------------------------------------70 71 60 class JSObject; 72 61 73 //--------------------------------------------------------74 // Error declarations75 //--------------------------------------------------------76 77 62 ERROR_TYPE(GUI, UnableToParse); 78 63 79 //--------------------------------------------------------80 // Declarations81 //--------------------------------------------------------82 83 64 /** 84 65 * Setting Type 85 66 * @see SGUISetting … … 192 173 * @throws PSERROR_GUI_ObjectNeedsName Name is missing 193 174 * @throws PSERROR_GUI_NameAmbiguity Name is already taken 194 175 */ 195 void AddToPointersMap(map_pObjects &ObjectMap);176 void AddToPointersMap(map_pObjects& ObjectMap); 196 177 197 178 /** 198 179 * Notice nothing will be returned or thrown if the child hasn't … … 210 191 * 211 192 * @throws PSERROR_GUI from CGUI::UpdateObjects(). 212 193 */ 213 void AddChild(IGUIObject *pChild);194 void AddChild(IGUIObject* pChild); 214 195 215 196 //@} 216 197 //-------------------------------------------------------- 217 /** @name Iterate */ 198 /** @name Iterate 199 * Used to iterate over all children of this object. 200 */ 218 201 //-------------------------------------------------------- 219 202 //@{ 220 203 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(); } 223 206 224 207 //@} 225 208 //-------------------------------------------------------- … … 264 247 * @param Type Stores an EGUISettingType 265 248 * @return PSRETURN (PSRETURN_OK if successful) 266 249 */ 267 PSRETURN GetSettingType(const CStr& Setting, EGUISettingType &Type) const;250 PSRETURN GetSettingType(const CStr& Setting, EGUISettingType& Type) const; 268 251 269 252 /** 270 253 * Set the script handler for a particular object-specific action … … 300 283 * @param Type Setting type 301 284 * @param Name Setting reference name 302 285 */ 303 void AddSetting(const EGUISettingType &Type, const CStr& Name);286 void AddSetting(const EGUISettingType& Type, const CStr& Name); 304 287 305 288 /** 306 289 * Calls Destroy on all children, and deallocates all memory. … … 346 329 * @param GUIinstance Reference to the GUI 347 330 * @param StyleName Style by name 348 331 */ 349 void LoadStyle(CGUI &GUIinstance, const CStr& StyleName);332 void LoadStyle(CGUI& GUIinstance, const CStr& StyleName); 350 333 351 334 /** 352 335 * Loads a style. 353 336 * 354 337 * @param Style The style object. 355 338 */ 356 void LoadStyle(const SGUIStyle &Style);339 void LoadStyle(const SGUIStyle& Style); 357 340 358 341 /** 359 342 * Returns not the Z value, but the actual buffered Z value, i.e. if it's … … 364 347 */ 365 348 virtual float GetBufferedZ() const; 366 349 367 void SetGUI(CGUI * const &pGUI);350 void SetGUI(CGUI* const& pGUI); 368 351 369 352 /** 370 353 * Set parent of this object 371 354 */ 372 void SetParent(IGUIObject *pParent) { m_pParent = pParent; }355 void SetParent(IGUIObject* pParent) { m_pParent = pParent; } 373 356 374 357 /** 375 358 * Reset internal state of this object … … 381 364 } 382 365 383 366 public: 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; } 386 369 387 370 /** 388 371 * Take focus! … … 404 387 * 405 388 * @return Pointer to parent 406 389 */ 407 IGUIObject *GetParent() const;390 IGUIObject* GetParent() const; 408 391 409 392 /** 410 393 * Get Mouse from CGUI. … … 419 402 * Notice 'false' is default, because an object not using this function, should not 420 403 * have any additional children (and this function should never be called). 421 404 */ 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 } 424 409 425 410 /** 426 411 * Cached size, real size m_Size is actually dependent on resolution … … 466 451 * @param pMouseOver Object that is currently hovered, 467 452 * can OF COURSE be NULL too! 468 453 */ 469 void UpdateMouseOver(IGUIObject * const &pMouseOver);454 void UpdateMouseOver(IGUIObject* const& pMouseOver); 470 455 471 456 //@} 472 457 private: … … 487 472 * @param pObject Object pointer, can be either the old one, or 488 473 * the new one. 489 474 */ 490 void ChooseMouseOverAndClosest(IGUIObject* &pObject);475 void ChooseMouseOverAndClosest(IGUIObject*& pObject); 491 476 492 477 // Is the object a Root object, in philosophy, this means it 493 478 // has got no parent, and technically, it's got the m_BaseObject … … 501 486 */ 502 487 PSRETURN LogInvalidSettings(const CStr8& Setting) const; 503 488 504 static void Trace(JSTracer *trc, void *data)489 static void Trace(JSTracer* trc, void* data) 505 490 { 506 491 reinterpret_cast<IGUIObject*>(data)->TraceMember(trc); 507 492 } 508 493 509 void TraceMember(JSTracer *trc);494 void TraceMember(JSTracer* trc); 510 495 511 496 // Variables 512 497 … … 579 564 virtual bool MouseOver() { return false; } 580 565 }; 581 566 582 #endif 567 #endif // INCLUDED_IGUIOBJECT -
source/gui/IGUIScrollBar.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 IGUIScrollBar20 */21 22 18 #include "precompiled.h" 19 23 20 #include "GUI.h" 24 21 #include "maths/MathUtil.h" 25 22 26 //-------------------------------------------------------------------27 // IGUIScrollBar28 //-------------------------------------------------------------------29 23 IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL), 30 24 m_X(300.f), m_Y(300.f), 31 25 m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division. … … 48 42 { 49 43 if (!GetStyle()) 50 44 return; 45 51 46 float min = GetStyle()->m_MinimumBarSize; 52 47 float max = GetStyle()->m_MaximumBarSize; 53 48 float length = m_Length; … … 66 61 m_BarSize = clamp(length * std::min((float)m_ScrollSpace / (float)m_ScrollRange, 1.f), min, max); 67 62 } 68 63 69 const SGUIScrollBarStyle *IGUIScrollBar::GetStyle() const64 const SGUIScrollBarStyle* IGUIScrollBar::GetStyle() const 70 65 { 71 66 if (!m_pHostObject) 72 67 return NULL; … … 74 69 return m_pHostObject->GetScrollBarStyle(m_ScrollBarStyle); 75 70 } 76 71 77 CGUI *IGUIScrollBar::GetGUI() const72 CGUI* IGUIScrollBar::GetGUI() const 78 73 { 79 74 if (!m_pHostObject) 80 75 return NULL; … … 87 82 if (m_Pos < 0.f || 88 83 m_ScrollRange < m_ScrollSpace) // <= scrolling not applicable 89 84 m_Pos = 0.f; 90 else 91 if (m_Pos > GetMaxPos()) 85 else if (m_Pos > GetMaxPos()) 92 86 m_Pos = GetMaxPos(); 93 87 } 94 88 95 void IGUIScrollBar::HandleMessage(SGUIMessage &Message)89 void IGUIScrollBar::HandleMessage(SGUIMessage& Message) 96 90 { 97 91 switch (Message.type) 98 92 { 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! 116 96 117 if (!m_ButtonMinusHovered) 118 m_ButtonMinusPressed = false; 97 CPos mouse = m_pHostObject->GetMousePos(); 119 98 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(); 123 104 } 124 105 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); 129 110 130 CPos mouse = m_pHostObject->GetMousePos(); 111 if (!m_ButtonMinusHovered) 112 m_ButtonMinusPressed = false; 131 113 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) 171 122 break; 172 }173 123 174 case GUIM_MOUSE_RELEASE_LEFT: 124 CPos mouse = m_pHostObject->GetMousePos(); 125 126 // if bar is pressed 127 if (GetBarRect().PointInside(mouse)) 175 128 { 176 m_B uttonMinusPressed = false;177 m_B uttonPlusPressed = false;178 break;129 m_BarPressed = true; 130 m_BarPressedAtPos = mouse; 131 m_PosWhenPressed = m_Pos; 179 132 } 180 181 case GUIM_MOUSE_WHEEL_UP:133 // if button-minus is pressed 134 else if (m_ButtonMinusHovered) 182 135 { 136 m_ButtonMinusPressed = true; 183 137 ScrollMinus(); 184 // Since the scroll was changed, let's simulate a mouse movement185 // to check if scrollbar now is hovered186 SGUIMessage msg(GUIM_MOUSE_MOTION);187 HandleMessage(msg);188 break;189 138 } 190 191 case GUIM_MOUSE_WHEEL_DOWN:139 // if button-plus is pressed 140 else if (m_ButtonPlusHovered) 192 141 { 142 m_ButtonPlusPressed = true; 193 143 ScrollPlus(); 194 // Since the scroll was changed, let's simulate a mouse movement195 // to check if scrollbar now is hovered196 SGUIMessage msg(GUIM_MOUSE_MOTION);197 HandleMessage(msg);198 break;199 144 } 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 } 200 165 201 default: 202 break; 166 case GUIM_MOUSE_RELEASE_LEFT: 167 { 168 m_ButtonMinusPressed = false; 169 m_ButtonPlusPressed = false; 170 break; 171 } 172 173 case GUIM_MOUSE_WHEEL_UP: 174 { 175 ScrollMinus(); 176 // Since the scroll was changed, let's simulate a mouse movement 177 // to check if scrollbar now is hovered 178 SGUIMessage msg(GUIM_MOUSE_MOTION); 179 HandleMessage(msg); 180 break; 181 } 182 183 case GUIM_MOUSE_WHEEL_DOWN: 184 { 185 ScrollPlus(); 186 // Since the scroll was changed, let's simulate a mouse movement 187 // to check if scrollbar now is hovered 188 SGUIMessage msg(GUIM_MOUSE_MOTION); 189 HandleMessage(msg); 190 break; 191 } 192 193 default: 194 break; 203 195 } 204 196 } -
source/gui/IGUIScrollBar.h
37 37 #ifndef INCLUDED_IGUISCROLLBAR 38 38 #define INCLUDED_IGUISCROLLBAR 39 39 40 //--------------------------------------------------------41 // Includes / Compiler directives42 //--------------------------------------------------------43 40 #include "GUI.h" 44 41 45 //--------------------------------------------------------46 // Declarations47 //--------------------------------------------------------48 49 42 /** 50 43 * The GUI Scroll-bar style. Tells us how scroll-bars look and feel. 51 44 * … … 178 171 * 179 172 * @see IGUIObject#HandleMessage() 180 173 */ 181 virtual void HandleMessage(SGUIMessage &Message)=0;174 virtual void HandleMessage(SGUIMessage& Message)=0; 182 175 183 176 /** 184 177 * Set m_Pos with g_mouse_x/y input, i.e. when draggin. 185 178 */ 186 virtual void SetPosFromMousePos(const CPos &mouse)=0;179 virtual void SetPosFromMousePos(const CPos& mouse)=0; 187 180 188 181 /** 189 182 * Hovering the scroll minus button … … 240 233 * Set host object, must be done almost at creation of scroll bar. 241 234 * @param pOwner Pointer to host object. 242 235 */ 243 void SetHostObject(IGUIScrollBarOwner 236 void SetHostObject(IGUIScrollBarOwner* pOwner) { m_pHostObject = pOwner; } 244 237 245 238 /** 246 239 * Get GUI pointer 247 240 * @return CGUI pointer 248 241 */ 249 CGUI *GetGUI() const;242 CGUI* GetGUI() const; 250 243 251 244 /** 252 245 * Set GUI pointer 253 246 * @param pGUI pointer to CGUI object. 254 247 */ 255 void SetGUI(CGUI *pGUI) { m_pGUI = pGUI; }248 void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; } 256 249 257 250 /** 258 251 * Set Width … … 312 305 * Get style used by the scrollbar 313 306 * @return Scroll bar style struct. 314 307 */ 315 const SGUIScrollBarStyle 308 const SGUIScrollBarStyle* GetStyle() const; 316 309 317 310 /** 318 311 * Get the rectangle of the actual BAR. not the whole scroll-bar. … … 451 444 //@} 452 445 }; 453 446 454 #endif 447 #endif // INCLUDED_IGUISCROLLBAR -
source/gui/IGUIScrollBarOwner.cpp
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 IGUIScrollBarOwner20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h"24 19 20 #include "GUI.h" 25 21 26 //-------------------------------------------------------------------27 // Constructor / Destructor28 //-------------------------------------------------------------------29 22 IGUIScrollBarOwner::IGUIScrollBarOwner() 30 23 { 31 24 } 32 25 33 26 IGUIScrollBarOwner::~IGUIScrollBarOwner() 34 27 { 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; 41 30 } 42 31 43 32 void IGUIScrollBarOwner::ResetStates() 44 33 { 45 34 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); 52 38 } 53 39 54 void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar 40 void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar* scrollbar) 55 41 { 56 42 scrollbar->SetHostObject(this); 57 43 scrollbar->SetGUI(GetGUI()); 58 44 m_ScrollBars.push_back(scrollbar); 59 45 } 60 46 61 const SGUIScrollBarStyle 47 const SGUIScrollBarStyle* IGUIScrollBarOwner::GetScrollBarStyle(const CStr& style) const 62 48 { 63 49 if (!GetGUI()) 64 50 { … … 76 62 return &it->second; 77 63 } 78 64 79 void IGUIScrollBarOwner::HandleMessage(SGUIMessage &Message)65 void IGUIScrollBarOwner::HandleMessage(SGUIMessage& msg) 80 66 { 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); 86 69 } 87 70 88 71 void IGUIScrollBarOwner::Draw() 89 72 { 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(); 95 75 } -
source/gui/IGUIScrollBarOwner.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 GUI Object Base - Scroll-bar owner20 21 --Overview--22 23 Base-class this if you want scroll-bars in an object.24 25 --More info--26 27 Check GUI.h28 29 */30 31 18 #ifndef INCLUDED_IGUISCROLLBAROWNER 32 19 #define INCLUDED_IGUISCROLLBAROWNER 33 20 34 //--------------------------------------------------------35 // Includes / Compiler directives36 //--------------------------------------------------------37 21 #include "GUI.h" 38 22 39 23 struct SGUIScrollBarStyle; 40 24 class IGUIScrollBar; 41 25 42 //--------------------------------------------------------43 // Macros44 //--------------------------------------------------------45 46 //--------------------------------------------------------47 // Types48 //--------------------------------------------------------49 50 //--------------------------------------------------------51 // Declarations52 //--------------------------------------------------------53 54 26 /** 55 27 * Base-class this if you want an object to contain 56 28 * one, or several, scroll-bars. … … 71 43 /** 72 44 * @see IGUIObject#HandleMessage() 73 45 */ 74 virtual void HandleMessage(SGUIMessage &Message);46 virtual void HandleMessage(SGUIMessage& Message); 75 47 76 48 /** 77 49 * @see IGUIObject#ResetStates() … … 81 53 /** 82 54 * Interface for the m_ScrollBar to use. 83 55 */ 84 virtual const SGUIScrollBarStyle *GetScrollBarStyle(const CStr& style) const;56 virtual const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const; 85 57 86 58 /** 87 59 * Add a scroll-bar 88 60 */ 89 virtual void AddScrollBar(IGUIScrollBar 61 virtual void AddScrollBar(IGUIScrollBar* scrollbar); 90 62 91 63 /** 92 64 * Get Scroll Bar reference (it should be transparent it's actually 93 65 * pointers). 94 66 */ 95 virtual IGUIScrollBar & GetScrollBar(const int &index)67 virtual IGUIScrollBar& GetScrollBar(const int& index) 96 68 { 97 69 return *m_ScrollBars[index]; 98 70 } … … 106 78 std::vector<IGUIScrollBar*> m_ScrollBars; 107 79 }; 108 80 109 #endif 81 #endif // INCLUDED_IGUISCROLLBAROWNER -
source/gui/IGUITextOwner.cpp
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 15 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 16 */ 17 17 18 /*19 IGUITextOwner20 */21 22 18 #include "precompiled.h" 23 #include "GUI.h"24 19 20 #include "GUI.h" 25 21 26 //-------------------------------------------------------------------27 // Constructor / Destructor28 //-------------------------------------------------------------------29 22 IGUITextOwner::IGUITextOwner() : m_GeneratedTextsValid(false) 30 23 { 31 24 } 32 25 33 26 IGUITextOwner::~IGUITextOwner() 34 27 { 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; 41 30 } 42 31 43 void IGUITextOwner::AddText(SGUIText 32 void IGUITextOwner::AddText(SGUIText* text) 44 33 { 45 34 m_GeneratedTexts.push_back(text); 46 35 } 47 36 48 void IGUITextOwner::HandleMessage(SGUIMessage &Message)37 void IGUITextOwner::HandleMessage(SGUIMessage& Message) 49 38 { 50 39 switch (Message.type) 51 40 { … … 78 67 m_GeneratedTextsValid = false; 79 68 } 80 69 81 void IGUITextOwner::DrawText( int index, const CColor& color, const CPos& pos, float z, const CRect& clipping)70 void IGUITextOwner::DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping) 82 71 { 83 72 if (!m_GeneratedTextsValid) 84 73 { … … 86 75 m_GeneratedTextsValid = true; 87 76 } 88 77 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"); 94 79 95 80 if (GetGUI()) 96 {97 81 GetGUI()->DrawText(*m_GeneratedTexts[index], color, pos, z, clipping); 98 }99 82 } 100 83 101 void IGUITextOwner::CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text)84 void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text) 102 85 { 103 86 EVAlign valign; 104 87 GUI<EVAlign>::GetSetting(this, "text_valign", valign); -
source/gui/IGUITextOwner.h
1 /* Copyright (C) 20 09Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 35 35 #ifndef INCLUDED_IGUITEXTOWNER 36 36 #define INCLUDED_IGUITEXTOWNER 37 37 38 //--------------------------------------------------------39 // Includes / Compiler directives40 //--------------------------------------------------------41 38 #include "GUI.h" 42 39 43 //--------------------------------------------------------44 // Macros45 //--------------------------------------------------------46 47 //--------------------------------------------------------48 // Types49 //--------------------------------------------------------50 51 //--------------------------------------------------------52 // Declarations53 //--------------------------------------------------------54 55 40 /** 56 41 * Framework for handling Output text. 57 42 * … … 66 51 /** 67 52 * Adds a text object. 68 53 */ 69 void AddText(SGUIText 54 void AddText(SGUIText* text); 70 55 71 56 /** 72 57 * @see IGUIObject#HandleMessage() 73 58 */ 74 virtual void HandleMessage(SGUIMessage &Message);59 virtual void HandleMessage(SGUIMessage& Message); 75 60 76 61 /** 77 62 * @see IGUIObject#UpdateCachedSize() … … 88 73 * @param clipping Clipping rectangle, don't even add a parameter 89 74 * to get no clipping. 90 75 */ 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()); 92 77 93 78 /** 94 79 * Test if mouse position is over an icon … … 115 100 /** 116 101 * Calculate the position for the text, based on the alignment. 117 102 */ 118 void CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text);103 void CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text); 119 104 }; 120 105 121 #endif 106 #endif // INCLUDED_IGUITEXTOWNER -
source/gui/MiniMap.cpp
30 30 #include "graphics/TerritoryTexture.h" 31 31 #include "gui/GUI.h" 32 32 #include "gui/GUIManager.h" 33 #include "lib/ogl.h"34 #include "lib/external_libraries/libsdl.h"35 33 #include "lib/bits.h" 34 #include "lib/external_libraries/libsdl.h" 35 #include "lib/ogl.h" 36 36 #include "lib/timer.h" 37 37 #include "ps/ConfigDB.h" 38 38 #include "ps/Game.h" … … 105 105 106 106 VertexArrayIterator<float[2]> attrPos = m_AttributePos.GetIterator<float[2]>(); 107 107 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) 109 109 { 110 110 (*attrColor)[0] = 0; 111 111 (*attrColor)[1] = 0; … … 137 137 Destroy(); 138 138 } 139 139 140 void CMiniMap::HandleMessage(SGUIMessage &Message)140 void CMiniMap::HandleMessage(SGUIMessage& Message) 141 141 { 142 switch (Message.type)142 switch (Message.type) 143 143 { 144 144 case GUIM_MOUSE_PRESS_LEFT: 145 if (m_MouseHovering) 145 146 { 146 if (m_MouseHovering) 147 { 148 SetCameraPos(); 149 m_Clicking = true; 150 } 151 break; 147 SetCameraPos(); 148 m_Clicking = true; 152 149 } 150 break; 153 151 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; 160 156 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; 167 161 case GUIM_MOUSE_ENTER: 168 { 169 m_MouseHovering = true; 170 break; 171 } 162 m_MouseHovering = true; 163 break; 172 164 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; 178 168 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; 183 171 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; 188 174 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; 194 178 case GUIM_MOUSE_WHEEL_DOWN: 195 179 case GUIM_MOUSE_WHEEL_UP: 196 180 Message.Skip(); … … 198 182 199 183 default: 200 184 break; 201 } // switch185 } 202 186 } 203 187 204 188 bool CMiniMap::MouseOver() … … 248 232 return -atan2(cameraIn.X, cameraIn.Z); 249 233 } 250 234 251 void CMiniMap::FireWorldClickEvent(int button, int clicks)235 void CMiniMap::FireWorldClickEvent(int UNUSED(button), int UNUSED(clicks)) 252 236 { 253 237 JSContext* cx = g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(); 254 238 JSAutoRequest rq(cx); … … 261 245 g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "x", x, false); 262 246 g_GUI->GetActiveGUI()->GetScriptInterface()->SetProperty(coords, "z", z, false); 263 247 ScriptEvent("worldclick", coords); 264 265 UNUSED2(button);266 UNUSED2(clicks);267 248 } 268 249 269 250 // This sets up and draws the rectangle on the minimap … … 284 265 hitPt[3] = m_Camera->GetWorldCoordinates(0, 0, h); 285 266 286 267 float ViewRect[4][2]; 287 for (int i = 0; i < 4; i++) { 268 for (int i = 0; i < 4; ++i) 269 { 288 270 // convert to minimap space 289 271 ViewRect[i][0] = (width * hitPt[i].X * invTileMapSize); 290 272 ViewRect[i][1] = (height * hitPt[i].Z * invTileMapSize); … … 465 447 CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture(); 466 448 467 449 shader->BindTexture(str_baseTex, territoryTexture.GetTexture()); 468 const CMatrix3D *territoryTransform = territoryTexture.GetMinimapTextureMatrix();450 const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix(); 469 451 shader->Uniform(str_transform, baseTransform); 470 452 shader->Uniform(str_textureTransform, *territoryTransform); 471 453 … … 484 466 485 467 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 486 468 487 const CMatrix3D *losTransform = losTexture.GetMinimapTextureMatrix();469 const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix(); 488 470 shader->Uniform(str_transform, baseTransform); 489 471 shader->Uniform(str_textureTransform, *losTransform); 490 472 … … 658 640 659 641 m_TerrainDirty = false; 660 642 661 for (u32 j = 0; j < h; j++)643 for (u32 j = 0; j < h; ++j) 662 644 { 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) 665 647 { 666 648 float avgHeight = ( m_Terrain->GetVertexGroundLevel((int)i, (int)j) 667 649 + m_Terrain->GetVertexGroundLevel((int)i+1, (int)j) … … 686 668 687 669 u32 color = 0xFFFFFFFF; 688 670 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) 691 673 { 692 CTerrainTextureEntry *tex = mp->GetTextureEntry();693 if (tex)674 CTerrainTextureEntry* tex = mp->GetTextureEntry(); 675 if (tex) 694 676 { 695 677 // If the texture can't be loaded yet, set the dirty flags 696 678 // so we'll try regenerating the terrain texture again soon … … 713 695 714 696 void CMiniMap::Destroy() 715 697 { 716 if (m_TerrainTexture)698 if (m_TerrainTexture) 717 699 { 718 700 glDeleteTextures(1, &m_TerrainTexture); 719 701 m_TerrainTexture = 0; 720 702 } 721 703 722 delete[] m_TerrainData; 723 m_TerrainData = 0; 704 SAFE_ARRAY_DELETE(m_TerrainData); 724 705 } -
source/gui/MiniMap.h
37 37 /** 38 38 * @see IGUIObject#HandleMessage() 39 39 */ 40 virtual void HandleMessage(SGUIMessage &Message);40 virtual void HandleMessage(SGUIMessage& Message); 41 41 42 42 /** 43 43 * @see IGUIObject#MouseOver() … … 109 109 bool m_BlinkState; 110 110 }; 111 111 112 #endif 112 #endif // INCLUDED_MINIMAP -
source/gui/scripting/JSInterface_GUITypes.cpp
89 89 if (per == 0) 90 90 return CStr::FromDouble(pix); 91 91 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)); 93 93 } 94 94 95 95 bool JSI_GUISize::toString(JSContext* cx, uint argc, jsval* vp) -
source/gui/scripting/ScriptFunctions.cpp
716 716 } 717 717 g_Game->m_Paused = pause; 718 718 #if CONFIG2_AUDIO 719 if ( g_SoundManager)719 if (g_SoundManager) 720 720 g_SoundManager->Pause(pause); 721 721 #endif 722 722 }