Esempio n. 1
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);
}
Esempio n. 2
0
/**************************************************************************
  ...
**************************************************************************/
void refresh_widget_background(struct widget *pWidget)
{
  if (pWidget) {
    if (pWidget->gfx && pWidget->gfx->w == pWidget->size.w &&
      				pWidget->gfx->h == pWidget->size.h) {
      clear_surface(pWidget->gfx, NULL);
      alphablit(pWidget->dst->surface, &pWidget->size, pWidget->gfx, NULL);
    } else {
      FREESURFACE(pWidget->gfx);
      pWidget->gfx = crop_rect_from_surface(pWidget->dst->surface, &pWidget->size);
    }
  }
}
Esempio n. 3
0
static int toggle_draw_alliance_status_callback(struct widget *pWidget)
{
  if (Main.event.button.button == SDL_BUTTON_LEFT) {
    /* exit button -> neutral -> war -> casefire -> peace -> alliance */
    struct widget *pPlayer = pPlayers_Dlg->pEndWidgetList->prev->prev->prev->prev->prev->prev;
    SDL_Client_Flags ^= CF_DRAW_PLAYERS_ALLIANCE_STATUS;
    do{
      pPlayer = pPlayer->prev;
      FREESURFACE(pPlayer->gfx);
    } while(pPlayer != pPlayers_Dlg->pBeginWidgetList);
    players_dialog_update();
  }
  return -1;
}
Esempio n. 4
0
/**************************************************************************
   ...
**************************************************************************/
void widget_free(struct widget **pWidget)
{
  struct widget *pGUI = *pWidget;
  
  if ((get_wflags(pGUI) & WF_FREE_STRING) == WF_FREE_STRING) {
    FREESTRING16(pGUI->string16);
  }
  if ((get_wflags(pGUI) & WF_WIDGET_HAS_INFO_LABEL)
      == WF_WIDGET_HAS_INFO_LABEL) {
    FREESTRING16(pGUI->info_label);
  }
  if ((get_wflags(pGUI) & WF_FREE_GFX) == WF_FREE_GFX) {
    FREESURFACE(pGUI->gfx);
  }
  if ((get_wflags(pGUI) & WF_FREE_THEME) == WF_FREE_THEME) {
    if (get_wtype(pGUI) == WT_CHECKBOX) {
      FREESURFACE(pGUI->private_data.cbox->pTRUE_Theme);
      FREESURFACE(pGUI->private_data.cbox->pFALSE_Theme);
    } else {
      FREESURFACE(pGUI->theme);
    }
  }
  if ((get_wflags(pGUI) & WF_FREE_THEME2) == WF_FREE_THEME2) {
    FREESURFACE(pGUI->theme2);
  }
  if ((get_wflags(pGUI) & WF_FREE_DATA) == WF_FREE_DATA) {
    FC_FREE(pGUI->data.ptr);
  }
  if ((get_wflags(pGUI) & WF_FREE_PRIVATE_DATA) == WF_FREE_PRIVATE_DATA) {
    FC_FREE(pGUI->private_data.ptr);
  }
  if (NULL != pGUI->destroy) {
    pGUI->destroy(pGUI);
  }

  FC_FREE(*pWidget);
}
Esempio n. 5
0
/**************************************************************************
  Create ( malloc ) Theme Icon (theme)Button Widget structure.

  Icon Theme graphic is taken from 'pIcon_theme' surface ( change with
  button changes ); Button Theme graphic is taken from pTheme->Button
  surface; Text is taken from 'pString16'.

  This function determinate future size of Button ( width, high ) and
  save this in: pWidget->size rectangle ( SDL_Rect )

  function return pointer to allocated Button Widget.
**************************************************************************/
struct widget * create_themeicon_button(SDL_Surface *pIcon_theme,
		struct gui_layer *pDest, SDL_String16 *pString16, Uint32 flags)
{
  /* extract a single icon */
  SDL_Surface *pIcon = create_icon_from_theme(pIcon_theme, 1);
  struct widget *pButton = create_icon_button(pIcon, pDest, pString16, flags);

  FREESURFACE(pButton->theme2);
  pButton->theme2 = pIcon_theme;
  set_wtype(pButton, WT_TI_BUTTON);

  pButton->redraw = redraw_tibutton;

  return pButton;
}
Esempio n. 6
0
/****************************************************************************
  Draw a full sprite onto the canvas.  If "fog" is specified draw it with
  fog.
****************************************************************************/
void canvas_put_sprite_fogged(struct canvas *pcanvas,
			      int canvas_x, int canvas_y,
			      struct sprite *psprite,
			      bool fog, int fog_x, int fog_y)
{
  SDL_Rect dst = {canvas_x, canvas_y, 0, 0};

  if (fog) {
    SDL_Surface *tmp_surf = blend_surface(GET_SURF(psprite), 160);
    alphablit(tmp_surf, NULL, pcanvas->surf, &dst);
    FREESURFACE(tmp_surf);
  } else {
    canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, psprite);
  }

}
Esempio n. 7
0
/****************************************************************************
  Create a new sprite by cropping and taking only the given portion of
  the image.

  source gives the sprite that is to be cropped.

  x,y, width, height gives the rectangle to be cropped.  The pixel at
  position of the source sprite will be at (0,0) in the new sprite, and
  the new sprite will have dimensions (width, height).

  mask gives an additional mask to be used for clipping the new
  sprite. Only the transparency value of the mask is used in
  crop_sprite. The formula is: dest_trans = src_trans *
  mask_trans. Note that because the transparency is expressed as an
  integer it is common to divide it by 256 afterwards.

  mask_offset_x, mask_offset_y is the offset of the mask relative to the
  origin of the source image.  The pixel at (mask_offset_x,mask_offset_y)
  in the mask image will be used to clip pixel (0,0) in the source image
  which is pixel (-x,-y) in the new image.
****************************************************************************/
struct sprite *crop_sprite(struct sprite *source,
			   int x, int y, int width, int height,
			   struct sprite *mask,
			   int mask_offset_x, int mask_offset_y)
{
  SDL_Rect src_rect = {(Sint16) x, (Sint16) y, (Uint16) width, (Uint16) height};
  SDL_Surface *pSrc = crop_rect_from_surface(GET_SURF(source), &src_rect);
  SDL_Surface *pDest = NULL;

  if (mask) {
    pDest = mask_surface(pSrc, mask->psurface, x - mask_offset_x, y - mask_offset_y);
    FREESURFACE(pSrc);    
    return ctor_sprite(pDest);
  }

  return ctor_sprite(pSrc);
}
Esempio n. 8
0
/****************************************************************************
  Draw the text onto the canvas in the given color and font.  The canvas
  position does not account for the ascent of the text; this function must
  take care of this manually.  The text will not be NULL but may be empty.
****************************************************************************/
void canvas_put_text(struct canvas *pcanvas, int canvas_x, int canvas_y,
		     enum client_font font, struct color *pcolor,
		     const char *text)
{
  SDL_Surface *pTmp;
  SDL_String16 *pText = create_string16(NULL, 0, *fonts[font]);
  copy_chars_to_string16(pText, text);
    
  pText->fgcol = *pcolor->color;
  pText->bgcol = (SDL_Color) {0, 0, 0, 0};
 
  pTmp = create_text_surf_from_str16(pText);
  
  blit_entire_src(pTmp, pcanvas->surf, canvas_x, canvas_y);

  FREESTRING16(pText);  
  FREESURFACE(pTmp);
}
Esempio n. 9
0
/**************************************************************************
  ...
**************************************************************************/
struct widget * create_textcheckbox(struct gui_layer *pDest, bool state,
		  SDL_String16 *pStr, Uint32 flags)
{
  struct widget *pCBox;
  struct CHECKBOX *pTmp;
  SDL_Surface *pSurf, *pIcon;
  struct widget *pTmpWidget;

  if (!pStr) {
    return create_checkbox(pDest, state, flags);
  }
  
  pTmp = fc_calloc(1, sizeof(struct CHECKBOX));
    
  if (state) {
    pSurf = pTheme->CBOX_Sell_Icon;
  } else {
    pSurf = pTheme->CBOX_Unsell_Icon;
  }
    
  pIcon = create_icon_from_theme(pSurf, 0);
  pCBox = create_iconlabel(pIcon, pDest, pStr, (flags | WF_FREE_PRIVATE_DATA));

  pStr->style &= ~SF_CENTER;

  pCBox->theme = pSurf;
  FREESURFACE(pIcon);

  set_wtype(pCBox, WT_TCHECKBOX);
  pTmp->state = state;
  pTmp->pTRUE_Theme = pTheme->CBOX_Sell_Icon;
  pTmp->pFALSE_Theme = pTheme->CBOX_Unsell_Icon;
  pCBox->private_data.cbox = pTmp;

  pTmpWidget = widget_new();
  /* we can't use pCBox->redraw here, because it is of type iconlabel */
  textcheckbox_baseclass_redraw = pTmpWidget->redraw;
  FREEWIDGET(pTmpWidget);
  pCBox->redraw = redraw_textcheckbox;
  
  return pCBox;
}
Esempio n. 10
0
/**************************************************************************
  Delete UniChar structure.
**************************************************************************/
static void del_chain(struct UniChar *pChain)
{
  int i, len = 0;

  if (!pChain) {
    return;
  }

  len = chainlen(pChain);

  if (len > 1) {
    pChain = pChain->next;
    for (i = 0; i < len - 1; i++) {
      FREESURFACE(pChain->prev->pTsurf);
      FC_FREE(pChain->prev);
      pChain = pChain->next;
    }
  }

  FC_FREE(pChain);
}
Esempio n. 11
0
/**************************************************************************
  Unsellect (sellected) widget and redraw this widget;
**************************************************************************/
void unsellect_widget_action(void)
{
  if (pSellected_Widget && (get_wstate(pSellected_Widget) != FC_WS_DISABLED)) {
    
      set_wstate(pSellected_Widget, FC_WS_NORMAL);
  
      if (!(get_wflags(pSellected_Widget) & WF_HIDDEN)) {
        pSellected_Widget->unselect(pSellected_Widget);
        
        /* turn off quick info timer/counter */ 
        widget_info_counter = 0;
      }
  }

  if (pInfo_Area) {
    flush_rect(*pInfo_Area, FALSE);
    FC_FREE(pInfo_Area);
    FREESURFACE(pInfo_Label);    
  }

  pSellected_Widget = NULL;
}
Esempio n. 12
0
/****************************************************************************
  Load the given graphics file into a sprite.  This function loads an
  entire image file, which may later be broken up into individual sprites
  with crop_sprite.
****************************************************************************/
struct sprite * load_gfxfile(const char *filename)
{
  SDL_Surface *pNew = NULL;
  SDL_Surface *pBuf = NULL;

  if ((pBuf = IMG_Load(filename)) == NULL) {
    log_error(_("load_gfxfile: Unable to load graphic file %s!"), filename);
    return NULL;		/* Should I use abotr() ? */
  }

  if (pBuf->flags & SDL_SRCCOLORKEY) {
    /* convert colorkey to alpha */
    SDL_SetColorKey(pBuf, SDL_SRCCOLORKEY, pBuf->format->colorkey);
    pNew = SDL_DisplayFormatAlpha(pBuf);
    FREESURFACE(pBuf);
    pBuf = pNew;
  }

  pNew = pBuf;
  
  return ctor_sprite(pNew);
}
Esempio n. 13
0
/**************************************************************************
  Create Icon Button image with text and Icon then blit to Dest(ination)
  on positon pTIButton->size.x , pTIButton->size.y. WARRING: pDest must
  exist.

  Text with atributes is taken from pTIButton->string16 parameter.

  Graphic for button is taken from pTIButton->theme surface 
  and blit to new created image.

  Graphic for Icon Theme is taken from pTIButton->theme2 surface 
  and blit to new created image.

  function return (-1) if there are no Icon and Text.  Else return 0.
**************************************************************************/
static int redraw_tibutton(struct widget *pTIButton)
{
  int iRet = 0;
  SDL_Surface *pIcon;
  SDL_Surface *pCopy_Of_Icon_Theme;

  iRet = (*baseclass_redraw)(pTIButton);
  if (iRet != 0) {
    return iRet;
  }
  
  pIcon = create_icon_from_theme(pTIButton->theme2, get_wstate(pTIButton));
  pCopy_Of_Icon_Theme = pTIButton->theme2;

  pTIButton->theme2 = pIcon;

  iRet = redraw_ibutton(pTIButton);

  FREESURFACE(pTIButton->theme2);
  pTIButton->theme2 = pCopy_Of_Icon_Theme;

  return iRet;
}
Esempio n. 14
0
/****************************************************************
 Pops-up the Spy sabotage dialog, upon return of list of
 available improvements requested by the above function.
*****************************************************************/
void popup_sabotage_dialog(struct city *pCity)
{
  struct widget *pWindow = NULL, *pBuf = NULL , *pLast = NULL;
  struct CONTAINER *pCont;
  struct unit *pUnit = head_of_units_in_focus();
  SDL_String16 *pStr;
  SDL_Rect area, area2;
  int n, w = 0, h, imp_h = 0;
  
  if (pDiplomat_Dlg || !pUnit || !unit_has_type_flag(pUnit, F_SPY)) {
    return;
  }
  
  is_unit_move_blocked = TRUE;
    
  pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog));
  pDiplomat_Dlg->diplomat_id = pUnit->id;
  pDiplomat_Dlg->diplomat_target_id = pCity->id;
  pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG));
  
  pCont = fc_calloc(1, sizeof(struct CONTAINER));
  pCont->id0 = pCity->id;
  pCont->id1 = pUnit->id;/* spy id */
    
  pStr = create_str16_from_char(_("Select Improvement to Sabotage") , adj_font(12));
  pStr->style |= TTF_STYLE_BOLD;
  
  pWindow = create_window_skeleton(NULL, pStr, 0);
    
  pWindow->action = diplomat_dlg_window_callback;
  set_wstate(pWindow, FC_WS_NORMAL);
  
  add_to_gui_list(ID_TERRAIN_ADV_DLG_WINDOW, pWindow);
  pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow;
  
  area = pWindow->area;
  area.h = MAX(area.h, adj_size(2));
  
  /* ---------- */
  /* 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 += pBuf->size.w + adj_size(10);
  pBuf->action = diplomat_close_callback;
  set_wstate(pBuf, FC_WS_NORMAL);
  pBuf->key = SDLK_ESCAPE;
  
  add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, pBuf);
  /* ---------- */
  
  create_active_iconlabel(pBuf, pWindow->dst, pStr,
	    _("City Production"), sabotage_impr_callback);
  pBuf->data.cont = pCont;  
  set_wstate(pBuf, FC_WS_NORMAL);
  set_wflag(pBuf, WF_FREE_DATA);
  add_to_gui_list(MAX_ID - 1000, pBuf);
    
  area.w = MAX(area.w, pBuf->size.w);
  area.h += pBuf->size.h;

  /* separator */
  pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME);
    
  add_to_gui_list(ID_SEPARATOR, pBuf);
  area.h += pBuf->next->size.h;
  /* ------------------ */
  n = 0;
  city_built_iterate(pCity, pImprove) {
    if (pImprove->sabotage > 0) {
      
      create_active_iconlabel(pBuf, pWindow->dst, pStr,
	      (char *) city_improvement_name_translation(pCity, pImprove),
				      sabotage_impr_callback);
      pBuf->data.cont = pCont;
      set_wstate(pBuf , FC_WS_NORMAL);
  
      add_to_gui_list(MAX_ID - improvement_number(pImprove), pBuf);
    
      area.w = MAX(area.w , pBuf->size.w);
      imp_h += pBuf->size.h;
      
      if (!pDiplomat_Dlg->pdialog->pEndActiveWidgetList)
      {
	pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pBuf;
      }
    
      if (improvement_number(pImprove) > 9)
      {
        set_wflag(pBuf, WF_HIDDEN);
      }
      
      n++;    
      /* ----------- */
    }  
  } city_built_iterate_end;

  pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pBuf;
  
  if (n > 0) {
    /* separator */
    pBuf = create_iconlabel(NULL, pWindow->dst, NULL, WF_FREE_THEME);
    
    add_to_gui_list(ID_SEPARATOR, pBuf);
    area.h += pBuf->next->size.h;
  /* ------------------ */
  }
  
  create_active_iconlabel(pBuf, pWindow->dst, pStr, _("At Spy's Discretion"),
			  sabotage_impr_callback);
  pBuf->data.cont = pCont;  
  set_wstate(pBuf, FC_WS_NORMAL);
  
  add_to_gui_list(MAX_ID - B_LAST, pBuf);
    
  area.w = MAX(area.w, pBuf->size.w);
  area.h += pBuf->size.h;
  /* ----------- */
  
  pLast = pBuf;
  pDiplomat_Dlg->pdialog->pBeginWidgetList = pLast;
  pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList;
  
  /* ---------- */
  if (n > 10)
  {
    imp_h = 10 * pBuf->size.h;
    
    n = create_vertical_scrollbar(pDiplomat_Dlg->pdialog,
		  1, 10, TRUE, TRUE);
    area.w += n;
  }
  /* ---------- */
  
  
  area.h += imp_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;
  
  auto_center_on_focus_unit();
  put_window_near_map_tile(pWindow, pWindow->size.w, pWindow->size.h,
                           pUnit->tile);        
  
  w = area.w;
  
  if (pDiplomat_Dlg->pdialog->pScroll)
  {
    w -= n;
    imp_h = pBuf->size.w;
  }
  else
  {
    imp_h = 0;
  }
  
  /* 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);
  
  /* Production sabotage */
  pBuf = pBuf->prev;
  
  pBuf->size.x = area.x;
  pBuf->size.y = area.y + 1;
  pBuf->size.w = w;
  h = pBuf->size.h;
  
  area2.x = adj_size(10);
  area2.h = adj_size(2);
  
  pBuf = pBuf->prev;
  while(pBuf)
  {
    
    if (pBuf == pDiplomat_Dlg->pdialog->pEndActiveWidgetList)
    {
      w -= imp_h;
    }
    
    pBuf->size.w = w;
    pBuf->size.x = pBuf->next->size.x;
    pBuf->size.y = pBuf->next->size.y + pBuf->next->size.h;
    
    if (pBuf->ID == ID_SEPARATOR)
    {
      FREESURFACE(pBuf->theme);
      pBuf->size.h = h;
      pBuf->theme = create_surf(w, h, SDL_SWSURFACE);
    
      area2.y = pBuf->size.h / 2 - 1;
      area2.w = pBuf->size.w - adj_size(20);
      
      SDL_FillRect(pBuf->theme , &area2, map_rgba(pBuf->theme->format, *get_game_colorRGB(COLOR_THEME_SABOTAGEDLG_SEPARATOR)));
    }
    
    if (pBuf == pLast) {
      break;
    }
    pBuf = pBuf->prev;  
  }
  
  if (pDiplomat_Dlg->pdialog->pScroll)
  {
    setup_vertical_scrollbar_area(pDiplomat_Dlg->pdialog->pScroll,
	area.x + area.w,
    	pDiplomat_Dlg->pdialog->pEndActiveWidgetList->size.y,
    	area.y - pDiplomat_Dlg->pdialog->pEndActiveWidgetList->size.y +
	    area.h, TRUE);
  }
  
  /* -------------------- */
  /* redraw */
  redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, 0);

  widget_flush(pWindow);
  
}
Esempio n. 15
0
/*
 *	Free memmory
 */
void tilespec_free_theme(void)
{
  if (!pTheme) {
    return;
  }

  FREESURFACE(pTheme->FR_Left);
  FREESURFACE(pTheme->FR_Right);
  FREESURFACE(pTheme->FR_Top);
  FREESURFACE(pTheme->FR_Bottom);
  
  FREESURFACE(pTheme->Button);
  
  FREESURFACE(pTheme->Edit);

  FREESURFACE(pTheme->CBOX_Sell_Icon);
  FREESURFACE(pTheme->CBOX_Unsell_Icon);

  FREESURFACE(pTheme->UP_Icon);
  FREESURFACE(pTheme->DOWN_Icon);
#if 0
  FREESURFACE(pTheme->LEFT_Icon);
  FREESURFACE(pTheme->RIGHT_Icon);
#endif
  FREESURFACE(pTheme->Vertic);
  FREESURFACE(pTheme->Horiz);
  
  /* ------------------- */
  
  FREESURFACE(pTheme->OK_Icon);
  FREESURFACE(pTheme->CANCEL_Icon);
  FREESURFACE(pTheme->Small_OK_Icon);
  FREESURFACE(pTheme->Small_CANCEL_Icon);
  FREESURFACE(pTheme->FORWARD_Icon);
  FREESURFACE(pTheme->BACK_Icon);
  FREESURFACE(pTheme->L_ARROW_Icon);
  FREESURFACE(pTheme->R_ARROW_Icon);
  FREESURFACE(pTheme->MAP_Icon);
  FREESURFACE(pTheme->FindCity_Icon);
  FREESURFACE(pTheme->NEW_TURN_Icon);
  FREESURFACE(pTheme->LOG_Icon);
  FREESURFACE(pTheme->UNITS_Icon);
  FREESURFACE(pTheme->UNITS2_Icon);
  FREESURFACE(pTheme->PLAYERS_Icon);
  FREESURFACE(pTheme->Options_Icon);
  FREESURFACE(pTheme->Block);
  FREESURFACE(pTheme->INFO_Icon);
  FREESURFACE(pTheme->Army_Icon);
  FREESURFACE(pTheme->Happy_Icon);
  FREESURFACE(pTheme->Support_Icon);
  FREESURFACE(pTheme->Buy_PROD_Icon);
  FREESURFACE(pTheme->PROD_Icon);
  FREESURFACE(pTheme->QPROD_Icon);
  FREESURFACE(pTheme->CMA_Icon);
  FREESURFACE(pTheme->LOCK_Icon);
  FREESURFACE(pTheme->UNLOCK_Icon);
  FREESURFACE(pTheme->OK_PACT_Icon);
  FREESURFACE(pTheme->CANCEL_PACT_Icon);
  FREESURFACE(pTheme->SAVE_Icon);
  FREESURFACE(pTheme->LOAD_Icon);
  FREESURFACE(pTheme->DELETE_Icon);
  FREESURFACE(pTheme->BORDERS_Icon);
  /* ------------------------------ */
  FREESURFACE(pTheme->Tech_Tree_Icon);
  /* ------------------------------ */

  FREESURFACE(pTheme->Order_Icon);
  FREESURFACE(pTheme->OAutoAtt_Icon);
  FREESURFACE(pTheme->OAutoConnect_Icon);
  FREESURFACE(pTheme->OAutoExp_Icon);
  FREESURFACE(pTheme->OAutoSett_Icon);
  FREESURFACE(pTheme->OBuildCity_Icon);
  FREESURFACE(pTheme->OCutDownForest_Icon);
  FREESURFACE(pTheme->OPlantForest_Icon);
  FREESURFACE(pTheme->OMine_Icon);
  FREESURFACE(pTheme->OIrrigation_Icon);
  FREESURFACE(pTheme->ODone_Icon);
  FREESURFACE(pTheme->ODisband_Icon);
  FREESURFACE(pTheme->OFortify_Icon);
  FREESURFACE(pTheme->OGoto_Icon);
  FREESURFACE(pTheme->OGotoCity_Icon);
  FREESURFACE(pTheme->OHomeCity_Icon);
  FREESURFACE(pTheme->ONuke_Icon);
  FREESURFACE(pTheme->OParaDrop_Icon);
  FREESURFACE(pTheme->OPatrol_Icon);
  FREESURFACE(pTheme->OPillage_Icon);
  FREESURFACE(pTheme->ORailRoad_Icon);
  FREESURFACE(pTheme->ORoad_Icon);
  FREESURFACE(pTheme->OSentry_Icon);
  FREESURFACE(pTheme->OUnload_Icon);
  FREESURFACE(pTheme->OWait_Icon);
  FREESURFACE(pTheme->OFortress_Icon);
  FREESURFACE(pTheme->OFallout_Icon);
  FREESURFACE(pTheme->OPollution_Icon);
  FREESURFACE(pTheme->OAirBase_Icon);
  FREESURFACE(pTheme->OTransform_Icon);
  FREESURFACE(pTheme->OAddCity_Icon);
  FREESURFACE(pTheme->OWonder_Icon);
  FREESURFACE(pTheme->OTrade_Icon);
  FREESURFACE(pTheme->OSpy_Icon);
  FREESURFACE(pTheme->OWakeUp_Icon);
  FREESURFACE(pTheme->OReturn_Icon);
  FREESURFACE(pTheme->OAirLift_Icon);
  FREESURFACE(pTheme->OLoad_Icon);

  FC_FREE(pTheme);
  return;
}
Esempio n. 16
0
/**************************************************************************
  ...
**************************************************************************/
static SDL_Surface *create_str16_multi_surf(SDL_String16 * pString)
{
  SDL_Rect des = {0, 0, 0, 0};
  SDL_Surface *pText = NULL, **pTmp = NULL;
  Uint16 i, w = 0, count = 0;
  Uint32 color;
  Uint16 *pBuf = pString->text;
  Uint16 **UniTexts = create_new_line_unistrings(pString->text);

  while (UniTexts[count]) {
    count++;
  }

  pTmp = fc_calloc(count, sizeof(SDL_Surface *));

  for (i = 0; i < count; i++) {
    pString->text = UniTexts[i];
    pTmp[i] = create_str16_surf(pString);
  }

  pString->text = pBuf;

  /* find max len */
  for (i = 0; i < count; i++) {
    if (pTmp[i]->w > w) {
      w = pTmp[i]->w;
    }
  }

  /* create and fill surface */
  
  color = pTmp[0]->format->colorkey;
  
  switch (pString->render) {
  case 1:
    pText = create_surf(w, count * pTmp[0]->h, SDL_SWSURFACE);
    SDL_FillRect(pText, NULL, color);
    SDL_SetColorKey(pText, SDL_SRCCOLORKEY, color);
    break;
  case 2:
      pText = create_surf_with_format(pTmp[0]->format,
				     w, count * pTmp[0]->h, pTmp[0]->flags);
      SDL_FillRect(pText, NULL, color);
    break;
  default:
    pText = create_surf(w, count * pTmp[0]->h, SDL_SWSURFACE);
    SDL_FillRect(pText, NULL, color);
    break;
  }

  /* blit (default: center left) */
  for (i = 0; i < count; i++) {
    if (pString->style & SF_CENTER) {
      des.x = (w - pTmp[i]->w) / 2;
    } else {
      if (pString->style & SF_CENTER_RIGHT) {
	des.x = w - pTmp[i]->w;
      } else {
	des.x = 0;
      }
    }

    alphablit(pTmp[i], NULL, pText, &des);
    des.y += pTmp[i]->h;
  }


  /* Free Memmory */
  for (i = 0; i < count; i++) {
    FC_FREE(UniTexts[i]);
    FREESURFACE(pTmp[i]);
  }
  
  FC_FREE(pTmp);

  return pText;
}
Esempio n. 17
0
/**************************************************************************
  ...
**************************************************************************/
static void show_main_page(void)
{
    SDL_Color bg_color = {255, 255, 255, 96};
    SDL_Color *line_color = &(SDL_Color) {
        128, 128, 128, 255
    };

    int count = 0;
    struct widget *pWidget = NULL, *pWindow = NULL;
    SDL_Surface *pBackground;
    int h = 0;
    SDL_Rect area;
    char verbuf[200];

    /* create dialog */
    pStartMenu = fc_calloc(1, sizeof(struct SMALL_DLG));

    pWindow = create_window_skeleton(NULL, NULL, 0);
    add_to_gui_list(ID_WINDOW, pWindow);
    pStartMenu->pEndWidgetList = pWindow;

    area = pWindow->area;

    /* Freeciv version */
    /* TRANS: Freeciv 2.4.0, gui-sdl client */
    fc_snprintf(verbuf, sizeof(verbuf), _("Freeciv %s, %s client"), VERSION_STRING, client_string);
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, verbuf,
                                          adj_font(12),
                                          (WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));


    pWidget->string16->style |= SF_CENTER | TTF_STYLE_BOLD;

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    add_to_gui_list(ID_LABEL, pWidget);

    /* Start New Game */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Start New Game"),
                                          adj_font(14),
                                          (WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND|WF_FREE_DATA));

    pWidget->action = start_new_game_callback;
    pWidget->string16->style |= SF_CENTER;
    set_wstate(pWidget, FC_WS_NORMAL);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    add_to_gui_list(ID_START_NEW_GAME, pWidget);

    /* Load Game */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Load Game"),
                                          adj_font(14),
                                          (WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND));
    pWidget->action = load_game_callback;
    pWidget->string16->style |= SF_CENTER;
    set_wstate(pWidget, FC_WS_NORMAL);

    add_to_gui_list(ID_LOAD_GAME, pWidget);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    /* Join Game */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join Game"),
                                          adj_font(14),
                                          WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
    pWidget->action = join_game_callback;
    pWidget->string16->style |= SF_CENTER;
    set_wstate(pWidget, FC_WS_NORMAL);

    add_to_gui_list(ID_JOIN_GAME, pWidget);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    /* Join Pubserver */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join Pubserver"),
                                          adj_font(14),
                                          WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
    pWidget->action = servers_callback;
    pWidget->string16->style |= SF_CENTER;
    set_wstate(pWidget, FC_WS_NORMAL);

    add_to_gui_list(ID_JOIN_META_GAME, pWidget);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    /* Join LAN Server */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Join LAN Server"),
                                          adj_font(14),
                                          WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
    pWidget->action = servers_callback;
    pWidget->string16->style |= SF_CENTER;
    set_wstate(pWidget, FC_WS_NORMAL);

    add_to_gui_list(ID_JOIN_GAME, pWidget);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    /* Options */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Options"),
                                          adj_font(14),
                                          WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
    pWidget->action = options_callback;
    pWidget->string16->style |= SF_CENTER;
    set_wstate(pWidget, FC_WS_NORMAL);

    add_to_gui_list(ID_CLIENT_OPTIONS_BUTTON, pWidget);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    /* Quit */
    pWidget = create_iconlabel_from_chars(NULL, pWindow->dst, _("Quit"),
                                          adj_font(14),
                                          WF_SELLECT_WITHOUT_BAR|WF_RESTORE_BACKGROUND);
    pWidget->action = quit_callback;
    pWidget->string16->style |= SF_CENTER;
    pWidget->key = SDLK_ESCAPE;
    set_wstate(pWidget, FC_WS_NORMAL);
    add_to_gui_list(ID_QUIT, pWidget);

    area.w = MAX(area.w, pWidget->size.w);
    h = MAX(h, pWidget->size.h);
    count++;

    pStartMenu->pBeginWidgetList = pWidget;

    /* ------*/

    area.w += adj_size(30);
    h += adj_size(6);

    area.h = MAX(area.h, h * count);

    /* ------*/

    pBackground = theme_get_background(theme, BACKGROUND_STARTMENU);
    if (resize_window(pWindow, pBackground, NULL,
                      (pWindow->size.w - pWindow->area.w) + area.w,
                      (pWindow->size.h - pWindow->area.h) + area.h)) {
        FREESURFACE(pBackground);
    }

    area = pWindow->area;

    group_set_area(pWidget, pWindow->prev, area);

    setup_vertical_widgets_position(1, area.x, area.y, area.w, h, pWidget, pWindow->prev);

    area.h = h;
    SDL_FillRectAlpha(pWindow->theme, &area, &bg_color);

    widget_set_position(pWindow,
                        (Main.screen->w - pWindow->size.w) - adj_size(20),
                        (Main.screen->h - pWindow->size.h) - adj_size(20));

    draw_intro_gfx();

    redraw_group(pStartMenu->pBeginWidgetList, pStartMenu->pEndWidgetList, FALSE);

    putline(pWindow->dst->surface,
            area.x, area.y + (h - 1),
            area.x + area.w - 1, area.y + (h - 1),
            line_color);

    set_output_window_text(_("SDLClient welcomes you..."));
    chat_welcome_message();

    meswin_dialog_popup(TRUE);

    flush_all();
}
Esempio n. 18
0
/****************************************************************************
  Free a sprite and all associated image data.
****************************************************************************/
void free_sprite(struct sprite *s)
{
  fc_assert_ret(s != NULL);
  FREESURFACE(GET_SURF_REAL(s));
  FC_FREE(s);
}
Esempio n. 19
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();
}
Esempio n. 20
0
enum Edit_Return_Codes edit_field(struct widget *pEdit_Widget)
{
  struct EDIT pEdt;
  struct UniChar ___last;
  struct UniChar *pInputChain_TMP = NULL;
  enum Edit_Return_Codes ret;
  void *backup = pEdit_Widget->data.ptr;
  
  pEdt.pWidget = pEdit_Widget;
  pEdt.ChainLen = 0;
  pEdt.Truelength = 0;
  pEdt.Start_X = adj_size(5);
  pEdt.InputChain_X = 0;
  
  pEdit_Widget->data.ptr = (void *)&pEdt;
  
  SDL_EnableUNICODE(1);

  SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

  pEdt.pBg = create_bcgnd_surf(pEdit_Widget->theme, 2,
			       pEdit_Widget->size.w, pEdit_Widget->size.h);

  /* Creating Chain */
  pEdt.pBeginTextChain = text2chain(pEdit_Widget->string16->text);


  /* Creating Empty (Last) pice of Chain */
  pEdt.pInputChain = &___last;
  pEdt.pEndTextChain = pEdt.pInputChain;
  pEdt.pEndTextChain->chr[0] = 32;	/*spacebar */
  pEdt.pEndTextChain->chr[1] = 0;	/*spacebar */
  pEdt.pEndTextChain->next = NULL;
  pEdt.pEndTextChain->prev = NULL;
  
  /* set font style (if any ) */
  if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) {
    TTF_SetFontStyle(pEdit_Widget->string16->font,
		     (pEdit_Widget->string16->style & 0x0F));
  }


  pEdt.pEndTextChain->pTsurf =
      TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font,
			      pEdt.pEndTextChain->chr,
			      pEdit_Widget->string16->fgcol);
  
  /* create surface for each font in chain and find chain length */
  if (pEdt.pBeginTextChain) {
    pInputChain_TMP = pEdt.pBeginTextChain;
    while (TRUE) {
      pEdt.ChainLen++;

      pInputChain_TMP->pTsurf =
	  TTF_RenderUNICODE_Blended(pEdit_Widget->string16->font,
				    pInputChain_TMP->chr,
				    pEdit_Widget->string16->fgcol);

      pEdt.Truelength += pInputChain_TMP->pTsurf->w;

      if (pInputChain_TMP->next == NULL) {
	break;
      }

      pInputChain_TMP = pInputChain_TMP->next;
    }
    /* set terminator of list */
    pInputChain_TMP->next = pEdt.pInputChain;
    pEdt.pInputChain->prev = pInputChain_TMP;
    pInputChain_TMP = NULL;
  } else {
    pEdt.pBeginTextChain = pEdt.pInputChain;
  }

  redraw_edit_chain(&pEdt);
  
  set_wstate(pEdit_Widget, FC_WS_PRESSED);
  {
    /* local loop */  
    Uint16 rety = gui_event_loop((void *)&pEdt, NULL,
  	edit_key_down, NULL, edit_mouse_button_down, NULL, NULL);
    
    if (pEdt.pBeginTextChain == pEdt.pEndTextChain) {
      pEdt.pBeginTextChain = NULL;
    }
    
    if (rety == MAX_ID) {
      ret = ED_FORCE_EXIT;
    } else {
      ret = (enum Edit_Return_Codes) rety;
      
      /* this is here becouse we have no knowladge that pEdit_Widget exist
         or nor in force exit mode from gui loop */
  
      /* reset font settings */
      if (!((pEdit_Widget->string16->style & 0x0F) & TTF_STYLE_NORMAL)) {
        TTF_SetFontStyle(pEdit_Widget->string16->font, TTF_STYLE_NORMAL);
      }
      
      if(ret != ED_ESC) {
        FC_FREE(pEdit_Widget->string16->text);
        pEdit_Widget->string16->text =
  	    chain2text(pEdt.pBeginTextChain, pEdt.ChainLen);
        pEdit_Widget->string16->n_alloc = (pEdt.ChainLen + 1) * sizeof(Uint16);
      }
      
      pEdit_Widget->data.ptr = backup;
      set_wstate(pEdit_Widget, FC_WS_NORMAL);    
    }
  }
  
  FREESURFACE(pEdt.pEndTextChain->pTsurf);
   
  del_chain(pEdt.pBeginTextChain);
  
  FREESURFACE(pEdt.pBg);
    
  /* disable repeate key */
  SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);

  /* disable Unicode */
  SDL_EnableUNICODE(0);
    
  return ret;
}
Esempio n. 21
0
/**************************************************************************
  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();
}
Esempio n. 22
0
/**************************************************************************
  Do default Widget action when pressed, and then call widget callback
  function.

  example for Button:
    set flags FW_Pressed
    redraw button ( pressed )
    refresh screen ( to see result )
    wait 300 ms	( to see result :)
    If exist (button callback function) then
      call (button callback function)

    Function normal return Widget ID.
    NOTE: NOZERO return of this function deterninate exit of
        MAIN_SDL_GAME_LOOP
    if ( pWidget->action )
      if ( pWidget->action(pWidget)  ) ID = 0;
    if widget callback function return = 0 then return NOZERO
    I default return (-1) from Widget callback functions.
**************************************************************************/
Uint16 widget_pressed_action(struct widget * pWidget)
{
  Uint16 ID = 0;

  if (!pWidget) {
    return 0;
  }
  
  widget_info_counter = 0;
  if (pInfo_Area) {
    sdl_dirty_rect(*pInfo_Area);
    FC_FREE(pInfo_Area);
    FREESURFACE(pInfo_Label);
  }

  switch (get_wtype(pWidget)) {
    case WT_TI_BUTTON:
    case WT_I_BUTTON:    
    case WT_ICON:
    case WT_ICON2:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        widget_redraw(pWidget);
        widget_mark_dirty(pWidget);
        flush_dirty();
        set_wstate(pWidget, FC_WS_SELLECTED);
        SDL_Delay(300);
      }
      ID = pWidget->ID;
      if (pWidget->action) {
        if (pWidget->action(pWidget)) {
          ID = 0;
        }
      }
      break;

    case WT_EDIT:
    {
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        bool ret, loop = ((get_wflags(pWidget) & WF_EDIT_LOOP) == WF_EDIT_LOOP);
        enum Edit_Return_Codes change;
        do {
          ret = FALSE;
          change = edit_field(pWidget);
          if (change != ED_FORCE_EXIT && (!loop || change != ED_RETURN)) {
            widget_redraw(pWidget);
            widget_mark_dirty(pWidget);
            flush_dirty();
          }
          if (change != ED_FORCE_EXIT && change != ED_ESC && pWidget->action) {
            if (pWidget->action(pWidget)) {
              ID = 0;
            }
          }
          if (loop && change == ED_RETURN) {
            ret = TRUE;
          }
        } while(ret);
        ID = 0;
      }
      break;
    }
    case WT_VSCROLLBAR:
    case WT_HSCROLLBAR:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        widget_redraw(pWidget);
        widget_mark_dirty(pWidget);
        flush_dirty();
      }
      ID = pWidget->ID;
      if (pWidget->action) {
        if (pWidget->action(pWidget)) {
          ID = 0;
        }
      }
      break;
    case WT_CHECKBOX:
    case WT_TCHECKBOX:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        widget_redraw(pWidget);
        widget_mark_dirty(pWidget);
        flush_dirty();
        set_wstate(pWidget, FC_WS_SELLECTED);
        togle_checkbox(pWidget);
        SDL_Delay(300);
      }
      ID = pWidget->ID;  
      if (pWidget->action) {
        if (pWidget->action(pWidget)) {
          ID = 0;
        }
      }
      break;
    case WT_COMBO:
      if (Main.event.button.button == SDL_BUTTON_LEFT) {
        set_wstate(pWidget, FC_WS_PRESSED);
        combo_popup(pWidget);
      } else {
        combo_popdown(pWidget);
      }
      break;
    default:
      ID = pWidget->ID;
      if (pWidget->action) {
        if (pWidget->action(pWidget) != 0) {
          ID = 0;
        }
      }
      break;
  }

  return ID;
}
Esempio n. 23
0
/**************************************************************************
  This functions are pure madness :)
  Create Edit Field surface ( with Text) and blit them to Main.screen,
  on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'

  Main role of this functions are been text input to GUI.
  This code allow you to add, del unichar from unistring.

  Graphic is taken from 'pEdit_Widget->theme'
  OldText is taken from	'pEdit_Widget->sting16'

  NewText is returned to 'pEdit_Widget->sting16' ( after free OldText )

  if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
  transparent ( Alpha = 128 )

  NOTE: This functions can return NULL in 'pEdit_Widget->sting16->text' but
        never free 'pEdit_Widget->sting16' struct.
**************************************************************************/
static Uint16 edit_key_down(SDL_keysym Key, void *pData)
{
  struct EDIT *pEdt = (struct EDIT *)pData;
  struct UniChar *pInputChain_TMP;
  bool Redraw = FALSE;
      
  /* find which key is pressed */
  switch (Key.sym) {
    case SDLK_ESCAPE:
      /* exit from loop without changes */
      return ED_ESC;
    case SDLK_RETURN:
    case SDLK_KP_ENTER:
      /* exit from loop */
      return ED_RETURN;
    case SDLK_KP6:
      if(Key.mod & KMOD_NUM) {
	goto INPUT;
      }
    case SDLK_RIGHT:
    {
      /* move cursor right */
      if (pEdt->pInputChain->next) {
	
       if (pEdt->InputChain_X >= (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(10))) {
	pEdt->Start_X -= pEdt->pInputChain->pTsurf->w -
		(pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(5) - pEdt->InputChain_X);
       }

	pEdt->pInputChain = pEdt->pInputChain->next;
	Redraw = TRUE;
      }
    }
    break;
    case SDLK_KP4:
      if(Key.mod & KMOD_NUM) {
	goto INPUT;
      }
    case SDLK_LEFT:
    {
      /* move cursor left */
      if (pEdt->pInputChain->prev) {
        pEdt->pInputChain = pEdt->pInputChain->prev;
	if ((pEdt->InputChain_X <=
	       (pEdt->pWidget->size.x + adj_size(9))) && (pEdt->Start_X != adj_size(5))) {
	  if (pEdt->InputChain_X != (pEdt->pWidget->size.x + adj_size(5))) {
	      pEdt->Start_X += (pEdt->pWidget->size.x - pEdt->InputChain_X + adj_size(5));
	  }

	  pEdt->Start_X += (pEdt->pInputChain->pTsurf->w);
	}
	Redraw = TRUE;
      }
    }
    break;
    case SDLK_KP7:
      if(Key.mod & KMOD_NUM) {
	goto INPUT;
      }  
    case SDLK_HOME:
    {
      /* move cursor to begin of chain (and edit field) */
      pEdt->pInputChain = pEdt->pBeginTextChain;
      Redraw = TRUE;
      pEdt->Start_X = adj_size(5);
    }
    break;
    case SDLK_KP1:
      if(Key.mod & KMOD_NUM) {
	goto INPUT;
      }
    case SDLK_END:
    {
	/* move cursor to end of chain (and edit field) */
      pEdt->pInputChain = pEdt->pEndTextChain;
      Redraw = TRUE;

      if (pEdt->pWidget->size.w - pEdt->Truelength < 0) {
	  pEdt->Start_X = pEdt->pWidget->size.w - pEdt->Truelength - adj_size(5);
      }
    }
    break;
    case SDLK_BACKSPACE:
    {
	/* del element of chain (and move cursor left) */
      if (pEdt->pInputChain->prev) {

	if ((pEdt->InputChain_X <=
	       (pEdt->pWidget->size.x + adj_size(9))) && (pEdt->Start_X != adj_size(5))) {
	  if (pEdt->InputChain_X != (pEdt->pWidget->size.x + adj_size(5))) {
	      pEdt->Start_X += (pEdt->pWidget->size.x - pEdt->InputChain_X + adj_size(5));
	  }
	  pEdt->Start_X += (pEdt->pInputChain->prev->pTsurf->w);
	}

	if (pEdt->pInputChain->prev->prev) {
	  pEdt->pInputChain->prev->prev->next = pEdt->pInputChain;
	  pInputChain_TMP = pEdt->pInputChain->prev->prev;
	  pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w;
	  FREESURFACE(pEdt->pInputChain->prev->pTsurf);
	  FC_FREE(pEdt->pInputChain->prev);
	  pEdt->pInputChain->prev = pInputChain_TMP;
	} else {
	  pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w;
	  FREESURFACE(pEdt->pInputChain->prev->pTsurf);
	  FC_FREE(pEdt->pInputChain->prev);
	  pEdt->pBeginTextChain = pEdt->pInputChain;
	}
	
	pEdt->ChainLen--;
	Redraw = TRUE;
      }
    }
    break;
    case SDLK_KP_PERIOD:
      if(Key.mod & KMOD_NUM) {
	goto INPUT;
      }  
    case SDLK_DELETE:
    {
	/* del element of chain */
      if (pEdt->pInputChain->next && pEdt->pInputChain->prev) {
	pEdt->pInputChain->prev->next = pEdt->pInputChain->next;
	pEdt->pInputChain->next->prev = pEdt->pInputChain->prev;
	pInputChain_TMP = pEdt->pInputChain->next;
	pEdt->Truelength -= pEdt->pInputChain->pTsurf->w;
	FREESURFACE(pEdt->pInputChain->pTsurf);
	FC_FREE(pEdt->pInputChain);
	pEdt->pInputChain = pInputChain_TMP;
	pEdt->ChainLen--;
	Redraw = TRUE;
      }

      if (pEdt->pInputChain->next && !pEdt->pInputChain->prev) {
	pEdt->pInputChain = pEdt->pInputChain->next;
	pEdt->Truelength -= pEdt->pInputChain->prev->pTsurf->w;
	FREESURFACE(pEdt->pInputChain->prev->pTsurf);
	FC_FREE(pEdt->pInputChain->prev);
	pEdt->pBeginTextChain = pEdt->pInputChain;
	pEdt->ChainLen--;
	Redraw = TRUE;
      }
    }
    break;
    default:
    {
INPUT:/* add new element of chain (and move cursor right) */
      if (Key.unicode) {
	if (pEdt->pInputChain != pEdt->pBeginTextChain) {
	  pInputChain_TMP = pEdt->pInputChain->prev;
	  pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar));
	  pEdt->pInputChain->prev->next = pEdt->pInputChain;
	  pEdt->pInputChain->prev->prev = pInputChain_TMP;
	  pInputChain_TMP->next = pEdt->pInputChain->prev;
	} else {
	  pEdt->pInputChain->prev = fc_calloc(1, sizeof(struct UniChar));
	  pEdt->pInputChain->prev->next = pEdt->pInputChain;
	  pEdt->pBeginTextChain = pEdt->pInputChain->prev;
	}
        
        pEdt->pInputChain->prev->chr[0] = Key.unicode;        
	pEdt->pInputChain->prev->chr[1] = '\0';

	if (pEdt->pInputChain->prev->chr) {
	  if (get_wflags(pEdt->pWidget) & WF_PASSWD_EDIT) {
	    Uint16 passwd_chr[2] = {'*', '\0'};
	    
	    pEdt->pInputChain->prev->pTsurf =
	      TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font,
					  passwd_chr,
					  pEdt->pWidget->string16->fgcol);
	  } else {
	    pEdt->pInputChain->prev->pTsurf =
	      TTF_RenderUNICODE_Blended(pEdt->pWidget->string16->font,
					  pEdt->pInputChain->prev->chr,
					  pEdt->pWidget->string16->fgcol);
	  }
	  pEdt->Truelength += pEdt->pInputChain->prev->pTsurf->w;
	}

	if (pEdt->InputChain_X >= pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(10)) {
	  if (pEdt->pInputChain == pEdt->pEndTextChain) {
	    pEdt->Start_X = pEdt->pBg->w - adj_size(5) - pEdt->Truelength;
	  } else {
	    pEdt->Start_X -= pEdt->pInputChain->prev->pTsurf->w -
		  (pEdt->pWidget->size.x + pEdt->pBg->w - adj_size(5) - pEdt->InputChain_X);
	  }
	}
	
	pEdt->ChainLen++;
	Redraw = TRUE;
      }
    }
    break;
  }				/* key pressed switch */
    
  if (Redraw) {
    redraw_edit_chain(pEdt);
  }
    
  return ID_ERROR;
}
Esempio n. 24
0
/**************************************************************************
  Create Edit Field surface ( with Text) and blit them to Main.screen,
  on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'

  Graphic is taken from 'pEdit_Widget->theme'
  Text is taken from	'pEdit_Widget->sting16'

  if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
  transparent ( Alpha = 128 )

  function return Hight of created surfaces or (-1) if theme surface can't
  be created.
**************************************************************************/
static int redraw_edit(struct widget *pEdit_Widget)
{
  int ret;
  
  if (get_wstate(pEdit_Widget) == FC_WS_PRESSED) {
    return redraw_edit_chain((struct EDIT *)pEdit_Widget->data.ptr);
  } else {
    int iRet = 0;
    SDL_Rect rDest = {pEdit_Widget->size.x, pEdit_Widget->size.y, 0, 0};
    SDL_Surface *pEdit = NULL;
    SDL_Surface *pText;

    ret = (*baseclass_redraw)(pEdit_Widget);
    if (ret != 0) {
      return ret;
    }
    
    if (pEdit_Widget->string16->text &&
    	get_wflags(pEdit_Widget) & WF_PASSWD_EDIT) {
      Uint16 *backup = pEdit_Widget->string16->text;
      size_t len = unistrlen(backup) + 1;
      char *cBuf = fc_calloc(1, len);
    
      memset(cBuf, '*', len - 1);
      cBuf[len - 1] = '\0';
      pEdit_Widget->string16->text = convert_to_utf16(cBuf);
      pText = create_text_surf_from_str16(pEdit_Widget->string16);
      FC_FREE(pEdit_Widget->string16->text);
      FC_FREE(cBuf);
      pEdit_Widget->string16->text = backup;
    } else {
      pText = create_text_surf_from_str16(pEdit_Widget->string16);
    }
  
    pEdit = create_bcgnd_surf(pEdit_Widget->theme, get_wstate(pEdit_Widget),
                              pEdit_Widget->size.w, pEdit_Widget->size.h);

    if (!pEdit) {
      return -1;
    }
    
    /* blit theme */
    alphablit(pEdit, NULL, pEdit_Widget->dst->surface, &rDest);

    /* set position and blit text */
    if (pText) {
      rDest.y += (pEdit->h - pText->h) / 2;
      /* blit centred text to botton */
      if (pEdit_Widget->string16->style & SF_CENTER) {
        rDest.x += (pEdit->w - pText->w) / 2;
      } else {
        if (pEdit_Widget->string16->style & SF_CENTER_RIGHT) {
	  rDest.x += pEdit->w - pText->w - adj_size(5);
        } else {
	  rDest.x += adj_size(5);		/* cennter left */
        }
      }

      alphablit(pText, NULL, pEdit_Widget->dst->surface, &rDest);
    }
    /* pText */
    iRet = pEdit->h;

    /* Free memory */
    FREESURFACE(pText);
    FREESURFACE(pEdit);
    return iRet;
  }
  return 0;
}
Esempio n. 25
0
/*******************************************************************************
 * reload small citizens "style" icons.
 *******************************************************************************/
static void reload_small_citizens_icons(int style)
{
  /* free info icons */
  FREESURFACE(pIcons->pMale_Content);
  FREESURFACE(pIcons->pFemale_Content);
  FREESURFACE(pIcons->pMale_Happy);
  FREESURFACE(pIcons->pFemale_Happy);
  FREESURFACE(pIcons->pMale_Unhappy);
  FREESURFACE(pIcons->pFemale_Unhappy);
  FREESURFACE(pIcons->pMale_Angry);
  FREESURFACE(pIcons->pFemale_Angry);
  
  FREESURFACE(pIcons->pSpec_Lux); /* Elvis */
  FREESURFACE(pIcons->pSpec_Tax); /* TaxMan */
  FREESURFACE(pIcons->pSpec_Sci); /* Scientist */
  
  /* allocate icons */
  pIcons->pMale_Happy = adj_surf(get_citizen_surface(CITIZEN_HAPPY, 0));
  pIcons->pFemale_Happy = adj_surf(get_citizen_surface(CITIZEN_HAPPY, 1));
  pIcons->pMale_Content = adj_surf(get_citizen_surface(CITIZEN_CONTENT, 0));
  pIcons->pFemale_Content = adj_surf(get_citizen_surface(CITIZEN_CONTENT, 1));
  pIcons->pMale_Unhappy = adj_surf(get_citizen_surface(CITIZEN_UNHAPPY, 0));
  pIcons->pFemale_Unhappy = adj_surf(get_citizen_surface(CITIZEN_UNHAPPY, 1));
  pIcons->pMale_Angry = adj_surf(get_citizen_surface(CITIZEN_ANGRY, 0));
  pIcons->pFemale_Angry = adj_surf(get_citizen_surface(CITIZEN_ANGRY, 1));
  pIcons->pSpec_Lux = get_tax_surface(O_LUXURY);
  pIcons->pSpec_Tax = get_tax_surface(O_GOLD);
  pIcons->pSpec_Sci = get_tax_surface(O_SCIENCE);
}
Esempio n. 26
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;
}
Esempio n. 27
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;
}
Esempio n. 28
0
void tilespec_free_city_icons(void)
{
  if (!pIcons) {
    return;
  }
  
  FREESURFACE(pIcons->pBIG_Food_Corr);
  FREESURFACE(pIcons->pBIG_Shield_Corr);
  FREESURFACE(pIcons->pBIG_Trade_Corr);
  FREESURFACE(pIcons->pBIG_Food);
  FREESURFACE(pIcons->pBIG_Food_Surplus);
  FREESURFACE(pIcons->pBIG_Shield);
  FREESURFACE(pIcons->pBIG_Shield_Surplus);
  FREESURFACE(pIcons->pBIG_Trade);
  FREESURFACE(pIcons->pBIG_Luxury);
  FREESURFACE(pIcons->pBIG_Coin);
  FREESURFACE(pIcons->pBIG_Colb);
  FREESURFACE(pIcons->pBIG_Face);
  FREESURFACE(pIcons->pBIG_Coin_Corr);
  FREESURFACE(pIcons->pBIG_Coin_UpKeep);

  FREESURFACE(pIcons->pFood);
  FREESURFACE(pIcons->pShield);
  FREESURFACE(pIcons->pTrade);
  FREESURFACE(pIcons->pFace);
  FREESURFACE(pIcons->pLuxury);
  FREESURFACE(pIcons->pCoin);		  
  FREESURFACE(pIcons->pColb);		  

  FREESURFACE(pIcons->pPollution);
  FREESURFACE(pIcons->pPolice);
  FREESURFACE(pIcons->pWorklist);

  /* small citizens */
  FREESURFACE(pIcons->pMale_Content);
  FREESURFACE(pIcons->pFemale_Content);
  FREESURFACE(pIcons->pMale_Happy);
  FREESURFACE(pIcons->pFemale_Happy);
  FREESURFACE(pIcons->pMale_Unhappy);
  FREESURFACE(pIcons->pFemale_Unhappy);
  FREESURFACE(pIcons->pMale_Angry);
  FREESURFACE(pIcons->pFemale_Angry);

  FREESURFACE(pIcons->pSpec_Lux); /* Elvis */
  FREESURFACE(pIcons->pSpec_Tax); /* TaxMan */
  FREESURFACE(pIcons->pSpec_Sci); /* Scientist */

  FC_FREE(pIcons);
  
}
Esempio n. 29
0
/**************************************************************************
  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;
}
Esempio n. 30
0
/**************************************************************************
  ...
**************************************************************************/
void free_auxiliary_tech_icons(void)
{
  FREESURFACE(pNeutral_Tech_Icon);
  FREESURFACE(pNone_Tech_Icon);
  FREESURFACE(pFuture_Tech_Icon);
}