Drawing text with opaque background?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Drawing text with opaque background?

Carl Gundel-2
What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Maarten Mostert

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Carl Gundel-2

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

 

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Carl Gundel
Thanks guys but I'm not using Cairo.

-Carl Gundel
Liberty BASIC for Windows - http://www.libertybasic.com
Run BASIC, easy web programming - http://www.runbasic.com

On Nov 19, 2012, at 9:32 AM, "Boris Popov, DeepCove Labs" <[hidden email]> wrote:

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

<image001.png>

 

-Boris

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Steven Kelly

Another way to do it: BackColor, from ExtraEmphases. You may of course reply that you’re not using ExtraEmphases J.

Steve

 

Carl Gundel wrote:

 

Thanks guys but I'm not using Cairo.

-Carl Gundel

Liberty BASIC for Windows - http://www.libertybasic.com

Run BASIC, easy web programming - http://www.runbasic.com


On Nov 19, 2012, at 9:32 AM, "Boris Popov, DeepCove Labs" <[hidden email]> wrote:

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

<image001.png>

 

-Boris

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Boris Popov, DeepCove Labs (SNN)

I would have a peek at WidgetState>>isOpaque: then and see the various senders, i.e. SimpleComponent>>displayBackgroundIfNeededOn:in:. I think it’ll ultimately come down to displaying a rectangle somewhere before painting the text either way you slice it.

 

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Carl Gundel
Sent: Monday, November 19, 2012 10:05 AM
To: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

Thanks guys but I'm not using Cairo.

-Carl Gundel

Liberty BASIC for Windows - http://www.libertybasic.com

Run BASIC, easy web programming - http://www.runbasic.com


On Nov 19, 2012, at 9:32 AM, "Boris Popov, DeepCove Labs" <[hidden email]> wrote:

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

<image001.png>

 

-Boris

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Dave Stevenson-3
In reply to this post by Carl Gundel
Here's some low level code. It does not first draw a background, so you'll have to do that if you want it. See senders of #displayFromCharacter:to:startX:forTranslation:on: to see higher level code.
 
...
aGraphicsContext paint: self selectionForegroundColor.
aComposedText
  displayFromCharacter: first
  to: last
  startX: startPoint left + self origin x
  forTranslation: self origin
  on: aGraphicsContext
 
Dave Stevenson
[hidden email]



From: Carl Gundel <[hidden email]>
To: "[hidden email]" <[hidden email]>
Sent: Mon, November 19, 2012 7:05:57 AM
Subject: Re: [vwnc] Drawing text with opaque background?

Thanks guys but I'm not using Cairo.

-Carl Gundel
Liberty BASIC for Windows - http://www.libertybasic.com
Run BASIC, easy web programming - http://www.runbasic.com

On Nov 19, 2012, at 9:32 AM, "Boris Popov, DeepCove Labs" <[hidden email]> wrote:

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

<image001.png>

 

-Boris

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Dave & Vicki Stevenson
In reply to this post by Carl Gundel
Here's some low level code. It does not first draw a background, so you'll have to do that if you want it. See senders of #displayFromCharacter:to:startX:forTranslation:on: to see higher level code.
 
...
aGraphicsContext paint: self selectionForegroundColor.
aComposedText
  displayFromCharacter: first
  to: last
  startX: startPoint left + self origin x
  forTranslation: self origin
  on: aGraphicsContext

 
Dave Stevenson
[hidden email]


From: Carl Gundel <[hidden email]>
To: "[hidden email]" <[hidden email]>
Sent: Mon, November 19, 2012 7:05:57 AM
Subject: Re: [vwnc] Drawing text with opaque background?

Thanks guys but I'm not using Cairo.

-Carl Gundel
Liberty BASIC for Windows - http://www.libertybasic.com
Run BASIC, easy web programming - http://www.runbasic.com

On Nov 19, 2012, at 9:32 AM, "Boris Popov, DeepCove Labs" <[hidden email]> wrote:

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

<image001.png>

 

-Boris

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Samuel S. Shuster-2
In reply to this post by Carl Gundel-2
Carl,

> What's the best way to draw text on a graphics context with an opaque
> background?


First, there are the concepts, some of which you probably know, but for completeness I'll include.

You draw with a GraphicsContext. A GraphicsContext knows nothing about foreground or background. It is just a, possibly clipped and/or offset area associated with the the screen or a window that you paint on.

It knows nothing about erasing or things that are "under" it.

Your job in effect is to fake the person who is looking at what you are drawing into perceiving that there is background and foreground and so on.

So, lets say you have a Rectangle (50 @ 50 extent: 100 @ 100) you want to draw opaque text on, which perhaps has other things already drawn on.

You first "Fill" the area with background color using the current background color:

        aGraphicsContext paint: aWidgetOrWindow backgroundColor.
        aGraphicsContext displayRectangle: 50 @ 50

Then you set the foreground/font color and display a string

        aGraphicsContext paint: aWidgetOrWindow foregroundColor.
        aGraphicsContext displayString: 'HiHo' at: 50 @ 74

Now, why at 74 and not 50? That is because text is displayed with the Y "0" at the baseline, which you can think of as the point that the two diagonal lines of the letter v meet.

If you wanted to be more exact, you could ask the current TextAttributes/widget textStyle for #baseline, and add that to the top of your rectangle.

FWIW, if you are actually using a Text, you can instead use:

        aText displayOn: aGraphicsContext at: 50 @ 74

Yes, the 7 years leading the GUI project still has some echoes in my head.

                                And So It Goes
                                     Sames
______________________________________________________________________

Samuel S. Shuster [|]





_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Drawing text with opaque background?

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Dave Stevenson-3

Another approach is to load HotDraw then do,

 

gc := Window currentWindow graphicsContext.

text := (TextFigure string: 'Hello, World')

                                                fillColor: ColorValue yellow;

                                                opaque;

                                                yourself.

text displayOn: gc at: 140@150.

 

 

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Dave Stevenson
Sent: Monday, November 19, 2012 11:31 AM
To: Carl Gundel; [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

Here's some low level code. It does not first draw a background, so you'll have to do that if you want it. See senders of #displayFromCharacter:to:startX:forTranslation:on: to see higher level code.

 

...
aGraphicsContext paint: self selectionForegroundColor.

aComposedText
  displayFromCharacter: first
  to: last
  startX: startPoint left + self origin x
  forTranslation: self origin
  on: aGraphicsContext

 

Dave Stevenson
[hidden email]

 

 


From: Carl Gundel <[hidden email]>
To: "[hidden email]" <[hidden email]>
Sent: Mon, November 19, 2012 7:05:57 AM
Subject: Re: [vwnc] Drawing text with opaque background?


Thanks guys but I'm not using Cairo.

-Carl Gundel

Liberty BASIC for Windows - http://www.libertybasic.com

Run BASIC, easy web programming - http://www.runbasic.com


On Nov 19, 2012, at 9:32 AM, "Boris Popov, DeepCove Labs" <[hidden email]> wrote:

gc := Window currentWindow graphicsContext.

gc newCairoContextWhile:

                                [:cr |

                                | layout |

                                layout := (cr newLayout)

                                                                                text: 'Hello, World!';

                                                                                fontDescriptionString: 'arial bold 10';

                                                                                yourself.

                                cr

                                                source: ColorValue red;

                                                rectangle: (50 @ 150 extent: layout extent);

                                                fill;

                                                source: ColorValue black;

                                                moveTo: 50 @ 150.

                                layout showOn: cr].

 

<image001.png>

 

-Boris

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Monday, November 19, 2012 9:12 AM
To: [hidden email]
Cc: [hidden email]
Subject: Re: [vwnc] Drawing text with opaque background?

 

http://www.cairographics.org/

 

Cheers,

 

Maarten,

 

-----Original Message-----
From: "Carl Gundel" <[hidden email]>
Sent: Saturday, 17 November, 2012 20:54
To: [hidden email]
Subject: [vwnc] Drawing text with opaque background?

What's the best way to draw text on a graphics context with an opaque
background?

Thanks,

-Carl Gundel
http://www.libertybasic.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc