From ee680bdefffc94f1c0a741be44e5770c586c6a67 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 7 May 2020 16:46:14 +0100 Subject: [PATCH] WButton CWFs --- wbutton.cc | 48 +++++++++++++++++++++--------------------------- wbutton.h | 18 +++++++----------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/wbutton.cc b/wbutton.cc index eed4a37..588fb5a 100644 --- a/wbutton.cc +++ b/wbutton.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,35 +14,21 @@ 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 . */ -#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(area.w) + && (y - getRootBoxOffsetY()) <= static_cast(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(area.w) + && (y - getRootBoxOffsetY()) <= static_cast(area.h) + && active + ) { return true; } diff --git a/wbutton.h b/wbutton.h index 7e0b7ca..3b6eb56 100644 --- 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. @@ -14,15 +14,13 @@ 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 . */ #ifndef WBUTTON_H #define WBUTTON_H -#include -#include +#include #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 -- 2.39.5