Ejemplo n.º 1
0
/* EXPORT-> MakeXGraf: Create and open window, initialization */
void MakeXGraf(char *wname, int x, int y, int w, int h, int bw)
     /* WIN32: bw is ignored. */
{
   WNDCLASS WindowClass;
   char sbuf[256], *hgraf = "HGraf";
   HDC dc;
     
   if (winCreated)
      HError(6870, "MakeXGraf: Attempt to recreate the graphics window");
     
   WindowClass.hInstance = GetModuleHandle(NULL);
   WindowClass.lpszClassName = hgraf;
   WindowClass.lpfnWndProc = HGWinFunc;
   WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
   WindowClass.hIcon = NULL;
   WindowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
   WindowClass.lpszMenuName = NULL;
   WindowClass.cbClsExtra = 0;
   WindowClass.cbWndExtra = 0;
   WindowClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
     
   RegisterClass(&WindowClass);
     
   strcpy(sbuf, hgraf);  strcat(sbuf, ": ");  strcat(sbuf, wname);
     
   theWindow = 
      CreateWindow(hgraf, sbuf, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                   x,y, w,h, HWND_DESKTOP, NULL,
                   WindowClass.hInstance,       NULL);
     
   /* adjust window size so that the client rectangle is the size requested */
   /* by the caller of MakeXGraf() --- Win32 interprets w and h as the dimensions */
   /* of the overall window. */
   GetClientRect(theWindow,&ClientRect);
   MoveWindow(theWindow,x,y,w+w-ClientRect.right,h+h-ClientRect.bottom,TRUE); 
   GetClientRect(theWindow,&ClientRect);
     
   /* Obtain and initialize device contexts */
   dc = GetDC(theWindow);
   memDC = CreateCompatibleDC(dc);
   SetArcDirection(memDC,AD_COUNTERCLOCKWISE);
   SetArcDirection(dc,AD_COUNTERCLOCKWISE);
   SetPolyFillMode(memDC,WINDING);
   SetPolyFillMode(memDC,WINDING);
   SetTextAlign(memDC,TA_BASELINE | TA_LEFT);
   SetTextAlign(dc,TA_BASELINE | TA_LEFT);
   SetBkMode(memDC,TRANSPARENT);
   SetBkMode(dc,TRANSPARENT);
   theBitmap = CreateCompatibleBitmap(dc,w,h);
   SelectObject(memDC,theBitmap);
   ReleaseDC(theWindow,dc);
   CreateHeap(&btnHeap, "Button heap", MHEAP, sizeof(HButton), 1.0, 100, 100);
     
   InitGlobals();
   InstallColours();
     
   winCreated = TRUE;
   HSetColour(WHITE);
   HFillRectangle(0,0,ClientRect.right,ClientRect.bottom);
}
Ejemplo n.º 2
0
/* EXPORT->RedrawHButton: readraw a single button object */
void RedrawHButton(HButton *btn)
{
   int pad = 2;
   int x, y, w, h, r, s, pos;
   HPoint poly[9], shad[4];
   char sbuf[256], nullchar = '\0';
     
   x = btn->x;   y=btn->y;   w=btn->w;   h=btn->h;   r=3; s=1;
     
   /* set up the polygon */
   poly[0].x = x;         poly[0].y = y+r;
   poly[1].x = x;         poly[1].y = y+h-r;
   poly[2].x = x+r;       poly[2].y = y+h;
   poly[3].x = x+w-r;     poly[3].y = y+h;
   poly[4].x = x+w;       poly[4].y = y+h-r;
   poly[5].x = x+w;       poly[5].y = y+r;
   poly[6].x = x+w-r;     poly[6].y = y;
   poly[7].x = x+r;       poly[7].y = y;
   poly[8].x = x;         poly[8].y = y+r;
   /* set up the extra lines for the shadow */
   shad[0].x = x+r+s;     shad[0].y = y+h+s;
   shad[1].x = x+w-r+s;   shad[1].y = y+h+s;
   shad[2].x = x+w+s;     shad[2].y = y+h-r+s;
   shad[3].x = x+w+s;     shad[3].y = y+r+s;
     
   if (btn->lit) 
      HSetColour(btn->fg);
   else 
      HSetColour(btn->bg);
   HFillPolygon(poly, 9);
   HSetColour(btn->fg);
   HDrawLines(poly, 9);
   HDrawLines(shad, 4);
   if (btn->active)
      if (btn->lit)
         HSetColour(btn->bg);
      else 
         HSetColour(btn->fg);
   else
      HSetGrey(30);
   strcpy(sbuf, btn->str);
   pos = strlen(sbuf); 
   while(HTextWidth(sbuf) > (w - 2*pad)) 
      sbuf[--pos]=nullchar;
   HPrintf(CentreX(x+w/2, sbuf), CentreY(y+h/2, sbuf), "%s", sbuf);
}
Ejemplo n.º 3
0
// Draw output line in main output box - char by char
void ARec::DrawOutLine(PhraseType k, HTime t, string wrd, string tag)
{
   char buf[1000];

   HSetFontSize(win,-14);
   switch(k){
   case Start_PT:
      ScrollOutBox();
      sprintf(buf,"%4.1f: ",t/1e7);
      rdline = string(buf);
      break;
   case OpenTag_PT:
      rdline = rdline + " (";
      break;
   case CloseTag_PT:  rdline = rdline + " )";
      if (tag != "") rdline = rdline + tag;
      break;
   case Null_PT:
      if (tag != "") rdline = rdline + " <"+tag+">";
      break;
   case Word_PT:
      rdline = rdline + " " + wrd;
      if (tag != "") rdline = rdline + "<"+tag+">";
      break;
   case End_PT:
      HSetColour(win,BLACK);
      HPrintf(win,x0+3,rdly,"%s",rdline.c_str());
      break;
   }
   int len,w = x1-x0-6;
   if (HTextWidth(win,rdline.c_str()) > w) {
      strcpy(buf,rdline.c_str());
      do {
         len = strlen(buf); --len;
         assert(len>5);
         buf[len] = '\0';
      } while (HTextWidth(win,buf) > w);
      HSetColour(win,BLACK);
      HPrintf(win,x0+3,rdly,"%s",buf);
      ScrollOutBox();
      rdline.erase(0,len);
      rdline = "   " + rdline;
   }
   HSetFontSize(win,0);
}
Ejemplo n.º 4
0
HWin MakeAWindow(char *name,int x, int y, int w, int h, int n)
{
	HWin win;
	int xx,yy;
	char buf[100];

	win = MakeHWin(name,x,y,w,h,1);

	strcpy(buf,"Window: "); strcat(buf,name);
	xx = CentreX(win,w/2,buf);
	yy = CentreY(win,h/2,buf);
	HSetColour(win,RED+n);
	HDrawLine(win,0,0,w,h);
	HPrintf(win,xx,yy,"%s",buf);
	return win;
}
Ejemplo n.º 5
0
/* EXPORT-> MakeXGraf: Connect to the X-server and init globals */
void MakeXGraf(char *wname, int x, int y, int w, int h, int bw)
{
   char sbuf[MAXSTRLEN], *hgraf = "HGraf";
   Window window, parent;
   XSetWindowAttributes setwinattr;
   unsigned long vmask;
   
   if (winCreated)
      HError(6870, "MakeXGraf: Attempt to recreate the graphics window");
   if ((theDisp = XOpenDisplay(NULL)) == NULL)
      HError(6870, "MakeXGraf: cannot connect to X server %s", XDisplayName(NULL));
   InitGlobals();
   InstallFonts();
   InstallColours();
   parent = RootWindow(theDisp, theScreen);
   window = XCreateSimpleWindow(theDisp, parent, x, y, w, h, bw, black, white );
   /* allow for backing up the contents of the window */
   vmask = CWBackingStore;  setwinattr.backing_store = WhenMapped;
   XChangeWindowAttributes(theDisp, window, vmask, &setwinattr);
   /* set the size hints for the window manager */
   hints.flags = PPosition | PSize | PMaxSize | PMinSize;
   hints.y = y;              hints.x = x;
   hints.width  = w;         hints.height = h;
   hints.min_width  = w;     hints.min_height = h;
   hints.max_width  = w;     hints.max_height = h;
   /* compose the name of the window */
   strcpy(sbuf, hgraf);  strcat(sbuf, ": ");  strcat(sbuf, wname);
   XSetStandardProperties(theDisp, window, sbuf, hgraf, None, NULL, 0, &hints);
   /* select events to receive */
   XSelectInput(theDisp, window, ExposureMask | KeyPressMask | ButtonPressMask | 
                ButtonReleaseMask | PointerMotionHintMask | PointerMotionMask);
   XMapWindow(theDisp, theWindow = window);
   InitGCs(); 
   HSetXMode(GCOPY); HSetFontSize(0); HSetLineWidth(0); HSetColour(BLACK);
   /* wait for the first expose event - cannot draw before it has arrived */
   do 
      XNextEvent(theDisp, &report); 
   while (report.type != Expose);
   XSendEvent(theDisp,window,False,ExposureMask,&report);
   /* Create heap for buttons */
   CreateHeap(&btnHeap, "Button heap", MHEAP, sizeof(HButton), 1.0, 100, 100);
   winCreated = TRUE;
}
Ejemplo n.º 6
0
// Draw current status
void ARec::DrawStatus()
{
   if (laststate != runstate){
      switch(runstate){
      case WAIT_STATE: HSetColour(win,RED); break;
      case PRIME_STATE: HSetColour(win,ORANGE); break;
      case FLUSH_STATE: HSetColour(win,YELLOW); break;
      case RUN_STATE: HSetColour(win,DARK_GREEN); break;
      case ANS_STATE: HSetColour(win,MAUVE); break;
      }
      HFillRectangle(win,x2,y4+4,x3,y5+1);
      laststate = runstate;
   }
   int npkts = in->NumPackets();
   if (npkts != inlevel){
      inlevel = npkts;
      int x = npkts+x0;
      if (x>x1) x = x1;
      HSetGrey(win,PANELGREY1);
      HFillRectangle(win,x0,y8,x1,y9);
      HSetColour(win,RED);
      HFillRectangle(win,x0+1,y8,x,y9);
   }
}
Ejemplo n.º 7
0
// Do traceback and if showRD then update display
void ARec::TraceBackRecogniser()
{
   int i,st,en;
   char *p,buf[10];
   MLink m;
   Path *pp;
   float tnow,confidence,ac;
   int iscore;
   PartialPath pptb,ppcb;

   ppcb = CurrentBestPath(pri);

   // get the word that the current best path is within
   p="";
   if (ppcb.node!=NULL && ppcb.node->wordset!=NULL)
      p = ppcb.node->wordset->name;

   // update time
   tnow = float((pri->frame*sampPeriod + stTime)/1e7);
   if (showRD){
      HSetColour(win,BLACK);
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x5-1,y4-1,x6+1,y5+1);
      HSetColour(win,BLACK);
      HPrintf(win,x5,y5,"%.1fs",tnow);
   }

   // update HMM, nactive, and score (but ignore silence)
   if (showRD){
      m=FindMacroStruct(hset,'h',pri->genMaxNode->info.hmm);
      assert(m!=NULL);
      if (strcmp(m->id->name,"sil") != 0 && strcmp(m->id->name,"sp") != 0) {
         st = trbakFrame; en = pri->frame;
         ac = float(pri->genMaxTok.like - trbakAc);
         confidence = GetConfidence(pri,st+1,en,ac,"");
         //printf("CONFA %d->%d = %f [%f - %f = %f]\n",st,en,confidence,pri->genMaxTok.like,trbakAc,ac);
         trbakFrame = pri->frame;
         trbakAc = float(pri->genMaxTok.like);
         iscore = (int) (float(x7) + confidence*float(x8-x7));
         if (iscore<=x7) {
            HSetColour(win,RED); HFillRectangle(win,x7,y4+4,x8,y5+1);
         }else if (iscore>=x8) {
            HSetColour(win,DARK_GREEN); HFillRectangle(win,x7,y4+4,x8,y5+1);
         }else {
            HSetColour(win,RED); HFillRectangle(win,iscore,y4+4,x8,y5+1);
            HSetColour(win,DARK_GREEN); HFillRectangle(win,x7,y4+4,iscore,y5+1);
         }
      }
      // update HMM
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x10,y4-1,x11,y5+3);
      HSetColour(win,BLACK);
      HPrintf(win,x10,y5,"%s",m->id->name);
      // update nactive
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x12,y4-1,x13,y5+1);
      HSetColour(win,BLACK);
      HPrintf(win,x12,y5,"%d", pri->nact);
      // update mode
      HSetGrey(win,PANELGREY2);
      HFillRectangle(win,x14,y4-1,x1,y5+1);
      HSetColour(win,BLACK);
      strcpy(buf,"    ");
      if (runmode&ONESHOT_MODE) buf[0] = '1';
      if (runmode&CONTINUOUS_MODE) buf[0] = 'C';
      if (runmode&RUN_IMMED) buf[1] = 'I';
      if (runmode&FLUSH_TOMARK) buf[1] = 'M';
      if (runmode&FLUSH_TOSPEECH) buf[1] = 'S';
      if (runmode&STOP_IMMED) buf[2] = 'I';
      if (runmode&STOP_ATMARK) buf[2] = 'M';
      if (runmode&STOP_ATSIL) buf[2] = 'S';
      if (runmode&RESULT_ATEND) buf[3] = 'E';
      if (runmode&RESULT_IMMED) buf[3] = 'I';
      if (runmode&RESULT_ASAP) buf[3] = 'A';
      if ((runmode&RESULT_ALL) == RESULT_ALL) buf[3] = 'X';
      HPrintf(win,x14,y5,"%s",buf);
   }

   // if showRD do full traceback
   if (showRD){
      string s = p;
      char buf[256],*bp;

      for (pp = ppcb.path; pp!=NULL; pp=pp->prev){
         if (pp->owner->node->info.pron != NULL)  // it might be a !NULL tag
            s = string(pp->owner->node->info.pron->word->wordName->name) + string(" ") + s;
      }
      if (s != trbak){
         int w = x1-x0-8,txtw;
         trbak = s;
         HSetGrey(win,PANELGREY1);
         strcpy(buf,s.c_str());  bp = buf;
         txtw = HTextWidth(win,bp);
         while (txtw>w) txtw = HTextWidth(win,++bp);
         HFillRectangle(win,x0+1,y6+2,x0+trbakLastWidth+5,y3-2);
         HSetColour(win,BLACK);
         HPrintf(win,x0+4,y3-4,"%s",bp);
         trbakLastWidth = txtw;
      }
   }

   // runmode is RESULT_ASAP, see if anything more can be disambiguated
   if (runmode&RESULT_ASAP){
      pptb = DoTraceBack(pri);
      if (pptb.n>0){
         if (trace&T_PAN) {
            printf(" traceback at frame %.1f\n",tnow);
            PrintPartialPath(pptb,FALSE);
         }
         for (i=1; i<=pptb.n; i++)
            OutPathElement(i,pptb);
      }
   }
   // runmode is RESULT_IMMED, output any new words regardless
   if ((runmode&RESULT_IMMED) && (ppcb.n>0)){
      if (trace&T_IAN) {
         printf(" current best at frame %.1f\n",tnow);
         PrintPartialPath(ppcb,FALSE);
      }
      for (i=1; i<=ppcb.n; i++)
         OutPathElement(i,ppcb);
   }
}