/************************************************************************** ... **************************************************************************/ 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; }
/********************************************************************** Set city icons sprite value; should only happen after tileset_load_tiles(tileset). ***********************************************************************/ void tilespec_setup_city_icons(void) { struct sprite *pSpr = NULL; pIcons = ( struct City_Icon *)fc_calloc(1, sizeof( struct City_Icon )); load_city_icon_surface(pSpr, pBIG_Food_Corr, "city.food_waste"); load_city_icon_surface(pSpr, pBIG_Shield_Corr, "city.shield_waste"); load_city_icon_surface(pSpr, pBIG_Trade_Corr, "city.trade_waste"); load_city_icon_surface(pSpr, pBIG_Food, "city.food"); pIcons->pBIG_Food_Surplus = crop_rect_from_surface(pIcons->pBIG_Food, NULL); SDL_SetAlpha(pIcons->pBIG_Food_Surplus, SDL_SRCALPHA, 128); load_city_icon_surface(pSpr, pBIG_Shield, "city.shield"); pIcons->pBIG_Shield_Surplus = crop_rect_from_surface(pIcons->pBIG_Shield, NULL); SDL_SetAlpha(pIcons->pBIG_Shield_Surplus, SDL_SRCALPHA, 128); load_city_icon_surface(pSpr, pBIG_Trade, "city.trade"); load_city_icon_surface(pSpr, pBIG_Luxury, "city.lux"); load_city_icon_surface(pSpr, pBIG_Coin, "city.coin"); load_city_icon_surface(pSpr, pBIG_Colb, "city.colb"); load_city_icon_surface(pSpr, pBIG_Face, "city.red_face"); load_city_icon_surface(pSpr, pBIG_Coin_Corr, "city.dark_coin"); load_city_icon_surface(pSpr, pBIG_Coin_UpKeep, "city.unkeep_coin"); /* small icon */ load_city_icon_surface(pSpr, pFood, "city.small_food"); load_city_icon_surface(pSpr, pShield, "city.small_shield"); load_city_icon_surface(pSpr, pTrade, "city.small_trade"); load_city_icon_surface(pSpr, pFace, "city.small_red_face"); load_city_icon_surface(pSpr, pLuxury, "city.small_lux"); load_city_icon_surface(pSpr, pCoin, "city.small_coin"); load_city_icon_surface(pSpr, pColb, "city.small_colb"); load_city_icon_surface(pSpr, pPollution, "city.pollution"); /* ================================================================= */ load_city_icon_surface(pSpr, pPolice, "city.police"); /* ================================================================= */ pIcons->pWorklist = create_surf_alpha(9,9, SDL_SWSURFACE); SDL_FillRect(pIcons->pWorklist, NULL, SDL_MapRGB(pIcons->pWorklist->format, 255, 255,255)); putframe(pIcons->pWorklist, 0,0, pIcons->pWorklist->w - 1, pIcons->pWorklist->h - 1, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); putline(pIcons->pWorklist, 3, 2, 5, 2, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); putline(pIcons->pWorklist, 3, 4, 7, 4, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); putline(pIcons->pWorklist, 3, 6, 6, 6, map_rgba(pIcons->pWorklist->format, *get_game_colorRGB(COLOR_THEME_CITYREP_FRAME))); /* ================================================================= */ /* force reload citizens icons */ pIcons->style = 999; }
/************************************************************************** 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 setup_auxiliary_tech_icons(void) { SDL_Color bg_color = {255, 255, 255, 136}; SDL_Surface *pSurf; SDL_String16 *pStr = create_str16_from_char(_("None"), adj_font(10)); pStr->style |= (TTF_STYLE_BOLD | SF_CENTER); /* create icons */ pSurf = create_surf_alpha(adj_size(50), adj_size(50), SDL_SWSURFACE); SDL_FillRect(pSurf, NULL, map_rgba(pSurf->format, bg_color)); putframe(pSurf, 0 , 0, pSurf->w - 1, pSurf->h - 1, map_rgba(pSurf->format, *get_game_colorRGB(COLOR_THEME_SCIENCEDLG_FRAME))); pNeutral_Tech_Icon = SDL_DisplayFormatAlpha(pSurf); pNone_Tech_Icon = SDL_DisplayFormatAlpha(pSurf); pFuture_Tech_Icon = SDL_DisplayFormatAlpha(pSurf); FREESURFACE(pSurf); /* None */ pSurf = create_text_surf_from_str16(pStr); blit_entire_src(pSurf, pNone_Tech_Icon , (adj_size(50) - pSurf->w) / 2 , (adj_size(50) - pSurf->h) / 2); FREESURFACE(pSurf); /* TRANS: Future Technology */ copy_chars_to_string16(pStr, _("FT")); pSurf = create_text_surf_from_str16(pStr); blit_entire_src(pSurf, pFuture_Tech_Icon, (adj_size(50) - pSurf->w) / 2 , (adj_size(50) - pSurf->h) / 2); FREESURFACE(pSurf); FREESTRING16(pStr); }
/************************************************************************** ... **************************************************************************/ 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; }
/************************************************************************** Do any necessary pre-initialization of the UI, if necessary. **************************************************************************/ void ui_init(void) { char device[20]; /* struct widget *pInit_String = NULL;*/ SDL_Surface *pBgd; Uint32 iSDL_Flags; button_behavior.counting = FALSE; button_behavior.button_down_ticks = 0; button_behavior.hold_state = MB_HOLD_SHORT; button_behavior.event = fc_calloc(1, sizeof(SDL_MouseButtonEvent)); SDL_Client_Flags = 0; iSDL_Flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; /* auto center new windows in X enviroment */ putenv((char *)"SDL_VIDEO_CENTERED=yes"); init_sdl(iSDL_Flags); log_normal(_("Using Video Output: %s"), SDL_VideoDriverName(device, sizeof(device))); /* create splash screen */ #ifdef SMALL_SCREEN { SDL_Surface *pTmpSurf = load_surf(fileinfoname(get_data_dirs(), "misc/intro.png")); pBgd = zoomSurface(pTmpSurf, DEFAULT_ZOOM, DEFAULT_ZOOM, 0); FREESURFACE(pTmpSurf); } #else /* SMALL_SCREEN */ pBgd = load_surf(fileinfoname(get_data_dirs(), "misc/intro.png")); #endif /* SMALL_SCREEN */ if (pBgd && SDL_GetVideoInfo()->wm_available) { set_video_mode(pBgd->w, pBgd->h, SDL_SWSURFACE | SDL_ANYFORMAT); #if 0 /* * call this for other than X enviroments - currently not supported. */ center_main_window_on_screen(); #endif /* 0 */ alphablit(pBgd, NULL, Main.map, NULL); putframe(Main.map, 0, 0, Main.map->w - 1, Main.map->h - 1, &(SDL_Color) { 255, 255, 255, 255 }); FREESURFACE(pBgd); SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); } else { #ifndef SMALL_SCREEN set_video_mode(640, 480, SDL_SWSURFACE | SDL_ANYFORMAT); #else /* SMALL_SCREEN */ set_video_mode(320, 240, SDL_SWSURFACE | SDL_ANYFORMAT); #endif /* SMALL_SCREEN */ if(pBgd) { blit_entire_src(pBgd, Main.map, (Main.map->w - pBgd->w) / 2, (Main.map->h - pBgd->h) / 2); FREESURFACE(pBgd); } else { SDL_FillRect(Main.map, NULL, SDL_MapRGB(Main.map->format, 0, 0, 128)); SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); } } #if 0 /* create label beackground */ pBgd = create_surf_alpha(adj_size(350), adj_size(50), SDL_SWSURFACE); SDL_FillRect(pBgd, NULL, SDL_MapRGBA(pBgd->format, 255, 255, 255, 128)); putframe(pBgd, 0, 0, pBgd->w - 1, pBgd->h - 1, SDL_MapRGB(pBgd->format, 0, 0, 0)); pInit_String = create_iconlabel(pBgd, Main.gui, create_str16_from_char(_("Initializing Client"), adj_font(20)), WF_ICON_CENTER|WF_FREE_THEME); pInit_String->string16->style |= SF_CENTER; draw_label(pInit_String, (Main.screen->w - pInit_String->size.w) / 2, (Main.screen->h - pInit_String->size.h) / 2); flush_all(); copy_chars_to_string16(pInit_String->string16, _("Waiting for the beginning of the game")); #endif /* 0 */ flush_all(); }