J
JoeC
I am still working in my maze game and I am making improvments. The
main sticking problem that I have is passing my graphic library. This
probram uses windows apis but my question has nothing to do with those.
So please dont jump on me for that. I am making this graphics library
and my bitmap data is stored in an array. This library works some time
and when I have to use the copy constructor it dosn't seem to work. I
did my best to use the rule of three when using this object. This
object seems to work better if I use dynmaic memory. Could I get some
advice in this object to make it work bette.
In header:
graphic gr;
In Constructor:
gr.SetGr(pgr);
The Graphic Object:
class graphic{
int btmap;
int lr,ud; //Diminsion (size) of the graphic
HBITMAP hbitmap;
HDC hdc, hdcmem;
BYTE gData[32];
void gCopy(BYTE in[], BYTE out[]);
BYTE dOut(const int n) const {return gData[n];}
public:
graphic();
graphic(BYTE c[]);
graphic(const graphic&);
graphic& operator = (const graphic&);
void SetGr(BYTE c[]);
void display(HWND, const int, const int);
};
void graphic::gCopy(BYTE in[], BYTE out[]){
for(int lp = 0; lp != 32; lp++){
out[lp] = in[lp];
}
}
graphic::graphic(){
lr = ud = 16;
BYTE c[32] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};
gCopy(c, gData);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
#include"graphic.h"
graphic::graphic(BYTE c[]){
//constructor need an array 32 int or hex elements to create graphic
ud = lr = 16; // size in bits
gCopy(c, gData);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
//MessageBox(NULL, "Graphic Created" , "Error!", MB_OK);
}
graphic::graphic(const graphic& gr){
lr = ud = 16;
for(int lp = 0; lp != 32; lp++){
gData[lp] = gr.dOut(lp);
}
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
graphic& graphic:
perator = (const graphic& gr){
lr = ud = 16;
if(&gr != this){
for(int lp = 0; lp != 32; lp++){
gData[lp] = gr.dOut(lp);
}
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
return *this;
}
void graphic::SetGr(BYTE c[]){
lr = ud = 16;
//Changing the graphic
gCopy(c, gData);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
void graphic::display(HWND hwnd, const int x, const int y){
//prints the graphic on the screen
hdc = GetDC(hwnd);
hdcmem = CreateCompatibleDC(hdc);
SelectObject(hdcmem, hbitmap);
BitBlt(hdc, x, y, ud, lr, hdcmem, 0, 0, SRCCOPY);
DeleteDC(hdcmem);
ReleaseDC(hwnd, hdc);
}
main sticking problem that I have is passing my graphic library. This
probram uses windows apis but my question has nothing to do with those.
So please dont jump on me for that. I am making this graphics library
and my bitmap data is stored in an array. This library works some time
and when I have to use the copy constructor it dosn't seem to work. I
did my best to use the rule of three when using this object. This
object seems to work better if I use dynmaic memory. Could I get some
advice in this object to make it work bette.
In header:
graphic gr;
In Constructor:
gr.SetGr(pgr);
The Graphic Object:
class graphic{
int btmap;
int lr,ud; //Diminsion (size) of the graphic
HBITMAP hbitmap;
HDC hdc, hdcmem;
BYTE gData[32];
void gCopy(BYTE in[], BYTE out[]);
BYTE dOut(const int n) const {return gData[n];}
public:
graphic();
graphic(BYTE c[]);
graphic(const graphic&);
graphic& operator = (const graphic&);
void SetGr(BYTE c[]);
void display(HWND, const int, const int);
};
void graphic::gCopy(BYTE in[], BYTE out[]){
for(int lp = 0; lp != 32; lp++){
out[lp] = in[lp];
}
}
graphic::graphic(){
lr = ud = 16;
BYTE c[32] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};
gCopy(c, gData);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
#include"graphic.h"
graphic::graphic(BYTE c[]){
//constructor need an array 32 int or hex elements to create graphic
ud = lr = 16; // size in bits
gCopy(c, gData);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
//MessageBox(NULL, "Graphic Created" , "Error!", MB_OK);
}
graphic::graphic(const graphic& gr){
lr = ud = 16;
for(int lp = 0; lp != 32; lp++){
gData[lp] = gr.dOut(lp);
}
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
graphic& graphic:
lr = ud = 16;
if(&gr != this){
for(int lp = 0; lp != 32; lp++){
gData[lp] = gr.dOut(lp);
}
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
return *this;
}
void graphic::SetGr(BYTE c[]){
lr = ud = 16;
//Changing the graphic
gCopy(c, gData);
BITMAP bitmap = {0,ud,lr,2,1,1};
bitmap.bmBits = gData;
hbitmap = CreateBitmapIndirect(&bitmap);
}
void graphic::display(HWND hwnd, const int x, const int y){
//prints the graphic on the screen
hdc = GetDC(hwnd);
hdcmem = CreateCompatibleDC(hdc);
SelectObject(hdcmem, hbitmap);
BitBlt(hdc, x, y, ud, lr, hdcmem, 0, 0, SRCCOPY);
DeleteDC(hdcmem);
ReleaseDC(hwnd, hdc);
}