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)
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)
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);
}
}
{
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;
}
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"
{
public:
WTextbox(const char* ttext = NULL);
- virtual ~WTextbox();
void setText(const char* text);
void draw();
void setForegroundColour(const DrawStyle& fcolour);
// 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