]> git.vomp.tv Git - vompclient.git/blob - wtextbox.cc
Fix resuming recording directly after stopping it
[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, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "wtextbox.h"
22
23 #include "colour.h"
24 #include "remote.h"
25
26 WTextbox::WTextbox(const char* ttext):
27 foreColour(DrawStyle::LIGHTTEXT)
28 {
29 //  int fontHeight = Surface::getFontHeight();
30   //setDimensions(70, fontHeight);
31   //setDimensions(100,100);
32   setSize(100, 100);
33   text = NULL;
34
35   textX = 5;
36   textY = 2;
37   
38   paraMode = true;
39   
40   if (ttext) setText(ttext);
41
42   cur_scroll_line=0;
43   rem_scroll_line=0;
44 }
45
46 WTextbox::~WTextbox()
47 {
48   if (text) delete[] text;
49 }
50
51 void WTextbox::setParaMode(bool mode)
52 {
53   paraMode = mode;
54 }
55
56 void WTextbox::setText(const char* takeText)
57 {
58   if (text) delete[] text;
59   int length = strlen(takeText);
60   text = new char[length + 1];
61   strcpy(text, takeText);
62 }
63
64 void WTextbox::setForegroundColour(const DrawStyle& fcolour)
65 {
66   foreColour = fcolour;
67 }
68
69 void WTextbox::draw()
70 {
71   Boxx::draw();
72   if (text)
73   {
74     if (paraMode) rem_scroll_line=drawPara(text, textX, textY, foreColour,cur_scroll_line);
75     else          drawText(text, textX, textY, foreColour);
76   }
77 }
78
79 void WTextbox::setTextPos(int x, int y)
80 {
81   textX = x;
82   textY = y;
83 }
84
85 int WTextbox::handleCommand(int command)
86 {
87   switch(command)
88   {
89     case Remote::DF_UP:
90     case Remote::UP:
91     {
92       if (cur_scroll_line > 0)
93       {
94           cur_scroll_line--;
95           rem_scroll_line++;
96           return 1;
97       }
98       else
99       {
100           return 4; // Signal return control to parent
101       }
102     }
103     case Remote::DF_DOWN:
104     case Remote::DOWN:
105     {
106         if (rem_scroll_line > 0)
107         {
108                 cur_scroll_line++;
109                 rem_scroll_line--;
110                 return 1;
111         } else {
112                 return 4;
113         }
114     }
115     case Remote::LEFT:
116     case Remote::RIGHT:
117     case Remote::DF_LEFT:
118     case Remote::DF_RIGHT:
119     {
120         return 5;
121     }
122
123   }
124
125   return 0;
126 }
127
128 bool WTextbox::mouseAndroidScroll(int x, int y, int sx, int sy)
129 {
130         if ((x - getRootBoxOffsetX()) >= 0 && (y - getRootBoxOffsetY()) >= 0
131                 && (x - getRootBoxOffsetX()) <= (int)area.w && (y - getRootBoxOffsetY()) <= (int)area.h )
132         {
133                 int change = -sy /120;
134                 if (change < 0) {
135                         int rel_change = min(cur_scroll_line, -change);
136                         cur_scroll_line-=rel_change;
137                         rem_scroll_line+=rel_change;
138                 }
139                 else if (change > 0) {
140                         int rel_change = min(rem_scroll_line, change);
141                         cur_scroll_line += rel_change;
142                         rem_scroll_line -= rel_change;
143                 }
144                 return true;
145         }
146         return false;
147
148 }