/* * This Software is the original work of Daniel TUNG * This Software is submitted in partial fulfillment of the * requirements for the degree of BCSE. * Dept. Computer Science, Monash University 2000 * * Copyright (c) 2000 beetung@cs.monash.edu.au * beetung@geocities.com * */ #include #include #include "xwin.h" #include "timer.h" #include "fastbuf.h" #include "autoline.h" #include "streamer.h" XColor Xwin::colorList[]; int Xwin::depth, Xwin::blackColor, Xwin::whiteColor; /// /// The following functions blitz out the appropriate XImage onto the screen /// straight away, using XShm routines! /// // ------------------------------------ inline void Xwin::drawXShm(const int& i) const { // ------------------------------------ XImage * xm = (XImage*&) *simBuffer[i]; XShmPutImage(dpy,w,gc, xm ,0,0,0,0,FRAME_SIZE_X, FRAME_SIZE_Y,false); XFlush(dpy); } // ------------------------------------ void Xwin::drawXShm(Fastbuf* f) { // ------------------------------------ XImage * xm = (XImage*)*f; XShmPutImage(dpy,w,gc, xm ,0,0,0,0,FRAME_SIZE_X, FRAME_SIZE_Y,false); XFlush(dpy); } // ------------------------------------ void Xwin::drawXShm(XImage*& ximPtr) { // ------------------------------------ XShmPutImage(dpy,w,gc,ximPtr,0,0,0,0,FRAME_SIZE_X, FRAME_SIZE_Y,false); XFlush(dpy); } // ------------------------------------ void Xwin::drawBaseFrame(void) { // ------------------------------------ // if we are drawing nodes on screen, dont wreck the screen!! // // if (isSettingNode) return; XImage * xm = (XImage*)*baseFrame; XShmPutImage(dpy,w,gc, xm ,0,0,0,0,FRAME_SIZE_X, FRAME_SIZE_Y,false); drawString("Manual Drive", 280, 10); XFlush(dpy); } //------------------------------------------------------------------- // standard X method, SLOW! // // XPutImage(dpy,w,gc,fastb->getXImageAddress(),0,0,0,0, // FRAME_SIZE_X, FRAME_SIZE_Y); //------------------------------------------------------------------- // ------------------------------------ void Xwin::drawX(XImage*& ximPtr) { // ------------------------------------ XPutImage(dpy,w,gc,ximPtr,0,0,0,0,FRAME_SIZE_X, FRAME_SIZE_Y); XFlush(dpy); } /// /// set the baseFrame to initialize nodes on, would change /// on every frame update, but basically only toggles between /// 2 buffers as encapsulated in our class BttvCapture /// //------------------------------------ void Xwin::setBaseFrame (Fastbuf * f) { //------------------------------------ // if (isSettingNode) return; baseFrame = f; } /// /// set the simulation buffer to the read in file data. /// in my case, I captured 15 frames and simulate it for /// testing out my track identification algorithm /// /// /// the 1st one is for backward compatibility reason //------------------------------------ void Xwin::setFastbuf (Fastbuf * fb) { setSimBuf(fb); } //------------------------------------ void Xwin::setSimBuf (Fastbuf * fb) { //------------------------------------ simBuffer[frameCount] = fb; frameCount++; ready2sim=true; } //// //// What? //// // ------------------------------------ void Xwin::getCriticalRegion() { // ------------------------------------ cout << "getCritialRegion()" << endl; return; } extern "C" { int XShmGetEventBase(Display*); }; //// //// simulate a moving vehicle by sequentially blitzg a series of pre-XSHM //// allocated images //// // ------------------------------------ void* Xwin::vdoSim (void) { // ------------------------------------ this->drawString("Simulating track identification -click to begin or 3secs"); // wait4Click(); int j=frameID; int CompletionType =false; Timer t; t.start(); /// /// stop until 1000 images are drawn /// while (j<(30+frameID)) { // cout << "before calling drawXShm - CompletionType : " << CompletionType << endl; drawXShm ( *simBuffer[++j%frameCount] ); // 0-4 // // has XShm Draw completed? // CompletionType = XShmGetEventBase (dpy) ; //+ ShmCompletion; // cout << " after calling drawXShm - CompletionType : " << CompletionType << endl; if (!CompletionType) { cerr << "waiting for XShmCompletion Signal " << endl; while(!CompletionType) ; } CompletionType=false ; } t.stop(); cerr<< "Timer("<drawString("Simulating track identification "); // wait4Click(); Timer t; int j =frameID; int center = -1; bool noHalt =false; t.start(); /// /// Set the baseframe for nodes to share /// /// /// stop until 1000 images are drawn /// while ( j<(30+frameID) ) { const int NO_SIZE_USED = 0; /// /// Copy the the next image sequence into the baseFrame and /// set that buffer as the baseFrame for nodes to swim around /// --- shouldnt do it this way! inefficient!!!! baseFrame->mXCopy(*simBuffer[j%frameCount],NO_SIZE_USED); baseFrame->setAsBaseFrame(); t.reset(); t.start(); // swim and draw on buffer space // baseFrame->swimNodes(); // baseFrame->drawNodes(); // center= baseFrame->getNodeCenter(); // get the center X position of all nodes markPoint( 120, center , 0xff0000); drawXShm ( *baseFrame ); // 0-4 XDrawLine(dpy, w, gc, 0, 0, 150, 180); t.stop(); cerr<< "Nodes Tracked (" << nodeCount << " ) time: "<< t << endl; /// initially halt on XNextEvent(...) /// if (! noHalt) { // not noHalt, then halt/block here till click! swimLoop: XNextEvent(dpy, &e); // this one would block & sleep until an event // should we halt anymore further? or just blast all 30 frames out? // if (e.type !=ButtonPress) goto swimLoop; else if (e.xbutton.button ==3) noHalt=true; } j++; } return 0; } //// //// simulate the autonode tracking ability on our //// vdoSim() movie sequence //// // ------------------------------------ void* Xwin::vdoSimNodeSwimLock () { // ------------------------------------ Timer t; int j =frameID; t.start(); /// /// Set the baseframe for nodes to share /// /// /// stop until 1000 images are drawn /// while ( 1 ) { const int NO_SIZE_USED = 0; /// /// Copy the the next image sequence into the baseFrame and /// set that buffer as the baseFrame for nodes to swim around /// --- shouldnt do it this way! inefficient!!!! baseFrame->mXCopy(*simBuffer[j%frameCount],NO_SIZE_USED); baseFrame->setAsBaseFrame(); t.reset(); t.start(); // swim and draw on buffer space // baseFrame->swimNodes(); // baseFrame->drawNodes(); // drawXShm( *baseFrame ); // 0-4 drawString( "Simulating track ... ",188,10 ); XDrawLine( dpy, w, gc, 0, 0, 150, 180); t.stop(); Timer l(0.1); l.block(); cerr<< "Nodes Tracked (" << nodeCount << " ) time: "<< t << endl; j++; } return 0; } //// //// Destructor for Xwin() //// //----------------------------- Xwin::~Xwin() { //----------------------------- cerr << "~Xwin() Dtor called " << endl; if (ready2sim) delete baseFrame; terminate_X11(); } //* Function: Murder the X Server //* //* ---------------------------- void Xwin::terminate_X11 () { //* ---------------------------- cout <<".Killing X server! \n"; XFreeGC (dpy, gc) ; // free gc XFreeCursor (dpy,cursor) ; // free cursor too! XCloseDisplay (dpy); return ; } //// //// Default Constructor for Xwin() //// // Xwin::Xwin(string wn ="( ) ECS4397 BCSE Thesis (CCC) 2000") // : Thread(this,this->serveEvent),ready2sim(false) { //----------------------------- Xwin::Xwin(string wn ="( ) ECS4397 BCSE Thesis (CCC) 2000") : ready2sim(false) , isAlive(true),isStopServe(false), frameCount(0), kbhitArrows(false),isSettingNode(false), baseFrame(0) { //----------------------------- /// bee Node /// bee Node nodeCount = frameID = 0; wn[1] = 0x30 + winID_total(); // as ASCII char on title bar init_X11( wn ); } //// //// Setup X Window and initialize its params //// // ------------------------------------ void Xwin::init_X11(string &wn) { // ------------------------------------ // // Do we have X at all? // if ((dpy = XOpenDisplay(NULL)) ==NULL) { cerr << "ERROR: Cannot open the bloody X display!!\n"; exit(-1); } // for text output cursor position strPosX =2; strPosY =1; // // Set Window Unique ID // winID = ++winID_total(); // // Once only inits // execute_once(); //* ================================= //* Create the Main window attributes, but not projecting it yet! //* ================================= // Initializing General X-Win Stuff... // We want to get MapNotify events char *winName = &wn[0]; char iconName[] ={"beetung@geocities.com"}; int xloc =((winID-1)%2)*(SCREEN_COLUMN_PIXEL+5)+5; // x int yloc =((winID-1)/2)*(SCREEN_ROW_PIXEL+25)+5; // y w =XCreateSimpleWindow (dpy, DefaultRootWindow(dpy), xloc, // x yloc, // y SCREEN_COLUMN_PIXEL, SCREEN_ROW_PIXEL, // width,height 0, // border width whiteColor, blackColor); XSelectInput(dpy, w, (ExposureMask| ButtonPressMask | // ButtonReleaseMask| // FocusChangeMask| // PointerMotionMask| KeyPressMask | StructureNotifyMask )); /// /// Init what? /// init_cursor(); /* size_hints.x =160*winID; size_hints.y =160; size_hints.width =SCREEN_COLUMN_PIXEL; size_hints.height =SCREEN_ROW_PIXEL; size_hints.base_width =SCREEN_COLUMN_PIXEL; size_hints.base_height =SCREEN_ROW_PIXEL; */ XSizeHints size_hints; size_hints.flags =PPosition | PSize | USPosition |USSize; // // Which flag have I stuffed up? // // set window name and all other hints XSetStandardProperties (dpy, w, winName,iconName ,None, \ 0,0,&size_hints ); /* XSetWMNormalHints(dpy, w, &size_hints); */ //* ============================ //* Create a Graphics Context //* ============================ // Wait for the MapNotify event gc = XCreateGC(dpy, w, 0, NULL); // reset to my favorites font font =XLoadFont(dpy,"-*-helvetica-*-*-*-*-16-*-*-*-*-*-*-*"); // font =XLoadFont(dpy,"-*-terminal-*-*-*-*-16-*-*-*-*-*-*-*"); // font =XLoadFont(dpy,"-dec-*-*-*-*-*-17-*-*-*-*-*-iso8859-*"); // font =XLoadFont(dpy,"-b&h-*-*-*-*-*-17-*-*-*-*-*-iso8859-*"); XSetFont(this->dpy,this->gc,font); //* Ready to rock & row --> Note: Window not Drawn yet!!!! // if (gc == NULL ) realize_window(); } /// /// stuff that only need to be initialized once... /// //------------------------------- void Xwin::execute_once (void) { //------------------------------- if (winID_total() != 1) return; /// /// I dont think we need to do this... /// /* if (XInitThreads() != 0) cout << " XInitThreads() ...enabled" << endl; */ /// /// Color Depth OK ? /// Xwin::depth =DefaultDepth(dpy,DefaultScreen(dpy)); if (depth < 24) { // Personally, I think we should quit() here!!! // since I am not planning to implement any quantized // color map here in the near future! cout << "ERROR: This implementation requires 24/32bpp X server for Full color!!!!"<< endl << " If running on linux, initiate X by >startx -- -bpp 24" << endl << "ERROR: Color depth (" << depth << ") not supported!!!" << endl << "otherwise, start X with the following params " << endl << " > startx -- -bpp 32 " << endl; exit (-1); } if (winID ==0) { cout << ".Initializing X window (" << winID << ")" " .Color Depth ("< SCREEN_ROW_PIXEL) { // next row position is off screen? if(ready2sim) drawXShm( frameID ); // draw next frame else XClearWindow(dpy,w); strPosY=16; // reset to zero } //XSetForeground(dpy,gc,whiteColor ); // overlay enabled! // cout << "msg: " << msg << endl; XDrawString(dpy,w,gc,strPosX,strPosY,msg,strlen(msg)); // With background covering... Not overlay!!! // XDrawImageString(dpy,w,gc,strPosX,strPosY,msg,strlen(msg)); strPosY +=18; // shift y position XFlush(dpy); } //* ---------------------------- void Xwin::drawString (const char *msg, int yy, int xx) { //* ---------------------------- if (xx < 0 || yy < 0) { cerr << "ERROR : String position less than 0 " << endl; return; } //XSetForeground(dpy,gc,whiteColor ); // overlay enabled! XDrawString(dpy,w,gc,xx,yy,msg,strlen(msg)); // With background covering... Not overlay!!! // XDrawImageString(dpy,w,gc,strPosX,strPosY,msg,strlen(msg)); XFlush(dpy); } //* //* Function: initialize the cursor shape //* //---------------------------- void Xwin::init_cursor () { //---------------------------- #define cursor_width 48 #define cursor_height 48 #define cursor_x_hot 0 #define cursor_y_hot 0 static unsigned char cursor_bits[] = { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x03, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x07, 0xf0, 0xfd, 0xbf, 0xff, 0xff, 0x3f, 0xf0, 0xfd, 0xbf, 0xff, 0xff, 0x3f, 0xe0, 0x39, 0x13, 0x95, 0xfb, 0x1f, 0xe0, 0x55, 0xb5, 0x55, 0xf5, 0x0f, 0xc0, 0x95, 0xb9, 0x55, 0xf5, 0x03, 0xc0, 0x31, 0x33, 0x53, 0xfb, 0x01, 0xc0, 0xff, 0xff, 0xff, 0xf7, 0x00, 0x80, 0xff, 0xff, 0xff, 0x3b, 0x00, 0x80, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x80, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x9c, 0xff, 0x03, 0x00, 0x00, 0x7f, 0x6b, 0xff, 0x01, 0x00, 0x00, 0x7e, 0x6b, 0xff, 0x01, 0x00, 0x00, 0xfe, 0x18, 0xff, 0x07, 0x00, 0x00, 0xfe, 0x7b, 0xff, 0x0f, 0x00, 0x00, 0xfc, 0x7b, 0xff, 0x1f, 0x00, 0x00, 0xfc, 0x9c, 0xff, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x07, 0x00, 0xf0, 0xff, 0xf9, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0xf1, 0xff, 0x1f, 0x00, 0xf0, 0xff, 0xf0, 0xff, 0x3f, 0x00, 0xe0, 0xff, 0xe0, 0xff, 0x3f, 0x00, 0xe0, 0x7f, 0xc0, 0xff, 0x7f, 0x00, 0xc0, 0x7f, 0x80, 0xff, 0x7f, 0x00, 0xc0, 0x3f, 0x00, 0xff, 0x7f, 0x00, 0xc0, 0x3f, 0x00, 0xff, 0x7f, 0x00, 0x80, 0x1f, 0x00, 0xfe, 0x7f, 0x00, 0x80, 0x1f, 0x00, 0xfc, 0x7f, 0x00, 0x80, 0x0f, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0x0f, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; #define beetung_width 48 #define beetung_height 48 static unsigned char beetung_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x60, 0xcc, 0xae, 0x46, 0x00, 0x00, 0xa0, 0xaa, 0xa4, 0xaa, 0x00, 0x00, 0xa0, 0x66, 0xa4, 0xaa, 0x00, 0x00, 0xe0, 0xcc, 0xcc, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40}; Pixmap shape ; Pixmap mask ; shape =XCreatePixmapFromBitmapData( dpy, w,(char *)cursor_bits, cursor_width, cursor_height, 1,0,1); mask =XCreatePixmapFromBitmapData( dpy, w,(char *)beetung_bits, beetung_width, beetung_height, 1,0,1); XColor *red = Xwin::colorList; cursor =XCreatePixmapCursor (dpy, shape,shape, red,red, cursor_x_hot, cursor_y_hot); XDefineCursor(dpy,w,cursor); XFreePixmap (dpy,shape); XFreePixmap (dpy,mask); /* cursor = XCreateFontCursor(dpy,10); XParseColor (dpy, DefaultColormap(dpy,DefaultScreen(dpy)), "green", &black); XRecolorCursor(dpy, cursor, &red, &black ); */ } /* static int color_loop ; static const char *color_list[] = { "red","green","yellow","blue","brown","grey","gold","purple","white" }; */ static const char *error_msg[] ={ "Test 1: asshole approaching", " Mesg 2: Warning: no food left!!! ", "Test 3: No default values ", "Final 4: Hello world!! "}; static int error_loop ; static int iCountfg ; static int iCountbg ; //// //// This function serves an X window Event //// //-------------------------- void* Xwin::serveEvent() { //-------------------------- isStopServe = false; while (1) { // we will block until an event arrives at this point!!!! // should not use non-block XCheckWindowEvent() if (!isStopServe) { XNextEvent(dpy, &e); // this one would block & sleep until an event // pthread_testcancel(); // should we die rather? // ///* :::::::::::::::::::::::::::::::::: /// Expose screen, so do something will ya! ///* :::::::::::::::::::::::::::::::::: // if (e.type == Expose) { strPosY=16; drawString("Screen not redrawn!"); ///* :::::::::::::::::::::::::::::::::: /// A Button Click Event! ///* :::::::::::::::::::::::::::::::::: /// } else if ((e.type ==ButtonPress) && (e.xbutton.button>0)) { switch (e.xbutton.button) { /// Left Click case 1: XSetForeground(dpy,gc,Xwin::colorList[++iCountfg%Xwin::colorMod].pixel); drawString((char *)error_msg[++error_loop%4]); this->drawString("Simulating Application..."); if (ready2sim) // for simulation only! if (nodeCount) { // if have nodes to apply track id on, /* Thread ee(this,&vdoSimNodeSwimLock,"vdoSimNodeSwimLock"); ee(); */ /* vdoSimNodeSwimLock(); ready2sim = false; // so we cant start thread again! */ vdoSimNodeSwim(); } else // else , just emulate a movie sequence vdoSim(); // simulate movement break; /// Mid Click case 2: XSetBackground(dpy,gc,Xwin::colorList[iCountbg++%Xwin::colorMod].pixel); if (ready2sim) { frameID = ++frameID %frameCount; drawXShm(*simBuffer[frameID%frameCount]); // draw next frame drawString((char *)error_msg[++error_loop%4]); } break; /// Right Click case 3: serveExit(); // set some exit conditions return 0; // return... /// 10 buttons mice? default: ; cout << " button press not between 1-3\n"; } // switch() ///* :::::::::::::::::::::::::::::::::: /// A Key Event! ///* :::::::::::::::::::::::::::::::::: /// } else if (e.type ==KeyPress ) { int g = XLookupKeysym(&e.xkey, 1); cout << "XLookupKeySym : " << g << endl; cout << "Key code: " << e.xkey.keycode << endl; int k= e.xkey.keycode; // // 'm' pressed //---------- if(g ==77) { //---------- if (ready2sim) drawGrid(); // // 'q' pressed //---------- } else if (g==81) { // 'q' //---------- serveQLock( ); // // '' pressed //---------- } else if ( g==65307 || k==9) { // '' serveExit(); return 0; // '' pressed //---------- } else if ( k==98 ||k==100 ||k==102|| k==104) { kbhitArrows = true; } // matching keys } // if KeyPress,MousePress // else // cout << " Xwin::serveEvent(...) an event detected!!! " << endl; } else { // if (isStopServe) Timer t(2); t.block(); } } // while (1) return 0; }// serveEvent() /// /// serve the Q lock, ie: press 'Q' to lock, and /// press again to unlock. For initiating autonodes /// //------------------------------- int Xwin::serveKey( void ) { //------------------------------- while (1) { // consume this event just happened // shouldnt we pass it away somehow if its not handled? XNextEvent(dpy,&e); ///* :::::::::::::::::::::::::::::::::: /// A Button Click Event! ///* :::::::::::::::::::::::::::::::::: /// if (e.type ==ButtonPress && e.xbutton.button ==3) { return 0; // return... /// :::::::::::::::: /// A Key Press /// :::::::::::::::: /// } else if (e.type ==KeyPress ) { return e.xkey.keycode; } // if (e.type ==KeyPress, ButtonPress) } // while(1) } /// /// /// //------------------------------- void Xwin::serveStop(void) { isStopServe = true; } void Xwin::serveStart(void) { isStopServe = false; kbhitArrows = false;} //------------------------------- void Xwin::serveExit(void) { //------------------------------- isAlive = false; // about to die cout << " isAlive == false now " << endl; XSetForeground(dpy,gc,Xwin::colorList[0].pixel); this->drawString("Terminating Screen..."); XUnmapWindow(dpy,w); for(;;) { // sure its unmapped XNextEvent(dpy, &e); if (e.type == UnmapNotify) break; } } /// /// serve the Q lock, ie: press 'Q' to lock, and /// press again to unlock. For initiating autonodes /// //------------------------------- void Xwin::serveQLock( void ) { //------------------------------- cout << " - Q lock enabled, Press 'q' again to unlock..." << endl; isSettingNode = true; cerr << " isSettingNode == true" <mXCopy(*simBuffer[frameID],NO_SIZE_USED); } } /// /// Initialize an autonode/autoline/automesh, and attach that new /// link-list node to the static nodelist on class Fastbuf /// //--------------------------- void Xwin::initNode(void) { //--------------------------- //// //// We call on baseFrame here to initialize a node and attach the //// new node to it. //// BaseNode *cnode= baseFrame->addNode(e.xbutton.y, e.xbutton.x); baseFrame->swimNodes(cnode); // allow nodes to swim baseFrame->drawNodes(cnode); // draw onto the buffer space drawXShm( *baseFrame ); nodeCount++; // markPoint(e.xbutton.y,e.xbutton.x,frameID); return; } //// //// Draw a grid on the _simulated_ image plane //// // ------------------------------------ void Xwin::drawGrid () { // ------------------------------------ int *idata =*simBuffer[frameID]; // on simBuffer, not baseFrame int offset =0; idata = &idata [offset]; /// /// draw Y grid /// for(int i=0; i!=288; i+=2) for(int j=0; j!=384; j+=16) idata[(i*384)+j] ^=0x00FFFFFF; /// /// draw x grid /// for(int i=0; i!=288; i+=16) for (int x=0;x!=384;x+=2) idata[(i*384)+x] ^=0x00FFFFFF; } //// //// simple wait for click routine! //// // ------------------------------------ int Xwin::wait4Click () { // ------------------------------------ // isWait4Click = true; while (1) { XNextEvent(dpy, &e); // block & sleep until an event if (e.type ==4) // until a button click break; } return e.xbutton.button; // return its button ID } //// //// tag a point on the image, by click, depreciated now... //// //------------------------------------ void Xwin::markPoint(int yLoc, int xLoc, int tagColor = 0xFF0000) { //------------------------------------ int *idata = *baseFrame; int offset =(yLoc*384) + xLoc; idata = &idata [offset]; /// /// Y span 3 pixels long /// idata[(384)] = idata[-384] = idata[(384*2)] = idata[(384*3)] = idata[(384*4)] = idata[-(384*2)] = idata[-(384*3)] = idata[-(384*4)] = tagColor; /// /// X span (+2 --> -2) pixels long /// int x; idata = &idata[-4]; for(x=0;x!=4;x++) { idata[x]= idata[ x+5 ]= tagColor; } //cerr << "markPoint about to exit!! " << endl; }