2
0
Эх сурвалжийг харах

- fixed emsc http leak
- text input with cursor

[email protected] 8 жил өмнө
parent
commit
19f7140683

+ 21 - 1
oxygine/src/InputText.cpp

@@ -2,7 +2,8 @@
 #include "TextField.h"
 #include "utils/stringUtils.h"
 #include "core/oxygine.h"
-
+#include "ColorRectSprite.h"
+#include "res/ResFont.h"
 #ifndef __S3E__
 #include "SDL_keyboard.h"
 #include "SDL_events.h"
@@ -14,7 +15,14 @@ namespace oxygine
 
     InputText::InputText(): _maxLength(0)
     {
+        _cursor = new ColorRectSprite;
+        _cursor->addTween(Actor::TweenAlpha(0), 400, -1, true);
+        _cursor->setVisible(false);
+    }
 
+    void InputText::showCursor(bool show)
+    {
+        _cursor->setVisible(show);
     }
 
     InputText::~InputText()
@@ -40,6 +48,14 @@ namespace oxygine
         _active = this;
 
         _textActor = ta;
+        _cursor->attachTo(_textActor);
+        int fs = _textActor->getFontSize();
+        if (fs == 0)
+            fs = _textActor->getFont()->getSize();
+        float h = fs * 0.9f;
+        _cursor->setSize(h / 10.0f, h);
+        
+        _cursor->setColor(_textActor->getColor() * _textActor->getStyle().color);
 
         core::getDispatcher()->addEventListener(core::EVENT_SYSTEM, CLOSURE(this, &InputText::_onSysEvent));
 
@@ -59,6 +75,7 @@ namespace oxygine
         SDL_StopTextInput();
         core::getDispatcher()->removeEventListeners(this);
 
+        _cursor->detach();
         _active = 0;
         _textActor = 0;
         //log::messageln("InputText::stop  %x", this);
@@ -100,6 +117,9 @@ namespace oxygine
     void InputText::updateText()
     {
         _textActor->setText(_txt);
+        float x = _textActor->getTextRect().getRight();
+        _cursor->setX(x);
+        
 
         Event evnt(EVENT_TEXT_CHANGED);
         dispatchEvent(&evnt);

+ 4 - 0
oxygine/src/InputText.h

@@ -30,6 +30,7 @@ namespace oxygine
         void setDisallowedSymbols(const std::string& utf8str);
         void setDisallowedSymbols(const std::wstring& str);
         void setMaxTextLength(int);
+        void showCursor(bool show);
 
         static void stopAnyInput();
 
@@ -39,6 +40,9 @@ namespace oxygine
         std::string _allowed;
         std::string _disallowed;
         std::string _txt;
+
+        spColorRectSprite _cursor;
+
         int _maxLength;
         void updateText();
         static InputText* _active;

+ 1 - 1
oxygine/src/core/emscripten/HttpRequestEmscriptenTask.cpp

@@ -49,7 +49,7 @@ namespace oxygine
         if (!_postData.empty())
             _postData.push_back(0);
 
-        emscripten_async_wget2_data(_url.c_str(), method, (char*)&_postData.front(), this, false, onload, onerror, onprogress);
+        emscripten_async_wget2_data(_url.c_str(), method, (char*)&_postData.front(), this, true, onload, onerror, onprogress);
     }
     //int  emscripten_async_wget2_data(const char* url, const char* requesttype, const char* param, void *arg, int free, em_async_wget2_data_onload_func onload, em_async_wget2_data_onerror_func onerror, em_async_wget2_data_onprogress_func onprogress);
     //void emscripten_async_wget2_data(const char* url, const char* requesttype, const char* param, void *arg, int free, void (*onload)(void*, void*, unsigned), void (*onerror)(void*, int, const char*), void (*onprogress)(void*, int, int));