Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] GC.setXORMode on Cocoa


It seems you are implementing a block caret. Instead of using XOR could you just invert background and foreground for the character at caret position?

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;


public class CaretTest {
        static boolean visible = true;
public static void main(String[] args) {        
        final Display display = new Display();
        final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
       
        //Try other colors
//        shell.setForeground(display.getSystemColor(SWT.COLOR_YELLOW));
//        shell.setBackground(display.getSystemColor(SWT.COLOR_BLUE));

        shell.setForeground(display.getSystemColor(SWT.COLOR_YELLOW));
        shell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
       
        Runnable runnable = new Runnable() {
                public void run() {
                        visible = !visible;
                        shell.redraw();
                        display.timerExec(500, this);
                }
        };
        display.timerExec(500, runnable);
       
        shell.addListener(SWT.Paint, new Listener() {
                public void handleEvent(Event e) {
                        GC gc = e.gc;
                        Color backcolor = gc.getBackground();
                        Color forecolor = gc.getForeground();
                       
                        TextLayout layout = new TextLayout(gc.getDevice());
                        layout.setText("HelloWorld");
                        if (visible) {
                                TextStyle style = new TextStyle(null, backcolor, forecolor);
                                layout.setStyle(style, 5, 5);
                        }
                       
                        layout.draw(gc, 10, 10);
                        layout.dispose();                        
                       
                       
                }
        });
        shell.open();
        while (!shell.isDisposed()) {
                if (!display.readAndDispatch())
                        display.sleep();
        }
        display.dispose();
}
}


Silenio



From: Silenio Quarti/Ottawa/IBM@IBMCA
To: "Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
Date: 09/30/2009 09:53 AM
Subject: Re: [platform-swt-dev] GC.setXORMode on Cocoa
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx






I am not sure setXORMode() can be implemented with NSGraphicsContext.  [NSGraphicsContext.
setCompositingOperation:NSCompositeXOR] is a possibility, but I remember it does not work in some situations. Please open a bug report so that we can investigate.

Silenio

From: Dave Smith <dave.smith@xxxxxxxxxxx>
To: "Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
Date: 09/30/2009 06:36 AM
Subject: [platform-swt-dev] GC.setXORMode on Cocoa
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx






I have a console based application that needs to display a cursor for the current position. We use the GC. setXORMode when drawing the cursor so the
cursor is the same colour as the text and the text at the cursor position is changed to a different colour so it is readable.

This works on all platforms (including carbon) except for Cocoa. I know that this is deprecated so is there a manual way to implement this in Cocoa ?

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx

https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev



Back to the top