📄 selector.java
字号:
int max = AnyView.cf.str2bytes(title).length;
itemPages = items.length / ShowItems;
if (items.length > ShowItems * itemPages && itemPages > 0) {
itemPages++;
}
for (int i = 0; i < items.length; i++) {
int c = AnyView.cf.str2bytes(items[i]).length;
if (c >= max) {
max = c;
}
}
this.width = max * AnyView.cf.AsciiWidth + (HorPad << 1);
if (itemPages == 0) { //当前可以显示完成
this.height = items.length * (AnyView.cf.FontHeight + LinePad) -
LinePad + VecPad + HorPad;
} else {
this.height = ShowItems * (AnyView.cf.FontHeight + LinePad) -
LinePad + VecPad + HorPad;
}
int[] c = new int[(width - 4) * (AnyView.cf.FontHeight + 2)];
for (int i = 0; i < c.length; i++) {
c[i] = 0x7FFFFFFF;
}
cube = Image.createRGBImage(c, (width - 4), CustomFont.FontHeight + 2, true);
c = null;
prepare();
}*/
/**
* 仅通过itemIndex、selectedIndex和itemPages来返回当前窗口
* @return Image
*/
public Image getWindow() {
Image window = Image.createImage(windowImage.getWidth(),
windowImage.getHeight());
Graphics g = window.getGraphics();
g.drawImage(windowImage, 0, 0, ANCHOR);
//绘制停留框
g.setColor(AnyView.bordorcolor);
int y = VecPad + 5 +
(itemIndex - topIndex) * (AnyView.cf.FontHeight + LinePad);
g.drawImage(cube, 2, y, ANCHOR);
g.setStrokeStyle(Graphics.DOTTED);
g.drawRoundRect(2, y - 1, cubeWidth - 1, CustomFont.FontHeight + 3, 8,
8);
g.setStrokeStyle(Graphics.SOLID);
return window;
}
public void destroy() {
byteItems = null;
//itemImage = null;
windowImage = null;
cube = null;
System.gc();
//System.out.println("destroy() " + Runtime.getRuntime().freeMemory());
}
public int getSelectedIndex() {
if (!hasItems) {
return -1;
}
return itemIndex;
}
public void keyUp() {
itemIndex--;
if (itemIndex < 0) {
itemIndex = 0;
return;
}
if (itemIndex < topIndex) {
topIndex -= ShowItems;
topIndex = topIndex < 0 ? 0 : topIndex;
refreshList();
}
}
public void keyDown() {
itemIndex++;
if (itemIndex == byteItems.length) { //已到达最后一项
itemIndex = byteItems.length - 1;
return;
}
if (itemIndex - topIndex == ShowItems) {
topIndex++;
refreshList();
}
}
public void keyLeft() {
itemIndex--;
if (itemIndex < 0) {
itemIndex = 0;
return;
}
if (itemIndex < topIndex) {
topIndex -= ShowItems;
topIndex = topIndex < 0 ? 0 : topIndex;
refreshList();
}
}
public void keyRight() {
if (topIndex + ShowItems >= byteItems.length) { //翻页无效
return;
}
topIndex += ShowItems;
if (topIndex + ShowItems > byteItems.length) { //到顶了
topIndex = byteItems.length - ShowItems;
}
itemIndex = topIndex;
refreshList();
}
public void keyFire() {
WINDOW_STATE = CLOSED;
}
public boolean bof() {
return (topIndex == 0);
}
protected void pointerPressed(int x, int y) {
super.pointerPressed(x, y);
if (!contains(PRESSED_X, PRESSED_Y)) {
//WINDOW_STATE = CLOSED;
return;
}
//首先检查是不是翻页
pageup = false;
pagedown = false;
if (showScrollBar) { //有滚动条时才会有翻页的动作
int top = height - ButtonHeight;
if (PRESSED_Y > top && PRESSED_Y < height) { //在翻页按钮的Y轴范围内
if (PRESSED_X > width >> 1) { //向下翻
pagedown = true;
} else if (PRESSED_X > 0) { //向上翻
pageup = true;
}
}
}
//判断用户当前的选择项
int find = -1;
for (int i = 0; i < ShowItems && find == -1; i++) {
int top = VecPad + i * (CustomFont.FontHeight + LinePad) - 1;
if (PRESSED_Y > top && PRESSED_Y < top + CustomFont.FontHeight) {
find = topIndex + i;
itemIndex = topIndex + i;
//System.out.println("pressed: itemIndex = " + itemIndex);
}
}
}
protected void pointerDragged(int x, int y) {
}
protected void pointerReleased(int x, int y) {
TOUCH_EVENT = false;
super.pointerReleased(x, y);
if (!contains(RELEASE_X, RELEASE_Y) && !contains(PRESSED_X, PRESSED_Y)) {
WINDOW_STATE = CLOSED;
return;
}
//首先检查是不是翻页
if (showScrollBar) { //有滚动条时才会有翻页的动作
int top = height - ButtonHeight;
if (RELEASE_Y > top && RELEASE_Y < height) { //在翻页按钮的Y轴范围内
if (RELEASE_X > width >> 1) { //向下翻
if (!pagedown) { //按下时的动作并不是向下翻页
return;
}
if (topIndex + ShowItems >= byteItems.length) { //翻页无效
return;
}
topIndex += ShowItems;
if (topIndex + ShowItems > byteItems.length) { //到顶了
topIndex = byteItems.length - ShowItems;
}
itemIndex = topIndex;
refreshList();
} else if (RELEASE_X > 0) { //向上翻
if (!pageup) { //按下时的动作并不是向上翻页
return;
}
if (topIndex == 0) { //向上翻页无效
return;
}
topIndex -= ShowItems;
topIndex = topIndex < 0 ? 0 : topIndex;
itemIndex = topIndex;
refreshList();
}
}
}
//判断用户当前的选择项
int find = -1;
for (int i = 0; i < ShowItems && find == -1; i++) {
int top = VecPad + i * (CustomFont.FontHeight + LinePad) - 1;
if (RELEASE_Y > top && RELEASE_Y < top + CustomFont.FontHeight) {
find = i + topIndex;
//System.out.println("released: find = " + find);
}
}
if (find == -1) {
return;
}
if (find == itemIndex) { //用户确认选择功能
TOUCH_EVENT = true;
keyFire();
}
else {
itemIndex = find;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -