📄 rdesktopcanvas.java
字号:
* @param y1
* y coordinate of start point of line
* @param x2
* x coordinate of end point of line
* @param y2
* y coordinate of end point of line
* @param color
* colour of line
* @param opcode
* Operation code defining operation to perform on pixels within
* the line
*/
public void drawLine(int x1, int y1, int x2, int y2, int color, int opcode) {
// convert to 24-bit colour
color = Bitmap.convertTo24(color);
if (x1 == x2 || y1 == y2) {
drawLineVerticalHorizontal(x1, y1, x2, y2, color, opcode);
return;
}
int deltax = Math.abs(x2 - x1); // The difference between the x's
int deltay = Math.abs(y2 - y1); // The difference between the y's
int x = x1; // Start x off at the first pixel
int y = y1; // Start y off at the first pixel
int xinc1, xinc2, yinc1, yinc2;
int num, den, numadd, numpixels;
if (x2 >= x1) { // The x-values are increasing
xinc1 = 1;
xinc2 = 1;
} else { // The x-values are decreasing
xinc1 = -1;
xinc2 = -1;
}
if (y2 >= y1) { // The y-values are increasing
yinc1 = 1;
yinc2 = 1;
} else { // The y-values are decreasing
yinc1 = -1;
yinc2 = -1;
}
if (deltax >= deltay) { // There is at least one x-value for every
// y-value
xinc1 = 0; // Don't change the x when numerator >= denominator
yinc2 = 0; // Don't change the y for every iteration
den = deltax;
num = deltax / 2;
numadd = deltay;
numpixels = deltax; // There are more x-values than y-values
} else { // There is at least one y-value for every x-value
xinc2 = 0; // Don't change the x for every iteration
yinc1 = 0; // Don't change the y when numerator >= denominator
den = deltay;
num = deltay / 2;
numadd = deltax;
numpixels = deltay; // There are more y-values than x-values
}
for (int curpixel = 0; curpixel <= numpixels; curpixel++) {
setPixel(opcode, x, y, color); // Draw the current pixel
num += numadd; // Increase the numerator by the top of the fraction
if (num >= den) { // Check if numerator >= denominator
num -= den; // Calculate the new numerator value
x += xinc1; // Change the x as appropriate
y += yinc1; // Change the y as appropriate
}
x += xinc2; // Change the x as appropriate
y += yinc2; // Change the y as appropriate
}
int x_min = x1 < x2 ? x1 : x2;
int x_max = x1 > x2 ? x1 : x2;
int y_min = y1 < y2 ? y1 : y2;
int y_max = y1 > y2 ? y1 : y2;
this.repaint(x_min, y_min, x_max - x_min + 1, y_max - y_min + 1);
}
/**
* Helper function for drawLine, draws a horizontal or vertical line using a
* much faster method than used for diagonal lines
*
* @param x1
* x coordinate of start point of line
* @param y1
* y coordinate of start point of line
* @param x2
* x coordinate of end point of line
* @param y2
* y coordinate of end point of line
* @param color
* colour of line
* @param opcode
* Operation code defining operation to perform on pixels within
* the line
*/
public void drawLineVerticalHorizontal(int x1, int y1, int x2, int y2,
int color, int opcode) {
int pbackstore;
int i;
// only vertical or horizontal lines
if (y1 == y2) { // HORIZONTAL
if (y1 >= this.top && y1 <= this.bottom) { // visible
if (x2 > x1) { // x inc, y1=y2
if (x1 < this.left)
x1 = this.left;
if (x2 > this.right)
x2 = this.right;
pbackstore = y1 * this.width + x1;
for (i = 0; i < x2 - x1; i++) {
rop.do_pixel(opcode, backstore, x1 + i, y1, color);
pbackstore++;
}
repaint(x1, y1, x2 - x1 + 1, 1);
} else { // x dec, y1=y2
if (x2 < this.left)
x2 = this.left;
if (x1 > this.right)
x1 = this.right;
pbackstore = y1 * this.width + x1;
for (i = 0; i < x1 - x2; i++) {
rop.do_pixel(opcode, backstore, x2 + i, y1, color);
pbackstore--;
}
repaint(x2, y1, x1 - x2 + 1, 1);
}
}
} else { // x1==x2 VERTICAL
if (x1 >= this.left && x1 <= this.right) { // visible
if (y2 > y1) { // x1=x2, y inc
if (y1 < this.top)
y1 = this.top;
if (y2 > this.bottom)
y2 = this.bottom;
pbackstore = y1 * this.width + x1;
for (i = 0; i < y2 - y1; i++) {
rop.do_pixel(opcode, backstore, x1, y1 + i, color);
pbackstore += this.width;
}
repaint(x1, y1, 1, y2 - y1 + 1);
} else { // x1=x2, y dec
if (y2 < this.top)
y2 = this.top;
if (y1 > this.bottom)
y1 = this.bottom;
pbackstore = y1 * this.width + x1;
for (i = 0; i < y1 - y2; i++) {
rop.do_pixel(opcode, backstore, x1, y2 + i, color);
pbackstore -= this.width;
}
repaint(x1, y2, 1, y1 - y2 + 1);
}
}
}
// if(logger.isInfoEnabled()) logger.info("line
// \t(\t"+x1+",\t"+y1+"),(\t"+x2+",\t"+y2+")");
}
/**
* Draw a line to the screen
*
* @param line
* LineOrder describing line to be drawn
*/
public void drawLineOrder(LineOrder line) {
int x1 = line.getStartX();
int y1 = line.getStartY();
int x2 = line.getEndX();
int y2 = line.getEndY();
int fgcolor = line.getPen().getColor();
int opcode = line.getOpcode() - 1;
drawLine(x1, y1, x2, y2, fgcolor, opcode);
}
/**
* Perform a dest blt
*
* @param destblt
* DestBltOrder describing the blit to be performed
*/
public void drawDestBltOrder(DestBltOrder destblt) {
int x = destblt.getX();
int y = destblt.getY();
if (x > this.right || y > this.bottom)
return; // off screen
int cx = destblt.getCX();
int cy = destblt.getCY();
int clipright = x + cx - 1;
if (clipright > this.right)
clipright = this.right;
if (x < this.left)
x = this.left;
cx = clipright - x + 1;
int clipbottom = y + cy - 1;
if (clipbottom > this.bottom)
clipbottom = this.bottom;
if (y < this.top)
y = this.top;
cy = clipbottom - y + 1;
rop.do_array(destblt.getOpcode(), backstore, this.width, x, y, cx, cy,
null, 0, 0, 0);
this.repaint(x, y, cx, cy);
}
/**
* Perform a screen blit
*
* @param screenblt
* ScreenBltOrder describing the blit to be performed
*/
public void drawScreenBltOrder(ScreenBltOrder screenblt) {
int x = screenblt.getX();
int y = screenblt.getY();
if (x > this.right || y > this.bottom)
return; // off screen
int cx = screenblt.getCX();
int cy = screenblt.getCY();
int srcx = screenblt.getSrcX();
int srcy = screenblt.getSrcY();
int clipright = x + cx - 1;
if (clipright > this.right)
clipright = this.right;
if (x < this.left)
x = this.left;
cx = clipright - x + 1;
int clipbottom = y + cy - 1;
if (clipbottom > this.bottom)
clipbottom = this.bottom;
if (y < this.top)
y = this.top;
cy = clipbottom - y + 1;
srcx += x - screenblt.getX();
srcy += y - screenblt.getY();
rop.do_array(screenblt.getOpcode(), backstore, this.width, x, y, cx,
cy, null, this.width, srcx, srcy);
this.repaint(x, y, cx, cy);
}
/**
* Perform a memory blit
*
* @param memblt
* MemBltOrder describing the blit to be performed
*/
public void drawMemBltOrder(MemBltOrder memblt) {
int x = memblt.getX();
int y = memblt.getY();
if (x > this.right || y > this.bottom)
return; // off screen
int cx = memblt.getCX();
int cy = memblt.getCY();
int srcx = memblt.getSrcX();
int srcy = memblt.getSrcY();
// 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;
srcx += x - memblt.getX();
srcy += y - memblt.getY();
if (logger.isInfoEnabled())
logger.info("MEMBLT x=" + x + " y=" + y + " cx=" + cx + " cy=" + cy
+ " srcx=" + srcx + " srcy=" + srcy + " opcode="
+ memblt.getOpcode());
try {
Bitmap bitmap = cache.getBitmap(memblt.getCacheID(), memblt
.getCacheIDX());
// IndexColorModel cm = cache.get_colourmap(memblt.getColorTable());
// should use the colormap, but requires high color backstore...
rop.do_array(memblt.getOpcode(), backstore, this.width, x, y, cx,
cy, bitmap.getBitmapData(), bitmap.getWidth(), srcx, srcy);
this.repaint(x, y, cx, cy);
} catch (RdesktopException e) {
}
}
/**
* Draw a pattern to the screen (pattern blit)
*
* @param opcode
* Code defining operation to be performed
* @param x
* x coordinate for left of blit area
* @param y
* y coordinate for top of blit area
* @param cx
* Width of blit area
* @param cy
* Height of blit area
* @param fgcolor
* Foreground colour for pattern
* @param bgcolor
* Background colour for pattern
* @param brush
* Brush object defining pattern to be drawn
*/
public void patBltOrder(int opcode, int x, int y, int cx, int cy,
int fgcolor, int bgcolor, Brush brush) {
// 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;
int i;
int[] src = null;
switch (brush.getStyle()) {
case 0: // solid
// make efficient version of rop later with int fgcolor and boolean
// usearray set to false for single colour
src = new int[cx * cy];
for (i = 0; i < src.length; i++)
src[i] = fgcolor;
rop.do_array(opcode, backstore, this.width, x, y, cx, cy, src, cx,
0, 0);
this.repaint(x, y, cx, cy);
break;
case 2: // hatch
System.out.println("hatch");
break;
case 3: // pattern
int brushx = brush.getXOrigin();
int brushy = brush.getYOrigin();
byte[] pattern = brush.getPattern();
byte[] ipattern = pattern;
/*
* // not sure if this inversion is needed byte[] ipattern = new
* byte[8]; for(i=0;i<ipattern.length;i++) {
* ipattern[ipattern.length-1-i] = pattern[i]; }
*/
src = new int[cx * cy];
int psrc = 0;
for (i = 0; i < cy; i++) {
for (int j = 0; j < cx; j++) {
if ((ipattern[(i + brushy) % 8] & (0x01 << ((j + brushx) % 8))) == 0)
src[psrc] = fgcolor;
else
src[psrc] = bgcolor;
psrc++;
}
}
rop.do_array(opcode, backstore, this.width, x, y, cx, cy, src, cx,
0, 0);
this.repaint(x, y, cx, cy);
break;
default:
logger.warn("Unsupported brush style " + brush.getStyle());
}
}
/**
* Perform a pattern blit on the screen
*
* @param patblt
* PatBltOrder describing the blit to be performed
*/
public void drawPatBltOrder(PatBltOrder patblt) {
Brush brush = patblt.getBrush();
int x = patblt.getX();
int y = patblt.getY();
if (x > this.right || y > this.bottom)
return; // off screen
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -