Example #1
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;
}
Example #2
0
/**************************************************************************
  Create a canvas of the given size (with alpha channel).
**************************************************************************/
struct canvas *canvas_create_with_alpha(int width, int height)
{
  struct canvas *result = fc_malloc(sizeof(*result));	

  result->surf = create_surf_alpha(width, height, SDL_SWSURFACE);

  return result;
}
Example #3
0
/**************************************************************************
  Create Text Surface from SDL_String16
**************************************************************************/
static SDL_Surface *create_str16_surf(SDL_String16 * pString)
{
  SDL_Surface *pText = NULL; /* FIXME: possibly uninitialized */

  if (!pString) {
    return NULL;
  }

  if (!((pString->style & 0x0F) & TTF_STYLE_NORMAL)) {
    TTF_SetFontStyle(pString->font, (pString->style & 0x0F));
  }

  switch (pString->render) {
  case 0:
    pText = TTF_RenderUNICODE_Shaded(pString->font,
				     pString->text, pString->fgcol,
				     pString->bgcol);
    break;
  case 1:
  {
    SDL_Surface *pTmp = TTF_RenderUNICODE_Solid(pString->font,
				    pString->text, pString->fgcol);

    if ((pText = SDL_DisplayFormat(pTmp)) == NULL) {
      log_error("SDL_create_str16_surf: couldn't convert text "
                "to display format: %s", SDL_GetError());
      pText = pTmp;
    } else {
      FREESURFACE( pTmp );
    }
    
  }
  break;
  case 2:
    pText = TTF_RenderUNICODE_Blended(pString->font,
				      pString->text, pString->fgcol);
    break;
  }

  if (pText != NULL) {
    log_debug("SDL_create_str16_surf: Font is generally %d big, and "
              "string is %hd big", TTF_FontHeight(pString->font), pText->h);
    log_debug("SDL_create_str16_surf: String is %d length", pText->w);
  } else {
    log_debug("SDL_create_str16_surf: pText NULL");
    pText = create_surf_alpha(0, 0, SDL_SWSURFACE);
  }

  if (!((pString->style & 0x0F) & TTF_STYLE_NORMAL)) {
    TTF_SetFontStyle(pString->font, TTF_STYLE_NORMAL);
  }

  return pText;
}
Example #4
0
/****************************************************************************
  Fill the area covered by the sprite with the given color.
****************************************************************************/
void canvas_fog_sprite_area(struct canvas *pcanvas, struct sprite *psprite,
			    int canvas_x, int canvas_y)
{
  SDL_Rect dst = {canvas_x, canvas_y, GET_SURF(psprite)->w,
                                      GET_SURF(psprite)->h};
                                      
  SDL_Surface *tmp_surf = create_surf_alpha(GET_SURF(psprite)->w, 
                                            GET_SURF(psprite)->h,
                                            SDL_SWSURFACE);
  SDL_FillRect(tmp_surf, NULL, SDL_MapRGBA(tmp_surf->format, 0, 0, 0, 64));
  alphablit(tmp_surf, NULL, pcanvas->surf, &dst);
  FREESURFACE(tmp_surf);
}
Example #5
0
/**************************************************************************
  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;
}
Example #6
0
/**************************************************************************
  ...
**************************************************************************/
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);
    
}
Example #7
0
/**************************************************************************
  Create background image for buttons, iconbuttons and edit fields
  then return  pointer to this image.

  Graphic is taken from pTheme surface and blit to new created image.

  Length and height depend of iText_with, iText_high parameters.

  Type of image depend of "state" parameter.
    state = 0 - normal
    state = 1 - selected
    state = 2 - pressed
    state = 3 - disabled
**************************************************************************/
SDL_Surface *create_bcgnd_surf(SDL_Surface * pTheme, Uint8 state,
                               Uint16 Width, Uint16 High)
{
  bool zoom;
  int iTile_width_len_end, iTile_width_len_mid, iTile_count_len_mid;
  int iTile_width_high_end, iTile_width_high_mid, iTile_count_high_mid;
  int i, j;

  SDL_Rect src, des;
  SDL_Surface *pBackground = NULL;

  int iStart_y = (pTheme->h / 4) * state;

  iTile_width_len_end = pTheme->w / 16;
  iTile_width_len_mid = pTheme->w - (iTile_width_len_end * 2);

  iTile_count_len_mid =
      (Width - (iTile_width_len_end * 2)) / iTile_width_len_mid;

  /* corrections I */
  if (((iTile_count_len_mid *
	iTile_width_len_mid) + (iTile_width_len_end * 2)) < Width) {
    iTile_count_len_mid++;
  }

  iTile_width_high_end = pTheme->h / 16;
  iTile_width_high_mid = (pTheme->h / 4) - (iTile_width_high_end * 2);
  iTile_count_high_mid =
      (High - (iTile_width_high_end * 2)) / iTile_width_high_mid;

  /* corrections II */
  if (((iTile_count_high_mid *
	iTile_width_high_mid) + (iTile_width_high_end * 2)) < High) {
    iTile_count_high_mid++;
  }

  i = MAX(iTile_width_len_end * 2, Width);
  j = MAX(iTile_width_high_end * 2, High);
  zoom = ((i != Width) ||  (j != High));
  
  /* now allocate memory */
  pBackground = create_surf_alpha(i, j, SDL_SWSURFACE);

  /* copy left end */

  /* copy left top end */
  src.x = 0;
  src.y = iStart_y;
  src.w = iTile_width_len_end;
  src.h = iTile_width_high_end;

  des.x = 0;
  des.y = 0;
  alphablit(pTheme, &src, pBackground, &des);

  /* copy left middels parts */
  src.y = iStart_y + iTile_width_high_end;
  src.h = iTile_width_high_mid;
  for (i = 0; i < iTile_count_high_mid; i++) {
    des.y = iTile_width_high_end + i * iTile_width_high_mid;
    alphablit(pTheme, &src, pBackground, &des);
  }

  /* copy left boton end */
  src.y = iStart_y + ((pTheme->h / 4) - iTile_width_high_end);
  src.h = iTile_width_high_end;
  des.y = pBackground->h - iTile_width_high_end;
  clear_surface(pBackground, &des);
  alphablit(pTheme, &src, pBackground, &des);

  /* copy middle parts without right end part */

  src.x = iTile_width_len_end;
  src.y = iStart_y;
  src.w = iTile_width_len_mid;

  for (i = 0; i < iTile_count_len_mid; i++) {

    /* top */
    des.x = iTile_width_len_end + i * iTile_width_len_mid;
    des.y = 0;
    src.y = iStart_y;
    alphablit(pTheme, &src, pBackground, &des);

    /*  middels */
    src.y = iStart_y + iTile_width_high_end;
    src.h = iTile_width_high_mid;
    for (j = 0; j < iTile_count_high_mid; j++) {
      des.y = iTile_width_high_end + j * iTile_width_high_mid;
      alphablit(pTheme, &src, pBackground, &des);
    }

    /* bottom */
    src.y = iStart_y + ((pTheme->h / 4) - iTile_width_high_end);
    src.h = iTile_width_high_end;
    des.y = pBackground->h - iTile_width_high_end;
    clear_surface(pBackground, &des);    
    alphablit(pTheme, &src, pBackground, &des);
  }

  /* copy right end */
  src.x = pTheme->w - iTile_width_len_end;
  src.y = iStart_y;
  src.w = iTile_width_len_end;

  des.x = pBackground->w - iTile_width_len_end;
  des.y = 0;

  alphablit(pTheme, &src, pBackground, &des);

  /*  middels */
  src.y = iStart_y + iTile_width_high_end;
  src.h = iTile_width_high_mid;
  for (i = 0; i < iTile_count_high_mid; i++) {
    des.y = iTile_width_high_end + i * iTile_width_high_mid;
    alphablit(pTheme, &src, pBackground, &des);
  }

  /*boton */
  src.y = iStart_y + ((pTheme->h / 4) - iTile_width_high_end);
  src.h = iTile_width_high_end;
  des.y = pBackground->h - iTile_width_high_end;
  clear_surface(pBackground, &des);  
  alphablit(pTheme, &src, pBackground, &des);
  
  if (zoom)
  {
    SDL_Surface *pZoom = ResizeSurface(pBackground, Width, High, 1);
    FREESURFACE(pBackground);
    pBackground = pZoom;
  }
  
  return pBackground;
}
Example #8
0
/**************************************************************************
  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();
}