List of usage examples for java.awt Graphics setPaintMode
public abstract void setPaintMode();
From source file:MainClass.java
public void paint(Graphics g) { int w = getSize().width; int midW = w / 2; g.drawString("XOR Mode", 0, 30); g.drawOval(7, 37, 50, 50);/*ww w . ja va 2 s. c o m*/ g.setXORMode(Color.white); for (int i = 0; i < 15; i += 3) { g.drawOval(10 + i, 40 + i, 50, 50); } g.setPaintMode(); g.drawString("Paint Mode", midW, 30); g.drawOval(midW + 7, 37, 50, 50); for (int i = 0; i < 15; i += 3) { g.drawOval(midW + 10 + i, 40 + i, 50, 50); } }
From source file:Main.java
public void paint(Graphics g) { int w = getSize().width; int midW = w / 2; g.drawString("XOR Mode", 0, 30); g.drawOval(7, 37, 50, 50);/* w w w .j a v a 2 s . c o m*/ g.setXORMode(Color.white); for (int i = 0; i < 15; i += 3) { g.drawOval(10 + i, 40 + i, 50, 50); } g.setPaintMode(); g.drawString("Paint Mode", midW, 30); g.drawOval(midW + 7, 37, 50, 50); for (int i = 0; i < 15; i += 3) { g.drawOval(midW + 10 + i, 40 + i, 50, 50); } }
From source file:XORModePaintWithMouse.java
public void paint(Graphics g) { g.drawLine(0, 0, 100, 100);//from w ww . ja v a 2 s .c o m g.drawLine(0, 100, 100, 0); g.setColor(Color.blue); g.drawLine(40, 25, 250, 180); g.drawLine(75, 90, 400, 400); g.setColor(Color.green); // xor cross hairs g.setXORMode(Color.black); g.drawLine(chsX - 10, chsY, chsX + 10, chsY); g.drawLine(chsX, chsY - 10, chsX, chsY + 10); g.setPaintMode(); }
From source file:com.jcraft.weirdx.Draw.java
static void reqFillPolyArc(Client c, XDrawable d, GC gc) throws IOException { //int foo;/*from ww w . ja v a 2s. com*/ int n = c.length; InputOutput io = c.client; Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { io.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { io.readPad(n * 4); return; } } n *= 4; short x, y, a1, a2; int width, height; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; while (n != 0) { x = (short) io.readShort(); y = (short) io.readShort(); if (x < sx) sx = x; if (y < sy) sy = y; width = io.readShort(); height = io.readShort(); if (lx < x + width) lx = x + width; if (ly < y + height) ly = y + height; a1 = (short) io.readShort(); a2 = (short) io.readShort(); n -= 12; graphics.fillArc(x, y, width, height, a1 / 64, a2 / 64); } if (d instanceof XWindow) { if (sx < 0) sx = 0; if (sy < 0) sy = 0; ((XWindow) d).draw(sx, sy, lx - sx + 2, ly - sy + 2); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolyArc(Client c, XDrawable d, GC gc) throws IOException { //int foo;// w ww . j a v a 2 s.co m int n = c.length; InputOutput io = c.client; Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode | GC.GCLineWidth); if (graphics == null) { io.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { io.readPad(n * 4); return; } } n *= 4; short x, y, a1, a2; int width, height; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; while (n != 0) { x = (short) io.readShort(); y = (short) io.readShort(); if (x < sx) sx = x; if (y < sy) sy = y; width = /*(short)*/io.readShort(); height = /*(short)*/io.readShort(); if (lx < x + width) lx = x + width; if (ly < y + height) ly = y + height; a1 = (short) io.readShort(); a2 = (short) io.readShort(); n -= 12; graphics.drawArc(x, y, width, height, a1 / 64, a2 / 64); } if (d instanceof XWindow) { if (sx < 0) sx = 0; if (sy < 0) sy = 0; ((XWindow) d).draw(sx, sy, lx - sx + 2, ly - sy + 2); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.Draw.java
static void reqImageText16(Client c, XDrawable d, GC gc, int x, int y) throws IOException { int len = c.data; int n = c.length; //int foo;// w w w. java 2 s . co m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCFont); if (graphics == null) { c.client.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } XFont font = gc.font; n *= 4; c.client.readByte(c.bbuffer, 0, n); len *= 2; if (font.encoding != null) { len = font.encode(c.bbuffer, 0, len, c.cbuffer); if (len == 0) { return; } } else { for (int i = 0; i < len; i++) { c.cbuffer[i] = (char) (c.bbuffer[i] & 0xff); } for (int i = 0; i < len; i++) { if (c.cbuffer[i] != 0) { c.cbuffer[i / 2] = c.cbuffer[i]; } } len /= 2; } { Color tmp = graphics.getColor(); graphics.setColor(d.getColormap().getColor(gc.bgPixel)); graphics.fillRect(x, y - (font.ascent), font.charsWidth(c.cbuffer, 0, len), font.ascent + font.descent); graphics.setColor(tmp); graphics.drawChars(c.cbuffer, 0, len, x, y); } if (d instanceof XWindow) { ((XWindow) d).draw(x, y - (font.ascent), font.charsWidth(c.cbuffer, 0, len), font.ascent + font.descent); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolyRectangle(Client c, XDrawable d, GC gc) throws IOException { int n = c.length; //int foo;//from www. j ava2 s.c o m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { c.client.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } n /= 2; short x, y; int ww, hh; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; while (n != 0) { x = (short) c.client.readShort(); y = (short) c.client.readShort(); ww = c.client.readShort(); hh = c.client.readShort(); if (x < sx) sx = x; if (lx < x + ww) lx = x + ww; if (y < sy) sy = y; if (ly < y + hh) ly = y + hh; if (gc.lineWidth > 1) { int l2 = gc.lineWidth / 2; x -= l2; y -= l2; ww += gc.lineWidth; hh += gc.lineWidth; for (int i = 0; i < gc.lineWidth; i++) { ww -= 2; hh -= 2; x += 1; y += 1; graphics.drawRect(x, y, ww, hh); } } else { graphics.drawRect(x, y, ww, hh); } n--; } if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 2, ly - sy + 2); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.Draw.java
@SuppressWarnings("unused") static void reqFillPoly(Client c, XDrawable d, GC gc) throws IOException { int n = c.length; int foo;//from w w w. j av a 2s. c o m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { c.client.readPad(n * 4); return; } byte shape; shape = (byte) c.client.readByte(); byte cmode; cmode = (byte) c.client.readByte(); c.client.readPad(2); n--; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } short x, y; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; if (c.xarray.length < n) { c.xarray = new int[n]; c.yarray = new int[n]; } foo = c.xarray[0] = (short) c.client.readShort(); if (foo < sx) sx = foo; if (lx < foo) lx = foo; foo = c.yarray[0] = (short) c.client.readShort(); if (foo < sy) sy = foo; if (ly < foo) ly = foo; for (int i = 1; i < n; i++) { c.xarray[i] = (short) c.client.readShort(); c.yarray[i] = (short) c.client.readShort(); if (cmode == 1) { c.xarray[i] += c.xarray[i - 1]; c.yarray[i] += c.yarray[i - 1]; } foo = c.xarray[i]; if (foo < sx) sx = foo; if (lx < foo) lx = foo; foo = c.yarray[i]; if (foo < sy) sy = foo; if (ly < foo) ly = foo; } graphics.fillPolygon(c.xarray, c.yarray, n); if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolyPoint(Client c, XDrawable d, GC gc) throws IOException { // int foo;/*from ww w. ja v a 2s . c om*/ int n = c.length; InputOutput io = c.client; Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { io.readPad(n * 4); return; } boolean coor = false; if (c.data != 0) coor = true; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { io.readPad(4 * n); return; } } int x, y; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; if (coor) { x = (short) io.readShort(); y = (short) io.readShort(); n--; graphics.drawLine(x, y, x, y); if (x <= sx) sx = x; if (x >= lx) lx = x; if (y <= sy) sy = y; if (y >= ly) ly = y; while (n != 0) { x += (short) io.readShort(); y += (short) io.readShort(); n--; graphics.drawLine(x, y, x, y); if (x <= sx) sx = x; if (x >= lx) lx = x; if (y <= sy) sy = y; if (y >= ly) ly = y; } } else { while (n != 0) { x = (short) io.readShort(); y = (short) io.readShort(); n--; graphics.drawLine(x, y, x, y); if (x <= sx) sx = x; if (x >= lx) lx = x; if (y <= sy) sy = y; if (y >= ly) ly = y; } } if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolyLine(Client c, XDrawable d, GC gc) throws IOException { int n = c.length; int foo;//from w w w .j a v a 2 s.c o m Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode | GC.GCLineWidth); if (graphics == null) { c.client.readPad(n * 4); return; } int mode = c.data; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } //short x, y; if (c.xarray.length < n) { c.xarray = new int[n]; c.yarray = new int[n]; } int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; foo = c.xarray[0] = (short) c.client.readShort(); if (foo <= sx) sx = foo; if (foo >= lx) lx = foo; foo = c.yarray[0] = (short) c.client.readShort(); if (foo <= sy) sy = foo; if (foo >= ly) ly = foo; for (int i = 1; i < n; i++) { c.xarray[i] = (short) c.client.readShort(); c.yarray[i] = (short) c.client.readShort(); if (mode == 1) { c.xarray[i] += c.xarray[i - 1]; c.yarray[i] += c.yarray[i - 1]; } foo = c.xarray[i]; if (foo <= sx) sx = foo; if (foo >= lx) lx = foo; foo = c.yarray[i]; if (foo <= sy) sy = foo; if (foo >= ly) ly = foo; } if (gc.lineWidth > 1 && n > 1) { --n; for (int i = 0; i < n; i++) { int j = i + 1; drawThickLine(graphics, c.xarray[i], c.yarray[i], c.xarray[j], c.yarray[j], gc.lineWidth); } } else graphics.drawPolyline(c.xarray, c.yarray, n); if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } else { ((XPixmap) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }