Board index » cppbuilder » canvas problem

canvas problem


2003-09-18 05:40:30 PM
cppbuilder95
Hi,
As nobody seems to understand what i need, i'm going to present my problem
differently. I hope that it will be clearer now ;-)
I want to write a transparent components, but first, i would like to test a
simple "save and restore" canvas method, with normal components.
I would to save form canvas (owner of my dropped component) when i drop a
component on it.
hidden idea -->crop form canvas to adjust it to the client area of my
dropped component (to make it transparent).
So for now, i'm looking for how to save this form canvas when i drop a
component on it. This saving must be in the component itself.
tia,
Alain
 
 

Re:canvas problem

Hi,
I 've derived a class from TCustomControl and instatinaed an object. This
object owns and is parent of several objects derived from TGraphicControl.
The issue is if I paint the owned controls in their own
(TGraphicControls) canvas does not paint, but if I paint the owned
controls on the Parent's canvas it does? Is it obligatory to have only one
canvas per window ? How can I use different Canvas for a shared Window ?
I think , the issue is not only to draw but to reply the occuring events.
If I paint them on Parent's canvas, I can only reply to the Parents Control
events not to parented controls. But if I can be able to draw this
controls on their own canvas I might be able to reply the occuring events
within the owned controls .
Does any body have any idea about this issue?
Thanks
Sabetay
 

Re:canvas problem

"Sabetay Toros" < XXXX@XXXXX.COM >wrote in message
Quote
I 've derived a class from TCustomControl and instatinaed an object.
Questions regarding writing your own components should be directed to the
.vcl.components.writing group instead.
As for the painting, the owner component should not be painting its child
controls to begin with. They should be doing their own individual painting
inside thier own Paint() methods, just as the parent component should only
be doing its own painting in its Paint() method.
Gambit
 

{smallsort}

Re:canvas problem

Remy,
Sory, next time I'll ask at the proper newsgroup.
I've done exactly what you have said. The windowed controls are painting
themselves in their own Paint metod using the GraphicControl derived Canvas
and also the parent is painting in their own method using TCustomControl
Canvas. if the Canvas are different the owned controls cannot be seen on
the screen. But if they share the TCustomControl's canvas it is visible.
Why?
Sabetay
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Sabetay Toros" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I 've derived a class from TCustomControl and instatinaed an object.

Questions regarding writing your own components should be directed to the
.vcl.components.writing group instead.

As for the painting, the owner component should not be painting its child
controls to begin with. They should be doing their own individual
painting
inside thier own Paint() methods, just as the parent component should only
be doing its own painting in its Paint() method.


Gambit


 

Re:canvas problem

"Sabetay Toros" < XXXX@XXXXX.COM >wrote in message
Quote
I've done exactly what you have said. The windowed controls are painting
themselves in their own Paint metod using the GraphicControl derived
Canvas
and also the parent is painting in their own method using TCustomControl
Canvas. if the Canvas are different the owned controls cannot be seen on
the screen. But if they share the TCustomControl's canvas it is visible.
Please show your actual code. You are not supposed to be sharing Canvases,
every visual component has its own Canvas whose Handle is provided by the
WM_PAINT message for that particular window.
Gambit
 

Re:canvas problem

Hi everyone.
I have four TBX buttons on a toolbar. Each of their OnDrawImage events
is linked to a custom event that draws a solid rectangle over the applicable
button's face, using Canvas.FillRect.
The problem is that it works for the first button, but not for the
subsequent
buttons.
Any ideas?
Thanks in advance
Chris
//========================================
Code example
=======================================//
procedure TfrmMain.DrawImage(Item: TTBCustomItem;
Viewer: TTBItemViewer; Canvas: TCanvas; ImageRect: TRect;
ImageOffset: TPoint; StateFlags: Integer);
var
image : TBitmap;
size : TSize;
px, py, i, item_index : integer;
found : boolean;
Toolbar : TTBXToolBar;
Dock : TTBDock;
line : String;
B : TBrush;
begin
(* here is code that searches for the Item's Toolbar and determines
integer place on Toolbar *)
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := ToolBar.Color;
//paint background color
Canvas.FillRect(Viewer.BoundsRect);
//display hot bitmap
image := TBitmap.Create();
ToolBar.Images.GetBitmap(item_index*5+3,image);
Canvas.Draw(ImageRect.Left,ImageRect.Top,image);
//position the text
size := Canvas.TextExtent(Item.Caption);
//x pos = Round((rect.width - text.length) / 2 - 1)
//y pos := rect.bottom - text.height - 3 pixels
px := Round(((Viewer.BoundsRect.Right - Viewer.BoundsRect.Left + 1) -
size.cx) / 2 - 1);
py := Viewer.BoundsRect.Bottom - size.cy - 3;
Canvas.TextOut(px,py,Item.Caption);
end;
end;
--------------------------------------
Chris Buys
Development
HAS Software (Pty) Ltd
 

Re:canvas problem

Hi Chris,
Some things to check
1. Is the event handler firing for every button?
2. When tracing, are the ImageRect fields filled with valid values?
3. The call to FillRect(Viewer.BoundsRect) is erasing what exactly? Is it
the rect of the button image and text, or is it something else?
4. I noticed you're not using the passed in ImageOffset parameter.
Best regards
 

Re:canvas problem

Thanks for the tips.
In the end, though, I used the Canvas.ClipRect object to paint
over the button (ClipRect was set to the correct values when the
event was fired). I use the ImageRect rectangle to paint a custom
bitmap; the use of the ImageOffset is not necessary.
Regards
Chris
--------------------------------------
Chris Buys
Development
HAS Software (Pty) Ltd
"RandomAccess" < XXXX@XXXXX.COM >wrote in message
Quote
Hi Chris,

Some things to check

1. Is the event handler firing for every button?

2. When tracing, are the ImageRect fields filled with valid values?

3. The call to FillRect(Viewer.BoundsRect) is erasing what exactly? Is
it
the rect of the button image and text, or is it something else?

4. I noticed you're not using the passed in ImageOffset parameter.

Best regards



 

Re:canvas problem

Hi all,
I try to use in my windows area Canvas->FillRect(...) and
Canvas->FloodFill(...) in a main
form.
When I move a new windows form on this region FillRect works good behind new
windows but FloodFill doesn't: it paints only a region part with new Brush
color, the rest is painted with default one.
Any Idea?
 

Re:canvas problem

"Giovanni Lazzarini" <glazzariniATmediasoft-srlDOTcom>wrote in message
Quote
Any Idea?
Your description is too vague. What does your actual code look like? Where
exactly are you performing the drawing? If you are drawing on the form
directly, but are not using the form's OnPaint event, then you should be.
Gambit