void draw_item(vector<dir_entry>::const_iterator i, SDL_Surface *s, int16 x, int16 y, uint16 width, bool selected) const { y += font->get_ascent(); set_drawing_clip_rectangle(0, x, s->h, x + width); if(i->is_directory) { string theName = i->name + "/"; draw_text(s, theName.c_str (), x, y, selected ? get_theme_color (ITEM_WIDGET, ACTIVE_STATE) : get_theme_color (ITEM_WIDGET, DEFAULT_STATE), font, style, true); } else { char date[256]; tm *time_info = localtime(&i->date); if (time_info) { strftime(date, 256, "%x %R", time_info); int date_width = text_width(date, font, style); draw_text(s, date, x + width - date_width, y, selected ? get_theme_color(ITEM_WIDGET, ACTIVE_STATE) : get_theme_color(ITEM_WIDGET, DEFAULT_STATE), font, style); set_drawing_clip_rectangle(0, x, s->h, x + width - date_width - 4); } draw_text(s, FileSpecifier::HideExtension(i->name).c_str (), x, y, selected ? get_theme_color (ITEM_WIDGET, ACTIVE_STATE) : get_theme_color (ITEM_WIDGET, DEFAULT_STATE), font, style, true); } set_drawing_clip_rectangle(SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); }
/************************************************************************** ... **************************************************************************/ static int redraw_icon2(struct widget *pIcon) { int ret; SDL_Rect dest; Uint32 state; ret = (*baseclass_redraw)(pIcon); if (ret != 0) { return ret; } if(!pIcon) { return -3; } if(!pIcon->theme) { return -4; } state = get_wstate(pIcon); dest.x = pIcon->size.x; dest.y = pIcon->size.y; dest.w = pIcon->theme->w; dest.h = pIcon->theme->h; if (state == FC_WS_SELLECTED) { putframe(pIcon->dst->surface, dest.x + 1, dest.y + 1, dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); } if (state == FC_WS_PRESSED) { putframe(pIcon->dst->surface, dest.x + 1, dest.y + 1, dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); putframe(pIcon->dst->surface, dest.x, dest.y, dest.x + dest.w + adj_size(3), dest.y + dest.h + adj_size(3), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_PRESSED_FRAME)); } if (state == FC_WS_DISABLED) { putframe(pIcon->dst->surface, dest.x + 1, dest.y + 1, dest.x + dest.w + adj_size(2), dest.y + dest.h + adj_size(2), get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT)); } dest.x += adj_size(2); dest.y += adj_size(2); ret = alphablit(pIcon->theme, NULL, pIcon->dst->surface, &dest); if (ret) { return ret; } return 0; }
void w_plugins::draw_item(Plugins::iterator it, SDL_Surface* s, int16 x, int16 y, uint16 width, bool selected) const { y += font->get_ascent(); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); uint32 color; if (selected) { color = get_theme_color(ITEM_WIDGET, ACTIVE_STATE); } else if (it->enabled && it->compatible()) { color = get_theme_color(ITEM_WIDGET, DEFAULT_STATE); } else { color = get_theme_color(ITEM_WIDGET, DISABLED_STATE); } std::string enabled; if (!it->compatible()) { enabled = " Incompatible"; } else if (it->enabled) { enabled = " Enabled"; } else { enabled = " Disabled"; } int right_text_width = text_width(enabled.c_str(), font, style); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width - right_text_width); std::string name_and_version = it->name + " " + it->version; draw_text(s, name_and_version.c_str(), x, y, color, font, style); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); draw_text(s, enabled.c_str(), x + width - right_text_width, y, color, font, style); set_drawing_clip_rectangle(SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); y += font->get_ascent() + 1; if (it->description.size()) { draw_text(s, it->description.c_str(), x, y, color, font, style); } else { draw_text(s, "No description", x, y, color, font, style); } }
void w_crosshair_display::draw(SDL_Surface *s) const { SDL_FillRect(surface, 0, get_theme_color(DIALOG_FRAME, DEFAULT_STATE, BACKGROUND_COLOR)); SDL_Rect r = { 0, 0, surface->w, surface->h }; draw_rectangle(surface, &r, get_theme_color(DIALOG_FRAME, FRAME_COLOR)); bool Old_Crosshairs_IsActive = Crosshairs_IsActive(); Crosshairs_SetActive(true); Crosshairs_Render(surface); Crosshairs_SetActive(Old_Crosshairs_IsActive); SDL_BlitSurface(surface, 0, s, const_cast<SDL_Rect *>(&rect)); }
/************************************************************************** Create string16 struct with ptsize font. Font will be loaded or aliased with existing font of that size. pInTextString must be allocated in memory (MALLOC/fc_calloc) **************************************************************************/ SDL_String16 *create_string16(Uint16 *pInTextString, size_t n_alloc, Uint16 ptsize) { SDL_String16 *str = fc_calloc(1, sizeof(SDL_String16)); if (!ptsize) { str->ptsize = theme_default_font_size(theme); } else { str->ptsize = ptsize; } if ((str->font = load_font(str->ptsize)) == NULL) { log_error("create_string16: load_font failed"); FC_FREE(str); return NULL; } str->style = TTF_STYLE_NORMAL; str->bgcol = (SDL_Color) {0, 0, 0, 0}; str->fgcol = *get_theme_color(COLOR_THEME_TEXT); str->render = 2; /* pInTextString must be allocated in memory (MALLOC/fc_calloc) */ str->text = pInTextString; str->n_alloc = n_alloc; return str; }
/************************************************************************** Ugly hack to create 4-state icon theme from static icon; **************************************************************************/ SDL_Surface *create_icon_theme_surf(SDL_Surface * pIcon) { SDL_Color bg_color = { 255, 255, 255, 128 }; SDL_Rect dest, src = get_smaller_surface_rect(pIcon); SDL_Surface *pTheme = create_surf_alpha((src.w + adj_size(4)) * 4, src.h + adj_size(4), SDL_SWSURFACE); dest.x = adj_size(2); dest.y = (pTheme->h - src.h) / 2; /* normal */ alphablit(pIcon, &src, pTheme, &dest); /* sellected */ dest.x += (src.w + adj_size(4)); alphablit(pIcon, &src, pTheme, &dest); /* draw sellect frame */ putframe(pTheme, dest.x - 1, dest.y - 1, dest.x + (src.w), dest.y + src.h, get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); /* pressed */ dest.x += (src.w + adj_size(4)); alphablit(pIcon, &src, pTheme, &dest); /* draw sellect frame */ putframe(pTheme, dest.x - 1, dest.y - 1, dest.x + src.w, dest.y + src.h, get_theme_color(COLOR_THEME_CUSTOM_WIDGET_SELECTED_FRAME)); /* draw press frame */ putframe(pTheme, dest.x - adj_size(2), dest.y - adj_size(2), dest.x + (src.w + 1), dest.y + (src.h + 1), get_theme_color(COLOR_THEME_CUSTOM_WIDGET_PRESSED_FRAME)); /* disabled */ dest.x += (src.w + adj_size(4)); alphablit(pIcon, &src, pTheme, &dest); dest.w = src.w; dest.h = src.h; SDL_FillRectAlpha(pTheme, &dest, &bg_color); return pTheme; }
void w_saves::draw_item(QuickSaves::iterator it, SDL_Surface* s, int16 x, int16 y, uint16 width, bool selected) const { std::ostringstream oss; oss << it->save_time; SDL_Surface *image = QuickSaveImageCache::instance()->get(oss.str()); SDL_Rect r = {x + 3, y + 3, PREVIEW_WIDTH, PREVIEW_HEIGHT}; SDL_BlitSurface(image, NULL, s, &r); x += PREVIEW_WIDTH + 12; width -= PREVIEW_WIDTH + 12; uint32 color; if (selected) { color = get_theme_color(ITEM_WIDGET, ACTIVE_STATE); } else { color = get_theme_color(ITEM_WIDGET, DEFAULT_STATE); } set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); y += font->get_ascent(); if (it->name.length()) { draw_text(s, utf8_to_mac_roman(it->name).c_str(), x, y, color, font, style); y += font->get_ascent() + 1; } draw_text(s, it->formatted_time.c_str(), x, y, color, font, style); y += font->get_ascent() + 1; draw_text(s, utf8_to_mac_roman(it->level_name).c_str(), x, y, color, font, style); y += font->get_ascent() + 1; std::string game_time = it->formatted_ticks; if (it->players > 1) { game_time += " (Cooperative Play)"; } draw_text(s, game_time.c_str(), x, y, color, font, style); set_drawing_clip_rectangle(SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); }
void w_found_players::draw_item(vector<prospective_joiner_info>::const_iterator i, SDL_Surface *s, int16 x, int16 y, uint16 width, bool selected) const { char theNameBuffer[SSLP_MAX_NAME_LENGTH + 12]; strncpy(theNameBuffer, (*i).name, SSLP_MAX_NAME_LENGTH - 1); if ((*i).gathering) { strncat(theNameBuffer, " (gathering)", 12); } int computed_x = x + (width - text_width(theNameBuffer, font, style)) / 2; int computed_y = y + font->get_ascent(); //unsigned char text_length = (*i)->sslps_name[0]; //if(text_length > SSLP_MAX_NAME_LENGTH - 1) // text_length = SSLP_MAX_NAME_LENGTH - 1; if ((*i).gathering) { draw_text(s, theNameBuffer, computed_x, computed_y, get_theme_color(ITEM_WIDGET, DISABLED_STATE), font, style); } else { draw_text(s, /*&((*i)->sslps_name[1]), text_length,*/ theNameBuffer, computed_x, computed_y, selected ? get_theme_color(ITEM_WIDGET, ACTIVE_STATE) : get_theme_color(ITEM_WIDGET, DEFAULT_STATE), font, style); } }
/************************************************************************** Create Icon Button image with text and Icon then blit to Dest(ination) on positon pIButton->size.x , pIButton->size.y. WARRING: pDest must exist. Text with atributes is taken from pIButton->string16 parameter. Graphic for button is taken from pIButton->theme surface and blit to new created image. Graphic for Icon is taken from pIButton->theme2 surface and blit to new created image. function return (-1) if there are no Icon and Text. Else return 0. **************************************************************************/ static int redraw_ibutton(struct widget *pIButton) { SDL_Rect dest = { 0, 0, 0, 0 }; SDL_String16 TMPString; SDL_Surface *pButton = NULL, *pText = NULL, *pIcon = pIButton->theme2; Uint16 Ix, Iy, x; Uint16 y = 0; /* FIXME: possibly uninitialized */ int ret; ret = (*baseclass_redraw)(pIButton); if (ret != 0) { return ret; } if (pIButton->string16) { /* make copy of string16 */ TMPString = *pIButton->string16; if (get_wstate(pIButton) == FC_WS_NORMAL) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_NORMAL_TEXT); } else if (get_wstate(pIButton) == FC_WS_SELLECTED) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_SELECTED_TEXT); TMPString.style |= TTF_STYLE_BOLD; } else if (get_wstate(pIButton) == FC_WS_PRESSED) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_PRESSED_TEXT); } else if (get_wstate(pIButton) == FC_WS_DISABLED) { TMPString.fgcol = *get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT); } pText = create_text_surf_from_str16(&TMPString); } if (!pText && !pIcon) { return -1; } /* create Button graphic */ pButton = create_bcgnd_surf(pIButton->theme, get_wstate(pIButton), pIButton->size.w, pIButton->size.h); clear_surface(pIButton->dst->surface, &pIButton->size); alphablit(pButton, NULL, pIButton->dst->surface, &pIButton->size); FREESURFACE(pButton); if (pIcon) { /* Icon */ if (pText) { if (get_wflags(pIButton) & WF_ICON_CENTER_RIGHT) { Ix = pIButton->size.w - pIcon->w - 5; } else { if (get_wflags(pIButton) & WF_ICON_CENTER) { Ix = (pIButton->size.w - pIcon->w) / 2; } else { Ix = 5; } } if (get_wflags(pIButton) & WF_ICON_ABOVE_TEXT) { Iy = 3; y = 3 + pIcon->h + 3 + (pIButton->size.h - (pIcon->h + 6) - pText->h) / 2; } else { if (get_wflags(pIButton) & WF_ICON_UNDER_TEXT) { y = 3 + (pIButton->size.h - (pIcon->h + 3) - pText->h) / 2; Iy = y + pText->h + 3; } else { /* center */ Iy = (pIButton->size.h - pIcon->h) / 2; y = (pIButton->size.h - pText->h) / 2; } } } else { /* no text */ Iy = (pIButton->size.h - pIcon->h) / 2; Ix = (pIButton->size.w - pIcon->w) / 2; } if (get_wstate(pIButton) == FC_WS_PRESSED) { Ix += 1; Iy += 1; } dest.x = pIButton->size.x + Ix; dest.y = pIButton->size.y + Iy; ret = alphablit(pIcon, NULL, pIButton->dst->surface, &dest); if (ret) { FREESURFACE(pText); return ret - 10; } } if (pText) { if (pIcon) { if (!(get_wflags(pIButton) & WF_ICON_ABOVE_TEXT) && !(get_wflags(pIButton) & WF_ICON_UNDER_TEXT)) { if (get_wflags(pIButton) & WF_ICON_CENTER_RIGHT) { if (pIButton->string16->style & SF_CENTER) { x = (pIButton->size.w - (pIcon->w + 5) - pText->w) / 2; } else { if (pIButton->string16->style & SF_CENTER_RIGHT) { x = pIButton->size.w - (pIcon->w + 7) - pText->w; } else { x = 5; } } } /* end WF_ICON_CENTER_RIGHT */ else { if (get_wflags(pIButton) & WF_ICON_CENTER) { /* text is blit on icon */ goto Alone; } /* end WF_ICON_CENTER */ else { /* icon center left - default */ if (pIButton->string16->style & SF_CENTER) { x = 5 + pIcon->w + ((pIButton->size.w - (pIcon->w + 5) - pText->w) / 2); } else { if (pIButton->string16->style & SF_CENTER_RIGHT) { x = pIButton->size.w - pText->w - 5; } else { /* text center left */ x = 5 + pIcon->w + 3; } } } /* end icon center left - default */ } /* 888888888888888888 */ } else { goto Alone; } } else { /* !pIcon */ y = (pIButton->size.h - pText->h) / 2; Alone: if (pIButton->string16->style & SF_CENTER) { x = (pIButton->size.w - pText->w) / 2; } else { if (pIButton->string16->style & SF_CENTER_RIGHT) { x = pIButton->size.w - pText->w - 5; } else { x = 5; } } } if (get_wstate(pIButton) == FC_WS_PRESSED) { x += 1; } else { y -= 1; } dest.x = pIButton->size.x + x; dest.y = pIButton->size.y + y; ret = alphablit(pText, NULL, pIButton->dst->surface, &dest); } FREESURFACE(pText); return 0; }
void w_plugins::draw_item(Plugins::iterator it, SDL_Surface* s, int16 x, int16 y, uint16 width, bool selected) const { y += font->get_ascent(); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); uint32 color; if (selected) { color = get_theme_color(ITEM_WIDGET, ACTIVE_STATE); } else if (it->enabled && it->compatible() && it->allowed()) { color = get_theme_color(ITEM_WIDGET, DEFAULT_STATE); } else { color = get_theme_color(ITEM_WIDGET, DISABLED_STATE); } std::string enabled; if (!it->compatible()) { enabled = " Incompatible"; } else if (!it->allowed()) { enabled = " Disallowed"; } else if (it->enabled) { enabled = " Enabled"; } else { enabled = " Disabled"; } int right_text_width = text_width(enabled.c_str(), font, style); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width - right_text_width); std::string name_and_version = it->name + " " + it->version; draw_text(s, name_and_version.c_str(), x, y, color, font, style); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); draw_text(s, enabled.c_str(), x + width - right_text_width, y, color, font, style); y += font->get_ascent() + 1; std::string types; if (it->solo_lua.size()) { types += ", Solo Lua"; } if (it->hud_lua.size()) { types += ", HUD"; } if (it->theme.size()) { types += ", Theme"; } if (it->shapes_patches.size()) { types += ", Shapes Patch"; } if (it->mmls.size()) { types += ", MML"; } if (it->stats_lua.size()) { types += ", Stats"; } types.erase(0, 2); right_text_width = text_width(types.c_str(), font, style | styleItalic); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); draw_text(s, types.c_str(), x + width - right_text_width, y, color, font, style | styleItalic); set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width - right_text_width); if (it->description.size()) { draw_text(s, it->description.c_str(), x, y, color, font, style); } else { draw_text(s, "No description", x, y, color, font, style); } set_drawing_clip_rectangle(SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); }
/************************************************************************** ... **************************************************************************/ static int redraw_edit_chain(struct EDIT *pEdt) { struct UniChar *pInputChain_TMP; SDL_Rect Dest, Dest_Copy = {0, 0, 0, 0}; int iStart_Mod_X; int ret; Dest_Copy.x = pEdt->pWidget->size.x; Dest_Copy.y = pEdt->pWidget->size.y; ret = (*baseclass_redraw)(pEdt->pWidget); if (ret != 0) { return ret; } /* blit theme */ Dest = Dest_Copy; alphablit(pEdt->pBg, NULL, pEdt->pWidget->dst->surface, &Dest); /* set start parametrs */ pInputChain_TMP = pEdt->pBeginTextChain; iStart_Mod_X = 0; Dest_Copy.y += (pEdt->pBg->h - pInputChain_TMP->pTsurf->h) / 2; Dest_Copy.x += pEdt->Start_X; /* draw loop */ while (pInputChain_TMP) { Dest_Copy.x += iStart_Mod_X; /* chech if we draw inside of edit rect */ if (Dest_Copy.x > pEdt->pWidget->size.x + pEdt->pBg->w - 4) { break; } if (Dest_Copy.x > pEdt->pWidget->size.x) { Dest = Dest_Copy; alphablit(pInputChain_TMP->pTsurf, NULL, pEdt->pWidget->dst->surface, &Dest); } iStart_Mod_X = pInputChain_TMP->pTsurf->w; /* draw cursor */ if (pInputChain_TMP == pEdt->pInputChain) { Dest = Dest_Copy; #if 0 putline(pEdt->pWidget->dst->surface, Dest.x - 1, Dest.y + (pEdt->pBg->h / 8), Dest.x - 1, Dest.y + pEdt->pBg->h - (pEdt->pBg->h / 4), get_theme_color(COLOR_THEME_EDITFIELD_CARET)); #endif /* save active element position */ pEdt->InputChain_X = Dest_Copy.x; } pInputChain_TMP = pInputChain_TMP->next; } /* while - draw loop */ widget_flush(pEdt->pWidget); return 0; }
/************************************************************************** ... **************************************************************************/ void redraw_widget_info_label(SDL_Rect *rect) { SDL_Surface *pText, *pBcgd; SDL_Rect srcrect, dstrect; SDL_Color color; struct widget *pWidget = pSellected_Widget; if (!pWidget || !pWidget->info_label) { return; } if (!pInfo_Label) { pInfo_Area = fc_calloc(1, sizeof(SDL_Rect)); color = pWidget->info_label->fgcol; pWidget->info_label->style |= TTF_STYLE_BOLD; pWidget->info_label->fgcol = *get_theme_color(COLOR_THEME_QUICK_INFO_TEXT); /* create string and bcgd theme */ pText = create_text_surf_from_str16(pWidget->info_label); pWidget->info_label->fgcol = color; pBcgd = create_filled_surface(pText->w + adj_size(10), pText->h + adj_size(6), SDL_SWSURFACE, get_theme_color(COLOR_THEME_QUICK_INFO_BG), TRUE); /* calculate start position */ if ((pWidget->dst->dest_rect.y + pWidget->size.y) - pBcgd->h - adj_size(6) < 0) { pInfo_Area->y = (pWidget->dst->dest_rect.y + pWidget->size.y) + pWidget->size.h + adj_size(3); } else { pInfo_Area->y = (pWidget->dst->dest_rect.y + pWidget->size.y) - pBcgd->h - adj_size(5); } if ((pWidget->dst->dest_rect.x + pWidget->size.x) + pBcgd->w + adj_size(5) > Main.screen->w) { pInfo_Area->x = (pWidget->dst->dest_rect.x + pWidget->size.x) - pBcgd->w - adj_size(5); } else { pInfo_Area->x = (pWidget->dst->dest_rect.x + pWidget->size.x) + adj_size(3); } pInfo_Area->w = pBcgd->w + adj_size(2); pInfo_Area->h = pBcgd->h + adj_size(3); pInfo_Label = SDL_DisplayFormatAlpha(pBcgd); FREESURFACE(pBcgd); /* draw text */ dstrect.x = adj_size(6); dstrect.y = adj_size(3); alphablit(pText, NULL, pInfo_Label, &dstrect); FREESURFACE(pText); /* draw frame */ putframe(pInfo_Label, 0, 0, pInfo_Label->w - 1, pInfo_Label->h - 1, get_theme_color(COLOR_THEME_QUICK_INFO_FRAME)); } if (rect) { dstrect.x = MAX(rect->x, pInfo_Area->x); dstrect.y = MAX(rect->y, pInfo_Area->y); srcrect.x = dstrect.x - pInfo_Area->x; srcrect.y = dstrect.y - pInfo_Area->y; srcrect.w = MIN((pInfo_Area->x + pInfo_Area->w), (rect->x + rect->w)) - dstrect.x; srcrect.h = MIN((pInfo_Area->y + pInfo_Area->h), (rect->y + rect->h)) - dstrect.y; alphablit(pInfo_Label, &srcrect, Main.screen, &dstrect); } else { alphablit(pInfo_Label, NULL, Main.screen, pInfo_Area); } if (correct_rect_region(pInfo_Area)) { SDL_UpdateRect(Main.screen, pInfo_Area->x, pInfo_Area->y, pInfo_Area->w, pInfo_Area->h); } return; }
/************************************************************************** Popup (or raise) the short player list dialog version. **************************************************************************/ void popup_players_nations_dialog(void) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_Surface *pLogo = NULL; SDL_String16 *pStr; char cBuf[128], *state; int n = 0, w = 0, units_h = 0; const struct player_diplstate *pDS; SDL_Rect area; if (pShort_Players_Dlg) { return; } pShort_Players_Dlg = fc_calloc(1, sizeof(struct ADVANCED_DLG)); /* TRANS: Nations report title */ pStr = create_str16_from_char(_("Nations") , adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = players_nations_window_dlg_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_WINDOW, pWindow); pShort_Players_Dlg->pEndWidgetList = pWindow; area = pWindow->area; /* ---------- */ /* exit button */ pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"), adj_font(12)); area.w = MAX(area.w, pBuf->size.w + adj_size(10)); pBuf->action = exit_players_nations_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BUTTON, pBuf); /* ---------- */ players_iterate(pPlayer) { if (pPlayer != client.conn.playing) { if(!pPlayer->is_alive || is_barbarian(pPlayer)) { continue; } pDS = player_diplstate_get(client.conn.playing, pPlayer); if(pPlayer->ai_controlled) { state = _("AI"); } else { if (pPlayer->is_connected) { if (pPlayer->phase_done) { state = _("done"); } else { state = _("moving"); } } else { state = _("disconnected"); } } if(pDS->type == DS_CEASEFIRE) { fc_snprintf(cBuf, sizeof(cBuf), "%s(%s) - %d %s", nation_adjective_for_player(pPlayer), state, pDS->turns_left, PL_("turn", "turns", pDS->turns_left)); } else { fc_snprintf(cBuf, sizeof(cBuf), "%s(%s)", nation_adjective_for_player(pPlayer), state); } pStr = create_str16_from_char(cBuf, adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pLogo = get_nation_flag_surface(nation_of_player(pPlayer)); pBuf = create_iconlabel(pLogo, pWindow->dst, pStr, (/*WF_FREE_THEME|*/WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE)); /* now add some eye candy ... */ switch (pDS->type) { case DS_ARMISTICE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_WAR: if(can_meet_with_player(pPlayer) || can_intel_with_player(pPlayer)) { set_wstate(pBuf, FC_WS_NORMAL); pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR); } else { pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_PLRDLG_WAR_RESTRICTED)); } break; case DS_CEASEFIRE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_PEACE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_ALLIANCE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_NO_CONTACT: pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT)); break; default: set_wstate(pBuf, FC_WS_NORMAL); break; } pBuf->string16->bgcol = (SDL_Color) {0, 0, 0, 0}; pBuf->data.player = pPlayer; pBuf->action = player_nation_callback; add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(w, pBuf->size.w); area.h += pBuf->size.h; if (n > 19) { set_wflag(pBuf, WF_HIDDEN); } n++; } } players_iterate_end; pShort_Players_Dlg->pBeginWidgetList = pBuf; pShort_Players_Dlg->pBeginActiveWidgetList = pShort_Players_Dlg->pBeginWidgetList; pShort_Players_Dlg->pEndActiveWidgetList = pWindow->prev->prev; pShort_Players_Dlg->pActiveWidgetList = pShort_Players_Dlg->pEndActiveWidgetList; /* ---------- */ if (n > 20) { units_h = create_vertical_scrollbar(pShort_Players_Dlg, 1, 20, TRUE, TRUE); pShort_Players_Dlg->pScroll->count = n; n = units_h; area.w += n; units_h = 20 * pBuf->size.h; } else { units_h = area.h; } /* ---------- */ area.h = units_h; resize_window(pWindow, NULL, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h + pWindow->area.h) + area.h); area = pWindow->area; widget_set_position(pWindow, ((Main.event.motion.x + pWindow->size.w + adj_size(10) < Main.screen->w) ? (Main.event.motion.x + adj_size(10)) : (Main.screen->w - pWindow->size.w - adj_size(10))), ((Main.event.motion.y - adj_size(2) + pWindow->size.h < Main.screen->h) ? (Main.event.motion.y - adj_size(2)) : (Main.screen->h - pWindow->size.h - adj_size(10)))); w = area.w; if (pShort_Players_Dlg->pScroll) { w -= n; } /* exit button */ pBuf = pWindow->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); /* cities */ pBuf = pBuf->prev; setup_vertical_widgets_position(1, area.x, area.y, w, 0, pShort_Players_Dlg->pBeginActiveWidgetList, pBuf); if (pShort_Players_Dlg->pScroll) { setup_vertical_scrollbar_area(pShort_Players_Dlg->pScroll, area.x + area.w, area.y, area.h, TRUE); } /* -------------------- */ /* redraw */ redraw_group(pShort_Players_Dlg->pBeginWidgetList, pWindow, 0); widget_mark_dirty(pWindow); flush_dirty(); }
/************************************************************************** Popup (or raise) the player list dialog. **************************************************************************/ void popup_players_dialog(bool raise) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_Surface *pLogo = NULL, *pZoomed = NULL; SDL_String16 *pStr; SDL_Rect dst; int i, n, h; double a, b, r; SDL_Rect area; if (pPlayers_Dlg) { return; } n = 0; players_iterate(pPlayer) { if(is_barbarian(pPlayer)) { continue; } n++; } players_iterate_end; if(n < 2) { return; } pPlayers_Dlg = fc_calloc(1, sizeof(struct SMALL_DLG)); pStr = create_str16_from_char(_("Players"), adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = players_window_dlg_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_WINDOW, pWindow); pPlayers_Dlg->pEndWidgetList = pWindow; /* ---------- */ /* exit button */ pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"), adj_font(12)); pBuf->action = exit_players_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BUTTON, pBuf); /* ---------- */ for(i = 0; i<DS_LAST; i++) { switch (i) { case DS_ARMISTICE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_NEUTRAL_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_neutral_status_callback; pBuf->key = SDLK_n; break; case DS_WAR: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_WAR_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_war_status_callback; pBuf->key = SDLK_w; break; case DS_CEASEFIRE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_CEASEFIRE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_ceasefire_status_callback; pBuf->key = SDLK_c; break; case DS_PEACE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_PEACE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_pease_status_callback; pBuf->key = SDLK_p; break; case DS_ALLIANCE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_alliance_status_callback; pBuf->key = SDLK_a; break; default: /* no contact */ continue; break; } set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(ID_CHECKBOX, pBuf); } /* ---------- */ players_iterate(pPlayer) { if(is_barbarian(pPlayer)) { continue; } pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= (TTF_STYLE_BOLD|SF_CENTER); pLogo = get_nation_flag_surface(nation_of_player(pPlayer)); { /* Aim for a flag height of 60 pixels, but draw smaller flags if there * are more players */ double zoom = DEFAULT_ZOOM * (60.0 - n) / pLogo->h; pZoomed = zoomSurface(pLogo, zoom, zoom, 1); } pBuf = create_icon2(pZoomed, pWindow->dst, WF_RESTORE_BACKGROUND | WF_WIDGET_HAS_INFO_LABEL | WF_FREE_THEME); pBuf->info_label = pStr; if(!pPlayer->is_alive) { pStr = create_str16_from_char(_("R.I.P.") , adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_TEXT); pLogo = create_text_surf_from_str16(pStr); FREESTRING16(pStr); dst.x = (pZoomed->w - pLogo->w) / 2; dst.y = (pZoomed->h - pLogo->h) / 2; alphablit(pLogo, NULL, pZoomed, &dst); FREESURFACE(pLogo); } if(pPlayer->is_alive) { set_wstate(pBuf, FC_WS_NORMAL); } pBuf->data.player = pPlayer; pBuf->action = player_callback; add_to_gui_list(ID_LABEL, pBuf); } players_iterate_end; pPlayers_Dlg->pBeginWidgetList = pBuf; resize_window(pWindow, NULL, NULL, adj_size(500), adj_size(400)); area = pWindow->area; r = MIN(area.w, area.h); r -= ((MAX(pBuf->size.w, pBuf->size.h) * 2)); r /= 2; a = (2.0 * M_PI) / n; widget_set_position(pWindow, (Main.screen->w - pWindow->size.w) / 2, (Main.screen->h - pWindow->size.h) / 2); /* exit button */ pBuf = pWindow->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); n = area.y; pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pStr->bgcol = (SDL_Color) {0, 0, 0, 0}; for(i = 0; i<DS_LAST; i++) { switch (i) { case DS_ARMISTICE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE); break; case DS_WAR: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR); break; case DS_CEASEFIRE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE); break; case DS_PEACE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE); break; case DS_ALLIANCE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE); break; default: /* no contact */ continue; break; } copy_chars_to_string16(pStr, diplstate_type_translated_name(i)); pLogo = create_text_surf_from_str16(pStr); pBuf = pBuf->prev; h = MAX(pBuf->size.h, pLogo->h); pBuf->size.x = area.x + adj_size(5); pBuf->size.y = n + (h - pBuf->size.h) / 2; dst.x = adj_size(5) + pBuf->size.w + adj_size(6); dst.y = n + (h - pLogo->h) / 2; alphablit(pLogo, NULL, pWindow->theme, &dst); n += h; FREESURFACE(pLogo); } FREESTRING16(pStr); /* first player shield */ pBuf = pBuf->prev; pBuf->size.x = area.x + area.w / 2 - pBuf->size.w / 2; pBuf->size.y = area.y + area.h / 2 - r - pBuf->size.h / 2; n = 1; if(pBuf != pPlayers_Dlg->pBeginWidgetList) { do{ pBuf = pBuf->prev; b = M_PI_2 + n * a; pBuf->size.x = area.x + area.w / 2 - r * cos(b) - pBuf->size.w / 2; pBuf->size.y = area.y + area.h / 2 - r * sin(b) - pBuf->size.h / 2; n++; } while(pBuf != pPlayers_Dlg->pBeginWidgetList); } players_dialog_update(); }
/************************************************************************** Update all information in the player list dialog. **************************************************************************/ void real_players_dialog_update(void) { if(pPlayers_Dlg) { struct widget *pPlayer0, *pPlayer1; struct player *pPlayer; SDL_Rect dst0, dst1; int i; struct astring astr = ASTRING_INIT; /* redraw window */ widget_redraw(pPlayers_Dlg->pEndWidgetList); /* exit button -> neutral -> war -> casefire -> peace -> alliance */ pPlayer0 = pPlayers_Dlg->pEndWidgetList->prev->prev->prev->prev->prev->prev; do{ pPlayer0 = pPlayer0->prev; pPlayer1 = pPlayer0; pPlayer = pPlayer0->data.player; for (i = 0; i < num_player_dlg_columns; i++) { if (player_dlg_columns[i].show) { switch (player_dlg_columns[i].type) { case COL_TEXT: case COL_RIGHT_TEXT: astr_add_line(&astr, "%s: %s", player_dlg_columns[i].title, player_dlg_columns[i].func(pPlayer)); break; case COL_BOOLEAN: astr_add_line(&astr, "%s: %s", player_dlg_columns[i].title, player_dlg_columns[i].bool_func(pPlayer) ? _("Yes") : _("No")); break; default: break; } } } copy_chars_to_string16(pPlayer0->info_label, astr_str(&astr)); astr_free(&astr); /* now add some eye candy ... */ if(pPlayer1 != pPlayers_Dlg->pBeginWidgetList) { dst0.x = pPlayer0->size.x + pPlayer0->size.w / 2; dst0.y = pPlayer0->size.y + pPlayer0->size.h / 2; do{ pPlayer1 = pPlayer1->prev; if (have_diplomat_info_about(pPlayer) || have_diplomat_info_about(pPlayer1->data.player)) { dst1.x = pPlayer1->size.x + pPlayer1->size.w / 2; dst1.y = pPlayer1->size.y + pPlayer1->size.h / 2; switch (player_diplstate_get(pPlayer, pPlayer1->data.player)->type) { case DS_ARMISTICE: if(SDL_Client_Flags & CF_DRAW_PLAYERS_NEUTRAL_STATUS) { putline(pPlayer1->dst->surface, dst0.x, dst0.y, dst1.x, dst1.y, get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE)); } break; case DS_WAR: if(SDL_Client_Flags & CF_DRAW_PLAYERS_WAR_STATUS) { putline(pPlayer1->dst->surface, dst0.x, dst0.y, dst1.x, dst1.y, get_theme_color(COLOR_THEME_PLRDLG_WAR)); } break; case DS_CEASEFIRE: if (SDL_Client_Flags & CF_DRAW_PLAYERS_CEASEFIRE_STATUS) { putline(pPlayer1->dst->surface, dst0.x, dst0.y, dst1.x, dst1.y, get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE)); } break; case DS_PEACE: if (SDL_Client_Flags & CF_DRAW_PLAYERS_PEACE_STATUS) { putline(pPlayer1->dst->surface, dst0.x, dst0.y, dst1.x, dst1.y, get_theme_color(COLOR_THEME_PLRDLG_PEACE)); } break; case DS_ALLIANCE: if (SDL_Client_Flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS) { putline(pPlayer1->dst->surface, dst0.x, dst0.y, dst1.x, dst1.y, get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE)); } break; default: /* no contact */ break; } } } while(pPlayer1 != pPlayers_Dlg->pBeginWidgetList); } } while(pPlayer0 != pPlayers_Dlg->pBeginWidgetList); /* -------------------- */ /* redraw */ redraw_group(pPlayers_Dlg->pBeginWidgetList, pPlayers_Dlg->pEndWidgetList->prev, 0); widget_mark_dirty(pPlayers_Dlg->pEndWidgetList); flush_dirty(); } }