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

index eed4a379c9bac4e95562419c28513049295f0337..588fb5a94e21f2ce66dd02cf6572f082a5c8af65 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright 2004-2005 Chris Tallon
+    Copyright 2004-2020 Chris Tallon
 
     This file is part of VOMP.
 
     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 "wbutton.h"
-
 #include "colour.h"
 
+#include "wbutton.h"
+
 WButton::WButton()
 {
-
   setSize(70, 21/*fontHeight*/);
-
-  mytext = NULL;
-  active = 0;
-  tag = 0;
-  dimmed = false;
-}
-
-WButton::~WButton()
-{
-  if (mytext) delete[] mytext;
 }
 
 void WButton::setText(const char* takeText)
 {
-  int length = strlen(takeText);
-  mytext = new char[length + 1];
-  strcpy(mytext, takeText);
+  mytext = takeText;
 }
 
 void WButton::setActive(UCHAR tactive)
@@ -63,17 +49,17 @@ void WButton::draw()
   if (dimmed)
   {
     fillColour(DrawStyle::BLACK);
-    drawTextCentre(mytext, area.w / 2, 0, DrawStyle::SELECTHIGHLIGHT);
+    drawTextCentre(mytext.c_str(), area.w / 2, 0, DrawStyle::SELECTHIGHLIGHT);
   }
   else if (active)
   {
     fillColour(DrawStyle::SELECTHIGHLIGHT);
-    drawTextCentre(mytext, area.w / 2, 0, DrawStyle::DARKTEXT);
+    drawTextCentre(mytext.c_str(), area.w / 2, 0, DrawStyle::DARKTEXT);
   }
   else
   {
     fillColour(DrawStyle::BUTTONBACKGROUND);
-    drawTextCentre(mytext, area.w / 2, 0, DrawStyle::LIGHTTEXT);
+    drawTextCentre(mytext.c_str(), area.w / 2, 0, DrawStyle::LIGHTTEXT);
   }
 }
 
@@ -87,12 +73,16 @@ int WButton::getTag()
   return tag;
 }
 
-// Sorry, I've broken these in the boxx upgrade - chris
+// Sorry, I've broken these in the boxx upgrade - chris // FIXME so fix it
 
 bool WButton::mouseMove(int x, int y)
 {
-  if ((x-getRootBoxOffsetX())>=0 && (y-getRootBoxOffsetY())>=0
-    && (x-getRootBoxOffsetX())<=(int)area.w && (y-getRootBoxOffsetY())<=(int)area.h && !active)
+  if (    (x - getRootBoxOffsetX()) >= 0
+       && (y - getRootBoxOffsetY()) >= 0
+       && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
+       && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
+       && !active
+     )
   {
     setActive(1);
     return true;
@@ -102,8 +92,12 @@ bool WButton::mouseMove(int x, int y)
 
 bool WButton::mouseLBDOWN(int x, int y)
 {
-  if ((x-getRootBoxOffsetX())>=0 && (y-getRootBoxOffsetY())>=0
-    && (x-getRootBoxOffsetX())<=(int)area.w && (y-getRootBoxOffsetY())<=(int)area.h && active)
+  if (    (x - getRootBoxOffsetX()) >= 0
+       && (y - getRootBoxOffsetY()) >= 0
+       && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
+       && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
+       && active
+     )
   {
     return true;
   }
index 7e0b7caa3f25204a73ef2cdd420db6b2abdeee1f..3b6eb5609218a701ce3092bdacf4969701405eed 100644 (file)
--- a/wbutton.h
+++ b/wbutton.h
@@ -1,5 +1,5 @@
 /*
-    Copyright 2004-2005 Chris Tallon
+    Copyright 2004-2020 Chris Tallon
 
     This file is part of VOMP.
 
     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 WBUTTON_H
 #define WBUTTON_H
 
-#include <stdio.h>
-#include <string.h>
+#include <string>
 
 #include "defines.h"
 #include "boxx.h"
@@ -31,7 +29,6 @@ class WButton : public Boxx
 {
   public:
     WButton();
-    virtual ~WButton();
     void setText(const char* text);
     void setActive(UCHAR tactive);
     void dim();
@@ -43,11 +40,10 @@ class WButton : public Boxx
     virtual bool mouseLBDOWN(int x, int y);
 
   private:
-    UCHAR active;
-    bool dimmed;
-
-    char* mytext;
-    int tag;
+    std::string mytext;
+    UCHAR active{};
+    bool dimmed{};
+    int tag{};
 };
 
 #endif