Browse Source

LineEdit: use signed type

1vanK 3 years ago
parent
commit
2fce5c3d84

+ 12 - 12
Source/Urho3D/AngelScript/Generated_Members.h

@@ -22259,17 +22259,17 @@ template <class T> void RegisterMembers_LineEdit(asIScriptEngine* engine, const
     engine->RegisterObjectMethod(className, "float GetCursorBlinkRate() const", AS_METHODPR(T, GetCursorBlinkRate, () const, float), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "float GetCursorBlinkRate() const", AS_METHODPR(T, GetCursorBlinkRate, () const, float), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "float get_cursorBlinkRate() const", AS_METHODPR(T, GetCursorBlinkRate, () const, float), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "float get_cursorBlinkRate() const", AS_METHODPR(T, GetCursorBlinkRate, () const, float), AS_CALL_THISCALL);
 
 
-    // unsigned LineEdit::GetCursorPosition() const
-    engine->RegisterObjectMethod(className, "uint GetCursorPosition() const", AS_METHODPR(T, GetCursorPosition, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_cursorPosition() const", AS_METHODPR(T, GetCursorPosition, () const, unsigned), AS_CALL_THISCALL);
+    // i32 LineEdit::GetCursorPosition() const
+    engine->RegisterObjectMethod(className, "int GetCursorPosition() const", AS_METHODPR(T, GetCursorPosition, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_cursorPosition() const", AS_METHODPR(T, GetCursorPosition, () const, i32), AS_CALL_THISCALL);
 
 
     // c32 LineEdit::GetEchoCharacter() const
     // c32 LineEdit::GetEchoCharacter() const
     engine->RegisterObjectMethod(className, "c32 GetEchoCharacter() const", AS_METHODPR(T, GetEchoCharacter, () const, c32), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "c32 GetEchoCharacter() const", AS_METHODPR(T, GetEchoCharacter, () const, c32), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "c32 get_echoCharacter() const", AS_METHODPR(T, GetEchoCharacter, () const, c32), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "c32 get_echoCharacter() const", AS_METHODPR(T, GetEchoCharacter, () const, c32), AS_CALL_THISCALL);
 
 
-    // unsigned LineEdit::GetMaxLength() const
-    engine->RegisterObjectMethod(className, "uint GetMaxLength() const", AS_METHODPR(T, GetMaxLength, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_maxLength() const", AS_METHODPR(T, GetMaxLength, () const, unsigned), AS_CALL_THISCALL);
+    // i32 LineEdit::GetMaxLength() const
+    engine->RegisterObjectMethod(className, "int GetMaxLength() const", AS_METHODPR(T, GetMaxLength, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_maxLength() const", AS_METHODPR(T, GetMaxLength, () const, i32), AS_CALL_THISCALL);
 
 
     // const String& LineEdit::GetText() const
     // const String& LineEdit::GetText() const
     engine->RegisterObjectMethod(className, "const String& GetText() const", AS_METHODPR(T, GetText, () const, const String&), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "const String& GetText() const", AS_METHODPR(T, GetText, () const, const String&), AS_CALL_THISCALL);
@@ -22299,17 +22299,17 @@ template <class T> void RegisterMembers_LineEdit(asIScriptEngine* engine, const
     engine->RegisterObjectMethod(className, "void SetCursorMovable(bool)", AS_METHODPR(T, SetCursorMovable, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetCursorMovable(bool)", AS_METHODPR(T, SetCursorMovable, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_cursorMovable(bool)", AS_METHODPR(T, SetCursorMovable, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_cursorMovable(bool)", AS_METHODPR(T, SetCursorMovable, (bool), void), AS_CALL_THISCALL);
 
 
-    // void LineEdit::SetCursorPosition(unsigned position)
-    engine->RegisterObjectMethod(className, "void SetCursorPosition(uint)", AS_METHODPR(T, SetCursorPosition, (unsigned), void), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_cursorPosition(uint)", AS_METHODPR(T, SetCursorPosition, (unsigned), void), AS_CALL_THISCALL);
+    // void LineEdit::SetCursorPosition(i32 position)
+    engine->RegisterObjectMethod(className, "void SetCursorPosition(int)", AS_METHODPR(T, SetCursorPosition, (i32), void), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_cursorPosition(int)", AS_METHODPR(T, SetCursorPosition, (i32), void), AS_CALL_THISCALL);
 
 
     // void LineEdit::SetEchoCharacter(c32 c)
     // void LineEdit::SetEchoCharacter(c32 c)
     engine->RegisterObjectMethod(className, "void SetEchoCharacter(c32)", AS_METHODPR(T, SetEchoCharacter, (c32), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetEchoCharacter(c32)", AS_METHODPR(T, SetEchoCharacter, (c32), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_echoCharacter(c32)", AS_METHODPR(T, SetEchoCharacter, (c32), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_echoCharacter(c32)", AS_METHODPR(T, SetEchoCharacter, (c32), void), AS_CALL_THISCALL);
 
 
-    // void LineEdit::SetMaxLength(unsigned length)
-    engine->RegisterObjectMethod(className, "void SetMaxLength(uint)", AS_METHODPR(T, SetMaxLength, (unsigned), void), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_maxLength(uint)", AS_METHODPR(T, SetMaxLength, (unsigned), void), AS_CALL_THISCALL);
+    // void LineEdit::SetMaxLength(i32 length)
+    engine->RegisterObjectMethod(className, "void SetMaxLength(int)", AS_METHODPR(T, SetMaxLength, (i32), void), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_maxLength(int)", AS_METHODPR(T, SetMaxLength, (i32), void), AS_CALL_THISCALL);
 
 
     // void LineEdit::SetText(const String& text)
     // void LineEdit::SetText(const String& text)
     engine->RegisterObjectMethod(className, "void SetText(const String&in)", AS_METHODPR(T, SetText, (const String&), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetText(const String&in)", AS_METHODPR(T, SetText, (const String&), void), AS_CALL_THISCALL);

+ 24 - 21
Source/Urho3D/UI/LineEdit.cpp

@@ -26,7 +26,7 @@ LineEdit::LineEdit(Context* context) :
     lastFont_(nullptr),
     lastFont_(nullptr),
     lastFontSize_(0),
     lastFontSize_(0),
     cursorPosition_(0),
     cursorPosition_(0),
-    dragBeginCursor_(M_MAX_UNSIGNED),
+    dragBeginCursor_(NINDEX),
     cursorBlinkRate_(1.0f),
     cursorBlinkRate_(1.0f),
     cursorBlinkTimer_(0.0f),
     cursorBlinkTimer_(0.0f),
     maxLength_(0),
     maxLength_(0),
@@ -101,8 +101,8 @@ void LineEdit::OnClickBegin(const IntVector2& position, const IntVector2& screen
 {
 {
     if (button == MOUSEB_LEFT && cursorMovable_)
     if (button == MOUSEB_LEFT && cursorMovable_)
     {
     {
-        unsigned pos = GetCharIndex(position);
-        if (pos != M_MAX_UNSIGNED)
+        i32 pos = GetCharIndex(position);
+        if (pos != NINDEX)
         {
         {
             SetCursorPosition(pos);
             SetCursorPosition(pos);
             text_->ClearSelection();
             text_->ClearSelection();
@@ -130,9 +130,9 @@ void LineEdit::OnDragMove(const IntVector2& position, const IntVector2& screenPo
 {
 {
     if (cursorMovable_ && textSelectable_)
     if (cursorMovable_ && textSelectable_)
     {
     {
-        unsigned start = dragBeginCursor_;
-        unsigned current = GetCharIndex(position);
-        if (start != M_MAX_UNSIGNED && current != M_MAX_UNSIGNED)
+        i32 start = dragBeginCursor_;
+        i32 current = GetCharIndex(position);
+        if (start != NINDEX && current != NINDEX)
         {
         {
             if (start < current)
             if (start < current)
                 text_->SetSelection(start, current - start);
                 text_->SetSelection(start, current - start);
@@ -263,8 +263,8 @@ void LineEdit::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
 
 
             if (textSelectable_ && qualifiers & QUAL_SHIFT)
             if (textSelectable_ && qualifiers & QUAL_SHIFT)
             {
             {
-                unsigned start = dragBeginCursor_;
-                unsigned current = cursorPosition_;
+                i32 start = dragBeginCursor_;
+                i32 current = cursorPosition_;
                 if (start < current)
                 if (start < current)
                     text_->SetSelection(start, current - start);
                     text_->SetSelection(start, current - start);
                 else
                 else
@@ -295,8 +295,8 @@ void LineEdit::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
 
 
             if (textSelectable_ && qualifiers & QUAL_SHIFT)
             if (textSelectable_ && qualifiers & QUAL_SHIFT)
             {
             {
-                unsigned start = dragBeginCursor_;
-                unsigned current = cursorPosition_;
+                i32 start = dragBeginCursor_;
+                i32 current = cursorPosition_;
                 if (start < current)
                 if (start < current)
                     text_->SetSelection(start, current - start);
                     text_->SetSelection(start, current - start);
                 else
                 else
@@ -469,8 +469,10 @@ void LineEdit::SetText(const String& text)
     }
     }
 }
 }
 
 
-void LineEdit::SetCursorPosition(unsigned position)
+void LineEdit::SetCursorPosition(i32 position)
 {
 {
+    assert(position >= 0);
+
     if (position > line_.LengthUTF8() || !cursorMovable_)
     if (position > line_.LengthUTF8() || !cursorMovable_)
         position = line_.LengthUTF8();
         position = line_.LengthUTF8();
 
 
@@ -489,8 +491,9 @@ void LineEdit::SetCursorBlinkRate(float rate)
         cursorBlinkTimer_ = 0.0f;   // Cursor does not blink, i.e. always visible
         cursorBlinkTimer_ = 0.0f;   // Cursor does not blink, i.e. always visible
 }
 }
 
 
-void LineEdit::SetMaxLength(unsigned length)
+void LineEdit::SetMaxLength(i32 length)
 {
 {
+    assert(length >= 0);
     maxLength_ = length;
     maxLength_ = length;
 }
 }
 
 
@@ -582,7 +585,7 @@ void LineEdit::UpdateText()
 
 
 void LineEdit::UpdateCursor()
 void LineEdit::UpdateCursor()
 {
 {
-    int x = text_->GetCharPosition(cursorPosition_).x_;
+    i32 x = text_->GetCharPosition(cursorPosition_).x_;
 
 
     text_->SetPosition(GetIndentWidth() + clipBorder_.left_, clipBorder_.top_);
     text_->SetPosition(GetIndentWidth() + clipBorder_.left_, clipBorder_.top_);
     cursor_->SetPosition(text_->GetPosition() + IntVector2(x, 0));
     cursor_->SetPosition(text_->GetPosition() + IntVector2(x, 0));
@@ -593,9 +596,9 @@ void LineEdit::UpdateCursor()
     SDL_SetTextInputRect(&rect);
     SDL_SetTextInputRect(&rect);
 
 
     // Scroll if necessary
     // Scroll if necessary
-    int sx = -GetChildOffset().x_;
-    int left = clipBorder_.left_;
-    int right = GetWidth() - clipBorder_.left_ - clipBorder_.right_ - cursor_->GetWidth();
+    i32 sx = -GetChildOffset().x_;
+    i32 left = clipBorder_.left_;
+    i32 right = GetWidth() - clipBorder_.left_ - clipBorder_.right_ - cursor_->GetWidth();
     if (x - sx > right)
     if (x - sx > right)
         sx = x - right;
         sx = x - right;
     if (x - sx < left)
     if (x - sx < left)
@@ -608,7 +611,7 @@ void LineEdit::UpdateCursor()
     cursorBlinkTimer_ = 0.0f;
     cursorBlinkTimer_ = 0.0f;
 }
 }
 
 
-unsigned LineEdit::GetCharIndex(const IntVector2& position)
+i32 LineEdit::GetCharIndex(const IntVector2& position)
 {
 {
     IntVector2 screenPosition = ElementToScreen(position);
     IntVector2 screenPosition = ElementToScreen(position);
     IntVector2 textPosition = text_->ScreenToElement(screenPosition);
     IntVector2 textPosition = text_->ScreenToElement(screenPosition);
@@ -616,13 +619,13 @@ unsigned LineEdit::GetCharIndex(const IntVector2& position)
     if (textPosition.x_ < 0)
     if (textPosition.x_ < 0)
         return 0;
         return 0;
 
 
-    for (int i = text_->GetNumChars(); i >= 0; --i)
+    for (i32 i = text_->GetNumChars(); i >= 0; --i)
     {
     {
-        if (textPosition.x_ >= text_->GetCharPosition((unsigned)i).x_)
-            return (unsigned)i;
+        if (textPosition.x_ >= text_->GetCharPosition(i).x_)
+            return i;
     }
     }
 
 
-    return M_MAX_UNSIGNED;
+    return NINDEX;
 }
 }
 
 
 void LineEdit::HandleFocused(StringHash /*eventType*/, VariantMap& eventData)
 void LineEdit::HandleFocused(StringHash /*eventType*/, VariantMap& eventData)

+ 9 - 9
Source/Urho3D/UI/LineEdit.h

@@ -56,13 +56,13 @@ public:
     void SetText(const String& text);
     void SetText(const String& text);
     /// Set cursor position.
     /// Set cursor position.
     /// @property
     /// @property
-    void SetCursorPosition(unsigned position);
+    void SetCursorPosition(i32 position);
     /// Set cursor blink rate. 0 disables blinking.
     /// Set cursor blink rate. 0 disables blinking.
     /// @property
     /// @property
     void SetCursorBlinkRate(float rate);
     void SetCursorBlinkRate(float rate);
     /// Set maximum text length. 0 for unlimited.
     /// Set maximum text length. 0 for unlimited.
     /// @property
     /// @property
-    void SetMaxLength(unsigned length);
+    void SetMaxLength(i32 length);
     /// Set echo character for password entry and such. 0 (default) shows the actual text.
     /// Set echo character for password entry and such. 0 (default) shows the actual text.
     /// @property
     /// @property
     void SetEchoCharacter(c32 c);
     void SetEchoCharacter(c32 c);
@@ -82,7 +82,7 @@ public:
 
 
     /// Return cursor position.
     /// Return cursor position.
     /// @property
     /// @property
-    unsigned GetCursorPosition() const { return cursorPosition_; }
+    i32 GetCursorPosition() const { return cursorPosition_; }
 
 
     /// Return cursor blink rate.
     /// Return cursor blink rate.
     /// @property
     /// @property
@@ -90,7 +90,7 @@ public:
 
 
     /// Return maximum text length.
     /// Return maximum text length.
     /// @property
     /// @property
-    unsigned GetMaxLength() const { return maxLength_; }
+    i32 GetMaxLength() const { return maxLength_; }
 
 
     /// Return echo character.
     /// Return echo character.
     /// @property
     /// @property
@@ -123,8 +123,8 @@ protected:
     void UpdateText();
     void UpdateText();
     /// Update cursor position and restart cursor blinking.
     /// Update cursor position and restart cursor blinking.
     void UpdateCursor();
     void UpdateCursor();
-    /// Return char index corresponding to position within element, or M_MAX_UNSIGNED if not found.
-    unsigned GetCharIndex(const IntVector2& position);
+    /// Return char index corresponding to position within element, or NINDEX if not found.
+    i32 GetCharIndex(const IntVector2& position);
 
 
     /// Text element.
     /// Text element.
     SharedPtr<Text> text_;
     SharedPtr<Text> text_;
@@ -137,15 +137,15 @@ protected:
     /// Last used text size.
     /// Last used text size.
     int lastFontSize_;
     int lastFontSize_;
     /// Text edit cursor position.
     /// Text edit cursor position.
-    unsigned cursorPosition_;
+    i32 cursorPosition_;
     /// Drag begin cursor position.
     /// Drag begin cursor position.
-    unsigned dragBeginCursor_;
+    i32 dragBeginCursor_;
     /// Cursor blink rate.
     /// Cursor blink rate.
     float cursorBlinkRate_;
     float cursorBlinkRate_;
     /// Cursor blink timer.
     /// Cursor blink timer.
     float cursorBlinkTimer_;
     float cursorBlinkTimer_;
     /// Maximum text length.
     /// Maximum text length.
-    unsigned maxLength_;
+    i32 maxLength_;
     /// Echo character.
     /// Echo character.
     c32 echoCharacter_;
     c32 echoCharacter_;
     /// Cursor movable flag.
     /// Cursor movable flag.