]> git.vomp.tv Git - vompclient.git/blob - wtextbox.cc
Bitmap and VPictureBanner CWFs
[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::setForegroundColour(const DrawStyle& fcolour)
52 {
53   foreColour = fcolour;
54 }
55
56 void WTextbox::draw()
57 {
58   Boxx::draw();
59   if (text.length())
60   {
61     if (paraMode) rem_scroll_line = drawPara(text.c_str(), textX, textY, foreColour, cur_scroll_line);
62     else          drawText(text.c_str(), textX, textY, foreColour);
63   }
64 }
65
66 void WTextbox::setTextPos(int x, int y)
67 {
68   textX = x;
69   textY = y;
70 }
71
72 int WTextbox::handleCommand(int command)
73 {
74   switch(command)
75   {
76     case Input::UP:
77     {
78       if (cur_scroll_line > 0)
79       {
80         --cur_scroll_line;
81         --rem_scroll_line;
82         return 1;
83       }
84       else
85       {
86         return 4; // Signal return control to parent
87       }
88     }
89     case Input::DOWN:
90     {
91       if (rem_scroll_line > 0)
92       {
93         ++cur_scroll_line;
94         --rem_scroll_line;
95         return 1;
96       }
97       else
98       {
99         return 4;
100       }
101     }
102     case Input::LEFT:
103     case Input::RIGHT:
104     {
105       return 5;
106     }
107   }
108
109   return 0;
110 }
111
112 bool WTextbox::mouseAndroidScroll(int x, int y, int /* sx */, int sy)
113 {
114   if (    (x - getRootBoxOffsetX()) >= 0
115        && (y - getRootBoxOffsetY()) >= 0
116        && (x - getRootBoxOffsetX()) <= static_cast<int>(area.w)
117        && (y - getRootBoxOffsetY()) <= static_cast<int>(area.h)
118      )
119   {
120     int change = -sy /120;
121     if (change < 0)
122     {
123       int rel_change = min(cur_scroll_line, -change);
124       cur_scroll_line-=rel_change;
125       rem_scroll_line+=rel_change;
126     }
127     else if (change > 0)
128     {
129       int rel_change = min(rem_scroll_line, change);
130       cur_scroll_line += rel_change;
131       rem_scroll_line -= rel_change;
132     }
133     return true;
134   }
135   return false;
136 }