Search in sources :

Example 21 with GCStringPrinter

use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.

the class NameItem method cellPaintName.

private void cellPaintName(TableCell cell, GC gc, Rectangle cellBounds, int textX, int originalBoundxsX) {
    final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
    String name = (fileInfo == null) ? "" : fileInfo.getFile(true).getName();
    if (name == null) {
        name = "";
    }
    GCStringPrinter sp = new GCStringPrinter(gc, name, new Rectangle(textX, cellBounds.y, cellBounds.x + cellBounds.width - textX, cellBounds.height), true, true, getTableID().endsWith(".big") ? SWT.WRAP : SWT.NULL);
    boolean fit = sp.printString();
    Point p = sp.getCalculatedPreferredSize();
    int pref = (textX - originalBoundxsX) + p.x + 10;
    TableColumn tableColumn = cell.getTableColumn();
    if (tableColumn != null && tableColumn.getPreferredWidth() < pref) {
        tableColumn.setPreferredWidth(pref);
    }
    String tooltip = fit ? "" : name;
    cell.setToolTip(tooltip.length() == 0 ? null : tooltip);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 22 with GCStringPrinter

use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.

the class SWTSkinObjectText2 method paintControl.

// @see SWTSkinObjectBasic#paintControl(org.eclipse.swt.graphics.GC)
@Override
public void paintControl(GC gc) {
    if (sText == null || sText.length() == 0) {
        return;
    }
    super.paintControl(gc);
    Composite composite = (Composite) control;
    Rectangle clientArea = composite.getClientArea();
    clientArea.x += hpadding;
    clientArea.width -= hpadding * 2;
    clientArea.y += vpadding;
    clientArea.height -= vpadding * 2;
    Font existingFont = (Font) canvas.getData("font");
    Color existingColor = (Color) canvas.getData("color");
    if (existingFont != null) {
        gc.setFont(existingFont);
    }
    if (debug) {
        System.out.println("paint " + existingColor + ";" + gc.getForeground());
    }
    if (existingColor != null) {
        gc.setForeground(existingColor);
    }
    if (antialiasMode != SWT.DEFAULT) {
        try {
            gc.setTextAntialias(antialiasMode);
        } catch (Exception ex) {
        // Ignore ERROR_NO_GRAPHICS_LIBRARY error or any others
        }
    }
    if (hasShadow) {
        Rectangle r = new Rectangle(clientArea.x + 1, clientArea.y + 1, clientArea.width, clientArea.height);
        Color foreground = gc.getForeground();
        if (colorShadow.color == null) {
            Color color = ColorCache.getColor(gc.getDevice(), 0, 0, 0);
            gc.setForeground(color);
            gc.setAlpha(64);
        } else {
            gc.setForeground(colorShadow.color);
            gc.setAlpha(colorShadow.alpha);
        }
        GCStringPrinter.printString(gc, sDisplayText, r, true, false, style);
        gc.setForeground(foreground);
    }
    gc.setAlpha(alpha);
    // hack to fix shadow wrapping (different widths for text drawn with alpha and text drawn without)
    if (alpha == 255 && hasShadow && (colorShadow.color == null || colorShadow.alpha < 255)) {
        gc.setAlpha(254);
    }
    lastStringPrinter = new GCStringPrinter(gc, sDisplayText, clientArea, true, false, style);
    if (colorUrl != null) {
        lastStringPrinter.setUrlColor(colorUrl);
    }
    if (colorUrl2 != null && mouseDown) {
        lastStringPrinter.calculateMetrics();
        Display display = Display.getCurrent();
        Point cursorLocation = canvas.toControl(display.getCursorLocation());
        URLInfo hitUrl = lastStringPrinter.getHitUrl(cursorLocation.x, cursorLocation.y);
        if (hitUrl != null) {
            hitUrl.urlColor = colorUrl2;
        }
    }
    lastStringPrinter.printString();
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) ParseException(java.text.ParseException)

Example 23 with GCStringPrinter

use of com.biglybt.ui.swt.shells.GCStringPrinter in project BiglyBT by BiglySoftware.

the class SideBarEntrySWT method swt_paintSideBar.

protected void swt_paintSideBar(Event event) {
    neverPainted = false;
    // System.out.println(System.currentTimeMillis() + "] paint " + getId() + ";sel? " + ((event.detail & SWT.SELECTED) > 0));
    TreeItem treeItem = (TreeItem) event.item;
    if (treeItem.isDisposed() || isDisposed()) {
        return;
    }
    Rectangle itemBounds = treeItem.getBounds();
    Rectangle drawBounds = event.gc.getClipping();
    if (drawBounds.isEmpty()) {
        drawBounds = event.getBounds();
    }
    Rectangle treeArea = treeItem.getParent().getClientArea();
    if (Utils.isGTK3) {
        // workaround bug
        if (treeArea.width > itemBounds.width) {
            itemBounds.width = treeArea.width;
        }
        if (treeArea.x < itemBounds.x) {
            itemBounds.x = treeArea.x;
        }
        drawBounds = itemBounds;
    }
    String text = getTitle();
    if (text == null)
        text = "";
    // Point size = event.gc.textExtent(text);
    // Rectangle treeBounds = tree.getBounds();
    GC gc = event.gc;
    gc.setAntialias(SWT.ON);
    gc.setAdvanced(true);
    Utils.setClipping(gc, null);
    boolean selected = (event.detail & SWT.SELECTED) > 0;
    Color fgText = swt_paintEntryBG(event.detail, gc, drawBounds);
    Tree tree = (Tree) event.widget;
    Font font = tree.getFont();
    if (font != null && !font.isDisposed()) {
        gc.setFont(font);
    }
    if (SideBar.USE_NATIVE_EXPANDER && Utils.isGTK3) {
        itemBounds.x = treeItem.getBounds().x;
    } else if (DO_OUR_OWN_TREE_INDENT) {
        TreeItem tempItem = treeItem.getParentItem();
        int indent;
        if (!isCollapseDisabled() && tempItem == null && !Utils.isGTK) {
            indent = 22;
        } else {
            indent = 10;
        }
        while (tempItem != null) {
            indent += 10;
            tempItem = tempItem.getParentItem();
        }
        if (SideBar.USE_NATIVE_EXPANDER && Utils.isGTK) {
            indent += 5;
        }
        itemBounds.x = indent;
    }
    int x1IndicatorOfs = SIDEBAR_SPACING;
    int x0IndicatorOfs = itemBounds.x;
    // System.out.println(System.currentTimeMillis() + "] refresh " + getId() + "; " + itemBounds + ";clip=" + event.gc.getClipping() + ";eb=" + event.getBounds());
    if (viewTitleInfo != null) {
        String textIndicator = null;
        try {
            textIndicator = (String) viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
        } catch (Exception e) {
            Debug.out(e);
        }
        if (textIndicator != null) {
            Point textSize = gc.textExtent(textIndicator);
            // Point minTextSize = gc.textExtent("99");
            // if (textSize.x < minTextSize.x + 2) {
            // textSize.x = minTextSize.x + 2;
            // }
            int width = textSize.x + Utils.adjustPXForDPI(10);
            x1IndicatorOfs += width + SIDEBAR_SPACING;
            int startX = treeArea.width - x1IndicatorOfs;
            int textOffsetY = 0;
            int height = textSize.y + 1;
            int startY = itemBounds.y + (itemBounds.height - height) / 2;
            // gc.fillRectangle(startX, startY, width, height);
            // Pattern pattern;
            // Color color1;
            // Color color2;
            Color default_color = ColorCache.getSchemedColor(gc.getDevice(), "#5b6e87");
            Object color = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
            if (color instanceof int[]) {
                gc.setBackground(ColorCache.getColor(gc.getDevice(), (int[]) color));
            } else {
                gc.setBackground(default_color);
            }
            /*
				if (selected) {
					color1 = ColorCache.getColor(gc.getDevice(), colors[0]);
					color2 = ColorCache.getColor(gc.getDevice(), colors[1]);
					pattern = new Pattern(gc.getDevice(), 0, startY, 0, startY + height,
							color1, 127, color2, 4);
				} else {
					color1 = ColorCache.getColor(gc.getDevice(), colors[2]);
					color2 = ColorCache.getColor(gc.getDevice(), colors[3]);
					pattern = new Pattern(gc.getDevice(), 0, startY, 0, startY + height,
							color1, color2);
				}
				gc.setBackgroundPattern(pattern);
				*/
            Color text_color = Colors.white;
            gc.fillRoundRectangle(startX, startY, width, height, textSize.y * 2 / 3, height * 2 / 3);
            if (color != null) {
                Color bg = gc.getBackground();
                int red = bg.getRed();
                int green = bg.getGreen();
                int blue = bg.getBlue();
                double brightness = Math.sqrt(red * red * 0.299 + green * green * 0.587 + blue * blue * 0.114);
                if (brightness >= 130) {
                    text_color = Colors.black;
                }
                gc.setBackground(default_color);
                gc.drawRoundRectangle(startX, startY, width, height, textSize.y * 2 / 3, height * 2 / 3);
            }
            // pattern.dispose();
            if (maxIndicatorWidth > width) {
                maxIndicatorWidth = width;
            }
            gc.setForeground(text_color);
            GCStringPrinter.printString(gc, textIndicator, new Rectangle(startX, startY + textOffsetY, width, height), true, false, SWT.CENTER);
        }
    }
    if (isCloseable()) {
        Image img = selected ? imgCloseSelected : imgClose;
        Rectangle closeArea = img.getBounds();
        closeArea.x = treeArea.width - closeArea.width - SIDEBAR_SPACING - x1IndicatorOfs;
        closeArea.y = itemBounds.y + (itemBounds.height - closeArea.height) / 2;
        x1IndicatorOfs += closeArea.width + SIDEBAR_SPACING;
        // gc.setBackground(treeItem.getBackground());
        // gc.fillRectangle(closeArea);
        gc.drawImage(img, closeArea.x, closeArea.y);
        treeItem.setData("closeArea", closeArea);
    }
    MdiEntryVitalityImage[] vitalityImages = getVitalityImages();
    for (int i = 0; i < vitalityImages.length; i++) {
        SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
        if (vitalityImage == null || !vitalityImage.isVisible() || vitalityImage.getAlignment() != SWT.RIGHT) {
            continue;
        }
        vitalityImage.switchSuffix(selected ? "-selected" : "");
        Image image = vitalityImage.getImage();
        if (image != null && !image.isDisposed()) {
            Rectangle bounds = image.getBounds();
            bounds.x = treeArea.width - bounds.width - SIDEBAR_SPACING - x1IndicatorOfs;
            bounds.y = itemBounds.y + (itemBounds.height - bounds.height) / 2;
            x1IndicatorOfs += bounds.width + SIDEBAR_SPACING;
            gc.drawImage(image, bounds.x, bounds.y);
            // setHitArea needs it relative to entry
            bounds.y -= itemBounds.y;
            vitalityImage.setHitArea(bounds);
        }
    }
    boolean greyScale = false;
    if (viewTitleInfo != null) {
        Object active_state = viewTitleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_ACTIVE_STATE);
        if (active_state instanceof Long) {
            greyScale = (Long) active_state == 2;
        }
    }
    String suffix = selected ? "-selected" : null;
    Image imageLeft = getImageLeft(suffix);
    if (imageLeft == null && selected) {
        releaseImageLeft(suffix);
        suffix = null;
        imageLeft = getImageLeft(null);
    }
    if (imageLeft != null) {
        Rectangle clipping = gc.getClipping();
        Utils.setClipping(gc, new Rectangle(x0IndicatorOfs, itemBounds.y, IMAGELEFT_SIZE, itemBounds.height));
        if (greyScale) {
            greyScale = false;
            String imageLeftID = getImageLeftID();
            if (imageLeftID != null) {
                Image grey = ImageLoader.getInstance().getImage(imageLeftID + "-gray");
                if (grey != null) {
                    imageLeft = grey;
                    gc.setAlpha(160);
                    greyScale = true;
                }
            }
        }
        Rectangle bounds = imageLeft.getBounds();
        int w = bounds.width;
        int h = bounds.height;
        if (w > IMAGELEFT_SIZE) {
            float pct = IMAGELEFT_SIZE / (float) w;
            w = IMAGELEFT_SIZE;
            h *= pct;
        }
        int x = x0IndicatorOfs + ((IMAGELEFT_SIZE - w) / 2);
        int y = itemBounds.y + ((itemBounds.height - h) / 2);
        gc.setAdvanced(true);
        gc.setInterpolation(SWT.HIGH);
        gc.drawImage(imageLeft, 0, 0, bounds.width, bounds.height, x, y, w, h);
        if (greyScale) {
            String imageLeftID = getImageLeftID();
            gc.setAlpha(255);
            ImageLoader.getInstance().releaseImage(imageLeftID + "-gray");
        }
        releaseImageLeft(suffix);
        Utils.setClipping(gc, clipping);
        // 0, 0, bounds.width, bounds.height,
        // x0IndicatorOfs, itemBounds.y
        // + ((itemBounds.height - IMAGELEFT_SIZE) / 2), IMAGELEFT_SIZE,
        // IMAGELEFT_SIZE);
        x0IndicatorOfs += IMAGELEFT_SIZE + IMAGELEFT_GAP;
        releaseImageLeft(suffix);
    } else if (ALWAYS_IMAGE_GAP) {
        if (isSelectable()) {
            x0IndicatorOfs += IMAGELEFT_SIZE + IMAGELEFT_GAP;
        }
    } else {
        if (treeItem.getParentItem() != null) {
            x0IndicatorOfs += 30 - 18;
        }
    }
    // Main Text
    // //////////
    Rectangle clipping = new Rectangle(x0IndicatorOfs, itemBounds.y, treeArea.width - x1IndicatorOfs - SIDEBAR_SPACING - x0IndicatorOfs, itemBounds.height);
    if (drawBounds.intersects(clipping)) {
        int style = SWT.NONE;
        if (!isSelectable()) {
            Font headerFont = sidebar.getHeaderFont();
            if (headerFont != null && !headerFont.isDisposed()) {
                gc.setFont(headerFont);
            }
            // text = text.toUpperCase();
            gc.setForeground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
            gc.setAlpha(100);
            clipping.x++;
            clipping.y++;
            // style = SWT.TOP;
            GCStringPrinter sp = new GCStringPrinter(gc, text, clipping, true, false, style);
            sp.printString();
            gc.setAlpha(255);
            clipping.x--;
            clipping.y--;
            gc.setForeground(fgText);
        } else {
            if (treeItem.getItemCount() > 0 || id.equals(MultipleDocumentInterface.SIDEBAR_HEADER_DASHBOARD)) {
                Font headerFont = sidebar.getHeaderFont();
                if (headerFont != null && !headerFont.isDisposed()) {
                    gc.setFont(headerFont);
                }
            }
            gc.setForeground(fgText);
        }
        // Utils.setClipping(gc, clipping);
        GCStringPrinter sp = new GCStringPrinter(gc, text, clipping, true, false, style);
        sp.printString();
        clipping.x += sp.getCalculatedSize().x + 5;
    // Utils.setClipping(gc, (Rectangle) null);
    }
    for (int i = 0; i < vitalityImages.length; i++) {
        SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
        if (!vitalityImage.isVisible() || vitalityImage.getAlignment() != SWT.LEFT) {
            continue;
        }
        vitalityImage.switchSuffix(selected ? "-selected" : "");
        Image image = vitalityImage.getImage();
        if (image != null && !image.isDisposed()) {
            Rectangle bounds = image.getBounds();
            bounds.x = clipping.x;
            bounds.y = itemBounds.y + (itemBounds.height - bounds.height) / 2;
            clipping.x += bounds.width + SIDEBAR_SPACING;
            if (clipping.x > (treeArea.width - x1IndicatorOfs)) {
                vitalityImage.setHitArea(null);
                continue;
            }
            gc.drawImage(image, bounds.x, bounds.y);
            vitalityImage.setHitArea(bounds);
        }
    }
    // on Windows because it doesn't have transparency and looks ugly
    if (treeItem.getItemCount() > 0 && !isCollapseDisabled() && !SideBar.USE_NATIVE_EXPANDER) {
        gc.setAntialias(SWT.ON);
        Color oldBG = gc.getBackground();
        gc.setBackground(Colors.getSystemColor(event.display, SWT.COLOR_LIST_FOREGROUND));
        // itemBounds.x;
        int baseX = 22;
        if (treeItem.getExpanded()) {
            int xStart = 12;
            int arrowSize = 8;
            int yStart = itemBounds.height - (itemBounds.height + arrowSize) / 2;
            gc.fillPolygon(new int[] { baseX - xStart, itemBounds.y + yStart, baseX - xStart + arrowSize, itemBounds.y + yStart, baseX - xStart + (arrowSize / 2), itemBounds.y + yStart + arrowSize });
        } else {
            int xStart = 12;
            int arrowSize = 8;
            int yStart = itemBounds.height - (itemBounds.height + arrowSize) / 2;
            gc.fillPolygon(new int[] { baseX - xStart, itemBounds.y + yStart, baseX - xStart + arrowSize, itemBounds.y + yStart + 4, baseX - xStart, itemBounds.y + yStart + 8 });
        }
        gc.setBackground(oldBG);
        Font headerFont = sidebar.getHeaderFont();
        if (headerFont != null && !headerFont.isDisposed()) {
            gc.setFont(headerFont);
        }
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MdiEntryVitalityImage(com.biglybt.ui.mdi.MdiEntryVitalityImage)

Aggregations

GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)23 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)8 Rectangle (org.eclipse.swt.graphics.Rectangle)8 Point (org.eclipse.swt.graphics.Point)5 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)4 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)4 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 GC (org.eclipse.swt.graphics.GC)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)2 ObfuscateImage (com.biglybt.ui.swt.debug.ObfuscateImage)2 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)2 SearchSubsResultBase (com.biglybt.ui.swt.utils.SearchSubsResultBase)2 URL (java.net.URL)2 EnhancedDownloadManager (com.biglybt.core.download.EnhancedDownloadManager)1 MessageText (com.biglybt.core.internat.MessageText)1 LogAlert (com.biglybt.core.logging.LogAlert)1 AERunnable (com.biglybt.core.util.AERunnable)1