Răsfoiți Sursa

Added default tooltip delay to UI, which will be used if the tooltip's own delay is zero. Use seconds for tooltip delay to match eg. the doubleclick interval. Removed layout from the editor's tooltip root element to prevent it resizing in unwanted fashion.

Lasse Öörni 12 ani în urmă
părinte
comite
358d9c2849

+ 0 - 1
Bin/Data/Scripts/Editor/EditorToolBar.as

@@ -134,7 +134,6 @@ UIElement@ CreateToolBarSpacer(uint width)
 UIElement@ CreateToolTip(UIElement@ parent, const String&in title, const IntVector2&in offset)
 {
     ToolTip@ toolTip = parent.CreateChild("ToolTip");
-    toolTip.SetLayout(LM_HORIZONTAL);
     toolTip.position = offset;
 
     BorderImage@ textHolder = toolTip.CreateChild("BorderImage");

+ 2 - 1
Docs/AngelScriptAPI.h

@@ -7338,7 +7338,7 @@ Button okButton;
 Button cancelButton;
 };
 
-class Tooltip
+class ToolTip
 {
 // Methods:
 void SendEvent(const String&, VariantMap& = VariantMap ( ));
@@ -7533,6 +7533,7 @@ String clipBoardText;
 float doubleClickInterval;
 float dragBeginInterval;
 int dragBeginDistance;
+float defaultToolTipDelay;
 int maxFontTextureSize;
 bool nonFocusedMouseWheel;
 bool useSystemClipBoard;

+ 7 - 3
Docs/LuaScriptAPI.dox

@@ -1496,6 +1496,7 @@ Methods:
 
 - unsigned GetNumBones() const
 - Bone* GetRootBone()
+- Bone* GetBone(String& name)
 - Bone* GetBone(unsigned index)
 
 Properties:
@@ -4678,12 +4679,12 @@ Properties:
 - ResourceRef materialAttr
 - Color& colorAttr (readonly)
 
-### Tooltip : UIElement
+### ToolTip : UIElement
 
 Methods:
 
-- Tooltip(Context* context)
-- virtual ~Tooltip()
+- ToolTip(Context* context)
+- virtual ~ToolTip()
 - void SetDelay(float delay)
 - float GetDelay() const
 
@@ -4708,6 +4709,7 @@ Methods:
 - void SetDoubleClickInterval(float interval)
 - void SetDragBeginInterval(float interval)
 - void SetDragBeginDistance(int pixels)
+- void SetDefaultToolTipDelay(float delay)
 - void SetMaxFontTextureSize(int size)
 - void SetNonFocusedMouseWheel(bool nonFocusedMouseWheel)
 - void SetUseSystemClipBoard(bool enable)
@@ -4726,6 +4728,7 @@ Methods:
 - float GetDoubleClickInterval() const
 - float GetDragBeginInterval() const
 - int GetDragBeginDistance() const
+- float GetDefaultToolTipDelay() const
 - int GetMaxFontTextureSize() const
 - bool IsNonFocusedMouseWheel() const
 - bool GetUseSystemClipBoard() const
@@ -4746,6 +4749,7 @@ Properties:
 - float doubleClickInterval
 - float dragBeginInterval
 - int dragBeginDistance
+- float defaultToolTipDelay
 - int maxFontTextureSize
 - bool nonFocusedMouseWheel
 - bool useSystemClipBoard

+ 2 - 1
Docs/ScriptAPI.dox

@@ -6247,7 +6247,7 @@ Properties:
 - Button@ cancelButton (readonly)
 
 
-### Tooltip
+### ToolTip
 
 Methods:
 
@@ -6410,6 +6410,7 @@ Properties:
 - float doubleClickInterval
 - float dragBeginInterval
 - int dragBeginDistance
+- float defaultToolTipDelay
 - int maxFontTextureSize
 - bool nonFocusedMouseWheel
 - bool useSystemClipBoard

+ 3 - 0
Source/Engine/LuaScript/pkgs/UI/UI.pkg

@@ -17,6 +17,7 @@ class UI : public Object
     void SetDoubleClickInterval(float interval);
     void SetDragBeginInterval(float interval);
     void SetDragBeginDistance(int pixels);
+    void SetDefaultToolTipDelay(float delay);
     void SetMaxFontTextureSize(int size);
     void SetNonFocusedMouseWheel(bool nonFocusedMouseWheel);
     void SetUseSystemClipBoard(bool enable);
@@ -37,6 +38,7 @@ class UI : public Object
     float GetDoubleClickInterval() const;
     float GetDragBeginInterval() const;
     int GetDragBeginDistance() const;
+    float GetDefaultToolTipDelay() const;
     int GetMaxFontTextureSize() const;
     bool IsNonFocusedMouseWheel() const;
     bool GetUseSystemClipBoard() const;
@@ -56,6 +58,7 @@ class UI : public Object
     tolua_property__get_set float doubleClickInterval;
     tolua_property__get_set float dragBeginInterval;
     tolua_property__get_set int dragBeginDistance;
+    tolua_property__get_set float defaultToolTipDelay;
     tolua_property__get_set int maxFontTextureSize;
     tolua_property__is_set bool nonFocusedMouseWheel;
     tolua_property__get_set bool useSystemClipBoard;

+ 2 - 0
Source/Engine/Script/UIAPI.cpp

@@ -616,6 +616,8 @@ static void RegisterUI(asIScriptEngine* engine)
     engine->RegisterObjectMethod("UI", "float get_dragBeginInterval() const", asMETHOD(UI, GetDragBeginInterval), asCALL_THISCALL);
     engine->RegisterObjectMethod("UI", "void set_dragBeginDistance(int)", asMETHOD(UI, SetDragBeginDistance), asCALL_THISCALL);
     engine->RegisterObjectMethod("UI", "int get_dragBeginDistance() const", asMETHOD(UI, GetDragBeginDistance), asCALL_THISCALL);
+    engine->RegisterObjectMethod("UI", "void set_defaultToolTipDelay(float)", asMETHOD(UI, SetDefaultToolTipDelay), asCALL_THISCALL);
+    engine->RegisterObjectMethod("UI", "float get_defaultToolTipDelay() const", asMETHOD(UI, GetDefaultToolTipDelay), asCALL_THISCALL);
     engine->RegisterObjectMethod("UI", "void set_maxFontTextureSize(int)", asMETHOD(UI, SetMaxFontTextureSize), asCALL_THISCALL);
     engine->RegisterObjectMethod("UI", "int get_maxFontTextureSize() const", asMETHOD(UI, GetMaxFontTextureSize), asCALL_THISCALL);
     engine->RegisterObjectMethod("UI", "void set_nonFocusedMouseWheel(bool)", asMETHOD(UI, SetNonFocusedMouseWheel), asCALL_THISCALL);

+ 6 - 3
Source/Engine/UI/ToolTip.cpp

@@ -24,6 +24,7 @@
 #include "ToolTip.h"
 #include "Context.h"
 #include "Timer.h"
+#include "UI.h"
 
 namespace Urho3D
 {
@@ -32,7 +33,7 @@ extern const char* UI_CATEGORY;
 
 ToolTip::ToolTip(Context* context) :
     UIElement(context),
-    delay_(500.f),
+    delay_(0.0f),
     parentHovered_(false)
 {
     SetVisible(false);
@@ -47,7 +48,7 @@ void ToolTip::RegisterObject(Context* context)
     context->RegisterFactory<ToolTip>(UI_CATEGORY);
 
     COPY_BASE_ATTRIBUTES(ToolTip, UIElement);
-    ACCESSOR_ATTRIBUTE(ToolTip, VAR_FLOAT, "Delay", GetDelay, SetDelay, float, 0.5f, AM_FILE);
+    ACCESSOR_ATTRIBUTE(ToolTip, VAR_FLOAT, "Delay", GetDelay, SetDelay, float, 0.0f, AM_FILE);
 }
 
 void ToolTip::Update(float timeStep)
@@ -69,12 +70,14 @@ void ToolTip::Update(float timeStep)
 
     if (target_->IsHovering())
     {
+        float effectiveDelay = delay_ > 0.0f ? delay_ : GetSubsystem<UI>()->GetDefaultToolTipDelay();
+        
         if (!parentHovered_)
         {
             parentHovered_ = true;
             displayAt_.Reset();
         }
-        else if(displayAt_.GetMSec(false) >= delay_ && parent_ == target_)
+        else if(displayAt_.GetMSec(false) >= (unsigned)(effectiveDelay * 1000.0f) && parent_ == target_)
         {
             originalPosition_ = GetPosition();
             IntVector2 screenPosition = GetScreenPosition();

+ 2 - 2
Source/Engine/UI/ToolTip.h

@@ -44,10 +44,10 @@ public:
     /// Perform UI element update.
     virtual void Update(float timeStep);
 
-    /// Set the delay (milliseconds) until the tooltip shows once hovering.
+    /// Set the delay in seconds until the tooltip shows once hovering. Set zero to use the default from the UI subsystem.
     void SetDelay(float delay);
 
-    /// Return the delay until the tooltip shows once hovering.
+    /// Return the delay in seconds until the tooltip shows once hovering.
     float GetDelay() const { return delay_; }
 
 private:

+ 7 - 0
Source/Engine/UI/UI.cpp

@@ -69,6 +69,7 @@ const ShortStringHash VAR_PARENT_CHANGED("ParentChanged");
 
 const float DEFAULT_DOUBLECLICK_INTERVAL = 0.5f;
 const float DEFAULT_DRAGBEGIN_INTERVAL = 0.5f;
+const float DEFAULT_TOOLTIP_DELAY = 0.5f;
 const int DEFAULT_DRAGBEGIN_DISTANCE = 5;
 const int DEFAULT_FONT_TEXTURE_MAX_SIZE = 2048;
 
@@ -85,6 +86,7 @@ UI::UI(Context* context) :
     doubleClickInterval_(DEFAULT_DOUBLECLICK_INTERVAL),
     dragBeginInterval_(DEFAULT_DRAGBEGIN_INTERVAL),
     dragBeginDistance_(DEFAULT_DRAGBEGIN_DISTANCE),
+    defaultToolTipDelay_(DEFAULT_TOOLTIP_DELAY),
     initialized_(false),
     usingTouchInput_(false),
     #ifdef WIN32
@@ -463,6 +465,11 @@ void UI::SetDragBeginDistance(int pixels)
     dragBeginDistance_ = Max(pixels, 0);
 }
 
+void UI::SetDefaultToolTipDelay(float delay)
+{
+    defaultToolTipDelay_ = Max(delay, 0.0f);
+}
+
 void UI::SetMaxFontTextureSize(int size)
 {
     if (IsPowerOfTwo(size) && size >= FONT_TEXTURE_MIN_SIZE)

+ 6 - 0
Source/Engine/UI/UI.h

@@ -83,6 +83,8 @@ public:
     void SetDragBeginInterval(float interval);
     /// Set UI drag event start distance threshold in pixels.
     void SetDragBeginDistance(int pixels);
+    /// Set tooltip default display delay in seconds.
+    void SetDefaultToolTipDelay(float delay);
     /// Set maximum font face texture size. Must be a power of two. Default is 2048.
     void SetMaxFontTextureSize(int size);
     /// Set whether mouse wheel can control also a non-focused element.
@@ -120,6 +122,8 @@ public:
     float GetDragBeginInterval() const { return dragBeginInterval_; }
     /// Return UI drag start event distance threshold in pixels.
     int GetDragBeginDistance() const { return dragBeginDistance_; }
+    /// Return tooltip default display delay in seconds.
+    float GetDefaultToolTipDelay() const { return defaultToolTipDelay_; }
     /// Return font texture maximum size.
     int GetMaxFontTextureSize() const { return maxFontTextureSize_; }
     /// Return whether mouse wheel can control also a non-focused element.
@@ -237,6 +241,8 @@ private:
     float doubleClickInterval_;
     /// Seconds from mouse button down to begin a drag if there has been no movement exceeding pixel threshold.
     float dragBeginInterval_;
+    /// Tooltip default display delay in seconds.
+    float defaultToolTipDelay_;
     /// Drag begin event distance threshold in pixels.
     int dragBeginDistance_;
     /// Mouse buttons held down.