Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 83 additions & 78 deletions TotalCrossSDK/src/main/java/totalcross/ui/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -788,97 +788,102 @@ public void onPaint(Graphics g) {
if (skipPaint) {
return;
}

int tx = tx0;
int ty = ty0;
int ix = ix0;
int iy = iy0;

if ((uiMaterial || uiAndroid) && this.border == BORDER_3D) {
int bbackColor = isEnabled() ?
backColor : (uiMaterial ? disabledColor : Color.interpolate(parent.backColor, backColor));
if(!transparentBackground) {
g.backColor = bbackColor;
if(!drawNinePatch) {
g.fillRect(4, 4, width - 6, height - 6);

boolean rendererPainted = controlRenderer != null;
if (rendererPainted) {
controlRenderer.draw(g, 0, 0, width, height, armed);
} else {
if ((uiMaterial || uiAndroid) && this.border == BORDER_3D) {
int bbackColor = isEnabled() ?
backColor : (uiMaterial ? disabledColor : Color.interpolate(parent.backColor, backColor));
if(!transparentBackground) {
g.backColor = bbackColor;
if(!drawNinePatch) {
g.fillRect(4, 4, width - 6, height - 6);
}
}
}

if(npParts != null) {
try {
if (!drawTranslucentBackground(g, armed ? alphaValue >= 80 ? alphaValue / 2 : alphaValue * 2 : alphaValue)) {
if(npback == null) {
npback = NinePatch.getInstance().getNormalInstance(npParts, width, height,
isEnabled() ? transparentBackground ? borderColor : bbackColor : bbackColor, false);
if(npParts != null) {
try {
if (!drawTranslucentBackground(g, armed ? alphaValue >= 80 ? alphaValue / 2 : alphaValue * 2 : alphaValue)) {
if(npback == null) {
npback = NinePatch.getInstance().getNormalInstance(npParts, width, height,
isEnabled() ? transparentBackground ? borderColor : bbackColor : bbackColor, false);
}
this.originalForeColor = this.originalForeColor == -1 ? this.foreColor : this.originalForeColor;
this.foreColor = this.isEnabled() ? this.originalForeColor : Color.BLACK;
}
this.originalForeColor = this.originalForeColor == -1 ? this.foreColor : this.originalForeColor;
this.foreColor = this.isEnabled() ? this.originalForeColor : Color.BLACK;
}
if (npback != null) {
NinePatch.tryDrawImage(g, armed && (isSticky || effect == null) ?
NinePatch.getInstance().getPressedInstance(npback, backColor,pressColor) : npback,
0, 0);
if (npback != null) {
NinePatch.tryDrawImage(g, armed && (isSticky || effect == null) ?
NinePatch.getInstance().getPressedInstance(npback, backColor,pressColor) : npback,
0, 0);
}
} catch (ImageException ie) {
ie.printStackTrace();
}
} catch (ImageException ie) {
ie.printStackTrace();
}
}
} else {
boolean isBorderRound = border == BORDER_ROUND;
if (uiMaterial && effect != null) {
effect.darkSideOnPress = border != BORDER_NONE;
}
if (isAndroidStyle) {
if (translucentShape == TranslucentShape.NONE && !uiMaterial && !Settings.isOpenGL) {
g.getClip(clip);
g.backColor = Settings.isOpenGL ? parent.backColor : g.getPixel(clip.x, clip.y);
g.fillRect(0, 0, width, height);
} else {
boolean isBorderRound = border == BORDER_ROUND;
if (uiMaterial && effect != null) {
effect.darkSideOnPress = border != BORDER_NONE;
}
} else if (!isBorderRound && (!transparentBackground || (armed && fillWhenPressedOnTransparentBackground)
|| drawBordersIfTransparentBackground)) {
paintBackground(g);
}

if (isBorderRound) {
g.backColor = backColor;
g.fillRoundRect(0, 0, width, height,
if (isAndroidStyle) {
if (translucentShape == TranslucentShape.NONE && !uiMaterial && !Settings.isOpenGL) {
g.getClip(clip);
g.backColor = Settings.isOpenGL ? parent.backColor : g.getPixel(clip.x, clip.y);
g.fillRect(0, 0, width, height);
}
} else if (!isBorderRound && (!transparentBackground || (armed && fillWhenPressedOnTransparentBackground)
|| drawBordersIfTransparentBackground)) {
paintBackground(g);
}

if (isBorderRound) {
g.backColor = backColor;
g.fillRoundRect(0, 0, width, height,
uiMaterial ? UnitsConverter.toPixels(DP + 4) : height / roundBorderFactor);
} else if (this.border == BORDER_OUTLINED) {
g.foreColor = transparentBackground ? this.borderColor : this.backColor;
g.drawRoundRect(0, 0, width, height,
uiMaterial ? UnitsConverter.toPixels(DP + 4) : height / roundBorderFactor);
} else if (this.border == BORDER_OUTLINED) {
g.foreColor = transparentBackground ? this.borderColor : this.backColor;
g.drawRoundRect(0, 0, width, height,
uiMaterial ? UnitsConverter.toPixels(DP + 4) : height / roundBorderFactor);

} else if (isAndroidStyle || (uiMaterial && border != BORDER_NONE)) {
paintImage(g, true, 0, 0);
}

} else if (isAndroidStyle || (uiMaterial && border != BORDER_NONE)) {
paintImage(g, true, 0, 0);
}

int border = txtPos == CENTER ? 0 : Math.min(2, this.border); // guich@tc112_31
g.setClip(border, border, width - (border << 1), height - (border << 1)); // guich@101: cut text if button is
// too small - guich@510_4

boolean isBorder3D = border == BORDER_3D_HORIZONTAL_GRADIENT || border == BORDER_3D_VERTICAL_GRADIENT;
if (armed && !isAndroidStyle && shiftOnPress && (isBorder3D || uiVista || (img != null && text == null))) { // guich@tc100: if this is an image-only button, let the button be pressed
int inc = isBorder3D ? borderWidth3DG : 1;
tx += inc;
ix += inc;
ty += inc;
iy += inc;
}
if(this.border != BORDER_OUTLINED)
{
g.foreColor = fColor;
}
}
int border = txtPos == CENTER ? 0 : Math.min(2, this.border); // guich@tc112_31
g.setClip(border, border, width - (border << 1), height - (border << 1)); // guich@101: cut text if button is
// too small - guich@510_4

if (getDoEffect() && effect != null) {
if(this.border == BORDER_OUTLINED) {
effect.color = Color.getBrightness(fColor) < 127 ? Color.brighter(fColor, 64) : Color.darker(fColor, 64);
int backup = this.backColor;
this.backColor = this.foreColor;
effect.paintEffect(g);
this.backColor = backup;
} else {
effect.paintEffect(g);
boolean isBorder3D = border == BORDER_3D_HORIZONTAL_GRADIENT || border == BORDER_3D_VERTICAL_GRADIENT;
if (armed && !isAndroidStyle && shiftOnPress && (isBorder3D || uiVista || (img != null && text == null))) { // guich@tc100: if this is an image-only button, let the button be pressed
int inc = isBorder3D ? borderWidth3DG : 1;
tx += inc;
ix += inc;
ty += inc;
iy += inc;
}
if(this.border != BORDER_OUTLINED)
{
g.foreColor = fColor;
}
}

if (getDoEffect() && effect != null) {
if(this.border == BORDER_OUTLINED) {
effect.color = Color.getBrightness(fColor) < 127 ? Color.brighter(fColor, 64) : Color.darker(fColor, 64);
int backup = this.backColor;
this.backColor = this.foreColor;
effect.paintEffect(g);
this.backColor = backup;
} else {
effect.paintEffect(g);
}
}
}

Expand Down
119 changes: 99 additions & 20 deletions TotalCrossSDK/src/main/java/totalcross/ui/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import totalcross.ui.event.PenEvent;
import totalcross.ui.event.PenListener;
import totalcross.ui.gfx.Graphics;
import totalcross.ui.gfx.RRect;
import totalcross.ui.gfx.Rect;
import totalcross.ui.image.Image;
import totalcross.ui.image.ImageException;
Expand Down Expand Up @@ -115,6 +116,8 @@ public class Container extends Control {
* @see #setInsets
*/
protected Insets insets = new Insets(); // guich@tc110_87
protected Insets userInsets = new Insets();
protected RRect childrenClip;

/** Set to true to always erase the background when repainting this container.
* @since TotalCross 1.0
Expand Down Expand Up @@ -196,11 +199,11 @@ public boolean isPressed() {
*/
public void setInsets(int left, int right, int top, int bottom) // guich@tc110_87
{
int gap = borderStyle == BORDER_NONE || borderStyle == BORDER_TOP ? 0 : borderStyle == BORDER_SIMPLE ? 1 : 2;
insets.left = left + gap;
insets.right = right + gap;
insets.top = top + gap;
insets.bottom = bottom + gap;
userInsets.left = left;
userInsets.right = right;
userInsets.top = top;
userInsets.bottom = bottom;
recomputeInsets();
}

/** Copy the current insets values into the given insets. If you call this method often,
Expand Down Expand Up @@ -504,22 +507,44 @@ public void broadcastEvent(Event e) {

/** Called by the system to draw the children of the container. */
public void paintChildren() {
for (Control child = children; child != null; child = child.next) {
if (child.visible) // guich@200: ignore hidden controls - note: a window added to a container may not be painted correctly
{
if (child.offscreen != null) {
Graphics g = getGraphics();
g.drawImage(child.offscreen, child.x, child.y);
if (child.offscreen0 != null) {
g.drawImage(child.offscreen0, child.x, child.y);
}
} else {
child.onPaint(child.getGraphics());
if (child.asContainer != null) {
child.asContainer.paintChildren();
paintChildren(getGraphics());
}

private void paintChildren(Graphics g) {
if (g == null) {
return;
}

RRect oldClip = null;
if (childrenClip != null) {
oldClip = g.getClip();
if (childrenClip.width <= 0 || childrenClip.height <= 0) {
return;
}
g.setClip(childrenClip);
}
try {
for (Control child = children; child != null; child = child.next) {
if (child.visible) // guich@200: ignore hidden controls - note: a window added to a container may not be painted correctly
{
if (child.offscreen != null) {
g.drawImage(child.offscreen, child.x, child.y);
if (child.offscreen0 != null) {
g.drawImage(child.offscreen0, child.x, child.y);
}
} else {
Graphics childGraphics = child.getGraphics(g);
child.onPaint(childGraphics);
if (child.asContainer != null) {
child.asContainer.paintChildren(childGraphics);
}
}
}
}
} finally {
if (oldClip != null) {
g.setClip(oldClip);
}
}
}

Expand All @@ -534,9 +559,8 @@ public void paintChildren() {
*/
public void setBorderStyle(byte border) // guich@200final_16
{
int gap = border == BORDER_NONE || borderStyle == BORDER_TOP ? 0 : borderStyle == BORDER_SIMPLE ? 1 : 2;
setInsets(gap, gap, gap, gap);
this.borderStyle = border;
recomputeInsets();
if (border == BORDER_ROUNDED) {
transparentBackground = true;
}
Expand Down Expand Up @@ -611,6 +635,12 @@ protected void fillBackground(Graphics g, int backColor, int foreColor, int x, i
@Override
public void onPaint(Graphics g) {
int b = pressColor != -1 && cpressed ? pressColor : backColor;

if (controlRenderer != null) {
controlRenderer.draw(g, 0, 0, width, height, cpressed);
return;
}

if (drawTranslucentBackground(g, alphaValue)) {
} else if (!transparentBackground
&& (parent != null && (b != parent.backColor || parent.asWindow != null || alwaysEraseBackground))) {
Expand Down Expand Up @@ -1108,4 +1138,53 @@ public void setBorderRadius(int borderRadius) {
this.borderRadius = borderRadius;
}

@Override
protected void onBoundsChanged(boolean screenChanged) {
super.onBoundsChanged(screenChanged);
updateChildrenClip();
}

@Override
protected void onStyleChanged() {
recomputeInsets();
updateChildrenClip();
}

private void recomputeInsets() {
int left = userInsets.left;
int right = userInsets.right;
int top = userInsets.top;
int bottom = userInsets.bottom;

if (controlRenderer != null) {
Insets rendererInsets = controlRenderer.getInsets();
left += rendererInsets.left;
right += rendererInsets.right;
top += rendererInsets.top;
bottom += rendererInsets.bottom;
} else {
int gap = borderStyle == BORDER_NONE || borderStyle == BORDER_TOP ? 0 : borderStyle == BORDER_SIMPLE ? 1 : 2;
left += gap;
right += gap;
top += gap;
bottom += gap;
}

insets.left = left;
insets.right = right;
insets.top = top;
insets.bottom = bottom;
}

private void updateChildrenClip() {
childrenClip = computeChildrenClip();
}

private RRect computeChildrenClip() {
if (controlRenderer != null) {
return controlRenderer.getChildrenClip(width, height);
}
return null;
}

}
Loading
Loading