📄 canvaselement.java
字号:
/*
Represents single element in Canvas-deligated screen table
*/
package inline.ui.ce;
import inline.ui.*;
import inline.sys.*;
import java.util.*;
import javax.microedition.lcdui.*;
public abstract class CanvasElement
{
public static final int CENTER = -20;
public static final int LEFT_SOFT = -21;
public static final int RIGHT_SOFT = -22;
public static final int MENU_SOFT = -23;
public static final int LEFT = -2;
public static final int RIGHT = -5;
public static final int UP = -1;
public static final int DOWN = -6;
private static final int REPEAT_DELAY = 200;
private static final int REPEAT_RATE = 50;
private Timer scrollertimer;
private Timer keytimer;
private int px = 0;
private int py = 0;
private boolean hasborder;
private boolean hasfocus;
private int brdd = 0;
private int fcsd = 0;
private int width = 0;
private int height = 0;
private int rwidth = 0;
private int rheight = 0;
protected HostCanvas parent;
protected Font selectedFont;
protected int fnthei = 0;
private int layanchor;
private boolean layouted;
private boolean visible;
private int style;
private boolean styleable;
private int minwidth;
private int minheight;
private boolean wantKeyRepeat;
private boolean wantRepaint;
private int accelKey;
private int last_rep_key;
private int keyrepeat;
private int BACKGROUND_COLOR;
private int FOREGROUND_COLOR;
private int MIDDLERAMP_COLOR;
private int backcolor_components[];
private int middcolor_components[];
private int forecolor_components[];
private int ramp_cache[];
private boolean shown;
private boolean autoscroll;
private int autoscroller;
private static final int SCROLL_INTERVAL = 2000;
private static final int TIMER_AUTO_SCROLL = 0xA3994653; //what?
private static final int TIMER_KEYREPEAT = 0x5001F791; //the heck?
// FIGURES
public final static int FIGURE_EMPTY = 0;
public final static int FIGURE_SQUARE = 1;
public final static int FIGURE_CIRCLE = 2;
public final static int FIGURE_TRI_E = 3;
public final static int FIGURE_PAUSE = 4;
public final static int FIGURE_MENU = 5;
public final static int FIGURE_MARKS = 6;
public final static int FIGURE_DIGIT0 = 7;
public final static int FIGURE_DIGIT1 = 8;
public final static int FIGURE_DIGIT2 = 9;
public final static int FIGURE_DIGIT3 = 10;
public final static int FIGURE_DIGIT4 = 11;
public final static int FIGURE_DIGIT5 = 12;
public final static int FIGURE_DIGIT6 = 13;
public final static int FIGURE_DIGIT7 = 14;
public final static int FIGURE_DIGIT8 = 15;
public final static int FIGURE_DIGIT9 = 16;
public final static int FIGURE_COLON_HALF = 17;
public final static int FIGURE_RARROW = 18;
public final static int FIGURE_NEBULA1 = 19;
public final static int FIGURE_NEBULA2 = 20;
public final static int FIGURE_NEBULA3 = 21;
public final static int FIGURE_NEBULA4 = 22;
public final static int FIGURE_SPLITRECT = 23;
public final static int FIGURE_LOCK = 24;
private final static byte COMMAND_END = -1;
private final static byte COMMAND_FILL_RECT = 1;
private final static byte COMMAND_FILL_TRI = 2;
private final static byte COMMAND_FILL_ARC = 3;
private final static byte COMMAND_COLOR = 4;
private final static byte COMMAND_FILL_RECT_BOUND = 5;
private final static byte COMMAND_COLOR_RAMP = 6;
private final static byte COLOR_BG = -2;
private final static byte COLOR_FG = -1;
private static byte[] figures;
protected static int[] figidxs;
// static init for metafigures
static
{
figures = (byte[])Base.getOption("_metafigs");
figidxs = null;
if (figures!=null)
{
Vector idxs = new Vector();
idxs.addElement(new Integer(0));
for(int i=0;i<figures.length;i++)
{
if (figures[i]==COMMAND_END)
{
idxs.addElement(new Integer(i+1));
}
}
figidxs = new int[idxs.size()];
for(int i=0;i<idxs.size();i++)
{
figidxs[i] = ((Integer)idxs.elementAt(i)).intValue();
}
}
}
CanvasElement(HostCanvas prnt, int x, int y, int w, int h)
{
parent = prnt;
px = x;
py = y;
brdd = 0;
fcsd = 0;
rwidth = w;
rheight = h;
shown = false;
layouted = false;
accelKey = 0;
visible = true;
calcSpaces();
selectedFont = Font.getDefaultFont();
fnthei = selectedFont.getHeight();
backcolor_components = new int[3];
middcolor_components = new int[3];
forecolor_components = new int[3];
ramp_cache = new int[11];
}
protected void calcSpaces()
{
width = rwidth;
height = rheight;
if (drawFocus())
{
// for focus
fcsd=1;
}
if (drawBorder())
{
// for border
brdd=1;
}
width -= (fcsd<<2)+(brdd<<2);
height -= (fcsd<<2)+(brdd<<2);
}
public void fixColors()
{
BACKGROUND_COLOR = parent.getBackgroundColor();
FOREGROUND_COLOR = parent.getForegroundColor();
MIDDLERAMP_COLOR = parent.getMiddleRampColor();
decomponentColors();
}
private void decomponentColors()
{
backcolor_components = divideColor(BACKGROUND_COLOR);
forecolor_components = divideColor(FOREGROUND_COLOR);
if (MIDDLERAMP_COLOR == -3)
{
// undefined, make it 50% ramp
middcolor_components = divideColor(FOREGROUND_COLOR);
MIDDLERAMP_COLOR = getRampColor(25);
}
middcolor_components = divideColor(MIDDLERAMP_COLOR);
clearRampCache();
}
private void clearRampCache()
{
for(int i=0;i<ramp_cache.length;i++)
{
ramp_cache[i] = -1;
}
}
public int[] divideColor(int color)
{
int abc[] = {0,0,0};
abc[0] = (color&0xff0000)>>16;
abc[1] = (color&0x00ff00)>>8;
abc[2] = (color&0x0000ff);
return abc;
}
public int joinColor(int ica[])
{
return (ica[0]<<16)|(ica[1]<<8)|ica[2];
}
/*
* ramp = 0...100 (0 - pure background, 100 - pure foreground)
*
*
*/
public int getRampColor(int ramp)
{
int cidx = -1;
if ((ramp%10)==0)
{
// cache lookup
cidx = ramp/10;
if (ramp_cache[cidx]!=-1)
{
return ramp_cache[cidx];
}
}
int ica[] = {0,0,0};
for(int c=0;c<3;c++)
{
if (ramp<50)
{
ica[c] = backcolor_components[c]+
200*ramp*(middcolor_components[c]-backcolor_components[c])/10000;
}
else
{
ica[c] = middcolor_components[c]+
200*(ramp-50)*(forecolor_components[c]-middcolor_components[c])/10000;
}
}
int color = ((ica[0]<<16)|(ica[1]<<8)|ica[2]);
if (cidx!=-1)
{
ramp_cache[cidx] = color;
}
return color;
}
public int getRampColor(int ramp, boolean sel)
{
if (sel) ramp = 100-ramp;
return getRampColor(ramp);
}
public int getBackgroundColor()
{
int color = -1;
if (style==100 || !styleable || !hasborder)
{
color = BACKGROUND_COLOR;
}
else
{
color = getRampColor(40);
}
return color;
}
public int getForegroundColor()
{
return FOREGROUND_COLOR;
/* int color = -1;
if (style==100 || !styleable || !hasborder)
{
color = FOREGROUND_COLOR;
}
else
{
color = BACKGROUND_COLOR;
}
return color; */
}
public int getMiddleRampColor()
{
return MIDDLERAMP_COLOR;
}
public int getX()
{
return px;
}
public int getY()
{
return py;
}
public int getRWidth()
{
return rwidth;
}
public int getRHeight()
{
return rheight;
}
public int getWidth()
{
return width;
}
public int getHeight()
{
return height;
}
public int getFontHeight()
{
return fnthei;
}
protected boolean drawFocus()
{
return hasfocus;
}
protected boolean drawBorder()
{
return hasborder;
}
public void hasFocus(boolean hf)
{
hasfocus = hf;
calcSpaces();
}
public void hasBorder(boolean hb)
{
hasborder = hb;
calcSpaces();
}
public boolean canFocus()
{
return false;
}
public void paint(Graphics g)
{
if (!shown) fixColors();
shown=true;
synchronized (g)
{
g.translate(-g.getTranslateX(), -g.getTranslateY());
g.setClip(0, 0, parent.getWidth(),parent.getHeight());
//g.setColor(0xff0000);
//g.fillRect(px, py, rwidth,rheight);
if (drawBorder())
{
if (style==100 || !styleable)
{
g.setColor(BACKGROUND_COLOR);
g.drawRect(px+(fcsd<<1)+1, py+(fcsd<<1)+1, width+1, height+1);
g.setColor(FOREGROUND_COLOR);
g.drawRect(px+(fcsd<<1), py+(fcsd<<1), width+3, height+3);
}
else
{
int xa = px+(fcsd<<1);
int ya = py+(fcsd<<1);
int xb = xa + width+3;
int yb = ya + height+3;
g.setColor(getRampColor(100));
g.drawLine(xa, ya, xb, ya);
g.drawLine(xa, ya, xa, yb);
g.setColor(getRampColor(70));
g.drawRect(xa+1, ya+1, width+1, height+1);
g.setColor(getRampColor(30));
g.drawLine(xa, yb, xb, yb);
g.drawLine(xb, ya, xb, yb);
}
}
if (drawFocus() && isFocused())
{
g.setColor(FOREGROUND_COLOR);
g.drawRect(px, py, rwidth-1, rheight-1);
}
g.translate(px+(fcsd<<1)+(brdd<<1),py+(fcsd<<1)+(brdd<<1));
g.setClip(0,0, width, height);
g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(getForegroundColor());
paintElement(g);
}
}
public void setStyleable(boolean sst)
{
styleable = sst;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -