-
diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp
index 0a6faed..76b5fb0 100644
a
|
b
|
void CButton::HandleMessage(SGUIMessage& Message)
|
83 | 83 | IGUITextOwner::HandleMessage(Message); |
84 | 84 | } |
85 | 85 | |
86 | | void CButton::Draw() |
| 86 | void CButton::Draw() |
87 | 87 | { |
88 | 88 | float bz = GetBufferedZ(); |
89 | 89 | |
-
diff --git a/source/gui/CButton.h b/source/gui/CButton.h
index f869019..3d66d95 100644
a
|
b
|
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Button |
25 | | * |
| 25 | * |
26 | 26 | * @see IGUIObject |
27 | 27 | * @see IGUIButtonBehavior |
28 | 28 | */ |
-
diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp
index 5921fa3..095f1f8 100644
a
|
b
|
void CCheckBox::HandleMessage(SGUIMessage& Message)
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | | void CCheckBox::Draw() |
| 110 | void CCheckBox::Draw() |
111 | 111 | { |
112 | 112 | float bz = GetBufferedZ(); |
113 | 113 | bool checked; |
… |
… |
void CCheckBox::Draw()
|
135 | 135 | GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite_disabled", sprite_disabled); |
136 | 136 | } |
137 | 137 | |
138 | | DrawButton(m_CachedActualSize, |
| 138 | DrawButton(m_CachedActualSize, |
139 | 139 | bz, |
140 | 140 | *sprite, |
141 | 141 | *sprite_over, |
-
diff --git a/source/gui/CCheckBox.h b/source/gui/CCheckBox.h
index b3a0f09..f924e75 100644
a
|
b
|
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * CheckBox |
25 | | * |
| 25 | * |
26 | 26 | * @see IGUIObject |
27 | 27 | * @see IGUISettingsObject |
28 | 28 | * @see IGUIButtonBehavior |
-
diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp
index c2b0e14..2d436d7 100644
a
|
b
|
CDropDown::CDropDown()
|
44 | 44 | AddSetting(GUIST_CGUISpriteInstance, "sprite2_pressed"); |
45 | 45 | AddSetting(GUIST_CGUISpriteInstance, "sprite2_disabled"); |
46 | 46 | AddSetting(GUIST_EVAlign, "text_valign"); |
47 | | |
| 47 | |
48 | 48 | // Add these in CList! And implement TODO |
49 | 49 | //AddSetting(GUIST_CColor, "textcolor_over"); |
50 | 50 | //AddSetting(GUIST_CColor, "textcolor_pressed"); |
… |
… |
void CDropDown::HandleMessage(SGUIMessage& Message)
|
82 | 82 | Message.value == "button_width") |
83 | 83 | { |
84 | 84 | SetupListRect(); |
85 | | } |
| 85 | } |
86 | 86 | |
87 | 87 | break; |
88 | 88 | } |
… |
… |
void CDropDown::HandleMessage(SGUIMessage& Message)
|
119 | 119 | set = i; |
120 | 120 | } |
121 | 121 | } |
122 | | |
| 122 | |
123 | 123 | if (set != -1) |
124 | 124 | { |
125 | 125 | //GUI<int>::SetSetting(this, "selected", set); |
… |
… |
InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev)
|
293 | 293 | if (ev->ev.type == SDL_KEYDOWN) |
294 | 294 | { |
295 | 295 | int szChar = ev->ev.key.keysym.sym; |
296 | | |
| 296 | |
297 | 297 | switch (szChar) |
298 | 298 | { |
299 | 299 | case '\r': |
… |
… |
InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev)
|
332 | 332 | m_InputBuffer = szChar; |
333 | 333 | else |
334 | 334 | m_InputBuffer += szChar; |
335 | | |
| 335 | |
336 | 336 | m_TimeOfLastInput = timer_Time(); |
337 | | |
| 337 | |
338 | 338 | CGUIList* pList; |
339 | 339 | GUI<CGUIList>::GetSettingPointer(this, "list", pList); |
340 | 340 | // let's look for the closest element |
… |
… |
bool CDropDown::MouseOver()
|
429 | 429 | return m_CachedActualSize.PointInside(GetMousePos()); |
430 | 430 | } |
431 | 431 | |
432 | | void CDropDown::Draw() |
| 432 | void CDropDown::Draw() |
433 | 433 | { |
434 | 434 | if (!GetGUI()) |
435 | 435 | return; |
… |
… |
void CDropDown::Draw()
|
468 | 468 | GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_disabled", sprite2_second); |
469 | 469 | GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect); |
470 | 470 | } |
471 | | else |
472 | | if (m_Open) |
| 471 | else if (m_Open) |
473 | 472 | { |
474 | 473 | GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_pressed", sprite2_second); |
475 | 474 | GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect); |
476 | 475 | } |
477 | | else |
478 | | if (m_MouseHovering) |
| 476 | else if (m_MouseHovering) |
479 | 477 | { |
480 | 478 | GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_over", sprite2_second); |
481 | 479 | GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect); |
482 | 480 | } |
483 | | else |
| 481 | else |
484 | 482 | GetGUI()->DrawSprite(*sprite2, cell_id, bz+0.05f, rect); |
485 | 483 | } |
486 | 484 | |
… |
… |
void CDropDown::Draw()
|
506 | 504 | *scrollbar = false; |
507 | 505 | |
508 | 506 | DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor"); |
509 | | |
| 507 | |
510 | 508 | if (m_HideScrollBar) |
511 | 509 | *scrollbar = old; |
512 | 510 | } |
-
diff --git a/source/gui/CDropDown.h b/source/gui/CDropDown.h
index 8d2c604..86e680a 100644
a
|
b
|
protected:
|
83 | 83 | * made that can change the visual. |
84 | 84 | */ |
85 | 85 | void SetupText(); |
86 | | |
| 86 | |
87 | 87 | // Sets up the cached GetListRect. Decided whether it should |
88 | 88 | // have a scrollbar, and so on. |
89 | 89 | virtual void SetupListRect(); |
… |
… |
protected:
|
111 | 111 | // it is set to "selected", but then when moving the mouse it will |
112 | 112 | // change. |
113 | 113 | int m_ElementHighlight; |
114 | | |
| 114 | |
115 | 115 | // Stores any text entered by the user for quick access to an element |
116 | 116 | // (ie if you type "acro" it will take you to acropolis). |
117 | 117 | std::string m_InputBuffer; |
118 | | |
| 118 | |
119 | 119 | // used to know if we want to restart anew or add to m_inputbuffer. |
120 | 120 | double m_TimeOfLastInput; |
121 | 121 | |
-
diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp
index 169d388..f16c96d 100644
a
|
b
|
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
82 | 82 | m_MousePos = CPos((float)ev->ev.motion.x * g_GuiScale, (float)ev->ev.motion.y * g_GuiScale); |
83 | 83 | |
84 | 84 | SGUIMessage msg(GUIM_MOUSE_MOTION); |
85 | | GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, |
86 | | &IGUIObject::HandleMessage, |
| 85 | GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, |
| 86 | &IGUIObject::HandleMessage, |
87 | 87 | msg); |
88 | 88 | } |
89 | 89 | |
… |
… |
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
125 | 125 | // Now we'll call UpdateMouseOver on *all* objects, |
126 | 126 | // we'll input the one hovered, and they will each |
127 | 127 | // update their own data and send messages accordingly |
128 | | GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, |
129 | | &IGUIObject::UpdateMouseOver, |
| 128 | GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, |
| 129 | &IGUIObject::UpdateMouseOver, |
130 | 130 | pNearest); |
131 | 131 | |
132 | 132 | if (ev->ev.type == SDL_MOUSEBUTTONDOWN) |
… |
… |
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
185 | 185 | { |
186 | 186 | double timeElapsed = timer_Time() - pNearest->m_LastClickTime[SDL_BUTTON_LEFT]; |
187 | 187 | pNearest->m_LastClickTime[SDL_BUTTON_LEFT] = timer_Time(); |
188 | | |
| 188 | |
189 | 189 | //Double click? |
190 | 190 | if (timeElapsed < SELECT_DBLCLICK_RATE) |
191 | 191 | { |
… |
… |
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
202 | 202 | { |
203 | 203 | double timeElapsed = timer_Time() - pNearest->m_LastClickTime[SDL_BUTTON_RIGHT]; |
204 | 204 | pNearest->m_LastClickTime[SDL_BUTTON_RIGHT] = timer_Time(); |
205 | | |
| 205 | |
206 | 206 | //Double click? |
207 | 207 | if (timeElapsed < SELECT_DBLCLICK_RATE) |
208 | 208 | { |
… |
… |
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // Reset all states on all visible objects |
220 | | GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, |
| 220 | GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject, |
221 | 221 | &IGUIObject::ResetStates); |
222 | 222 | |
223 | 223 | // Since the hover state will have been reset, we reload it. |
224 | | GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, |
225 | | &IGUIObject::UpdateMouseOver, |
| 224 | GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, |
| 225 | &IGUIObject::UpdateMouseOver, |
226 | 226 | pNearest); |
227 | 227 | } |
228 | 228 | } |
… |
… |
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
263 | 263 | (ev->ev.type == SDL_KEYDOWN && |
264 | 264 | ev->ev.key.keysym.sym != SDLK_ESCAPE && |
265 | 265 | !g_keys[SDLK_LCTRL] && !g_keys[SDLK_RCTRL] && |
266 | | !g_keys[SDLK_LALT] && !g_keys[SDLK_RALT]) |
| 266 | !g_keys[SDLK_LALT] && !g_keys[SDLK_RALT]) |
267 | 267 | || ev->ev.type == SDL_HOTKEYDOWN |
268 | 268 | #if SDL_VERSION_ATLEAST(2, 0, 0) |
269 | 269 | || ev->ev.type == SDL_TEXTINPUT || ev->ev.type == SDL_TEXTEDITING |
… |
… |
InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
281 | 281 | void CGUI::TickObjects() |
282 | 282 | { |
283 | 283 | CStr action = "tick"; |
284 | | GUI<CStr>::RecurseObject(0, m_BaseObject, |
| 284 | GUI<CStr>::RecurseObject(0, m_BaseObject, |
285 | 285 | &IGUIObject::ScriptEvent, action); |
286 | 286 | |
287 | 287 | // Also update tooltips: |
… |
… |
void CGUI::SendEventToAll(const CStr& EventName)
|
297 | 297 | // (sending events here) wasn't converting to lower case, |
298 | 298 | // leading to a similar problem. |
299 | 299 | // now fixed; case is irrelevant since all are converted to lower. |
300 | | GUI<CStr>::RecurseObject(0, m_BaseObject, |
| 300 | GUI<CStr>::RecurseObject(0, m_BaseObject, |
301 | 301 | &IGUIObject::ScriptEvent, EventName.LowerCase()); |
302 | 302 | } |
303 | 303 | |
… |
… |
CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
|
308 | 308 | GuiScriptingInit(*m_ScriptInterface); |
309 | 309 | m_ScriptInterface->LoadGlobalScripts(); |
310 | 310 | m_BaseObject = new CGUIDummyObject; |
311 | | m_BaseObject->SetGUI(this); |
| 311 | m_BaseObject->SetGUI(this); |
312 | 312 | } |
313 | 313 | |
314 | 314 | CGUI::~CGUI() |
… |
… |
struct SGenerateTextImage
|
508 | 508 | |
509 | 509 | // Some help functions |
510 | 510 | // TODO Gee: CRect => CPoint ? |
511 | | void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall, |
| 511 | void SetupSpriteCall(const bool Left, SGUIText::SSpriteCall& SpriteCall, |
512 | 512 | const float width, const float y, |
513 | | const CSize& Size, const CStr& TextureName, |
| 513 | const CSize& Size, const CStr& TextureName, |
514 | 514 | const float BufferZone, const int CellID) |
515 | 515 | { |
516 | 516 | // TODO Gee: Temp hardcoded values |
517 | 517 | SpriteCall.m_Area.top = y+BufferZone; |
518 | 518 | SpriteCall.m_Area.bottom = y+BufferZone + Size.cy; |
519 | | |
| 519 | |
520 | 520 | if (Left) |
521 | 521 | { |
522 | 522 | SpriteCall.m_Area.left = BufferZone; |
… |
… |
SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const
|
585 | 585 | FirstLine); |
586 | 586 | |
587 | 587 | // Loop through our images queues, to see if images has been added. |
588 | | |
| 588 | |
589 | 589 | // Check if this has already been processed. |
590 | 590 | // Also, floating images are only applicable if Word-Wrapping is on |
591 | 591 | if (WordWrapping && i > pos_last_img) |
… |
… |
SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const
|
604 | 604 | if (!Images[j].empty()) |
605 | 605 | _y = std::max(y, Images[j].back().m_YTo); |
606 | 606 | else |
607 | | _y = y; |
| 607 | _y = y; |
608 | 608 | |
609 | 609 | // Get Size from Icon database |
610 | 610 | SGUIIcon icon = GetIcon(imgname); |
… |
… |
SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const
|
660 | 660 | |
661 | 661 | union_from = std::max(y, img.m_YFrom); |
662 | 662 | union_to = std::min(y+prelim_line_height, img.m_YTo); |
663 | | |
| 663 | |
664 | 664 | // The union is not empty |
665 | 665 | if (union_to > union_from) |
666 | 666 | { |
… |
… |
SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const
|
748 | 748 | |
749 | 749 | // Defaults |
750 | 750 | string.GenerateTextCall(this, Feedback2, Font, |
751 | | string.m_Words[j], string.m_Words[j+1], |
| 751 | string.m_Words[j], string.m_Words[j+1], |
752 | 752 | FirstLine, pObject); |
753 | 753 | |
754 | 754 | // Iterate all and set X/Y values |
… |
… |
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
1310 | 1310 | if (!object->HandleAdditionalChildren(child, pFile)) |
1311 | 1311 | LOGERROR("GUI: (object: %s) Reading unknown children for its type", object->GetPresentableName().c_str()); |
1312 | 1312 | } |
1313 | | } |
| 1313 | } |
1314 | 1314 | |
1315 | 1315 | // |
1316 | 1316 | // Check if Z wasn't manually set |
… |
… |
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
|
1437 | 1437 | { |
1438 | 1438 | // Sprite object we're adding |
1439 | 1439 | CGUISprite* Sprite = new CGUISprite; |
1440 | | |
| 1440 | |
1441 | 1441 | // and what will be its reference name |
1442 | 1442 | CStr name; |
1443 | 1443 | |
… |
… |
void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
1504 | 1504 | |
1505 | 1505 | // Image object we're adding |
1506 | 1506 | SGUIImage* Image = new SGUIImage; |
1507 | | |
| 1507 | |
1508 | 1508 | // Set defaults to "0 0 100% 100%" |
1509 | 1509 | Image->m_TextureSize = CClientArea(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); |
1510 | 1510 | Image->m_Size = CClientArea(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); |
1511 | | |
| 1511 | |
1512 | 1512 | // TODO Gee: Setup defaults here (or maybe they are in the SGUIImage ctor) |
1513 | 1513 | |
1514 | 1514 | // |
… |
… |
void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
1726 | 1726 | for (XMBAttribute attr : Element.GetAttributes()) |
1727 | 1727 | { |
1728 | 1728 | CStr attr_name = pFile->GetAttributeString(attr.Name); |
1729 | | CStr attr_value(attr.Value); |
| 1729 | CStr attr_value(attr.Value); |
1730 | 1730 | |
1731 | 1731 | if (attr_value == "null") |
1732 | 1732 | continue; |
… |
… |
void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile)
|
1792 | 1792 | } |
1793 | 1793 | |
1794 | 1794 | // |
1795 | | // Add to CGUI |
| 1795 | // Add to CGUI |
1796 | 1796 | // |
1797 | 1797 | |
1798 | 1798 | m_ScrollBarStyles[name] = scrollbar; |
… |
… |
void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
|
1871 | 1871 | CColor color; |
1872 | 1872 | CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name")); |
1873 | 1873 | |
1874 | | // Try parsing value |
| 1874 | // Try parsing value |
1875 | 1875 | CStr value(Element.GetText()); |
1876 | 1876 | if (value.empty()) |
1877 | 1877 | return; |
-
diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h
index 87e6f2b..d6d421a 100644
a
|
b
|
ERROR_TYPE(GUI, JSOpenFailed);
|
49 | 49 | */ |
50 | 50 | struct SGUIStyle |
51 | 51 | { |
52 | | // A list of defaults for |
| 52 | // A list of defaults for |
53 | 53 | std::map<CStr, CStrW> m_SettingsDefaults; |
54 | 54 | }; |
55 | 55 | |
… |
… |
class GUITooltip;
|
74 | 74 | class CGUI |
75 | 75 | { |
76 | 76 | NONCOPYABLE(CGUI); |
77 | | |
| 77 | |
78 | 78 | friend class IGUIObject; |
79 | 79 | friend class IGUIScrollBarOwner; |
80 | 80 | friend class CInternalCGUIAccessorBase; |
… |
… |
public:
|
91 | 91 | * Initializes the GUI, needs to be called before the GUI is used |
92 | 92 | */ |
93 | 93 | void Initialize(); |
94 | | |
| 94 | |
95 | 95 | /** |
96 | 96 | * Performs processing that should happen every frame |
97 | 97 | * (including sending the "Tick" event to scripts) |
… |
… |
public:
|
185 | 185 | * The GUI needs to have all object types inputted and |
186 | 186 | * their constructors. Also it needs to associate a type |
187 | 187 | * by a string name of the type. |
188 | | * |
| 188 | * |
189 | 189 | * To add a type: |
190 | 190 | * @code |
191 | 191 | * AddObjectType("button", &CButton::ConstructObject); |
… |
… |
public:
|
216 | 216 | * will be sent to the Renderer. Also, horizontal alignment |
217 | 217 | * is taken into acount in this method but NOT vertical alignment. |
218 | 218 | * |
219 | | * Done through the CGUI since it can communicate with |
| 219 | * Done through the CGUI since it can communicate with |
220 | 220 | * |
221 | 221 | * @param Text Text to generate SGUIText object from |
222 | 222 | * @param Font Default font, notice both Default color and default font |
223 | 223 | * can be changed by tags. |
224 | 224 | * @param Width Width, 0 if no word-wrapping. |
225 | 225 | * @param BufferZone space between text and edge, and space between text and images. |
226 | | * @param pObject Optional parameter for error output. Used *only* if error parsing fails, |
227 | | * and we need to be able to output which object the error occured in to aid the user. |
| 226 | * @param pObject Optional parameter for error output. Used *only* if error parsing fails, |
| 227 | * and we need to be able to output which object the error occured in to aid the user. |
228 | 228 | */ |
229 | 229 | SGUIText GenerateText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone, const IGUIObject* pObject = NULL); |
230 | 230 | |
… |
… |
public:
|
244 | 244 | * Returns false if it fails. |
245 | 245 | */ |
246 | 246 | bool GetPreDefinedColor(const CStr& name, CColor& Output) const; |
247 | | |
| 247 | |
248 | 248 | shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; }; |
249 | 249 | jsval GetGlobalObject() { return m_ScriptInterface->GetGlobalObject(); }; |
250 | 250 | |
… |
… |
private:
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * Adds an object to the GUI's object database |
266 | | * Private, since you can only add objects through |
| 266 | * Private, since you can only add objects through |
267 | 267 | * XML files. Why? Because it enables the GUI to |
268 | 268 | * be much more encapsulated and safe. |
269 | 269 | * |
… |
… |
private:
|
512 | 512 | * @see LoadXmlFile() |
513 | 513 | */ |
514 | 514 | void Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile); |
515 | | |
| 515 | |
516 | 516 | /** |
517 | 517 | * Reads in the element \<tooltip\> (the XMBElement) and stores the |
518 | 518 | * result as an object with the name __tooltip_#. |
… |
… |
private:
|
547 | 547 | /** @name Miscellaneous */ |
548 | 548 | //-------------------------------------------------------- |
549 | 549 | //@{ |
550 | | |
| 550 | |
551 | 551 | shared_ptr<ScriptInterface> m_ScriptInterface; |
552 | 552 | |
553 | 553 | /** |
554 | | * don't want to pass this around with the |
| 554 | * don't want to pass this around with the |
555 | 555 | * ChooseMouseOverAndClosest broadcast - |
556 | 556 | * we'd need to pack this and pNearest in a struct |
557 | 557 | */ |
… |
… |
private:
|
593 | 593 | */ |
594 | 594 | IGUIObject* m_FocusedObject; |
595 | 595 | |
596 | | /** |
| 596 | /** |
597 | 597 | * Just pointers for fast name access, each object |
598 | 598 | * is really constructed within its parent for easy |
599 | 599 | * recursive management. |
-
diff --git a/source/gui/CGUIScrollBarVertical.cpp b/source/gui/CGUIScrollBarVertical.cpp
index 3eb770b..0a08a5e 100644
a
|
b
|
void CGUIScrollBarVertical::Draw()
|
61 | 61 | // Draw background |
62 | 62 | GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical, |
63 | 63 | 0, |
64 | | m_Z+0.1f, |
| 64 | m_Z+0.1f, |
65 | 65 | CRect(outline.left, |
66 | 66 | outline.top+(GetStyle()->m_UseEdgeButtons?GetStyle()->m_Width:0), |
67 | 67 | outline.right, |
… |
… |
void CGUIScrollBarVertical::Draw()
|
95 | 95 | } |
96 | 96 | else |
97 | 97 | button_bottom = &GetStyle()->m_SpriteButtonBottom; |
98 | | |
| 98 | |
99 | 99 | // Draw top button |
100 | 100 | GetGUI()->DrawSprite(*button_top, |
101 | 101 | 0, |
… |
… |
void CGUIScrollBarVertical::Draw()
|
105 | 105 | outline.right, |
106 | 106 | outline.top+GetStyle()->m_Width) |
107 | 107 | ); |
108 | | |
| 108 | |
109 | 109 | // Draw bottom button |
110 | 110 | GetGUI()->DrawSprite(*button_bottom, |
111 | 111 | 0, |
… |
… |
void CGUIScrollBarVertical::Draw()
|
123 | 123 | m_Z + 0.2f, |
124 | 124 | GetBarRect()); |
125 | 125 | } |
126 | | } |
| 126 | } |
127 | 127 | |
128 | 128 | void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message) |
129 | 129 | { |
-
diff --git a/source/gui/CGUISprite.cpp b/source/gui/CGUISprite.cpp
index ce7394c..8153d30 100644
a
|
b
|
|
1 | | /* Copyright (C) 2015 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 |
-
diff --git a/source/gui/CGUISprite.h b/source/gui/CGUISprite.h
index 181c134..2989f29 100644
a
|
b
|
public:
|
61 | 61 | m_Effects(NULL), m_Border(false), m_DeltaZ(0.f) |
62 | 62 | { |
63 | 63 | } |
64 | | |
| 64 | |
65 | 65 | ~SGUIImage() |
66 | 66 | { |
67 | 67 | delete m_Effects; |
-
diff --git a/source/gui/CImage.cpp b/source/gui/CImage.cpp
index 18c329d..1c2ae63 100644
a
|
b
|
CImage::~CImage()
|
35 | 35 | { |
36 | 36 | } |
37 | 37 | |
38 | | void CImage::Draw() |
| 38 | void CImage::Draw() |
39 | 39 | { |
40 | 40 | if (!GetGUI()) |
41 | 41 | return; |
-
diff --git a/source/gui/CImage.h b/source/gui/CImage.h
index fa46371..5427149 100644
a
|
b
|
|
29 | 29 | * without functionality used, and that is a lot of unnecessary |
30 | 30 | * overhead. That's why I thought I'd go with an intuitive |
31 | 31 | * control. |
32 | | * |
| 32 | * |
33 | 33 | * @see IGUIObject |
34 | 34 | */ |
35 | 35 | class CImage : public IGUIObject |
-
diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp
index d05d849..cb788d9 100644
a
|
b
|
InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
226 | 226 | if (m_iBufferPos == (int)pCaption->length()) |
227 | 227 | *pCaption = pCaption->Left((long)pCaption->length()-1); |
228 | 228 | else |
229 | | *pCaption = pCaption->Left(m_iBufferPos-1) + |
| 229 | *pCaption = pCaption->Left(m_iBufferPos-1) + |
230 | 230 | pCaption->Right((long)pCaption->length()-m_iBufferPos); |
231 | 231 | |
232 | 232 | --m_iBufferPos; |
… |
… |
InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
248 | 248 | if (pCaption->empty() || m_iBufferPos == (int)pCaption->length()) |
249 | 249 | break; |
250 | 250 | |
251 | | *pCaption = pCaption->Left(m_iBufferPos) + |
| 251 | *pCaption = pCaption->Left(m_iBufferPos) + |
252 | 252 | pCaption->Right((long)pCaption->length()-(m_iBufferPos+1)); |
253 | 253 | |
254 | 254 | UpdateText(m_iBufferPos, m_iBufferPos+1, m_iBufferPos); |
… |
… |
InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev)
|
326 | 326 | else if (!SelectingText()) |
327 | 327 | m_iBufferPos_Tail = m_iBufferPos; |
328 | 328 | |
329 | | if (m_iBufferPos > 0) |
| 329 | if (m_iBufferPos > 0) |
330 | 330 | --m_iBufferPos; |
331 | 331 | } |
332 | 332 | else |
… |
… |
InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
|
556 | 556 | if (m_iBufferPos == (int)pCaption->length()) |
557 | 557 | *pCaption += text; |
558 | 558 | else |
559 | | *pCaption = pCaption->Left(m_iBufferPos) + text + |
| 559 | *pCaption = pCaption->Left(m_iBufferPos) + text + |
560 | 560 | pCaption->Right((long) pCaption->length()-m_iBufferPos); |
561 | 561 | |
562 | 562 | UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); |
… |
… |
InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev)
|
642 | 642 | DeleteCurSelection(); |
643 | 643 | } |
644 | 644 | return IN_HANDLED; |
645 | | } |
| 645 | } |
646 | 646 | else if (hotkey == "text.delete.right") |
647 | 647 | { |
648 | 648 | m_WantedX = 0.0f; |
… |
… |
void CInput::HandleMessage(SGUIMessage& Message)
|
802 | 802 | |
803 | 803 | // Update scroll-bar |
804 | 804 | // TODO Gee: (2004-09-01) Is this really updated each time it should? |
805 | | if (scrollbar && |
806 | | (Message.value == CStr("size") || |
| 805 | if (scrollbar && |
| 806 | (Message.value == CStr("size") || |
807 | 807 | Message.value == CStr("z") || |
808 | 808 | Message.value == CStr("absolute"))) |
809 | 809 | { |
… |
… |
void CInput::HandleMessage(SGUIMessage& Message)
|
828 | 828 | m_iBufferPos_Tail = -1; // position change resets selection |
829 | 829 | } |
830 | 830 | |
831 | | if (Message.value == CStr("size") || |
| 831 | if (Message.value == CStr("size") || |
832 | 832 | Message.value == CStr("z") || |
833 | | Message.value == CStr("font") || |
| 833 | Message.value == CStr("font") || |
834 | 834 | Message.value == CStr("absolute") || |
835 | 835 | Message.value == CStr("caption") || |
836 | 836 | Message.value == CStr("scrollbar") || |
… |
… |
void CInput::Draw()
|
1225 | 1225 | // Set the Z to somewhat more, so we can draw a selected area between the |
1226 | 1226 | // the control and the text. |
1227 | 1227 | textRenderer.Translate( |
1228 | | (float)(int)(m_CachedActualSize.left) + buffer_zone, |
| 1228 | (float)(int)(m_CachedActualSize.left) + buffer_zone, |
1229 | 1229 | (float)(int)(m_CachedActualSize.top+h) + buffer_zone, |
1230 | 1230 | bz+0.1f); |
1231 | 1231 | |
… |
… |
void CInput::Draw()
|
1291 | 1291 | if (it->m_ListStart + i == VirtualFrom) |
1292 | 1292 | { |
1293 | 1293 | // we won't actually draw it now, because we don't |
1294 | | // know the width of each glyph to that position. |
| 1294 | // know the width of each glyph to that position. |
1295 | 1295 | // we need to go along with the iteration, and |
1296 | 1296 | // make a mark where the box started: |
1297 | 1297 | drawing_box = true; // will turn false when finally rendered. |
… |
… |
void CInput::Draw()
|
1327 | 1327 | // Set 'rect' depending on if it's a multiline control, or a one-line control |
1328 | 1328 | if (multiline) |
1329 | 1329 | { |
1330 | | rect = CRect(m_CachedActualSize.left+box_x+buffer_zone, |
| 1330 | rect = CRect(m_CachedActualSize.left+box_x+buffer_zone, |
1331 | 1331 | m_CachedActualSize.top+buffered_y+(h-ls)/2, |
1332 | | m_CachedActualSize.left+x_pointer+buffer_zone, |
| 1332 | m_CachedActualSize.left+x_pointer+buffer_zone, |
1333 | 1333 | m_CachedActualSize.top+buffered_y+(h+ls)/2); |
1334 | 1334 | |
1335 | 1335 | if (rect.bottom < m_CachedActualSize.top) |
… |
… |
void CInput::Draw()
|
1343 | 1343 | } |
1344 | 1344 | else // if one-line |
1345 | 1345 | { |
1346 | | rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll, |
| 1346 | rect = CRect(m_CachedActualSize.left+box_x+buffer_zone-m_HorizontalScroll, |
1347 | 1347 | m_CachedActualSize.top+buffered_y+(h-ls)/2, |
1348 | | m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll, |
| 1348 | m_CachedActualSize.left+x_pointer+buffer_zone-m_HorizontalScroll, |
1349 | 1349 | m_CachedActualSize.top+buffered_y+(h+ls)/2); |
1350 | 1350 | |
1351 | 1351 | if (rect.left < m_CachedActualSize.left) |
… |
… |
void CInput::Draw()
|
1426 | 1426 | } |
1427 | 1427 | |
1428 | 1428 | // End of selected area, change back color |
1429 | | if (SelectingText() && |
| 1429 | if (SelectingText() && |
1430 | 1430 | it->m_ListStart + i == VirtualTo) |
1431 | 1431 | { |
1432 | 1432 | using_selected_color = false; |
… |
… |
void CInput::Draw()
|
1440 | 1440 | textRenderer.Put(0.0f, 0.0f, L"_"); |
1441 | 1441 | |
1442 | 1442 | // Drawing selected area |
1443 | | if (SelectingText() && |
| 1443 | if (SelectingText() && |
1444 | 1444 | it->m_ListStart + i >= VirtualFrom && |
1445 | 1445 | it->m_ListStart + i < VirtualTo && |
1446 | 1446 | using_selected_color == false) |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1551 | 1551 | |
1552 | 1552 | std::list<SRow>::iterator destroy_row_from; |
1553 | 1553 | std::list<SRow>::iterator destroy_row_to; |
1554 | | // Used to check if the above has been set to anything, |
| 1554 | // Used to check if the above has been set to anything, |
1555 | 1555 | // previously a comparison like: |
1556 | 1556 | // destroy_row_from == std::list<SRow>::iterator() |
1557 | 1557 | // ... was used, but it didn't work with GCC. |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1563 | 1563 | // to be redone. And when going along, we'll delete a row at a time |
1564 | 1564 | // when continuing to see how much more after 'to' we need to remake. |
1565 | 1565 | int i = 0; |
1566 | | for (std::list<SRow>::iterator it = m_CharacterPositions.begin(); |
| 1566 | for (std::list<SRow>::iterator it = m_CharacterPositions.begin(); |
1567 | 1567 | it != m_CharacterPositions.end(); |
1568 | 1568 | ++it, ++i) |
1569 | 1569 | { |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1578 | 1578 | |
1579 | 1579 | // For the rare case that we might remove characters to a word |
1580 | 1580 | // so that it suddenly fits on the previous row, |
1581 | | // we need to by standards re-do the whole previous line too |
| 1581 | // we need to by standards re-do the whole previous line too |
1582 | 1582 | // (if one exists) |
1583 | 1583 | if (destroy_row_from != m_CharacterPositions.begin()) |
1584 | 1584 | --destroy_row_from; |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1592 | 1592 | destroy_row_to_used = true; |
1593 | 1593 | |
1594 | 1594 | // If it isn't the last row, we'll add another row to delete, |
1595 | | // just so we can see if the last restorted line is |
| 1595 | // just so we can see if the last restorted line is |
1596 | 1596 | // identical to what it was before. If it isn't, then we'll |
1597 | 1597 | // have to continue. |
1598 | 1598 | // 'check_point_row_start' is where we store how the that |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1746 | 1746 | // also check if the current line isn't the end |
1747 | 1747 | if (to_before != -1 && i == to-1 && current_line != m_CharacterPositions.end()) |
1748 | 1748 | { |
1749 | | // check all rows and see if any existing |
| 1749 | // check all rows and see if any existing |
1750 | 1750 | if (row.m_ListStart != check_point_row_start) |
1751 | 1751 | { |
1752 | 1752 | std::list<SRow>::iterator destroy_row_from; |
1753 | 1753 | std::list<SRow>::iterator destroy_row_to; |
1754 | | // Are used to check if the above has been set to anything, |
| 1754 | // Are used to check if the above has been set to anything, |
1755 | 1755 | // previously a comparison like: |
1756 | 1756 | // destroy_row_from == std::list<SRow>::iterator() |
1757 | 1757 | // was used, but it didn't work with GCC. |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1763 | 1763 | // to be redone. And when going along, we'll delete a row at a time |
1764 | 1764 | // when continuing to see how much more after 'to' we need to remake. |
1765 | 1765 | int i = 0; |
1766 | | for (std::list<SRow>::iterator it = m_CharacterPositions.begin(); |
| 1766 | for (std::list<SRow>::iterator it = m_CharacterPositions.begin(); |
1767 | 1767 | it != m_CharacterPositions.end(); |
1768 | 1768 | ++it, ++i) |
1769 | 1769 | { |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1787 | 1787 | destroy_row_to_used = true; |
1788 | 1788 | |
1789 | 1789 | // If it isn't the last row, we'll add another row to delete, |
1790 | | // just so we can see if the last restorted line is |
| 1790 | // just so we can see if the last restorted line is |
1791 | 1791 | // identical to what it was before. If it isn't, then we'll |
1792 | 1792 | // have to continue. |
1793 | 1793 | // 'check_point_row_start' is where we store how the that |
… |
… |
void CInput::UpdateText(int from, int to_before, int to_after)
|
1860 | 1860 | } |
1861 | 1861 | } |
1862 | 1862 | |
1863 | | int CInput::GetMouseHoveringTextPosition() |
| 1863 | int CInput::GetMouseHoveringTextPosition() const |
1864 | 1864 | { |
1865 | 1865 | if (m_CharacterPositions.empty()) |
1866 | 1866 | return 0; |
… |
… |
int CInput::GetMouseHoveringTextPosition()
|
1873 | 1873 | GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); |
1874 | 1874 | GUI<bool>::GetSetting(this, "multiline", multiline); |
1875 | 1875 | |
1876 | | std::list<SRow>::iterator current = m_CharacterPositions.begin(); |
| 1876 | std::list<SRow>::const_iterator current = m_CharacterPositions.begin(); |
1877 | 1877 | |
1878 | 1878 | CPos mouse = GetMousePos(); |
1879 | 1879 | |
… |
… |
int CInput::GetMouseHoveringTextPosition()
|
1887 | 1887 | |
1888 | 1888 | float scroll = 0.f; |
1889 | 1889 | if (scrollbar) |
1890 | | scroll = GetScrollBar(0).GetPos(); |
1891 | | |
1892 | | // Pointer to caption, will come in handy |
1893 | | CStrW* pCaption = (CStrW*)m_Settings["caption"].m_pSetting; |
1894 | | UNUSED2(pCaption); |
| 1890 | scroll = GetScrollBarPos(0); |
1895 | 1891 | |
1896 | 1892 | // Now get the height of the font. |
1897 | 1893 | // TODO: Get the real font |
1898 | 1894 | CFontMetrics font(font_name); |
1899 | 1895 | float spacing = (float)font.GetLineSpacing(); |
1900 | | //float height = (float)font.GetHeight(); // unused |
1901 | 1896 | |
1902 | 1897 | // Change mouse position relative to text. |
1903 | 1898 | mouse -= m_CachedActualSize.TopLeft(); |
1904 | 1899 | mouse.x -= buffer_zone; |
1905 | 1900 | mouse.y += scroll - buffer_zone; |
1906 | 1901 | |
1907 | | //if ((m_CharacterPositions.size()-1) * spacing + height < mouse.y) |
1908 | | // m_iBufferPos = pCaption->Length(); |
1909 | | int row = (int)((mouse.y) / spacing);//m_CharachterPositions.size() |
| 1902 | int row = (int)((mouse.y) / spacing); |
1910 | 1903 | |
1911 | 1904 | if (row < 0) |
1912 | 1905 | row = 0; |
… |
… |
int CInput::GetMouseHoveringTextPosition()
|
1929 | 1922 | // mouse.y is moot |
1930 | 1923 | } |
1931 | 1924 | |
1932 | | //m_iBufferPos = m_CharacterPositions.get.m_ListStart; |
1933 | 1925 | retPosition = current->m_ListStart; |
1934 | 1926 | |
1935 | 1927 | // Okay, now loop through the glyphs to find the appropriate X position |
… |
… |
int CInput::GetMouseHoveringTextPosition()
|
1940 | 1932 | } |
1941 | 1933 | |
1942 | 1934 | // Does not process horizontal scrolling, 'x' must be modified before inputted. |
1943 | | int CInput::GetXTextPosition(const std::list<SRow>::iterator& current, const float& x, float& wanted) |
| 1935 | int CInput::GetXTextPosition(const std::list<SRow>::const_iterator& current, const float& x, float& wanted) const |
1944 | 1936 | { |
1945 | 1937 | int ret = 0; |
1946 | 1938 | float previous = 0.f; |
1947 | 1939 | int i = 0; |
1948 | 1940 | |
1949 | | for (std::vector<float>::iterator it = current->m_ListOfX.begin(); |
| 1941 | for (std::vector<float>::const_iterator it = current->m_ListOfX.begin(); |
1950 | 1942 | it != current->m_ListOfX.end(); |
1951 | 1943 | ++it, ++i) |
1952 | 1944 | { |
… |
… |
void CInput::DeleteCurSelection()
|
1992 | 1984 | virtualTo = m_iBufferPos; |
1993 | 1985 | } |
1994 | 1986 | |
1995 | | *pCaption = pCaption->Left(virtualFrom) + |
| 1987 | *pCaption = pCaption->Left(virtualFrom) + |
1996 | 1988 | pCaption->Right((long)pCaption->length() - virtualTo); |
1997 | 1989 | |
1998 | 1990 | UpdateText(virtualFrom, virtualTo, virtualFrom); |
-
diff --git a/source/gui/CInput.h b/source/gui/CInput.h
index f5aa0ed..8a9a955 100644
a
|
b
|
public:
|
47 | 47 | |
48 | 48 | // Check where the mouse is hovering, and get the appropriate text position. |
49 | 49 | // return is the text-position index. |
50 | | // const in philosophy, but I need to retrieve the caption in a non-const way. |
51 | | int GetMouseHoveringTextPosition(); |
| 50 | int GetMouseHoveringTextPosition() const; |
52 | 51 | |
53 | | // Same as above, but only on one row in X, and a given value, not the mouse's |
54 | | // wanted is filled with x if the row didn't extend as far as we |
55 | | int GetXTextPosition(const std::list<SRow>::iterator& c, const float& x, float& wanted); |
| 52 | // Same as above, but only on one row in X, and a given value, not the mouse's. |
| 53 | // wanted is filled with x if the row didn't extend as far as the mouse pos. |
| 54 | int GetXTextPosition(const std::list<SRow>::const_iterator& c, const float& x, float& wanted) const; |
56 | 55 | |
57 | 56 | protected: |
58 | 57 | /** |
-
diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp
index ba3f3c3..7f5af0a 100644
a
|
b
|
void CList::SetupText()
|
104 | 104 | |
105 | 105 | // Generate texts |
106 | 106 | float buffered_y = 0.f; |
107 | | |
| 107 | |
108 | 108 | for (size_t i = 0; i < pList->m_Items.size(); ++i) |
109 | 109 | { |
110 | 110 | // Create a new SGUIText. Later on, input it using AddText() |
… |
… |
void CList::SetupText()
|
119 | 119 | } |
120 | 120 | |
121 | 121 | m_ItemsYPositions[pList->m_Items.size()] = buffered_y; |
122 | | |
| 122 | |
123 | 123 | // Setup scrollbar |
124 | 124 | if (scrollbar) |
125 | 125 | { |
… |
… |
void CList::HandleMessage(SGUIMessage& Message)
|
152 | 152 | // TODO: Check range |
153 | 153 | |
154 | 154 | // TODO only works if lower-case, shouldn't it be made case sensitive instead? |
155 | | ScriptEvent("selectionchange"); |
| 155 | ScriptEvent("selectionchange"); |
156 | 156 | } |
157 | 157 | |
158 | 158 | if (Message.value == "scrollbar") |
… |
… |
void CList::HandleMessage(SGUIMessage& Message)
|
206 | 206 | set = i; |
207 | 207 | } |
208 | 208 | } |
209 | | |
| 209 | |
210 | 210 | if (set != -1) |
211 | 211 | { |
212 | 212 | GUI<int>::SetSetting(this, "selected", set); |
… |
… |
InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev)
|
286 | 286 | return result; |
287 | 287 | } |
288 | 288 | |
289 | | void CList::Draw() |
| 289 | void CList::Draw() |
290 | 290 | { |
291 | 291 | int selected; |
292 | 292 | GUI<int>::GetSetting(this, "selected", selected); |
293 | | |
| 293 | |
294 | 294 | DrawList(selected, "sprite", "sprite_selectarea", "textcolor"); |
295 | 295 | } |
296 | 296 | |
… |
… |
bool CList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile)
|
411 | 411 | if (child.GetNodeName() == elmt_item) |
412 | 412 | { |
413 | 413 | AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); |
414 | | |
415 | 414 | return true; |
416 | 415 | } |
417 | | else |
418 | | { |
419 | | return false; |
420 | | } |
| 416 | |
| 417 | return false; |
421 | 418 | } |
422 | 419 | |
423 | 420 | void CList::SelectNextElement() |
… |
… |
void CList::SelectNextElement()
|
438 | 435 | g_SoundManager->PlayAsUI(soundPath.c_str(), false); |
439 | 436 | } |
440 | 437 | } |
441 | | |
| 438 | |
442 | 439 | void CList::SelectPrevElement() |
443 | 440 | { |
444 | 441 | int selected; |
… |
… |
void CList::SelectFirstElement()
|
463 | 460 | if (selected >= 0) |
464 | 461 | GUI<int>::SetSetting(this, "selected", 0); |
465 | 462 | } |
466 | | |
| 463 | |
467 | 464 | void CList::SelectLastElement() |
468 | 465 | { |
469 | 466 | int selected; |
-
diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp
index bbe81e9..81ce852 100644
a
|
b
|
void COList::HandleMessage(SGUIMessage& Message)
|
152 | 152 | CPos mouse = GetMousePos(); |
153 | 153 | if (!m_CachedActualSize.PointInside(mouse)) |
154 | 154 | return; |
155 | | |
| 155 | |
156 | 156 | float xpos = 0; |
157 | 157 | for (size_t def = 0; def < m_ObjectsDefs.size(); ++def) |
158 | 158 | { |
… |
… |
void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
361 | 361 | CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, |
362 | 362 | m_CachedActualSize.top + m_HeadingHeight); |
363 | 363 | GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head); |
364 | | |
| 364 | |
365 | 365 | CGUISpriteInstance* sprite_order; |
366 | 366 | CGUISpriteInstance* sprite_not_sorted; |
367 | 367 | if (m_SelectedColumnOrder != -1) |
-
diff --git a/source/gui/COList.h b/source/gui/COList.h
index 7ebabbe..239f23c 100644
a
|
b
|
struct ObjectDef
|
32 | 32 | /** |
33 | 33 | * Multi-column list. One row can be selected by the user. |
34 | 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 |
| 35 | * |
| 36 | * The list can be sorted dynamically by JS code when a |
37 | 37 | * heading is ckicked. |
38 | 38 | * A scroll-bar will appear when needed. |
39 | 39 | */ |
-
diff --git a/source/gui/CProgressBar.cpp b/source/gui/CProgressBar.cpp
index df8a816..009fb68 100644
a
|
b
|
void CProgressBar::HandleMessage(SGUIMessage& Message)
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | | void CProgressBar::Draw() |
| 64 | void CProgressBar::Draw() |
65 | 65 | { |
66 | 66 | if (!GetGUI()) |
67 | 67 | return; |
-
diff --git a/source/gui/CProgressBar.h b/source/gui/CProgressBar.h
index 7a22fe5..3f34db5 100644
a
|
b
|
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Object used to draw a value (e.g. progress) from 0 to 100 visually. |
25 | | * |
| 25 | * |
26 | 26 | * @see IGUIObject |
27 | 27 | */ |
28 | 28 | class CProgressBar : public IGUIObject |
-
diff --git a/source/gui/CRadioButton.h b/source/gui/CRadioButton.h
index 1656308..e9227f7 100644
a
|
b
|
|
24 | 24 | /** |
25 | 25 | * Just like a check box, but it'll nullify its siblings (of the same kind), |
26 | 26 | * and it won't switch itself. |
27 | | * |
| 27 | * |
28 | 28 | * @see CCheckBox |
29 | 29 | */ |
30 | 30 | class CRadioButton : public CCheckBox |
-
diff --git a/source/gui/CText.cpp b/source/gui/CText.cpp
index cccbdfc..b2b1090 100644
a
|
b
|
void CText::HandleMessage(SGUIMessage& Message)
|
182 | 182 | IGUITextOwner::HandleMessage(Message); |
183 | 183 | } |
184 | 184 | |
185 | | void CText::Draw() |
| 185 | void CText::Draw() |
186 | 186 | { |
187 | 187 | float bz = GetBufferedZ(); |
188 | 188 | |
-
diff --git a/source/gui/CText.h b/source/gui/CText.h
index 7b7fb4b..81d18b0 100644
a
|
b
|
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Text field that just displays static text. |
25 | | * |
| 25 | * |
26 | 26 | * @see IGUIObject |
27 | 27 | */ |
28 | 28 | class CText : public IGUIScrollBarOwner, public IGUITextOwner |
-
diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp
index 3a1483d..f44dbe6 100644
a
|
b
|
void CTooltip::SetupText()
|
87 | 87 | CPos mousepos, offset; |
88 | 88 | EVAlign anchor; |
89 | 89 | bool independent; |
90 | | |
| 90 | |
91 | 91 | GUI<bool>::GetSetting(this, "independent", independent); |
92 | 92 | if (independent) |
93 | 93 | mousepos = GetMousePos(); |
… |
… |
void CTooltip::HandleMessage(SGUIMessage& Message)
|
147 | 147 | IGUITextOwner::HandleMessage(Message); |
148 | 148 | } |
149 | 149 | |
150 | | void CTooltip::Draw() |
| 150 | void CTooltip::Draw() |
151 | 151 | { |
152 | 152 | if (!GetGUI()) |
153 | 153 | return; |
-
diff --git a/source/gui/GUIManager.cpp b/source/gui/GUIManager.cpp
index c8a8940..8199fdf 100644
a
|
b
|
void CGUIManager::PopPageCB(shared_ptr<ScriptInterface::StructuredClone> args)
|
114 | 114 | { |
115 | 115 | shared_ptr<ScriptInterface::StructuredClone> initDataClone = m_PageStack.back().initData; |
116 | 116 | PopPage(); |
117 | | |
| 117 | |
118 | 118 | shared_ptr<ScriptInterface> scriptInterface = m_PageStack.back().gui->GetScriptInterface(); |
119 | 119 | JSContext* cx = scriptInterface->GetContext(); |
120 | 120 | JS::RootedValue initDataVal(cx); |
121 | | if (initDataClone) |
122 | | scriptInterface->ReadStructuredClone(initDataClone, &initDataVal); |
123 | | else |
| 121 | if (!initDataClone) |
124 | 122 | { |
125 | 123 | LOGERROR("Called PopPageCB when initData (which should contain the callback function name) isn't set!"); |
126 | 124 | return; |
127 | 125 | } |
128 | | |
| 126 | |
| 127 | scriptInterface->ReadStructuredClone(initDataClone, &initDataVal); |
| 128 | |
129 | 129 | if (!scriptInterface->HasProperty(initDataVal, "callback")) |
130 | 130 | { |
131 | 131 | LOGERROR("Called PopPageCB when the callback function name isn't set!"); |
132 | 132 | return; |
133 | 133 | } |
134 | | |
| 134 | |
135 | 135 | std::string callback; |
136 | 136 | if (!scriptInterface->GetProperty(initDataVal, "callback", callback)) |
137 | 137 | { |
138 | 138 | LOGERROR("Failed to get the callback property as a string from initData in PopPageCB!"); |
139 | 139 | return; |
140 | 140 | } |
141 | | |
| 141 | |
142 | 142 | JS::RootedValue global(cx, scriptInterface->GetGlobalObject()); |
143 | 143 | if (!scriptInterface->HasProperty(global, callback.c_str())) |
144 | 144 | { |
… |
… |
void CGUIManager::LoadPage(SGUIPage& page)
|
182 | 182 | shared_ptr<ScriptInterface> scriptInterface = page.gui->GetScriptInterface(); |
183 | 183 | JSContext* cx = scriptInterface->GetContext(); |
184 | 184 | JSAutoRequest rq(cx); |
185 | | |
| 185 | |
186 | 186 | JS::RootedValue global(cx, scriptInterface->GetGlobalObject()); |
187 | 187 | JS::RootedValue hotloadDataVal(cx); |
188 | | scriptInterface->CallFunction(global, "getHotloadData", &hotloadDataVal); |
| 188 | scriptInterface->CallFunction(global, "getHotloadData", &hotloadDataVal); |
189 | 189 | hotloadData = scriptInterface->WriteStructuredClone(hotloadDataVal); |
190 | 190 | } |
191 | | |
| 191 | |
192 | 192 | page.inputs.clear(); |
193 | 193 | page.gui.reset(new CGUI(m_ScriptRuntime)); |
194 | 194 | |
… |
… |
void CGUIManager::LoadPage(SGUIPage& page)
|
252 | 252 | shared_ptr<ScriptInterface> scriptInterface = page.gui->GetScriptInterface(); |
253 | 253 | JSContext* cx = scriptInterface->GetContext(); |
254 | 254 | JSAutoRequest rq(cx); |
255 | | |
| 255 | |
256 | 256 | JS::RootedValue initDataVal(cx); |
257 | 257 | JS::RootedValue hotloadDataVal(cx); |
258 | 258 | JS::RootedValue global(cx, scriptInterface->GetGlobalObject()); |
259 | | if (page.initData) |
| 259 | if (page.initData) |
260 | 260 | scriptInterface->ReadStructuredClone(page.initData, &initDataVal); |
261 | 261 | if (hotloadData) |
262 | 262 | scriptInterface->ReadStructuredClone(hotloadData, &hotloadDataVal); |
263 | | |
| 263 | |
264 | 264 | // Call the init() function |
265 | 265 | if (!scriptInterface->CallFunctionVoid( |
266 | | global, |
267 | | "init", |
268 | | initDataVal, |
| 266 | global, |
| 267 | "init", |
| 268 | initDataVal, |
269 | 269 | hotloadDataVal) |
270 | 270 | ) |
271 | 271 | { |
… |
… |
std::string CGUIManager::GetSavedGameData()
|
302 | 302 | shared_ptr<ScriptInterface> scriptInterface = top()->GetScriptInterface(); |
303 | 303 | JSContext* cx = scriptInterface->GetContext(); |
304 | 304 | JSAutoRequest rq(cx); |
305 | | |
| 305 | |
306 | 306 | JS::RootedValue data(cx); |
307 | 307 | JS::RootedValue global(cx, top()->GetGlobalObject()); |
308 | 308 | scriptInterface->CallFunction(global, "getSavedGameData", &data); |
… |
… |
void CGUIManager::RestoreSavedGameData(std::string jsonData)
|
314 | 314 | shared_ptr<ScriptInterface> scriptInterface = top()->GetScriptInterface(); |
315 | 315 | JSContext* cx = scriptInterface->GetContext(); |
316 | 316 | JSAutoRequest rq(cx); |
317 | | |
| 317 | |
318 | 318 | JS::RootedValue global(cx, top()->GetGlobalObject()); |
319 | 319 | JS::RootedValue dataVal(cx); |
320 | 320 | scriptInterface->ParseJSON(jsonData, &dataVal); |
… |
… |
InReaction CGUIManager::HandleEvent(const SDL_Event_* ev)
|
329 | 329 | // visible game area), sometimes they'll want to intercepts events before the GUI (e.g. |
330 | 330 | // to capture all mouse events until a mouseup after dragging). |
331 | 331 | // So we call two separate handler functions: |
332 | | |
| 332 | |
333 | 333 | bool handled; |
334 | 334 | |
335 | 335 | { |
… |
… |
void CGUIManager::TickObjects()
|
392 | 392 | // We share the script runtime with everything else that runs in the same thread. |
393 | 393 | // This call makes sure we trigger GC regularly even if the simulation is not running. |
394 | 394 | m_ScriptInterface->GetRuntime()->MaybeIncrementalGC(1.0f); |
395 | | |
| 395 | |
396 | 396 | // Save an immutable copy so iterators aren't invalidated by tick handlers |
397 | 397 | PageStackType pageStack = m_PageStack; |
398 | 398 | |
-
diff --git a/source/gui/GUIManager.h b/source/gui/GUIManager.h
index bad6d20..5e76232 100644
a
|
b
|
public:
|
51 | 51 | CGUIManager(); |
52 | 52 | ~CGUIManager(); |
53 | 53 | |
54 | | shared_ptr<ScriptInterface> GetScriptInterface() |
55 | | { |
56 | | return m_ScriptInterface; |
| 54 | shared_ptr<ScriptInterface> GetScriptInterface() |
| 55 | { |
| 56 | return m_ScriptInterface; |
57 | 57 | } |
58 | 58 | shared_ptr<ScriptRuntime> GetRuntime() { return m_ScriptRuntime; } |
59 | 59 | shared_ptr<CGUI> GetActiveGUI() { return top(); } |
… |
… |
public:
|
136 | 136 | * Calls the current page's script function getSavedGameData() and returns the result. |
137 | 137 | */ |
138 | 138 | std::string GetSavedGameData(); |
139 | | |
| 139 | |
140 | 140 | void RestoreSavedGameData(std::string jsonData); |
141 | 141 | |
142 | 142 | /** |
… |
… |
private:
|
165 | 165 | void LoadPage(SGUIPage& page); |
166 | 166 | |
167 | 167 | shared_ptr<CGUI> top() const; |
168 | | |
| 168 | |
169 | 169 | shared_ptr<CGUI> m_CurrentGUI; // used to latch state during TickObjects/LoadPage (this is kind of ugly) |
170 | 170 | shared_ptr<ScriptRuntime> m_ScriptRuntime; |
171 | 171 | shared_ptr<ScriptInterface> m_ScriptInterface; |
-
diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp
index 1597f27..09c1050 100644
a
|
b
|
void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName,
|
86 | 86 | { |
87 | 87 | // TODO: Should check (nicely) that this is a valid file? |
88 | 88 | SGUIImage* Image = new SGUIImage; |
89 | | |
| 89 | |
90 | 90 | // Allow grayscale images for disabled portraits |
91 | 91 | if (SpriteName.substr(10, 10) == "grayscale:") |
92 | 92 | { |
… |
… |
void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName,
|
107 | 107 | Sprite->AddImage(Image); |
108 | 108 | |
109 | 109 | Sprites[SpriteName] = Sprite; |
110 | | |
| 110 | |
111 | 111 | it = Sprites.find(SpriteName); |
112 | 112 | ENSURE(it != Sprites.end()); // The insertion above shouldn't fail |
113 | 113 | } |
… |
… |
void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName,
|
118 | 118 | |
119 | 119 | double xRatio = SpriteName.BeforeFirst(",").AfterLast("(").ToDouble(); |
120 | 120 | double yRatio = SpriteName.BeforeFirst(")").AfterLast(",").ToDouble(); |
121 | | |
| 121 | |
122 | 122 | int PathStart = SpriteName.Find(")") + 1; |
123 | | |
| 123 | |
124 | 124 | Image->m_TextureName = VfsPath("art/textures/ui") / wstring_from_utf8(SpriteName.substr(PathStart)); |
125 | 125 | |
126 | 126 | CClientArea ca(CRect(0, 0, 0, 0), CRect(0, 0, 100, 100)); |
… |
… |
void GUIRenderer::UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName,
|
132 | 132 | Sprite->AddImage(Image); |
133 | 133 | |
134 | 134 | Sprites[SpriteName] = Sprite; |
135 | | |
| 135 | |
136 | 136 | it = Sprites.find(SpriteName); |
137 | 137 | ENSURE(it != Sprites.end()); // The insertion above shouldn't fail |
138 | 138 | } |
… |
… |
void GUIRenderer::Draw(DrawCalls& Calls, float Z)
|
437 | 437 | } |
438 | 438 | #undef ADD |
439 | 439 | } |
440 | | |
| 440 | |
441 | 441 | cit->m_Shader->EndPass(); |
442 | 442 | |
443 | 443 | glDisable(GL_BLEND); |
-
diff --git a/source/gui/GUITooltip.cpp b/source/gui/GUITooltip.cpp
index aa321a5..009a5bd 100644
a
|
b
|
void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI)
|
332 | 332 | // Mouse moved onto a new object |
333 | 333 | |
334 | 334 | if (GetTooltip(Nearest, style)) |
335 | | { |
| 335 | { |
336 | 336 | CStr style_old; |
337 | 337 | |
338 | | // If we're displaying a tooltip with no delay, then we want to |
| 338 | // If we're displaying a tooltip with no delay, then we want to |
339 | 339 | // reset so that other object that should have delay can't |
340 | 340 | // "ride this tail", it have to wait. |
341 | 341 | // Notice that this doesn't apply to when you go from one delay=0 |
… |
… |
void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI* GUI)
|
354 | 354 | } |
355 | 355 | } |
356 | 356 | else |
357 | | { |
| 357 | { |
358 | 358 | nextstate = ST_COOLING; |
359 | 359 | } |
360 | 360 | } |
-
diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h
index d89427b..1a9daa0 100644
a
|
b
|
GUI Core, stuff that the whole GUI uses
|
20 | 20 | |
21 | 21 | --Overview-- |
22 | 22 | |
23 | | Contains defines, includes, types etc that the whole |
| 23 | Contains defines, includes, types etc that the whole |
24 | 24 | GUI should have included. |
25 | 25 | |
26 | 26 | --More info-- |
… |
… |
public: \
|
50 | 50 | static IGUIObject* ConstructObject() { return new obj(); } |
51 | 51 | |
52 | 52 | |
53 | | /** |
| 53 | /** |
54 | 54 | * Message types. |
55 | 55 | * @see SGUIMessage |
56 | 56 | */ |
… |
… |
enum EGUIMessageType
|
78 | 78 | GUIM_LOST_FOCUS, |
79 | 79 | GUIM_PRESSED_MOUSE_RIGHT, |
80 | 80 | GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, |
81 | | GUIM_TAB // Used by CInput |
| 81 | GUIM_TAB // Used by CInput |
82 | 82 | }; |
83 | 83 | |
84 | 84 | /** |
… |
… |
public:
|
182 | 182 | * |
183 | 183 | * "0 0 100% 100%" |
184 | 184 | * "50%-10 50%-10 50%+10 50%+10" |
185 | | * |
| 185 | * |
186 | 186 | * i.e. First percent modifier, then + or - and the pixel modifier. |
187 | 187 | * Although you can use just the percent or the pixel modifier. Notice |
188 | 188 | * though that the percent modifier must always be the first when |
-
diff --git a/source/gui/GUItext.h b/source/gui/GUItext.h
index dc8bffd..0cbccf15 100644
a
|
b
|
class CGUI;
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * An SGUIText object is a parsed string, divided into |
42 | | * text-rendering components. Each component, being a |
| 42 | * text-rendering components. Each component, being a |
43 | 43 | * call to the Renderer. For instance, if you by tags |
44 | 44 | * change the color, then the GUI will have to make |
45 | 45 | * individual calls saying it want that color on the |
… |
… |
struct SGUIText
|
89 | 89 | */ |
90 | 90 | struct STextCall |
91 | 91 | { |
92 | | STextCall() : |
| 92 | STextCall() : |
93 | 93 | m_UseCustomColor(false), |
94 | 94 | m_Bold(false), m_Italic(false), m_Underlined(false), |
95 | 95 | m_pSpriteCall(NULL) {} |
-
diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp
index ca4dd9c..6ee03ab 100644
a
|
b
|
bool __ParseString<bool>(const CStrW& Value, bool& Output)
|
32 | 32 | Output = true; |
33 | 33 | else if (Value == L"false") |
34 | 34 | Output = false; |
35 | | else |
| 35 | else |
36 | 36 | return false; |
37 | 37 | |
38 | 38 | return true; |
… |
… |
PSRETURN GUI<T>::GetSettingPointer(const IGUIObject* pObject, const CStr& Settin
|
329 | 329 | std::map<CStr, SGUISetting>::const_iterator it = pObject->m_Settings.find(Setting); |
330 | 330 | if (it == pObject->m_Settings.end()) |
331 | 331 | { |
332 | | LOGWARNING("setting %s was not found on object %s", |
| 332 | LOGWARNING("setting %s was not found on object %s", |
333 | 333 | Setting.c_str(), |
334 | 334 | pObject->GetPresentableName().c_str()); |
335 | 335 | return PSRETURN_GUI_InvalidSetting; |
… |
… |
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& V
|
377 | 377 | |
378 | 378 | if (!pObject->SettingExists(Setting)) |
379 | 379 | { |
380 | | LOGWARNING("setting %s was not found on object %s", |
| 380 | LOGWARNING("setting %s was not found on object %s", |
381 | 381 | Setting.c_str(), |
382 | 382 | pObject->GetPresentableName().c_str()); |
383 | 383 | return PSRETURN_GUI_InvalidSetting; |
-
diff --git a/source/gui/GUIutil.h b/source/gui/GUIutil.h
index 249ce31..e17a582 100644
a
|
b
|
CMatrix3D GetDefaultGuiMatrix();
|
50 | 50 | struct SGUIMessage; |
51 | 51 | |
52 | 52 | /** |
53 | | * Base class to only the class GUI. This superclass is |
| 53 | * Base class to only the class GUI. This superclass is |
54 | 54 | * kind of a templateless extention of the class GUI. |
55 | 55 | * Used for other functions to friend with, because it |
56 | 56 | * can't friend with GUI since it's templated (at least |
… |
… |
class CInternalCGUIAccessorBase
|
61 | 61 | protected: |
62 | 62 | /// Get object pointer |
63 | 63 | static IGUIObject* GetObjectPointer(CGUI& GUIinstance, const CStr& Object); |
64 | | |
| 64 | |
65 | 65 | /// const version |
66 | 66 | static const IGUIObject* GetObjectPointer(const CGUI& GUIinstance, const CStr& Object); |
67 | 67 | |
… |
… |
protected:
|
73 | 73 | |
74 | 74 | |
75 | 75 | #ifndef NDEBUG |
76 | | // Used to ensure type-safety, sort of |
| 76 | // Used to ensure type-safety, sort of |
77 | 77 | template<typename T> void CheckType(const IGUIObject* obj, const CStr& setting); |
78 | 78 | #endif |
79 | 79 | |
… |
… |
public:
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | | * Sets a value by setting and object name using a real |
| 144 | * Sets a value by setting and object name using a real |
145 | 145 | * datatype as input |
146 | 146 | * |
147 | 147 | * This is just a wrapper so that we can type the object name |
… |
… |
public:
|
167 | 167 | |
168 | 168 | return SetSetting(pObject, Setting, Value, SkipMessage); |
169 | 169 | } |
170 | | |
| 170 | |
171 | 171 | /** |
172 | 172 | * This will return the value of the first sprite if it's not null, |
173 | 173 | * if it is null, it will return the value of the second sprite, if |
… |
… |
public:
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | | * Sets a value by setting and object name using a real |
| 200 | * Sets a value by setting and object name using a real |
201 | 201 | * datatype as input. |
202 | 202 | * |
203 | 203 | * This is just a wrapper for __ParseString() which really |
… |
… |
private:
|
256 | 256 | return; |
257 | 257 | |
258 | 258 | (pObject->*pFunc)(Argument); |
259 | | |
| 259 | |
260 | 260 | // Iterate children |
261 | 261 | for (IGUIObject* const& obj : *pObject) |
262 | 262 | RecurseObject(RR, obj, pFunc, Argument); |
… |
… |
private:
|
273 | 273 | return; |
274 | 274 | |
275 | 275 | (pObject->*pFunc)(Argument); |
276 | | |
| 276 | |
277 | 277 | // Iterate children |
278 | 278 | for (IGUIObject* const& obj : *pObject) |
279 | 279 | RecurseObject(RR, obj, pFunc, Argument); |
-
diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp
index 53f7980..eb2b755 100644
a
|
b
|
void IGUIObject::AddChild(IGUIObject* pChild)
|
100 | 100 | // If anything went wrong, reverse what we did and throw |
101 | 101 | // an exception telling it never added a child |
102 | 102 | m_Children.erase(m_Children.end()-1); |
103 | | |
| 103 | |
104 | 104 | throw; |
105 | 105 | } |
106 | 106 | } |
… |
… |
bool IGUIObject::MouseOverIcon()
|
177 | 177 | } |
178 | 178 | |
179 | 179 | CPos IGUIObject::GetMousePos() const |
180 | | { |
181 | | return ((GetGUI())?(GetGUI()->m_MousePos):CPos()); |
| 180 | { |
| 181 | if (GetGUI()) |
| 182 | return GetGUI()->m_MousePos; |
| 183 | |
| 184 | return CPos(); |
182 | 185 | } |
183 | 186 | |
184 | 187 | void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver) |
… |
… |
void IGUIObject::UpdateCachedSize()
|
309 | 312 | |
310 | 313 | CClientArea ca; |
311 | 314 | GUI<CClientArea>::GetSetting(this, "size", ca); |
312 | | |
| 315 | |
313 | 316 | // If absolute="false" and the object has got a parent, |
314 | 317 | // use its cached size instead of the screen. Notice |
315 | 318 | // it must have just been cached for it to work. |
… |
… |
float IGUIObject::GetBufferedZ() const
|
385 | 388 | else |
386 | 389 | { |
387 | 390 | // In philosophy, a parentless object shouldn't be able to have a relative sizing, |
388 | | // but we'll accept it so that absolute can be used as default without a complaint. |
| 391 | // but we'll accept it so that absolute can be used as default without a complaint. |
389 | 392 | // Also, you could consider those objects children to the screen resolution. |
390 | 393 | return Z; |
391 | 394 | } |
… |
… |
void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
396 | 399 | { |
397 | 400 | if(!GetGUI()) |
398 | 401 | throw PSERROR_GUI_OperationNeedsGUIObject(); |
399 | | |
| 402 | |
400 | 403 | JSContext* cx = pGUI->GetScriptInterface()->GetContext(); |
401 | 404 | JSAutoRequest rq(cx); |
402 | 405 | JS::RootedValue globalVal(cx, pGUI->GetGlobalObject()); |
403 | 406 | JS::RootedObject globalObj(cx, &globalVal.toObject()); |
404 | | |
| 407 | |
405 | 408 | const int paramCount = 1; |
406 | 409 | const char* paramNames[paramCount] = { "mouse" }; |
407 | 410 | |
… |
… |
void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
422 | 425 | |
423 | 426 | if (!func) |
424 | 427 | return; // JS will report an error message |
425 | | |
| 428 | |
426 | 429 | JS::RootedObject funcObj(cx, JS_GetFunctionObject(func)); |
427 | 430 | SetScriptHandler(Action, funcObj); |
428 | 431 | } |
… |
… |
CStr IGUIObject::GetPresentableName() const
|
528 | 531 | |
529 | 532 | void IGUIObject::SetFocus() |
530 | 533 | { |
531 | | GetGUI()->m_FocusedObject = this; |
| 534 | GetGUI()->m_FocusedObject = this; |
532 | 535 | } |
533 | 536 | |
534 | 537 | bool IGUIObject::IsFocused() const |
535 | 538 | { |
536 | | return GetGUI()->m_FocusedObject == this; |
| 539 | return GetGUI()->m_FocusedObject == this; |
537 | 540 | } |
538 | 541 | |
539 | 542 | bool IGUIObject::IsRootObject() const |
… |
… |
void IGUIObject::TraceMember(JSTracer* trc)
|
549 | 552 | |
550 | 553 | PSRETURN IGUIObject::LogInvalidSettings(const CStr8& Setting) const |
551 | 554 | { |
552 | | LOGWARNING("IGUIObject: setting %s was not found on an object", |
| 555 | LOGWARNING("IGUIObject: setting %s was not found on an object", |
553 | 556 | Setting.c_str()); |
554 | 557 | return PSRETURN_GUI_InvalidSetting; |
555 | 558 | } |
-
diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h
index 1f29053..2b4dd72 100644
a
|
b
|
public:
|
176 | 176 | void AddToPointersMap(map_pObjects& ObjectMap); |
177 | 177 | |
178 | 178 | /** |
179 | | * Notice nothing will be returned or thrown if the child hasn't |
180 | | * been inputted into the GUI yet. This is because that's were |
| 179 | * Notice nothing will be returned or thrown if the child hasn't |
| 180 | * been inputted into the GUI yet. This is because that's were |
181 | 181 | * all is checked. Now we're just linking two objects, but |
182 | 182 | * it's when we're inputting them into the GUI we'll check |
183 | 183 | * validity! Notice also when adding it to the GUI this function |
… |
… |
public:
|
219 | 219 | * @return True if settings exist. |
220 | 220 | */ |
221 | 221 | bool SettingExists(const CStr& Setting) const; |
222 | | |
| 222 | |
223 | 223 | /** |
224 | 224 | * All sizes are relative to resolution, and the calculation |
225 | 225 | * is not wanted in real time, therefore it is cached, update |
… |
… |
public:
|
257 | 257 | * @param pGUI GUI instance to associate the script with |
258 | 258 | */ |
259 | 259 | void RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI* pGUI); |
260 | | |
| 260 | |
261 | 261 | /** |
262 | 262 | * Retrieves the JSObject representing this GUI object. |
263 | 263 | */ |
… |
… |
protected:
|
290 | 290 | * MEGA TODO Should it destroy it's children? |
291 | 291 | */ |
292 | 292 | virtual void Destroy(); |
293 | | |
| 293 | |
294 | 294 | public: |
295 | 295 | /** |
296 | 296 | * This function is called with different messages |
… |
… |
protected:
|
353 | 353 | * Set parent of this object |
354 | 354 | */ |
355 | 355 | void SetParent(IGUIObject* pParent) { m_pParent = pParent; } |
356 | | |
| 356 | |
357 | 357 | /** |
358 | 358 | * Reset internal state of this object |
359 | 359 | */ |
… |
… |
private:
|
459 | 459 | /** @name Internal functions */ |
460 | 460 | //-------------------------------------------------------- |
461 | 461 | //@{ |
462 | | |
| 462 | |
463 | 463 | /** |
464 | 464 | * Inputs a reference pointer, checks if the new inputted object |
465 | 465 | * if hovered, if so, then check if this's Z value is greater |
… |
… |
protected:
|
518 | 518 | * read. This is important to know because I don't want to force |
519 | 519 | * the user to include its \<styles\>-XML-files first, so somehow |
520 | 520 | * the GUI needs to know which settings were set, and which is meant |
521 | | * to |
| 521 | * to. |
522 | 522 | */ |
523 | 523 | |
524 | 524 | // More variables |
… |
… |
private:
|
543 | 543 | |
544 | 544 | // Internal storage for registered script handlers. |
545 | 545 | std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers; |
546 | | |
| 546 | |
547 | 547 | // Cached JSObject representing this GUI object |
548 | 548 | DefPersistentRooted<JSObject*> m_JSObject; |
549 | 549 | }; |
-
diff --git a/source/gui/IGUIScrollBar.cpp b/source/gui/IGUIScrollBar.cpp
index 0ad463a..1d20afd 100644
a
|
b
|
|
23 | 23 | IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL), |
24 | 24 | m_X(300.f), m_Y(300.f), |
25 | 25 | m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division. |
26 | | m_Length(200.f), m_Width(20.f), |
| 26 | m_Length(200.f), m_Width(20.f), |
27 | 27 | m_BarSize(0.f), m_Pos(0.f), |
28 | 28 | m_ButtonPlusPressed(false), |
29 | 29 | m_ButtonMinusPressed(false), |
… |
… |
const SGUIScrollBarStyle* IGUIScrollBar::GetStyle() const
|
69 | 69 | return m_pHostObject->GetScrollBarStyle(m_ScrollBarStyle); |
70 | 70 | } |
71 | 71 | |
72 | | CGUI* IGUIScrollBar::GetGUI() const |
73 | | { |
| 72 | CGUI* IGUIScrollBar::GetGUI() const |
| 73 | { |
74 | 74 | if (!m_pHostObject) |
75 | 75 | return NULL; |
76 | 76 | |
77 | | return m_pHostObject->GetGUI(); |
| 77 | return m_pHostObject->GetGUI(); |
78 | 78 | } |
79 | 79 | |
80 | 80 | void IGUIScrollBar::UpdatePosBoundaries() |
-
diff --git a/source/gui/IGUIScrollBar.h b/source/gui/IGUIScrollBar.h
index 6ad6710..bda4a4a 100644
a
|
b
|
struct SGUIScrollBarStyle
|
89 | 89 | * in pixels. |
90 | 90 | */ |
91 | 91 | float m_MaximumBarSize; |
92 | | |
| 92 | |
93 | 93 | /** |
94 | 94 | * True if you want edge buttons, i.e. buttons that can be pressed in order |
95 | 95 | * to scroll. |
… |
… |
public:
|
252 | 252 | * @param width Width |
253 | 253 | */ |
254 | 254 | void SetWidth(float width) { m_Width = width; } |
255 | | |
| 255 | |
256 | 256 | /** |
257 | 257 | * Set X Position |
258 | 258 | * @param x Position in this axis |
… |
… |
protected:
|
341 | 341 | /** |
342 | 342 | * Width of the scroll bar |
343 | 343 | */ |
344 | | float m_Width; |
| 344 | float m_Width; |
345 | 345 | |
346 | 346 | /** |
347 | 347 | * Absolute X Position |
-
diff --git a/source/gui/IGUIScrollBarOwner.cpp b/source/gui/IGUIScrollBarOwner.cpp
index 1062c6c..6a2dac3 100644
a
|
b
|
void IGUIScrollBarOwner::HandleMessage(SGUIMessage& msg)
|
68 | 68 | sb->HandleMessage(msg); |
69 | 69 | } |
70 | 70 | |
71 | | void IGUIScrollBarOwner::Draw() |
| 71 | void IGUIScrollBarOwner::Draw() |
72 | 72 | { |
73 | 73 | for (IGUIScrollBar* const& sb : m_ScrollBars) |
74 | 74 | sb->Draw(); |
75 | 75 | } |
| 76 | |
| 77 | float IGUIScrollBarOwner::GetScrollBarPos(const int index) const |
| 78 | { |
| 79 | return m_ScrollBars[index]->GetPos(); |
| 80 | } |
-
diff --git a/source/gui/IGUIScrollBarOwner.h b/source/gui/IGUIScrollBarOwner.h
index f1a5d50..e22adda 100644
a
|
b
|
public:
|
69 | 69 | return *m_ScrollBars[index]; |
70 | 70 | } |
71 | 71 | |
| 72 | /** |
| 73 | * Get the position of the scroll bar at @param index. |
| 74 | * Equivalent to GetScrollbar(index).GetPos(). |
| 75 | */ |
| 76 | virtual float GetScrollBarPos(const int index) const; |
| 77 | |
72 | 78 | protected: |
73 | 79 | |
74 | 80 | /** |
-
diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp
index 745f20e..185f52e 100644
a
|
b
|
CMiniMap::CMiniMap() :
|
86 | 86 | m_AttributePos.type = GL_FLOAT; |
87 | 87 | m_AttributePos.elems = 2; |
88 | 88 | m_VertexArray.AddAttribute(&m_AttributePos); |
89 | | |
| 89 | |
90 | 90 | m_AttributeColor.type = GL_UNSIGNED_BYTE; |
91 | 91 | m_AttributeColor.elems = 4; |
92 | 92 | m_VertexArray.AddAttribute(&m_AttributeColor); |
93 | | |
| 93 | |
94 | 94 | m_VertexArray.SetNumVertices(MAX_ENTITIES_DRAWN); |
95 | 95 | m_VertexArray.Layout(); |
96 | 96 | |
… |
… |
void CMiniMap::FireWorldClickEvent(int UNUSED(button), int UNUSED(clicks))
|
236 | 236 | { |
237 | 237 | JSContext* cx = g_GUI->GetActiveGUI()->GetScriptInterface()->GetContext(); |
238 | 238 | JSAutoRequest rq(cx); |
239 | | |
| 239 | |
240 | 240 | float x, z; |
241 | 241 | GetMouseWorldCoordinates(x, z); |
242 | 242 | |
… |
… |
void CMiniMap::DrawViewRect(CMatrix3D transform)
|
283 | 283 | glScissor( |
284 | 284 | m_CachedActualSize.left / g_GuiScale, |
285 | 285 | g_Renderer.GetHeight() - m_CachedActualSize.bottom / g_GuiScale, |
286 | | width / g_GuiScale, |
| 286 | width / g_GuiScale, |
287 | 287 | height / g_GuiScale); |
288 | 288 | glEnable(GL_SCISSOR_TEST); |
289 | 289 | glLineWidth(2.0f); |
… |
… |
void CMiniMap::Draw()
|
405 | 405 | const double cur_time = timer_Time(); |
406 | 406 | const bool doUpdate = cur_time - last_time > 0.5; |
407 | 407 | if (doUpdate) |
408 | | { |
| 408 | { |
409 | 409 | last_time = cur_time; |
410 | 410 | if (m_TerrainDirty) |
411 | 411 | RebuildTerrainTexture(); |
-
diff --git a/source/gui/MiniMap.h b/source/gui/MiniMap.h
index 2cf6d16..7e5409e 100644
a
|
b
|
protected:
|
84 | 84 | |
85 | 85 | // 1.f if map is circular or 1.414f if square (to shrink it inside the circle) |
86 | 86 | float m_MapScale; |
87 | | |
| 87 | |
88 | 88 | // maximal water height to allow the passage of a unit (for underwater shallows). |
89 | 89 | float m_ShallowPassageHeight; |
90 | 90 | |
-
diff --git a/source/gui/scripting/JSInterface_GUITypes.cpp b/source/gui/scripting/JSInterface_GUITypes.cpp
index 2246568..ea5c276 100644
a
|
b
|
JSClass JSI_GUISize::JSI_class = {
|
30 | 30 | NULL, NULL, JSI_GUISize::construct, NULL |
31 | 31 | }; |
32 | 32 | |
33 | | JSFunctionSpec JSI_GUISize::JSI_methods[] = |
| 33 | JSFunctionSpec JSI_GUISize::JSI_methods[] = |
34 | 34 | { |
35 | 35 | JS_FS("toString", JSI_GUISize::toString, 0, 0), |
36 | 36 | JS_FS_END |
… |
… |
JSClass JSI_GUIColor::JSI_class = {
|
138 | 138 | NULL, NULL, JSI_GUIColor::construct, NULL |
139 | 139 | }; |
140 | 140 | |
141 | | JSFunctionSpec JSI_GUIColor::JSI_methods[] = |
| 141 | JSFunctionSpec JSI_GUIColor::JSI_methods[] = |
142 | 142 | { |
143 | 143 | JS_FS("toString", JSI_GUIColor::toString, 0, 0), |
144 | 144 | JS_FS_END |
… |
… |
bool JSI_GUIColor::construct(JSContext* cx, uint argc, jsval* vp)
|
148 | 148 | { |
149 | 149 | JSAutoRequest rq(cx); |
150 | 150 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
151 | | |
| 151 | |
152 | 152 | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; |
153 | 153 | JS::RootedObject obj(cx, pScriptInterface->CreateCustomObject("GUIColor")); |
154 | | |
| 154 | |
155 | 155 | if (args.length() == 4) |
156 | 156 | { |
157 | 157 | JS_SetProperty(cx, obj, "r", args[0]); |
… |
… |
JSClass JSI_GUIMouse::JSI_class = {
|
208 | 208 | NULL, NULL, JSI_GUIMouse::construct, NULL |
209 | 209 | }; |
210 | 210 | |
211 | | JSFunctionSpec JSI_GUIMouse::JSI_methods[] = |
| 211 | JSFunctionSpec JSI_GUIMouse::JSI_methods[] = |
212 | 212 | { |
213 | 213 | JS_FS("toString", JSI_GUIMouse::toString, 0, 0), |
214 | 214 | JS_FS_END |
-
diff --git a/source/gui/scripting/JSInterface_IGUIObject.cpp b/source/gui/scripting/JSInterface_IGUIObject.cpp
index b651c97..5b2e43b 100644
a
|
b
|
bool JSI_IGUIObject::construct(JSContext* cx, uint argc, jsval* vp)
|
594 | 594 | JSAutoRequest rq(cx); |
595 | 595 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
596 | 596 | ScriptInterface* pScriptInterface = ScriptInterface::GetScriptInterfaceAndCBData(cx)->pScriptInterface; |
597 | | |
| 597 | |
598 | 598 | if (args.length() == 0) |
599 | 599 | { |
600 | 600 | JS_ReportError(cx, "GUIObject has no default constructor"); |
… |
… |
bool JSI_IGUIObject::toString(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
622 | 622 | JS::CallReceiver rec = JS::CallReceiverFromVp(vp); |
623 | 623 | |
624 | 624 | JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); |
625 | | |
| 625 | |
626 | 626 | IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); |
627 | 627 | if (!e) |
628 | 628 | return false; |
… |
… |
bool JSI_IGUIObject::focus(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
640 | 640 | JS::CallReceiver rec = JS::CallReceiverFromVp(vp); |
641 | 641 | |
642 | 642 | JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); |
643 | | |
| 643 | |
644 | 644 | IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); |
645 | 645 | if (!e) |
646 | 646 | return false; |
… |
… |
bool JSI_IGUIObject::blur(JSContext* cx, uint UNUSED(argc), jsval* vp)
|
657 | 657 | JS::CallReceiver rec = JS::CallReceiverFromVp(vp); |
658 | 658 | |
659 | 659 | JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); |
660 | | |
| 660 | |
661 | 661 | IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); |
662 | 662 | if (!e) |
663 | 663 | return false; |
… |
… |
bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint UNUSED(argc), jsval* vp
|
672 | 672 | { |
673 | 673 | JSAutoRequest rq(cx); |
674 | 674 | JS::CallReceiver rec = JS::CallReceiverFromVp(vp); |
675 | | |
| 675 | |
676 | 676 | JS::RootedObject thisObj(cx, JS_THIS_OBJECT(cx, vp)); |
677 | | |
| 677 | |
678 | 678 | IGUIObject* e = (IGUIObject*)JS_GetInstancePrivate(cx, thisObj, &JSI_IGUIObject::JSI_class, NULL); |
679 | 679 | if (!e) |
680 | 680 | return false; |
-
diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp
index 69baf4e..939a416 100644
a
|
b
|
void StartGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs,
|
217 | 217 | CSimulation2* sim = g_Game->GetSimulation2(); |
218 | 218 | JSContext* cxSim = sim->GetScriptInterface().GetContext(); |
219 | 219 | JSAutoRequest rqSim(cxSim); |
220 | | |
221 | | JS::RootedValue gameAttribs(cxSim, |
| 220 | |
| 221 | JS::RootedValue gameAttribs(cxSim, |
222 | 222 | sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), attribs)); |
223 | 223 | |
224 | 224 | g_Game->SetPlayerID(playerID); |
… |
… |
JS::Value StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring na
|
230 | 230 | // We need to be careful with different compartments and contexts. |
231 | 231 | // The GUI calls this function from the GUI context and expects the return value in the same context. |
232 | 232 | // The game we start from here creates another context and expects data in this context. |
233 | | |
| 233 | |
234 | 234 | JSContext* cxGui = pCxPrivate->pScriptInterface->GetContext(); |
235 | 235 | JSAutoRequest rq(cxGui); |
236 | 236 | |
… |
… |
JS::Value StartSavedGame(ScriptInterface::CxPrivate* pCxPrivate, std::wstring na
|
247 | 247 | return JS::UndefinedValue(); |
248 | 248 | |
249 | 249 | g_Game = new CGame(); |
250 | | |
| 250 | |
251 | 251 | { |
252 | 252 | CSimulation2* sim = g_Game->GetSimulation2(); |
253 | 253 | JSContext* cxGame = sim->GetScriptInterface().GetContext(); |
254 | 254 | JSAutoRequest rq(cxGame); |
255 | | |
256 | | JS::RootedValue gameContextMetadata(cxGame, |
| 255 | |
| 256 | JS::RootedValue gameContextMetadata(cxGame, |
257 | 257 | sim->GetScriptInterface().CloneValueFromOtherContext(*(pCxPrivate->pScriptInterface), guiContextMetadata)); |
258 | 258 | JS::RootedValue gameInitAttributes(cxGame); |
259 | 259 | sim->GetScriptInterface().GetProperty(gameContextMetadata, "initAttributes", &gameInitAttributes); |
… |
… |
JS::Value GetMapSettings(ScriptInterface::CxPrivate* pCxPrivate)
|
464 | 464 | |
465 | 465 | JSContext* cx = g_Game->GetSimulation2()->GetScriptInterface().GetContext(); |
466 | 466 | JSAutoRequest rq(cx); |
467 | | |
| 467 | |
468 | 468 | JS::RootedValue mapSettings(cx); |
469 | 469 | g_Game->GetSimulation2()->GetMapSettings(&mapSettings); |
470 | 470 | return pCxPrivate->pScriptInterface->CloneValueFromOtherContext( |
… |
… |
static void InitJsTimers(ScriptInterface& scriptInterface)
|
888 | 888 | void StartJsTimer(ScriptInterface::CxPrivate* pCxPrivate, unsigned int slot) |
889 | 889 | { |
890 | 890 | ONCE(InitJsTimers(*(pCxPrivate->pScriptInterface))); |
891 | | |
| 891 | |
892 | 892 | if (slot >= MAX_JS_TIMERS) |
893 | 893 | LOGERROR("Exceeded the maximum number of timer slots for scripts!"); |
894 | 894 | |
… |
… |
void GuiScriptingInit(ScriptInterface& scriptInterface)
|
923 | 923 | JSI_Sound::RegisterScriptFunctions(scriptInterface); |
924 | 924 | JSI_L10n::RegisterScriptFunctions(scriptInterface); |
925 | 925 | JSI_Lobby::RegisterScriptFunctions(scriptInterface); |
926 | | |
| 926 | |
927 | 927 | // VFS (external) |
928 | 928 | scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &JSI_VFS::BuildDirEntList>("BuildDirEntList"); |
929 | 929 | scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists"); |