use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class BubbleTransition method paint.
@Override
public void paint(Graphics g) {
Component source = getSource();
Component dest = getDestination();
Component srcCmp = source;
Component destCmp = dest;
if ((source instanceof Dialog && dest instanceof Form) || originDest != null) {
srcCmp = dest;
destCmp = source;
}
paint(g, srcCmp, -srcCmp.getAbsoluteX(), -srcCmp.getAbsoluteY(), true);
int[] clip = g.getClip();
if (destCmp instanceof Dialog) {
destCmp = getDialogParent(destCmp);
}
if (roundBubble && g.isShapeClipSupported()) {
GeneralPath p = getBubbleShape();
p.reset();
p.arc(x + destCmp.getWidth() / 2 - clipSize / 2, y + destCmp.getHeight() / 2 - clipSize / 2, clipSize, clipSize, 0, Math.toRadians(360));
g.setClip(p);
} else {
g.setClip(x + destCmp.getWidth() / 2 - clipSize / 2, y + destCmp.getHeight() / 2 - clipSize / 2, clipSize, clipSize);
}
g.drawImage(destBuffer, x, y);
g.setClip(clip);
}
use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class CommonTransitions method drawDialogCmp.
private void drawDialogCmp(Graphics g, Dialog dlg) {
Painter p = dlg.getStyle().getBgPainter();
dlg.getStyle().setBgPainter(null);
g.setClip(0, 0, dlg.getWidth(), dlg.getHeight());
g.translate(-getDialogParent(dlg).getX(), -getDialogParent(dlg).getY() + getDialogTitleHeight(dlg));
getDialogParent(dlg).paintComponent(g, false);
if (drawDialogMenu && dlg.getCommandCount() > 0) {
Component menuBar = dlg.getSoftButton(0).getParent();
if (menuBar != null) {
g.setClip(0, 0, dlg.getWidth(), dlg.getHeight());
menuBar.paintComponent(g, false);
}
}
dlg.getStyle().setBgPainter(p);
}
use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class CommonTransitions method paint.
private void paint(Graphics g, Component cmp, int x, int y, boolean background) {
boolean b = cmp.isVisible();
cmp.setVisible(true);
int cx = g.getClipX();
int cy = g.getClipY();
int cw = g.getClipWidth();
int ch = g.getClipHeight();
if (cmp instanceof Dialog) {
if (transitionType == TYPE_FADE && Display.getInstance().areMutableImagesFast()) {
cmp.paintComponent(g, background);
return;
}
if (!(getSource() instanceof Dialog && getDestination() instanceof Dialog && cmp == getDestination())) {
Painter p = cmp.getStyle().getBgPainter();
cmp.getStyle().setBgPainter(null);
g.translate(x, y);
Dialog dlg = (Dialog) cmp;
g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());
getDialogParent(dlg).paintComponent(g, false);
g.translate(-x, -y);
if (drawDialogMenu && dlg.getCommandCount() > 0) {
Component menuBar = dlg.getSoftButton(0).getParent();
if (menuBar != null) {
g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());
menuBar.paintComponent(g, false);
}
}
g.setClip(cx, cy, cw, ch);
cmp.getStyle().setBgPainter(p);
} else {
cmp.paintComponent(g, background);
}
return;
}
// g.clipRect(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
g.translate(x, y);
// g.clipRect(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
cmp.paintComponent(g, background);
g.translate(-x, -y);
g.setClip(cx, cy, cw, ch);
cmp.setVisible(b);
}
use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class CommonTransitions method paintCoverAtPosition.
private void paintCoverAtPosition(Graphics g, int slideX, int slideY) {
Component source = getSource();
// if this is the first form we can't do a slide transition since we have no source form
if (source == null) {
return;
}
Component dest = getDestination();
int w = source.getWidth();
int h = source.getHeight();
if (slideType == SLIDE_HORIZONTAL) {
h = 0;
} else {
w = 0;
}
boolean dir = forward;
if (dest != null && dest.getUIManager().getLookAndFeel().isRTL()) {
dir = !dir;
}
if (dir) {
w = -w;
h = -h;
} else {
slideX = -slideX;
slideY = -slideY;
}
g.setClip(source.getAbsoluteX() + source.getScrollX(), source.getAbsoluteY() + source.getScrollY(), source.getWidth(), source.getHeight());
// dialog animation is slightly different...
if (source instanceof Dialog) {
if (buffer != null) {
g.drawImage(buffer, 0, 0);
} else {
paint(g, dest, 0, 0);
}
paint(g, source, -slideX, -slideY);
return;
}
if (dest instanceof Dialog) {
if (buffer != null) {
g.drawImage(buffer, 0, 0);
} else {
paint(g, source, 0, 0);
}
paint(g, dest, -slideX - w, -slideY - h);
return;
}
if (transitionType == TYPE_UNCOVER) {
paint(g, dest, 0, 0);
if (source.getParent() != null || buffer == null) {
source.paintBackgrounds(g);
paint(g, source, slideX + w, slideY + h);
} else {
g.drawImage(buffer, slideX + w, slideY + h);
}
} else {
if (source.getParent() != null || buffer == null) {
source.paintBackgrounds(g);
paint(g, source, 0, 0);
} else {
g.drawImage(buffer, 0, 0);
}
paint(g, dest, slideX + w, slideY + h);
}
}
use of com.codename1.ui.Dialog in project CodenameOne by codenameone.
the class SideMenuBar method installMenuBar.
/**
* {@inheritDoc}
*/
protected void installMenuBar() {
if (parent.getClientProperty("Menu") != null) {
return;
}
super.installMenuBar();
if (parent instanceof Dialog) {
return;
}
openButton = createOpenButton();
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
openMenu(null);
}
});
addOpenButton(null, true);
UIManager uim = parent.getUIManager();
final boolean[] hasSideMenus = new boolean[2];
if (uim.isThemeConstant("sideMenuFoldedSwipeBool", true) && parent.getClientProperty("sideMenuFoldedSwipeListeners") == null) {
pointerDragged = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (sideSwipePotential && hasSideMenus[0]) {
final int x = evt.getX();
final int y = evt.getY();
if (Math.abs(y - initialDragY) > x - initialDragX) {
sideSwipePotential = false;
return;
}
evt.consume();
if (x - initialDragX > Display.getInstance().getDisplayWidth() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
draggedX = x;
dragActivated = true;
parent.pointerReleased(-1, -1);
openMenu(null, 0, draggedX, false);
initialDragX = 0;
initialDragY = 0;
}
return;
}
if (rightSideSwipePotential && (hasSideMenus[1] || (hasSideMenus[0] && isRTL()))) {
final int x = evt.getX();
final int y = evt.getY();
if (x < 0 || Math.abs(y - initialDragY) > initialDragX - x) {
rightSideSwipePotential = false;
return;
}
evt.consume();
if (initialDragX - x > Display.getInstance().getDisplayWidth() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
draggedX = x;
dragActivated = true;
parent.pointerReleased(-1, -1);
if (isRTL()) {
openMenu(null, 0, draggedX, false);
} else {
openMenu(COMMAND_PLACEMENT_VALUE_RIGHT, 0, draggedX, false);
}
initialDragX = 0;
initialDragY = 0;
}
}
if (topSwipePotential) {
final int x = evt.getX();
final int y = evt.getY();
if (Math.abs(y - initialDragY) < x - initialDragX) {
topSwipePotential = false;
return;
}
evt.consume();
if (initialDragY - y > Display.getInstance().getDisplayHeight() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
draggedX = y;
dragActivated = true;
parent.pointerReleased(-1, -1);
openMenu(COMMAND_PLACEMENT_VALUE_TOP, 0, draggedX, false);
initialDragX = 0;
initialDragY = 0;
}
}
}
};
parent.addPointerDraggedListener(pointerDragged);
pointerPressed = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
rightSideSwipePotential = false;
topSwipePotential = false;
sideSwipePotential = false;
if (getCommandCount() == 0) {
return;
}
if (parent.getCommandCount() == 1) {
if (parent.getCommand(0) == parent.getBackCommand()) {
return;
}
}
for (int iter = 0; iter < getCommandCount(); iter++) {
Command c = getCommand(iter);
String p = (String) c.getClientProperty(COMMAND_PLACEMENT_KEY);
if (p == null) {
// has left menu
hasSideMenus[0] = true;
} else if (p.equals(COMMAND_PLACEMENT_VALUE_RIGHT)) {
// has right menu
hasSideMenus[1] = true;
}
}
int displayWidth = Display.getInstance().getDisplayWidth();
if (rightSideButton != null || isRTL()) {
rightSideSwipePotential = !transitionRunning && evt.getX() > displayWidth - displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
}
if (getTitleComponent() instanceof Button) {
topSwipePotential = !transitionRunning && evt.getY() < Display.getInstance().getDisplayHeight() / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
}
sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
initialDragX = evt.getX();
initialDragY = evt.getY();
if (sideSwipePotential || rightSideSwipePotential || topSwipePotential) {
Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
if (c != null && c.shouldBlockSideSwipe()) {
sideSwipePotential = false;
}
}
}
};
parent.addPointerPressedListener(pointerPressed);
parent.putClientProperty("sideMenuFoldedSwipeListeners", "true");
}
}
Aggregations