]> git.vomp.tv Git - vompclient.git/blob - wtextbox.cc
Switch Channel to std::string
[vompclient.git] / wtextbox.cc
1 /*
2     Copyright 2005 Brian Walton
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "colour.h"
21 #include "input.h"
22
23 #include "wtextbox.h"
24
25 WTextbox::WTextbox(const char* takeText):
26 foreColour(DrawStyle::LIGHTTEXT)
27 {
28 //  int fontHeight = Surface::getFontHeight();
29   //setDimensions(70, fontHeight);
30   //setDimensions(100,100);
31   setSize(100, 100);
32
33   textX = 5;
34   textY = 2;
35   
36   paraMode = true;
37   
38   if (takeText) setText(takeText);
39 }
40
41 void WTextbox::setParaMode(bool mode)
42 {
43   paraMode = mode;
44 }
45
46 void WTextbox::setText(const char* takeText)
47 {
48   text = takeText;
49 }
50
51 void WTextbox::setText(const std::string& takeText)
52 {
53   text = takeText;
54 }
55
56 void WTextbox::setForegroundColour(const DrawStyle& fcolour)
57 {
58   foreColour = fcolour;
59 }
60
61 void WTextbox::draw()
62 {
63   Boxx::draw();
64   if (text.length())
65   {
66     if (paraMode) rem_scroll_line = drawPara(text.c_str(), textX, textY, foreColour, cur_scroll_line);
67     else          drawText(text.c_str(), textX, textY, foreColour);
68   }
69 }
70
71 void WTextbox::setTextPos(int x, int y)
72 {
73   textX = x;
74   textY = y;
75 }
76
77 int WTextbox::handleCommand(int command)
78 {
79   switch(command)
80   {
81     case Input::UP:
82     {
83       if (cur_scroll_line > 0)
84       {
85         --cur_scroll_line;
86         --rem_scroll_line;
87         return 1;
88       }
89       else
90       {
91         return 4; // Signal return control to parent
92       }
93     }
94     case Input::DOWN:
95     {
96       if (rem_scroll_line > 0)
97       {
98         ++cur_scroll_line;
99         --rem_scroll_line;
100         return 1;
101       }
102       else
103       {
104         return 4;
105       }
106     }
107     case Input::LEFT:
108     case Input::RIGHT:
109     {
110       return 5;
111     }
112   }
113
114   return 0;
115 }
116
117 bool WTextbox::mouseAndroidScroll(int x, int y, int /* sx */, int sy)
118 {
119   if (    (x - getRootBoxOffsetX()) >= 0
120        && (y - getRootBoxOffsetY()) >= 0
121        && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
122        && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
123      )
124   {
125     int change = -sy /120;
126     if (change < 0)
127     {
128       int rel_change = min(cur_scroll_line, -change);
129       cur_scroll_line-=rel_change;
130       rem_scroll_line+=rel_change;
131     }
132     else if (change > 0)
133     {
134       int rel_change = min(rem_scroll_line, change);
135       cur_scroll_line += rel_change;
136       rem_scroll_line -= rel_change;
137     }
138     return true;
139   }
140   return false;
141 }