Board index » delphi » Callouts/ Balloons and Clouds of text

Callouts/ Balloons and Clouds of text

Greetings and Salutations from Houston;

and yes Houston, We have a problem. In Powerpoint,
there are "callouts", little text balloons like you see in
the comics. I need something
like that for D4. I have searched the usual suspects and
have not found anything like it.
(Well one, but it wasn't very clean). All the component
needs to do is put a "oval type"
border around the text for spoken words and a "cloud type"
border around thoughts. Thanks
for any help or suggestions (except for the negative ones.
To those, same to you, Bud)
TImage and Text don't seem to mix, is it possible to
"adjust" the border on a label enough?

Thanks
Bill

 

Re:Callouts/ Balloons and Clouds of text


What do you mean by "spoken text"? I know of a product called HTMLBalloons that
does that. You can get it at: http://www.educationx.com/agents/deve/htmlballoons/index.htm

From the site:
Developed by Costas Andriotis, HTMLBalloons? is a new API that allows you to host
rectangular or bubble-style HTML controls in your Web pages and desktop applications.
You can toggle display of icons on the balloon, change the foreground and background
colors, set the font displayed, move and resize balloons, allow users to move and resize
balloons, dynamically insert HTML or load Web pages for balloon content, and do so
much more. Support for inline HTML makes them the richest balloons created to date.

You can dynamically insert HTML and DHTML or scripting into balloons, or you can load
pre-existing HTML files using file://, http://, or res:// protocols.

Perfect for MSAgent-enabled products, you can combine HTMLBalloons? with existing
MSAgent character interfaces, adding completely input-oriented balloons.

All development environments supporting ActiveX should work with HTMLBalloons?.
Installation of Internet Explorer 4.0 or later is required. Installation of MS Office or use
with Microsoft Agent is not required. We have run tests under Visual C++ 6.0, Visual
Basic 5.0/6.0, Internet Explorer 4.0/5.0 final release.

Quote
Bill Talbert wrote:
> Greetings and Salutations from Houston;

> and yes Houston, We have a problem. In Powerpoint,
> there are "callouts", little text balloons like you see in
> the comics. I need something
> like that for D4. I have searched the usual suspects and
> have not found anything like it.
> (Well one, but it wasn't very clean). All the component
> needs to do is put a "oval type"
> border around the text for spoken words and a "cloud type"
> border around thoughts. Thanks
> for any help or suggestions (except for the negative ones.
> To those, same to you, Bud)
> TImage and Text don't seem to mix, is it possible to
> "adjust" the border on a label enough?

> Thanks
> Bill

Re:Callouts/ Balloons and Clouds of text


Spoken text is the text in the comics the characters speak.
The thought text is the text they think, usually in cloud
type containers with little bubbles back to the character
thinking.

Re:Callouts/ Balloons and Clouds of text


Quote
Bill Talbert wrote:
> TImage and Text don't seem to mix, is it possible to
> "adjust" the border on a label enough?

By Timage and TExt not mixing are you saying that Using the Canvas
property ov TImage doesn't work.
If your TImage is the Image of a balloon or thought cloud you should be
able to simply go...
  Image1.Canvas.Brush.Style := bsClear;            
  Image1.Canvas.TextOut( 2, 2, 'Hello');
and it should work( Obviously with some funky algorith to Centre the
Text ).
I just did this in a simple project and it worked fine.

Ciao

Dominique Louis
Delphi Developer and aspiring Delphi Game Developer when wife and son
permit.
********************************************************
** Punching the Monitor Hurts You more than Microsoft **
** -------------------Jim Williams------------------- **
********************************************************

Re:Callouts/ Balloons and Clouds of text


Dominique;

Thanks for the help.  I am not much on Graphics, this is new to me.  I took
your suggestion and added it to a label and cam up with this:

procedure TForm1.Button4Click(Sender: TObject);
begin
// Label1.Repaint;
 Label1.Canvas.brush.color := clRed;
 Label1.Canvas.brush.style := bsClear;
 Label1.AutoSize := False;
 Label1.Width :=Label1.Canvas.TextWidth(Edit1.text) + 20 ;
 Label1.Height :=Label1.Canvas.TextHeight(Edit1.text) +20 ;
 Label1.Canvas.Ellipse(0, 0, Label1.Width, Label1.Height);
 Label1.Canvas.TextOut(10,10,Edit1.text);
 end;

My new problem is on the first onClick , Label1 goes blank.  Subsequent
clicks, it displays correctly.  each time the text in Edit1 is changed, the
first click blanks out Label1 and subsequent clicks it is correct.  Any
ideas?

Re:Callouts/ Balloons and Clouds of text


Hi,
Do you mean something like the window on this page :

http://friko3.onet.pl/ld/vizyp/chmurka.htm

?

Vizvary Istvan, jr.
vi...@hotmail.com

Re:Callouts/ Balloons and Clouds of text


Hi;
That is close.  I do not need the shadows, is that yours?
could you share with me how it was done?

thanks
Bill

Re:Callouts/ Balloons and Clouds of text


Quote
Bill Talbert wrote:
> My new problem is on the first onClick , Label1 goes blank.  Subsequent
> clicks, it displays correctly.  each time the text in Edit1 is changed, the
> first click blanks out Label1 and subsequent clicks it is correct.  Any
> ideas?

I had a bit of spare time on my hands and literally threw this component
together.
It is probably far from the best implementation of a TGraphicControl but
it gets the basics done and should get you started. If you improve it
please send me a copy of the unit. As this news group does not support
attachments you will have to cut and paste the text below and save it
into a unit called SpeechBubble. Install and you should be away.

unit SpeechBubble;

{**  A Very basic Speech Bubble component with 2 styles.
   SpeechBox and Think Cloud. It needs a bit of tweaking to get things
   perfect but I think it should be a good starting point for someone
   who needs such a component. I only put it together because I hadn't
   written a component from scratch in a while ( an this probably shows
)
   and someone on the delphi.graphics newsgroup was asking for one. So
this
   was my first attempt.
   All I ask is that if you improve this component in any way ( which
I'm sure
    someone will ) is that you send me a copy of the improved component.
   So it's free to use for what ever purpose you so desire.
   I couldn't work out how to get the component to notice a font change
so if someone
   fixes this, please let me know how you fixed this.
   I'll also be putting this up on my website for download soon.

   Created By : Dominique Louis On : 30/05/1999.
   Send e- mailto:Domini...@SavageSoftware.com.au
   Company : Savage Software Solutions
   WebSite : http://www.SavageSoftware.com.au
   Delphi Games Site : http://www.SavageSoftware.com.au/delphi/
**}
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  ExtCtrls, StdCtrls;

type
  TBubbleShape = ( bsSpeechBox, bsThinkCloud );

  TSpeechBubble = class(TGraphicControl)
  private
    { Private declarations }
    fBrush: TBrush;
    fBubbleShape: TBubbleShape;
    fPen: TPen;
    procedure setBubbleShape(const Value: TBubbleShape);
    function DrawThinkCloud : TRect;
    function DrawSpeechBox : TRect;
    procedure SetBrush(const Value: TBrush);
    procedure SetPen(const Value: TPen);
    procedure CMTextChanged(var Message: TMessage); message
CM_TEXTCHANGED;
    procedure CMFontChanged(var Message: TMessage); message
CM_FONTCHANGED;
  protected
    { Protected declarations }
    procedure Paint; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
    property Align;
    property Anchors;
    procedure StyleChanged(Sender: TObject);
    property Brush: TBrush read FBrush write SetBrush;
    property BubbleShape : TBubbleShape read fBubbleShape write
setBubbleShape;
    property Caption;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property ParentShowHint;
    property Pen: TPen read FPen write SetPen;
    property ShowHint;
    property Visible;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TSpeechBubble]);
end;

{ TSpeechButton }

procedure TSpeechBubble.CMFontChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;

procedure TSpeechBubble.CMTextChanged(var Message: TMessage);
begin
  Invalidate;
end;

constructor TSpeechBubble.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csReplicatable];
  Width := 180;
  Height := 60;
  fPen := TPen.Create;
  fPen.OnChange := StyleChanged;
  fPen.Style := psClear;
  fBrush := TBrush.Create;
  fBrush.OnChange := StyleChanged;
  fBubbleShape := bsSpeechBox;
end;

destructor TSpeechBubble.Destroy;
begin
  FPen.Free;
  FBrush.Free;
  inherited Destroy;
end;

function TSpeechBubble.DrawSpeechBox : TRect;
var
  X, Y, W, H, S: Integer;
begin
  with Canvas do
  begin
    Pen := fPen;
    Brush := fBrush;
    X := Pen.Width div 2;
    Y := X;
    W := Width - Pen.Width + 1;
    H := Height - ( Pen.Width + 8 ) ;
    if Pen.Width = 0 then
    begin
      Dec(W);
      Dec(H);
    end;
    if W < H then S := W else S := H;
    Polygon( [Point(10, Height - 10), Point(0, Height), Point(20, Height
- 10)] );
    RoundRect(X, Y, X + W, Y + H, S div 4, S div 4);
    result := Rect( X , Y, W - 5, H - 10);
  end;
end;

function TSpeechBubble.DrawThinkCloud : TRect;
var
  X, Y, W, H: Integer;
  CloudRect : TRect;
begin
  with Canvas do
  begin
    Pen := fPen;
    Brush := fBrush;
    X := Pen.Width div 2;
    Y := X;
    W := Width - Pen.Width + 1;
    H := Height - ( Pen.Width + 8 );
    if Pen.Width = 0 then
    begin
      Dec(W);
      Dec(H);
    end;
    CloudRect := Rect( X , Y, W div 2 + 10, H div 2 + 10 );
    Ellipse( 0, Height - 5, 5, Height - 10 );
    Ellipse( 5, Height - 10, 15, Height - 15 );
    Ellipse( CloudRect.Left, CloudRect.Top, CloudRect.Right ,
CloudRect.Bottom );
    OffSetRect ( CloudRect, (w div 2) - 10, 0 );
    Ellipse( CloudRect.Left, CloudRect.Top, CloudRect.Right ,
CloudRect.Bottom );
    OffSetRect ( CloudRect, -( (w div 2) - 10), ( H div 2 - 10 ) );
    Ellipse( CloudRect.Left, CloudRect.Top, CloudRect.Right ,
CloudRect.Bottom );
    OffSetRect ( CloudRect, (w div 2)- 10 , -( ( H div 2 ) - 10 ) + ( H
div 2 - 10 ) );
    Ellipse( CloudRect.Left, CloudRect.Top, CloudRect.Right ,
CloudRect.Bottom );
    result := Rect( X , Y, W - 10, H - 10 );
  end;
end;

procedure TSpeechBubble.Paint;
var
  Rect, CalcRect : TRect;
begin
  case fBubbleShape of
    bsThinkCloud :
      Rect := DrawThinkCloud;
    bsSpeechBox :
      Rect := DrawSpeechBox;
  end;
  with Canvas do
  begin
    Font := Font;
    Font.Color := Pen.Color;
    Brush.Style := bsClear;
    CalcRect := Rect;
    DrawText(Canvas.Handle, PChar(Caption), Length(Caption), CalcRect, (
DT_WORDBREAK or DT_CENTER or DT_CALCRECT ) );
    OffsetRect(Rect, 0, (Height - CalcRect.Bottom) div 2);
    DrawText(Canvas.Handle, PChar(Caption), Length(Caption), Rect, (
DT_WORDBREAK or DT_CENTER ) );
  end;
end;

procedure TSpeechBubble.SetBrush(const Value: TBrush);
begin
  if fBrush <> Value then
    fBrush.Assign(Value);
end;

procedure TSpeechBubble.setBubbleShape(const Value: TBubbleShape);
begin
  if fBubbleShape <> Value then
  begin
    fBubbleShape := Value;
    Invalidate;
  end;
end;

procedure TSpeechBubble.SetPen(const Value: TPen);
begin
  if fPen <> Value then
    fPen.Assign(Value);
end;

procedure TSpeechBubble.StyleChanged(Sender: TObject);
begin
  Invalidate;
end;

end.

Well, I hope this helps.

Ciao,

Dominique Louis
Delphi Developer and aspiring Delphi Game Developer.
*********************************************************
**  To Do Nothing is to Collaborate with the oppressor **
**  -------------------------------------------------- **
**  Punching the monitor hurts you more than Micro$oft **
*********************************************************
=========================================================
From . . . . . . . : Dominique Louis                    
Company. . . . . . : Savage Software Solutions
Web Site . . . . . : http://www.SavageSoftware.com.au
Delphi Site. . . . : http://www.SavageSoftware.com.au/delphi
Email. . . . . . . : Domini...@SavageSoftware.com.au
=========================================================

Other Threads