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 

Help with TDrawGrid!

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Mr B
Guest





PostPosted: Sat Dec 23, 2006 5:02 pm    Post subject: Help with TDrawGrid! Reply with quote



Hi everyone,

I trying to make use of a TDrawGrid for a project of mine which will
represent creatures in a world as shapes. I've been trying for
sometime to get the TDrawGrid to work but havn't found anycode which
will let me do something like this, basically I want an underlying grid
of values which determine the creature or element graphically. I have
found some code on the Internet that has shown me how to use graphics
on a TStringGrid, (this same code doesn't work with a TDrawGrid as it
accesses a property "Cells" which TDrawGrid doesn't have)

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if ( StringGrid1->Cells[ ACol ][ARow ].ToInt() != 0 )
StringGrid1->Canvas->Draw(Rect.Left, Rect.Top,GreenLightBmp );
else
StringGrid1->Canvas->Draw(Rect.Left, Rect.Top, BlankBmp );
}

Are there any performance penalties for using a StringGrid as opposed
to a DrawGrid? I presume there is a way of doing this with a DrawGrid
could anybody tell me this?

Thanks alot, I'm new to using Borlands VCL so i'm a little unsure about
all this!
Thanks
Daniel
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Dec 27, 2006 2:25 am    Post subject: Re: Help with TDrawGrid! Reply with quote



"Mr B" <mrb_16 (AT) hotmail (DOT) com> wrote in message
news:1166871745.068748.77960 (AT) 73g2000cwn (DOT) googlegroups.com...

Quote:
I've been trying for sometime to get the TDrawGrid to work but havn't
found anycode which will let me do something like this, basically I want
an underlying grid of values which determine the creature or element
graphically.

You need to maintain a list of data for each cell so that the OnDrawCell
event knows what to draw. Since you are not using TStringGrid, you will
have to maintain that data in a separate list.

Quote:
I have found some code on the Internet that has shown me how to use
graphics on a TStringGrid, (this same code doesn't work with a
TDrawGrid as it accesses a property "Cells" which TDrawGrid doesn't
have)

The same principles apply to TDrawGrid as well. All that matters is that
the necessary data needs to be stored somewhere that the OnDrawCell event
handler can get to when needed. For example:

class TForm1 : public TForm
{
__published:
void __fastcall ToggleButtonClick(TObject *Sender);
private:
bool GridData[10][10]; // assuming a 10x10 grid as an example
};

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if( GridData[ACol][ARow] )
DrawGrid1->Canvas->Draw(Rect.Left, Rect.Top, GreenLightBmp);
else
DrawGrid1->Canvas->Draw(Rect.Left, Rect.Top, BlankBmp);
}

void __fastcall TForm1::ToggleButtonClick(TObject *Sender)
{
int col = DrawGrid1->Col;
int row = DrawGrid1->Row;
if( (col > -1) && (row > -1) )
{
GridData[col][row] = !GridData[col][row]
DrawGrid1->Invalidate();
}
}


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) 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.