Skip to content
Closed
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,10 @@ void drawBackground(GC gc, Rectangle bounds, int state) {
int[] percents = selected ? parent.selectionGradientPercents : parent.gradientPercents;
boolean vertical = selected ? parent.selectionGradientVertical : parent.gradientVertical;

drawBackground(gc, null, bounds.x, bounds.y, bounds.width, bounds.height, defaultBackground, image, colors, percents, vertical);
drawBackground(gc, bounds.x, bounds.y, bounds.width, bounds.height, defaultBackground, image, colors, percents, vertical);
}

void drawBackground(GC gc, int[] shape, boolean selected) {
void drawBackground(GC gc, boolean selected) {
Color defaultBackground = selected && parent.shouldHighlight() ? parent.selectionBackground : parent.getBackground();
Image image = selected ? parent.selectionBgImage : null;
Color[] colors = selected && parent.shouldHighlight() ? parent.selectionGradientColors : parent.gradientColors;
Expand All @@ -495,19 +495,10 @@ void drawBackground(GC gc, int[] shape, boolean selected) {
x += 1; width -= 2;
}
int y = parent.onBottom ? size.y - borderBottom - height : borderTop;
drawBackground(gc, shape, x, y, width, height, defaultBackground, image, colors, percents, vertical);
drawBackground(gc, x, y, width, height, defaultBackground, image, colors, percents, vertical);
}

void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Color defaultBackground, Image image, Color[] colors, int[] percents, boolean vertical) {
Region clipping = null, region = null;
if (shape != null) {
clipping = new Region();
gc.getClipping(clipping);
region = new Region();
region.add(shape);
region.intersect(clipping);
gc.setClipping(region);
}
void drawBackground(GC gc, int x, int y, int width, int height, Color defaultBackground, Image image, Color[] colors, int[] percents, boolean vertical) {
if (image != null) {
// draw the background image in shape
gc.setBackground(defaultBackground);
Expand Down Expand Up @@ -581,26 +572,12 @@ void drawBackground(GC gc, int[] shape, int x, int y, int width, int height, Col
}
}
} else {
// draw a solid background using default background in shape
// draw a solid background
if ((parent.getStyle() & SWT.NO_BACKGROUND) != 0 || !defaultBackground.equals(parent.getBackground())) {
gc.setBackground(defaultBackground);
gc.fillRectangle(x, y, width, height);
}
}
if (shape != null) {
gc.setClipping(clipping);
clipping.dispose();
region.dispose();
}
}

/*
* Draw the border of the tab
*/
void drawBorder(GC gc, int[] shape) {

gc.setForeground(parent.getDisplay().getSystemColor(BORDER1_COLOR));
gc.drawPolyline(shape);
}

void drawBody(GC gc, Rectangle bounds, int state) {
Expand Down Expand Up @@ -641,15 +618,8 @@ void drawBody(GC gc, Rectangle bounds, int state) {
x2-highlight_margin,y2-highlight_margin, x2-highlight_margin,y1,
x2,y1, x2,y2, x1,y2};
}
// If horizontal gradient, show gradient across the whole area
if (selectedIndex != -1 && parent.selectionGradientColors != null && parent.selectionGradientColors.length > 1 && !parent.selectionGradientVertical) {
drawBackground(gc, shape, true);
} else if (selectedIndex == -1 && parent.gradientColors != null && parent.gradientColors.length > 1 && !parent.gradientVertical) {
drawBackground(gc, shape, false);
} else {
gc.setBackground(selectedIndex != -1 && parent.shouldHighlight() ? parent.selectionBackground : parent.getBackground());
gc.fillPolygon(shape);
}
Comment on lines -644 to -652
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand how the different cases became obsolete and were thus removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three branches applied gradient fill to the highlight_margin L-shaped frame. That frame is 2 pixels wide (highlight_margin = 2 for non-FLAT; 0 for FLAT). Rendering a horizontal gradient across a 2-pixel strip is visually indistinguishable from a solid color — the gradient collapses to a single color sample at that scale. gc.fillPolygon(shape) with the solid background color produces an equivalent visual result.

gc.setBackground(selectedIndex != -1 && parent.shouldHighlight() ? parent.selectionBackground : parent.getBackground());
gc.fillPolygon(shape);
}
//Draw client area
if ((parent.getStyle() & SWT.NO_BACKGROUND) != 0) {
Expand Down Expand Up @@ -715,8 +685,7 @@ void drawClose(GC gc, Rectangle closeRect, int closeImageState) {
break;
}
case SWT.BACKGROUND: {
int[] shape = new int[] {x,y, x+10,y, x+10,y+10, x,y+10};
drawBackground(gc, shape, false);
drawBackground(gc, x, y, 10, 10, parent.getBackground(), null, null, null, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not easily understand why this is equivalent to the previous call either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SWT.BACKGROUND case repaints the close button area to erase a previously drawn hot/selected close icon and restore the background. The tab background (including any gradient) was already painted by drawTabArea/drawSelected before drawClose is called. The old drawBackground(gc, shape, false) applied parent.gradientColors over a 10×10 pixel area — a gradient fragment at that scale is visually indistinguishable from a solid color. Using parent.getBackground() correctly restores the area with no perceptible difference.

break;
}
}
Expand Down Expand Up @@ -793,11 +762,10 @@ private void drawChevronContent(GC gc, int x, int y, String chevronString) {
* Draw the unselected border for the receiver on the left.
*/
void drawLeftUnselectedBorder(GC gc, Rectangle bounds, int state) {
gc.setForeground(parent.getDisplay().getSystemColor(BORDER1_COLOR));
int x = bounds.x;
int y = bounds.y;
int height = bounds.height;

gc.setForeground(parent.getDisplay().getSystemColor(BORDER1_COLOR));
if (parent.onBottom) {
gc.drawLine(x, y - 1, x, y + height - 1);
} else {
Expand Down Expand Up @@ -908,11 +876,10 @@ void drawHighlight(GC gc, Rectangle bounds, int state, int rightEdge) {
* Draw the unselected border for the receiver on the right.
*/
void drawRightUnselectedBorder(GC gc, Rectangle bounds, int state) {
gc.setForeground(parent.getDisplay().getSystemColor(BORDER1_COLOR));
int x = bounds.x + bounds.width - 1;
int y = bounds.y;
int height = bounds.height;

gc.setForeground(parent.getDisplay().getSystemColor(BORDER1_COLOR));
if (parent.onBottom) {
gc.drawLine(x, y + height - 1, x, y - 1);
} else {
Expand Down Expand Up @@ -942,9 +909,8 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
int yy = parent.onBottom ? size.y - borderBottom - parent.tabHeight - highlight_header : borderTop + parent.tabHeight + 1;
int ww = size.x - borderLeft - borderRight;
int hh = highlight_header - 1;
int[] shape = new int[] {xx,yy, xx+ww,yy, xx+ww,yy+hh, xx,yy+hh};
if (parent.selectionGradientColors != null && !parent.selectionGradientVertical) {
drawBackground(gc, shape, parent.shouldHighlight());
drawBackground(gc, parent.shouldHighlight());
} else {
gc.setBackground(parent.shouldHighlight() ? parent.selectionBackground : parent.getBackground());
gc.fillRectangle(xx, yy, ww, hh);
Expand All @@ -965,43 +931,19 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
}

// draw selected tab background and outline
shape = new int[12];
int[] shape = null;
if (parent.onBottom) {
int index = 0;
shape[index++] = x; // first point repeated here because below we reuse shape to draw outline
shape[index++] = y - 1;
shape[index++] = x;
shape[index++] = y - 1;
shape[index++] = x;
shape[index++] = y + height;
if (borderLeft == 0 && itemIndex == parent.firstIndex) {
shape[index - 2] += x;
shape[index - 1] += y + height;
shape = new int[] {x, y-1, x, y+height, x, y+height, rightEdge-1, y+height-1, rightEdge-1, y-1, rightEdge-1, y-1};
} else {
shape = new int[] {x, y-1, x, y-1, x, y+height-1, rightEdge-1, y+height-1, rightEdge-1, y-1, rightEdge-1, y-1};
}
shape[index++] = rightEdge - 1;
shape[index++] = y + height - 1;
shape[index++] = rightEdge - 1;
shape[index++] = y - 1;
shape[index++] = rightEdge - 1;
shape[index++] = y - 1;
} else {
int index = 0;
shape[index++] = x; // first point repeated here because below we reuse shape to draw outline
shape[index++] = y + height + 1;
shape[index++] = x;
shape[index++] = y + height + 1;
shape[index++] = x;
shape[index++] = y;
if (borderLeft == 0 && itemIndex == parent.firstIndex) {
shape[index - 2] += x;
shape[index - 1] += y;
shape = new int[] {x, y+height+1, x, y, x, y, rightEdge-1, y, rightEdge-1, y+height+1, rightEdge-1, y+height+1};
} else {
shape = new int[] {x, y+height+1, x, y+height+1, x, y, rightEdge-1, y, rightEdge-1, y+height+1, rightEdge-1, y+height+1};
}
shape[index++] = rightEdge - 1;
shape[index++] = y;
shape[index++] = rightEdge - 1;
shape[index++] = y + height + 1;
shape[index++] = rightEdge - 1;
shape[index++] = y + height + 1;
}

Rectangle clipping = gc.getClipping();
Expand All @@ -1013,18 +955,18 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) {
if (tabInPaint) {
// fill in tab background
if (parent.selectionGradientColors != null && !parent.selectionGradientVertical) {
drawBackground(gc, shape, true);
drawBackground(gc, true);
} else {
Color defaultBackground = parent.shouldHighlight() ? parent.selectionBackground : parent.getBackground();
Image image = parent.selectionBgImage;
Color[] colors = parent.selectionGradientColors;
int[] percents = parent.selectionGradientPercents;
boolean vertical = parent.selectionGradientVertical;
xx = x;
yy = parent.onBottom ? y -1 : y + 1;
yy = parent.onBottom ? y - 1 : y + 1;
ww = width;
hh = height;
drawBackground(gc, shape, xx, yy, ww, hh, defaultBackground, image, colors, percents, vertical);
drawBackground(gc, xx, yy, ww, hh, defaultBackground, image, colors, percents, vertical);
}
}

Expand Down Expand Up @@ -1158,9 +1100,9 @@ void drawTabArea(GC gc, Rectangle bounds, int state) {

// If horizontal gradient, show gradient across the whole area
if (selectedIndex != -1 && parent.selectionGradientColors != null && parent.selectionGradientColors.length > 1 && !parent.selectionGradientVertical) {
drawBackground(gc, shape, true);
drawBackground(gc, true);
} else if (selectedIndex == -1 && parent.gradientColors != null && parent.gradientColors.length > 1 && !parent.gradientVertical) {
drawBackground(gc, shape, false);
drawBackground(gc, false);
} else {
gc.setBackground(selectedIndex != -1 && parent.shouldHighlight() ? parent.selectionBackground : parent.getBackground());
gc.fillPolygon(shape);
Expand All @@ -1178,44 +1120,18 @@ void drawTabArea(GC gc, Rectangle bounds, int state) {
int y = parent.onBottom ? size.y - borderBottom - tabHeight : borderTop;
int width = size.x - borderLeft - borderRight + 1;
int height = tabHeight - 1;
int[] shape = new int[8];
int[] shape;
// Draw Tab Header
if (parent.onBottom) {
int index = 0;
shape[index++] = x;
shape[index++] = y - highlight_header;
shape[index++] = x;
shape[index++] = y + height;
if (borderLeft == 0)
shape[index - 1] += 1;
shape[index++] = x + width;
shape[index++] = y + height;
if (borderLeft == 0)
shape[index - 1] += 1;
shape[index++] = x + width;
shape[index++] = y - highlight_header;
int bottomY = y + height + (borderLeft == 0 ? 1 : 0);
shape = new int[] {x, y-highlight_header, x, bottomY, x+width, bottomY, x+width, y-highlight_header};
} else {
int index = 0;
shape[index++] = x;
shape[index++] = y + height + highlight_header + 1;
shape[index++] = x;
shape[index++] = y;
shape[index++] = x + width;
shape[index++] = y;
shape[index++] = x + width;
shape[index++] = y + height + highlight_header + 1;
shape = new int[] {x, y+height+highlight_header+1, x, y, x+width, y, x+width, y+height+highlight_header+1};
}
// Fill in background
boolean single = parent.single;
boolean bkSelected = single && selectedIndex != -1;
drawBackground(gc, shape, bkSelected);
// Fill in parent background for non-rectangular shape
Region r = new Region();
r.add(new Rectangle(x, y, width + 1, height + 1));
r.subtract(shape);
gc.setBackground(parent.getParent().getBackground());
fillRegion(gc, r);
r.dispose();
drawBackground(gc, bkSelected);

// Draw selected tab
if (selectedIndex == -1) {
Expand Down Expand Up @@ -1302,16 +1218,6 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) {
}
}

void fillRegion(GC gc, Region region) {
// NOTE: region passed in to this function will be modified
Region clipping = new Region();
gc.getClipping(clipping);
region.intersect(clipping);
gc.setClipping(region);
gc.fillRectangle(region.getBounds());
gc.setClipping(clipping);
clipping.dispose();
}

Color getFillColor() {
if (fillColor == null) {
Expand Down
Loading