X Tutup
Skip to content

Commit a6752c9

Browse files
author
zhourenjian
committed
Add Image drawing support basing on GC using DIV elements
1 parent 5582333 commit a6752c9

File tree

2 files changed

+95
-22
lines changed
  • sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/graphics

2 files changed

+95
-22
lines changed

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/graphics/GC.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ public GC(Drawable drawable, int style) {
151151
} else if (drawable instanceof Image) {
152152
Image img = (Image) drawable;
153153
handle = img.handle;
154+
img.gcDrawn = true;
155+
img.drawings = new int[0][5];
154156
} else {
155157
handle = document.createElement("DIV");
156158
handle.style.position = "absolute";
157159
}
160+
this.drawable = drawable;
158161
}
159162

160163
static int checkStyle(int style) {
@@ -1678,18 +1681,20 @@ public void drawRectangle (int x, int y, int width, int height) {
16781681
OS.Rectangle (handle, x, y, x + width + 1, y + height + 1);
16791682
OS.SelectObject (handle, hOld);
16801683
*/
1681-
Element rect = document.createElement("DIV");
1682-
rect.style.position = "absolute";
1683-
rect.style.fontSize = "0px";
1684-
rect.style.left = x + "px";
1685-
rect.style.top = y + "px";
1686-
rect.style.width = width + "px";
1687-
rect.style.height = height + "px";
1688-
if (fgColor != null)
1689-
rect.style.borderColor = fgColor.getCSSHandle();
1690-
rect.style.borderStyle = "solid";
1691-
rect.style.borderWidth = "1px";
1692-
handle.appendChild(rect);
1684+
if (drawable instanceof Image) {
1685+
int[] drawing = new int[5];
1686+
drawing[0] = 1;
1687+
drawing[1] = x;
1688+
drawing[2] = y;
1689+
drawing[3] = width;
1690+
drawing[4] = height;
1691+
/**
1692+
* @j2sNative
1693+
* drawing[5] = this.fgColor == null ? "black" : this.fgColor.getCSSHandle();
1694+
*/ {}
1695+
Image image = (Image) this.drawable;
1696+
image.drawings[image.drawings.length] = drawing;
1697+
}
16931698
}
16941699

16951700
/**
@@ -2544,14 +2549,20 @@ public void fillRectangle (int x, int y, int width, int height) {
25442549
int dwRop = rop2 == OS.R2_XORPEN ? OS.PATINVERT : OS.PATCOPY;
25452550
OS.PatBlt(handle, x, y, width, height, dwRop);
25462551
*/
2547-
Element rect = document.createElement("DIV");
2548-
rect.style.position = "absolute";
2549-
rect.style.left = x + "px";
2550-
rect.style.top = y + "px";
2551-
rect.style.width = width + "px";
2552-
rect.style.height = height + "px";
2553-
rect.style.backgroundColor = bgColor.getCSSHandle();
2554-
handle.appendChild(rect);
2552+
if (drawable instanceof Image) {
2553+
int[] drawing = new int[5];
2554+
drawing[0] = 2;
2555+
drawing[1] = x;
2556+
drawing[2] = y;
2557+
drawing[3] = width;
2558+
drawing[4] = height;
2559+
/**
2560+
* @j2sNative
2561+
* drawing[5] = this.bgColor == null ? "white" : this.bgColor.getCSSHandle();
2562+
*/ {}
2563+
Image image = (Image) this.drawable;
2564+
image.drawings[image.drawings.length] = drawing;
2565+
}
25552566
}
25562567

25572568
/**

sources/net.sf.j2s.java.org.eclipse.swt/src/org/eclipse/swt/graphics/Image.java

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.swt.SWT;
1515
import org.eclipse.swt.SWTError;
1616
import org.eclipse.swt.SWTException;
17+
import org.eclipse.swt.internal.browser.OS;
1718
import org.eclipse.swt.internal.xhtml.Element;
1819
import org.eclipse.swt.internal.xhtml.document;
1920

@@ -90,7 +91,7 @@ public class Image extends Resource implements Drawable {
9091

9192
public int width;
9293
public int height;
93-
private Element imgHandle;
94+
//private Element imgHandle;
9495

9596

9697
/**
@@ -111,6 +112,10 @@ public class Image extends Resource implements Drawable {
111112
*/
112113
public Element handle;
113114

115+
public boolean gcDrawn = false;
116+
117+
public int[][] drawings;
118+
114119
/**
115120
* specifies the transparent pixel
116121
*/
@@ -200,7 +205,7 @@ void init(Device device, int width, int height) {
200205
handle.style.height = height + "px";
201206
// imgHandle = document.createElement("IMG");
202207
// handle.appendChild(imgHandle);
203-
imgHandle = handle;
208+
// imgHandle = handle;
204209
// imgHandle.width = width;
205210
// imgHandle.height = height;
206211
// imgHandle.src = url;
@@ -2134,6 +2139,63 @@ public String toString () {
21342139
return "Image {" + handle + "}";
21352140
}
21362141

2142+
public void draw(Element handle) {
2143+
OS.clearChildren(handle);
2144+
if (drawings != null) {
2145+
Element rect = null;
2146+
for (int i = 0; i < this.drawings.length; i++) {
2147+
int[] drawing = this.drawings[i];
2148+
int type = drawing[0];
2149+
switch (type) {
2150+
case 1:
2151+
rect = document.createElement("DIV");
2152+
rect.style.position = "absolute";
2153+
rect.style.fontSize = "0";
2154+
rect.style.left = drawing[1] + "px";
2155+
if (OS.isFirefox && handle.nodeName == "BUTTON") {
2156+
rect.style.top = (drawing[2] - drawing[4] / 2 - 3) + "px";
2157+
} else {
2158+
rect.style.top = drawing[2] + "px";
2159+
}
2160+
rect.style.width = drawing[3] + "px";
2161+
rect.style.height = drawing[4] + "px";
2162+
rect.style.borderColor = "" + drawing[5];
2163+
rect.style.borderStyle = "solid";
2164+
rect.style.borderWidth = "1px";
2165+
handle.appendChild(rect);
2166+
break;
2167+
case 2:
2168+
rect = document.createElement("DIV");
2169+
rect.style.position = "absolute";
2170+
rect.style.fontSize = "0";
2171+
rect.style.left = drawing[1] + "px";
2172+
if (OS.isFirefox) {
2173+
rect.style.top = (drawing[2] - drawing[4] / 2 - 1) + "px";
2174+
} else {
2175+
rect.style.top = drawing[2] + "px";
2176+
}
2177+
rect.style.width = drawing[3] + "px";
2178+
rect.style.height = drawing[4] + "px";
2179+
rect.style.backgroundColor = "" + drawing[5];
2180+
handle.appendChild(rect);
2181+
break;
2182+
default:
2183+
;
2184+
}
2185+
}
2186+
} else {
2187+
Element rect = document.createElement("DIV");
2188+
rect.style.position = "absolute";
2189+
rect.style.fontSize = "0";
2190+
rect.style.left = 0 + "px";
2191+
rect.style.top = 0 + "px";
2192+
rect.style.width = width + "px";
2193+
rect.style.height = height + "px";
2194+
rect.style.backgroundColor = "black";
2195+
handle.appendChild(rect);
2196+
}
2197+
}
2198+
21372199
/*
21382200
/**
21392201
* Invokes platform specific functionality to allocate a new image.

0 commit comments

Comments
 (0)
X Tutup