use of com.codename1.ui.Painter in project CodenameOne by codenameone.
the class SideMenuBar method setMenuGlassPane.
private void setMenuGlassPane(Form m, final String placement) {
boolean isRTLValue = m.isRTL();
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
isRTLValue = !isRTLValue;
}
final boolean isRTL = isRTLValue;
final Image image = rightPanel.getStyle().getBgImage();
UIManager uim = rightPanel.getUIManager();
Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
if (sh == null) {
sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
}
if (isRTL) {
sh = sh.flipHorizontally(true);
}
final Image shadow = sh;
if (m.getGlassPane() == null) {
m.setGlassPane(new Painter() {
Image img = image;
public void paint(Graphics g, Rectangle rect) {
if (img == null) {
// will happen for areMutableImagesFast returning false on iOS and Windows Phone
Component c = (Component) rightPanel.getClientProperty("$parent");
// not sure what is happening here
if (c == null) {
return;
}
boolean b = c.isVisible();
c.setVisible(true);
if (isRTL) {
int x = Math.max(draggedX, rightPanel.getWidth()) - c.getWidth();
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
if (shadow != null) {
g.tileImage(shadow, x + c.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
} else {
int x = Math.min(draggedX, rightPanel.getX());
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
if (shadow != null) {
g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
}
c.setVisible(b);
} else {
if (Display.getInstance().areMutableImagesFast()) {
if (img.getHeight() != Display.getInstance().getDisplayHeight()) {
img = updateRightPanelBgImage(placement, parent);
}
}
if (isRTL) {
int x = Math.max(draggedX, rightPanel.getWidth()) - img.getWidth();
if (shadow != null) {
g.tileImage(shadow, x + img.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
g.drawImage(img, x, 0);
} else {
int x = Math.min(draggedX, rightPanel.getX());
if (shadow != null) {
g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
g.drawImage(img, x, 0);
}
}
}
});
}
}
use of com.codename1.ui.Painter in project CodenameOne by codenameone.
the class Component method drawPaintersImpl.
private void drawPaintersImpl(com.codename1.ui.Graphics g, Component par, Component c, int x, int y, int w, int h) {
if (par == null) {
return;
} else {
if (par.getStyle().getBgTransparency() != ((byte) 0xFF)) {
drawPainters(g, par.getParent(), par, x, y, w, h);
}
}
if (!par.isVisible()) {
return;
}
int transX = par.getAbsoluteX() + par.getScrollX();
int transY = par.getAbsoluteY() + par.getScrollY();
g.translate(transX, transY);
((Container) par).paintIntersecting(g, c, x, y, w, h, false);
if (par.isBorderPainted()) {
Border b = par.getBorder();
if (b.isBackgroundPainter()) {
g.translate(-par.getX(), -par.getY());
par.paintBorderBackground(g);
par.paintBorder(g);
g.translate(par.getX() - transX, par.getY() - transY);
return;
}
}
Painter p = par.getStyle().getBgPainter();
if (p != null) {
Rectangle rect;
if (painterBounds == null) {
painterBounds = new Rectangle(0, 0, par.getWidth(), par.getHeight());
rect = painterBounds;
} else {
rect = painterBounds;
rect.getSize().setWidth(par.getWidth());
rect.getSize().setHeight(par.getHeight());
}
p.paint(g, rect);
}
par.paintBackground(g);
g.translate(-transX, -transY);
}
use of com.codename1.ui.Painter in project CodenameOne by codenameone.
the class Component method animate.
/**
* {@inheritDoc}
*/
public boolean animate() {
if (!visible) {
return false;
}
Image bgImage = getStyle().getBgImage();
boolean animateBackground = bgImage != null && bgImage.isAnimation() && bgImage.animate();
Motion m = getAnimationMotion();
// perform regular scrolling
if (m != null && destScrollY != -1 && destScrollY != getScrollY()) {
// change the variable directly for efficiency both in removing redundant
// repaints and scroll checks
setScrollY(m.getValue());
if (destScrollY == scrollY) {
destScrollY = -1;
deregisterAnimatedInternal();
updateTensileHighlightIntensity(0, 0, m != null);
}
return true;
}
boolean animateY = false;
boolean animateX = false;
// perform the dragging motion if exists
if (draggedMotionY != null) {
// change the variable directly for efficiency both in removing redundant
// repaints and scroll checks
int dragVal = draggedMotionY.getValue();
// this can't be a part of the parent if since we need the last value to arrive
if (draggedMotionY.isFinished()) {
if (dragVal < 0) {
startTensile(dragVal, 0, true);
} else {
int iv = getInvisibleAreaUnderVKB();
int edge = (getScrollDimension().getHeight() - getHeight() + iv);
if (dragVal > edge && edge > 0) {
startTensile(dragVal, getScrollDimension().getHeight() - getHeight() + iv, true);
} else {
if (snapToGrid && getScrollY() < edge && getScrollY() > 0) {
boolean tVal = tensileDragEnabled;
tensileDragEnabled = true;
int dest = getGridPosY();
int scroll = getScrollY();
if (dest != scroll) {
startTensile(scroll, dest, true);
} else {
draggedMotionY = null;
}
tensileDragEnabled = tVal;
} else {
draggedMotionY = null;
}
}
}
// special callback to scroll Y to allow developers to override the setScrollY method effectively
setScrollY(dragVal);
updateTensileHighlightIntensity(dragVal, getScrollDimension().getHeight() - getHeight() + getInvisibleAreaUnderVKB(), false);
}
if (scrollListeners != null) {
scrollListeners.fireScrollEvent(this.scrollX, dragVal, this.scrollX, this.scrollY);
}
scrollY = dragVal;
onScrollY(scrollY);
updateTensileHighlightIntensity(0, 0, false);
animateY = true;
}
if (draggedMotionX != null) {
// change the variable directly for efficiency both in removing redundant
// repaints and scroll checks
int dragVal = draggedMotionX.getValue();
// this can't be a part of the parent if since we need the last value to arrive
if (draggedMotionX.isFinished()) {
if (dragVal < 0) {
startTensile(dragVal, 0, false);
} else {
int edge = (getScrollDimension().getWidth() - getWidth());
if (dragVal > edge && edge > 0) {
startTensile(dragVal, getScrollDimension().getWidth() - getWidth(), false);
} else {
if (snapToGrid && getScrollX() < edge && getScrollX() > 0) {
boolean tVal = tensileDragEnabled;
tensileDragEnabled = true;
int dest = getGridPosX();
int scroll = getScrollX();
if (dest != scroll) {
startTensile(scroll, dest, false);
} else {
draggedMotionX = null;
}
tensileDragEnabled = tVal;
} else {
draggedMotionX = null;
}
}
}
// special callback to scroll X to allow developers to override the setScrollY method effectively
setScrollX(dragVal);
}
if (scrollListeners != null) {
scrollListeners.fireScrollEvent(dragVal, this.scrollY, this.scrollX, this.scrollY);
}
scrollX = dragVal;
onScrollX(scrollX);
animateX = true;
}
if (animateY || animateX) {
return true;
}
if (getClientProperty("$pullToRelease") != null) {
return true;
}
Painter bgp = getStyle().getBgPainter();
boolean animateBackgroundB = bgp != null && bgp.getClass() != BGPainter.class && bgp instanceof Animation && (bgp != this) && ((Animation) bgp).animate();
animateBackground = animateBackgroundB || animateBackground;
if (getUIManager().getLookAndFeel().isFadeScrollBar()) {
if (tensileHighlightIntensity > 0) {
tensileHighlightIntensity = Math.max(0, tensileHighlightIntensity - (scrollOpacityChangeSpeed * 2));
}
if (scrollOpacity > 0 && !dragActivated) {
scrollOpacity = Math.max(0, scrollOpacity - scrollOpacityChangeSpeed);
return true;
}
}
if (!animateBackground && (destScrollY == -1 || destScrollY == scrollY) && !animateBackground && m == null && draggedMotionY == null && draggedMotionX == null && !dragActivated) {
tryDeregisterAnimated();
}
return animateBackground;
}
Aggregations