int main (){ #ifdef I18N_MB if(b->flags&b_Title && (fontset = buttonFontSet(b)) && (font=buttonFont(b))) #else if(b->flags&b_Title && (font=buttonFont(b))) #endif { } }
/**************************************************************************** * * 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
VotePanel::VotePanel(wxWindow* parentWindow) : wxPanel(parentWindow) , chatPanel(0) , parentWnd(parentWindow) , player(0) { mainSizer = new wxBoxSizer(wxHORIZONTAL); voteTextLabel = new wxStaticText(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize); wxFont labelFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); voteTextLabel->SetFont(labelFont); mainSizer->Add(voteTextLabel, 0, wxALIGN_CENTER, 0); wxFont buttonFont(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); yesButton = new wxButton(this, VotePanel::ID_YES_BUTTON, "yes", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); yesButton->SetFont(buttonFont); yesButton->SetForegroundColour(*wxGREEN); yesButton->SetToolTip(_("Vote for YES, (Ctrl-Y)")); mainSizer->Add(yesButton); dontCareButton = new wxButton(this, VotePanel::ID_DONTCARE_BUTTON, "don't care", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); dontCareButton->SetFont(buttonFont); dontCareButton->SetToolTip(_("Vote for DON'T CARE, (Ctrl-B)")); mainSizer->Add(dontCareButton); noButton = new wxButton(this, VotePanel::ID_NO_BUTTON, "no", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); noButton->SetFont(buttonFont); noButton->SetForegroundColour(*wxRED); noButton->SetToolTip(_("Vote for NO, (Ctrl-N)")); mainSizer->Add(noButton); SetSizer(mainSizer); //Set up acceleration table for hotkeys const int ENTRIES_COUNT = 3; wxAcceleratorEntry accelEntries[ENTRIES_COUNT]; accelEntries[0].Set(wxACCEL_CTRL, (int)'Y', ID_YES_BUTTON); accelEntries[1].Set(wxACCEL_CTRL, (int)'B', ID_DONTCARE_BUTTON); accelEntries[2].Set(wxACCEL_CTRL, (int)'N', ID_NO_BUTTON); wxAcceleratorTable accelTable(ENTRIES_COUNT, accelEntries); //TODO: this line overrides parent's window acceleration table! parentWindow->SetAcceleratorTable(accelTable); //Reset vote panel to "no vote" state ResetState(); }
*/int drawButtonWithState (SDL_Surface *destinationSurface, myButton *button, int withState) { //draw border SDL_Rect buttonBorder = button->rect; buttonBorder.h++; buttonBorder.w++; buttonBorder.x--; buttonBorder.y--; SDL_FillRect(destinationSurface, &buttonBorder, SDL_MapRGB( destinationSurface->format, 0xFF, 0xFF, 0xFF )); //draw button if (button->disabled&&withState) { SDL_FillRect(destinationSurface, &button->rect, SDL_MapRGB( destinationSurface->format, 0x73, 0x73, 0x73 )); } else { SDL_FillRect(destinationSurface, &button->rect, SDL_MapRGB( destinationSurface->format, 0x00, 0x00, 0xFF )); } //draw button title SDL_Surface *message; TTF_Font *font = buttonFont(); SDL_Color blackTextColor = { 0, 0, 0,0}; //text shade if (!(message = TTF_RenderText_Blended( font, button->name, blackTextColor ))) { printf("%s\n",TTF_GetError()); return 1; } SDL_Rect textBlack = {button->rect.x+button->rect.w/2-message->w/2+2,button->rect.y+button->rect.h/2-message->h/2+2,0,0}; if(0!=SDL_BlitSurface( message, NULL, destinationSurface, &textBlack)) { printf("%s\n",SDL_GetError()); return 1; } //text SDL_Color textColor = { 255, 255, 255,0}; if (!(message = TTF_RenderText_Blended( font, button->name, textColor ))) { printf("%s\n",TTF_GetError()); return 1; } SDL_Rect text = {button->rect.x+button->rect.w/2-message->w/2,button->rect.y+button->rect.h/2-message->h/2,0,0}; TTF_CloseFont(font); if(0!=SDL_BlitSurface( message, NULL, destinationSurface, &text)) { printf("%s\n",SDL_GetError()); return 1; } SDL_FreeSurface(message); return 0; }
/** *** MakeButton() *** To position subwindows in a button: icons and swallowed windows. **/ void MakeButton(button_info *b) { /* This is resposible for drawing the contents of a button, placing the icon and/or swallowed item in the correct position inside potential padding or frame. */ int ih,iw,ix,iy; XFontStruct *font; if(!b) { fprintf(stderr,"%s: BUG: DrawButton called with NULL pointer\n",MyName); exit(2); } if(b->flags&b_Container) { fprintf(stderr,"%s: BUG: DrawButton called with container\n",MyName); exit(2); } if(!(b->flags&b_Icon) && (buttonSwallowCount(b)<3)) return; font = buttonFont(b); GetInternalSize(b,&ix,&iy,&iw,&ih); /* At this point iw,ih,ix and iy should be correct. Now all we have to do is place title and iconwin in their proper positions */ /* For now, use the old routine in icons.h for buttons with icons */ if(b->flags&b_Icon) ConfigureIconWindow(b); /* For now, hardcoded window centered, title bottom centered, below window */ else if(buttonSwallowCount(b)==3) { long supplied; if(!b->IconWin) { fprintf(stderr,"%s: BUG: Swallowed window has no IconWin\n",MyName); exit(2); } if(b->flags&b_Title && font && !(buttonJustify(b)&b_Horizontal)) ih -= font->ascent+font->descent; b->icon_w=iw; b->icon_h=ih; if(iw>0 && ih>0) { if(!(buttonSwallow(b)&b_NoHints)) { if(!XGetWMNormalHints(Dpy,b->IconWin,b->hints,&supplied)) b->hints->flags=0; ConstrainSize(b->hints,&b->icon_w,&b->icon_h); } XMoveResizeWindow(Dpy,b->IconWin,ix+(iw-b->icon_w)/2, iy+(ih-b->icon_h)/2,b->icon_w,b->icon_h); } else XMoveWindow(Dpy,b->IconWin,2000,2000); } }
/** *** 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); } } } }