C++ Builder 5 Drawing an image on a TDrawGrid

Started by
2 comments, last by Dark_Icer 20 years, 8 months ago
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: http://www.vizzed.com/RPGMaker95/MapShop.htm
//---------------------------------------------------------------------------

#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.
Signed - Tne Nevermelting Icer - Dark Icer
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]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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.
Signed - Tne Nevermelting Icer - Dark Icer
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.
Signed - Tne Nevermelting Icer - Dark Icer

This topic is closed to new replies.

Advertisement