Ticket #3354: gui_cleanup_2.patch
File gui_cleanup_2.patch, 269.8 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"); … … 66 58 if (!GetGUI()) 67 59 return; 68 60 69 ENSURE(m_GeneratedTexts.size() ==1);61 ENSURE(m_GeneratedTexts.size() == 1); 70 62 71 63 CStrW font; 72 64 if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) … … 77 69 CGUIString caption; 78 70 GUI<CGUIString>::GetSetting(this, "caption", caption); 79 71 80 float buffer_zone =0.f;72 float buffer_zone = 0.f; 81 73 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 82 74 *m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this); 83 75 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); … … 95 87 { 96 88 float bz = GetBufferedZ(); 97 89 98 CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled; 90 CGUISpriteInstance* sprite; 91 CGUISpriteInstance* sprite_over; 92 CGUISpriteInstance* sprite_pressed; 93 CGUISpriteInstance* sprite_disabled; 99 94 int cell_id; 100 95 101 96 // Statically initialise some strings, so we don't have to do 102 97 // lots of allocation every time this function is called 103 static CStr strSprite("sprite");104 static CStr strSpriteOver("sprite_over");105 static CStr strSpritePressed("sprite_pressed");106 static CStr strSpriteDisabled("sprite_disabled");107 static CStr strCellId("cell_id");98 static const CStr strSprite("sprite"); 99 static const CStr strSpriteOver("sprite_over"); 100 static const CStr strSpritePressed("sprite_pressed"); 101 static const CStr strSpriteDisabled("sprite_disabled"); 102 static const CStr strCellId("cell_id"); 108 103 109 104 GUI<CGUISpriteInstance>::GetSettingPointer(this, strSprite, sprite); 110 105 GUI<CGUISpriteInstance>::GetSettingPointer(this, strSpriteOver, sprite_over); -
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"); … … 72 64 if (!GetGUI()) 73 65 return; 74 66 75 ENSURE(m_GeneratedTexts.size() ==1);67 ENSURE(m_GeneratedTexts.size() == 1); 76 68 77 69 CStrW font; 78 70 if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) … … 86 78 CGUIString caption; 87 79 GUI<CGUIString>::GetSetting(this, "caption", caption); 88 80 89 float buffer_zone =0.f;81 float buffer_zone = 0.f; 90 82 GUI<float>::GetSetting(this, "buffer_zone", 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); … … 120 112 float bz = GetBufferedZ(); 121 113 bool checked; 122 114 int cell_id; 123 CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled; 115 CGUISpriteInstance* sprite; 116 CGUISpriteInstance* sprite_over; 117 CGUISpriteInstance* sprite_pressed; 118 CGUISpriteInstance* sprite_disabled; 124 119 125 120 GUI<bool>::GetSetting(this, "checked", checked); 126 121 GUI<int>::GetSetting(this, "cell_id", cell_id); -
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 } … … 344 335 345 336 m_TimeOfLastInput = timer_Time(); 346 337 347 CGUIList *pList;338 CGUIList* pList; 348 339 GUI<CGUIList>::GetSettingPointer(this, "list", pList); 349 340 // let's look for the closest element 350 341 // basically it's alphabetic order and "as many letters as we can get". 351 342 int closest = -1; 352 343 int bestIndex = -1; 353 344 int difference = 1250; 354 for (int i =0; i<(int)pList->m_Items.size(); ++i)345 for (int i = 0; i < (int)pList->m_Items.size(); ++i) 355 346 { 356 347 int indexOfDifference = 0; 357 348 int diff = 0; 358 for (size_t j =0; j < m_InputBuffer.length(); ++j)349 for (size_t j = 0; j < m_InputBuffer.length(); ++j) 359 350 { 360 351 diff = abs(pList->m_Items[i].GetOriginalString().LowerCase()[j] - (int)m_InputBuffer[j]); 361 352 if (diff == 0) … … 449 440 GUI<float>::GetSetting(this, "dropdown_size", dropdown_size); 450 441 GUI<float>::GetSetting(this, "button_width", button_width); 451 442 452 CGUISpriteInstance *sprite, *sprite2, *sprite2_second; 453 int cell_id, selected=0; 443 CGUISpriteInstance* sprite; 444 CGUISpriteInstance* sprite2; 445 CGUISpriteInstance* sprite2_second; 446 int cell_id, selected = 0; 454 447 CColor color; 455 448 456 449 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); … … 501 494 DrawText(selected, color, pos, bz+0.1f, cliparea); 502 495 } 503 496 504 bool *scrollbar=NULL, old; 497 bool* scrollbar = NULL; 498 bool old; 505 499 GUI<bool>::GetSettingPointer(this, "scrollbar", scrollbar); 506 500 507 501 old = *scrollbar; -
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) … … 119 110 } 120 111 121 112 // Only one object can be hovered 122 IGUIObject *pNearest = NULL;113 IGUIObject* pNearest = NULL; 123 114 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 … … 310 301 &IGUIObject::ScriptEvent, EventName.LowerCase()); 311 302 } 312 303 313 //------------------------------------------------------------------- 314 // Constructor / Destructor 315 //------------------------------------------------------------------- 316 317 CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0) 304 CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime) 305 : m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0) 318 306 { 319 307 m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime)); 320 308 GuiScriptingInit(*m_ScriptInterface); … … 331 319 delete m_BaseObject; 332 320 } 333 321 334 //------------------------------------------------------------------- 335 // Functions 336 //------------------------------------------------------------------- 337 IGUIObject *CGUI::ConstructObject(const CStr& str) 322 IGUIObject* CGUI::ConstructObject(const CStr& str) 338 323 { 339 324 if (m_ObjectTypes.count(str) > 0) 340 325 return (*m_ObjectTypes[str])(); … … 383 368 } 384 369 } 385 370 386 void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, 387 int CellID, 388 const float& Z, 389 const CRect& Rect, 390 const CRect& UNUSED(Clipping)) 371 void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping)) 391 372 { 392 373 // If the sprite doesn't exist (name == ""), don't bother drawing anything 393 374 if (Sprite.IsEmpty()) … … 402 383 { 403 384 // We can use the map to delete all 404 385 // now we don't want to cancel all if one Destroy fails 405 for ( map_pObjects::iterator it = m_pAllObjects.begin(); it != m_pAllObjects.end(); ++it)386 for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects) 406 387 { 407 388 try 408 389 { 409 it->second->Destroy();390 p.second->Destroy(); 410 391 } 411 392 catch (PSERROR_GUI& e) 412 393 { … … 415 396 // TODO Gee: Handle 416 397 } 417 398 418 delete it->second;399 delete p.second; 419 400 } 420 421 // Clear all422 401 m_pAllObjects.clear(); 423 for(std::map<CStr, CGUISprite*>::iterator it = m_Sprites.begin(); it != m_Sprites.end(); ++it) 424 delete it->second; 402 403 for (const std::pair<CStr, CGUISprite*>& p : m_Sprites) 404 delete p.second; 425 405 m_Sprites.clear(); 426 406 m_Icons.clear(); 427 407 } … … 429 409 void CGUI::UpdateResolution() 430 410 { 431 411 // Update ALL cached 432 GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize 412 GUI<>::RecurseObject(0, m_BaseObject, &IGUIObject::UpdateCachedSize); 433 413 } 434 414 435 415 void CGUI::AddObject(IGUIObject* pObject) … … 464 444 try 465 445 { 466 446 // Fill freshly 467 GUI< map_pObjects >::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects);447 GUI<map_pObjects>::RecurseObject(0, m_BaseObject, &IGUIObject::AddToPointersMap, AllObjects); 468 448 } 469 449 catch (PSERROR_GUI&) 470 450 { … … 528 508 529 509 // Some help functions 530 510 // TODO Gee: CRect => CPoint ? 531 void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall &SpriteCall,511 void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall, 532 512 const float width, const float y, 533 const CSize &Size, const CStr& TextureName,513 const CSize& Size, const CStr& TextureName, 534 514 const float BufferZone, const int CellID) 535 515 { 536 516 // TODO Gee: Temp hardcoded values … … 557 537 } 558 538 }; 559 539 560 SGUIText CGUI::GenerateText(const CGUIString &string, 561 const CStrW& FontW, const float &Width, const float &BufferZone, 562 const IGUIObject *pObject) 540 SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const float& Width, const float& BufferZone, const IGUIObject* pObject) 563 541 { 564 542 SGUIText Text; // object we're generating 565 543 566 544 CStrIntern Font(FontW.ToUTF8()); 567 545 568 if (string.m_Words. size() == 0)546 if (string.m_Words.empty()) 569 547 return Text; 570 548 571 float x =BufferZone, y=BufferZone; // drawing pointer572 int from =0;573 bool done =false;549 float x = BufferZone, y = BufferZone; // drawing pointer 550 int from = 0; 551 bool done = false; 574 552 575 553 bool FirstLine = true; // Necessary because text in the first line is shorter 576 554 // (it doesn't count the line spacing) 577 555 578 556 // Images on the left or the right side. 579 557 std::vector<SGenerateTextImage> Images[2]; 580 int pos_last_img =-1; // Position in the string where last img (either left or right) were encountered.558 int pos_last_img = -1; // Position in the string where last img (either left or right) were encountered. 581 559 // in order to avoid duplicate processing. 582 560 583 561 // Easier to read. … … 590 568 GUI<EAlign>::GetSetting(pObject, "text_align", align); 591 569 592 570 // Go through string word by word 593 for (int i =0; i<(int)string.m_Words.size()-1 && !done; ++i)571 for (int i = 0; i < (int)string.m_Words.size()-1 && !done; ++i) 594 572 { 595 573 // Pre-process each line one time, so we know which floating images 596 574 // will be added for that line. … … 599 577 CGUIString::SFeedback Feedback; 600 578 601 579 // Preliminary line_height, used for word-wrapping with floating images. 602 float prelim_line_height =0.f;580 float prelim_line_height = 0.f; 603 581 604 582 // Width and height of all text calls generated. 605 583 string.GenerateTextCall(this, Feedback, Font, … … 613 591 if (WordWrapping && i > pos_last_img) 614 592 { 615 593 // Loop left/right 616 for (int j =0; j<2; ++j)594 for (int j = 0; j < 2; ++j) 617 595 { 618 for (std::vector<CStr>::const_iterator it = Feedback.m_Images[j].begin(); 619 it != Feedback.m_Images[j].end(); 620 ++it) 596 for (const CStr& imgname : Feedback.m_Images[j]) 621 597 { 622 598 SGUIText::SSpriteCall SpriteCall; 623 599 SGenerateTextImage Image; … … 631 607 _y = y; 632 608 633 609 // Get Size from Icon database 634 SGUIIcon icon = GetIcon( *it);610 SGUIIcon icon = GetIcon(imgname); 635 611 636 612 CSize size = icon.m_Size; 637 Image.SetupSpriteCall((j ==CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID);613 Image.SetupSpriteCall((j == CGUIString::SFeedback::Left), SpriteCall, Width, _y, size, icon.m_SpriteName, BufferZone, icon.m_CellID); 638 614 639 615 // Check if image is the lowest thing. 640 616 Text.m_Size.cy = std::max(Text.m_Size.cy, Image.m_YTo); … … 657 633 int temp_from = from; 658 634 from = i; 659 635 660 static const int From =0, To=1;636 static const int From = 0, To = 1; 661 637 //int width_from=0, width_to=width; 662 638 float width_range[2]; 663 639 width_range[From] = BufferZone; … … 674 650 // structures his text in a stylistically pure fashion. Even if not, it 675 651 // is still quite unlikely it will happen. 676 652 // Loop through left and right side, from and to. 677 for (int j =0; j<2; ++j)653 for (int j = 0; j < 2; ++j) 678 654 { 679 for (std::vector<SGenerateTextImage>::const_iterator it = Images[j].begin(); 680 it != Images[j].end(); 681 ++it) 655 for (const SGenerateTextImage& img : Images[j]) 682 656 { 683 657 // We're working with two intervals here, the image's and the line height's. 684 658 // let's find the union of these two. 685 659 float union_from, union_to; 686 660 687 union_from = std::max(y, i t->m_YFrom);688 union_to = std::min(y+prelim_line_height, i t->m_YTo);661 union_from = std::max(y, img.m_YFrom); 662 union_to = std::min(y+prelim_line_height, img.m_YTo); 689 663 690 664 // The union is not empty 691 665 if (union_to > union_from) 692 666 { 693 667 if (j == From) 694 width_range[From] = std::max(width_range[From], i t->m_Indentation);668 width_range[From] = std::max(width_range[From], img.m_Indentation); 695 669 else 696 width_range[To] = std::min(width_range[To], Width - i t->m_Indentation);670 width_range[To] = std::min(width_range[To], Width - img.m_Indentation); 697 671 } 698 672 } 699 673 } … … 709 683 // because it didn't regard images, so we don't know 710 684 // if all characters processed, will actually be involved 711 685 // in that line. 712 float line_height =0.f;713 float line_width =0.f;714 for (int j =temp_from; j<=i; ++j)686 float line_height = 0.f; 687 float line_width = 0.f; 688 for (int j = temp_from; j <= i; ++j) 715 689 { 716 690 // We don't want to use Feedback now, so we'll have to use 717 691 // another. … … 766 740 y += line_height; 767 741 768 742 // Do the real processing now 769 for (int j =temp_from; j<=i; ++j)743 for (int j = temp_from; j <= i; ++j) 770 744 { 771 745 // We don't want to use Feedback now, so we'll have to use 772 746 // another one. … … 781 755 // Since X values are not set, we need to make an internal 782 756 // iteration with an increment that will append the internal 783 757 // x, that is what x_pointer is for. 784 float x_pointer =0.f;758 float x_pointer = 0.f; 785 759 786 std::vector<SGUIText::STextCall>::iterator it; 787 for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it) 760 for (SGUIText::STextCall& tc : Feedback2.m_TextCalls) 788 761 { 789 it->m_Pos = CPos(dx + x + x_pointer, y);762 tc.m_Pos = CPos(dx + x + x_pointer, y); 790 763 791 x_pointer += it->m_Size.cx;764 x_pointer += tc.m_Size.cx; 792 765 793 if (it->m_pSpriteCall) 794 { 795 it->m_pSpriteCall->m_Area += it->m_Pos - CSize(0,it->m_pSpriteCall->m_Area.GetHeight()); 796 } 766 if (tc.m_pSpriteCall) 767 tc.m_pSpriteCall->m_Area += tc.m_Pos - CSize(0, tc.m_pSpriteCall->m_Area.GetHeight()); 797 768 } 798 769 799 770 // Append X value. … … 815 786 Text.m_SpriteCalls.insert(Text.m_SpriteCalls.end(), Feedback2.m_SpriteCalls.begin(), Feedback2.m_SpriteCalls.end()); 816 787 break; 817 788 } 818 else 819 if (x > width_range[To] && j==temp_from) 789 else if (x > width_range[To] && j == temp_from) 820 790 { 821 791 from = j+1; 822 792 // do not break, since we want it to be added to m_TextCalls 823 793 } 824 else 825 if (x > width_range[To]) 794 else if (x > width_range[To]) 826 795 { 827 796 from = j; 828 797 break; … … 856 825 return Text; 857 826 } 858 827 859 void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor, 860 const CPos &pos, const float &z, const CRect &clipping) 828 void CGUI::DrawText(SGUIText& Text, const CColor& DefaultColor, const CPos& pos, const float& z, const CRect& clipping) 861 829 { 862 830 CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); 863 831 … … 878 846 textRenderer.SetClippingRect(clipping); 879 847 textRenderer.Translate(0.0f, 0.0f, z); 880 848 881 for (std::vector<SGUIText::STextCall>::const_iterator it = Text.m_TextCalls.begin(); 882 it != Text.m_TextCalls.end(); 883 ++it) 849 for (const SGUIText::STextCall& tc : Text.m_TextCalls) 884 850 { 885 851 // If this is just a placeholder for a sprite call, continue 886 if ( it->m_pSpriteCall)852 if (tc.m_pSpriteCall) 887 853 continue; 888 854 889 CColor color = it->m_UseCustomColor ? it->m_Color : DefaultColor;855 CColor color = tc.m_UseCustomColor ? tc.m_Color : DefaultColor; 890 856 891 857 textRenderer.Color(color); 892 textRenderer.Font( it->m_Font);893 textRenderer.Put((float)(int)(pos.x +it->m_Pos.x), (float)(int)(pos.y+it->m_Pos.y), &it->m_String);858 textRenderer.Font(tc.m_Font); 859 textRenderer.Put((float)(int)(pos.x + tc.m_Pos.x), (float)(int)(pos.y + tc.m_Pos.y), &tc.m_String); 894 860 } 895 861 896 862 textRenderer.Render(); 897 863 898 for (std::list<SGUIText::SSpriteCall>::iterator it=Text.m_SpriteCalls.begin(); 899 it!=Text.m_SpriteCalls.end(); 900 ++it) 901 { 902 DrawSprite(it->m_Sprite, it->m_CellID, z, it->m_Area + pos); 903 } 864 for (const SGUIText::SSpriteCall& sc : Text.m_SpriteCalls) 865 DrawSprite(sc.m_Sprite, sc.m_CellID, z, sc.m_Area + pos); 904 866 905 867 if (isClipped) 906 868 glDisable(GL_SCISSOR_TEST); … … 908 870 tech->EndPass(); 909 871 } 910 872 911 bool CGUI::GetPreDefinedColor(const CStr& name, CColor &Output)873 bool CGUI::GetPreDefinedColor(const CStr& name, CColor& Output) const 912 874 { 913 if (m_PreDefinedColors.count(name) == 0)914 {875 std::map<CStr, CColor>::const_iterator cit = m_PreDefinedColors.find(name); 876 if (cit == m_PreDefinedColors.end()) 915 877 return false; 916 } 917 else 918 { 919 Output = m_PreDefinedColors[name]; 920 return true; 921 } 878 879 Output = cit->second; 880 return true; 922 881 } 923 882 924 883 /** … … 941 900 942 901 try 943 902 { 944 945 903 if (root_name == "objects") 946 904 { 947 905 Xeromyces_ReadRootObjects(node, &XeroFile, Paths); … … 949 907 // Re-cache all values so these gets cached too. 950 908 //UpdateResolution(); 951 909 } 952 else 953 if (root_name == "sprites") 954 { 910 else if (root_name == "sprites") 955 911 Xeromyces_ReadRootSprites(node, &XeroFile); 956 } 957 else 958 if (root_name == "styles") 959 { 912 else if (root_name == "styles") 960 913 Xeromyces_ReadRootStyles(node, &XeroFile); 961 } 962 else 963 if (root_name == "setup") 964 { 914 else if (root_name == "setup") 965 915 Xeromyces_ReadRootSetup(node, &XeroFile); 966 }967 916 else 968 {969 917 debug_warn(L"CGUI::LoadXmlFile error"); 970 // TODO Gee: Output in log971 }972 918 } 973 919 catch (PSERROR_GUI& e) 974 920 { … … 1029 975 CStr name(pFile->GetElementString(child.GetNodeName())); 1030 976 1031 977 if (name == "scrollbar") 1032 {1033 978 Xeromyces_ReadScrollBarStyle(child, pFile); 1034 } 1035 else 1036 if (name == "icon") 1037 { 979 else if (name == "icon") 1038 980 Xeromyces_ReadIcon(child, pFile); 1039 } 1040 else 1041 if (name == "tooltip") 1042 { 981 else if (name == "tooltip") 1043 982 Xeromyces_ReadTooltip(child, pFile); 1044 } 1045 else 1046 if (name == "color") 1047 { 983 else if (name == "color") 1048 984 Xeromyces_ReadColor(child, pFile); 1049 }1050 985 else 1051 {1052 986 debug_warn(L"Invalid data - DTD shouldn't allow this"); 1053 }1054 987 } 1055 988 } 1056 989 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)990 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 991 { 1059 992 ENSURE(pParent); 1060 993 1061 994 // Our object we are going to create 1062 IGUIObject *object = NULL;995 IGUIObject* object = NULL; 1063 996 1064 997 XMBAttributeList attributes = Element.GetAttributes(); 1065 998 1066 999 // Well first of all we need to determine the type 1067 CStr type 1000 CStr type(attributes.GetNamedItem(pFile->GetAttributeID("type"))); 1068 1001 if (type.empty()) 1069 1002 type = "empty"; 1070 1003 … … 1150 1083 CStr name(attr.Value); 1151 1084 1152 1085 // Apply the requested substitutions 1153 for ( size_t j = 0; j < NameSubst.size(); ++j)1154 name.Replace( NameSubst[j].first, NameSubst[j].second);1086 for (const std::pair<CStr, CStr>& sub : NameSubst) 1087 name.Replace(sub.first, sub.second); 1155 1088 1156 1089 object->SetName(name); 1157 1090 NameSet = true; … … 1415 1348 } 1416 1349 } 1417 1350 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)1351 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 1352 { 1420 1353 #define ELMT(x) int elmt_##x = pFile->GetElementID(#x) 1421 1354 #define ATTR(x) int attr_##x = pFile->GetAttributeID(#x) … … 1432 1365 1433 1366 for (int n = 0; n < count; ++n) 1434 1367 { 1435 NameSubst. push_back(std::make_pair(var, "[" + CStr::FromInt(n) + "]"));1368 NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]"); 1436 1369 1437 1370 XERO_ITER_EL(Element, child) 1438 1371 { … … 1448 1381 void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths) 1449 1382 { 1450 1383 // Check for a 'file' parameter 1451 CStrW file(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file")).FromUTF8());1384 CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8()); 1452 1385 1453 1386 // If there is a file specified, open and execute it 1454 1387 if (!file.empty()) … … 1465 1398 } 1466 1399 1467 1400 // If it has a directory attribute, read all JS files in that directory 1468 CStrW directory(Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("directory")).FromUTF8());1401 CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8()); 1469 1402 if (!directory.empty()) 1470 1403 { 1471 1404 VfsPaths pathnames; … … 1513 1446 // 1514 1447 1515 1448 // Get name, we know it exists because of DTD requirements 1516 name = Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("name"));1449 name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name")); 1517 1450 1518 1451 if (m_Sprites.find(name) != m_Sprites.end()) 1519 1452 LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str()); … … 1553 1486 // Apply the effects to every image (unless the image overrides it with 1554 1487 // different effects) 1555 1488 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 later1489 for (SGUIImage* const& img : Sprite->m_Images) 1490 if (!img->m_Effects) 1491 img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later 1559 1492 1560 1493 delete effects; 1561 1494 … … 1566 1499 m_Sprites[name] = Sprite; 1567 1500 } 1568 1501 1569 void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite &parent)1502 void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite& parent) 1570 1503 { 1571 1504 1572 1505 // Image object we're adding … … 1592 1525 { 1593 1526 Image->m_TextureName = VfsPath("art/textures/ui") / attr_value; 1594 1527 } 1595 else 1596 if (attr_name == "size") 1528 else if (attr_name == "size") 1597 1529 { 1598 1530 CClientArea ca; 1599 1531 if (!GUI<CClientArea>::ParseString(attr_value, ca)) 1600 1532 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1601 else Image->m_Size = ca; 1533 else 1534 Image->m_Size = ca; 1602 1535 } 1603 else 1604 if (attr_name == "texture_size") 1536 else if (attr_name == "texture_size") 1605 1537 { 1606 1538 CClientArea ca; 1607 1539 if (!GUI<CClientArea>::ParseString(attr_value, ca)) 1608 1540 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1609 else Image->m_TextureSize = ca; 1541 else 1542 Image->m_TextureSize = ca; 1610 1543 } 1611 else 1612 if (attr_name == "real_texture_placement") 1544 else if (attr_name == "real_texture_placement") 1613 1545 { 1614 1546 CRect rect; 1615 1547 if (!GUI<CRect>::ParseString(attr_value, rect)) 1616 1548 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1617 else Image->m_TexturePlacementInFile = rect; 1549 else 1550 Image->m_TexturePlacementInFile = rect; 1618 1551 } 1619 else 1620 if (attr_name == "cell_size") 1552 else if (attr_name == "cell_size") 1621 1553 { 1622 1554 CSize size; 1623 1555 if (!GUI<CSize>::ParseString(attr_value, size)) 1624 1556 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1625 else Image->m_CellSize = size; 1557 else 1558 Image->m_CellSize = size; 1626 1559 } 1627 else 1628 if (attr_name == "fixed_h_aspect_ratio") 1560 else if (attr_name == "fixed_h_aspect_ratio") 1629 1561 { 1630 1562 float val; 1631 1563 if (!GUI<float>::ParseString(attr_value, val)) 1632 1564 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1633 else Image->m_FixedHAspectRatio = val; 1565 else 1566 Image->m_FixedHAspectRatio = val; 1634 1567 } 1635 else 1636 if (attr_name == "round_coordinates") 1568 else if (attr_name == "round_coordinates") 1637 1569 { 1638 1570 bool b; 1639 1571 if (!GUI<bool>::ParseString(attr_value, b)) 1640 1572 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1641 else Image->m_RoundCoordinates = b; 1573 else 1574 Image->m_RoundCoordinates = b; 1642 1575 } 1643 else 1644 if (attr_name == "wrap_mode") 1576 else if (attr_name == "wrap_mode") 1645 1577 { 1646 1578 if (attr_value == L"repeat") 1647 1579 Image->m_WrapMode = GL_REPEAT; … … 1652 1584 else 1653 1585 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1654 1586 } 1655 else 1656 if (attr_name == "z_level") 1587 else if (attr_name == "z_level") 1657 1588 { 1658 1589 float z_level; 1659 1590 if (!GUI<float>::ParseString(attr_value, z_level)) 1660 1591 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1661 else Image->m_DeltaZ = z_level/100.f; 1592 else 1593 Image->m_DeltaZ = z_level/100.f; 1662 1594 } 1663 else 1664 if (attr_name == "backcolor") 1595 else if (attr_name == "backcolor") 1665 1596 { 1666 1597 CColor color; 1667 1598 if (!GUI<CColor>::ParseString(attr_value, color)) 1668 1599 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1669 else Image->m_BackColor = color; 1600 else 1601 Image->m_BackColor = color; 1670 1602 } 1671 else 1672 if (attr_name == "bordercolor") 1603 else if (attr_name == "bordercolor") 1673 1604 { 1674 1605 CColor color; 1675 1606 if (!GUI<CColor>::ParseString(attr_value, color)) 1676 1607 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1677 else Image->m_BorderColor = color; 1608 else 1609 Image->m_BorderColor = color; 1678 1610 } 1679 else 1680 if (attr_name == "border") 1611 else if (attr_name == "border") 1681 1612 { 1682 1613 bool b; 1683 1614 if (!GUI<bool>::ParseString(attr_value, b)) 1684 1615 LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); 1685 else Image->m_Border = b; 1616 else 1617 Image->m_Border = b; 1686 1618 } 1687 1619 else 1688 1620 { … … 1719 1651 parent.AddImage(Image); 1720 1652 } 1721 1653 1722 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)1654 void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects) 1723 1655 { 1724 1656 for (XMBAttribute attr : Element.GetAttributes()) 1725 1657 { … … 1801 1733 1802 1734 if (attr_name == "name") 1803 1735 name = attr_value; 1804 else 1805 if (attr_name == "show_edge_buttons") 1736 else if (attr_name == "show_edge_buttons") 1806 1737 { 1807 1738 bool b; 1808 1739 if (!GUI<bool>::ParseString(attr_value.FromUTF8(), b)) … … 1810 1741 else 1811 1742 scrollbar.m_UseEdgeButtons = b; 1812 1743 } 1813 if (attr_name == "width")1744 else if (attr_name == "width") 1814 1745 { 1815 1746 float f; 1816 1747 if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) … … 1818 1749 else 1819 1750 scrollbar.m_Width = f; 1820 1751 } 1821 else 1822 if (attr_name == "minimum_bar_size") 1752 else if (attr_name == "minimum_bar_size") 1823 1753 { 1824 1754 float f; 1825 1755 if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) … … 1827 1757 else 1828 1758 scrollbar.m_MinimumBarSize = f; 1829 1759 } 1830 else 1831 if (attr_name == "maximum_bar_size") 1760 else if (attr_name == "maximum_bar_size") 1832 1761 { 1833 1762 float f; 1834 1763 if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) … … 1836 1765 else 1837 1766 scrollbar.m_MaximumBarSize = f; 1838 1767 } 1839 else 1840 if (attr_name == "sprite_button_top") 1768 else if (attr_name == "sprite_button_top") 1841 1769 scrollbar.m_SpriteButtonTop = attr_value; 1842 else 1843 if (attr_name == "sprite_button_top_pressed") 1770 else if (attr_name == "sprite_button_top_pressed") 1844 1771 scrollbar.m_SpriteButtonTopPressed = attr_value; 1845 else 1846 if (attr_name == "sprite_button_top_disabled") 1772 else if (attr_name == "sprite_button_top_disabled") 1847 1773 scrollbar.m_SpriteButtonTopDisabled = attr_value; 1848 else 1849 if (attr_name == "sprite_button_top_over") 1774 else if (attr_name == "sprite_button_top_over") 1850 1775 scrollbar.m_SpriteButtonTopOver = attr_value; 1851 else 1852 if (attr_name == "sprite_button_bottom") 1776 else if (attr_name == "sprite_button_bottom") 1853 1777 scrollbar.m_SpriteButtonBottom = attr_value; 1854 else 1855 if (attr_name == "sprite_button_bottom_pressed") 1778 else if (attr_name == "sprite_button_bottom_pressed") 1856 1779 scrollbar.m_SpriteButtonBottomPressed = attr_value; 1857 else 1858 if (attr_name == "sprite_button_bottom_disabled") 1780 else if (attr_name == "sprite_button_bottom_disabled") 1859 1781 scrollbar.m_SpriteButtonBottomDisabled = attr_value; 1860 else 1861 if (attr_name == "sprite_button_bottom_over") 1782 else if (attr_name == "sprite_button_bottom_over") 1862 1783 scrollbar.m_SpriteButtonBottomOver = attr_value; 1863 else 1864 if (attr_name == "sprite_back_vertical") 1784 else if (attr_name == "sprite_back_vertical") 1865 1785 scrollbar.m_SpriteBackVertical = attr_value; 1866 else 1867 if (attr_name == "sprite_bar_vertical") 1786 else if (attr_name == "sprite_bar_vertical") 1868 1787 scrollbar.m_SpriteBarVertical = attr_value; 1869 else 1870 if (attr_name == "sprite_bar_vertical_over") 1788 else if (attr_name == "sprite_bar_vertical_over") 1871 1789 scrollbar.m_SpriteBarVerticalOver = attr_value; 1872 else 1873 if (attr_name == "sprite_bar_vertical_pressed") 1790 else if (attr_name == "sprite_bar_vertical_pressed") 1874 1791 scrollbar.m_SpriteBarVerticalPressed = attr_value; 1875 1792 } 1876 1793 … … 1951 1868 1952 1869 XMBAttributeList attributes = Element.GetAttributes(); 1953 1870 1954 //IGUIObject* object = new CTooltip;1955 1871 CColor color; 1956 1872 CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name")); 1957 1873 1958 1874 // Try parsing value 1959 1875 CStr value(Element.GetText()); 1960 if (!value.empty()) 1876 if (value.empty()) 1877 return; 1878 1879 // Try setting color to value 1880 if (!color.ParseString(value)) 1961 1881 { 1962 // Try setting color to value 1963 if (!color.ParseString(value)) 1964 { 1965 LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str()); 1966 } 1967 else 1968 { 1969 // input color 1970 m_PreDefinedColors[name] = color; 1971 } 1882 LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str()); 1883 return; 1972 1884 } 1885 1886 // input color 1887 m_PreDefinedColors[name] = color; 1973 1888 } -
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; … … 72 71 if (GetStyle()->m_UseEdgeButtons) 73 72 { 74 73 // Get Appropriate sprites 75 const CGUISpriteInstance *button_top, *button_bottom; 74 const CGUISpriteInstance* button_top; 75 const CGUISpriteInstance* button_bottom; 76 76 77 77 // figure out what sprite to use for top button 78 78 if (m_ButtonMinusHovered) … … 82 82 else 83 83 button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop); 84 84 } 85 else button_top = &GetStyle()->m_SpriteButtonTop; 85 else 86 button_top = &GetStyle()->m_SpriteButtonTop; 86 87 87 88 // figure out what sprite to use for bottom button 88 89 if (m_ButtonPlusHovered) … … 92 93 else 93 94 button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom); 94 95 } 95 else button_bottom = &GetStyle()->m_SpriteButtonBottom; 96 else 97 button_bottom = &GetStyle()->m_SpriteButtonBottom; 96 98 97 99 // Draw top button 98 100 GetGUI()->DrawSprite(*button_top, … … 123 125 } 124 126 } 125 127 126 void CGUIScrollBarVertical::HandleMessage(SGUIMessage &Message)128 void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message) 127 129 { 128 130 IGUIScrollBar::HandleMessage(Message); 129 131 } … … 167 169 return ret; 168 170 } 169 171 170 bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos &mouse)172 bool CGUIScrollBarVertical::HoveringButtonMinus(const CPos& mouse) 171 173 { 172 174 if (!GetStyle()) 173 175 return false; … … 180 182 mouse.y <= m_Y + GetStyle()->m_Width); 181 183 } 182 184 183 bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos &mouse)185 bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos& mouse) 184 186 { 185 187 if (!GetStyle()) 186 188 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(); … … 112 107 else if (ev->ev.type == SDL_TEXTINPUT) 113 108 { 114 109 // Text has been committed, either single key presses or through an IME 115 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;110 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 116 111 std::wstring text = wstring_from_utf8(ev->ev.text.text); 117 112 118 m_WantedX =0.0f;113 m_WantedX = 0.0f; 119 114 120 115 if (SelectingText()) 121 116 DeleteCurSelection(); … … 145 140 { 146 141 // Text is being composed with an IME 147 142 // TODO: indicate this by e.g. underlining the uncommitted text 148 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;149 const char *rawText = ev->ev.edit.text;143 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 144 const char* rawText = ev->ev.edit.text; 150 145 int rawLength = strlen(rawText); 151 146 std::wstring wtext = wstring_from_utf8(rawText); 152 147 153 148 debug_printf("SDL_TEXTEDITING: text=%s, start=%d, length=%d\n", rawText, ev->ev.edit.start, ev->ev.edit.length); 154 m_WantedX =0.0f;149 m_WantedX = 0.0f; 155 150 156 151 if (SelectingText()) 157 152 DeleteCurSelection(); … … 195 190 // Since the GUI framework doesn't handle to set settings 196 191 // in Unicode (CStrW), we'll simply retrieve the actual 197 192 // pointer and edit that. 198 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;193 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 199 194 bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT]; 200 195 201 196 #if !SDL_VERSION_ATLEAST(2, 0, 0) … … 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 ); 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; 239 213 240 --m_iBufferPos; 214 case SDLK_BACKSPACE: // '\b' 215 m_WantedX = 0.0f; 241 216 242 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 243 } 244 } 217 if (SelectingText()) 218 DeleteCurSelection(); 219 else 220 { 221 m_iBufferPos_Tail = -1; 245 222 246 UpdateAutoScroll();247 break;223 if (pCaption->empty() || m_iBufferPos == 0) 224 break; 248 225 249 case SDLK_DELETE: 250 m_WantedX=0.0f; 251 // If selection: 252 if (SelectingText()) 253 { 254 DeleteCurSelection(); 255 } 226 if (m_iBufferPos == (int)pCaption->length()) 227 *pCaption = pCaption->Left((long)pCaption->length()-1); 256 228 else 257 { 258 if (pCaption->empty() || m_iBufferPos == (int)pCaption->length()) 259 { 260 break; 261 } 262 else 263 { 264 *pCaption = pCaption->Left( m_iBufferPos ) + 265 pCaption->Right( (long) pCaption->length()-(m_iBufferPos+1) ); 229 *pCaption = pCaption->Left(m_iBufferPos-1) + 230 pCaption->Right((long)pCaption->length()-m_iBufferPos); 266 231 267 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 268 } 269 } 232 --m_iBufferPos; 270 233 271 UpdateAutoScroll(); 272 break; 234 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 273 235 274 case SDLK_HOME: 275 // If there's not a selection, we should create one now 276 if (!shiftKeyPressed) 277 { 278 // Make sure a selection isn't created. 279 m_iBufferPos_Tail = -1; 280 } 281 else if (!SelectingText()) 282 { 283 // Place tail at the current point: 284 m_iBufferPos_Tail = m_iBufferPos; 285 } 286 287 m_iBufferPos = 0; 288 m_WantedX=0.0f; 289 290 UpdateAutoScroll(); 291 break; 236 } 292 237 293 case SDLK_END: 294 // If there's not a selection, we should create one now 295 if (!shiftKeyPressed) 296 { 297 // Make sure a selection isn't created. 298 m_iBufferPos_Tail = -1; 299 } 300 else if (!SelectingText()) 301 { 302 // Place tail at the current point: 303 m_iBufferPos_Tail = m_iBufferPos; 304 } 238 UpdateAutoScroll(); 239 break; 305 240 306 m_iBufferPos = (long) pCaption->length(); 307 m_WantedX=0.0f; 241 case SDLK_DELETE: 242 m_WantedX = 0.0f; 243 // If selection: 244 if (SelectingText()) 245 DeleteCurSelection(); 246 else 247 { 248 if (pCaption->empty() || m_iBufferPos == (int)pCaption->length()) 249 break; 308 250 309 UpdateAutoScroll();310 break;251 *pCaption = pCaption->Left(m_iBufferPos) + 252 pCaption->Right((long)pCaption->length()-(m_iBufferPos+1)); 311 253 312 /**313 Conventions for Left/Right when text is selected:254 UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); 255 } 314 256 315 References: 257 UpdateAutoScroll(); 258 break; 316 259 317 Visual Studio 318 Visual Studio has the 'newer' approach, used by newer versions of 319 things, and in newer applications. A left press will always place 320 the pointer on the left edge of the selection, and then of course 321 remove the selection. Right will do the exakt same thing. 322 If you have the pointer on the right edge and press right, it will 323 in other words just remove the selection. 260 case SDLK_HOME: 261 // If there's not a selection, we should create one now 262 if (!shiftKeyPressed) 263 { 264 // Make sure a selection isn't created. 265 m_iBufferPos_Tail = -1; 266 } 267 else if (!SelectingText()) 268 { 269 // Place tail at the current point: 270 m_iBufferPos_Tail = m_iBufferPos; 271 } 324 272 325 Windows (eg. Notepad) 326 A left press always takes the pointer a step to the left and 327 removes the selection as if it were never there in the first place. 328 Right of course does the same thing but to the right. 273 m_iBufferPos = 0; 274 m_WantedX = 0.0f; 329 275 330 I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN331 Messenger.276 UpdateAutoScroll(); 277 break; 332 278 333 **/ 334 case SDLK_LEFT: 335 m_WantedX=0.f; 279 case SDLK_END: 280 // If there's not a selection, we should create one now 281 if (!shiftKeyPressed) 282 { 283 // Make sure a selection isn't created. 284 m_iBufferPos_Tail = -1; 285 } 286 else if (!SelectingText()) 287 { 288 // Place tail at the current point: 289 m_iBufferPos_Tail = m_iBufferPos; 290 } 336 291 337 if (shiftKeyPressed || !SelectingText()) 338 { 339 if (!shiftKeyPressed) 340 { 341 m_iBufferPos_Tail = -1; 342 } 343 else if (!SelectingText()) 344 { 345 m_iBufferPos_Tail = m_iBufferPos; 346 } 292 m_iBufferPos = (long)pCaption->length(); 293 m_WantedX = 0.0f; 347 294 348 if (m_iBufferPos > 0) 349 --m_iBufferPos; 350 } 351 else 352 { 353 if (m_iBufferPos_Tail < m_iBufferPos) 354 m_iBufferPos = m_iBufferPos_Tail; 295 UpdateAutoScroll(); 296 break; 355 297 298 /** 299 * Conventions for Left/Right when text is selected: 300 * 301 * References: 302 * 303 * Visual Studio 304 * Visual Studio has the 'newer' approach, used by newer versions of 305 * things, and in newer applications. A left press will always place 306 * the pointer on the left edge of the selection, and then of course 307 * remove the selection. Right will do the exact same thing. 308 * If you have the pointer on the right edge and press right, it will 309 * in other words just remove the selection. 310 * 311 * Windows (eg. Notepad) 312 * A left press always takes the pointer a step to the left and 313 * removes the selection as if it were never there in the first place. 314 * Right of course does the same thing but to the right. 315 * 316 * I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN 317 * Messenger. 318 */ 319 case SDLK_LEFT: 320 m_WantedX = 0.f; 321 322 if (shiftKeyPressed || !SelectingText()) 323 { 324 if (!shiftKeyPressed) 356 325 m_iBufferPos_Tail = -1; 357 } 326 else if (!SelectingText()) 327 m_iBufferPos_Tail = m_iBufferPos; 358 328 359 UpdateAutoScroll(); 360 break; 329 if (m_iBufferPos > 0) 330 --m_iBufferPos; 331 } 332 else 333 { 334 if (m_iBufferPos_Tail < m_iBufferPos) 335 m_iBufferPos = m_iBufferPos_Tail; 361 336 362 case SDLK_RIGHT:363 m_WantedX=0.0f;337 m_iBufferPos_Tail = -1; 338 } 364 339 365 if (shiftKeyPressed || !SelectingText()) 366 { 367 if (!shiftKeyPressed) 368 { 369 m_iBufferPos_Tail = -1; 370 } 371 else if (!SelectingText()) 372 { 373 m_iBufferPos_Tail = m_iBufferPos; 374 } 340 UpdateAutoScroll(); 341 break; 375 342 376 if (m_iBufferPos < (int)pCaption->length()) 377 ++m_iBufferPos; 378 } 379 else 380 { 381 if (m_iBufferPos_Tail > m_iBufferPos) 382 m_iBufferPos = m_iBufferPos_Tail; 343 case SDLK_RIGHT: 344 m_WantedX = 0.0f; 383 345 346 if (shiftKeyPressed || !SelectingText()) 347 { 348 if (!shiftKeyPressed) 384 349 m_iBufferPos_Tail = -1; 385 } 386 387 UpdateAutoScroll(); 388 break; 389 390 /** 391 Conventions for Up/Down when text is selected: 350 else if (!SelectingText()) 351 m_iBufferPos_Tail = m_iBufferPos; 392 352 393 References: 353 if (m_iBufferPos < (int)pCaption->length()) 354 ++m_iBufferPos; 355 } 356 else 357 { 358 if (m_iBufferPos_Tail > m_iBufferPos) 359 m_iBufferPos = m_iBufferPos_Tail; 394 360 395 Visual Studio 396 Visual Studio has a very strange approach, down takes you below the 397 selection to the next row, and up to the one prior to the whole 398 selection. The weird part is that it is always aligned as the 399 'pointer'. I decided this is to much work for something that is 400 a bit arbitrary 361 m_iBufferPos_Tail = -1; 362 } 401 363 402 Windows (eg. Notepad) 403 Just like with left/right, the selection is destroyed and it moves 404 just as if there never were a selection. 364 UpdateAutoScroll(); 365 break; 405 366 406 I chose the Notepad convention even though I use the VS convention with 407 left/right. 367 /** 368 * Conventions for Up/Down when text is selected: 369 * 370 * References: 371 * 372 * Visual Studio 373 * Visual Studio has a very strange approach, down takes you below the 374 * selection to the next row, and up to the one prior to the whole 375 * selection. The weird part is that it is always aligned as the 376 * 'pointer'. I decided this is to much work for something that is 377 * a bit arbitrary 378 * 379 * Windows (eg. Notepad) 380 * Just like with left/right, the selection is destroyed and it moves 381 * just as if there never were a selection. 382 * 383 * I chose the Notepad convention even though I use the VS convention with 384 * left/right. 385 */ 386 case SDLK_UP: 387 { 388 if (!shiftKeyPressed) 389 m_iBufferPos_Tail = -1; 390 else if (!SelectingText()) 391 m_iBufferPos_Tail = m_iBufferPos; 408 392 409 **/410 case SDLK_UP:393 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 394 while (current != m_CharacterPositions.end()) 411 395 { 412 if (!shiftKeyPressed) 413 { 414 m_iBufferPos_Tail = -1; 415 } 416 else if (!SelectingText()) 417 { 418 m_iBufferPos_Tail = m_iBufferPos; 419 } 396 if (m_iBufferPos >= current->m_ListStart && 397 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 398 break; 420 399 421 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 422 while (current != m_CharacterPositions.end()) 423 { 424 if (m_iBufferPos >= current->m_ListStart && 425 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 426 break; 400 ++current; 401 } 427 402 428 ++current; 429 } 403 float pos_x; 430 404 431 float pos_x; 405 if (m_iBufferPos-current->m_ListStart == 0) 406 pos_x = 0.f; 407 else 408 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 432 409 433 if (m_iBufferPos-current->m_ListStart == 0) 434 pos_x = 0.f; 435 else 436 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 410 if (m_WantedX > pos_x) 411 pos_x = m_WantedX; 437 412 438 if (m_WantedX > pos_x) 439 pos_x = m_WantedX; 413 // Now change row: 414 if (current != m_CharacterPositions.begin()) 415 { 416 --current; 440 417 441 // Now change row:442 if (current != m_CharacterPositions.begin())443 {444 --current;418 // Find X-position: 419 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 420 } 421 // else we can't move up 445 422 446 // Find X-position: 447 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 448 } 449 // else we can't move up 423 UpdateAutoScroll(); 424 break; 425 } 450 426 451 UpdateAutoScroll(); 452 } 453 break; 427 case SDLK_DOWN: 428 { 429 if (!shiftKeyPressed) 430 m_iBufferPos_Tail = -1; 431 else if (!SelectingText()) 432 m_iBufferPos_Tail = m_iBufferPos; 454 433 455 case SDLK_DOWN: 434 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 435 while (current != m_CharacterPositions.end()) 456 436 { 457 if (!shiftKeyPressed) 458 { 459 m_iBufferPos_Tail = -1; 460 } 461 else if (!SelectingText()) 462 { 463 m_iBufferPos_Tail = m_iBufferPos; 464 } 437 if (m_iBufferPos >= current->m_ListStart && 438 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 439 break; 465 440 466 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 467 while (current != m_CharacterPositions.end()) 468 { 469 if (m_iBufferPos >= current->m_ListStart && 470 m_iBufferPos <= current->m_ListStart+(int)current->m_ListOfX.size()) 471 break; 441 ++current; 442 } 472 443 473 ++current; 474 } 444 float pos_x; 475 445 476 float pos_x; 446 if (m_iBufferPos-current->m_ListStart == 0) 447 pos_x = 0.f; 448 else 449 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 477 450 478 if (m_iBufferPos-current->m_ListStart == 0) 479 pos_x = 0.f; 480 else 481 pos_x = current->m_ListOfX[m_iBufferPos-current->m_ListStart-1]; 451 if (m_WantedX > pos_x) 452 pos_x = m_WantedX; 482 453 483 if (m_WantedX > pos_x) 484 pos_x = m_WantedX; 454 // Now change row: 455 // Add first, so we can check if it's .end() 456 ++current; 457 if (current != m_CharacterPositions.end()) 458 { 459 // Find X-position: 460 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 461 } 462 // else we can't move up 485 463 486 // Now change row: 487 // Add first, so we can check if it's .end() 488 ++current; 489 if (current != m_CharacterPositions.end()) 490 { 491 // Find X-position: 492 m_iBufferPos = current->m_ListStart + GetXTextPosition(current, pos_x, m_WantedX); 493 } 494 // else we can't move up 464 UpdateAutoScroll(); 465 break; 466 } 495 467 496 UpdateAutoScroll();497 }498 468 case SDLK_PAGEUP: 469 GetScrollBar(0).ScrollMinusPlenty(); 470 break; 499 471 500 case SDLK_PAGEUP: 501 GetScrollBar(0).ScrollMinusPlenty(); 502 break; 472 case SDLK_PAGEDOWN: 473 GetScrollBar(0).ScrollPlusPlenty(); 474 break; 475 /* END: Message History Lookup */ 503 476 504 case SDLK_PAGEDOWN: 505 GetScrollBar(0).ScrollPlusPlenty(); 477 case SDLK_KP_ENTER: 478 case SDLK_RETURN: 479 // 'Return' should do a Press event for single liners (e.g. submitting forms) 480 // otherwise a '\n' character will be added. 481 { 482 bool multiline; 483 GUI<bool>::GetSetting(this, "multiline", multiline); 484 if (!multiline) 485 { 486 SendEvent(GUIM_PRESSED, "press"); 506 487 break; 507 /* END: Message History Lookup */ 508 509 case SDLK_KP_ENTER: 510 case SDLK_RETURN: 511 // 'Return' should do a Press event for single liners (e.g. submitting forms) 512 // otherwise a '\n' character will be added. 513 { 514 bool multiline; 515 GUI<bool>::GetSetting(this, "multiline", multiline); 516 if (!multiline) 517 { 518 SendEvent(GUIM_PRESSED, "press"); 519 break; 520 } 488 } 521 489 522 523 524 525 526 490 cooked = '\n'; // Change to '\n' and do default: 491 // NOTE: Fall-through 492 } 493 default: //Insert a character 494 { 527 495 #if !SDL_VERSION_ATLEAST(2, 0, 0) 528 529 496 if (cooked == 0) 497 return IN_PASS; // Important, because we didn't use any key 530 498 #else // SDL2 531 532 533 534 499 // In SDL2, we no longer get Unicode wchars via SDL_Keysym 500 // we use text input events instead and they provide UTF-8 chars 501 if (ev->ev.type == SDL_KEYDOWN && cooked == 0) 502 return IN_HANDLED; 535 503 #endif 536 504 537 538 539 540 541 505 // check max length 506 int max_length; 507 GUI<int>::GetSetting(this, "max_length", max_length); 508 if (max_length != 0 && (int)pCaption->length() >= max_length) 509 break; 542 510 543 m_WantedX=0.0f;511 m_WantedX = 0.0f; 544 512 545 546 547 513 if (SelectingText()) 514 DeleteCurSelection(); 515 m_iBufferPos_Tail = -1; 548 516 549 550 551 552 553 517 if (m_iBufferPos == (int)pCaption->length()) 518 *pCaption += cooked; 519 else 520 *pCaption = pCaption->Left(m_iBufferPos) + cooked + 521 pCaption->Right((long) pCaption->length()-m_iBufferPos); 554 522 555 523 UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); 556 524 557 525 ++m_iBufferPos; 558 526 559 560 }561 break;527 UpdateAutoScroll(); 528 break; 529 } 562 530 } 563 531 564 532 UpdateBufferPositionSetting(); … … 571 539 572 540 InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) 573 541 { 574 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;542 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 575 543 bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT]; 576 544 577 545 std::string hotkey = static_cast<const char*>(ev->ev.user.data1); 578 546 if (hotkey == "paste") 579 547 { 580 m_WantedX =0.0f;548 m_WantedX = 0.0f; 581 549 582 550 wchar_t* text = sys_clipboard_get(); 583 551 if (text) 584 552 { 585 553 if (SelectingText()) 586 {587 554 DeleteCurSelection(); 588 }589 555 590 556 if (m_iBufferPos == (int)pCaption->length()) 591 557 *pCaption += text; … … 605 571 } 606 572 else if (hotkey == "copy" || hotkey == "cut") 607 573 { 608 m_WantedX =0.0f;574 m_WantedX = 0.0f; 609 575 610 576 if (SelectingText()) 611 577 { … … 637 603 } 638 604 else if (hotkey == "text.delete.left") 639 605 { 640 m_WantedX =0.0f;606 m_WantedX = 0.0f; 641 607 642 608 if (SelectingText()) 643 609 { … … 646 612 if (!pCaption->empty() && m_iBufferPos != 0) 647 613 { 648 614 m_iBufferPos_Tail = m_iBufferPos; 649 CStrW searchString = pCaption->Left( m_iBufferPos);615 CStrW searchString = pCaption->Left(m_iBufferPos); 650 616 651 617 // If we are starting in whitespace, adjust position until we get a non whitespace 652 618 while (m_iBufferPos > 0) … … 679 645 } 680 646 else if (hotkey == "text.delete.right") 681 647 { 682 m_WantedX =0.0f;648 m_WantedX = 0.0f; 683 649 684 650 if (SelectingText()) 685 651 { … … 703 669 if (!iswspace((*pCaption)[m_iBufferPos])) 704 670 break; 705 671 706 m_iBufferPos++;672 ++m_iBufferPos; 707 673 } 708 674 UpdateBufferPositionSetting(); 709 675 DeleteCurSelection(); … … 712 678 } 713 679 else if (hotkey == "text.move.left") 714 680 { 715 m_WantedX =0.0f;681 m_WantedX = 0.0f; 716 682 717 683 if (shiftKeyPressed || !SelectingText()) 718 684 { … … 727 693 728 694 if (!pCaption->empty() && m_iBufferPos != 0) 729 695 { 730 CStrW searchString = pCaption->Left( m_iBufferPos);696 CStrW searchString = pCaption->Left(m_iBufferPos); 731 697 732 698 // If we are starting in whitespace, adjust position until we get a non whitespace 733 699 while (m_iBufferPos > 0) … … 769 735 } 770 736 else if (hotkey == "text.move.right") 771 737 { 772 m_WantedX =0.0f;738 m_WantedX = 0.0f; 773 739 774 740 if (shiftKeyPressed || !SelectingText()) 775 741 { … … 799 765 if (!iswspace((*pCaption)[m_iBufferPos])) 800 766 break; 801 767 802 m_iBufferPos++;768 ++m_iBufferPos; 803 769 } 804 770 } 805 771 } … … 823 789 } 824 790 825 791 826 void CInput::HandleMessage(SGUIMessage &Message)792 void CInput::HandleMessage(SGUIMessage& Message) 827 793 { 828 // TODO Gee:829 794 IGUIScrollBarOwner::HandleMessage(Message); 830 795 831 796 switch (Message.type) 832 797 { 833 798 case GUIM_SETTINGS_UPDATED: 834 799 { 835 800 bool scrollbar; 836 801 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 837 802 … … 886 851 887 852 UpdateText(); 888 853 } 889 890 }break;854 break; 855 } 891 856 892 857 case GUIM_MOUSE_PRESS_LEFT: 893 // Check if we're selecting the scrollbar: 894 { 858 { 895 859 bool scrollbar, multiline; 896 860 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 897 861 GUI<bool>::GetSetting(this, "multiline", multiline); 898 862 863 // Check if we're selecting the scrollbar 899 864 if (GetScrollBar(0).GetStyle() && multiline) 900 865 { 901 866 if (GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) … … 921 886 922 887 // If we immediately release the button it will just be seen as a click 923 888 // for the user though. 924 925 }break;889 break; 890 } 926 891 927 892 case GUIM_MOUSE_DBLCLICK_LEFT: 928 929 930 893 { 894 if (m_ComposingText) 895 break; 931 896 932 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;897 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 933 898 934 if (pCaption->length() == 0)935 899 if (pCaption->empty()) 900 break; 936 901 937 902 m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition(); 938 903 939 940 904 if (m_iBufferPos >= (int)pCaption->length()) 905 m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1; 941 906 942 // See if we are clicking over whitespace 943 if (iswspace((*pCaption)[m_iBufferPos])) 907 // See if we are clicking over whitespace 908 if (iswspace((*pCaption)[m_iBufferPos])) 909 { 910 // see if we are in a section of whitespace greater than one character 911 if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) || 912 (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1]))) 944 913 { 945 // see if we are in a section of whitespace greater than one character 946 if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) || 947 (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1]))) 914 // 915 // We are clicking in an area with more than one whitespace character 916 // so we select both the word to the left and then the word to the right 917 // 918 // [1] First the left 919 // skip the whitespace 920 while (m_iBufferPos > 0) 948 921 { 949 // 950 // We are clicking in an area with more than one whitespace character 951 // so we select both the word to the left and then the word to the right 952 // 953 // [1] First the left 954 // skip the whitespace 955 while (m_iBufferPos > 0) 956 { 957 if (!iswspace((*pCaption)[m_iBufferPos - 1])) 958 break; 959 960 m_iBufferPos--; 961 } 962 // now go until we hit white space or punctuation 963 while (m_iBufferPos > 0) 964 { 965 if (iswspace((*pCaption)[m_iBufferPos - 1])) 966 break; 967 968 m_iBufferPos--; 922 if (!iswspace((*pCaption)[m_iBufferPos - 1])) 923 break; 969 924 970 if (iswpunct((*pCaption)[m_iBufferPos])) 971 break; 972 } 925 m_iBufferPos--; 926 } 927 // now go until we hit white space or punctuation 928 while (m_iBufferPos > 0) 929 { 930 if (iswspace((*pCaption)[m_iBufferPos - 1])) 931 break; 973 932 974 // [2] Then the right 975 // go right until we are not in whitespace 976 while (++m_iBufferPos_Tail < (int)pCaption->length()) 977 { 978 if (!iswspace((*pCaption)[m_iBufferPos_Tail])) 979 break; 980 } 933 m_iBufferPos--; 981 934 982 if ( m_iBufferPos_Tail == (int)pCaption->length())935 if (iswpunct((*pCaption)[m_iBufferPos])) 983 936 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 937 } 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 938 1001 if (m_iBufferPos_Tail == (int)pCaption->length()) 939 // [2] Then the right 940 // go right until we are not in whitespace 941 while (++m_iBufferPos_Tail < (int)pCaption->length()) 942 { 943 if (!iswspace((*pCaption)[m_iBufferPos_Tail])) 1002 944 break; 945 } 1003 946 1004 // Don't include the leading whitespace1005 m_iBufferPos = m_iBufferPos_Tail;947 if (m_iBufferPos_Tail == (int)pCaption->length()) 948 break; 1006 949 1007 // now go to the right until we hit whitespace or punctuation 1008 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1009 { 1010 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) 1011 break; 1012 } 950 // now go to the right until we hit whitespace or punctuation 951 while (++m_iBufferPos_Tail < (int)pCaption->length()) 952 { 953 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) 954 break; 1013 955 } 1014 956 } 1015 957 else 1016 958 { 1017 // clicked on non-whitespace so select current word 1018 // go until we hit white space or punctuation 1019 while (m_iBufferPos > 0) 959 // single whitespace so select word to the right 960 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1020 961 { 1021 if ( iswspace((*pCaption)[m_iBufferPos - 1]))962 if (!iswspace((*pCaption)[m_iBufferPos_Tail])) 1022 963 break; 964 } 1023 965 1024 m_iBufferPos--; 966 if (m_iBufferPos_Tail == (int)pCaption->length()) 967 break; 1025 968 1026 if (iswpunct((*pCaption)[m_iBufferPos]))1027 break;1028 } 1029 // go to the right until we hit whitespace or punctuation969 // Don't include the leading whitespace 970 m_iBufferPos = m_iBufferPos_Tail; 971 972 // now go to the right until we hit whitespace or punctuation 1030 973 while (++m_iBufferPos_Tail < (int)pCaption->length()) 1031 974 { 1032 975 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) … … 1034 977 } 1035 978 } 1036 979 } 980 else 981 { 982 // clicked on non-whitespace so select current word 983 // go until we hit white space or punctuation 984 while (m_iBufferPos > 0) 985 { 986 if (iswspace((*pCaption)[m_iBufferPos - 1])) 987 break; 988 989 m_iBufferPos--; 990 991 if (iswpunct((*pCaption)[m_iBufferPos])) 992 break; 993 } 994 // go to the right until we hit whitespace or punctuation 995 while (++m_iBufferPos_Tail < (int)pCaption->length()) 996 { 997 if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) 998 break; 999 } 1000 } 1037 1001 break; 1002 } 1038 1003 1039 1004 case GUIM_MOUSE_RELEASE_LEFT: 1040 1005 if (m_SelectingText) 1041 {1042 1006 m_SelectingText = false; 1043 }1044 1007 break; 1045 1008 1046 1009 case GUIM_MOUSE_MOTION: … … 1059 1022 break; 1060 1023 1061 1024 case GUIM_LOAD: 1062 1063 GetScrollBar(0).SetX( m_CachedActualSize.right);1064 GetScrollBar(0).SetY( m_CachedActualSize.top);1065 GetScrollBar(0).SetZ( GetBufferedZ());1066 GetScrollBar(0).SetLength( m_CachedActualSize.bottom - m_CachedActualSize.top);1025 { 1026 GetScrollBar(0).SetX(m_CachedActualSize.right); 1027 GetScrollBar(0).SetY(m_CachedActualSize.top); 1028 GetScrollBar(0).SetZ(GetBufferedZ()); 1029 GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); 1067 1030 1068 1031 CStr scrollbar_style; 1069 1032 GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); 1070 GetScrollBar(0).SetScrollBarStyle( scrollbar_style);1033 GetScrollBar(0).SetScrollBarStyle(scrollbar_style); 1071 1034 1072 1035 UpdateText(); 1073 }1074 1036 break; 1037 } 1075 1038 1076 1039 case GUIM_GOT_FOCUS: 1077 1040 m_iBufferPos = 0; … … 1164 1127 GUI<bool>::GetSetting(this, "mask", mask); 1165 1128 1166 1129 if (scrollbar && multiline) 1167 {1168 // Draw scrollbar1169 1130 IGUIScrollBarOwner::Draw(); 1131 1132 if (!GetGUI()) 1133 return; 1134 1135 CStrW font_name_w; 1136 CColor color, color_selected; 1137 GUI<CStrW>::GetSetting(this, "font", font_name_w); 1138 GUI<CColor>::GetSetting(this, "textcolor", color); 1139 GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected); 1140 CStrIntern font_name(font_name_w.ToUTF8()); 1141 1142 // Get pointer of caption, it might be very large, and we don't 1143 // want to copy it continuously. 1144 CStrW* pCaption = NULL; 1145 wchar_t mask_char = L'*'; 1146 if (mask) 1147 { 1148 CStrW maskStr; 1149 GUI<CStrW>::GetSetting(this, "mask_char", maskStr); 1150 if (maskStr.length() > 0) 1151 mask_char = maskStr[0]; 1170 1152 } 1153 else 1154 pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 1155 1156 CGUISpriteInstance* sprite = NULL; 1157 CGUISpriteInstance* sprite_selectarea = NULL; 1158 int cell_id; 1159 1160 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 1161 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea); 1171 1162 1172 if (GetGUI()) 1163 GUI<int>::GetSetting(this, "cell_id", cell_id); 1164 1165 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 1166 1167 float scroll = 0.f; 1168 if (scrollbar && multiline) 1169 scroll = GetScrollBar(0).GetPos(); 1170 1171 CFontMetrics font(font_name); 1172 1173 // We'll have to setup clipping manually, since we're doing the rendering manually. 1174 CRect cliparea(m_CachedActualSize); 1175 1176 // First we'll figure out the clipping area, which is the cached actual size 1177 // substracted by an optional scrollbar 1178 if (scrollbar) 1173 1179 { 1174 CStrW font_name_w; 1175 CColor color, color_selected; 1176 //CStrW caption; 1177 GUI<CStrW>::GetSetting(this, "font", font_name_w); 1178 GUI<CColor>::GetSetting(this, "textcolor", color); 1179 GUI<CColor>::GetSetting(this, "textcolor_selected", color_selected); 1180 CStrIntern font_name(font_name_w.ToUTF8()); 1180 scroll = GetScrollBar(0).GetPos(); 1181 1181 1182 // Get pointer of caption, it might be very large, and we don't 1183 // want to copy it continuously. 1184 CStrW *pCaption = NULL; 1185 wchar_t mask_char = L'*'; 1186 if (mask) 1187 { 1188 CStrW maskStr; 1189 GUI<CStrW>::GetSetting(this, "mask_char", maskStr); 1190 if (maskStr.length() > 0) 1191 mask_char = maskStr[0]; 1192 } 1193 else 1194 pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 1182 // substract scrollbar from cliparea 1183 if (cliparea.right > GetScrollBar(0).GetOuterRect().left && 1184 cliparea.right <= GetScrollBar(0).GetOuterRect().right) 1185 cliparea.right = GetScrollBar(0).GetOuterRect().left; 1195 1186 1196 CGUISpriteInstance *sprite=NULL, *sprite_selectarea=NULL; 1197 int cell_id; 1187 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && 1188 cliparea.left < GetScrollBar(0).GetOuterRect().right) 1189 cliparea.left = GetScrollBar(0).GetOuterRect().right; 1190 } 1198 1191 1199 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite); 1200 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea); 1192 if (cliparea != CRect()) 1193 { 1194 glEnable(GL_SCISSOR_TEST); 1195 glScissor( 1196 cliparea.left / g_GuiScale, 1197 g_yres - cliparea.bottom / g_GuiScale, 1198 cliparea.GetWidth() / g_GuiScale, 1199 cliparea.GetHeight() / g_GuiScale); 1200 } 1201 1201 1202 GUI<int>::GetSetting(this, "cell_id", cell_id); 1202 // These are useful later. 1203 int VirtualFrom, VirtualTo; 1203 1204 1204 GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); 1205 if (m_iBufferPos_Tail >= m_iBufferPos) 1206 { 1207 VirtualFrom = m_iBufferPos; 1208 VirtualTo = m_iBufferPos_Tail; 1209 } 1210 else 1211 { 1212 VirtualFrom = m_iBufferPos_Tail; 1213 VirtualTo = m_iBufferPos; 1214 } 1205 1215 1206 float scroll=0.f; 1207 if (scrollbar && multiline) 1208 { 1209 scroll = GetScrollBar(0).GetPos(); 1210 } 1216 // Get the height of this font. 1217 float h = (float)font.GetHeight(); 1218 float ls = (float)font.GetLineSpacing(); 1211 1219 1212 CFontMetrics font(font_name);1220 CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_gui_text); 1213 1221 1214 // We'll have to setup clipping manually, since we're doing the rendering manually.1215 CRect cliparea(m_CachedActualSize);1222 CTextRenderer textRenderer(tech->GetShader()); 1223 textRenderer.Font(font_name); 1216 1224 1217 // First we'll figure out the clipping area, which is the cached actual size 1218 // substracted by an optional scrollbar 1219 if (scrollbar) 1220 { 1221 scroll = GetScrollBar(0).GetPos(); 1225 // Set the Z to somewhat more, so we can draw a selected area between the 1226 // the control and the text. 1227 textRenderer.Translate( 1228 (float)(int)(m_CachedActualSize.left) + buffer_zone, 1229 (float)(int)(m_CachedActualSize.top+h) + buffer_zone, 1230 bz+0.1f); 1222 1231 1223 // substract scrollbar from cliparea 1224 if (cliparea.right > GetScrollBar(0).GetOuterRect().left && 1225 cliparea.right <= GetScrollBar(0).GetOuterRect().right) 1226 cliparea.right = GetScrollBar(0).GetOuterRect().left; 1232 // U+FE33: PRESENTATION FORM FOR VERTICAL LOW LINE 1233 // (sort of like a | which is aligned to the left of most characters) 1227 1234 1228 if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && 1229 cliparea.left < GetScrollBar(0).GetOuterRect().right) 1230 cliparea.left = GetScrollBar(0).GetOuterRect().right; 1231 } 1235 float buffered_y = -scroll+buffer_zone; 1232 1236 1233 if (cliparea != CRect()) 1234 { 1235 glEnable(GL_SCISSOR_TEST); 1236 glScissor( 1237 cliparea.left / g_GuiScale, 1238 g_yres - cliparea.bottom / g_GuiScale, 1239 cliparea.GetWidth() / g_GuiScale, 1240 cliparea.GetHeight() / g_GuiScale); 1241 } 1237 // When selecting larger areas, we need to draw a rectangle box 1238 // around it, and this is to keep track of where the box 1239 // started, because we need to follow the iteration until we 1240 // reach the end, before we can actually draw it. 1241 bool drawing_box = false; 1242 float box_x = 0.f; 1243 1244 float x_pointer = 0.f; 1245 1246 // If we have a selecting box (i.e. when you have selected letters, not just when 1247 // the pointer is between two letters) we need to process all letters once 1248 // before we do it the second time and render all the text. We can't do it 1249 // in the same loop because text will have been drawn, so it will disappear when 1250 // drawn behind the text that has already been drawn. Confusing, well it's necessary 1251 // (I think). 1252 1253 if (SelectingText()) 1254 { 1255 // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos, 1256 // just like you can select from right to left, as you can 1257 // left to right. Is there a difference? Yes, the pointer 1258 // be placed accordingly, so that if you select shift and 1259 // expand this selection, it will expand on appropriate side. 1260 // Anyway, since the drawing procedure needs "To" to be 1261 // greater than from, we need virtual values that might switch 1262 // place. 1242 1263 1243 // These are useful later.1244 1264 int VirtualFrom, VirtualTo; 1245 1265 1246 1266 if (m_iBufferPos_Tail >= m_iBufferPos) … … 1254 1274 VirtualTo = m_iBufferPos; 1255 1275 } 1256 1276 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 1277 1276 float buffered_y = -scroll+buffer_zone; 1277 1278 // When selecting larger areas, we need to draw a rectangle box 1279 // around it, and this is to keep track of where the box 1280 // started, because we need to follow the iteration until we 1281 // reach the end, before we can actually draw it. 1282 bool drawing_box = false; 1283 float box_x=0.f; 1284 1285 float x_pointer=0.f; 1286 1287 // If we have a selecting box (i.e. when you have selected letters, not just when 1288 // the pointer is between two letters) we need to process all letters once 1289 // before we do it the second time and render all the text. We can't do it 1290 // in the same loop because text will have been drawn, so it will disappear when 1291 // drawn behind the text that has already been drawn. Confusing, well it's necessary 1292 // (I think). 1293 1294 if (SelectingText()) 1278 bool done = false; 1279 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1280 it != m_CharacterPositions.end(); 1281 ++it, buffered_y += ls, x_pointer = 0.f) 1295 1282 { 1296 // Now m_iBufferPos_Tail can be of both sides of m_iBufferPos, 1297 // just like you can select from right to left, as you can 1298 // left to right. Is there a difference? Yes, the pointer 1299 // be placed accordingly, so that if you select shift and 1300 // expand this selection, it will expand on appropriate side. 1301 // Anyway, since the drawing procedure needs "To" to be 1302 // greater than from, we need virtual values that might switch 1303 // place. 1304 1305 int VirtualFrom, VirtualTo; 1306 1307 if (m_iBufferPos_Tail >= m_iBufferPos) 1308 { 1309 VirtualFrom = m_iBufferPos; 1310 VirtualTo = m_iBufferPos_Tail; 1311 } 1312 else 1313 { 1314 VirtualFrom = m_iBufferPos_Tail; 1315 VirtualTo = m_iBufferPos; 1316 } 1317 1283 if (multiline 1284 && buffered_y > m_CachedActualSize.GetHeight()) 1285 break; 1318 1286 1319 bool done = false; 1320 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1321 it != m_CharacterPositions.end(); 1322 ++it, buffered_y += ls, x_pointer = 0.f) 1287 // We might as well use 'i' here to iterate, because we need it 1288 // (often compared against ints, so don't make it size_t) 1289 for (int i = 0; i < (int)it->m_ListOfX.size()+2; ++i) 1323 1290 { 1324 if ( multiline)1291 if (it->m_ListStart + i == VirtualFrom) 1325 1292 { 1326 if (buffered_y > m_CachedActualSize.GetHeight()) 1327 break; 1293 // we won't actually draw it now, because we don't 1294 // know the width of each glyph to that position. 1295 // we need to go along with the iteration, and 1296 // make a mark where the box started: 1297 drawing_box = true; // will turn false when finally rendered. 1298 1299 // Get current x position 1300 box_x = x_pointer; 1328 1301 } 1329 1302 1330 // We might as well use 'i' here to iterate, because we need it 1331 // (often compared against ints, so don't make it size_t) 1332 for (int i=0; i < (int)it->m_ListOfX.size()+2; ++i) 1333 { 1334 if (it->m_ListStart + i == VirtualFrom) 1335 { 1336 // we won't actually draw it now, because we don't 1337 // know the width of each glyph to that position. 1338 // we need to go along with the iteration, and 1339 // make a mark where the box started: 1340 drawing_box = true; // will turn false when finally rendered. 1341 1342 // Get current x position 1343 box_x = x_pointer; 1344 } 1345 1346 // no else! 1303 // no else! 1347 1304 1348 1305 const bool at_end = (i == (int)it->m_ListOfX.size()+1); 1349 1306 1350 if (drawing_box == true && 1351 (it->m_ListStart + i == VirtualTo || at_end)) 1307 if (drawing_box == true && 1308 (it->m_ListStart + i == VirtualTo || at_end)) 1309 { 1310 // Depending on if it's just a row change, or if it's 1311 // the end of the select box, do slightly different things. 1312 if (at_end) 1352 1313 { 1353 // Depending on if it's just a row change, or if it's 1354 // the end of the select box, do slightly different things. 1355 if (at_end) 1314 if (it->m_ListStart + i != VirtualFrom) 1356 1315 { 1357 if (it->m_ListStart + i != VirtualFrom) 1358 { 1359 // and actually add a white space! yes, this is done in any common input 1360 x_pointer += (float)font.GetCharacterWidth(L' '); 1361 } 1316 // and actually add a white space! yes, this is done in any common input 1317 x_pointer += (float)font.GetCharacterWidth(L' '); 1362 1318 } 1363 else 1364 { 1365 drawing_box = false; 1366 done = true; 1367 } 1368 1369 CRect rect; 1370 // Set 'rect' depending on if it's a multiline control, or a one-line control 1371 if (multiline) 1372 { 1373 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone, 1374 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1375 m_CachedActualSize.left+x_pointer+buffer_zone, 1376 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1319 } 1320 else 1321 { 1322 drawing_box = false; 1323 done = true; 1324 } 1377 1325 1378 if (rect.bottom < m_CachedActualSize.top) 1379 continue; 1326 CRect rect; 1327 // Set 'rect' depending on if it's a multiline control, or a one-line control 1328 if (multiline) 1329 { 1330 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone, 1331 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1332 m_CachedActualSize.left+x_pointer+buffer_zone, 1333 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1380 1334 1381 if (rect.top< m_CachedActualSize.top)1382 rect.top = m_CachedActualSize.top;1335 if (rect.bottom < m_CachedActualSize.top) 1336 continue; 1383 1337 1384 if (rect.bottom > m_CachedActualSize.bottom) 1385 rect.bottom = m_CachedActualSize.bottom; 1386 } 1387 else // if one-line 1388 { 1389 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll, 1390 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1391 m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll, 1392 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1338 if (rect.top < m_CachedActualSize.top) 1339 rect.top = m_CachedActualSize.top; 1393 1340 1394 if (rect.left < m_CachedActualSize.left) 1395 rect.left = m_CachedActualSize.left; 1341 if (rect.bottom > m_CachedActualSize.bottom) 1342 rect.bottom = m_CachedActualSize.bottom; 1343 } 1344 else // if one-line 1345 { 1346 rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll, 1347 m_CachedActualSize.top+buffered_y+(h-ls)/2, 1348 m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll, 1349 m_CachedActualSize.top+buffered_y+(h+ls)/2); 1396 1350 1397 if (rect.right > m_CachedActualSize.right) 1398 rect.right = m_CachedActualSize.right; 1399 } 1351 if (rect.left < m_CachedActualSize.left) 1352 rect.left = m_CachedActualSize.left; 1400 1353 1401 if ( sprite_selectarea)1402 GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect);1354 if (rect.right > m_CachedActualSize.right) 1355 rect.right = m_CachedActualSize.right; 1403 1356 } 1404 1357 1405 if (i < (int)it->m_ListOfX.size()) 1406 { 1407 if (!mask) 1408 x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]); 1409 else 1410 x_pointer += (float)font.GetCharacterWidth(mask_char); 1411 } 1358 if (sprite_selectarea) 1359 GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect); 1412 1360 } 1413 1361 1414 if (done) 1415 break; 1416 1417 // If we're about to draw a box, and all of a sudden changes 1418 // line, we need to draw that line's box, and then reset 1419 // the box drawing to the beginning of the new line. 1420 if (drawing_box) 1362 if (i < (int)it->m_ListOfX.size()) 1421 1363 { 1422 box_x = 0.f; 1364 if (!mask) 1365 x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]); 1366 else 1367 x_pointer += (float)font.GetCharacterWidth(mask_char); 1423 1368 } 1424 1369 } 1370 1371 if (done) 1372 break; 1373 1374 // If we're about to draw a box, and all of a sudden changes 1375 // line, we need to draw that line's box, and then reset 1376 // the box drawing to the beginning of the new line. 1377 if (drawing_box) 1378 box_x = 0.f; 1425 1379 } 1380 } 1426 1381 1427 1428 1382 // Reset some from previous run 1383 buffered_y = -scroll; 1429 1384 1430 1431 1385 // Setup initial color (then it might change and change back, when drawing selected area) 1386 textRenderer.Color(color); 1432 1387 1433 1388 tech->BeginPass(); 1434 1389 1435 1390 bool using_selected_color = false; 1436 1391 1437 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1438 it != m_CharacterPositions.end(); 1439 ++it, buffered_y += ls) 1392 for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); 1393 it != m_CharacterPositions.end(); 1394 ++it, buffered_y += ls) 1395 { 1396 if (buffered_y + buffer_zone >= -ls || !multiline) 1440 1397 { 1441 if (buffered_y + buffer_zone >= -ls || !multiline) 1442 { 1443 if (multiline) 1444 { 1445 if (buffered_y + buffer_zone > m_CachedActualSize.GetHeight()) 1446 break; 1447 } 1398 if (multiline 1399 && buffered_y + buffer_zone > m_CachedActualSize.GetHeight()) 1400 break; 1448 1401 1449 1402 CMatrix3D savedTransform = textRenderer.GetTransform(); 1450 1403 1451 1452 1453 1454 1455 1404 // Text must always be drawn in integer values. So we have to convert scroll 1405 if (multiline) 1406 textRenderer.Translate(0.f, -(float)(int)scroll, 0.f); 1407 else 1408 textRenderer.Translate(-(float)(int)m_HorizontalScroll, 0.f, 0.f); 1456 1409 1457 // We might as well use 'i' here, because we need it 1458 // (often compared against ints, so don't make it size_t) 1459 for (int i=0; i < (int)it->m_ListOfX.size()+1; ++i) 1410 // We might as well use 'i' here, because we need it 1411 // (often compared against ints, so don't make it size_t) 1412 for (int i = 0; i < (int)it->m_ListOfX.size()+1; ++i) 1413 { 1414 if (!multiline && i < (int)it->m_ListOfX.size()) 1460 1415 { 1461 if (!multiline && i < (int)it->m_ListOfX.size()) 1462 { 1463 if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone) 1464 { 1465 // We still need to translate the OpenGL matrix 1466 if (i == 0) 1467 textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f); 1468 else 1469 textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f); 1470 1471 continue; 1472 } 1473 } 1474 1475 // End of selected area, change back color 1476 if (SelectingText() && 1477 it->m_ListStart + i == VirtualTo) 1478 { 1479 using_selected_color = false; 1480 textRenderer.Color(color); 1481 } 1482 1483 if (i != (int)it->m_ListOfX.size() && 1484 it->m_ListStart + i == m_iBufferPos) 1485 { 1486 // selecting only one, then we need only to draw a cursor. 1487 if (m_CursorVisState) 1488 textRenderer.Put(0.0f, 0.0f, L"_"); 1489 } 1490 1491 // Drawing selected area 1492 if (SelectingText() && 1493 it->m_ListStart + i >= VirtualFrom && 1494 it->m_ListStart + i < VirtualTo && 1495 using_selected_color == false) 1496 { 1497 using_selected_color = true; 1498 textRenderer.Color(color_selected); 1499 } 1500 1501 if (i != (int)it->m_ListOfX.size()) 1416 if (it->m_ListOfX[i] - m_HorizontalScroll < -buffer_zone) 1502 1417 { 1503 if (!mask) 1504 textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]); 1418 // We still need to translate the OpenGL matrix 1419 if (i == 0) 1420 textRenderer.Translate(it->m_ListOfX[i], 0.f, 0.f); 1505 1421 else 1506 textRenderer.PrintfAdvance(L"%lc", mask_char); 1507 } 1422 textRenderer.Translate(it->m_ListOfX[i] - it->m_ListOfX[i-1], 0.f, 0.f); 1508 1423 1509 // check it's now outside a one-liner, then we'll break 1510 if (!multiline && i < (int)it->m_ListOfX.size()) 1511 { 1512 if (it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone) 1513 break; 1424 continue; 1514 1425 } 1515 1426 } 1516 1427 1517 if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos) 1428 // End of selected area, change back color 1429 if (SelectingText() && 1430 it->m_ListStart + i == VirtualTo) 1518 1431 { 1432 using_selected_color = false; 1519 1433 textRenderer.Color(color); 1520 if (m_CursorVisState) 1521 textRenderer.PutAdvance(L"_"); 1434 } 1522 1435 1523 if (using_selected_color) 1524 { 1525 textRenderer.Color(color_selected); 1526 } 1436 // selecting only one, then we need only to draw a cursor. 1437 if (i != (int)it->m_ListOfX.size() 1438 && it->m_ListStart + i == m_iBufferPos 1439 && m_CursorVisState) 1440 textRenderer.Put(0.0f, 0.0f, L"_"); 1441 1442 // Drawing selected area 1443 if (SelectingText() && 1444 it->m_ListStart + i >= VirtualFrom && 1445 it->m_ListStart + i < VirtualTo && 1446 using_selected_color == false) 1447 { 1448 using_selected_color = true; 1449 textRenderer.Color(color_selected); 1450 } 1451 1452 if (i != (int)it->m_ListOfX.size()) 1453 { 1454 if (!mask) 1455 textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]); 1456 else 1457 textRenderer.PrintfAdvance(L"%lc", mask_char); 1527 1458 } 1528 1459 1529 textRenderer.SetTransform(savedTransform); 1460 // check it's now outside a one-liner, then we'll break 1461 if (!multiline && i < (int)it->m_ListOfX.size() 1462 && it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth()-buffer_zone) 1463 break; 1530 1464 } 1531 1465 1532 textRenderer.Translate(0.f, ls, 0.f); 1533 } 1466 if (it->m_ListStart + (int)it->m_ListOfX.size() == m_iBufferPos) 1467 { 1468 textRenderer.Color(color); 1469 if (m_CursorVisState) 1470 textRenderer.PutAdvance(L"_"); 1534 1471 1535 textRenderer.Render(); 1472 if (using_selected_color) 1473 textRenderer.Color(color_selected); 1474 } 1536 1475 1537 if (cliparea != CRect())1538 glDisable(GL_SCISSOR_TEST);1476 textRenderer.SetTransform(savedTransform); 1477 } 1539 1478 1540 te ch->EndPass();1479 textRenderer.Translate(0.f, ls, 0.f); 1541 1480 } 1481 1482 textRenderer.Render(); 1483 1484 if (cliparea != CRect()) 1485 glDisable(GL_SCISSOR_TEST); 1486 1487 tech->EndPass(); 1542 1488 } 1543 1489 1544 1490 void CInput::UpdateText(int from, int to_before, int to_after) … … 1603 1549 { 1604 1550 ENSURE(to_before != -1); 1605 1551 1606 std::list<SRow>::iterator destroy_row_from, destroy_row_to; 1552 std::list<SRow>::iterator destroy_row_from; 1553 std::list<SRow>::iterator destroy_row_to; 1607 1554 // Used to check if the above has been set to anything, 1608 1555 // previously a comparison like: 1609 1556 // destroy_row_from == std::list<SRow>::iterator() 1610 1557 // ... was used, but it didn't work with GCC. 1611 bool destroy_row_from_used=false, destroy_row_to_used=false; 1558 bool destroy_row_from_used = false; 1559 bool destroy_row_to_used = false; 1612 1560 1613 1561 // Iterate, and remove everything between 'from' and 'to_before' 1614 1562 // actually remove the entire lines they are on, it'll all have 1615 1563 // to be redone. And when going along, we'll delete a row at a time 1616 1564 // when continuing to see how much more after 'to' we need to remake. 1617 int i =0;1565 int i = 0; 1618 1566 for (std::list<SRow>::iterator it = m_CharacterPositions.begin(); 1619 it != m_CharacterPositions.end(); ++it, ++i) 1567 it != m_CharacterPositions.end(); 1568 ++it, ++i) 1620 1569 { 1621 1570 if (destroy_row_from_used == false && 1622 1571 it->m_ListStart > from) … … 1705 1654 if (delta != 0) 1706 1655 { 1707 1656 for (std::list<SRow>::iterator it = current_line; 1708 it != m_CharacterPositions.end(); 1709 ++it) 1710 { 1657 it != m_CharacterPositions.end(); 1658 ++it) 1711 1659 it->m_ListStart += delta; 1712 }1713 1660 1714 1661 // Update our check point too! 1715 1662 check_point_row_start += delta; … … 1720 1667 } 1721 1668 } 1722 1669 1723 int last_word_started=from; 1724 //int last_list_start=-1; // unused 1670 int last_word_started = from; 1725 1671 float x_pos = 0.f; 1726 1672 1727 1673 //if (to_before != -1) 1728 1674 // return; 1729 1675 1730 for (int i =from; i<to; ++i)1676 for (int i = from; i < to; ++i) 1731 1677 { 1732 1678 if (caption[i] == L'\n' && multiline) 1733 1679 { 1734 if (i ==to-1 && to != (int)caption.length())1680 if (i == to-1 && to != (int)caption.length()) 1735 1681 break; // it will be added outside 1736 1682 1737 current_line = m_CharacterPositions.insert( current_line, row);1683 current_line = m_CharacterPositions.insert(current_line, row); 1738 1684 ++current_line; 1739 1685 1740 1686 … … 1764 1710 { 1765 1711 last_word_started = i; 1766 1712 row.m_ListOfX.resize(row.m_ListOfX.size() - (i-last_word_started)); 1767 //row.m_ListOfX.push_back( x_pos);1713 //row.m_ListOfX.push_back(x_pos); 1768 1714 //continue; 1769 1715 } 1770 1716 else … … 1779 1725 // rows. With automatic word-wrapping, that is not possible. Which 1780 1726 // is intuitively correct. 1781 1727 1782 current_line = m_CharacterPositions.insert( current_line, row);1728 current_line = m_CharacterPositions.insert(current_line, row); 1783 1729 ++current_line; 1784 1730 1785 1731 // Setup the next row: 1786 1732 row.m_ListOfX.clear(); 1787 1733 row.m_ListStart = last_word_started; 1788 1734 1789 i =last_word_started-1;1735 i = last_word_started-1; 1790 1736 1791 1737 x_pos = 0.f; 1792 1738 } 1793 1739 else 1794 1740 // Get width of this character: 1795 row.m_ListOfX.push_back( x_pos);1741 row.m_ListOfX.push_back(x_pos); 1796 1742 } 1797 1743 1798 1744 // Check if it's the last iteration, and we're not revising the whole string … … 1803 1749 // check all rows and see if any existing 1804 1750 if (row.m_ListStart != check_point_row_start) 1805 1751 { 1806 std::list<SRow>::iterator destroy_row_from, destroy_row_to; 1752 std::list<SRow>::iterator destroy_row_from; 1753 std::list<SRow>::iterator destroy_row_to; 1807 1754 // Are used to check if the above has been set to anything, 1808 1755 // previously a comparison like: 1809 1756 // destroy_row_from == std::list<SRow>::iterator() 1810 1757 // was used, but it didn't work with GCC. 1811 bool destroy_row_from_used=false, destroy_row_to_used=false; 1758 bool destroy_row_from_used = false; 1759 bool destroy_row_to_used = false; 1812 1760 1813 1761 // Iterate, and remove everything between 'from' and 'to_before' 1814 1762 // actually remove the entire lines they are on, it'll all have 1815 1763 // to be redone. And when going along, we'll delete a row at a time 1816 1764 // when continuing to see how much more after 'to' we need to remake. 1817 int i=0; 1818 for (std::list<SRow>::iterator it=m_CharacterPositions.begin(); 1819 it!=m_CharacterPositions.end(); ++it, ++i) 1765 int i = 0; 1766 for (std::list<SRow>::iterator it = m_CharacterPositions.begin(); 1767 it != m_CharacterPositions.end(); 1768 ++it, ++i) 1820 1769 { 1821 1770 if (destroy_row_from_used == false && 1822 1771 it->m_ListStart > check_point_row_start) … … 1843 1792 // have to continue. 1844 1793 // 'check_point_row_start' is where we store how the that 1845 1794 // line looked. 1846 // if (destroy_row_to !=1847 1795 if (destroy_row_to != m_CharacterPositions.end()) 1848 1796 { 1849 1797 check_point_row_start = destroy_row_to->m_ListStart; … … 1884 1832 // in the coming erase. 1885 1833 current_line = destroy_row_to; 1886 1834 1887 std::list<SRow>::iterator temp = destroy_row_to;1888 1889 --temp;1890 1891 1835 m_CharacterPositions.erase(destroy_row_from, destroy_row_to); 1892 1836 } 1893 1837 // else, the for loop will end naturally. … … 1900 1844 if (current_line != m_CharacterPositions.end()) 1901 1845 { 1902 1846 if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart) 1903 row.m_ListOfX.resize( row.m_ListOfX.size()-1);1847 row.m_ListOfX.resize(row.m_ListOfX.size()-1); 1904 1848 } 1905 1849 1906 1850 // add the final row (even if empty) … … 1941 1885 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 1942 1886 CStrIntern font_name(font_name_w.ToUTF8()); 1943 1887 1944 float scroll =0.f;1888 float scroll = 0.f; 1945 1889 if (scrollbar) 1946 {1947 1890 scroll = GetScrollBar(0).GetPos(); 1948 }1949 1891 1950 1892 // Pointer to caption, will come in handy 1951 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;1893 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 1952 1894 UNUSED2(pCaption); 1953 1895 1954 1896 // Now get the height of the font. … … 1975 1917 // TODO Gee (2004-11-21): Okay, I need a 'std::list' for some reasons, but I would really like to 1976 1918 // be able to get the specific element here. This is hopefully a temporary hack. 1977 1919 1978 for (int i =0; i<row; ++i)1920 for (int i = 0; i < row; ++i) 1979 1921 ++current; 1980 1922 } 1981 1923 else … … 1998 1940 } 1999 1941 2000 1942 // 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)1943 int CInput::GetXTextPosition(const std::list<SRow>::iterator& current, const float& x, float& wanted) 2002 1944 { 2003 int ret =0;2004 float previous =0.f;2005 int i =0;1945 int ret = 0; 1946 float previous = 0.f; 1947 int i = 0; 2006 1948 2007 for (std::vector<float>::iterator it =current->m_ListOfX.begin();2008 it!=current->m_ListOfX.end();2009 1949 for (std::vector<float>::iterator it = current->m_ListOfX.begin(); 1950 it != current->m_ListOfX.end(); 1951 ++it, ++i) 2010 1952 { 2011 1953 if (*it >= x) 2012 1954 { … … 2026 1968 ret += i; 2027 1969 wanted = x; 2028 1970 } 2029 else wanted = 0.f; 1971 else 1972 wanted = 0.f; 2030 1973 2031 1974 return ret; 2032 1975 } 2033 1976 2034 1977 void CInput::DeleteCurSelection() 2035 1978 { 2036 CStrW *pCaption = (CStrW*)m_Settings["caption"].m_pSetting;1979 CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; 2037 1980 2038 1981 int virtualFrom; 2039 1982 int virtualTo; … … 2049 1992 virtualTo = m_iBufferPos; 2050 1993 } 2051 1994 2052 *pCaption = pCaption->Left( virtualFrom) +2053 pCaption->Right( (long) pCaption->length() - (virtualTo));1995 *pCaption = pCaption->Left(virtualFrom) + 1996 pCaption->Right((long)pCaption->length() - virtualTo); 2054 1997 2055 1998 UpdateText(virtualFrom, virtualTo, virtualFrom); 2056 1999 … … 2095 2038 GUI<bool>::GetSetting(this, "scrollbar", scrollbar); 2096 2039 CStrIntern font_name(font_name_w.ToUTF8()); 2097 2040 2098 float scroll =0.f;2041 float scroll = 0.f; 2099 2042 if (!scrollbar) 2100 2043 return; 2101 2044 … … 2111 2054 // be able to get the specific element here. This is hopefully a temporary hack. 2112 2055 2113 2056 std::list<SRow>::iterator current = m_CharacterPositions.begin(); 2114 int row =0;2057 int row = 0; 2115 2058 while (current != m_CharacterPositions.end()) 2116 2059 { 2117 2060 if (m_iBufferPos >= current->m_ListStart && … … 2128 2071 // Scroll so the selected row is shown completely, also with buffer_zone length to the edge. 2129 2072 GetScrollBar(0).SetPos((float)(row+1) * spacing - m_CachedActualSize.GetHeight() + buffer_zone*2.f); 2130 2073 } 2131 else2132 2074 // If scrolling up 2133 if (-scroll + (float)row * spacing < 0.f)2075 else if (-scroll + (float)row * spacing < 0.f) 2134 2076 { 2135 2077 // Scroll so the selected row is shown completely, also with buffer_zone length to the edge. 2136 2078 GetScrollBar(0).SetPos((float)row * spacing); … … 2153 2095 x_position = m_CharacterPositions.begin()->m_ListOfX[m_iBufferPos-1]; 2154 2096 2155 2097 // Get complete length: 2156 x_total = m_CharacterPositions.begin()->m_ListOfX[ m_CharacterPositions.begin()->m_ListOfX.size()-1];2098 x_total = m_CharacterPositions.begin()->m_ListOfX[m_CharacterPositions.begin()->m_ListOfX.size()-1]; 2157 2099 } 2158 2100 2159 2101 // Check if outside to the right -
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. … … 118 90 * appears, because then the word-wrapping won't change after 119 91 * that. 120 92 */ 121 void UpdateText(int from =0, int to_before=-1, int to_after=-1);93 void UpdateText(int from = 0, int to_before = -1, int to_after = -1); 122 94 123 95 /** 124 96 * Delete the current selection. Also places the pointer at the … … 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(); … … 113 99 if (scrollbar && GetScrollBar(0).GetStyle()) 114 100 width -= GetScrollBar(0).GetStyle()->m_Width; 115 101 116 float buffer_zone =0.f;102 float buffer_zone = 0.f; 117 103 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 118 104 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 float scroll =0.f;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(); 219 196 mouse.y += scroll; 220 int set =-1;221 for (int i =0; i<(int)pList->m_Items.size(); ++i)197 int set = -1; 198 for (int i = 0; i < (int)pList->m_Items.size(); ++i) 222 199 { 223 200 if (mouse.y >= rect.top + m_ItemsYPositions[i] && 224 201 mouse.y < rect.top + m_ItemsYPositions[i+1] && … … 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 float scroll =0.f;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; … … 77 76 // Cache width for other use 78 77 m_TotalAvalibleColumnWidth = width; 79 78 80 float buffer_zone =0.f;79 float buffer_zone = 0.f; 81 80 GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); 82 81 83 82 CStr defaultColumn; 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 if (c ==0)111 if (c == 0) 113 112 buffered_y += text->m_Size.cy; 114 113 AddText(text); 115 114 } … … 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; 72 CGUISpriteInstance* sprite_bar; 73 int cell_id = 0; 74 float value = 0; 75 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_background", sprite_background); 76 GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_bar", sprite_bar); 77 GUI<float>::GetSetting(this, "caption", value); 85 78 79 GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize); 86 80 87 // Get size of bar (notice it is drawn slightly closer, to appear above the background) 88 CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, 89 m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); 90 GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size); 91 } 81 // Get size of bar (notice it is drawn slightly closer, to appear above the background) 82 CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, 83 m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); 84 GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size); 92 85 } -
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 … … 92 86 width -= GetScrollBar(0).GetStyle()->m_Width; 93 87 94 88 95 float buffer_zone =0.f;89 float buffer_zone = 0.f; 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" … … 66 64 if (!GetGUI()) 67 65 return; 68 66 69 ENSURE(m_GeneratedTexts.size() ==1);67 ENSURE(m_GeneratedTexts.size() == 1); 70 68 71 69 CStrW font; 72 70 if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) … … 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; … … 34 35 { 35 36 public: 36 37 virtual ~IGLState() {}; 37 virtual void Set(const CTexturePtr& tex) =0;38 virtual void Unset() =0;38 virtual void Set(const CTexturePtr& tex) = 0; 39 virtual void Unset() = 0; 39 40 }; 40 41 41 42 struct SDrawCall … … 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 … … 339 340 // "ride this tail", it have to wait. 340 341 // Notice that this doesn't apply to when you go from one delay=0 341 342 // to another delay=0 342 if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI) ==0 &&343 GetTooltipDelay(style, GUI) !=0)343 if (GetTooltip(m_PreviousObject, style_old) && GetTooltipDelay(style_old, GUI) == 0 && 344 GetTooltipDelay(style, GUI) != 0) 344 345 { 345 346 HideTooltip(m_PreviousTooltipName, GUI); 346 347 nextstate = ST_IN_MOTION; -
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
44 44 m_TextCalls.clear(); 45 45 m_SpriteCalls.clear(); 46 46 m_Size = CSize(); 47 m_NewLine =false;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 /** … … 248 248 struct SFeedback 249 249 { 250 250 // Constants 251 static const int Left =0;252 static const int Right =1;251 static const int Left = 0; 252 static const int Right = 1; 253 253 254 254 /** 255 255 * Reset all member data. … … 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 if (GUIinstance.m_Styles.count(StyleName) ==1)344 if (GUIinstance.m_Styles.count(StyleName) == 1) 374 345 { 375 346 LoadStyle(GUIinstance.m_Styles[StyleName]); 376 347 } … … 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. … … 439 409 CStr CodeName = GetName()+" "+Action; 440 410 441 411 // Generate a unique name 442 static int x =0;412 static int x = 0; 443 413 char buf[64]; 444 414 sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str()); 445 415 … … 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 //-------------------------------------------------------- … … 255 238 * 256 239 * @return PSRETURN (PSRETURN_OK if successful) 257 240 */ 258 PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage =false);241 PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage = false); 259 242 260 243 /** 261 244 * Retrieves the type of a named setting. … … 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. … … 326 309 * it'll probably only output in the Error log, and not 327 310 * disrupt the whole GUI drawing. 328 311 */ 329 virtual void Draw() =0;312 virtual void Draw() = 0; 330 313 331 314 /** 332 315 * Some objects need to handle the SDL_Event_ manually. … … 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 m_ButtonMinusPressed = false; 168 m_ButtonPlusPressed = false; 169 break; 170 171 case GUIM_MOUSE_WHEEL_UP: 172 { 173 ScrollMinus(); 174 // Since the scroll was changed, let's simulate a mouse movement 175 // to check if scrollbar now is hovered 176 SGUIMessage msg(GUIM_MOUSE_MOTION); 177 HandleMessage(msg); 178 break; 179 } 180 181 case GUIM_MOUSE_WHEEL_DOWN: 182 { 183 ScrollPlus(); 184 // Since the scroll was changed, let's simulate a mouse movement 185 // to check if scrollbar now is hovered 186 SGUIMessage msg(GUIM_MOUSE_MOTION); 187 HandleMessage(msg); 188 break; 189 } 190 191 default: 192 break; 203 193 } 204 194 } -
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 * … … 169 162 /** 170 163 * Draw the scroll-bar 171 164 */ 172 virtual void Draw() =0;165 virtual void Draw() = 0; 173 166 174 167 /** 175 168 * If an object that contains a scrollbar has got messages, send … … 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 … … 100 85 /** 101 86 * Setup texts. Functions that sets up all texts when changes have been made. 102 87 */ 103 virtual void SetupText() =0;88 virtual void SetupText() = 0; 104 89 105 90 /** 106 91 * Whether the cached text is currently valid (if not then SetupText will be called by Draw) … … 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/JSInterface_IGUIObject.cpp
88 88 // Use onWhatever to access event handlers 89 89 if (propName.substr(0, 2) == "on") 90 90 { 91 CStr eventName 91 CStr eventName(CStr(propName.substr(2)).LowerCase()); 92 92 auto it = e->m_ScriptHandlers.find(eventName); 93 93 if (it == e->m_ScriptHandlers.end()) 94 94 vp.setNull(); … … 135 135 switch (Type) 136 136 { 137 137 case GUIST_bool: 138 139 140 141 142 143 138 { 139 bool value; 140 GUI<bool>::GetSetting(e, propName, value); 141 vp.set(JS::BooleanValue(value)); 142 break; 143 } 144 144 145 145 case GUIST_int: 146 147 148 149 150 151 146 { 147 int value; 148 GUI<int>::GetSetting(e, propName, value); 149 vp.set(JS::Int32Value(value)); 150 break; 151 } 152 152 153 153 case GUIST_float: 154 155 156 157 158 159 160 154 { 155 float value; 156 GUI<float>::GetSetting(e, propName, value); 157 // Create a garbage-collectable double 158 vp.set(JS::NumberValue(value)); 159 return !vp.isNull(); 160 } 161 161 162 162 case GUIST_CColor: 163 164 165 166 167 168 169 170 #define P(x) c = JS::NumberValue(color.x);\171 if (c.isNull())\172 return false;\173 JS_SetProperty(cx, obj, #x, c)174 P(r);175 P(g);176 P(b);177 P(a);178 #undef P179 180 181 163 { 164 CColor color; 165 GUI<CColor>::GetSetting(e, propName, color); 166 JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor")); 167 vp.setObject(*obj); 168 JS::RootedValue c(cx); 169 // Attempt to minimise ugliness through macrosity 170 #define P(x) \ 171 c = JS::NumberValue(color.x); \ 172 if (c.isNull()) \ 173 return false; \ 174 JS_SetProperty(cx, obj, #x, c) 175 P(r); 176 P(g); 177 P(b); 178 P(a); 179 #undef P 180 break; 181 } 182 182 183 183 case GUIST_CClientArea: 184 { 185 CClientArea area; 186 GUI<CClientArea>::GetSetting(e, propName, area); 187 188 JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize")); 189 vp.setObject(*obj); 190 try 191 { 192 #define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true) 193 P(pixel, left, left); 194 P(pixel, top, top); 195 P(pixel, right, right); 196 P(pixel, bottom, bottom); 197 P(percent, left, rleft); 198 P(percent, top, rtop); 199 P(percent, right, rright); 200 P(percent, bottom, rbottom); 201 #undef P 202 } 203 catch (PSERROR_Scripting_ConversionFailed&) 204 { 205 debug_warn(L"Error creating size object!"); 206 break; 207 } 184 { 185 CClientArea area; 186 GUI<CClientArea>::GetSetting(e, propName, area); 208 187 209 break; 188 JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUISize")); 189 vp.setObject(*obj); 190 try 191 { 192 #define P(x, y, z) pScriptInterface->SetProperty(vp, #z, area.x.y, false, true) 193 P(pixel, left, left); 194 P(pixel, top, top); 195 P(pixel, right, right); 196 P(pixel, bottom, bottom); 197 P(percent, left, rleft); 198 P(percent, top, rtop); 199 P(percent, right, rright); 200 P(percent, bottom, rbottom); 201 #undef P 210 202 } 211 212 case GUIST_CGUIString: 203 catch (PSERROR_Scripting_ConversionFailed&) 213 204 { 214 CGUIString value; 215 GUI<CGUIString>::GetSetting(e, propName, value); 216 ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString()); 205 debug_warn(L"Error creating size object!"); 217 206 break; 218 207 } 219 208 209 break; 210 } 211 212 case GUIST_CGUIString: 213 { 214 CGUIString value; 215 GUI<CGUIString>::GetSetting(e, propName, value); 216 ScriptInterface::ToJSVal(cx, vp, value.GetOriginalString()); 217 break; 218 } 219 220 220 case GUIST_CStr: 221 222 223 224 225 226 221 { 222 CStr value; 223 GUI<CStr>::GetSetting(e, propName, value); 224 ScriptInterface::ToJSVal(cx, vp, value); 225 break; 226 } 227 227 228 228 case GUIST_CStrW: 229 230 231 232 233 234 229 { 230 CStrW value; 231 GUI<CStrW>::GetSetting(e, propName, value); 232 ScriptInterface::ToJSVal(cx, vp, value); 233 break; 234 } 235 235 236 236 case GUIST_CGUISpriteInstance: 237 238 239 240 241 242 237 { 238 CGUISpriteInstance *value; 239 GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value); 240 ScriptInterface::ToJSVal(cx, vp, value->GetName()); 241 break; 242 } 243 243 244 244 case GUIST_EAlign: 245 { 246 EAlign value; 247 GUI<EAlign>::GetSetting(e, propName, value); 248 CStr word; 249 switch (value) 245 250 { 246 EAlign value; 247 GUI<EAlign>::GetSetting(e, propName, value); 248 CStr word; 249 switch (value) 250 { 251 case EAlign_Left: word = "left"; break; 252 case EAlign_Right: word = "right"; break; 253 case EAlign_Center: word = "center"; break; 254 default: debug_warn(L"Invalid EAlign!"); word = "error"; break; 255 } 256 ScriptInterface::ToJSVal(cx, vp, word); 257 break; 251 case EAlign_Left: word = "left"; break; 252 case EAlign_Right: word = "right"; break; 253 case EAlign_Center: word = "center"; break; 254 default: debug_warn(L"Invalid EAlign!"); word = "error"; break; 258 255 } 256 ScriptInterface::ToJSVal(cx, vp, word); 257 break; 258 } 259 259 260 260 case GUIST_EVAlign: 261 { 262 EVAlign value; 263 GUI<EVAlign>::GetSetting(e, propName, value); 264 CStr word; 265 switch (value) 261 266 { 262 EVAlign value; 263 GUI<EVAlign>::GetSetting(e, propName, value); 264 CStr word; 265 switch (value) 266 { 267 case EVAlign_Top: word = "top"; break; 268 case EVAlign_Bottom: word = "bottom"; break; 269 case EVAlign_Center: word = "center"; break; 270 default: debug_warn(L"Invalid EVAlign!"); word = "error"; break; 271 } 272 ScriptInterface::ToJSVal(cx, vp, word); 273 break; 267 case EVAlign_Top: word = "top"; break; 268 case EVAlign_Bottom: word = "bottom"; break; 269 case EVAlign_Center: word = "center"; break; 270 default: debug_warn(L"Invalid EVAlign!"); word = "error"; break; 274 271 } 272 ScriptInterface::ToJSVal(cx, vp, word); 273 break; 274 } 275 275 276 276 case GUIST_CGUIList: 277 { 278 CGUIList value; 279 GUI<CGUIList>::GetSetting(e, propName, value); 280 281 JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty())); 282 vp.setObject(*obj); 277 { 278 CGUIList value; 279 GUI<CGUIList>::GetSetting(e, propName, value); 283 280 284 for (u32 i = 0; i < value.m_Items.size(); ++i) 285 { 286 JS::RootedValue val(cx); 287 ScriptInterface::ToJSVal(cx, &val, value.m_Items[i].GetOriginalString()); 288 JS_SetElement(cx, obj, i, val); 289 } 281 JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty())); 282 vp.setObject(*obj); 290 283 291 break; 284 for (u32 i = 0; i < value.m_Items.size(); ++i) 285 { 286 JS::RootedValue val(cx); 287 ScriptInterface::ToJSVal(cx, &val, value.m_Items[i].GetOriginalString()); 288 JS_SetElement(cx, obj, i, val); 292 289 } 293 290 291 break; 292 } 293 294 294 default: 295 295 JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str()); 296 296 DEBUG_WARN_ERR(ERR::LOGIC); … … 338 338 return false; 339 339 } 340 340 341 CStr eventName 341 CStr eventName(CStr(propName.substr(2)).LowerCase()); 342 342 e->SetScriptHandler(eventName, vpObj); 343 343 344 344 return true; … … 354 354 355 355 switch (Type) 356 356 { 357 358 357 case GUIST_CStr: 359 360 361 362 358 { 359 std::string value; 360 if (!ScriptInterface::FromJSVal(cx, vp, value)) 361 return false; 363 362 364 365 366 363 GUI<CStr>::SetSetting(e, propName, value); 364 break; 365 } 367 366 368 367 case GUIST_CStrW: 369 370 371 372 368 { 369 std::wstring value; 370 if (!ScriptInterface::FromJSVal(cx, vp, value)) 371 return false; 373 372 374 375 376 373 GUI<CStrW>::SetSetting(e, propName, value); 374 break; 375 } 377 376 378 377 case GUIST_CGUISpriteInstance: 379 380 381 382 378 { 379 std::string value; 380 if (!ScriptInterface::FromJSVal(cx, vp, value)) 381 return false; 383 382 384 385 386 383 GUI<CGUISpriteInstance>::SetSetting(e, propName, CGUISpriteInstance(value)); 384 break; 385 } 387 386 388 387 case GUIST_CGUIString: 389 390 391 392 388 { 389 std::wstring value; 390 if (!ScriptInterface::FromJSVal(cx, vp, value)) 391 return false; 393 392 394 395 396 397 398 393 CGUIString str; 394 str.SetValue(value); 395 GUI<CGUIString>::SetSetting(e, propName, str); 396 break; 397 } 399 398 400 399 case GUIST_EAlign: 401 402 403 404 400 { 401 std::string value; 402 if (!ScriptInterface::FromJSVal(cx, vp, value)) 403 return false; 405 404 406 EAlign a; 407 if (value == "left") a = EAlign_Left; 408 else if (value == "right") a = EAlign_Right; 409 else if (value == "center" || value == "centre") a = EAlign_Center; 410 else 411 { 412 JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); 413 return false; 414 } 415 GUI<EAlign>::SetSetting(e, propName, a); 416 break; 405 EAlign a; 406 if (value == "left") a = EAlign_Left; 407 else if (value == "right") a = EAlign_Right; 408 else if (value == "center" || value == "centre") a = EAlign_Center; 409 else 410 { 411 JS_ReportError(cx, "Invalid alignment (should be 'left', 'right' or 'center')"); 412 return false; 417 413 } 414 GUI<EAlign>::SetSetting(e, propName, a); 415 break; 416 } 418 417 419 418 case GUIST_EVAlign: 420 421 422 423 419 { 420 std::string value; 421 if (!ScriptInterface::FromJSVal(cx, vp, value)) 422 return false; 424 423 425 EVAlign a; 426 if (value == "top") a = EVAlign_Top; 427 else if (value == "bottom") a = EVAlign_Bottom; 428 else if (value == "center" || value == "centre") a = EVAlign_Center; 429 else 430 { 431 JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')"); 432 return false; 433 } 434 GUI<EVAlign>::SetSetting(e, propName, a); 435 break; 424 EVAlign a; 425 if (value == "top") a = EVAlign_Top; 426 else if (value == "bottom") a = EVAlign_Bottom; 427 else if (value == "center" || value == "centre") a = EVAlign_Center; 428 else 429 { 430 JS_ReportError(cx, "Invalid alignment (should be 'top', 'bottom' or 'center')"); 431 return false; 436 432 } 433 GUI<EVAlign>::SetSetting(e, propName, a); 434 break; 435 } 437 436 438 437 case GUIST_int: 438 { 439 int value; 440 if (ScriptInterface::FromJSVal(cx, vp, value)) 441 GUI<int>::SetSetting(e, propName, value); 442 else 439 443 { 440 int value; 441 if (ScriptInterface::FromJSVal(cx, vp, value)) 442 GUI<int>::SetSetting(e, propName, value); 443 else 444 { 445 JS_ReportError(cx, "Cannot convert value to int"); 446 return false; 447 } 448 break; 444 JS_ReportError(cx, "Cannot convert value to int"); 445 return false; 449 446 } 447 break; 448 } 450 449 451 450 case GUIST_float: 451 { 452 double value; 453 if (JS::ToNumber(cx, vp, &value) == true) 454 GUI<float>::SetSetting(e, propName, (float)value); 455 else 452 456 { 453 double value; 454 if (JS::ToNumber(cx, vp, &value) == true) 455 GUI<float>::SetSetting(e, propName, (float)value); 456 else 457 { 458 JS_ReportError(cx, "Cannot convert value to float"); 459 return false; 460 } 461 break; 457 JS_ReportError(cx, "Cannot convert value to float"); 458 return false; 462 459 } 460 break; 461 } 463 462 464 463 case GUIST_bool: 465 466 467 468 469 464 { 465 bool value = JS::ToBoolean(vp); 466 GUI<bool>::SetSetting(e, propName, value); 467 break; 468 } 470 469 471 470 case GUIST_CClientArea: 471 { 472 if (vp.isString()) 472 473 { 473 if (vp.isString()) 474 { 475 std::wstring value; 476 if (!ScriptInterface::FromJSVal(cx, vp, value)) 477 return false; 478 479 if (e->SetSetting(propName, value) != PSRETURN_OK) 480 { 481 JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); 482 return false; 483 } 484 } 485 else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL)) 486 { 487 CClientArea area; 488 GUI<CClientArea>::GetSetting(e, propName, area); 489 490 ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; 491 #define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y) 492 P(pixel, left, left); 493 P(pixel, top, top); 494 P(pixel, right, right); 495 P(pixel, bottom, bottom); 496 P(percent, left, rleft); 497 P(percent, top, rtop); 498 P(percent, right, rright); 499 P(percent, bottom, rbottom); 500 #undef P 501 502 GUI<CClientArea>::SetSetting(e, propName, area); 503 } 504 else 474 std::wstring value; 475 if (!ScriptInterface::FromJSVal(cx, vp, value)) 476 return false; 477 478 if (e->SetSetting(propName, value) != PSRETURN_OK) 505 479 { 506 JS_ReportError(cx, " Size only accepts strings or GUISize objects");480 JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); 507 481 return false; 508 482 } 509 break;510 483 } 484 else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUISize::JSI_class, NULL)) 485 { 486 CClientArea area; 487 GUI<CClientArea>::GetSetting(e, propName, area); 488 489 ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; 490 #define P(x, y, z) pScriptInterface->GetProperty(vp, #z, area.x.y) 491 P(pixel, left, left); 492 P(pixel, top, top); 493 P(pixel, right, right); 494 P(pixel, bottom, bottom); 495 P(percent, left, rleft); 496 P(percent, top, rtop); 497 P(percent, right, rright); 498 P(percent, bottom, rbottom); 499 #undef P 500 501 GUI<CClientArea>::SetSetting(e, propName, area); 502 } 503 else 504 { 505 JS_ReportError(cx, "Size only accepts strings or GUISize objects"); 506 return false; 507 } 508 break; 509 } 511 510 512 511 case GUIST_CColor: 512 { 513 if (vp.isString()) 513 514 { 514 if (vp.isString()) 515 { 516 std::wstring value; 517 if (!ScriptInterface::FromJSVal(cx, vp, value)) 518 return false; 519 520 if (e->SetSetting(propName, value) != PSRETURN_OK) 521 { 522 JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); 523 return false; 524 } 525 } 526 else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL)) 527 { 528 CColor color; 529 JS::RootedValue t(cx); 530 double s; 531 #define PROP(x) JS_GetProperty(cx, vpObj, #x, &t); \ 532 s = t.toDouble(); \ 533 color.x = (float)s 534 PROP(r); PROP(g); PROP(b); PROP(a); 535 #undef PROP 536 537 GUI<CColor>::SetSetting(e, propName, color); 538 } 539 else 515 std::wstring value; 516 if (!ScriptInterface::FromJSVal(cx, vp, value)) 517 return false; 518 519 if (e->SetSetting(propName, value) != PSRETURN_OK) 540 520 { 541 JS_ReportError(cx, " Color only accepts strings or GUIColor objects");521 JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str()); 542 522 return false; 543 523 } 544 break;545 524 } 525 else if (vp.isObject() && JS_InstanceOf(cx, vpObj, &JSI_GUIColor::JSI_class, NULL)) 526 { 527 CColor color; 528 JS::RootedValue t(cx); 529 double s; 530 #define PROP(x) \ 531 JS_GetProperty(cx, vpObj, #x, &t); \ 532 s = t.toDouble(); \ 533 color.x = (float)s 534 PROP(r); 535 PROP(g); 536 PROP(b); 537 PROP(a); 538 #undef PROP 539 GUI<CColor>::SetSetting(e, propName, color); 540 } 541 else 542 { 543 JS_ReportError(cx, "Color only accepts strings or GUIColor objects"); 544 return false; 545 } 546 break; 547 } 546 548 547 549 case GUIST_CGUIList: 550 { 551 u32 length; 552 if (!vp.isObject() || !JS_GetArrayLength(cx, vpObj, &length)) 548 553 { 549 u32 length; 550 if (!vp.isObject() || !JS_GetArrayLength(cx, vpObj, &length)) 551 { 552 JS_ReportError(cx, "List only accepts a GUIList object"); 553 return false; 554 } 554 JS_ReportError(cx, "List only accepts a GUIList object"); 555 return false; 556 } 555 557 556 558 CGUIList list; 557 559 558 for (u32 i=0; i<length; ++i) 560 for (u32 i = 0; i < length; ++i) 561 { 562 JS::RootedValue element(cx); 563 if (!JS_GetElement(cx, vpObj, i, &element)) 559 564 { 560 JS::RootedValue element(cx); 561 if (!JS_GetElement(cx, vpObj, i, &element)) 562 { 563 JS_ReportError(cx, "Failed to get list element"); 564 return false; 565 } 566 567 std::wstring value; 568 if (!ScriptInterface::FromJSVal(cx, element, value)) 569 return false; 565 JS_ReportError(cx, "Failed to get list element"); 566 return false; 567 } 570 568 571 CGUIString str; 572 str.SetValue(value); 569 std::wstring value; 570 if (!ScriptInterface::FromJSVal(cx, element, value)) 571 return false; 573 572 574 list.m_Items.push_back(str);575 }573 CGUIString str; 574 str.SetValue(value); 576 575 577 GUI<CGUIList>::SetSetting(e, propName, list); 578 break; 576 list.m_Items.push_back(str); 579 577 } 580 578 581 // TODO Gee: (2004-09-01) EAlign and EVAlign too. 579 GUI<CGUIList>::SetSetting(e, propName, list); 580 break; 581 } 582 582 583 583 default: 584 584 JS_ReportError(cx, "Setting '%s' uses an unimplemented type", propName.c_str()); … … 616 616 scriptInterface.DefineCustomObjectType(&JSI_class, construct, 1, JSI_props, JSI_methods, NULL, NULL); 617 617 } 618 618 619 bool JSI_IGUIObject::toString(JSContext* cx, uint argc, jsval* vp)619 bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), jsval* vp) 620 620 { 621 UNUSED2(argc);622 621 JSAutoRequest rq(cx); 623 622 JS::CallReceiver rec = JS::CallReceiverFromVp(vp); 624 623 … … 635 634 return true; 636 635 } 637 636 638 bool JSI_IGUIObject::focus(JSContext* cx, uint argc, jsval* vp)637 bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), jsval* vp) 639 638 { 640 UNUSED2(argc);641 639 JSAutoRequest rq(cx); 642 640 JS::CallReceiver rec = JS::CallReceiverFromVp(vp); 643 641 … … 653 651 return true; 654 652 } 655 653 656 bool JSI_IGUIObject::blur(JSContext* cx, uint argc, jsval* vp)654 bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), jsval* vp) 657 655 { 658 UNUSED2(argc);659 656 JSAutoRequest rq(cx); 660 657 JS::CallReceiver rec = JS::CallReceiverFromVp(vp); 661 658 … … 671 668 return true; 672 669 } 673 670 674 bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, jsval* vp)671 bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), jsval* vp) 675 672 { 676 UNUSED2(argc);677 673 JSAutoRequest rq(cx); 678 674 JS::CallReceiver rec = JS::CallReceiverFromVp(vp); 679 675 -
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 }