Ejemplo n.º 1
0
// Set the button information for the button designated by "index".
OsStatus PsButtonTask::setButtonInfo(const int index, const int buttonId,
                                                                         const char* name,
                                     const int eventMask,
                                     const OsTime& repInterval)
{
   OsWriteLock  lock(mMutex);      // acquire a write lock
   PsButtonInfo buttonInfo(buttonId, name, eventMask, repInterval);

    mpButtonInfo[index] = buttonInfo;

   return OS_SUCCESS;
}
Ejemplo n.º 2
0
/****************************************************************************
 *
 * Combines icon shape masks after a resize
 *
 ****************************************************************************/
void ConfigureIconWindow(button_info *b)
{
#ifndef NO_ICONS
  int x,y,w,h;
  int xoff,yoff;
  int framew,xpad,ypad;
  XFontStruct *font;
  int BW,BH;

  if(!b || !(b->flags&b_Icon))
    return;

  if(!b->IconWin)
    {
      fprintf(stderr,"%s: DEBUG: Tried to configure erroneous iconwindow\n",
	      MyName);
      exit(2);
    }

  buttonInfo(b,&x,&y,&xpad,&ypad,&framew);
  framew=abs(framew);

  font = buttonFont(b);
  w = b->icon->width;
  h = b->icon->height;
  BW = buttonWidth(b);
  BH = buttonHeight(b);

  w=min(w,BW-2*(xpad+framew));

  if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal))
    h=min(h,BH-2*(ypad+framew)-font->ascent-font->descent);
  else
    h=min(h,BH-2*(ypad+framew));

  if(w < 1 || h < 1)
    {
      XMoveResizeWindow(Dpy, b->IconWin, 2000,2000,1,1);
      return; /* No need drawing to this */
    }

  if(buttonJustify(b)&b_Horizontal)
    xoff=0;
  else
    xoff=(BW-w)>>1;

  if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal))
    yoff=(BH-(h+font->ascent+font->descent))>>1;
  else
Ejemplo n.º 3
0
void get_button_root_geometry(rectangle *r, const button_info *b)
{
	int x;
	int y;
	int f;
	Window win;

	r->width = buttonWidth(b);
	r->height = buttonHeight(b);
	buttonInfo(b, &r->x, &r->y, &x, &y, &f);
	XTranslateCoordinates(
		Dpy, MyWindow, Root, r->x, r->y, &r->x, &r->y, &win);

	return;
}
Ejemplo n.º 4
0
Archivo: button.c Proyecto: att/uwin
/**
*** GetInternalSize()
**/
void GetInternalSize(button_info *b,int *x,int *y,int *w,int *h)
{
  int f;
  int px,py;
  buttonInfo(b,x,y,&px,&py,&f);
  f=abs(f);

  *w=buttonWidth(b)-2*(px+f);
  *h=buttonHeight(b)-2*(py+f);

  *x+=f+px;
  *y+=f+py;

  if (*w < 1)
    *w = 1;
  if (*h < 1)
    *h = 1;

  return;
}
Ejemplo n.º 5
0
int Dialog::AdventureOptions(bool enabledig)
{
    Display & display = Display::Get();

    // preload
    const int apanbkg = Settings::Get().ExtGameEvilInterface() ? ICN::APANBKGE : ICN::APANBKG;
    const int apanel  = Settings::Get().ExtGameEvilInterface() ? ICN::APANELE : ICN::APANEL;

    // cursor
    Cursor & cursor = Cursor::Get();
    const int oldcursor = cursor.Themes();

    cursor.Hide();
    cursor.SetThemes(cursor.POINTER);

    // image box
    const Sprite &box = AGG::GetICN(apanbkg, 0);
    SpriteBack back(Rect((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()));
    const Point & rb = back.GetPos();
    box.Blit(rb.x, rb.y);

    LocalEvent & le = LocalEvent::Get();

    Button buttonWorld(rb.x + 62, rb.y + 30, apanel, 0, 1);
    Button buttonPuzzle(rb.x + 195, rb.y + 30, apanel, 2, 3);
    Button buttonInfo(rb.x + 62, rb.y + 107, apanel, 4, 5);
    Button buttonDig(rb.x + 195, rb.y + 107, apanel, 6, 7);
    Button buttonCancel(rb.x + 128, rb.y + 184, apanel, 8, 9);

    if(! enabledig) buttonDig.SetDisable(true);

    buttonWorld.Draw();
    buttonPuzzle.Draw();
    buttonInfo.Draw();
    buttonDig.Draw();
    buttonCancel.Draw();

    cursor.Show();
    display.Flip();

    int result = Dialog::ZERO;

    // dialog menu loop
    while(le.HandleEvents())
    {
        le.MousePressLeft(buttonWorld) ? buttonWorld.PressDraw() : buttonWorld.ReleaseDraw();
        le.MousePressLeft(buttonPuzzle) ? buttonPuzzle.PressDraw() : buttonPuzzle.ReleaseDraw();
        le.MousePressLeft(buttonInfo) ? buttonInfo.PressDraw() : buttonInfo.ReleaseDraw();
        le.MousePressLeft(buttonDig) ? buttonDig.PressDraw() : buttonDig.ReleaseDraw();
        le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw();

        if(le.MouseClickLeft(buttonWorld)){ result = Dialog::WORLD; break; }
        if(le.MouseClickLeft(buttonPuzzle)){ result = Dialog::PUZZLE; break; }
        if(le.MouseClickLeft(buttonInfo)){ result = Dialog::INFO; break; }
        if(le.MouseClickLeft(buttonDig) && buttonDig.isEnable()){ result = Dialog::DIG; break; }
        if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPressEvent(Game::EVENT_DEFAULT_EXIT)){ result = Dialog::CANCEL; break; }

	// right info
        if(le.MousePressRight(buttonWorld)) Dialog::Message("", _("View the entire world."), Font::BIG);
        if(le.MousePressRight(buttonPuzzle)) Dialog::Message("", _("View the obelisk puzzle."), Font::BIG);
        if(le.MousePressRight(buttonInfo)) Dialog::Message("", _("View information on the scenario you are currently playing."), Font::BIG);
        if(le.MousePressRight(buttonDig)) Dialog::Message("", _("Dig for the Ultimate Artifact."), Font::BIG);
        if(le.MousePressRight(buttonCancel)) Dialog::Message("", _("Exit this menu without doing anything."), Font::BIG);
    }

    // restore background
    cursor.Hide();
    back.Restore();
    cursor.SetThemes(oldcursor);
    cursor.Show();
    display.Flip();

    return result;
}
Ejemplo n.º 6
0
/**
*** RedrawButton()
*** Writes out title, if any, and displays the bevel right, by calling 
*** RelieveWindow. If clean is nonzero, also clears background.
**/
void RedrawButton(button_info *b,int clean)
{
  int i,j,k,BH,BW;
  int f,x,y,px,py;
  int ix,iy,iw,ih;
  XFontStruct *font=buttonFont(b);
  XGCValues gcv;
  unsigned long gcm=0;
  int rev=0;
  int justify=buttonJustify(b);

  BW = buttonWidth(b);
  BH = buttonHeight(b);

  buttonInfo(b,&x,&y,&px,&py,&f);
  GetInternalSize(b,&ix,&iy,&iw,&ih);

  /* This probably isn't the place for this, but it seems to work here and not
     elsewhere, so... */
  if((buttonSwallowCount(b)==3) && b->IconWin!=None)
    XSetWindowBorderWidth(Dpy,b->IconWin,0);

  /* ----------------------------------------------------------------------- */

  if(b->flags&b_Hangon || b==CurrentButton)  /* Hanging or held down by user */
    rev=1;
  if(b->flags&b_Action) /* If this is a Desk button that takes you to here.. */
    {
      int n=0;
      while(n<4 && (!b->action[n] || strncasecmp(b->action[n],"Desk",4)))
	n++;
      if(n<4)
	{
	  k=sscanf(&b->action[n][4],"%d%d",&i,&j);
	  if(k==2 && i==0 && j==new_desk)
	    rev=1;
	}
    }
  RelieveWindow(MyWindow,f,x,y,BW,BH,buttonHilite(b),buttonShadow(b),rev);

  /* ----------------------------------------------------------------------- */

  f=abs(f);

  if(clean && BW>2*f && BH>2*f)
    {
      gcm = GCForeground;
      gcv.foreground=buttonBack(b);
      XChangeGC(Dpy,NormalGC,gcm,&gcv);

      if(b->flags&b_Container)
	{
	  int x1=x+f,y1=y+f;
	  int w1=px,h1=py,w2=w1,h2=h1;
	  int w=BW-2*f,h=BH-2*f;
	  w2+=iw - b->c->num_columns*b->c->ButtonWidth;
	  h2+=ih - b->c->num_rows*b->c->ButtonHeight;

	  if(w1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w1,h);
	  if(w2)XFillRectangle(Dpy,MyWindow,NormalGC,x1+w-w2,y1,w2,h);
	  if(h1)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1,w,h1);
	  if(h2)XFillRectangle(Dpy,MyWindow,NormalGC,x1,y1+h-h2,w,h2);
	}
      else 
	XFillRectangle(Dpy,MyWindow,NormalGC,x+f,y+f,BW-2*f,BH-2*f);
    }

  /* ----------------------------------------------------------------------- */

  /* If a title is to be shown, truncate it until it fits */
  if(b->flags&b_Title && font)
    {
      int l,i,xpos;
      char *s;
      int just=justify&b_TitleHoriz; /* Left, center, right */

      gcm = GCForeground | GCFont; 
      gcv.foreground=buttonFore(b);
      gcv.font = font->fid;
      XChangeGC(Dpy,NormalGC,gcm,&gcv);

      if(justify&b_Horizontal)
	{
	  if(b->flags&b_Icon)
	    {
	      ix+=b->icon->width+buttonXPad(b);
	      iw-=b->icon->width+buttonXPad(b);
	    }
	  else if (buttonSwallowCount(b)==3)
	    {
	      ix+=b->icon_w+buttonXPad(b);
	      iw-=b->icon_w+buttonXPad(b);
	    }
	}

      s=b->title;
      l=strlen(s);
      i=XTextWidth(font,s,l);

      if(i>iw)
	{
	  if(just==2)
	    {
	      while(i>iw && *s)
		i=XTextWidth(font,++s,--l);
	    }
	  else /* Left or center - cut off its tail */
	    {
	      while(i>iw && l>0)
		i=XTextWidth(font,s,--l);
	    }
	}
      if(just==0) /* Left */
	xpos=ix;
      else if(just==2) /* Right */
	xpos=max(ix,ix+iw-i);
      else /* Centered, I guess */
 	xpos=ix+(iw-i)/2;

      if(*s && l>0 && BH>=font->descent+font->ascent) /* Clip it somehow? */
	{
	  /* If there is more than the title, put it at the bottom */
          /* Unless stack flag is set, put it to the right of icon */
	  if((b->flags&b_Icon || (buttonSwallowCount(b)==3)) &&
	     !(justify&b_Horizontal))
	    {
	      XDrawString(Dpy,MyWindow,NormalGC,xpos,
			  iy+ih-font->descent,s,l);
	      /* Shrink the space available for icon/window */
	      ih-=font->descent+font->ascent;
	    }
	  /* Or else center vertically */
	  else
	    {
	      XDrawString(Dpy,MyWindow,NormalGC,xpos,
			  iy+(ih+font->ascent-font->descent)/2,s,l);
	    }
	}
    }
}
Ejemplo n.º 7
0
Archivo: parse.c Proyecto: att/uwin
char *expand_action(char *in_action, button_info *b)
{
  char *variables[] =
  {
    "$",
    "fg",
    "bg",
    "left",
    "-left",
    "right",
    "-right",
    "top",
    "-top",
    "bottom",
    "-bottom",
    "width",
    "height",
    NULL
  };
  char *action = NULL;
  char *src;
  char *dest;
  char *string = NULL;
  char *rest;
  int px;
  int py;
  int val = 0;
  int offset;
  int x;
  int y;
  int f;
  int i;
  unsigned int w = 0;
  unsigned int h = 0;
  Window win;
  extern int dpw;
  extern int dph;

  /* create a temporary storage for expanding */
  action = (char *)malloc(MAX_MODULE_INPUT_TEXT_LEN);
  if (!action)
  {
    /* could not alloc memory */
    return NULL;
  }

  /* calculate geometry */
  if (b)
  {
    w = buttonWidth(b);
    h = buttonHeight(b);
    buttonInfo(b, &x, &y, &px, &py, &f);
    XTranslateCoordinates(Dpy, MyWindow, Root, x, y, &x, &y, &win);
  }

  for (src = in_action, dest = action; *src != 0; src++)
  {
    if (*src != '$')
    {
      *(dest++) = *src;
    }
    else
    {
      char *dest_org = dest;
      Bool is_string = False;
      Bool is_value = False;

      *(dest++) = *(src++);
      i = GetTokenIndex(src, variables, -1, &rest);
      if (i == -1)
      {
	src--;
	continue;
      }
      switch (i)
      {
      case 0: /* $ */
	continue;
      case 1: /* fg */
	string = UberButton->c->fore;
	is_string = True;
	break;
      case 2: /* bg */
	string = UberButton->c->back;
	is_string = True;
	break;
      case 3: /* left */
	val = x;
	is_value = True;
	break;
      case 4: /* -left */
	val = dpw - x - 1;
	is_value = True;
	break;
      case 5: /* right */
	val = x + w;
	is_value = True;
	break;
      case 6: /* -right */
	val = dpw - x - w - 1;
	is_value = True;
	break;
      case 7: /* top */
	val = y;
	is_value = True;
	break;
      case 8: /* -top */
	val = dph - y - 1;
	is_value = True;
	break;
      case 9: /* bottom */
	val = y + h;
	is_value = True;
	break;
      case 10: /* -bottom */
	val = dph - y - h - 1;
	is_value = True;
	break;
      case 11: /* width */
	val = w;
	is_value = True;
	break;
      case 12: /* height */
	val = h;
	is_value = True;
	break;
      default: /* unknown */
	src--;
	continue;
      } /* switch */
      dest = dest_org;
      src = --rest;
      if (is_value)
      {
	if (MAX_MODULE_INPUT_TEXT_LEN - (dest - action) <= 16)
	{
	  /* out of space */
	  free(action);
	  return NULL;
	}
	/* print the number into the string */
	sprintf(dest, "%d%n", val, &offset);
	dest += offset;
      }
      else if (is_string)
      {
	if (MAX_MODULE_INPUT_TEXT_LEN - (dest - action) <= strlen(string))
	{
	  /* out of space */
	  free(action);
	  return NULL;
	}
	/* print the colour name into the string */
	if (string)
	{
	  sprintf(dest, "%s%n", string, &offset);
	  dest += offset;
	}
      }
    } /* if */
  } /* for */
  *dest = 0;
  return action;
}