]> git.vomp.tv Git - vompclient.git/commitdiff
WTextBox CWFs
authorChris Tallon <chris@vomp.tv>
Thu, 7 May 2020 15:57:16 +0000 (16:57 +0100)
committerChris Tallon <chris@vomp.tv>
Thu, 7 May 2020 15:57:16 +0000 (16:57 +0100)
wtextbox.cc
wtextbox.h

index 6a9e9e03fc47b91e4184d8f4a97b56c39a9e66c3..33464b1c53b898c72acbad860d97169762ea7cb3 100644 (file)
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with VOMP; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+    along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-#include "wtextbox.h"
-
 #include "colour.h"
 #include "input.h"
 
-WTextbox::WTextbox(const char* ttext):
+#include "wtextbox.h"
+
+WTextbox::WTextbox(const char* takeText):
 foreColour(DrawStyle::LIGHTTEXT)
 {
 //  int fontHeight = Surface::getFontHeight();
   //setDimensions(70, fontHeight);
   //setDimensions(100,100);
   setSize(100, 100);
-  text = NULL;
 
   textX = 5;
   textY = 2;
   
   paraMode = true;
   
-  if (ttext) setText(ttext);
-
-  cur_scroll_line=0;
-  rem_scroll_line=0;
-}
-
-WTextbox::~WTextbox()
-{
-  if (text) delete[] text;
+  if (takeText) setText(takeText);
 }
 
 void WTextbox::setParaMode(bool mode)
@@ -55,10 +45,7 @@ void WTextbox::setParaMode(bool mode)
 
 void WTextbox::setText(const char* takeText)
 {
-  if (text) delete[] text;
-  int length = strlen(takeText);
-  text = new char[length + 1];
-  strcpy(text, takeText);
+  text = takeText;
 }
 
 void WTextbox::setForegroundColour(const DrawStyle& fcolour)
@@ -69,10 +56,10 @@ void WTextbox::setForegroundColour(const DrawStyle& fcolour)
 void WTextbox::draw()
 {
   Boxx::draw();
-  if (text)
+  if (text.length())
   {
-    if (paraMode) rem_scroll_line=drawPara(text, textX, textY, foreColour,cur_scroll_line);
-    else          drawText(text, textX, textY, foreColour);
+    if (paraMode) rem_scroll_line = drawPara(text.c_str(), textX, textY, foreColour, cur_scroll_line);
+    else          drawText(text.c_str(), textX, textY, foreColour);
   }
 }
 
@@ -90,55 +77,60 @@ int WTextbox::handleCommand(int command)
     {
       if (cur_scroll_line > 0)
       {
-         cur_scroll_line--;
-         rem_scroll_line++;
-         return 1;
+        --cur_scroll_line;
+        --rem_scroll_line;
+        return 1;
       }
       else
       {
-         return 4; // Signal return control to parent
+        return 4; // Signal return control to parent
       }
     }
     case Input::DOWN:
     {
-       if (rem_scroll_line > 0)
-       {
-               cur_scroll_line++;
-               rem_scroll_line--;
-               return 1;
-       } else {
-               return 4;
-       }
+      if (rem_scroll_line > 0)
+      {
+        ++cur_scroll_line;
+        --rem_scroll_line;
+        return 1;
+      }
+      else
+      {
+        return 4;
+      }
     }
     case Input::LEFT:
     case Input::RIGHT:
     {
-       return 5;
+      return 5;
     }
-
   }
 
   return 0;
 }
 
-bool WTextbox::mouseAndroidScroll(int x, int y, int sx, int sy)
+bool WTextbox::mouseAndroidScroll(int x, int y, int /* sx */, int sy)
 {
-       if ((x - getRootBoxOffsetX()) >= 0 && (y - getRootBoxOffsetY()) >= 0
-               && (x - getRootBoxOffsetX()) <= (int)area.w && (y - getRootBoxOffsetY()) <= (int)area.h )
-       {
-               int change = -sy /120;
-               if (change < 0) {
-                       int rel_change = min(cur_scroll_line, -change);
-                       cur_scroll_line-=rel_change;
-                       rem_scroll_line+=rel_change;
-               }
-               else if (change > 0) {
-                       int rel_change = min(rem_scroll_line, change);
-                       cur_scroll_line += rel_change;
-                       rem_scroll_line -= rel_change;
-               }
-               return true;
-       }
-       return false;
-
+  if (    (x - getRootBoxOffsetX()) >= 0
+       && (y - getRootBoxOffsetY()) >= 0
+       && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
+       && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
+     )
+  {
+    int change = -sy /120;
+    if (change < 0)
+    {
+      int rel_change = min(cur_scroll_line, -change);
+      cur_scroll_line-=rel_change;
+      rem_scroll_line+=rel_change;
+    }
+    else if (change > 0)
+    {
+      int rel_change = min(rem_scroll_line, change);
+      cur_scroll_line += rel_change;
+      rem_scroll_line -= rel_change;
+    }
+    return true;
+  }
+  return false;
 }
index 1f82c97f75117bc2846329fa02e81fa18a697aeb..c9b256dcda1f1223890a534dc4b9b2f1662c149f 100644 (file)
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with VOMP; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+    along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
 */
 
 #ifndef WTEXTBOX_H
 #define WTEXTBOX_H
 
-#include <stdio.h>
-#include <string.h>
+#include <string>
 
 #include "defines.h"
 #include "boxx.h"
@@ -33,7 +31,6 @@ class WTextbox : public Boxx
 {
   public:
     WTextbox(const char* ttext = NULL);
-    virtual ~WTextbox();
     void setText(const char* text);
     void draw();
     void setForegroundColour(const DrawStyle& fcolour);
@@ -42,17 +39,16 @@ class WTextbox : public Boxx
 
     // if added as a pane
     int handleCommand(int command);
-       bool mouseAndroidScroll(int x, int y, int sx, int sy);
+    bool mouseAndroidScroll(int x, int y, int sx, int sy);
 
   private:
-
-    char* text;
+    std::string text;
     DrawStyle foreColour;
     int textX;
     int textY;
     bool paraMode;
-    unsigned int cur_scroll_line;
-    unsigned int rem_scroll_line;
+    unsigned int cur_scroll_line{};
+    unsigned int rem_scroll_line{};
 };
 
 #endif