RENDERER: remove unnecessary lines
authorGiWoong Kim <giwoong.kim@samsung.com>
Mon, 27 Jun 2016 09:12:07 +0000 (18:12 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Mon, 27 Jun 2016 09:15:52 +0000 (18:15 +0900)
- gradient color, shadow image, etc

Change-Id: Idfa16091a2902a3e158256da3d574f55ff6df90b
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/TizenTabRendering.java

index 086f649..a5824fc 100644 (file)
@@ -13,6 +13,7 @@
  * 2016-05-04 GiWoong Kim giwoong.kim@samsung.com
  * Modifications by S-Core Co., Ltd.
  * 1. Give a Tizen identity (based on CTabRendering.java)
+ * 2. Remove unnecessary lines
  */
 package org.eclipse.e4.ui.workbench.renderers.swt;
 
@@ -32,14 +33,12 @@ import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.Pattern;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.graphics.Rectangle;
 import org.eclipse.swt.graphics.Region;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.ToolBar;
 
 /**
@@ -65,8 +64,6 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
 
        // keylines
        final static int OUTER_KEYLINE = 1;
-       final static int INNER_KEYLINE = 0;
-       final static int TOP_KEYLINE = 0;
 
        // Item Constants
        static final int ITEM_TOP_MARGIN = 2;
@@ -77,11 +74,8 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
 
        int[] shape;
 
-       Image shadowImage;
-
        int cornerSize = 14;
 
-       Color shadowColor;
        Color outerKeyline, innerKeyline;
        Color[] activeToolbar;
        int[] activePercents;
@@ -132,8 +126,8 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
        @Override
        protected Rectangle computeTrim(int part, int state, int x, int y,
                        int width, int height) {
-               int borderTop = TOP_KEYLINE + OUTER_KEYLINE;
-               int borderBottom = INNER_KEYLINE + OUTER_KEYLINE;
+               int borderTop = OUTER_KEYLINE;
+               int borderBottom = OUTER_KEYLINE;
                int marginWidth = parent.marginWidth;
                int marginHeight = parent.marginHeight;
                switch (part) {
@@ -148,8 +142,8 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                                                height += tabHeight + (cornerSize / 4) + borderBottom
                                                                + borderTop;
                        } else {
-                               x = x - marginWidth - OUTER_KEYLINE - INNER_KEYLINE - (cornerSize / 2);
-                               width = width + 2 * OUTER_KEYLINE + 2 * INNER_KEYLINE + 2
+                               x = x - marginWidth - OUTER_KEYLINE - (cornerSize / 2);
+                               width = width + 2 * OUTER_KEYLINE + 2
                                                * marginWidth + cornerSize;
                                int tabHeight = parent.getTabHeight() + 1; // TODO: Figure out
                                // what
@@ -168,13 +162,12 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                        }
                        break;
                case PART_HEADER:
-                       x = x - (INNER_KEYLINE + OUTER_KEYLINE);
-                       width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE);
+                       x = x - OUTER_KEYLINE;
+                       width = width + 2 * OUTER_KEYLINE;
                        break;
                case PART_BORDER:
-                       x = x - INNER_KEYLINE - OUTER_KEYLINE - (cornerSize / 4);
-                       width = width + 2 * (INNER_KEYLINE + OUTER_KEYLINE)
-                                       + cornerSize / 2;
+                       x = x - OUTER_KEYLINE - (cornerSize / 4);
+                       width = width + 2 * OUTER_KEYLINE + cornerSize / 2;
                        height = height + borderTop + borderBottom;
                        y = y - borderTop;
 
@@ -205,10 +198,6 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
 
        @Override
        protected void dispose() {
-               if (shadowImage != null && !shadowImage.isDisposed()) {
-                       shadowImage.dispose();
-                       shadowImage = null;
-               }
                super.dispose();
        }
 
@@ -253,17 +242,14 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
        }
 
        void drawTabHeader(GC gc, Rectangle bounds, int state) {
-               // gc.setClipping(bounds.x, bounds.y, bounds.width,
-               // parent.getTabHeight() + 1);
-
                int[] points = new int[1024];
                int index = 0;
                int radius = cornerSize / 2;
                int marginWidth = parent.marginWidth;
                int marginHeight = parent.marginHeight;
-               int delta = INNER_KEYLINE + OUTER_KEYLINE + 2 * marginWidth;
+               int delta = OUTER_KEYLINE + 2 * marginWidth;
                int width = bounds.width - delta;
-               int height = bounds.height - INNER_KEYLINE - OUTER_KEYLINE - 2 * marginHeight;
+               int height = bounds.height - OUTER_KEYLINE - 2 * marginHeight;
                int circX = bounds.x + delta / 2 + radius;
                int circY = bounds.y + radius;
 
@@ -313,12 +299,12 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                int[] tempPoints = new int[index];
                System.arraycopy(points, 0, tempPoints, 0, index);
 
-               if (outerKeyline == null)
+               /* draw outerlines */
+               if (outerKeyline == null) {
                        outerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
+               }
                gc.setForeground(outerKeyline);
                /* Tizen */
-               // gc.drawPolyline(shape);
-
                /*
                 * FIXME: This polyline is related to 'swt-outer-keyline-color' CSS
                 * property. Condition should be set based on pseudo-state. But,
@@ -342,10 +328,9 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                int radius = cornerSize / 2;
                int marginWidth = parent.marginWidth;
                int marginHeight = parent.marginHeight;
-               int delta = INNER_KEYLINE + OUTER_KEYLINE + 2 * marginWidth;
+               int delta = OUTER_KEYLINE + 2 * marginWidth;
                int width = bounds.width - delta;
-               int height = Math.max(parent.getTabHeight() + INNER_KEYLINE + OUTER_KEYLINE,
-                               bounds.height - INNER_KEYLINE - OUTER_KEYLINE - 2 * marginHeight);
+               int height = Math.max(parent.getTabHeight() + OUTER_KEYLINE, bounds.height - OUTER_KEYLINE - 2 * marginHeight);
 
                int circX = bounds.x + delta / 2 + radius;
                int circY = bounds.y + radius;
@@ -356,8 +341,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                System.arraycopy(ltt, 0, points, index, ltt.length);
                index += ltt.length;
 
-               int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius,
-                               LEFT_BOTTOM);
+               int[] lbb = drawCircle(circX, circY + height - (radius * 2), radius, LEFT_BOTTOM);
                System.arraycopy(lbb, 0, points, index, lbb.length);
                index += lbb.length;
 
@@ -366,8 +350,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                System.arraycopy(rb, 0, points, index, rb.length);
                index += rb.length;
 
-               int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
-                               RIGHT_TOP);
+               int[] rt = drawCircle(circX + width - (radius * 2), circY, radius, RIGHT_TOP);
                System.arraycopy(rt, 0, points, index, rt.length);
                index += rt.length;
                points[index++] = circX;
@@ -381,8 +364,9 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
        }
 
        void drawSelectedTab(int itemIndex, GC gc, Rectangle bounds, int state) {
-               if (parent.getSingle() && parent.getItem(itemIndex).isShowing())
+               if (parent.getSingle() && parent.getItem(itemIndex).isShowing()) {
                        return;
+               }
 
                int width = bounds.width;
                int[] points = new int[1024];
@@ -392,9 +376,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                int circY = bounds.y - 1 + radius;
                int selectionX1, selectionY1, selectionX2, selectionY2;
                int bottomY = bounds.y + bounds.height;
-               if (itemIndex == 0
-                               && bounds.x == -computeTrim(CTabFolderRenderer.PART_HEADER,
-                                               SWT.NONE, 0, 0, 0, 0).x) {
+               if (itemIndex == 0 && bounds.x == -computeTrim(CTabFolderRenderer.PART_HEADER, SWT.NONE, 0, 0, 0, 0).x) {
                        circX -= 1;
                        points[index++] = circX - radius;
                        points[index++] = bottomY;
@@ -403,7 +385,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                        points[index++] = selectionY1 = bottomY;
                } else {
                        if (active) {
-                               points[index++] = INNER_KEYLINE + OUTER_KEYLINE;
+                               points[index++] = OUTER_KEYLINE;
                                points[index++] = bottomY;
                        }
                        points[index++] = selectionX1 = bounds.x;
@@ -445,58 +427,33 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                        points[index++] = selectionY2 = bounds.y + bounds.height;
 
                if (active) {
-                       points[index++] = parent.getSize().x - (INNER_KEYLINE + OUTER_KEYLINE);
+                       points[index++] = parent.getSize().x - OUTER_KEYLINE;
                        points[index++] = bottomY;
                }
-               gc.setClipping(0, bounds.y,
-                               parent.getSize().x - (INNER_KEYLINE + OUTER_KEYLINE),
-                               bounds.y + bounds.height);// bounds.height
+               gc.setClipping(0, bounds.y, parent.getSize().x - OUTER_KEYLINE, bounds.y + bounds.height);
 
-               Pattern backgroundPattern = null;
                if (selectedTabFillColors == null) {
                        setSelectedTabFill(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
                }
-               if (selectedTabFillColors.length == 1) {
-                       gc.setBackground(selectedTabFillColors[0]);
-                       gc.setForeground(selectedTabFillColors[0]);
-               } else if (selectedTabFillColors.length == 2) {
-                       // for now we support the 2-colors gradient for selected tab
-                       backgroundPattern = new Pattern(gc.getDevice(), 0, 0, 0,
-                                       bounds.height + 1, selectedTabFillColors[0],
-                                       selectedTabFillColors[1]);
-                       gc.setBackgroundPattern(backgroundPattern);
-                       gc.setForeground(selectedTabFillColors[1]);
-               }
+               gc.setBackground(selectedTabFillColors[0]);
+               gc.setForeground(selectedTabFillColors[0]);
 
                int[] tmpPoints = new int[index];
                System.arraycopy(points, 0, tmpPoints, 0, index);
                gc.fillPolygon(tmpPoints);
 
                /* Tizen */
-               Color prevColor = gc.getForeground();
-
                gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
                gc.fillRectangle(selectionX1, 0, selectionX2 - selectionX1, selectionY1);
 
-               gc.setForeground(prevColor);
+               gc.setForeground(selectedTabFillColors[0]);
                /* ===== */
 
                gc.drawLine(selectionX1, selectionY1, selectionX2, selectionY2);
                if (tabOutlineColor == null)
                        tabOutlineColor = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
                gc.setForeground(tabOutlineColor);
-               Color gradientLineTop = null;
-               Pattern foregroundPattern = null;
-               if (!active) {
-                       RGB blendColor = gc.getDevice()
-                                       .getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW).getRGB();
-                       RGB topGradient = blend(blendColor, tabOutlineColor.getRGB(), 40);
-                       gradientLineTop = new Color(gc.getDevice(), topGradient);
-                       foregroundPattern = new Pattern(gc.getDevice(), 0, 0, 0,
-                                       bounds.height + 1, gradientLineTop, gc.getDevice()
-                                       .getSystemColor(SWT.COLOR_WHITE));
-                       gc.setForegroundPattern(foregroundPattern);
-               }
+
                /* Tizen */
                // gc.drawPolyline(tmpPoints);
                if (unselectedTabSeparator) {
@@ -510,12 +467,11 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                gc.setClipping(rect);
 
                if (active) {
-                       if (outerKeyline == null)
+                       if (outerKeyline == null) {
                                outerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_RED);
+                       }
                        gc.setForeground(outerKeyline);
                        /* Tizen */
-                       // gc.drawPolyline(shape);
-
                        /*
                         * FIXME: This polyline is related to 'swt-outer-keyline-color' CSS
                         * property. Condition should be set based on pseudo-state. But,
@@ -539,7 +495,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                /* Tizen */
                if (selectedTabUnderline) {
                        // draw a underline
-                       prevColor = gc.getForeground();
+                       Color prevColor = gc.getForeground();
                        int prevLineWidth = gc.getLineWidth();
 
                        gc.setForeground(JFaceResources.getColorRegistry().get(TIZEN_POINT_COLOR_1_KEY));
@@ -552,16 +508,6 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                        gc.setForeground(prevColor);
                }
                /* ===== */
-
-               if (backgroundPattern != null) {
-                       backgroundPattern.dispose();
-               }
-               if (gradientLineTop != null) {
-                       gradientLineTop.dispose();
-               }
-               if (foregroundPattern != null) {
-                       foregroundPattern.dispose();
-               }
        }
 
        void drawUnselectedTab(int itemIndex, GC gc, Rectangle bounds, int state) {
@@ -637,7 +583,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                                inactive_index += 2;
                        }
                        gc.setClipping(points[0], bounds.y,
-                                       parent.getSize().x - (INNER_KEYLINE + OUTER_KEYLINE), bounds.y + bounds.height);
+                                       parent.getSize().x - OUTER_KEYLINE, bounds.y + bounds.height);
 
                        Color color = hotUnselectedTabsColorBackground;
                        if (color == null) {
@@ -665,8 +611,9 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                        Rectangle rect = null;
                        gc.setClipping(rect);
 
-                       if (outerKeyline == null)
+                       if (outerKeyline == null) {
                                outerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
+                       }
                        // gc.setForeground(outerKeyline);
                        // gc.drawPolyline(shape);
                }
@@ -810,24 +757,6 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
                return Math.min(255, b);
        }
 
-       void createShadow(final Display display) {
-               if (shadowImage != null) {
-                       shadowImage.dispose();
-                       shadowImage = null;
-               }
-               ImageData data = new ImageData(60, 60, 32, new PaletteData(0xFF0000,
-                               0xFF00, 0xFF));
-               Image tmpImage = shadowImage = new Image(display, data);
-               GC gc = new GC(tmpImage);
-               if (shadowColor == null)
-                       shadowColor = gc.getDevice().getSystemColor(SWT.COLOR_GRAY);
-               gc.setBackground(shadowColor);
-               drawTabBody(gc, new Rectangle(0, 0, 60, 60), SWT.None);
-               ImageData blured = blur(tmpImage, 5, 25);
-               shadowImage = new Image(display, blured);
-               tmpImage.dispose();
-       }
-
        public ImageData blur(Image src, int radius, int sigma) {
                float[] kernel = create1DKernel(radius, sigma);
 
@@ -974,8 +903,7 @@ public class TizenTabRendering extends CTabFolderRenderer implements ICTabRender
 
        @Override
        public void setShadowColor(Color color) {
-               this.shadowColor = color;
-               createShadow(parent.getDisplay());
+               /* do nothing */
                parent.redraw();
        }