Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Dark_Icer

C++ Builder 5 Drawing an image on a TDrawGrid

This topic is 5574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Below is a simple code to display 32x32 pixel Tilesets in a draw grid that displays 6 colums and 32 rows of tiles. There is another DrawGrid that you can use to edit a map that is of size 20x15 tilesets. I finally figured out how to display the image but the problem is in the loop and it just doesent display correctly. I''ve got the map file from this tileset zip file from this site: [url]http://www.vizzed.com/RPGMaker95/MapShop.htm[/url]
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "most.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DrawGrid1Click(TObject *Sender)
{
TRect DestRect, SourceRect;
DestRect = DrawGrid1->CellRect(DrawGrid1->Col,DrawGrid1->Row);
SourceRect = DrawGrid2->CellRect(DrawGrid2->Col,DrawGrid2->Row);
DrawGrid1->Canvas->CopyMode= cmSrcCopy;
DrawGrid1->Canvas->CopyRect(DestRect,DrawGrid2->Canvas,SourceRect);
DrawGrid1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawGrid2DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{

int tilex=0,tiley=0,celx=0,cely=0;
TRect DestRect, SourceRect;

DestRect = DrawGrid2->CellRect(0,0);
SourceRect.Right=32;
SourceRect.Bottom=32;

Graphics::TBitmap *TileSet = new Graphics::TBitmap();
TileSet->LoadFromFile("desert.bmp");

DrawGrid2->Canvas->CopyMode= cmSrcCopy;

for(int i=0;i<6;i++)
    {
    if (i==6) break;
    SourceRect.Top=tiley;
    for(int j=0;j<32;j++)
        {
        SourceRect.Left=tilex;
        DestRect = DrawGrid2->CellRect(cely,celx);
        DrawGrid2->Canvas->CopyRect(DestRect, TileSet->Canvas, SourceRect);
        tilex+=32;//DrawGrid2->Canvas-
        celx++;
        }
    celx=0;
    tiley+=32;
    cely++;
    }
delete TileSet;
DrawGrid2->Invalidate();

    
}
//---------------------------------------------------------------------------
 
Just because some one is new to something does not me that they shoud not try to do something big with it, after all trail and error is what build experence and experence built is experence gain.

Share this post


Link to post
Share on other sites
Advertisement
There's a 'turbo' forum just for Builder and Delphi (and the VCL). You might have better luck there.

[edited by - Magmai Kai Holmlor on August 17, 2003 2:18:36 AM]

Share this post


Link to post
Share on other sites
I didn''t know that but seeing that very little people post there, and most post are about Delphi, odds maybe higer here.

Just because some one is new to something does not me that they shoud not try to do something big with it, after all trail and error is what build experence and experence built is experence gain.

Share this post


Link to post
Share on other sites
I''ve updated the code a bit here

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "most.h"
bool dtile;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
dtile=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::DrawGrid2DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{

int tilex=0,tiley=0,celx=0,cely=0;
TRect DestRect, SourceRect;

DestRect = DrawGrid2->CellRect(0,0);
SourceRect.Right=32;
SourceRect.Bottom=32;

DrawGrid2->Canvas->CopyMode= cmSrcCopy;

if(dtile==true){
Graphics::TBitmap *TileSet = new Graphics::TBitmap();
TileSet->LoadFromFile("desert.bmp");
ImageList1->GetBitmap(0,TileSet);
for(int i=0;i<6;i++)
{
SourceRect.Top=tiley;
for(int j=0;j<32;j++)
{
SourceRect.Left=tilex;
DestRect = DrawGrid2->CellRect(cely,celx);
DrawGrid2->Canvas->/*Brush*/CopyRect(DestRect, TileSet->Canvas, SourceRect/*,0xff00ff*/);
tilex+=32;
celx++;
}
celx=0;
tiley+=32;
cely++;
}
delete TileSet;
dtile=false;
}
//DrawGrid2->Invalidate();


}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawGrid2SelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
dtile=true;
DrawGrid2->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawGrid1SelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
dtile=true;
DrawGrid2->Invalidate();
TRect DestRect, SourceRect;
DestRect = DrawGrid1->CellRect(DrawGrid1->Col,DrawGrid1->Row);
SourceRect = DrawGrid2->CellRect(DrawGrid2->Col,DrawGrid2->Row);
DrawGrid1->Canvas->CopyMode= cmSrcCopy;
DrawGrid1->Canvas->CopyRect(DestRect,DrawGrid2->Canvas,SourceRect);
DrawGrid1->Invalidate();
}
//---------------------------------------------------------------------------


and yet the problem now is that the first 32x32 clip of the bitmap is placed into the right grid but the other grid get all messed up.

Whoa I think I may have another solution I think that each cell is drawn at one colum at a time I''m not sure though.

Just because some one is new to something does not me that they shoud not try to do something big with it, after all trail and error is what build experence and experence built is experence gain.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!