BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to undraw on Canvas?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Jun 20, 2005 9:53 pm    Post subject: Re: How to undraw on Canvas? Reply with quote




"Veebo" <depandi (AT) sa (DOT) com> wrote


Quote:
I derived my own classes from VCL classes so I can
access the Canvas property.

You can use a TControlCanvas, then you don't need descendants.

Quote:
Here's my question: How can I "un-draw" the squares??

The short answer is, you don't "undraw" anything. To remove a drawing, you
have to draw something else over it , such as the control's background, or
the control's parent's background. If you are drawing within the control's
rectange, not over the edges, then simply invalidate the control and have
the drawing not include the squares again until you are ready for them
again.

Quote:
for example, when say a button, a label, and a panel are selected.
When you click on the Form, all 3 controls should get de-selected.
i.e. the little square on their corners should disappear. How can I
do that?

That is hard to answer without first seeing how you are drawing them to
begin with.


Gambit



Back to top
Veebo
Guest





PostPosted: Mon Jun 20, 2005 9:56 pm    Post subject: How to undraw on Canvas? Reply with quote




Hi,

I draw four small squares on a controls (Button, labels, Panel,
groupboxes, pagecontrols) when a control is clicked on to
indicate that it is selected.

I allow user to select multiple controls and them let him
peform actions such as cut, copy, paste etc.. similar to BCB IDE

I derived my own classes from VCL classes so I can access the
Canvas property. i draw four boxes at four corners.

Here's my question: How can I "un-draw" the squares??

for example, when say a button, a label, and a panel are
selected. When you click on the Form, all 3 controls should
get de-selected.. i.e. the little square on their corners should
disappear. How can I do that?

I thought re-painting the control and then the form would take
care of it. I tried something like this on Form's OnMouseDown
event...

// here SelControls is derived from TList and has pointers to
//controls that are selected

if(SelControls->Count > 0)
{
for(int i= 0; i<SelControls->Count; i++)
{
SelControls->Items[i]->Repaint();
}
SelControls->Clear();
Invalidate();
}


the results are strange... i.e. depending the order in which
the controls were selected.

If I paint on a controls canvas using FillRect and the later if
I call Repaint() on that controls, shouldn't whatever that was
drawn on the cntrol's canvas get removed??

I will appreciate your help.

thanks,
Veebo

Back to top
Rudy Velthuis [TeamB]
Guest





PostPosted: Mon Jun 20, 2005 10:03 pm    Post subject: Re: How to undraw on Canvas? Reply with quote



At 23:56:18, 20.06.2005, Veebo wrote:

Quote:
If I paint on a controls canvas using FillRect and the later if
I call Repaint() on that controls, shouldn't whatever that was
drawn on the cntrol's canvas get removed??

You'll have to call Invalidate and then, in the Paint routine, draw the
control according to its state.
--
Rudy Velthuis [TeamB] http://velthuis.homepage.t-online.de

"Wit makes its own welcome and levels all distinctions."
-- Ralph Waldo Emerson (1803-1882)

Back to top
Veebo
Guest





PostPosted: Mon Jun 20, 2005 10:43 pm    Post subject: Re: How to undraw on Canvas? Reply with quote


Hi,

Quote:
You can use a TControlCanvas, then you don't need descendants.

I see. thanks. Actually I needed to derive my own classes
anyway for other reasons, so I just made sure that Canvas
Proprerty is accessible.

Quote:
To remove a drawing, you
have to draw something else over it , such as the control's background, or
the control's parent's background.

How do you do that? I think in my case this may not be
necessary.

Quote:
If you are drawing within the control's
rectange, not over the edges, then simply invalidate the >control

I tried this and it work for every control except pageControl.
I draw right at the edges and inside.. Look at the code below

for example top left will be drawn like this..

TempCont->Canvas->FillRect(TRect(0,0,6,6));
So at the edge and inside.

Quote:
That is hard to answer without first seeing how you are drawing them to
begin with.


if(pCont->ClassNameIs("SLabel") )
{
SLabel *TempCont = dynamic_cast<SLabel*>(pCont);
TempCont->Canvas->Brush->Style = bsSolid;
TempCont->Canvas->Brush->Color = clRed;
TempCont->Canvas->FillRect(TRect(0,0,6,6));
TempCont->Canvas->FillRect(TRect(pCont->Width-
6,0,pCont->Width,6));
TempCont->Canvas->FillRect(TRect(pCont->Width-6,pCont-
Quote:
Height-6,pCont->Width,pCont->Height));
TempCont->Canvas->FillRect(TRect(0,pCont->Height-

6,6,pCont->Height));
}
else if(pCont->ClassNameIs("SGroupBox") )
{
...
}
else if (...)


When you click on the Form (so that everything selected
becomes un-selected), I do the following

if(SelControls->Count > 0)
{
for(int i= 0; i<SelControls->Count; i++)
{
// SelControls->Items[i]->Repaint();
// removed Repaint() and replaced it with Invalidate()
SelControls->Items[i]->Invalidate();
}
SelControls->Clear();
Invalidate();
}

This works for all controls except PageControl??!! any
particular reason??

thanks,
Veebo

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Jun 21, 2005 12:22 am    Post subject: Re: How to undraw on Canvas? Reply with quote


"Veebo" <depandi (AT) sa (DOT) com> wrote


Quote:
I tried this and it work for every control except pageControl.

Why not? You need to be more specific. What EXACTLY is going wrong?

Quote:
if(pCont->ClassNameIs("SLabel") )
{
SLabel *TempCont = dynamic_cast<SLabel*>(pCont);

That code is redundant. You are essentially doing two dynamic type lookups
that do the same thing. Do this instead:

SLabel *TempCont = dynamic_cast<SLabel*>(pCont);
if( pCont )
{
//...
}

Quote:
When you click on the Form (so that everything selected
becomes un-selected), I do the following

Where exactly do you decide to draw the squares? You only showed HOW you
draw them, but you did not show WHERE the drawing is happening. It should
only be when the control is actually being painted onscreen by the VCL/API.
Removing the squares would then only be a matter of clearing whatever
condition triggers the drawing and then calling Invalidate(). For example:

void __fastcall SLabel::Paint()
{
// default drawing ...

if( some condition )
// draw squares ...
}

// to draw the squares...
SelControls->Add(SLabel1);
// set some condition that tells SLabel1 that it needs to draw the
squares...
SLabel1->Invalidate();

// to remove the squares...
SelControls->Remove(SLabel1);
// clear some condition that tells SLabel1 that it no longer needs to
draw the squares...
SLabel1->Invalidate();

Again, you need to be more specific. You have not explained what is
actually happening, or explained any ways to reproduce it.


Gambit



Back to top
Veebo
Guest





PostPosted: Tue Jun 21, 2005 11:32 pm    Post subject: Re: How to undraw on Canvas? Reply with quote



Quote:
Why not? You need to be more specific. What EXACTLY is >going wrong?

Basically in all other controls, the 4 squares get removed, but
in PageControl TopLeft one gets removed completely. TopRight
one stays fully. BOttom left and right onese stay partially.
I can see why bottom left and right ones stay, cuz they get
painted sort ofon the TabSheets eventhough i paint them on
the pageControl. I don't invalidate TabSheets.

Top right I don't uderstand why doesn't get
removed? Is it because nothing gets painted over it? i.e.
when you have a PageControl with only one or two TabSheets,
the shape is not perfect rectangular. There some sort of
"empty" space.


Quote:
That code is redundant. You are essentially doing two
dynamic type lookups

I see. I will correct that. thanks.


Quote:

Where exactly do you decide to draw the squares? You only >showed HOW you
draw them, but you did not show WHERE the drawing is >happening.

sorry about that. I assumed you undestood what I mean.
My application mimics BCB IDE (but obviously not even remotely
as powerful). So, when you press SHIFT and left click on a
control, it gets "selected" and those 4 squares get drawn on it

Here's WHERE i draw those squares: On each control's
OnMouseDown event...
roughly like this.. (i have removed other code that will only
confuse you since it doesn't apply to this question)
here, say in PageControl's OnMouseDown event..

void __fastcall TChildForm::PageControlMouseDown(TObject
*Sender,TMouseButton Button, TShiftState Shift, int X, int Y)
{
....

if(Shift.Contains(ssShift) && Button == mbLeft)
{
// if not in list add in list and draw squares
if(!IsInSelList(MyActiveControl))
{
SelControls->Add(MyActiveControl);
DrawMulSel(MyActiveControl);
}
}
....
}
MyActiveControl will be the PageControl that is clicked on.
I know I can sue Sender or even application's active control,
but I have a reason to use MyActiveControl.


I will appreciate your input on why the problem i described
above takes place.

thanks,
Veebo

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.