Index: binaries/data/mods/mod/gui/common/modern/setup.xml =================================================================== --- binaries/data/mods/mod/gui/common/modern/setup.xml +++ binaries/data/mods/mod/gui/common/modern/setup.xml @@ -8,7 +8,7 @@ ========================================== --> - + Index: binaries/data/mods/public/gui/pregame/mainmenu.js =================================================================== --- binaries/data/mods/public/gui/pregame/mainmenu.js +++ binaries/data/mods/public/gui/pregame/mainmenu.js @@ -18,6 +18,33 @@ g_BackgroundLayerData, g_ProjectInformation, g_CommunityButtons); + + + let tstCt = [ "blue", "red", "purple", "cyan", "rainbow", "tartan", "plaid", "brown", "black", "grey", "gray", "pink", "green", "magenta", "taupe", "mauve", "pecan", "orange" ]; + let tstDd = Engine.GetGUIObjectByName("testDrop"); + tstDd.list = tstCt; + tstDd.selected = 2; + + let tstLt = Engine.GetGUIObjectByName("testList"); + tstLt.list = tstCt; + tstLt.selected = 4; + + let tstOLt = Engine.GetGUIObjectByName("testOList"); + tstOLt.list_name = tstCt; + tstOLt.list_a = tstCt; + tstOLt.list_b = tstCt.reverse(); + tstOLt.list = tstCt; + tstOLt.selected = 1; + + let tstTxt = Engine.GetGUIObjectByName("testTextbox").caption; + let tstTB = Engine.GetGUIObjectByName("testTextboxScrollable"); + for (let i=0; i<3; ++i) + tstTB.caption += '[font="sans-bold-12"]Scrollable [/font]' + tstTxt + "\n\n"; + + let tstML = Engine.GetGUIObjectByName("testInputMultiline"); + for (let i=0; i<24; ++i) + tstML.caption += "\n."; + tstML.caption += "\nGroovy, baby!"; } function getHotloadData() Index: binaries/data/mods/public/gui/pregame/mainmenu.xml =================================================================== --- binaries/data/mods/public/gui/pregame/mainmenu.xml +++ binaries/data/mods/public/gui/pregame/mainmenu.xml @@ -10,6 +10,31 @@ + + + + + +[font="sans-bold-14"]Textbox:[/font] +Consider yourself, at home! +Consider yourself, part of the furniture! +We've taken to you, so strong. +It's clear. We're. Going to get along! + + + + + + + + + + Single Line Input Box + Multiple Line Input Box + + + + Index: source/gui/CGUI.h =================================================================== --- source/gui/CGUI.h +++ source/gui/CGUI.h @@ -646,7 +646,7 @@ // Styles std::map m_Styles; - // Scroll-bar styles + // Scrollbar styles std::map m_ScrollBarStyles; // Icons Index: source/gui/CGUI.cpp =================================================================== --- source/gui/CGUI.cpp +++ source/gui/CGUI.cpp @@ -1144,13 +1144,13 @@ else scrollbar.m_UseEdgeButtons = b; } - else if (attr_name == "width") + else if (attr_name == "breadth") { float f; if (!ParseString(this, attr_value.FromUTF8(), f)) LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); else - scrollbar.m_Width = f; + scrollbar.m_Breadth = f; } else if (attr_name == "minimum_bar_size") { Index: source/gui/CGUIScrollBarVertical.h =================================================================== --- source/gui/CGUIScrollBarVertical.h +++ source/gui/CGUIScrollBarVertical.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -16,9 +16,10 @@ */ /* - A GUI Scrollbar, this class doesn't present all functionality - to the scrollbar, it just controls the drawing and a wrapper - for interaction with it. + A vertical GUI Scrollbar, this class doesn't present all functionality + to the scrollbar, it just controls the drawing, handles some events, + and provides a wrapper for interaction with itself. Actual tracking + of how far we've scrolled inside the owner is handled elsewhere. */ #ifndef INCLUDED_CGUISCROLLBARVERTICAL @@ -39,15 +40,19 @@ public: /** - * Draw the scroll-bar + * Draw the scrollbar */ virtual void Draw(); /** - * If an object that contains a scrollbar has got messages, send - * them to the scroll-bar and it will see if the message regarded - * itself. + * Setup the scrollbar, setting the size, length and position. * + * @see IGUIScrollBar#Setup() + */ + virtual void Setup(); + virtual void Setup(const CRect& content); + + /** * @see IGUIObject#HandleMessage() */ virtual void HandleMessage(SGUIMessage& Message); @@ -81,14 +86,14 @@ /** * Get the rectangle of the outline of the scrollbar, every component of the - * scroll-bar should be inside this area. + * scrollbar should be inside this area. * @return Rectangle, CRect */ virtual CRect GetOuterRect() const; protected: /** - * Should the scroll bar proceed to the left or to the right of the m_X value. + * Should the scrollbar be drawn on the left or on the right of the m_X value. * Notice, this has nothing to do with where the owner places it. */ bool m_RightAligned; Index: source/gui/CGUIScrollBarVertical.cpp =================================================================== --- source/gui/CGUIScrollBarVertical.cpp +++ source/gui/CGUIScrollBarVertical.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -31,6 +31,26 @@ { } +void CGUIScrollBarVertical::Setup() +{ + CRect host = GetHostGUIObject().GetCachedSize(); + CRect content = GetHostGUIObject().GetContentSize(); + + SetScrollRange(content.GetHeight()); + Setup(host); +} + +void CGUIScrollBarVertical::Setup(const CRect& content) +{ + SetScrollSpace(content.GetHeight()); + + SetX(m_RightAligned ? content.right : content.left); + SetY(content.top); + SetZ(GetHostGUIObject().GetBufferedZ()); + + SetLength(content.bottom - content.top); +} + void CGUIScrollBarVertical::SetPosFromMousePos(const CPos& mouse) { if (!GetStyle()) @@ -39,10 +59,10 @@ /** * Calculate the position for the top of the item being scrolled */ - float emptyBackground = m_Length - m_BarSize; + float emptyBackground = m_Breadth - m_BarSize; if (GetStyle()->m_UseEdgeButtons) - emptyBackground -= GetStyle()->m_Width * 2; + emptyBackground -= GetStyle()->m_Breadth * 2; m_Pos = m_PosWhenPressed + GetMaxPos() * (mouse.y - m_BarPressedAtPos.y) / emptyBackground; } @@ -51,23 +71,23 @@ { if (!GetStyle()) { - LOGWARNING("Attempt to draw scrollbar without a style."); + LOGWARNING("Attempt to draw a vertical scrollbar without a style."); return; } - if (IsVisible()) + if (IsNeeded()) { CRect outline = GetOuterRect(); m_pGUI.DrawSprite( GetStyle()->m_SpriteBackVertical, 0, - m_Z+0.1f, + m_Z + 0.1f, CRect( outline.left, - outline.top + (GetStyle()->m_UseEdgeButtons ? GetStyle()->m_Width : 0), + outline.top + (GetStyle()->m_UseEdgeButtons ? GetStyle()->m_Breadth : 0), outline.right, - outline.bottom - (GetStyle()->m_UseEdgeButtons ? GetStyle()->m_Width : 0) + outline.bottom - (GetStyle()->m_UseEdgeButtons ? GetStyle()->m_Breadth : 0) ) ); @@ -99,22 +119,22 @@ m_pGUI.DrawSprite( *button_top, 0, - m_Z+0.2f, + m_Z + 0.2f, CRect( outline.left, outline.top, outline.right, - outline.top+GetStyle()->m_Width + outline.top + GetStyle()->m_Breadth ) ); m_pGUI.DrawSprite( *button_bottom, 0, - m_Z+0.2f, + m_Z + 0.2f, CRect( outline.left, - outline.bottom-GetStyle()->m_Width, + outline.bottom - GetStyle()->m_Breadth, outline.right, outline.bottom ) @@ -132,6 +152,20 @@ void CGUIScrollBarVertical::HandleMessage(SGUIMessage& Message) { + switch (Message.type) + { + case GUIM_MOUSE_WHEEL_UP: + ScrollMinus(); + break; + + case GUIM_MOUSE_WHEEL_DOWN: + ScrollPlus(); + break; + + default: + break; + } + IGUIScrollBar::HandleMessage(Message); } @@ -147,14 +181,14 @@ if (GetStyle()->m_UseEdgeButtons) { - from += GetStyle()->m_Width; - to -= GetStyle()->m_Width; + from += GetStyle()->m_Breadth; + to -= GetStyle()->m_Breadth; } ret.top = from + (to - from) * m_Pos / GetMaxPos(); ret.bottom = ret.top + m_BarSize; - ret.right = m_X + (m_RightAligned ? 0 : GetStyle()->m_Width); - ret.left = ret.right - GetStyle()->m_Width; + ret.right = m_X + (m_RightAligned ? 0 : GetStyle()->m_Breadth); + ret.left = ret.right - GetStyle()->m_Breadth; return ret; } @@ -166,9 +200,9 @@ return ret; ret.top = m_Y; - ret.bottom = m_Y+m_Length; - ret.right = m_X + (m_RightAligned ? 0 : GetStyle()->m_Width); - ret.left = ret.right - GetStyle()->m_Width; + ret.bottom = m_Y + m_Length; + ret.right = m_X + (m_RightAligned ? 0 : GetStyle()->m_Breadth); + ret.left = ret.right - GetStyle()->m_Breadth; return ret; } @@ -178,12 +212,12 @@ if (!GetStyle()) return false; - float StartX = m_RightAligned ? m_X-GetStyle()->m_Width : m_X; + float StartX = m_RightAligned ? m_X - GetStyle()->m_Breadth : m_X; return mouse.x >= StartX && - mouse.x <= StartX + GetStyle()->m_Width && + mouse.x <= StartX + GetStyle()->m_Breadth && mouse.y >= m_Y && - mouse.y <= m_Y + GetStyle()->m_Width; + mouse.y <= m_Y + GetStyle()->m_Breadth; } bool CGUIScrollBarVertical::HoveringButtonPlus(const CPos& mouse) @@ -191,10 +225,10 @@ if (!GetStyle()) return false; - float StartX = m_RightAligned ? m_X-GetStyle()->m_Width : m_X; + float StartX = m_RightAligned ? m_X - GetStyle()->m_Breadth : m_X; return mouse.x > StartX && - mouse.x < StartX + GetStyle()->m_Width && - mouse.y > m_Y + m_Length - GetStyle()->m_Width && + mouse.x < StartX + GetStyle()->m_Breadth && + mouse.y > m_Y + m_Length - GetStyle()->m_Breadth && mouse.y < m_Y + m_Length; } Index: source/gui/IGUIScrollBar.h =================================================================== --- source/gui/IGUIScrollBar.h +++ source/gui/IGUIScrollBar.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -25,14 +25,15 @@ #define INCLUDED_IGUISCROLLBAR #include "gui/CGUISprite.h" +#include "gui/ObjectBases/IGUIScrollBarOwner.h" -class IGUIScrollBarOwner; +class IGUIObject; struct SGUIMessage; /** - * The GUI Scroll-bar style. Tells us how scroll-bars look and feel. + * The GUI Scrollbar style. Tells us how scrollbars look and feel. * - * A scroll-bar style can choose whether to support horizontal, vertical + * A scrollbar style can choose whether to support horizontal, vertical * or both. * * @see IGUIScrollBar @@ -50,9 +51,11 @@ //@{ /** - * Width of bar, also both sides of the edge buttons. + * Breadth of bar, from side to side. It is the width of a vertical bar + * and the height of a horizontal bar. It is also used as the dimensions + * of both sides of the edge buttons. */ - float m_Width; + float m_Breadth; /** * Scrollable with the wheel. @@ -79,7 +82,7 @@ float m_MinimumBarSize; /** - * Sometimes you would like your scroll bar to have a fixed maximum size + * Sometimes you would like your scrollbar to have a fixed maximum size * so that the texture does not get too stretched, you can set a maximum * in pixels. */ @@ -135,17 +138,17 @@ /** - * The GUI Scroll-bar, used everywhere there is a scroll-bar in the game. + * The GUI Scrollbar, used everywhere there is a scrollbar in the game. * - * To include a scroll-bar to an object, inherent the object from - * IGUIScrollBarOwner and call AddScrollBar() to add the scroll-bars. + * To include a scrollbar to an object, inherent the object from + * IGUIScrollBarOwner and call AddScrollBar() to add the scrollbars. * * It's also important that the scrollbar is located within the parent * object's mouse over area. Otherwise the input won't be sent to the - * scroll-bar. + * scrollbar. * - * The class does not provide all functionality to the scroll-bar, many - * things the parent of the scroll-bar, must provide. Like a combo-box. + * The class does not provide all functionality to the scrollbar, many + * things the parent of the scrollbar, must provide. Like a combo-box. */ class IGUIScrollBar { @@ -157,19 +160,36 @@ public: /** - * Draw the scroll-bar + * Draw the scrollbar */ virtual void Draw() = 0; /** * If an object that contains a scrollbar has got messages, send - * them to the scroll-bar and it will see if the message regarded + * them to the scrollbar and it will see if the message regarded * itself. * * @see IGUIObject#HandleMessage() */ virtual void HandleMessage(SGUIMessage& Message) = 0; + /** + * Setup the scrollbar. Sets the size, length and position. + * An object owning scrollbars still has to call this (preferably + * in the object's own Setup function), it isn't called + * automatically. There are two variations covering several common + * uses. + * + * The first assumes that the content is inside the host and thus + * uses the host's dimensions. + * + * The second permits a CRect defining the dimensions of the + * scrollable content to be passed. Any object that uses this + * variant is required to explicitly set a scroll range. + */ + virtual void Setup() = 0; + virtual void Setup(const CRect& content) = 0; + /** * Set m_Pos with g_mouse_x/y input, i.e. when draggin. */ @@ -209,7 +229,7 @@ /** * Scrollbars without height shouldn't be visible */ - bool IsVisible() const { return GetMaxPos() != 0.f; } + bool IsNeeded() const { return GetMaxPos() != 0.f; } /** * Increase scroll one step @@ -232,16 +252,16 @@ virtual void ScrollMinusPlenty() { m_Pos -= 90.f; UpdatePosBoundaries(); } /** - * Set host object, must be done almost at creation of scroll bar. + * Set host object, must be done almost at creation of the scrollbar. * @param pOwner Pointer to host object. */ void SetHostObject(IGUIScrollBarOwner* pOwner) { m_pHostObject = pOwner; } /** - * Set Width - * @param width Width + * Set the Breadth of the scrollbar + * @param breadth Breadth */ - void SetWidth(float width) { m_Width = width; } + void SetBreadth(float breadth) { m_Breadth = breadth; } /** * Set X Position @@ -262,7 +282,7 @@ void SetZ(float z) { m_Z = z; } /** - * Set Length of scroll bar + * Set the length of the scrollbar * @param length Length */ void SetLength(float length) { m_Length = length; } @@ -286,30 +306,37 @@ void SetBarPressed(bool b) { m_BarPressed = b; } /** - * Set Scroll bar style string - * @param style String with scroll bar style reference name + * Set the scrollbar style + * @param style String consisting of the name of the scrollbar style */ void SetScrollBarStyle(const CStr& style) { m_ScrollBarStyle = style; } /** * Get style used by the scrollbar - * @return Scroll bar style struct. + * @return Scrollbar style struct. */ const SGUIScrollBarStyle* GetStyle() const; /** - * Get the rectangle of the actual BAR. not the whole scroll-bar. + * Get the rectangle of the actual BAR. not the whole scrollbar. * @return Rectangle, CRect */ virtual CRect GetBarRect() const = 0; /** * Get the rectangle of the outline of the scrollbar, every component of the - * scroll-bar should be inside this area. + * scrollbar should be inside this area. * @return Rectangle, CRect */ virtual CRect GetOuterRect() const = 0; + /** + * The difference between this and m_pHostObject is the latter is the ScrollBarOwner class, + * while this retuns the IGUIObject class, and as such has access to the object attributes + * set via JS, along with other attributes. + */ + IGUIObject& GetHostGUIObject() { return m_pHostObject->m_pObject; } + protected: /** * Sets up bar size @@ -329,9 +356,9 @@ //@{ /** - * Width of the scroll bar + * Breadth of the scrollbar */ - float m_Width; + float m_Breadth; /** * Absolute X Position @@ -369,15 +396,10 @@ float m_BarSize; /** - * Scroll bar style reference name + * Scrollbar style reference name */ CStr m_ScrollBarStyle; - /** - * Pointer to scroll bar style used. - */ - SGUIScrollBarStyle* m_pStyle; - /** * Host object, prerequisite! */ @@ -420,7 +442,7 @@ bool m_ButtonMinusPressed, m_ButtonPlusPressed; /** - * Position of scroll bar, 0 means scrolled all the way to one side. + * Position of the scrollbar, 0 means scrolled all the way to one side. * It is measured in pixels, it is up to the host to make it actually * apply in pixels. */ Index: source/gui/IGUIScrollBar.cpp =================================================================== --- source/gui/IGUIScrollBar.cpp +++ source/gui/IGUIScrollBar.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -25,10 +25,9 @@ IGUIScrollBar::IGUIScrollBar(CGUI& pGUI) : m_pGUI(pGUI), - m_pStyle(nullptr), m_X(300.f), m_Y(300.f), m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division. - m_Length(200.f), m_Width(20.f), + m_Length(200.f), m_Breadth(20.f), m_BarSize(0.f), m_Pos(0.f), m_ButtonPlusPressed(false), m_ButtonMinusPressed(false), @@ -54,7 +53,7 @@ // Check for edge buttons if (GetStyle()->m_UseEdgeButtons) - length -= GetStyle()->m_Width * 2.f; + length -= GetStyle()->m_Breadth * 2.f; // Check min and max are valid if (min > length) @@ -167,7 +166,10 @@ case GUIM_MOUSE_WHEEL_UP: { - ScrollMinus(); + // If we're at the limit, pass the message to host object's parent. + if (m_Pos <= 0) + GetHostGUIObject().GetParent()->HandleMessage(Message); + // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); @@ -177,7 +179,10 @@ case GUIM_MOUSE_WHEEL_DOWN: { - ScrollPlus(); + // If we're at the limit, pass the message to host object's parent. + if (m_Pos >= GetMaxPos()) + GetHostGUIObject().GetParent()->HandleMessage(Message); + // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); Index: source/gui/ObjectBases/IGUIObject.h =================================================================== --- source/gui/ObjectBases/IGUIObject.h +++ source/gui/ObjectBases/IGUIObject.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -103,6 +103,12 @@ /// Get object name void SetName(const CStr& Name) { m_Name = Name; } + /// Get object size + const CRect& GetCachedSize() { return m_CachedActualSize; } + + /// Get object content size + const CRect& GetContentSize() { return m_CachedContentSize; } + // Get Presentable name. // Will change all internally set names to something like "" CStr GetPresentableName() const; @@ -306,15 +312,6 @@ */ void LoadStyle(const CStr& StyleName); - /** - * Returns not the Z value, but the actual buffered Z value, i.e. if it's - * defined relative, then it will check its parent's Z value and add - * the relativity. - * - * @return Actual Z value on the screen. - */ - virtual float GetBufferedZ() const; - /** * Set parent of this object */ @@ -330,11 +327,14 @@ */ void SetFocus(); -protected: /** - * Check if object is focused. + * Returns not the Z value, but the actual buffered Z value, i.e. if it's + * defined relative, then it will check its parent's Z value and add + * the relativity. + * + * @return Actual Z value on the screen. */ - bool IsFocused() const; + virtual float GetBufferedZ() const; /** * NOTE! This will not just return m_pParent, when that is @@ -347,6 +347,12 @@ */ IGUIObject* GetParent() const; +protected: + /** + * Check if object is focused. + */ + bool IsFocused() const; + /** * Handle additional children to the \-tag. In IGUIObject, this function does * nothing. In CList and CDropDown, it handles the \, used to build the data. @@ -373,6 +379,12 @@ */ CRect m_CachedActualSize; + /** + * Like m_CachedActualSize above, except this stores a cached + * value of the combined size of all the children. + */ + CRect m_CachedContentSize; + /** * Execute the script for a particular action. * Does nothing if no script has been registered for that action. Index: source/gui/ObjectBases/IGUIScrollBarOwner.h =================================================================== --- source/gui/ObjectBases/IGUIScrollBarOwner.h +++ source/gui/ObjectBases/IGUIScrollBarOwner.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -26,8 +26,8 @@ class IGUIScrollBar; /** - * Base-class this if you want an object to contain - * one, or several, scroll-bars. + * Base class if you want an object to contain + * one, or several, scrollbars. */ class IGUIScrollBarOwner { @@ -57,13 +57,13 @@ virtual const SGUIScrollBarStyle* GetScrollBarStyle(const CStr& style) const; /** - * Add a scroll-bar + * Add a scrollbar */ virtual void AddScrollBar(IGUIScrollBar* scrollbar); /** - * Get Scroll Bar reference (it should be transparent it's actually - * pointers). + * Get a scrollbar reference (it should be transparent it's actually a + * pointer). */ virtual IGUIScrollBar& GetScrollBar(const int& index) { @@ -71,7 +71,7 @@ } /** - * Get the position of the scroll bar at @param index. + * Get the position of the scrollbar at @param index. * Equivalent to GetScrollbar(index).GetPos(). */ virtual float GetScrollBarPos(const int index) const; Index: source/gui/ObjectTypes/CDropDown.cpp =================================================================== --- source/gui/ObjectTypes/CDropDown.cpp +++ source/gui/ObjectTypes/CDropDown.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -105,6 +105,7 @@ Message.value == "dropdown_buffer" || Message.value == "minimum_visible_items" || Message.value == "scrollbar_style" || + Message.value == "scrollbar" || Message.value == "button_width") { SetupListRect(); @@ -132,7 +133,7 @@ { if (mouse.y >= rect.top + m_ItemsYPositions[i] && mouse.y < rect.top + m_ItemsYPositions[i+1] && - // mouse is not over scroll-bar + // Mouse is not over scrollbar. (m_HideScrollBar || mouse.x < GetScrollBar(0).GetOuterRect().left || mouse.x > GetScrollBar(0).GetOuterRect().right)) @@ -166,8 +167,8 @@ break; } - // We can't inherent this routine from CList, because we need to include - // a mouse click to open the dropdown, also the coordinates are changed. + // We can't inheret this routine from CList, because we need to include + // a mouse click to open the dropdown. Also, the coordinates are changed. case GUIM_MOUSE_PRESS_LEFT: { if (!m_Enabled) Index: source/gui/ObjectTypes/CInput.cpp =================================================================== --- source/gui/ObjectTypes/CInput.cpp +++ source/gui/ObjectTypes/CInput.cpp @@ -861,20 +861,14 @@ { case GUIM_SETTINGS_UPDATED: { - // Update scroll-bar - // TODO Gee: (2004-09-01) Is this really updated each time it should? if (m_ScrollBar && (Message.value == "size" || Message.value == "z" || Message.value == "absolute")) { - GetScrollBar(0).SetX(m_CachedActualSize.right); - GetScrollBar(0).SetY(m_CachedActualSize.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); + GetScrollBar(0).Setup(); } - // Update scrollbar if (Message.value == "scrollbar_style") GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); @@ -916,7 +910,7 @@ m_MultiLine && GetScrollBar(0).GetStyle()) { - if (m_pGUI.GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) + if (m_pGUI.GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Breadth) break; } @@ -1073,11 +1067,8 @@ } case GUIM_LOAD: { - GetScrollBar(0).SetX(m_CachedActualSize.right); - GetScrollBar(0).SetY(m_CachedActualSize.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); + GetScrollBar(0).Setup(); UpdateText(); UpdateAutoScroll(); @@ -1134,12 +1125,7 @@ IGUIObject::UpdateCachedSize(); if (m_ScrollBar) - { - GetScrollBar(0).SetX(m_CachedActualSize.right); - GetScrollBar(0).SetY(m_CachedActualSize.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); - } + GetScrollBar(0).Setup(); } void CInput::Draw() @@ -1828,8 +1814,9 @@ if (m_ScrollBar) { - GetScrollBar(0).SetScrollRange(m_CharacterPositions.size() * font.GetLineSpacing() + m_BufferZone * 2.f); - GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight()); + float height = m_CharacterPositions.size() * font.GetLineSpacing() + m_BufferZone * 2.f; + m_CachedContentSize = CRect(0.0f, 0.0f, GetTextAreaWidth(), height); + GetScrollBar(0).Setup(); } } @@ -1965,7 +1952,7 @@ float CInput::GetTextAreaWidth() { if (m_ScrollBar && GetScrollBar(0).GetStyle()) - return m_CachedActualSize.GetWidth() - m_BufferZone * 2.f - GetScrollBar(0).GetStyle()->m_Width; + return m_CachedActualSize.GetWidth() - m_BufferZone * 2.f - GetScrollBar(0).GetStyle()->m_Breadth; return m_CachedActualSize.GetWidth() - m_BufferZone * 2.f; } Index: source/gui/ObjectTypes/CList.h =================================================================== --- source/gui/ObjectTypes/CList.h +++ source/gui/ObjectTypes/CList.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -31,7 +31,7 @@ * text-object for each element, which will be managed * by the IGUITextOwner structure. * - * A scroll-bar will appear when needed. This will be + * A scrollbar will appear when needed. This will be * achieved with the IGUIScrollBarOwner structure. */ class CList : public IGUIObject, public IGUIScrollBarOwner, public IGUITextOwner Index: source/gui/ObjectTypes/CList.cpp =================================================================== --- source/gui/ObjectTypes/CList.cpp +++ source/gui/ObjectTypes/CList.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -81,7 +81,7 @@ SetSetting("hovered", -1, true); SetSetting("auto_scroll", false, true); - // Add scroll-bar + // Add scrollbar CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); bar->SetRightAligned(true); AddScrollBar(bar); @@ -103,9 +103,10 @@ m_GeneratedTexts.clear(); float width = GetListRect().GetWidth(); - // remove scrollbar if applicable + + // Reduce width by the breadth of the scrollbar if applicable. if (m_ScrollBar && GetScrollBar(0).GetStyle()) - width -= GetScrollBar(0).GetStyle()->m_Width; + width -= GetScrollBar(0).GetStyle()->m_Breadth; // Generate texts float buffered_y = 0.f; @@ -130,17 +131,10 @@ m_ItemsYPositions[m_List.m_Items.size()] = buffered_y; - // Setup scrollbar if (m_ScrollBar) { GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); - GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight()); - - CRect rect = GetListRect(); - GetScrollBar(0).SetX(rect.right); - GetScrollBar(0).SetY(rect.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(rect.bottom - rect.top); + GetScrollBar(0).Setup(GetListRect()); } } @@ -160,7 +154,6 @@ { IGUIObject::HandleMessage(Message); IGUIScrollBarOwner::HandleMessage(Message); - //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! m_Modified = false; switch (Message.type) @@ -180,16 +173,11 @@ ScriptEvent(EventNameSelectionChange); } - if (Message.value == "scrollbar") + if (Message.value == "scrollbar" || Message.value == "scrollbar_style") SetupText(); - // Update scrollbar if (Message.value == "scrollbar_style") - { GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); - SetupText(); - } - break; case GUIM_MOUSE_PRESS_LEFT: @@ -239,15 +227,14 @@ } case GUIM_LOAD: - { GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); break; - } default: break; } + // Deliberately placed after the switch...case. IGUITextOwner::HandleMessage(Message); } @@ -361,7 +348,7 @@ m_ItemsYPositions[i] - scroll > rect.GetHeight()) continue; - // Clipping area (we'll have to substract the scrollbar) + // Clipping area (we'll have to subtract the scrollbar) CRect cliparea = GetListRect(); if (m_ScrollBar) @@ -473,7 +460,7 @@ mouse.y += scroll; // Mouse is over scrollbar - if (m_ScrollBar && GetScrollBar(0).IsVisible() && + if (m_ScrollBar && GetScrollBar(0).IsNeeded() && mouse.x >= GetScrollBar(0).GetOuterRect().left && mouse.x <= GetScrollBar(0).GetOuterRect().right) return -1; Index: source/gui/ObjectTypes/COList.h =================================================================== --- source/gui/ObjectTypes/COList.h +++ source/gui/ObjectTypes/COList.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -45,7 +45,7 @@ * * The list can be sorted dynamically by JS code when a * heading is clicked. - * A scroll-bar will appear when needed. + * A scrollbar will appear when needed. */ class COList : public CList { Index: source/gui/ObjectTypes/COList.cpp =================================================================== --- source/gui/ObjectTypes/COList.cpp +++ source/gui/ObjectTypes/COList.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -60,9 +60,10 @@ m_GeneratedTexts.clear(); m_TotalAvailableColumnWidth = GetListRect().GetWidth(); - // remove scrollbar if applicable + + // Reduce width by the breadth of the scrollbar if applicable. if (m_ScrollBar && GetScrollBar(0).GetStyle()) - m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Width; + m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Breadth; m_HeadingHeight = SORT_SPRITE_DIM; // At least the size of the sorting sprite @@ -111,14 +112,8 @@ if (m_ScrollBar) { - CRect rect = GetListRect(); GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); - GetScrollBar(0).SetScrollSpace(rect.GetHeight()); - - GetScrollBar(0).SetX(rect.right); - GetScrollBar(0).SetY(rect.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(rect.bottom - rect.top); + GetScrollBar(0).Setup(GetListRect()); } } Index: source/gui/ObjectTypes/CText.cpp =================================================================== --- source/gui/ObjectTypes/CText.cpp +++ source/gui/ObjectTypes/CText.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -67,7 +67,7 @@ SetSetting("scrollbar", false, true); SetSetting("clip", true, true); - // Add scroll-bar + // Add scrollbar CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); bar->SetRightAligned(true); AddScrollBar(bar); @@ -86,17 +86,17 @@ return; float width = m_CachedActualSize.GetWidth(); - // remove scrollbar if applicable + + // Reduce width by scrollbar breadth if applicable. if (m_ScrollBar && GetScrollBar(0).GetStyle()) - width -= GetScrollBar(0).GetStyle()->m_Width; + width -= GetScrollBar(0).GetStyle()->m_Breadth; m_GeneratedTexts[0] = CGUIText(m_pGUI, m_Caption, m_Font, width, m_BufferZone, this); + m_CachedContentSize = m_GeneratedTexts[0].GetSize(); if (!m_ScrollBar) CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); - - // Setup scrollbar - if (m_ScrollBar) + else { // If we are currently scrolled to the bottom of the text, // then add more lines of text, update the scrollbar so we @@ -106,13 +106,7 @@ if (m_ScrollBottom && GetScrollBar(0).GetPos() > GetScrollBar(0).GetMaxPos() - 1.5f) bottom = true; - GetScrollBar(0).SetScrollRange(m_GeneratedTexts[0].GetSize().cy); - GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight()); - - GetScrollBar(0).SetX(m_CachedActualSize.right); - GetScrollBar(0).SetY(m_CachedActualSize.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); + GetScrollBar(0).Setup(); if (bottom) GetScrollBar(0).SetPos(GetScrollBar(0).GetMaxPos()); @@ -138,55 +132,32 @@ { IGUIObject::HandleMessage(Message); IGUIScrollBarOwner::HandleMessage(Message); - //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! switch (Message.type) { case GUIM_SETTINGS_UPDATED: - if (Message.value == "scrollbar") + if (Message.value == "scrollbar" || Message.value == "scrollbar_style") SetupText(); - // Update scrollbar if (Message.value == "scrollbar_style") - { GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); - SetupText(); - } - break; case GUIM_MOUSE_WHEEL_DOWN: - { - GetScrollBar(0).ScrollPlus(); - // Since the scroll was changed, let's simulate a mouse movement - // to check if scrollbar now is hovered - SGUIMessage msg(GUIM_MOUSE_MOTION); - HandleMessage(msg); - break; - } case GUIM_MOUSE_WHEEL_UP: - { - GetScrollBar(0).ScrollMinus(); - // Since the scroll was changed, let's simulate a mouse movement - // to check if scrollbar now is hovered - SGUIMessage msg(GUIM_MOUSE_MOTION); - HandleMessage(msg); + if (!m_ScrollBar) + m_pParent->HandleMessage(Message); break; - } + case GUIM_LOAD: - { - GetScrollBar(0).SetX(m_CachedActualSize.right); - GetScrollBar(0).SetY(m_CachedActualSize.top); - GetScrollBar(0).SetZ(GetBufferedZ()); - GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); break; - } default: break; } + // Deliberately placed after the switch...case. IGUITextOwner::HandleMessage(Message); }