1 |
// (c): Asko Soukka |
/* |
2 |
|
MMTextCursor.java |
3 |
|
* |
4 |
|
* Copyright (c) 2003, Asko Soukka |
5 |
|
* This file is part of Fenfire. |
6 |
|
* |
7 |
|
* Fenfire is free software; you can redistribute it and/or modify it under |
8 |
|
* the terms of the GNU Lesser General Public License as published by |
9 |
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
* (at your option) any later version. |
11 |
|
* |
12 |
|
* Fenfire is distributed in the hope that it will be useful, but WITHOUT |
13 |
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 |
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General |
15 |
|
* Public License for more details. |
16 |
|
* |
17 |
|
* You should have received a copy of the GNU Lesser General |
18 |
|
* Public License along with Fenfire; if not, write to the Free |
19 |
|
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
|
* MA 02111-1307 USA |
21 |
|
* |
22 |
|
*/ |
23 |
|
/* |
24 |
|
* Written by Asko Soukka |
25 |
|
*/ |
26 |
|
|
27 |
/** |
/** |
28 |
* Cursor class especially designed for MM purposes. Could be |
* Cursor class especially designed for MM purposes. Could be |
93 |
/** Move the cursor to the previous line. */ |
/** Move the cursor to the previous line. */ |
94 |
public int moveUp() throws NotYetRenderedException { |
public int moveUp() throws NotYetRenderedException { |
95 |
if (p == null) throw new NotYetRenderedException(); |
if (p == null) throw new NotYetRenderedException(); |
96 |
float cursorXY[] = new float[2]; |
float cursorXY[] = new float[3]; |
97 |
p.getCursorXY(offset, cursorXY); |
p.getCursorXYY(offset, cursorXY); |
98 |
cursorXY[1] -= style.getHeight(scale); |
cursorXY[2] -= style.getHeight(scale); |
99 |
offset = p.getCursorPos(cursorXY[0], cursorXY[1]); |
offset = p.getCursorPos(cursorXY[0], cursorXY[2]); |
100 |
return offset; |
return offset; |
101 |
} |
} |
102 |
/** Move the cursor to the next line. */ |
/** Move the cursor to the next line. */ |
103 |
public int moveDown() throws NotYetRenderedException { |
public int moveDown() throws NotYetRenderedException { |
104 |
if (p == null) throw new NotYetRenderedException(); |
if (p == null) throw new NotYetRenderedException(); |
105 |
float cursorXY[] = new float[2]; |
float cursorXY[] = new float[3]; |
106 |
p.getCursorXY(offset, cursorXY); |
p.getCursorXYY(offset, cursorXY); |
107 |
cursorXY[1] += style.getHeight(scale); |
cursorXY[2] += style.getHeight(scale); |
108 |
offset = p.getCursorPos(cursorXY[0], cursorXY[1]); |
offset = p.getCursorPos(cursorXY[0], cursorXY[2]); |
109 |
return offset; |
return offset; |
110 |
} |
} |
111 |
/** Move the cursor into the beginning of the text. */ |
/** Move the cursor into the beginning of the text. */ |
123 |
/** Move the cursor into the beginning of the line. */ |
/** Move the cursor into the beginning of the line. */ |
124 |
public int moveBeginLine() throws NotYetRenderedException{ |
public int moveBeginLine() throws NotYetRenderedException{ |
125 |
if (p == null) throw new NotYetRenderedException(); |
if (p == null) throw new NotYetRenderedException(); |
126 |
float cursorXY[] = new float[2]; |
float cursorXY[] = new float[3]; |
127 |
p.getCursorXY(offset, cursorXY); |
p.getCursorXYY(offset, cursorXY); |
128 |
cursorXY[0] = 0; |
cursorXY[0] = 0; |
129 |
offset = p.getCursorPos(cursorXY[0], cursorXY[1]); |
offset = p.getCursorPos(cursorXY[0], cursorXY[2]); |
130 |
return offset; |
return offset; |
131 |
} |
} |
132 |
/** Move the cursor to the end of the line. */ |
/** Move the cursor to the end of the line. */ |
135 |
if (length == 0) length = getLength(); |
if (length == 0) length = getLength(); |
136 |
// the end of line is reached by going to home of the line below |
// the end of line is reached by going to home of the line below |
137 |
// and returning a single character back if not the end of text was reached |
// and returning a single character back if not the end of text was reached |
138 |
float cursorXY[] = new float[2]; |
float cursorXY[] = new float[3]; |
139 |
p.getCursorXY(offset, cursorXY); |
p.getCursorXYY(offset, cursorXY); |
140 |
cursorXY[0] = 0; |
cursorXY[0] = 0; |
141 |
cursorXY[1] += style.getHeight(scale); |
cursorXY[2] += style.getHeight(scale); |
142 |
offset = p.getCursorPos(cursorXY[0], cursorXY[1]); |
offset = p.getCursorPos(cursorXY[0], cursorXY[2]); |
143 |
if (offset < length) offset -= 1; |
if (offset < length) offset -= 1; |
144 |
return offset; |
return offset; |
145 |
} |
} |
156 |
public void render(VobScene vs, int into, int matchCS, int matchParentCS, TextPlaceable p) { |
public void render(VobScene vs, int into, int matchCS, int matchParentCS, TextPlaceable p) { |
157 |
setTextPlaceable(p); |
setTextPlaceable(p); |
158 |
|
|
159 |
float cursorXY[] = new float[2]; |
float cursorXY[] = new float[3]; |
160 |
this.p.getCursorXY(offset, cursorXY); |
this.p.getCursorXYY(offset, cursorXY); |
161 |
|
|
162 |
int nodeCS = 0; |
int nodeCS = 0; |
163 |
int cursorCS = 0; |
int cursorCS = 0; |
164 |
if (matchParentCS == -1) { |
if (matchParentCS == -1) { |
165 |
cursorCS = vs.coords.ortho(into, -1000, |
cursorCS = vs.coords.ortho(into, -1000, |
166 |
-p.getWidth()/2 + cursorXY[0], |
-p.getWidth()/2 + cursorXY[0], |
167 |
-p.getHeight()/2 + cursorXY[1], |
-p.getHeight()/2 + cursorXY[2], |
168 |
1, -style.getHeight(scale)); |
1, -style.getHeight(scale)); |
169 |
vs.matcher.add(matchCS, cursorCS, "CURSOR"); |
vs.matcher.add(matchCS, cursorCS, "CURSOR"); |
170 |
} else { |
} else { |
174 |
|
|
175 |
cursorCS = vs.coords.ortho(into, -1000, |
cursorCS = vs.coords.ortho(into, -1000, |
176 |
nodeXY[0] + cursorXY[0], |
nodeXY[0] + cursorXY[0], |
177 |
nodeXY[1] + cursorXY[1], |
nodeXY[1] + cursorXY[2], |
178 |
1, -style.getHeight(scale)); |
1, -style.getHeight(scale)); |
179 |
vs.matcher.add(matchCS, cursorCS, "CURSOR"); |
vs.matcher.add(matchCS, cursorCS, "CURSOR"); |
180 |
} |
} |