use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.
the class RoundBorder method fillShape.
private void fillShape(Graphics g, int color, int opacity, int width, int height, boolean stroke) {
g.setColor(color);
g.setAlpha(opacity);
if (!rectangle || width <= height) {
int x = 0;
int y = 0;
int size = width;
if (width != height) {
if (width > height) {
size = height;
x = (width - height) / 2;
} else {
size = width;
y = (height - width) / 2;
}
}
if (size < 5) {
// probably won't be visible anyway so do nothing, otherwise it might throw an exception
return;
}
if (stroke && this.stroke != null) {
int sw = (int) Math.ceil((stroke && this.stroke != null) ? this.stroke.getLineWidth() : 0);
GeneralPath arc = new GeneralPath();
arc.arc(x + sw / 2, y + sw / 2, size - 2 * sw, size - 2 * sw, 0, 2 * Math.PI);
g.fillShape(arc);
g.setColor(strokeColor);
g.setAlpha(strokeOpacity);
if (strokeAngle != 360) {
arc = new GeneralPath();
arc.arc(x + sw / 2, y + sw / 2, size - 2 * sw, size - 2 * sw, Math.PI / 2, -Math.toRadians(strokeAngle));
}
g.drawShape(arc, this.stroke);
} else {
g.fillArc(x, y, size, size, 0, 360);
}
} else {
GeneralPath gp = new GeneralPath();
float sw = (stroke && this.stroke != null) ? this.stroke.getLineWidth() : 0;
gp.moveTo(height / 2.0, sw);
gp.lineTo(width - (height / 2.0), sw);
gp.arcTo(width - (height / 2.0), height / 2.0, width - (height / 2.0), height - sw, true);
gp.lineTo(height / 2.0, height - sw);
gp.arcTo(height / 2.0, height / 2.0, height / 2.0, sw, true);
gp.closePath();
g.fillShape(gp);
if (stroke && this.stroke != null) {
g.setAlpha(strokeOpacity);
g.setColor(strokeColor);
g.drawShape(gp, this.stroke);
}
}
}
use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.
the class RoundBorder method createTargetImage.
private Image createTargetImage(Component c, int w, int h, boolean fast) {
Image target = Image.createImage(w, h, 0);
int shapeX = 0;
int shapeY = 0;
int shapeW = w;
int shapeH = h;
Graphics tg = target.getGraphics();
tg.setAntiAliased(true);
int shadowSpreadL = shadowSpread;
if (shadowMM) {
shadowSpreadL = Display.getInstance().convertToPixels(shadowSpreadL);
}
if (shadowOpacity > 0) {
shapeW -= shadowSpreadL;
shapeW -= (shadowBlur / 2);
shapeH -= shadowSpreadL;
shapeH -= (shadowBlur / 2);
shapeX += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowX);
shapeY += Math.round((shadowSpreadL + (shadowBlur / 2)) * shadowY);
// draw a gradient of sort for the shadow
for (int iter = shadowSpreadL - 1; iter >= 0; iter--) {
tg.translate(iter, iter);
fillShape(tg, 0, shadowOpacity / shadowSpreadL, w - (iter * 2), h - (iter * 2), false);
tg.translate(-iter, -iter);
}
if (Display.getInstance().isGaussianBlurSupported() && !fast) {
Image blured = Display.getInstance().gaussianBlurImage(target, shadowBlur / 2);
target = Image.createImage(w, h, 0);
tg = target.getGraphics();
tg.drawImage(blured, 0, 0);
tg.setAntiAliased(true);
}
}
tg.translate(shapeX, shapeY);
if (uiid && tg.isShapeClipSupported()) {
c.getStyle().setBorder(Border.createEmpty());
GeneralPath gp = new GeneralPath();
if (rectangle) {
float sw = this.stroke != null ? this.stroke.getLineWidth() : 0;
gp.moveTo(shapeH / 2.0, sw);
gp.lineTo(shapeW - (shapeH / 2.0), sw);
gp.arcTo(shapeW - (shapeH / 2.0), shapeH / 2.0, shapeW - (shapeH / 2.0), shapeH - sw, true);
gp.lineTo(shapeH / 2.0, shapeH - sw);
gp.arcTo(shapeH / 2.0, shapeH / 2.0, shapeH / 2.0, sw, true);
gp.closePath();
} else {
int size = shapeW;
int xPos = 0;
int yPos = 0;
if (shapeW != shapeH) {
if (shapeW > shapeH) {
size = shapeH;
xPos = (shapeW - shapeH) / 2;
} else {
size = shapeW;
yPos = (shapeH - shapeW) / 2;
}
}
gp.arc(xPos, yPos, size, size, 0, 2 * Math.PI);
}
tg.setClip(gp);
c.getStyle().getBgPainter().paint(tg, new Rectangle(0, 0, w, h));
c.getStyle().setBorder(this);
} else {
fillShape(tg, color, opacity, shapeW, shapeH, true);
}
return target;
}
use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.
the class RoundBorder method stroke.
/**
* Sets the stroke of the circle/rectangle
* @param stroke the thickness of the stroke object
* @param mm set to true to indicate the value is in millimeters, false indicates pixels
* @return border instance so these calls can be chained
*/
public RoundBorder stroke(float stroke, boolean mm) {
strokeThickness = stroke;
if (strokeThickness == 0) {
this.stroke = null;
return this;
}
strokeMM = mm;
if (mm) {
stroke = Display.getInstance().convertToPixels(stroke);
}
return stroke(new Stroke(stroke, Stroke.CAP_SQUARE, Stroke.JOIN_MITER, 1));
}
use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.
the class JavaSEPort method loadSkinFile.
private void loadSkinFile(InputStream skin, final JFrame frm) {
try {
ZipInputStream z = new ZipInputStream(skin);
ZipEntry e = z.getNextEntry();
final Properties props = new Properties();
BufferedImage map = null;
BufferedImage landscapeMap = null;
// if we load the native theme imediately the multi-image's will be loaded with the size of the old skin
byte[] nativeThemeData = null;
nativeThemeRes = null;
nativeTheme = null;
while (e != null) {
String name = e.getName();
if (name.equals("skin.png")) {
portraitSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header.png")) {
header = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header_l.png")) {
headerLandscape = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin.properties")) {
props.load(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_l.png")) {
landscapeSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map.png")) {
map = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map_l.png")) {
landscapeMap = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.endsWith(".res")) {
long esize = e.getSize();
if (esize > 0) {
nativeThemeData = new byte[(int) esize];
readFully(z, nativeThemeData);
} else {
ByteArrayOutputStream b = new ByteArrayOutputStream();
Util.copyNoClose(z, b, 8192);
nativeThemeData = b.toByteArray();
}
e = z.getNextEntry();
continue;
}
if (name.endsWith(".ttf")) {
try {
java.awt.Font result = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, z);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(result);
} catch (FontFormatException ex) {
ex.printStackTrace();
}
e = z.getNextEntry();
continue;
}
e = z.getNextEntry();
}
z.close();
String ppi = props.getProperty("ppi");
if (ppi != null) {
double ppiD = Double.valueOf(ppi);
pixelMilliRatio = ppiD / 25.4;
} else {
String pix = props.getProperty("pixelRatio");
if (pix != null && pix.length() > 0) {
try {
pixelMilliRatio = Double.valueOf(pix);
} catch (NumberFormatException err) {
err.printStackTrace();
pixelMilliRatio = null;
}
} else {
pixelMilliRatio = null;
}
}
portraitSkinHotspots = new HashMap<Point, Integer>();
portraitScreenCoordinates = new Rectangle();
landscapeSkinHotspots = new HashMap<Point, Integer>();
landscapeScreenCoordinates = new Rectangle();
if (props.getProperty("roundScreen", "false").equalsIgnoreCase("true")) {
portraitScreenCoordinates.x = Integer.parseInt(props.getProperty("displayX"));
portraitScreenCoordinates.y = Integer.parseInt(props.getProperty("displayY"));
portraitScreenCoordinates.width = Integer.parseInt(props.getProperty("displayWidth"));
portraitScreenCoordinates.height = Integer.parseInt(props.getProperty("displayHeight"));
landscapeScreenCoordinates.x = portraitScreenCoordinates.y;
landscapeScreenCoordinates.y = portraitScreenCoordinates.x;
landscapeScreenCoordinates.width = portraitScreenCoordinates.height;
landscapeScreenCoordinates.height = portraitScreenCoordinates.width;
roundedSkin = true;
} else {
initializeCoordinates(map, props, portraitSkinHotspots, portraitScreenCoordinates);
initializeCoordinates(landscapeMap, props, landscapeSkinHotspots, landscapeScreenCoordinates);
}
platformName = props.getProperty("platformName", "se");
platformOverrides = props.getProperty("overrideNames", "").split(",");
String ua = null;
if (platformName.equals("and")) {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
} else if (platformName.equals("rim")) {
ua = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9860; en-GB) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.296 Mobile Safari/534.11+";
} else if (platformName.equals("ios")) {
if (isTablet()) {
ua = "Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5";
} else {
ua = "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";
}
} else if (platformName.equals("me")) {
ua = "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124";
} else {
if (platformName.equals("win")) {
ua = "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)";
} else {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
}
}
Display.getInstance().setProperty("User-Agent", ua);
isIOS = props.getProperty("systemFontFamily", "Arial").toLowerCase().contains("helvetica");
setFontFaces(props.getProperty("systemFontFamily", "Arial"), props.getProperty("proportionalFontFamily", "SansSerif"), props.getProperty("monospaceFontFamily", "Monospaced"));
int med;
int sm;
int la;
if (pixelMilliRatio == null) {
float factor = ((float) getDisplayHeightImpl()) / 480.0f;
med = (int) (15.0f * factor);
sm = (int) (11.0f * factor);
la = (int) (19.0f * factor);
} else {
med = (int) Math.round(2.6 * pixelMilliRatio.doubleValue());
sm = (int) Math.round(2 * pixelMilliRatio.doubleValue());
la = (int) Math.round(3.3 * pixelMilliRatio.doubleValue());
}
setFontSize(Integer.parseInt(props.getProperty("mediumFontSize", "" + med)), Integer.parseInt(props.getProperty("smallFontSize", "" + sm)), Integer.parseInt(props.getProperty("largeFontSize", "" + la)));
tablet = props.getProperty("tablet", "false").equalsIgnoreCase("true");
rotateTouchKeysOnLandscape = props.getProperty("rotateKeys", "false").equalsIgnoreCase("true");
touchDevice = props.getProperty("touch", "true").equalsIgnoreCase("true");
keyboardType = Integer.parseInt(props.getProperty("keyboardType", "0"));
softkeyCount = Integer.parseInt(props.getProperty("softbuttonCount", "1"));
if (softkeyCount < 2) {
// the values of the static variables to be correct!
try {
Field f = com.codename1.ui.MenuBar.class.getDeclaredField("leftSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F1);
f = com.codename1.ui.MenuBar.class.getDeclaredField("rightSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F2);
} catch (Throwable t) {
t.printStackTrace();
}
}
final byte[] nativeThemeFinalData = nativeThemeData;
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (nativeThemeFinalData != null) {
try {
nativeThemeRes = Resources.open(new ByteArrayInputStream(nativeThemeFinalData));
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
try {
boolean isJ2me = props.getProperty("platformName", "").equals("me");
String t = props.getProperty("nativeThemeAttribute", null);
if (t != null) {
Properties cnop = new Properties();
File cnopFile = new File("codenameone_settings.properties");
if (cnopFile.exists()) {
cnop.load(new FileInputStream(cnopFile));
int themeConst = Integer.parseInt(cnop.getProperty("codename1.j2me.nativeThemeConst", "3"));
t = cnop.getProperty(t, null);
if (isJ2me && themeConst == 3 && t != null && new File(t).exists()) {
nativeThemeRes = Resources.open(new FileInputStream(t));
}
}
}
} catch (IOException ioErr) {
ioErr.printStackTrace();
}
}
}
});
installMenu(frm, false);
} catch (IOException err) {
err.printStackTrace();
}
}
use of com.codename1.ui.geom.Rectangle in project CodenameOne by codenameone.
the class IOSImplementation method share.
@Override
public void share(String text, String image, String mimeType, Rectangle sourceRect) {
if (image != null && image.length() > 0) {
try {
Image img = Image.createImage(image);
if (img == null) {
nativeInstance.socialShare(text, 0, sourceRect);
return;
}
NativeImage n = (NativeImage) img.getImage();
nativeInstance.socialShare(text, n.peer, sourceRect);
} catch (IOException err) {
err.printStackTrace();
Dialog.show("Error", "Error loading image: " + image, "OK", null);
}
} else {
nativeInstance.socialShare(text, 0, sourceRect);
}
}
Aggregations