id
int64
22
34.9k
comment_id
int64
0
328
comment
stringlengths
2
2.55k
code
stringlengths
31
107k
classification
stringclasses
6 values
isFinished
bool
1 class
code_context_2
stringlengths
21
27.3k
code_context_10
stringlengths
29
27.3k
code_context_20
stringlengths
29
27.3k
32,108
11
// 4.2.1 remove old adjacents (crossing triangle hole)
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
} } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1;
tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) {
edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } }
32,108
12
// TODO: performance
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
DESIGN
true
tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) {
for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent);
if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i));
32,108
13
// TODO: make faster
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
DESIGN
true
} } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); }
Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) {
int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else {
32,108
14
// 4.3 Stitch holes using edge
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
} } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size());
removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0;
for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb);
32,108
15
// Update adjacents map
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb);
Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID);
int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair);
32,108
16
// find out which triangle got deleted
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle);
} else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else {
vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else {
32,108
17
// TODO: just relevant for first iteration, move before loop
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
DESIGN
true
oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle));
if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID),
norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1))
32,108
18
// TODO: just relevant for last iteration
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else {
if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) {
tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
32,108
19
// 5. Assign all points of all light-faces to the new created faces
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) {
oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
32,108
20
// 6. Push new created faces on the stack and start at (1))
private static boolean step(int faceIndex) { Triangle t = faces.get(faceIndex); // 2. Get most distant point of the face's point set Vector3f furthestPoint = null; int furthestPointID = -1; Vector3f A = vertices.get(t.a); List<Vector3f> facepoints = listsOfFacePoints.get(faceIndex); float distance = 0; for (int i = 0; i < facepoints.size(); i++) { Vector3f P = facepoints.get(i); float dist = VecMath.dotproduct(VecMath.subtraction(P, A, tmpvec), t.normal); if (dist >= distance) { distance = dist; furthestPoint = P; furthestPointID = i; } } if (furthestPointID == -1 || vertices.contains(furthestPoint)) { // TODO: check return true; } facepoints.remove(furthestPointID); vertices.add(furthestPoint); furthestPointID = vertices.size() - 1; lastremovedTriangles.clear(); lastremovedTriangles.add(faces.remove(faceIndex)); listsOfFacePoints.remove(faceIndex); // 3. Find all faces that can be seen from this point HashSet<Integer> lightFaceVertices = new HashSet<Integer>(); // HAS TO BE REINITIALIZED... don't ask why. lightFaceVertices.add(t.a); lightFaceVertices.add(t.b); lightFaceVertices.add(t.c); List<Triangle> vertsA = new ArrayList<Triangle>(); List<Triangle> vertsB = new ArrayList<Triangle>(); List<Triangle> vertsC = new ArrayList<Triangle>(); vertsA.add(t); vertsB.add(t); vertsC.add(t); lightFaceVerticesToTriangles.clear(); lightFaceVerticesToTriangles.put(t.a, vertsA); lightFaceVerticesToTriangles.put(t.b, vertsB); lightFaceVerticesToTriangles.put(t.c, vertsC); for (int i = faces.size() - 1; i >= 0; i--) { Triangle tri = faces.get(i); Vector3f triA = vertices.get(tri.a); if (VecMath.dotproduct(tri.normal, VecMath.subtraction(furthestPoint, triA, tmpvec)) > 0) { lastremovedTriangles.add(faces.remove(i)); lightFaceVertices.add(tri.a); lightFaceVertices.add(tri.b); lightFaceVertices.add(tri.c); if ((vertsA = lightFaceVerticesToTriangles.get(tri.a)) != null) { vertsA.add(tri); } else { vertsA = new ArrayList<Triangle>(); vertsA.add(tri); lightFaceVerticesToTriangles.put(tri.a, vertsA); } if ((vertsB = lightFaceVerticesToTriangles.get(tri.b)) != null) { vertsB.add(tri); } else { vertsB = new ArrayList<Triangle>(); vertsB.add(tri); lightFaceVerticesToTriangles.put(tri.b, vertsB); } if ((vertsC = lightFaceVerticesToTriangles.get(tri.c)) != null) { vertsC.add(tri); } else { vertsC = new ArrayList<Triangle>(); vertsC.add(tri); lightFaceVerticesToTriangles.put(tri.c, vertsC); } facepoints.addAll(listsOfFacePoints.remove(i)); } } // 4.0 Remove all vertices that are only connected to lightFaceVertices Iterator<Integer> iter = lightFaceVertices.iterator(); toRemove.clear(); for (int i = 0; i < lightFaceVertices.size(); i++) { int vert = iter.next(); // TODO: check if (lightFaceVerticesToTriangles.get(vert).size() == adjacentsMap.get(vert).size()) { toRemove.add(vert); } } for (Integer i : toRemove) { for (Integer adj : adjacentsMap.get(i)) { adjacentsMap.get(adj).remove(i); tmppair.set(i, adj); edgesToTriangles.remove(tmppair); } lightFaceVertices.remove((int) i); vertices.set((int) i, null); freeVertexPositions.add(i); } // 4.1 Get vertices on border between lit and unlit triangles HashSet<Integer> vertsOnEdge = new HashSet<Integer>(); // HAS TO BE REINITIALIZED for (Integer vert : lightFaceVertices) { vertsOnEdge.add(vert); } // 4.2 Get edges on border int currentVert = vertsOnEdge.iterator().next(); edge.clear(); // TODO: make HashSet (no! has to be ordered list!) for (int i = 0; i < vertsOnEdge.size(); i++) { edge.add(currentVert); ArrayList<Integer> adjs = adjacentsMap.get(currentVert); List<Triangle> vertexLightTriangles = lightFaceVerticesToTriangles.get(currentVert); for (int j = 0; j < adjs.size(); j++) { Integer currAdj = adjs.get(j); if (vertsOnEdge.contains(currAdj) && !edge.contains(currAdj)) { int tricount = 0; for (int k = 0; k < vertexLightTriangles.size() && tricount < 2; k++) { Triangle kTri = vertexLightTriangles.get(k); if (kTri.a == currAdj || kTri.b == currAdj || kTri.c == currAdj) { tricount++; } } if (tricount == 1) { currentVert = currAdj; break; } } } } // 4.2.1 remove old adjacents (crossing triangle hole) int edgesize = edge.size(); int edgesizeMinusOne = edgesize - 1; for (int i = 0; i < edgesize; i++) { currentVert = edge.get(i); removeAdj.clear(); for (Integer adj : adjacentsMap.get(currentVert)) { if (edge.contains(adj)) { int adjIndexOnEdge = edge.indexOf(adj); if (Math.abs(i - adjIndexOnEdge) > 1 && !(i == 0 && adjIndexOnEdge == edgesizeMinusOne) && !(i == edgesizeMinusOne && adjIndexOnEdge == 0)) { tmppair.set(currentVert, adj); Pair<Triangle, Triangle> edgeTriangles = edgesToTriangles.get(tmppair); // TODO: performance if (lastremovedTriangles.contains(edgeTriangles.getFirst()) && lastremovedTriangles.contains(edgeTriangles.getSecond())) { removeAdj.add(adj); edgesToTriangles.remove(edgeTriangles); } } } } for (Integer removAdjacent : removeAdj) { // TODO: make faster adjacentsMap.get(currentVert).remove(removAdjacent); } } // 4.3 Stitch holes using edge newLightFaces.clear(); ArrayList<Integer> furthestPointNeighbours = new ArrayList<Integer>(edge.size()); A = vertices.get(edge.get(0)); Vector3f B = vertices.get(edge.get(1)); Vector3f C = vertices.get(edge.get(2)); for (int i = 3; i < edge.size() && !linearIndependent(A, B, C); i++) { C = vertices.get(edge.get(i)); } Vector3f normal = VecMath.computeNormal(A, B, C); boolean correctOrientation = VecMath.dotproduct(normal, VecMath.subtraction(A, furthestPoint, tmpvec)) < 0; int vertIDb = edge.get(0); for (int i = 0; i < edge.size(); i++) { int vertIDa = vertIDb; if (i < edge.size() - 1) { vertIDb = edge.get(i + 1); } else { vertIDb = edge.get(0); } Vector3f vA = vertices.get(vertIDa); Vector3f vB = vertices.get(vertIDb); Vector3f norm = VecMath.computeNormal(vA, vB, furthestPoint); Triangle stitchTriangle; if (correctOrientation) { stitchTriangle = new Triangle(vertIDa, vertIDb, furthestPointID, norm); } else { norm.negate(); stitchTriangle = new Triangle(vertIDa, furthestPointID, vertIDb, norm); } faces.add(0, stitchTriangle); newLightFaces.add(stitchTriangle); // Update adjacents map adjacentsMap.get(vertIDa).add(furthestPointID); tmppair.set(vertIDa, vertIDb); Pair<Triangle, Triangle> oldEdgeInfo = edgesToTriangles.get(tmppair); // find out which triangle got deleted if (lastremovedTriangles.contains(oldEdgeInfo.getFirst())) { oldEdgeInfo.setFirst(stitchTriangle); } else { oldEdgeInfo.setSecond(stitchTriangle); } tmppair.set(vertIDa, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { oldEdgeInfo.setSecond(stitchTriangle); } else { // TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
NONSATD
true
listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
// TODO: just relevant for first iteration, move before loop edgesToTriangles.put(new Pair<Integer, Integer>(vertIDa, furthestPointID), new Pair<Triangle, Triangle>(null, stitchTriangle)); } tmppair.set(vertIDb, furthestPointID); oldEdgeInfo = edgesToTriangles.get(tmppair); if (oldEdgeInfo != null) { // TODO: just relevant for last iteration oldEdgeInfo.setFirst(stitchTriangle); } else { edgesToTriangles.put(new Pair<Integer, Integer>(vertIDb, furthestPointID), new Pair<Triangle, Triangle>(stitchTriangle, null)); } furthestPointNeighbours.add(vertIDa); } // 5. Assign all points of all light-faces to the new created faces adjacentsMap.put(furthestPointID, furthestPointNeighbours); for (Triangle tri : newLightFaces) { listsOfFacePoints.add(0, getLightPoints(tri, facepoints)); } // 6. Push new created faces on the stack and start at (1)) return false; }
32,113
0
/** * Sorts the entries of the specified node according to their minimum distance * to the specified object. * * @param node the node * @param q the query object * @param distanceFunction the distance function for computing the distances * @return a list of the sorted entries */ // TODO: move somewhere else?
protected List<DoubleObjPair<RdKNNEntry>> getSortedEntries(AbstractRStarTreeNode<?, ?> node, SpatialComparable q, SpatialPrimitiveDistanceFunction<?> distanceFunction) { List<DoubleObjPair<RdKNNEntry>> result = new ArrayList<>(); for(int i = 0; i < node.getNumEntries(); i++) { RdKNNEntry entry = (RdKNNEntry) node.getEntry(i); double minDist = distanceFunction.minDist(entry, q); result.add(new DoubleObjPair<>(minDist, entry)); } Collections.sort(result); return result; }
DESIGN
true
protected List<DoubleObjPair<RdKNNEntry>> getSortedEntries(AbstractRStarTreeNode<?, ?> node, SpatialComparable q, SpatialPrimitiveDistanceFunction<?> distanceFunction) { List<DoubleObjPair<RdKNNEntry>> result = new ArrayList<>(); for(int i = 0; i < node.getNumEntries(); i++) { RdKNNEntry entry = (RdKNNEntry) node.getEntry(i); double minDist = distanceFunction.minDist(entry, q); result.add(new DoubleObjPair<>(minDist, entry)); } Collections.sort(result); return result; }
protected List<DoubleObjPair<RdKNNEntry>> getSortedEntries(AbstractRStarTreeNode<?, ?> node, SpatialComparable q, SpatialPrimitiveDistanceFunction<?> distanceFunction) { List<DoubleObjPair<RdKNNEntry>> result = new ArrayList<>(); for(int i = 0; i < node.getNumEntries(); i++) { RdKNNEntry entry = (RdKNNEntry) node.getEntry(i); double minDist = distanceFunction.minDist(entry, q); result.add(new DoubleObjPair<>(minDist, entry)); } Collections.sort(result); return result; }
protected List<DoubleObjPair<RdKNNEntry>> getSortedEntries(AbstractRStarTreeNode<?, ?> node, SpatialComparable q, SpatialPrimitiveDistanceFunction<?> distanceFunction) { List<DoubleObjPair<RdKNNEntry>> result = new ArrayList<>(); for(int i = 0; i < node.getNumEntries(); i++) { RdKNNEntry entry = (RdKNNEntry) node.getEntry(i); double minDist = distanceFunction.minDist(entry, q); result.add(new DoubleObjPair<>(minDist, entry)); } Collections.sort(result); return result; }
15,732
0
// TODO how to react to failure status of DCEVStatus of cableCheckReq? /* * TODO we need a timeout mechanism here so that a response can be sent within 2s * the DCEVSEStatus should be generated according to already available values * (if EVSEProcessing == ONGOING, maybe because of EVSE_IsolationMonitoringActive, * within a certain timeout, then the status must be different) */
@Override public ReactionToIncomingMessage processIncomingMessage(Object message) { if (isIncomingMessageValid(message, CableCheckReqType.class, cableCheckRes)) { V2GMessage v2gMessageReq = (V2GMessage) message; CableCheckReqType cableCheckReq = (CableCheckReqType) v2gMessageReq.getBody().getBodyElement().getValue(); // TODO how to react to failure status of DCEVStatus of cableCheckReq? /* * TODO we need a timeout mechanism here so that a response can be sent within 2s * the DCEVSEStatus should be generated according to already available values * (if EVSEProcessing == ONGOING, maybe because of EVSE_IsolationMonitoringActive, * within a certain timeout, then the status must be different) */ setEvseProcessingFinished(true); if (isEvseProcessingFinished()) { cableCheckRes.setEVSEProcessing(EVSEProcessingType.FINISHED); cableCheckRes.setDCEVSEStatus( ((IDCEVSEController) getCommSessionContext().getDCEvseController()).getDCEVSEStatus(EVSENotificationType.NONE) ); return getSendMessage(cableCheckRes, V2GMessages.PRE_CHARGE_REQ); } else { cableCheckRes.setEVSEProcessing(EVSEProcessingType.ONGOING); return getSendMessage(cableCheckRes, V2GMessages.CABLE_CHECK_REQ); } } else { setMandatoryFieldsForFailedRes(); } return getSendMessage(cableCheckRes, V2GMessages.NONE); }
IMPLEMENTATION
true
CableCheckReqType cableCheckReq = (CableCheckReqType) v2gMessageReq.getBody().getBodyElement().getValue(); // TODO how to react to failure status of DCEVStatus of cableCheckReq? /* * TODO we need a timeout mechanism here so that a response can be sent within 2s * the DCEVSEStatus should be generated according to already available values * (if EVSEProcessing == ONGOING, maybe because of EVSE_IsolationMonitoringActive, * within a certain timeout, then the status must be different) */ setEvseProcessingFinished(true); if (isEvseProcessingFinished()) {
@Override public ReactionToIncomingMessage processIncomingMessage(Object message) { if (isIncomingMessageValid(message, CableCheckReqType.class, cableCheckRes)) { V2GMessage v2gMessageReq = (V2GMessage) message; CableCheckReqType cableCheckReq = (CableCheckReqType) v2gMessageReq.getBody().getBodyElement().getValue(); // TODO how to react to failure status of DCEVStatus of cableCheckReq? /* * TODO we need a timeout mechanism here so that a response can be sent within 2s * the DCEVSEStatus should be generated according to already available values * (if EVSEProcessing == ONGOING, maybe because of EVSE_IsolationMonitoringActive, * within a certain timeout, then the status must be different) */ setEvseProcessingFinished(true); if (isEvseProcessingFinished()) { cableCheckRes.setEVSEProcessing(EVSEProcessingType.FINISHED); cableCheckRes.setDCEVSEStatus( ((IDCEVSEController) getCommSessionContext().getDCEvseController()).getDCEVSEStatus(EVSENotificationType.NONE) ); return getSendMessage(cableCheckRes, V2GMessages.PRE_CHARGE_REQ); } else { cableCheckRes.setEVSEProcessing(EVSEProcessingType.ONGOING); return getSendMessage(cableCheckRes, V2GMessages.CABLE_CHECK_REQ);
@Override public ReactionToIncomingMessage processIncomingMessage(Object message) { if (isIncomingMessageValid(message, CableCheckReqType.class, cableCheckRes)) { V2GMessage v2gMessageReq = (V2GMessage) message; CableCheckReqType cableCheckReq = (CableCheckReqType) v2gMessageReq.getBody().getBodyElement().getValue(); // TODO how to react to failure status of DCEVStatus of cableCheckReq? /* * TODO we need a timeout mechanism here so that a response can be sent within 2s * the DCEVSEStatus should be generated according to already available values * (if EVSEProcessing == ONGOING, maybe because of EVSE_IsolationMonitoringActive, * within a certain timeout, then the status must be different) */ setEvseProcessingFinished(true); if (isEvseProcessingFinished()) { cableCheckRes.setEVSEProcessing(EVSEProcessingType.FINISHED); cableCheckRes.setDCEVSEStatus( ((IDCEVSEController) getCommSessionContext().getDCEvseController()).getDCEVSEStatus(EVSENotificationType.NONE) ); return getSendMessage(cableCheckRes, V2GMessages.PRE_CHARGE_REQ); } else { cableCheckRes.setEVSEProcessing(EVSEProcessingType.ONGOING); return getSendMessage(cableCheckRes, V2GMessages.CABLE_CHECK_REQ); } } else { setMandatoryFieldsForFailedRes(); } return getSendMessage(cableCheckRes, V2GMessages.NONE); }
23,927
0
/* * * corpus_%corpusName% = { name: "...", tokenCount: 500, typeCount: 1000, commonTypes: 900, clusterCount: 100, identityEps: 0.00004 iterationCount: 7, typeToId: { typeName:0, typeName2: 1, ... }, idToType: { 1: "word", 4: "bleh", } }; */ /** * */
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
NONSATD
true
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
23,927
1
//TODO add proper number formatters
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
DESIGN
true
s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter));
Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {");
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile));
23,927
2
//TODO see if necessary
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
IMPLEMENTATION
true
s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); }
s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } }
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace();
23,927
3
//No rare word check here, to keep vector status
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
NONSATD
true
s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name));
s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s);
Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
23,927
4
// TODO Auto-generated catch block
public void recordCorpusData (Corpus c, Learner l){ if (!isRecording) return; this.c=c; Vocabulary v = c.getVocabulary(); Set<Map.Entry<String, Integer>> entrySet = v.getWordIndicesEntrySet(); Set<Map.Entry<Integer, Word>> wordSet = v.getWordEntrySet(); StringBuilder s = new StringBuilder(v.getNumOfWords()*30); corpusFile = new File(mainPath, "corpus_"+name+".js"); s.append(String.format("corpus_%1$s = \n{\n\tname:\"%1$s\",\n", name)); s.append(String.format("\ttokenCount: %1$s,\n", c.tokenCount)); s.append(String.format("\ttypeCount: %1$s,\n", v.getNumOfWords())); s.append(String.format("\tcommonTypes: %1$s,\n", (v.getNumOfWords()-v.countWordsBelowThreshold(l.RARE_WORD_THRESHOLD)))); s.append(String.format("\tclusterCount: %1$s,\n", l.NUMBER_OF_CLUSTERS)); //TODO add proper number formatters s.append(String.format("\tidentityEps: %1$s,\n", l.IDENTITY_EPSILON)); s.append(String.format("\titerationCount: %1$s,\n", iterationCounter)); s.append("\ttypeToId: \n\t{\n\t"); for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
DESIGN
true
out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
} } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
for (Map.Entry<String, Integer> e: entrySet){ if (v.getWord(e.getValue()).frequency >= l.RARE_WORD_THRESHOLD){ //TODO see if necessary s.append(String.format("\t\t\"%1$s\": %2$s,\n", e.getKey(), e.getValue())); } } s.append("},\n"); s.append("\tidToType: {"); for (Map.Entry<Integer, Word> e: wordSet){ //No rare word check here, to keep vector status if (e.getValue().frequency >= l.RARE_WORD_THRESHOLD){ s.append(String.format("\t\t%1$s: \"%2$s\",\n",e.getKey(), e.getValue().name)); } } s.append("}"); s.append("\n};"); try { corpusFile.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(corpusFile)); out.append(s); out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
32,148
0
// TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data...
@Override protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false); addTestContact("Jim", "650 123 1233", "[email protected]", false); addTestContact("Samantha", "650-123-1235", "[email protected]", true); addTestContact("Adrienne", "650-123-1236", "[email protected]", true); }
TEST
true
protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts.
@Override protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false); addTestContact("Jim", "650 123 1233", "[email protected]", false); addTestContact("Samantha", "650-123-1235", "[email protected]", true); addTestContact("Adrienne", "650-123-1236", "[email protected]", true); }
@Override protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false); addTestContact("Jim", "650 123 1233", "[email protected]", false); addTestContact("Samantha", "650-123-1235", "[email protected]", true); addTestContact("Adrienne", "650-123-1236", "[email protected]", true); }
32,148
1
// add test contacts.
@Override protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false); addTestContact("Jim", "650 123 1233", "[email protected]", false); addTestContact("Samantha", "650-123-1235", "[email protected]", true); addTestContact("Adrienne", "650-123-1236", "[email protected]", true); }
NONSATD
true
// Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false);
@Override protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false); addTestContact("Jim", "650 123 1233", "[email protected]", false); addTestContact("Samantha", "650-123-1235", "[email protected]", true); addTestContact("Adrienne", "650-123-1236", "[email protected]", true); }
@Override protected void setUp() throws Exception { super.setUp(); // TODO: This test will actually mess with contacts on your phone. // Ideally we would use a fake content provider to give us contact data... FakeFactory.registerWithoutFakeContext(getTestContext()); // add test contacts. addTestContact("John", "650-123-1233", "[email protected]", false); addTestContact("Joe", "(650)123-1233", "[email protected]", false); addTestContact("Jim", "650 123 1233", "[email protected]", false); addTestContact("Samantha", "650-123-1235", "[email protected]", true); addTestContact("Adrienne", "650-123-1236", "[email protected]", true); }
32,149
0
//TODO: this can be improved further to handle large powers
public static int raiseTo(int n, int p) { if (n == 0) { return 0; } if (p == 0) { return 1; } if (n == 1) { return n; } long result = n; int counter = 1; while (counter < p) { if (result * n >= Integer.MAX_VALUE) { return Integer.MAX_VALUE; } result *= n; counter++; } return (int) result; }
DESIGN
true
public static int raiseTo(int n, int p) { if (n == 0) { return 0; } if (p == 0) { return 1; } if (n == 1) { return n; } long result = n; int counter = 1; while (counter < p) { if (result * n >= Integer.MAX_VALUE) { return Integer.MAX_VALUE; } result *= n; counter++; } return (int) result; }
public static int raiseTo(int n, int p) { if (n == 0) { return 0; } if (p == 0) { return 1; } if (n == 1) { return n; } long result = n; int counter = 1; while (counter < p) { if (result * n >= Integer.MAX_VALUE) { return Integer.MAX_VALUE; } result *= n; counter++; } return (int) result; }
public static int raiseTo(int n, int p) { if (n == 0) { return 0; } if (p == 0) { return 1; } if (n == 1) { return n; } long result = n; int counter = 1; while (counter < p) { if (result * n >= Integer.MAX_VALUE) { return Integer.MAX_VALUE; } result *= n; counter++; } return (int) result; }
32,153
0
// TODO Augment the scenes/transitions API to support this.
@Override public void addContentView(View view, ViewGroup.LayoutParams params) { if (mContentParent == null) { installDecor(); } if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { // TODO Augment the scenes/transitions API to support this. Log.v(TAG, "addContentView does not support content transitions"); } mContentParent.addView(view, params); mContentParent.requestApplyInsets(); final Callback cb = getCallback(); if (cb != null && !isDestroyed()) { cb.onContentChanged(); } }
DESIGN
true
} if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { // TODO Augment the scenes/transitions API to support this. Log.v(TAG, "addContentView does not support content transitions"); }
@Override public void addContentView(View view, ViewGroup.LayoutParams params) { if (mContentParent == null) { installDecor(); } if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { // TODO Augment the scenes/transitions API to support this. Log.v(TAG, "addContentView does not support content transitions"); } mContentParent.addView(view, params); mContentParent.requestApplyInsets(); final Callback cb = getCallback(); if (cb != null && !isDestroyed()) { cb.onContentChanged(); } }
@Override public void addContentView(View view, ViewGroup.LayoutParams params) { if (mContentParent == null) { installDecor(); } if (hasFeature(FEATURE_CONTENT_TRANSITIONS)) { // TODO Augment the scenes/transitions API to support this. Log.v(TAG, "addContentView does not support content transitions"); } mContentParent.addView(view, params); mContentParent.requestApplyInsets(); final Callback cb = getCallback(); if (cb != null && !isDestroyed()) { cb.onContentChanged(); } }
15,785
0
// TODO: Try to come up with a generic way of implementing this
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { // TODO: Try to come up with a generic way of implementing this return null; }
DESIGN
true
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { // TODO: Try to come up with a generic way of implementing this return null; }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { // TODO: Try to come up with a generic way of implementing this return null; }
@Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { // TODO: Try to come up with a generic way of implementing this return null; }
7,631
0
//TODO need to add paging somewhere (page, items) to handle long commit histories
public JSONArray getProjectRevisions(ProjectEndpoint endpoint) { //TODO need to add paging somewhere (page, items) to handle long commit histories String json = restInterface.get(TeamworkCloudEndpoints.GET_PROJECT_REVISIONS.buildUrl(endpoint.getHost(), endpoint.getCollection(), endpoint.getProject(), "true"), endpoint.getToken(), String.class); return new JSONArray(json); }
IMPLEMENTATION
true
public JSONArray getProjectRevisions(ProjectEndpoint endpoint) { //TODO need to add paging somewhere (page, items) to handle long commit histories String json = restInterface.get(TeamworkCloudEndpoints.GET_PROJECT_REVISIONS.buildUrl(endpoint.getHost(), endpoint.getCollection(), endpoint.getProject(), "true"), endpoint.getToken(), String.class);
public JSONArray getProjectRevisions(ProjectEndpoint endpoint) { //TODO need to add paging somewhere (page, items) to handle long commit histories String json = restInterface.get(TeamworkCloudEndpoints.GET_PROJECT_REVISIONS.buildUrl(endpoint.getHost(), endpoint.getCollection(), endpoint.getProject(), "true"), endpoint.getToken(), String.class); return new JSONArray(json); }
public JSONArray getProjectRevisions(ProjectEndpoint endpoint) { //TODO need to add paging somewhere (page, items) to handle long commit histories String json = restInterface.get(TeamworkCloudEndpoints.GET_PROJECT_REVISIONS.buildUrl(endpoint.getHost(), endpoint.getCollection(), endpoint.getProject(), "true"), endpoint.getToken(), String.class); return new JSONArray(json); }
7,632
0
// FIXME: flashing blank activity
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras; Log.d(TAG, "Widget configuration activity created"); setResult(RESULT_CANCELED); extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
DEFECT
true
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras; Log.d(TAG, "Widget configuration activity created"); setResult(RESULT_CANCELED); extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras; Log.d(TAG, "Widget configuration activity created"); setResult(RESULT_CANCELED); extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras; Log.d(TAG, "Widget configuration activity created"); setResult(RESULT_CANCELED); extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
7,632
1
// Finish activity earlier
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras; Log.d(TAG, "Widget configuration activity created"); setResult(RESULT_CANCELED); extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
NONSATD
true
setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish();
AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras; Log.d(TAG, "Widget configuration activity created"); setResult(RESULT_CANCELED); extras = getIntent().getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { finish(); return; } resultValue = new Intent(); resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, resultValue); if(SessionManager.hasSessionInStore(this)) { // Finish activity earlier Log.d(TAG, "Session already taken, leaving configuration activity"); finish(); } }
24,024
0
// lets escape quotes
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true; } for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } sqlLiteralForObject(buffer, Array.get(object, i)); } if (trimming) { buffer.append("..."); } buffer.append('>'); } else { buffer.append(object.getClass().getName()).append("@").append(System.identityHashCode(object)); } }
NONSATD
true
} else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) {
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; }
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object);
24,024
1
// handle byte pretty formatting
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true; } for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } sqlLiteralForObject(buffer, Array.get(object, i)); } if (trimming) { buffer.append("..."); } buffer.append('>'); } else { buffer.append(object.getClass().getName()).append("@").append(System.identityHashCode(object)); } }
NONSATD
true
buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue());
int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) {
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) {
24,024
2
// process numeric value (do something smart in the future)
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true; } for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } sqlLiteralForObject(buffer, Array.get(object, i)); } if (trimming) { buffer.append("..."); } buffer.append('>'); } else { buffer.append(object.getClass().getName()).append("@").append(System.identityHashCode(object)); } }
NONSATD
true
IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) {
curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis();
buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue();
24,024
3
// buffer.append(object.getClass().getName()).append(".");
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true; } for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } sqlLiteralForObject(buffer, Array.get(object, i)); } if (trimming) { buffer.append("..."); } buffer.append('>'); } else { buffer.append(object.getClass().getName()).append("@").append(System.identityHashCode(object)); } }
NONSATD
true
buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) {
long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal());
else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD;
24,024
4
// FIXME -- this isn't quite right
void sqlLiteralForObject(StringBuilder buffer, Object object) { if (object == null) { buffer.append("NULL"); } else if (object instanceof String) { buffer.append('\''); // lets escape quotes String literal = (String) object; if (literal.length() > TRIM_VALUES_THRESHOLD) { literal = literal.substring(0, TRIM_VALUES_THRESHOLD) + "..."; } int curPos = 0; int endPos = 0; while ((endPos = literal.indexOf('\'', curPos)) >= 0) { buffer.append(literal.substring(curPos, endPos + 1)).append('\''); curPos = endPos + 1; } if (curPos < literal.length()) buffer.append(literal.substring(curPos)); buffer.append('\''); } // handle byte pretty formatting else if (object instanceof Byte) { IDUtil.appendFormattedByte(buffer, ((Byte) object).byteValue()); } else if (object instanceof Number) { // process numeric value (do something smart in the future) buffer.append(object); } else if (object instanceof java.sql.Date) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.sql.Time) { buffer.append('\'').append(object).append('\''); } else if (object instanceof java.util.Date) { long time = ((java.util.Date) object).getTime(); buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true; } for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } sqlLiteralForObject(buffer, Array.get(object, i)); } if (trimming) { buffer.append("..."); } buffer.append('>'); } else { buffer.append(object.getClass().getName()).append("@").append(System.identityHashCode(object)); } }
DEFECT
true
} else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) {
buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true;
buffer.append('\'').append(new java.sql.Timestamp(time)).append('\''); } else if (object instanceof java.util.Calendar) { long time = ((java.util.Calendar) object).getTimeInMillis(); buffer.append(object.getClass().getName()).append('(').append(new java.sql.Timestamp(time)).append(')'); } else if (object instanceof Character) { buffer.append(((Character) object).charValue()); } else if (object instanceof Boolean) { buffer.append('\'').append(object).append('\''); } else if (object instanceof Enum<?>) { // buffer.append(object.getClass().getName()).append("."); buffer.append(((Enum<?>) object).name()).append("="); if (object instanceof ExtendedEnumeration) { Object value = ((ExtendedEnumeration) object).getDatabaseValue(); if (value instanceof String) buffer.append("'"); buffer.append(value); if (value instanceof String) buffer.append("'"); } else { buffer.append(((Enum<?>) object).ordinal()); // FIXME -- this isn't quite right } } else if (object instanceof SQLParameterBinding) { sqlLiteralForObject(buffer, ((SQLParameterBinding) object).getValue()); } else if (object.getClass().isArray()) { buffer.append("< "); int len = Array.getLength(object); boolean trimming = false; if (len > TRIM_VALUES_THRESHOLD) { len = TRIM_VALUES_THRESHOLD; trimming = true; } for (int i = 0; i < len; i++) { if (i > 0) { buffer.append(","); } sqlLiteralForObject(buffer, Array.get(object, i)); } if (trimming) { buffer.append("..."); }
15,833
0
/* skip this+serviceChanged */
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
NONSATD
true
{ final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i];
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown");
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
15,833
1
// Skip framework (todo: add more fws)
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
DESIGN
true
StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves {
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
15,833
2
// Skip ourselves
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
NONSATD
true
String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ());
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
private String get_location () { final StackTraceElement[] stackTrace = new Throwable ().getStackTrace (); for (int i = 2 /* skip this+serviceChanged */; i < stackTrace.length; i++) { StackTraceElement ste = stackTrace [i]; String class_name = ste.getClassName (); if (!class_name.startsWith ("org.apache.felix.framework.") // Skip framework (todo: add more fws) && !class_name.equals (this.getClass ().getName ())) // Skip ourselves { return (ste.toString ()); } } return ("StackTraceElement:Unknown"); }
15,851
0
// compiler complains unless I include the full classname!!! Huh?
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable) return ((Valuable)o).doubleValue(); else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
DESIGN
true
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable)
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable) return ((Valuable)o).doubleValue(); else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable) return ((Valuable)o).doubleValue(); else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
15,851
1
// unknown
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable) return ((Valuable)o).doubleValue(); else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
NONSATD
true
else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable) return ((Valuable)o).doubleValue(); else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
protected double valueFor(Object o) { if (o instanceof java.lang.Number) // compiler complains unless I include the full classname!!! Huh? return ((Number)o).doubleValue(); else if (o instanceof Valuable) return ((Valuable)o).doubleValue(); else if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? 1 : 0; else return Double.NaN; // unknown }
24,068
0
/** * Assign a new unique id up to slices count - then add replicas evenly. * * @return the assigned shard id */
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
NONSATD
true
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
24,068
1
// TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method?
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
DESIGN
true
String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1";
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>();
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0);
24,068
2
// TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
DESIGN
true
return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) {
String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); });
public static String assignShard(DocCollection collection, Integer numShards) { if (numShards == null) { numShards = 1; } String returnShardId = null; Map<String, Slice> sliceMap = collection != null ? collection.getActiveSlicesMap() : null; // TODO: now that we create shards ahead of time, is this code needed? Esp since hash ranges aren't assigned when creating via this method? if (sliceMap == null) { return "shard1"; } List<String> shardIdNames = new ArrayList<>(sliceMap.keySet()); if (shardIdNames.size() < numShards) { return "shard" + (shardIdNames.size() + 1); } // TODO: don't need to sort to find shard with fewest replicas! // else figure out which shard needs more replicas final Map<String, Integer> map = new HashMap<>(); for (String shardId : shardIdNames) { int cnt = sliceMap.get(shardId).getReplicasMap().size(); map.put(shardId, cnt); } Collections.sort(shardIdNames, (String o1, String o2) -> { Integer one = map.get(o1); Integer two = map.get(o2); return one.compareTo(two); }); returnShardId = shardIdNames.get(0); return returnShardId; }
15,882
0
/** * Starts this service to perform action Foo with the given parameters. If * the service is already performing a task this action will be queued. * * @see IntentService */ // TODO: Customize helper method
public static void startActionFoo(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_FOO); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
IMPLEMENTATION
true
public static void startActionFoo(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_FOO); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
public static void startActionFoo(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_FOO); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
public static void startActionFoo(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_FOO); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
15,883
0
/** * Starts this service to perform action Baz with the given parameters. If * the service is already performing a task this action will be queued. * * @see IntentService */ // TODO: Customize helper method
public static void startActionBaz(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_BAZ); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
IMPLEMENTATION
true
public static void startActionBaz(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_BAZ); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
public static void startActionBaz(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_BAZ); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
public static void startActionBaz(Context context, String param1, String param2) { Intent intent = new Intent(context, MyIntentService.class); intent.setAction(ACTION_BAZ); intent.putExtra(EXTRA_PARAM1, param1); intent.putExtra(EXTRA_PARAM2, param2); context.startService(intent); }
24,088
0
/** * Metodo que se encarga de crear un Grid para la visualizacion de los datos de un movimiento * @return Devuelve un grid con los campos para representar Movimientos */
private Grid<Cuenta> createGrid() { grid = new Grid<>(); grid.setWidthFull(); grid.addThemeVariants(GridVariant.LUMO_NO_BORDER,GridVariant.LUMO_ROW_STRIPES); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); grid.addColumn(c -> c.getIban()).setHeader("Iban").setFlexGrow(1); grid.addColumn(c -> c.getSaldo()).setHeader("Saldo").setFlexGrow(1); grid.addColumn(c -> dateFormat.format(c.getFechaCreacion())).setHeader("Fecha Creacion").setWidth("250px").setFlexGrow(0); return grid; }
NONSATD
true
private Grid<Cuenta> createGrid() { grid = new Grid<>(); grid.setWidthFull(); grid.addThemeVariants(GridVariant.LUMO_NO_BORDER,GridVariant.LUMO_ROW_STRIPES); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); grid.addColumn(c -> c.getIban()).setHeader("Iban").setFlexGrow(1); grid.addColumn(c -> c.getSaldo()).setHeader("Saldo").setFlexGrow(1); grid.addColumn(c -> dateFormat.format(c.getFechaCreacion())).setHeader("Fecha Creacion").setWidth("250px").setFlexGrow(0); return grid; }
private Grid<Cuenta> createGrid() { grid = new Grid<>(); grid.setWidthFull(); grid.addThemeVariants(GridVariant.LUMO_NO_BORDER,GridVariant.LUMO_ROW_STRIPES); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); grid.addColumn(c -> c.getIban()).setHeader("Iban").setFlexGrow(1); grid.addColumn(c -> c.getSaldo()).setHeader("Saldo").setFlexGrow(1); grid.addColumn(c -> dateFormat.format(c.getFechaCreacion())).setHeader("Fecha Creacion").setWidth("250px").setFlexGrow(0); return grid; }
private Grid<Cuenta> createGrid() { grid = new Grid<>(); grid.setWidthFull(); grid.addThemeVariants(GridVariant.LUMO_NO_BORDER,GridVariant.LUMO_ROW_STRIPES); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); grid.addColumn(c -> c.getIban()).setHeader("Iban").setFlexGrow(1); grid.addColumn(c -> c.getSaldo()).setHeader("Saldo").setFlexGrow(1); grid.addColumn(c -> dateFormat.format(c.getFechaCreacion())).setHeader("Fecha Creacion").setWidth("250px").setFlexGrow(0); return grid; }
7,716
0
// merge sort
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
NONSATD
true
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
7,716
1
// TODO: implement this method (in an iterative way)
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
IMPLEMENTATION
true
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
public void mergeSort(Card[] cardArray) { // TODO: implement this method (in an iterative way) }
24,102
0
/** * Tests that pressing the app button on the Daydream controller exists voice input mode. This * would fit better in VrBrowserControllerInputTest, but having it here allows code reuse. */
@Test @MediumTest public void testAppButtonExitsVoiceInput() throws InterruptedException { Runnable exitAction = () -> { NativeUiUtils.clickAppButton(UserFriendlyElementName.CURRENT_POSITION, new PointF()); }; testExitVoiceInputImpl(exitAction); }
TEST
true
@Test @MediumTest public void testAppButtonExitsVoiceInput() throws InterruptedException { Runnable exitAction = () -> { NativeUiUtils.clickAppButton(UserFriendlyElementName.CURRENT_POSITION, new PointF()); }; testExitVoiceInputImpl(exitAction); }
@Test @MediumTest public void testAppButtonExitsVoiceInput() throws InterruptedException { Runnable exitAction = () -> { NativeUiUtils.clickAppButton(UserFriendlyElementName.CURRENT_POSITION, new PointF()); }; testExitVoiceInputImpl(exitAction); }
@Test @MediumTest public void testAppButtonExitsVoiceInput() throws InterruptedException { Runnable exitAction = () -> { NativeUiUtils.clickAppButton(UserFriendlyElementName.CURRENT_POSITION, new PointF()); }; testExitVoiceInputImpl(exitAction); }
15,912
0
// spend coins
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos);
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action),
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager)));
15,912
1
// wait while balance be a 100
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf(
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) ));
15,912
2
// wait while balance isn't update
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
// wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d)));
public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager)
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString)));
15,912
3
// submit disabled
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount)));
ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true
15,912
4
// empty string is valid zero
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST"));
inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute();
15,912
5
// valid value
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null)));
amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol()));
ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab
15,912
6
// @TODO potentially, may break test, as coin can be created
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
TEST
true
amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists")));
actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo());
ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute();
15,912
7
// we can send transaction even if coin does not exists, because it can be no a true
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission
// submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount());
15,912
8
// amount without commission
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol()))));
// we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount());
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
15,912
9
// visible "use max" for spend tab
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click());
coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
// valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
15,912
10
// amount without commission
@Test public void testSpendInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 0; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal(100.d))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); coinOutput.check(matches(withText(balanceString))); actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
NONSATD
true
Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol()))));
// we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount());
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_get_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeSellValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate3 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate3, mExchangeCoin.getSymbol())))); // visible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); actionUseMax.perform(click()); amountInput.check(matches(withText("100"))); Response<GateResult<ExchangeSellValue>> estimate2 = estimateRepo.getCoinExchangeCurrencyToSell(MinterSDK.DEFAULT_COIN, new BigDecimal("100"), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate2.body().isOk()); // amount without commission String expectEstimate2 = bdHuman(estimate2.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate2, mExchangeCoin.getSymbol())))); }
15,913
0
// spend coins
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos);
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action),
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager)));
15,913
1
// wait while balance be a 100
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf(
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) ));
15,913
2
// wait while balance isn't update
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
// wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100")));
public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager)
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab
15,913
3
// invisible "use max" for spend tab
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
)); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString)));
inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled())));
// wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created
15,913
4
// submit disabled
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount)));
ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true
15,913
5
// empty string is valid zero
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0")));
actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST"));
)); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute();
15,913
6
// valid value
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null)));
amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol()));
withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
15,913
7
// @TODO potentially, may break test, as coin can be created
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
TEST
true
amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists")));
actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo());
// invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
15,913
8
// we can send transaction even if coin does not exists, because it can be no a true
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission
// submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
15,913
9
// amount without commission
@Test public void testGetInputs() throws Throwable { ExplorerCoinsRepository repo = TestWallet.app().explorerCoinsRepo(); GateEstimateRepository estimateRepo = TestWallet.app().estimateRepo(); final int tabPos = 1; // spend coins mActivityTestRule.runOnUiThread(() -> { mActivityTestRule.getActivity().setCurrentPage(tabPos); }); // wait while balance be a 100 waitForBalance(100); // wait while balance isn't update waitForBalanceUpdate(); final String balanceString = String.format("%s (%s)", MinterSDK.DEFAULT_COIN, bdHuman(new BigDecimal("100"))); ViewInteraction actionBtn = onView(allOf( withId(R.id.action), withText("EXCHANGE"), inViewPager(tabPos, R.id.pager) )); ViewInteraction actionUseMax = onView(allOf( withId(R.id.action_maximum), inViewPager(tabPos, R.id.pager) )); ViewInteraction amountInput = onView(allOf(withId(R.id.input_amount), inViewPager(tabPos, R.id.pager))); ViewInteraction coinInput = onView(allOf(withId(R.id.input_incoming_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction coinOutput = onView(allOf(withId(R.id.input_outgoing_coin), inViewPager(tabPos, R.id.pager))); ViewInteraction layoutCalculation = onView(allOf( withId(R.id.layout_calculation), inViewPager(tabPos, R.id.pager) )); ViewInteraction calculationSum = onView(allOf(withId(R.id.calculation), inViewPager(tabPos, R.id.pager))); // invisible "use max" for spend tab actionUseMax.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinOutput.check(matches(withText(balanceString))); // submit disabled actionBtn.check(matches(not(isEnabled()))); amountInput.check(matches(withInputLayoutHint(R.string.label_amount))); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); amountInput.perform(replaceText("0")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); // empty string is valid zero amountInput.perform(replaceText("")); amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
NONSATD
true
Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN))));
// we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
amountInput.check(matches(withInputLayoutError("Amount must be greater than 0"))); actionBtn.check(matches(not(isEnabled()))); final String amount = "1"; // valid value amountInput.perform(replaceText(amount)); amountInput.check(matches(withInputLayoutError(null))); actionBtn.check(matches(not(isEnabled()))); // @TODO potentially, may break test, as coin can be created coinInput.perform(replaceText("DOSNTEXIST")); coinInput.check(matches(withInputLayoutError("Coin to buy not exists"))); // we can send transaction even if coin does not exists, because it can be no a true actionBtn.check(matches(isEnabled())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); coinInput.perform(scrollTo(), replaceText(mExchangeCoin.getSymbol())); layoutCalculation.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); onView(allOf(withId(R.id.calculation_title), inViewPager(tabPos, R.id.pager))) .check(matches(withText(R.string.label_you_will_pay_approximately))); calculationSum.perform(scrollTo()); Response<GateResult<ExchangeBuyValue>> estimate1 = estimateRepo.getCoinExchangeCurrencyToBuy(MinterSDK.DEFAULT_COIN, new BigDecimal(amount), mExchangeCoin.getSymbol()).execute(); assertTrue(estimate1.body().isOk()); // amount without commission String expectEstimate1 = bdHuman(estimate1.body().result.getAmount()); calculationSum.check(matches(withText(String.format("%s %s", expectEstimate1, MinterSDK.DEFAULT_COIN)))); }
24,107
0
//TODO: Figure our why these tests fail on CI build, despite passing locally //@Test
public void ClearScreenTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_divide); press(R.id.btn_all_clear); checkResult(""); checkBinary1(""); checkBinary2(""); }
TEST
true
public void ClearScreenTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_divide); press(R.id.btn_all_clear); checkResult(""); checkBinary1(""); checkBinary2(""); }
public void ClearScreenTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_divide); press(R.id.btn_all_clear); checkResult(""); checkBinary1(""); checkBinary2(""); }
public void ClearScreenTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_divide); press(R.id.btn_all_clear); checkResult(""); checkBinary1(""); checkBinary2(""); }
24,108
0
//TODO: Figure our why these tests fail on CI build, despite passing locally //@Test
public void DeleteTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_del); checkBinary1("1000011111"); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_del); checkBinary2("10"); }
TEST
true
public void DeleteTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_del); checkBinary1("1000011111"); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_del); checkBinary2("10"); }
public void DeleteTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_del); checkBinary1("1000011111"); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_del); checkBinary2("10"); }
public void DeleteTest(){ press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_1); press(R.id.btn_del); checkBinary1("1000011111"); press(R.id.binary_number_2); press(R.id.btn_1); press(R.id.btn_0); press(R.id.btn_0); press(R.id.btn_del); checkBinary2("10"); }
15,921
0
/** * Parses a SAML response for attributes. * * @param samlResponse the SAML response sent by Identity provider * @param attributes the attributes to fetch from assertion * @return {@link Map} containing the mapped keys in {@code attributes} with a {@link List} of * values found for the attribute * @throws ServletException if the parsing fails for the {@code samlResponse} */
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded); Assertion assertion; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(is); Element element = document.getDocumentElement(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); if (unmarshaller == null) { throw new RuntimeException("Could not find an unmarshaller for XML parsing"); } XMLObject responseXmlObj = unmarshaller.unmarshall(element); Response response = (Response) responseXmlObj; if (response.getAssertions() == null || response.getAssertions().isEmpty()) { throw new ServletException("No assertions found in SAML response"); } assertion = response.getAssertions().get(0); } catch (UnmarshallingException | ParserConfigurationException | SAXException | IOException e) { throw new ServletException("Could not parse the SAML assertion", e); } for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (attributes.contains(attribute.getName())) { List<Object> values = new ArrayList<>(attribute.getAttributeValues()); parsedResult.put(attribute.getName(), values); } } } return parsedResult; }
NONSATD
true
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded); Assertion assertion; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(is); Element element = document.getDocumentElement(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); if (unmarshaller == null) { throw new RuntimeException("Could not find an unmarshaller for XML parsing"); } XMLObject responseXmlObj = unmarshaller.unmarshall(element); Response response = (Response) responseXmlObj; if (response.getAssertions() == null || response.getAssertions().isEmpty()) { throw new ServletException("No assertions found in SAML response"); } assertion = response.getAssertions().get(0); } catch (UnmarshallingException | ParserConfigurationException | SAXException | IOException e) { throw new ServletException("Could not parse the SAML assertion", e); } for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (attributes.contains(attribute.getName())) { List<Object> values = new ArrayList<>(attribute.getAttributeValues()); parsedResult.put(attribute.getName(), values); } } } return parsedResult; }
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded); Assertion assertion; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(is); Element element = document.getDocumentElement(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); if (unmarshaller == null) { throw new RuntimeException("Could not find an unmarshaller for XML parsing"); } XMLObject responseXmlObj = unmarshaller.unmarshall(element); Response response = (Response) responseXmlObj; if (response.getAssertions() == null || response.getAssertions().isEmpty()) { throw new ServletException("No assertions found in SAML response"); } assertion = response.getAssertions().get(0); } catch (UnmarshallingException | ParserConfigurationException | SAXException | IOException e) { throw new ServletException("Could not parse the SAML assertion", e); } for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (attributes.contains(attribute.getName())) { List<Object> values = new ArrayList<>(attribute.getAttributeValues()); parsedResult.put(attribute.getName(), values); } } } return parsedResult; }
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded); Assertion assertion; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(is); Element element = document.getDocumentElement(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); if (unmarshaller == null) { throw new RuntimeException("Could not find an unmarshaller for XML parsing"); } XMLObject responseXmlObj = unmarshaller.unmarshall(element); Response response = (Response) responseXmlObj; if (response.getAssertions() == null || response.getAssertions().isEmpty()) { throw new ServletException("No assertions found in SAML response"); } assertion = response.getAssertions().get(0); } catch (UnmarshallingException | ParserConfigurationException | SAXException | IOException e) { throw new ServletException("Could not parse the SAML assertion", e); } for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (attributes.contains(attribute.getName())) { List<Object> values = new ArrayList<>(attribute.getAttributeValues()); parsedResult.put(attribute.getName(), values); } } } return parsedResult; }
15,921
1
// TODO - Using a library for managing collections
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded); Assertion assertion; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(is); Element element = document.getDocumentElement(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); if (unmarshaller == null) { throw new RuntimeException("Could not find an unmarshaller for XML parsing"); } XMLObject responseXmlObj = unmarshaller.unmarshall(element); Response response = (Response) responseXmlObj; if (response.getAssertions() == null || response.getAssertions().isEmpty()) { throw new ServletException("No assertions found in SAML response"); } assertion = response.getAssertions().get(0); } catch (UnmarshallingException | ParserConfigurationException | SAXException | IOException e) { throw new ServletException("Could not parse the SAML assertion", e); } for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (attributes.contains(attribute.getName())) { List<Object> values = new ArrayList<>(attribute.getAttributeValues()); parsedResult.put(attribute.getName(), values); } } } return parsedResult; }
IMPLEMENTATION
true
Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult;
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded);
public static Map<String, List<Object>> parseAttributes(String samlResponse, Set<String> attributes) throws ServletException { Map<String, List<Object>> parsedResult = new HashMap<>(); // TODO - Using a library for managing collections if (attributes == null || attributes.isEmpty()) { return parsedResult; } byte[] samlAssertionDecoded = new byte[0]; try { samlAssertionDecoded = Base64.decodeBase64(samlResponse.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Unsupported encoding to decode Saml Response"); } ByteArrayInputStream is = new ByteArrayInputStream(samlAssertionDecoded); Assertion assertion; try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(is); Element element = document.getDocumentElement(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(element); if (unmarshaller == null) { throw new RuntimeException("Could not find an unmarshaller for XML parsing"); } XMLObject responseXmlObj = unmarshaller.unmarshall(element);
7,735
0
// TODO(pdex): why are we making our own threadpool?
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture = tailer.getSchema(PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME); Futures.addCallback( schemaSetFuture, new FutureCallback<SchemaSet>() { @Override public void onSuccess(SchemaSet schemaSet) { log.info("Successfully Processed the Table Schema. Starting the poller now ..."); if (DISRUPTOR) { DisruptorHandler handler = new DisruptorHandler(schemaSet, publisher, metadata, l.get(0)); handler.start(); tailer.setRingBuffer(handler.getRingBuffer()); ScheduledFuture<?> result = tailer.start( 2, 500, PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME, "lpts_table", schemaSet.tsColName(), "2000"); doneSignal.countDown(); } else { WorkStealingHandler handler = new WorkStealingHandler(scheduler, schemaSet, publisher, metadata); tailer.start( handler, schemaSet.tsColName(), l.size(), THREAD_POOL, 500, PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME, "lpts_table", "2000", 500, 500); scheduler.scheduleAtFixedRate( () -> { handler.logStats(); tailer.logStats(); }, 30, 30, TimeUnit.SECONDS); doneSignal.countDown(); } } @Override public void onFailure(Throwable t) { log.error("Unable to process schema", t); System.exit(-1); } }, l.get(l.size() % THREAD_POOL)); try { log.debug("Dumping all known Loggers"); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); java.util.Iterator<ch.qos.logback.classic.Logger> it = lc.getLoggerList().iterator(); while (it.hasNext()) { ch.qos.logback.classic.Logger thisLog = it.next(); log.debug("name: {} status: {}", thisLog.getName(), thisLog.getLevel()); } log.info("waiting for doneSignal"); doneSignal.await(); } catch (InterruptedException e) { e.printStackTrace(); } }
DESIGN
true
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker");
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool();
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture =
7,735
1
// final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME);
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture = tailer.getSchema(PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME); Futures.addCallback( schemaSetFuture, new FutureCallback<SchemaSet>() { @Override public void onSuccess(SchemaSet schemaSet) { log.info("Successfully Processed the Table Schema. Starting the poller now ..."); if (DISRUPTOR) { DisruptorHandler handler = new DisruptorHandler(schemaSet, publisher, metadata, l.get(0)); handler.start(); tailer.setRingBuffer(handler.getRingBuffer()); ScheduledFuture<?> result = tailer.start( 2, 500, PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME, "lpts_table", schemaSet.tsColName(), "2000"); doneSignal.countDown(); } else { WorkStealingHandler handler = new WorkStealingHandler(scheduler, schemaSet, publisher, metadata); tailer.start( handler, schemaSet.tsColName(), l.size(), THREAD_POOL, 500, PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME, "lpts_table", "2000", 500, 500); scheduler.scheduleAtFixedRate( () -> { handler.logStats(); tailer.logStats(); }, 30, 30, TimeUnit.SECONDS); doneSignal.countDown(); } } @Override public void onFailure(Throwable t) { log.error("Unable to process schema", t); System.exit(-1); } }, l.get(l.size() % THREAD_POOL)); try { log.debug("Dumping all known Loggers"); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); java.util.Iterator<ch.qos.logback.classic.Logger> it = lc.getLoggerList().iterator(); while (it.hasNext()) { ch.qos.logback.classic.Logger thisLog = it.next(); log.debug("name: {} status: {}", thisLog.getName(), thisLog.getLevel()); } log.info("waiting for doneSignal"); doneSignal.await(); } catch (InterruptedException e) { e.printStackTrace(); } }
NONSATD
true
Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial(
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1);
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture = tailer.getSchema(PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME); Futures.addCallback( schemaSetFuture, new FutureCallback<SchemaSet>() {
7,735
2
// Populate CDC Metadata
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture = tailer.getSchema(PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME); Futures.addCallback( schemaSetFuture, new FutureCallback<SchemaSet>() { @Override public void onSuccess(SchemaSet schemaSet) { log.info("Successfully Processed the Table Schema. Starting the poller now ..."); if (DISRUPTOR) { DisruptorHandler handler = new DisruptorHandler(schemaSet, publisher, metadata, l.get(0)); handler.start(); tailer.setRingBuffer(handler.getRingBuffer()); ScheduledFuture<?> result = tailer.start( 2, 500, PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME, "lpts_table", schemaSet.tsColName(), "2000"); doneSignal.countDown(); } else { WorkStealingHandler handler = new WorkStealingHandler(scheduler, schemaSet, publisher, metadata); tailer.start( handler, schemaSet.tsColName(), l.size(), THREAD_POOL, 500, PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME, "lpts_table", "2000", 500, 500); scheduler.scheduleAtFixedRate( () -> { handler.logStats(); tailer.logStats(); }, 30, 30, TimeUnit.SECONDS); doneSignal.countDown(); } } @Override public void onFailure(Throwable t) { log.error("Unable to process schema", t); System.exit(-1); } }, l.get(l.size() % THREAD_POOL)); try { log.debug("Dumping all known Loggers"); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); java.util.Iterator<ch.qos.logback.classic.Logger> it = lc.getLoggerList().iterator(); while (it.hasNext()) { ch.qos.logback.classic.Logger thisLog = it.next(); log.debug("name: {} status: {}", thisLog.getName(), thisLog.getLevel()); } log.info("waiting for doneSignal"); doneSignal.await(); } catch (InterruptedException e) { e.printStackTrace(); } }
NONSATD
true
final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME);
ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture = tailer.getSchema(PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME); Futures.addCallback( schemaSetFuture, new FutureCallback<SchemaSet>() { @Override public void onSuccess(SchemaSet schemaSet) {
public static void main(String[] args) { // TODO(pdex): why are we making our own threadpool? final List<ListeningExecutorService> l = Spez.ServicePoolGenerator(THREAD_POOL, "Spanner Tailer Event Worker"); final SpannerTailer tailer = new SpannerTailer(THREAD_POOL, 200000000); // final EventPublisher publisher = new EventPublisher(PROJECT_NAME, TOPIC_NAME); final ThreadLocal<EventPublisher> publisher = ThreadLocal.withInitial( () -> { return new EventPublisher(PROJECT_NAME, TOPIC_NAME); }); final ExecutorService workStealingPool = Executors.newWorkStealingPool(); final ListeningExecutorService forkJoinPool = MoreExecutors.listeningDecorator(workStealingPool); final Map<String, String> metadata = new HashMap<>(); final CountDownLatch doneSignal = new CountDownLatch(1); final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); // Populate CDC Metadata metadata.put("SrcDatabase", DB_NAME); metadata.put("SrcTablename", TABLE_NAME); metadata.put("DstTopic", TOPIC_NAME); final ListenableFuture<SchemaSet> schemaSetFuture = tailer.getSchema(PROJECT_NAME, INSTANCE_NAME, DB_NAME, TABLE_NAME); Futures.addCallback( schemaSetFuture, new FutureCallback<SchemaSet>() { @Override public void onSuccess(SchemaSet schemaSet) { log.info("Successfully Processed the Table Schema. Starting the poller now ..."); if (DISRUPTOR) { DisruptorHandler handler = new DisruptorHandler(schemaSet, publisher, metadata, l.get(0)); handler.start(); tailer.setRingBuffer(handler.getRingBuffer()); ScheduledFuture<?> result = tailer.start( 2, 500,
15,927
0
// for the 4 byte header
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd);
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try {
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT:
15,927
1
// Nothing to return by default
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
{ len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10);
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT:
15,927
2
// System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) {
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} }
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER:
15,927
3
// System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
{ if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try {
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd)
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT:
15,927
4
// System.out.println("INIT"); // start up native renderer
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0;
case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle);
case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) {
15,927
5
// platform default
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager()
// System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds());
15,927
6
//System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds());
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } };
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); }
windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio
15,927
7
/* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
} f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView();
ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon);
{ c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) {
15,927
8
/* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
} myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose();
public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); }
ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this);
15,927
9
// f.dispose();
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
System.exit(0);*/ close(); // f.dispose(); } });
/* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this);
public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100;
15,927
10
//f.addMouseListener(this);
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this);
}); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720;
if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY);
15,927
11
//f.addMouseMotionListener(this);
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); }
myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480"));
}catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150;
15,927
12
// f.setVisible(true);
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT:
newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL;
frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR));
15,927
13
// System.out.println("DEINIT");
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break;
f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata);
frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0,
15,927
14
// System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet...
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
DEFECT
true
argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0,
int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len);
// f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata);
15,927
15
// x, y, width, height, argbTL, argbTR, argbBR, argbBL
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) {
null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata);
thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(),
15,927
16
// System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR));
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height);
float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied
} else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else
15,927
17
//(float)((argbTL>>24)&0xff)/255.0f);
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else {
argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } }
{ float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height,
15,927
18
// alpha already supplied
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null,
// System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else
float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL;
15,927
19
// x, y, width, height, argbTL, argbTR, argbBR, argbBL
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) {
null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata);
thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(),
15,927
20
// System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR));
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect);
int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL,
} else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata);
15,927
21
// x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) {
// System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata);
int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height);
15,927
22
// System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
DEFECT
true
clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH);
height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else {
case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH;
15,927
23
// x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) {
null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata);
clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height);
15,927
24
// System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR));
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height);
width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else {
case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len);
15,927
25
// x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) {
null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata);
if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata);
15,927
26
// System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
DEFECT
true
clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH);
thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else
if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height,
15,927
27
// x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH
public int ExecuteGFXCommand(int cmd, int len, byte[] cmddata, int[] hasret) { len -= 4; // for the 4 byte header hasret[0] = 0; // Nothing to return by default // System.out.println("GFXCMD=" + cmd); // make sure the frame is still valid or we could crash on fullscreen mode switches if((cmd != GFXCMD_INIT) && (cmd != GFXCMD_DEINIT)) { if((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { // System.out.println("GFXCMD while frame not displayable"); // spin until the frame is valid and displayable, if we don't we'll lose parts of the UI or crash while((f != null) ? (!f.isDisplayable() || !f.isValid() || !f.isShowing()) : true) { try { Thread.sleep(10); } catch(InterruptedException ex) {} } } } if (c != null) { switch(cmd) { case GFXCMD_INIT: case GFXCMD_DEINIT: case GFXCMD_STARTFRAME: case GFXCMD_FLIPBUFFER: c.setCursor(null); break; case GFXCMD_DRAWRECT: case GFXCMD_FILLRECT: case GFXCMD_CLEARRECT: case GFXCMD_DRAWOVAL: case GFXCMD_FILLOVAL: case GFXCMD_DRAWROUNDRECT: case GFXCMD_FILLROUNDRECT: case GFXCMD_DRAWTEXT: case GFXCMD_DRAWTEXTURED: case GFXCMD_DRAWLINE: case GFXCMD_LOADIMAGE: case GFXCMD_LOADIMAGETARGETED: case GFXCMD_UNLOADIMAGE: case GFXCMD_LOADFONT: case GFXCMD_UNLOADFONT: case GFXCMD_SETTARGETSURFACE: case GFXCMD_CREATESURFACE: break; case GFXCMD_PREPIMAGE: case GFXCMD_LOADIMAGELINE: case GFXCMD_LOADIMAGECOMPRESSED: case GFXCMD_XFMIMAGE: case GFXCMD_LOADCACHEDIMAGE: case GFXCMD_PREPIMAGETARGETED: if (!cursorHidden) c.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); break; } } switch(cmd) { case GFXCMD_INIT: hasret[0] = 1; // System.out.println("INIT"); // start up native renderer init0(); int windowTitleStyle = 0; try { windowTitleStyle = Integer.parseInt(MiniClient.myProperties.getProperty("window_title_style", "0")); } catch (NumberFormatException e){} if (!"true".equals(MiniClient.myProperties.getProperty("enable_custom_title_bar", MiniClient.MAC_OS_X ? "false" : "true"))) windowTitleStyle = 10; // platform default f = new MiniClientWindow(myConn.getWindowTitle(), windowTitleStyle); java.awt.LayoutManager layer = new java.awt.LayoutManager() { public void addLayoutComponent(String name, java.awt.Component comp) {} public java.awt.Dimension minimumLayoutSize(java.awt.Container parent) { return preferredLayoutSize(parent); } public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) { return parent.getPreferredSize(); } public void removeLayoutComponent(java.awt.Component comp) {} public void layoutContainer(java.awt.Container parent) { c.setBounds(parent.getInsets().left, parent.getInsets().top, parent.getWidth() - parent.getInsets().left - parent.getInsets().right, parent.getHeight() - parent.getInsets().top - parent.getInsets().bottom); //System.out.println("LAYOUT frame bounds=" + f.getBounds() + " videoBounds=" + videoBounds + " parentBounds=" + parent.getBounds()); } }; f.getContentPane().setLayout(layer); try { bgImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/Background.jpg")); ensureImageIsLoaded(bgImage); logoImage = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/SageLogo256.png")); ensureImageIsLoaded(logoImage); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.setFocusTraversalKeysEnabled(false); /* if not connecting to localhost: - draw background to bounds (scaled) - draw logo to {{2% from left, 15% from top}{20% view width, 7% view height}}, no clipping, alpha = 0.85, adjust size to keep aspect ratio - load Arial 32 bold - draw the following text, double spaced using Arial 32 bold, white with black shadow (offset by (+2,+2)) "SageTV Placeshifter is connecting to" "the server: "+myConn.getServerName() "Please Wait..." text is centered in the view on the middle line, use font metrics to determine proper location g.setFont(pleaseWaitFont); g.setColor(java.awt.Color.black); y += 2; g.drawString(str1, 2 + (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, 2 + (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, 2 + (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); g.setColor(java.awt.Color.white); y = (getHeight() / 2) - fh/2; g.drawString(str1, (getWidth()/2) - (fm.stringWidth(str1)/2), y + fm.getAscent()); y += fm.getHeight(); g.drawString(str2, (getWidth()/2) - (fm.stringWidth(str2)/2), y + fm.getAscent()); y += 2*fm.getHeight(); g.drawString(str3, (getWidth()/2) - (fm.stringWidth(str3)/2), y + fm.getAscent()); */ java.awt.Dimension panelSize = f.getContentPane().getSize(); c = new QuartzRendererView(); c.setSize(panelSize); c.setFocusTraversalKeysEnabled(false); f.getContentPane().add(c); try { java.awt.Image frameIcon = java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("images/tvicon.gif")); ensureImageIsLoaded(frameIcon); f.setIconImage(frameIcon); } catch (Exception e) { System.out.println("ERROR:" + e); e.printStackTrace(); } f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { if (!f.isFullScreen() || System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) { MiniClient.myProperties.setProperty("main_window_width", Integer.toString(f.getWidth())); MiniClient.myProperties.setProperty("main_window_height", Integer.toString(f.getHeight())); MiniClient.myProperties.setProperty("main_window_x", Integer.toString(f.getX())); MiniClient.myProperties.setProperty("main_window_y", Integer.toString(f.getY())); } myConn.close(); /* try { if (myConn.getMediaCmd().getPlaya() != null) { myConn.getMediaCmd().getPlaya().stop(); myConn.getMediaCmd().getPlaya().free(); } }catch (Exception e){} System.exit(0);*/ close(); // f.dispose(); } }); c.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentResized(java.awt.event.ComponentEvent evt) { myConn.postResizeEvent(new java.awt.Dimension(c.getWidth(), c.getHeight())); } }); f.addKeyListener(this); c.addKeyListener(this); //f.addMouseListener(this); f.addMouseWheelListener(this); c.addMouseListener(this); if (ENABLE_MOUSE_MOTION_EVENTS) { //f.addMouseMotionListener(this); c.addMouseMotionListener(this); } int frameX = 100; int frameY = 100; int frameW = 720; int frameH = 480; try { frameW = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_width", "720")); frameH = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_height", "480")); frameX = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_x", "100")); frameY = Integer.parseInt(MiniClient.myProperties.getProperty("main_window_y", "100")); } catch (NumberFormatException e){} java.awt.Point newPos = new java.awt.Point(frameX, frameY); boolean foundScreen = sage.UIUtils.isPointOnAScreen(newPos); if (!foundScreen) { newPos.x = 150; newPos.y = 150; } f.setVisible(true); f.setSize(1,1); f.setSize(Math.max(frameW, 320), Math.max(frameH, 240)); f.setLocation(newPos); if (MiniClient.fsStartup) f.setFullScreen(true); MiniClient.hideSplash(); // f.setVisible(true); return 1; case GFXCMD_DEINIT: // System.out.println("DEINIT"); close(); break; case GFXCMD_DRAWRECT: if(len==36) { float x, y, width, height; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); // System.out.println("DRAWRECT: dest=("+x+","+y+" "+width+"x"+height+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on framed rects yet... drawRect0(new java.awt.geom.Rectangle2D.Float(x, y, width, height), null, 0, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWRECT : " + len); } break; case GFXCMD_FILLRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { float x, y, width, height; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("FILLRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); if(gp != null) { drawRect0(bounds, null, 0, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); // alpha already supplied } else { drawRect0(bounds, null, 0, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLRECT : " + len); } break; case GFXCMD_CLEARRECT: // x, y, width, height, argbTL, argbTR, argbBR, argbBL if(len==32) { int x, y, width, height, argbTL, argbTR, argbBR, argbBL; x=readInt(0, cmddata); y=readInt(4, cmddata); width=readInt(8, cmddata); height=readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); // System.out.println("CLEARRECT: dest=("+x+","+y+" "+width+"x"+height+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x, y, width, height); clearRect0(destRect); } else { System.out.println("Invalid len for GFXCMD_CLEARRECT : " + len); } break; case GFXCMD_DRAWOVAL: // x, y, width, height, thickness, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("DRAWOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradient for framed ovals java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawOval0(bounds, clipRect, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWOVAL : " + len); } break; case GFXCMD_FILLOVAL: // x, y, width, height, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==48) { float x, y, width, height, clipX, clipY, clipW, clipH; int argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); argbTL=readInt(16, cmddata); argbTR=readInt(20, cmddata); argbBR=readInt(24, cmddata); argbBL=readInt(28, cmddata); clipX=(float)readInt(32, cmddata); clipY=(float)readInt(36, cmddata); clipW=(float)readInt(40, cmddata); clipH=(float)readInt(44, cmddata); // System.out.println("FILLOVAL: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawOval0(bounds, clipRect, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), 1.0f); } else { drawOval0(bounds, clipRect, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLOVAL : " + len); } break; case GFXCMD_DRAWROUNDRECT: // x, y, width, height, thickness, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==56) { float x, y, width, height, clipX, clipY, clipW, clipH; int thickness, arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); thickness=readInt(16, cmddata); arcRadius=readInt(20, cmddata); argbTL=readInt(24, cmddata); argbTR=readInt(28, cmddata); argbBR=readInt(32, cmddata); argbBL=readInt(36, cmddata); clipX=(float)readInt(40, cmddata); clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR); java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); if(gp != null) { drawRect0(bounds, clipRect, arcRadius, null, 0, gp.getColor1(), (float)gp.getPoint1().getX(), (float)gp.getPoint1().getY(), gp.getColor2(), (float)gp.getPoint2().getX(), (float)gp.getPoint2().getY(), //(float)((argbTL>>24)&0xff)/255.0f); 1.0f); } else { drawRect0(bounds, clipRect, arcRadius, null, 0, new java.awt.Color(argbTL, true), 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } } else { System.out.println("Invalid len for GFXCMD_FILLROUNDRECT : " + len); } break; case GFXCMD_DRAWTEXT: // x, y, len, text, handle, argb, clipX, clipY, clipW, clipH if(len>=36 && len>=(36+readInt(8, cmddata)*2)) { float x, y, clipX, clipY, clipW, clipH; int textlen, fontHandle, argb; StringBuffer text = new StringBuffer(); int i; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); textlen=readInt(8, cmddata); for(i=0;i<textlen;i++) { text.append((char)readShort(12+i*2, cmddata)); } fontHandle=readInt(textlen*2+12, cmddata); argb=readInt(textlen*2+16, cmddata); clipX=(float)readInt(textlen*2+20, cmddata); clipY=(float)readInt(textlen*2+24, cmddata); clipW=(float)readInt(textlen*2+28, cmddata); clipH=(float)readInt(textlen*2+32, cmddata); // TODO: check if this is needed // if (System.getProperty("java.version").startsWith("1.4")) // clipW = clipW * 5 / 4; // System.out.println("DRAWTEXT: dest=("+x+","+y+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") fontHandle="+fontHandle+" argb="+Integer.toHexString(argb)+" text="+text.toString()); McFont fontPtr = (McFont)fontMap.get(new Integer(fontHandle)); if(fontPtr != null) { // use AWT string bounds or we'll clip on occasion String theString = text.toString(); // java.awt.Dimension textSize = fontPtr.getStringSize(theString); float[] positions = fontPtr.getGlyphPositions(theString); // System.out.println("drawText: \""+theString+"\" loc=("+x+","+y+") num positions="+positions.length); drawTextWithPositions0(theString, fontPtr.nativeFont, x, y, positions, new java.awt.geom.Rectangle2D.Float(clipX,clipY,clipW,clipH), new java.awt.Color(argb, true)); } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXT : " + len); } break; case GFXCMD_DRAWTEXTURED: // x, y, width, height, handle, srcx, srcy, srcwidth, srcheight, blend if(len==40) { float x, y, width, height, srcx, srcy, srcwidth, srcheight; int handle, blend; // blend is a color, use alpha component for blending x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); handle=readInt(16, cmddata); // either an image handle or layer handle (if not in imageMap) srcx=(float)readInt(20, cmddata); srcy=(float)readInt(24, cmddata); srcwidth=(float)readInt(28, cmddata); srcheight=(float)readInt(32, cmddata); blend=readInt(36, cmddata); /* if height < 0 disable blending if width < 0 (font mode, composite with background and blend with given color) blend with full RGBA color else blend with alpha only */ // System.out.println("DRAWTEXTURED: handle="+handle+" dest=("+x+","+y+" "+width+"x"+height+") src=("+srcx+","+srcy+" "+srcwidth+"x"+srcheight+") blend="+Integer.toHexString(blend)); boolean doBlend = true; if(height < 0) { doBlend = false; height *= -1; } if(width < 0) { width *= -1; } else { if(doBlend) blend |= 0x00ffffff; // only use alpha } Long imagePtr = (Long)imageMap.get(new Integer(handle)); java.awt.geom.Rectangle2D.Float destRect = new java.awt.geom.Rectangle2D.Float(x,y,width,height); java.awt.geom.Rectangle2D.Float srcRect = new java.awt.geom.Rectangle2D.Float(srcx,srcy,srcwidth,srcheight); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (drawing image) imagePtr="+imagePtr); drawImage1(imagePtr.longValue(), destRect, srcRect, (doBlend) ? new java.awt.Color(blend, true) : null); } else { imagePtr = (Long)layerMap.get(new Integer(handle)); if(imagePtr != null) { myConn.registerImageAccess(handle); // System.out.println(" (compositing surface) layerPtr="+Long.toHexString(imagePtr.longValue())+" currentLayer="+currentLayer); float alpha = (doBlend ? (float)(((blend >> 24)&0xff))/255.0f : 1.0f); composite0(imagePtr.longValue(), currentLayer, srcRect, destRect, alpha, doBlend); } else { System.out.println("ERROR invalid handle passed for texture rendering of: " + handle); abortRenderCycle = true; } } } else { System.out.println("Invalid len for GFXCMD_DRAWTEXTURED : " + len); } break; case GFXCMD_DRAWLINE: // x1, y1, x2, y2, argb1, argb2 if(len==24) { float x1, y1, x2, y2; int argb1, argb2; x1=readInt(0, cmddata); y1=readInt(4, cmddata); x2=readInt(8, cmddata); y2=readInt(12, cmddata); argb1=readInt(16, cmddata); argb2=readInt(20, cmddata); // System.out.println("DRAWLINE: start=("+x1+","+y1+") end=("+x2+","+y2+") argb1="+Integer.toHexString(argb1)+" argb2="+Integer.toHexString(argb2)); drawLine0(x1, y1, x2, y2, 1, new java.awt.Color(argb1, true)); } else { System.out.println("Invalid len for GFXCMD_DRAWLINE : " + len); } break; case GFXCMD_LOADIMAGE: // width, height if(len>=8) { int width, height; int imghandle = 0; width=readInt(0, cmddata); height=readInt(4, cmddata); // System.out.println("LOADIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) { imghandle = 0; } else { // creating a new image from bitmap data being sent over myConn, create a new empty image long imagePtr = createNewImage0(width, height); imghandle = handleCount++; // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; } hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGE : " + len); } break; case GFXCMD_LOADIMAGETARGETED: // handle, width, height // Not used unless we do uncompressed images if(len>=12) { int width, height; int imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } long imagePtr = createNewImage0(width, height); // System.out.println(" imghandle="+imghandle+" imagePtr="+imagePtr); imageMap.put(new Integer(imghandle), new Long(imagePtr)); // actual value is filled in later when it's prepared imageCacheSize += width * height * 4; myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGETARGETED : " + len); } break; case GFXCMD_CREATESURFACE: // width, height if(len>=8) { int width, height; int handle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); // width/height is managed here long layerPtr = createLayer0(c.getSize()); layerMap.put(new Integer(handle), new Long(layerPtr)); // System.out.println("CREATESURFACE: ("+width+","+height+") handle="+handle+" layerPtr="+layerPtr); hasret[0]=1; return handle; } else { System.out.println("Invalid len for GFXCMD_CREATESURFACE : " + len); } break; case GFXCMD_PREPIMAGE: // width, height if(len>=8) { int width, height; //int imghandle = handleCount++;; width=readInt(0, cmddata); height=readInt(4, cmddata); int imghandle = 1; // System.out.println("PREPIMAGE: size=("+width+"x"+height+")"); if (width * height * 4 + imageCacheSize > imageCacheLimit) imghandle = 0; else if (len >= 12) { // We've got enough room for it and there's a cache ID, check if we've got it cached locally int strlen = readInt(8, cmddata); if (strlen > 1) { String rezName = new String(cmddata, 16, strlen - 1); // System.out.println(" rezName="+rezName); lastImageResourceID = rezName; // We use this hashcode to match it up on the loadCompressedImage call so we know we're caching the right thing lastImageResourceIDHandle = imghandle = Math.abs(lastImageResourceID.hashCode()); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null) { if(imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it imghandle = handleCount++; // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); hasret[0] = 1; return -1 * imghandle; } else freeNativeImage0(imagePtr); } else freeNativeImage0(imagePtr); } } } } //imghandle=STBGFX.GFX_loadImage(width, height); hasret[0]=1; return imghandle; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_PREPIMAGETARGETED: // handle, width, height, [rezID] if(len>=12) { int imghandle, width, height; imghandle = readInt(0, cmddata); width=readInt(4, cmddata); height=readInt(8, cmddata); int strlen = readInt(12, cmddata); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } if (len >= 16) { // We will not have this cached locally...but setup our vars to track it String rezName = new String(cmddata, 20, strlen - 1); lastImageResourceID = rezName; lastImageResourceIDHandle = imghandle; System.out.println("Prepped targeted image with handle " + imghandle + " resource=" + rezName); } myConn.registerImageAccess(imghandle); hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_LOADCACHEDIMAGE: // width, height if(len>=18) { int width, height, imghandle; imghandle = readInt(0, cmddata); width = readInt(4, cmddata); height = readInt(8, cmddata); int strlen = readInt(12, cmddata); String rezName = new String(cmddata, 20, strlen - 1); System.out.println("imghandle=" + imghandle + " width=" + width + " height=" + height + " strlen=" + strlen + " rezName=" + rezName); while (width * height * 4 + imageCacheSize > imageCacheLimit) { // Keep freeing the oldest image until we have enough memory to do this int oldestImage = myConn.getOldestImage(); if (oldestImage != 0) { System.out.println("Freeing image to make room in cache"); unloadImage(oldestImage); myConn.postImageUnload(oldestImage); } else { System.out.println("ERROR cannot free enough from the cache to support loading a new image!!!"); break; } } myConn.registerImageAccess(imghandle); try { System.out.println("Loading resource from cache: " + rezName); java.io.File cachedFile = myConn.getCachedImageFile(rezName); if (cachedFile != null) { // We've got it locally in our cache! Read it from there. System.out.println("Image found in cache!"); // We've got it locally in our cache! Read it from there. long imagePtr = createImageFromPath0(cachedFile.getAbsolutePath()); if(imagePtr != 0) { java.awt.Dimension imgSize = getImageDimensions0(imagePtr); if(imgSize != null && imgSize.getWidth() == width && imgSize.getHeight() == height) { // valid image in cache, use it // System.out.println(" loaded from cache, imagePtr="+imagePtr+" handle="+imghandle); imageMap.put(new Integer(imghandle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); } else { if (imgSize != null) { // It doesn't match the cache System.out.println("CACHE ID verification failed for rezName=" + rezName + " target=" + width + "x" + height + " actual=" + imgSize.getWidth() + "x" + imgSize.getHeight()); } else System.out.println("CACHE Load failed for rezName=" + rezName); cachedFile.delete(); freeNativeImage0(imagePtr); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { cachedFile.delete(); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } else { System.out.println("ERROR Image not found in cache that should be there! rezName=" + rezName); // This load failed but the server thought it would succeed, so we need to inform it that the image is no longer loaded. myConn.postImageUnload(imghandle); myConn.postOfflineCacheChange(false, rezName); } } catch (java.io.IOException e) { System.out.println("ERROR loading compressed image: " + e); } hasret[0]=0; } else { System.out.println("Invalid len for GFXCMD_PREPIMAGE : " + len); } break; case GFXCMD_UNLOADIMAGE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); unloadImage(handle); myConn.clearImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_UNLOADIMAGE : " + len); } break; case GFXCMD_SETTARGETSURFACE: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadImage(handle); Long layerPtr = (Long)layerMap.get(new Integer(handle)); // System.out.println("SETTARGETSURFACE: handle="+handle+" layerPtr="+ (layerPtr == null ? "0" : Long.toHexString(layerPtr.longValue()))); currentLayer = (layerPtr != null) ? layerPtr.longValue() : 0; java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight()); setLayer0(currentLayer, c.getSize(), clipRect); } else { System.out.println("Invalid len for GFXCMD_SETTARGETSURFACE : " + len); } break; case GFXCMD_LOADFONT: // namelen, name, style, size if(len>=12 && len>=(12+readInt(0, cmddata))) { int namelen, style, size; StringBuffer name = new StringBuffer(); int i; int fonthandle = handleCount++; namelen=readInt(0, cmddata); for(i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } style=readInt(namelen+4, cmddata); size=readInt(namelen+8, cmddata); // System.out.println("LOADFONT: handle="+fonthandle+" name="+name.toString()+" style="+Integer.toHexString(style)+" size="+size); McFont fontPtr = new McFont(name.toString(), style, size); // long fontPtr = loadFont0(name.toString(), style, size); if(fontPtr == null) { // FIXME: implement! // we don't have the font on this sytem (yet) see if it's cached and try to load it manually // String cacheName = name.toString() + "-" + style; // fontPtr = loadCachedFont0(cacheDir.getAbsolutePath(), name.toString() + "-" + myConn.getServerName(), style, size); // if (fontPtr == 0) { // Return that we don't have this font so it'll load it into our cache hasret[0] = 1; return 0; // } } // System.out.println(" fontPtr=" + fontPtr); fontMap.put(new Integer(fonthandle), fontPtr); hasret[0] = 1; return fonthandle; } else { System.out.println("Invalid len for GFXCMD_LOADFONT : " + len); } break; case GFXCMD_UNLOADFONT: // handle if(len==4) { int handle; handle=readInt(0, cmddata); //STBGFX.GFX_unloadFont(handle); McFont fontPtr = (McFont)fontMap.get(new Integer(handle)); // System.out.println("UNLOADFONT: handle="+handle+" fontPtr="+fontPtr); if(fontPtr != null) fontPtr.unload(); fontMap.remove(new Integer(handle)); } else { System.out.println("Invalid len for GFXCMD_UNLOADFONT : " + len); } break; case GFXCMD_LOADFONTSTREAM: // namelen, name, len, data if (len>=8) { StringBuffer name = new StringBuffer(); int namelen = readInt(0, cmddata); for(int i=0;i<namelen-1;i++) // skip the terminating \0 character { name.append((char) cmddata[8 + i]); // an extra 4 for the header } int datalen = readInt(4 + namelen, cmddata); if (len >= datalen + 8 + namelen) { // System.out.println("Saving font " + name.toString() + " to cache"); myConn.saveCacheData(name.toString() + "-" + myConn.getServerName(), cmddata, 12 + namelen, datalen); } } else { System.out.println("Invalid len for GFXCMD_LOADFONTSTREAM : " + len); } break; case GFXCMD_FLIPBUFFER: // System.out.println("FLIPBUFFER"); if (abortRenderCycle) { System.out.println("ERROR in painting cycle, ABORT was set...send full repaint command"); myConn.postRepaintEvent(0, 0, c.getWidth(), c.getHeight()); } else { present0(c.nativeView, new java.awt.Rectangle(0, 0, c.getWidth(), c.getHeight())); } hasret[0] = 1; //STBGFX.GFX_flipBuffer(); firstFrameDone = true; return 0; case GFXCMD_STARTFRAME: // System.out.println("STARTFRAME"); // prepare for a new frame to be rendered setTargetView0(c.nativeView); setLayer0(0, c.getSize(), null); // this makes sure the drawing surface gets resized properly abortRenderCycle = false; break; case GFXCMD_LOADIMAGELINE: // handle, line, len, data if(len>=12 && len>=(12+readInt(8, cmddata))) { int handle, line, len2; //unsigned char *data=&cmddata[12]; handle=readInt(0, cmddata); line=readInt(4, cmddata); len2=readInt(8, cmddata); // the last number is the offset into the data array to start reading from //STBGFX.GFX_loadImageLine(handle, line, len, data, 12); //int dataPos = 12; Long imagePtr = (Long)imageMap.get(new Integer(handle)); // System.out.println("LOADIMAGELINE: handle="+handle+" imagePtr="+imagePtr+" line="+line+" len2="+len2); if(imagePtr != null) loadImageLine0(imagePtr.longValue(), line, cmddata, 16/*12*/, len2); myConn.registerImageAccess(handle); } else { System.out.println("Invalid len for GFXCMD_LOADIMAGELINE : " + len); } break; case GFXCMD_LOADIMAGECOMPRESSED: // handle, line, len, data if(len>=8 && len>=(8+readInt(4, cmddata))) { int handle, len2; handle=readInt(0, cmddata); len2=readInt(4, cmddata); if (lastImageResourceID != null && lastImageResourceIDHandle == handle) { myConn.saveCacheData(lastImageResourceID, cmddata, 12, len2); myConn.postOfflineCacheChange(true, lastImageResourceID); } if (!myConn.doesUseAdvancedImageCaching()) { handle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; myConn.registerImageAccess(handle); long imagePtr = createImageFromBytes0(cmddata, 12, len2, null); // FIXME: grab extension if possible // System.out.println("LOADIMAGECOMPRESSED: handle="+handle+" imagePtr="+imagePtr+" len2="+len2); imageMap.put(new Integer(handle), new Long(imagePtr)); imageCacheSize += getImageSize0(imagePtr); return handle; } else { System.out.println("Invalid len for GFXCMD_LOADIMAGECOMPRESSED : " + len); } break; case GFXCMD_XFMIMAGE: // srcHandle, destHandle, destWidth, destHeight, maskCornerArc if (len >= 20) { int srcHandle, destHandle, destWidth, destHeight, maskCornerArc; srcHandle = readInt(0, cmddata); destHandle = readInt(4, cmddata); // seems to be unused destWidth = readInt(8, cmddata); // scaled size (ignore?) destHeight = readInt(12, cmddata); maskCornerArc = readInt(16, cmddata); int rvHandle = destHandle; if (!myConn.doesUseAdvancedImageCaching()) { rvHandle = handleCount++; hasret[0] = 1; } else hasret[0] = 0; // we cheat and apply the transforms to a metaimage object without actually creating a new image (saves oodles of memory) Long srcImg = (Long)imageMap.get(new Integer(srcHandle)); // System.out.println("XFMIMAGE: srcHandle="+srcHandle+" srcImg="+srcImg+" destHandle="+destHandle+" destWidth="+destWidth+" destHeight="+destHeight+" maskCornerArc="+maskCornerArc); if(srcImg != null) { long newImage = transformImage0(srcImg.longValue(), destWidth, destHeight, maskCornerArc); if(newImage != 0) { // System.out.println(" newImage="+newImage); imageMap.put(new Integer(rvHandle), new Long(newImage)); } } return rvHandle; } else { System.out.println("Invalid len for GFXCMD_XFMIMAGE : " + len); } break; case GFXCMD_SETVIDEOPROP: if (len >= 40) { java.awt.Rectangle srcRect = new java.awt.Rectangle(readInt(4, cmddata), readInt(8, cmddata), readInt(12, cmddata), readInt(16, cmddata)); java.awt.Rectangle destRect = new java.awt.Rectangle(readInt(20, cmddata), readInt(24, cmddata), readInt(28, cmddata), readInt(32, cmddata)); System.out.println("SETVIDEOPROP: srcRect="+srcRect+" dstRect="+destRect); setVideoBounds(srcRect, destRect); } else { System.out.println("Invalid len for GFXCMD_SETVIDEOPROP: " + len); } break; default: return -1; } return 0; }
NONSATD
true
break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) {
null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata);
clipY=(float)readInt(44, cmddata); clipW=(float)readInt(48, cmddata); clipH=(float)readInt(52, cmddata); // System.out.println("DRAWROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") thickness="+thickness+" arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); // FIXME: no gradients on stroked shapes java.awt.geom.Rectangle2D.Float bounds = new java.awt.geom.Rectangle2D.Float(x, y, width, height); java.awt.geom.Rectangle2D.Float clipRect = new java.awt.geom.Rectangle2D.Float(clipX, clipY, clipW, clipH); drawRect0(bounds, clipRect, arcRadius, new java.awt.Color(argbTL, true), thickness, null, 0.0f, 0.0f, null, 0.0f, 0.0f, 1.0f); } else { System.out.println("Invalid len for GFXCMD_DRAWROUNDRECT : " + len); } break; case GFXCMD_FILLROUNDRECT: // x, y, width, height, arcRadius, argbTL, argbTR, argbBR, argbBL, // clipX, clipY, clipW, clipH if(len==52) { float x, y, width, height, clipX, clipY, clipW, clipH; int arcRadius, argbTL, argbTR, argbBR, argbBL; x=(float)readInt(0, cmddata); y=(float)readInt(4, cmddata); width=(float)readInt(8, cmddata); height=(float)readInt(12, cmddata); arcRadius=readInt(16, cmddata); argbTL=readInt(20, cmddata); argbTR=readInt(24, cmddata); argbBR=readInt(28, cmddata); argbBL=readInt(32, cmddata); clipX=(float)readInt(36, cmddata); clipY=(float)readInt(40, cmddata); clipW=(float)readInt(44, cmddata); clipH=(float)readInt(48, cmddata); // System.out.println("FILLROUNDRECT: dest=("+x+","+y+" "+width+"x"+height+") clip=("+clipX+","+clipY+" "+clipW+"x"+clipH+") arcRadius="+arcRadius+" argbTL="+Integer.toHexString(argbTL)+" argbTR="+Integer.toHexString(argbTR)+" argbBL="+Integer.toHexString(argbBL)+" argbBR="+Integer.toHexString(argbBR)); java.awt.GradientPaint gp = getGradient(x, y, width, height, argbTL, argbTR, argbBL, argbBR);