Professional Web Applications Themes

How to use PaintRect and XOR with colors? - Mac Programming

Hi.. I've been porting an app to the Mac, and have a problem with the use of XOR and PaintRect to show specific colors. I have a PICT resource copied from a 24-bit BMP file, which is a piano keyboard. I want to show which key is being hit in an audio program, and to do this in Windows I use an XOR drawing mode with an appropriate color. That way, I can simply draw it once to show it as down, then draw it again with the same code to show the key in its normal state again. However, ...

  1. #1

    Default How to use PaintRect and XOR with colors?

    Hi..

    I've been porting an app to the Mac, and have a problem with the use of
    XOR and PaintRect to show specific colors.

    I have a PICT resource copied from a 24-bit BMP file, which is a piano
    keyboard. I want to show which key is being hit in an audio program, and to
    do this in Windows I use an XOR drawing mode with an appropriate color.
    That way, I can simply draw it once to show it as down, then draw it again
    with the same code to show the key in its normal state again. However, on
    the Mac, all I get is an inversion of the color from white-to-black or
    vise-versa. Why??? I am using this code:

    RGBColor c = { 0xffff, 0x0000, 0x0000 ); // red - should make white key turn
    cyan!
    RGBForeColor( &c );
    PenNormal();
    PenMode( patXor );
    PaintRect(&myRect);

    When I do a LineTo call, this method of setting the color and xor mode works
    fine. But using PaintRect, all I get is black and white. Sure, the second
    call returns the key to its normal state, but I want the (white) keys to
    turn cyan when pressed. Why doesn't this work? Anyone know what I need to
    do to make it work (short of saving the key state and drawing in a different
    color depending onw hether it's up or down)?

    Thanks,
    Howard




    Howard Guest

  2. #2

    Default Re: How to use PaintRect and XOR with colors?

    In article <bhqskp$bo0dispatch.concentric.net>,
    "Howard" <alicebthotmail.com> wrote:
    > Hi..
    >
    > I've been porting an app to the Mac, and have a problem with the use of
    > XOR and PaintRect to show specific colors.
    >
    > I have a PICT resource copied from a 24-bit BMP file, which is a piano
    > keyboard. I want to show which key is being hit in an audio program, and to
    > do this in Windows I use an XOR drawing mode with an appropriate color.
    > That way, I can simply draw it once to show it as down, then draw it again
    > with the same code to show the key in its normal state again. However, on
    > the Mac, all I get is an inversion of the color from white-to-black or
    > vise-versa. Why??? I am using this code:
    >
    > RGBColor c = { 0xffff, 0x0000, 0x0000 ); // red - should make white key turn
    > cyan!
    > RGBForeColor( &c );
    > PenNormal();
    > PenMode( patXor );
    > PaintRect(&myRect);
    >
    > turn cyan when pressed. Why doesn't this work?
    PenNormal() resets the color. Move it BEFORE the RGBForeColor().
    David Phillip Oster Guest

  3. #3

    Default Re: How to use PaintRect and XOR with colors?

    In Article bhqv6r$bnldispatch.concentric.net, Howard wrote:
    > "David Phillip Oster" <osterieee.org> wrote in message
    > news:oster-7B777D.09223618082003news.sf.sbcglobal.net...
    >> In article <bhqskp$bo0dispatch.concentric.net>,
    >> "Howard" <alicebthotmail.com> wrote:
    >>
    >> PenNormal() resets the color. Move it BEFORE the RGBForeColor().
    It doesn't, although it resets penMode among other things.
    > Thanks, but that has no noticeable effect. It still only
    > shows me black&white.
    >
    > Surely it can't be hard to simply xor a specific color with an existing
    > background using PaintRect? It works fine with LineTo...what this
    > difference?
    It is very strange that it works with LineTo and doesn't work
    with PaintRect: these two calls should behave the same in this
    respect.

    Do you observe this on Mac OS <= 9 with monitors set to 256 or
    less colors? QuickDraw ignores color and inverts indices instead
    of inverting color components when in indexed mode (8-bit per
    pixel or less). E.g. if you draw red rectangle over white
    background with xor mode it will become black in 8 bits.

    The traditional way to do hiliting is:

    RGBBackColor(&backgroundColor); // e.g. white if your keys are white
    LMSetHiliteMode(LMGetHiliteMode() & ~(1L << hiliteBit));
    InvertRect(&r);
    // do the same to unhilite

    -- OR --

    RGBBackColor(&backgroundColor); // e.g. white if your keys are white
    PenMode(hilite);
    PaintRect(&r);
    // restore PenMode, e.g. call PenNormal
    // do the same to unhilite

    That will respect the hilite color of user preference.

    Although that will work pretty only if the area you are hiliting
    is of solid color (that should match current background color).
    If the hilited area contains shades of gray this works poor.

    --
    Mike Kluev

    PS. Remove "-DELETE-." part of my e-mail address to reply.

    Mike Kluev Guest

  4. #4

    Default Re: How to use PaintRect and XOR with colors?


    "Mike Kluev" <mikeobjc-source.-DELETE-.org> wrote in message
    news:BB671D8F.154B3%mikeobjc-source.-DELETE-.org...
    > In Article bhqv6r$bnldispatch.concentric.net, Howard wrote:
    The traditional way to do hiliting is:
    >
    > RGBBackColor(&backgroundColor); // e.g. white if your keys are white
    > LMSetHiliteMode(LMGetHiliteMode() & ~(1L << hiliteBit));
    > InvertRect(&r);
    > // do the same to unhilite
    >
    > -- OR --
    >
    > RGBBackColor(&backgroundColor); // e.g. white if your keys are white
    > PenMode(hilite);
    > PaintRect(&r);
    > // restore PenMode, e.g. call PenNormal
    > // do the same to unhilite
    >
    > That will respect the hilite color of user preference.
    >
    > Although that will work pretty only if the area you are hiliting
    > is of solid color (that should match current background color).
    > If the hilited area contains shades of gray this works poor.
    >
    > --
    > Mike Kluev
    Thanks, Mike! Works perfectly! :-D

    -Howard


    Howard Guest

Similar Threads

  1. Colors in pdf are different -- help!
    By Teresa_Halbrehder@adobeforums.com in forum Adobe Indesign Windows
    Replies: 1
    Last Post: August 5th, 04:45 PM
  2. Colors change to differnt colors when printing
    By alphamacg4@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 2
    Last Post: June 2nd, 11:27 PM
  3. Bitmap image colors match FH colors?
    By imalbion in forum Macromedia Freehand
    Replies: 2
    Last Post: May 12th, 11:37 PM
  4. Printout colors inconsistent with monitor colors
    By Lilian_Im@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 1
    Last Post: April 29th, 08:11 PM
  5. Why do the colors in the 'print preview' not match the colors on the desktop?
    By BMC15 in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 4
    Last Post: April 8th, 01:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139