📄 rdesktopcanvas.java
字号:
int cx = patblt.getCX();
int cy = patblt.getCY();
int fgcolor = patblt.getForegroundColor();
int bgcolor = patblt.getBackgroundColor();
int opcode = patblt.getOpcode();
patBltOrder(opcode, x, y, cx, cy, fgcolor, bgcolor, brush);
}
/**
* Perform a tri blit on the screen
*
* @param triblt
* TriBltOrder describing the blit
*/
public void drawTriBltOrder(TriBltOrder triblt) {
int x = triblt.getX();
int y = triblt.getY();
if (x > this.right || y > this.bottom)
return; // off screen
int cx = triblt.getCX();
int cy = triblt.getCY();
int srcx = triblt.getSrcX();
int srcy = triblt.getSrcY();
int fgcolor = triblt.getForegroundColor();
int bgcolor = triblt.getBackgroundColor();
Brush brush = triblt.getBrush();
// convert to 24-bit colour
fgcolor = Bitmap.convertTo24(fgcolor);
bgcolor = Bitmap.convertTo24(bgcolor);
// Perform standard clipping checks, x-axis
int clipright = x + cx - 1;
if (clipright > this.right)
clipright = this.right;
if (x < this.left)
x = this.left;
cx = clipright - x + 1;
// Perform standard clipping checks, y-axis
int clipbottom = y + cy - 1;
if (clipbottom > this.bottom)
clipbottom = this.bottom;
if (y < this.top)
y = this.top;
cy = clipbottom - y + 1;
try {
Bitmap bitmap = cache.getBitmap(triblt.getCacheID(), triblt
.getCacheIDX());
switch (triblt.getOpcode()) {
case 0x69: // PDSxxn
rop.do_array(ROP2_XOR, backstore, this.width, x, y, cx, cy,
bitmap.getBitmapData(), bitmap.getWidth(), srcx, srcy);
patBltOrder(ROP2_NXOR, x, y, cx, cy, fgcolor, bgcolor, brush);
break;
case 0xb8: // PSDPxax
patBltOrder(ROP2_XOR, x, y, cx, cy, fgcolor, bgcolor, brush);
rop.do_array(ROP2_AND, backstore, this.width, x, y, cx, cy,
bitmap.getBitmapData(), bitmap.getWidth(), srcx, srcy);
patBltOrder(ROP2_XOR, x, y, cx, cy, fgcolor, bgcolor, brush);
break;
case 0xc0: // PSa
rop.do_array(ROP2_COPY, backstore, this.width, x, y, cx, cy,
bitmap.getBitmapData(), bitmap.getWidth(), srcx, srcy);
patBltOrder(ROP2_AND, x, y, cx, cy, fgcolor, bgcolor, brush);
break;
default:
logger
.warn("Unimplemented Triblt opcode:"
+ triblt.getOpcode());
rop.do_array(ROP2_COPY, backstore, this.width, x, y, cx, cy,
bitmap.getBitmapData(), bitmap.getWidth(), srcx, srcy);
}
} catch (RdesktopException e) {
}
}
/**
* Parse a delta co-ordinate in polyline order form
*
* @param buffer
* @param offset
* @return
*/
static int parse_delta(byte[] buffer, int[] offset) {
int value = buffer[offset[0]++] & 0xff;
int two_byte = value & 0x80;
if ((value & 0x40) != 0) /* sign bit */
value |= ~0x3f;
else
value &= 0x3f;
if (two_byte != 0)
value = (value << 8) | (buffer[offset[0]++] & 0xff);
return value;
}
/**
* Draw a multi-point set of lines to the screen
* @param polyline PolyLineOrder describing the set of lines to draw
*/
public void drawPolyLineOrder(PolyLineOrder polyline) {
int x = polyline.getX();
int y = polyline.getY();
int fgcolor = polyline.getForegroundColor();
int datasize = polyline.getDataSize();
byte[] databytes = polyline.getData();
int lines = polyline.getLines();
// convert to 24-bit colour
fgcolor = Bitmap.convertTo24(fgcolor);
// hack - data as single element byte array so can pass by ref to
// parse_delta
// see http://www.rgagnon.com/javadetails/java-0035.html
int[] data = new int[1];
data[0] = ((lines - 1) / 4) + 1;
int flags = 0;
int index = 0;
int opcode = polyline.getOpcode() - 1;
for (int line = 0; (line < lines) && (data[0] < datasize); line++) {
int xfrom = x;
int yfrom = y;
if (line % 4 == 0)
flags = databytes[index++];
if ((flags & 0xc0) == 0)
flags |= 0xc0; /* none = both */
if ((flags & 0x40) != 0)
x += parse_delta(databytes, data);
if ((flags & 0x80) != 0)
y += parse_delta(databytes, data);
// logger.info("polyline
// "+line+","+xfrom+","+yfrom+","+x+","+y+","+fgcolor+","+opcode);
drawLine(xfrom, yfrom, x, y, fgcolor, opcode);
flags <<= 2;
}
}
/**
* Draw a rectangle to the screen
* @param rect RectangleOrder defining the rectangle to be drawn
*/
public void drawRectangleOrder(RectangleOrder rect) {
// if(logger.isInfoEnabled()) logger.info("RectangleOrder!");
fillRectangle(rect.getX(), rect.getY(), rect.getCX(), rect.getCY(),
rect.getColor());
}
/**
* Perform an operation on a pixel in the backstore
* @param opcode ID of operation to perform
* @param x x coordinate of pixel
* @param y y coordinate of pixel
* @param color Colour value to be used in operation
*/
public void setPixel(int opcode, int x, int y, int color) {
int Bpp = Options.Bpp;
// correction for 24-bit colour
if (Bpp == 3)
color = ((color & 0xFF) << 16) | (color & 0xFF00)
| ((color & 0xFF0000) >> 16);
if ((x < this.left) || (x > this.right) || (y < this.top)
|| (y > this.bottom)) { // Clip
} else {
rop.do_pixel(opcode, backstore, x, y, color);
}
}
/**
* Draw a single glyph to the screen
* @param mixmode 0 for transparent background, specified colour for background otherwide
* @param x x coordinate on screen at which to draw glyph
* @param y y coordinate on screen at which to draw glyph
* @param cx Width of clipping area for glyph
* @param cy Height of clipping area for glyph
* @param data Set of values defining glyph's pattern
* @param bgcolor Background colour for glyph pattern
* @param fgcolor Foreground colour for glyph pattern
*/
public void drawGlyph(int mixmode, int x, int y, int cx, int cy,
byte[] data, int bgcolor, int fgcolor) {
int pdata = 0;
int index = 0x80;
int bytes_per_row = (cx - 1) / 8 + 1;
int newx, newy, newcx, newcy;
int Bpp = Options.Bpp;
// convert to 24-bit colour
fgcolor = Bitmap.convertTo24(fgcolor);
bgcolor = Bitmap.convertTo24(bgcolor);
// correction for 24-bit colour
if (Bpp == 3) {
fgcolor = ((fgcolor & 0xFF) << 16) | (fgcolor & 0xFF00) | ((fgcolor & 0xFF0000) >> 16);
bgcolor = ((bgcolor & 0xFF) << 16) | (bgcolor & 0xFF00) | ((bgcolor & 0xFF0000) >> 16);
}
// clip here instead
if (x > this.right || y > this.bottom)
return; // off screen
int clipright = x + cx - 1;
if (clipright > this.right)
clipright = this.right;
if (x < this.left)
newx = this.left;
else
newx = x;
newcx = clipright - x + 1; // not clipright - newx - 1
int clipbottom = y + cy - 1;
if (clipbottom > this.bottom)
clipbottom = this.bottom;
if (y < this.top)
newy = this.top;
else
newy = y;
newcy = clipbottom - newy + 1;
int pbackstore = (newy * this.width) + x;
pdata = bytes_per_row * (newy - y); // offset y, but not x
if (mixmode == MIX_TRANSPARENT) { // FillStippled
for (int i = 0; i < newcy; i++) {
for (int j = 0; j < newcx; j++) {
if (index == 0) { // next row
pdata++;
index = 0x80;
}
if ((data[pdata] & index) != 0) {
if ((x + j >= newx) && (newx + j > 0) && (newy + i > 0))
// since haven't offset x
backstore.setRGB(newx + j, newy + i, fgcolor);
}
index >>= 1;
}
pdata++;
index = 0x80;
pbackstore += this.width;
if (pdata == data.length) {
pdata = 0;
}
}
} else { // FillOpaqueStippled
for (int i = 0; i < newcy; i++) {
for (int j = 0; j < newcx; j++) {
if (index == 0) { // next row
pdata++;
index = 0x80;
}
if (x + j >= newx) {
if ((x + j > 0) && (y + i > 0)) {
if ((data[pdata] & index) != 0)
backstore.setRGB(x + j, y + i, fgcolor);
else
backstore.setRGB(x + j, y + i, bgcolor);
}
}
index >>= 1;
}
pdata++;
index = 0x80;
pbackstore += this.width;
if (pdata == data.length) {
pdata = 0;
}
}
}
// if(logger.isInfoEnabled()) logger.info("glyph
// \t(\t"+x+",\t"+y+"),(\t"+(x+cx-1)+",\t"+(y+cy-1)+")");
this.repaint(newx, newy, newcx, newcy);
}
/**
* Create an AWT Cursor object
* @param x
* @param y
* @param w
* @param h
* @param andmask
* @param xormask
* @param cache_idx
* @return Created Cursor
*/
public Cursor createCursor(int x, int y, int w, int h, byte[] andmask,
byte[] xormask, int cache_idx) {
int pxormask = 0;
int pandmask = 0;
Point p = new Point(x, y);
int size = w * h;
int scanline = w / 8;
int offset = 0;
byte[] mask = new byte[size];
int[] cursor = new int[size];
int pcursor = 0, pmask = 0;
offset = size;
for (int i = 0; i < h; i++) {
offset -= w;
pmask = offset;
for (int j = 0; j < scanline; j++) {
for (int bit = 0x80; bit > 0; bit >>= 1) {
if ((andmask[pandmask] & bit) != 0) {
mask[pmask] = 0;
} else {
mask[pmask] = 1;
}
pmask++;
}
pandmask++;
}
}
offset = size;
pcursor = 0;
for (int i = 0; i < h; i++) {
offset -= w;
pcursor = offset;
for (int j = 0; j < w; j++) {
cursor[pcursor] = ((xormask[pxormask + 2] << 16) & 0x00ff0000)
| ((xormask[pxormask + 1] << 8) & 0x0000ff00)
| (xormask[pxormask] & 0x000000ff);
pxormask += 3;
pcursor++;
}
}
offset = size;
pmask = 0;
pcursor = 0;
pxormask = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if ((mask[pmask] == 0) && (cursor[pcursor] != 0)) {
cursor[pcursor] = ~(cursor[pcursor]);
cursor[pcursor] |= 0xff000000;
} else if ((mask[pmask] == 1) || (cursor[pcursor] != 0)) {
cursor[pcursor] |= 0xff000000;
}
pcursor++;
pmask++;
}
}
Image wincursor = this.createImage(new MemoryImageSource(w, h, cursor,
0, w));
return createCustomCursor(wincursor, p, "", cache_idx);
}
/**
* Create an AWT Cursor from an image
* @param wincursor
* @param p
* @param s
* @param cache_idx
* @return Generated Cursor object
*/
protected Cursor createCustomCursor(Image wincursor, Point p, String s,
int cache_idx) {
if (cache_idx == 1)
return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
return Cursor.getDefaultCursor();
}
/**
* Handle the window losing focus, notify input classes
*/
public void lostFocus() {
if (input != null)
input.lostFocus();
}
/**
* Handle the window gaining focus, notify input classes
*/
public void gainedFocus() {
if (input != null)
input.gainedFocus();
}
/**
* Notify the input classes that the connection is ready for sending messages
*/
public void triggerReadyToSend() {
input.triggerReadyToSend();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -