Je suis actuellement sur un projet dont une parti necessite un petit editeur de map en 2D. Je prend un bitmap que je "découpe" en Tile de 32*32 (en fait je me contente de spliiter le bitmap pour n'afficher que la partie qui m'interesse). Si dans chaque "case" c'est bien le bon bitmap qui apparait il se retrouve la tete en bas.
Je pense que cela vient du fait que dans la vue que j'utilise le point d'origine des coordonnées est en haut a gauche alors que celui du bitmap est en bas à gauche. Bon en tout cas voila le code responsable de ca si jamais quelqu'un a une idée de ce qui peut clocher...
//la methode OnDraw de ma view
void
CMapCreateView::OnDraw(CDC* pDC)
{
CSquaresDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPoint pos=CScrollView::GetDeviceScrollPosition();
OnPrepareDC (pDC);
pDC->DPtoLP (&pos);
CRect Rect ;
GetClientRect(&Rect) ;
pDC->SetMapMode (MM_LOENGLISH);
CRect rect;
pDC->GetClipBox (&rect);
for
(int i=0; i<largeur; i++)
{
for
(int j=0; j<longueur; j++)
{
int
x1 = (i * 32) + 32;
int
y2 = (j*(-32))-64;
if
(y2>(rect.BottomRight().y-32) && y2<(rect.TopLeft().y+32))
{
pDoc->m_clrCurrentBitmap.DrawPartOfBitmap(pDC,x1,y2,i+1,j+1);
}
TabEdit[i][j].x=i+1;
TabEdit[i][j].y=j+1;
}
}
[..]
}
//Et voila ma méthode DrawPartOfBitmap inspiré d'un code tiré du site
BOOL CMaskedBitmap::DrawPartOfBitmap(CDC *dc,int xpos,int ypos,int x, int y)
{
CRect rect;
dc->GetClipBox (&rect);
_xparts = 8;
_yparts = 160;
if
(x <= 0 || x > _xparts || y>_yparts || y <= 0)
return
false;
_filename="Tiles.bmp";
CString szFilename(_filename);
HBITMAP hBmp = (HBITMAP)::LoadImageA(NULL,szFilename,
IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
CBitmap bmp;
bmp.Attach(hBmp);
CDC bmDC;
bmDC.CreateCompatibleDC(dc);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
int
xwidth, ywidth;
xwidth = bi.bmWidth/_xparts;
ywidth = bi.bmHeight/_yparts;
dc->BitBlt(xpos,ypos,xwidth,ywidth,&bmDC,(x-1)*xwidth,(y-1)*ywidth,SRCCOPY);
return
true;
}