#include"graphele.h" #include #include #ifdef XWIN //for X-Win only void GraphElement::draw(int x,int y) { //draw graphical element XCopyArea(display,pixmap,window,gc,0,0,UNITWIDTH,UNITHEIGHT,TEXTSPACE+UNITWIDTH*x,UNITWIDTH*y); //copy pixmap to window } void GraphElement::consfn() { //function to help with constructing UserInterface* u=UserInterface::instance(); //get UserInterface instance display=u->getdisplay(); //get pointer to display connection window=u->getwindow(); //get window screen=u->getscreen(); //get screen gc=u->getgc(); //get graphic context int wx,wy; //dummies Window root; //dummy unsigned int wwidth,wheight,wdepth,wborder,width,height,status; //dummies, except wdepth XGetGeometry(display,window,&root,&wx,&wy,&wwidth,&wheight, &wborder,&wdepth); //get X data depth=wdepth; //setting depth } GraphElement::~GraphElement(void) { //destructor XFreePixmap(display,pixmap); //freeing pixmap } //create pixmap void GraphElement::pix(Pixmap *p,char map[],unsigned long myforeground, unsigned long mybackground) { *p=XCreatePixmapFromBitmapData(display,window,map,UNITWIDTH,UNITHEIGHT, myforeground,mybackground,depth); } #elif defined MSWIN //for MS-Win only void GraphElement::draw(int x,int y) { //draw graphical element HDC hdcDest; //destination device context HBITMAP hbmpOld; //previously selected bitmap hdcDest=GetDC(hwnd); //select device context hbmpOld=SelectObject(hdcMemory,pixmap); //select our pixmap BitBlt(hdcDest,TEXTSPACE+UNITWIDTH*x,UNITHEIGHT*y,UNITWIDTH,UNITHEIGHT,hdcMemory,0,0, SRCCOPY); //copy pixmap to window SelectObject(hdcMemory, hbmpOld); //select back previous bitmap ReleaseDC(hwnd,hdcDest); //release device context } void GraphElement::consfn() { //function to help with constructing UserInterface* u=UserInterface::instance(); //get userinterface instance HDC hdcDest; //destination device context hwnd=u->gethwnd(); //get handle to window hdcMemory = u->gethdcmem(); //get and set device context memory //cbBits=16; } GraphElement::~GraphElement(void) { //destructor DeleteObject(pixmap); //delete the pixmap } void GraphElement::pix(HBITMAP *p,short map[],COLOURNAME foreground, COLOURNAME background) { //create pixmap HDC hdcDest; //destination device context HDC hDC; //device context HDC hMemoryDC; //memory device context HBITMAP hBitmap; //current bitmap HBITMAP hOldBitmap; //previous bitmap HBRUSH hForeBrush; //foreground colour brush HBRUSH hBackBrush; //background colour brush HBRUSH hOldBrush; //previous brush hDC = GetDC(hwnd); //get device context for window hMemoryDC = CreateCompatibleDC(hDC);//create a compatible device context hBitmap = CreateCompatibleBitmap(hDC, UNITWIDTH, UNITHEIGHT); //create a compatible bitmap hOldBitmap = SelectObject(hMemoryDC, hBitmap); //select our bitmap hForeBrush = CreateSolidBrush(foreground); //create fore brush hBackBrush = CreateSolidBrush(background); //create back brush hOldBrush = SelectObject(hMemoryDC, hForeBrush); //select fore brush PatBlt(hMemoryDC, 0, 0, UNITWIDTH,UNITHEIGHT, BLACKNESS); //set pixmap to all blackness int x,y, //counters bitno=0; //bit number short* mapptr=map; //initial source counter short byte=*mapptr; //initial content for(y=0; y