示例#1
0
LRESULT CALLBACK cg_container_win32_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	widget_t *w;
	container_widget_t *sw;
	native_container_widget_t *nw;
	//bounds_t b;
	
	w = cg_find_by_native( hWnd );
	
	if ( w == 0 )
		return DefWindowProc( hWnd, uMsg, wParam, lParam );
	
	sw = (container_widget_t *)w;
	nw = (native_container_widget_t *)w->ndata;
	
	switch ( uMsg )
	{
		case WM_MOVE:
			widget_set_position( w, LOWORD(lParam), HIWORD(lParam), 1 );
			break;
		case WM_SIZE:
			widget_set_size( w, LOWORD(lParam), HIWORD(lParam), 1 );
			widget_set_content_size( w, LOWORD(lParam), HIWORD(lParam), 1 );
			widget_resized_handle( OBJECT(w), 0 );
			break;
		case WM_COMMAND:
		case WM_NOTIFY:
			return cg_win32_proc( hWnd, uMsg, wParam, lParam );
	}
	
	return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
示例#2
0
文件: widget.c 项目: jheusala/freeciv
/**************************************************************************
  ...
**************************************************************************/
void set_new_group_start_pos(const struct widget *pBeginGroupWidgetList,
			     const struct widget *pEndGroupWidgetList,
			     Sint16 Xrel, Sint16 Yrel)
{
  struct widget *pTmpWidget = (struct widget *) pEndGroupWidgetList;

  while (pTmpWidget) {

    widget_set_position(pTmpWidget, pTmpWidget->size.x + Xrel,
                                    pTmpWidget->size.y + Yrel);
    
    if (get_wtype(pTmpWidget) == WT_VSCROLLBAR
      && pTmpWidget->private_data.adv_dlg
      && pTmpWidget->private_data.adv_dlg->pScroll) {
      pTmpWidget->private_data.adv_dlg->pScroll->max += Yrel;
      pTmpWidget->private_data.adv_dlg->pScroll->min += Yrel;
    }
    
    if (get_wtype(pTmpWidget) == WT_HSCROLLBAR
      && pTmpWidget->private_data.adv_dlg
      && pTmpWidget->private_data.adv_dlg->pScroll) {
      pTmpWidget->private_data.adv_dlg->pScroll->max += Xrel;
      pTmpWidget->private_data.adv_dlg->pScroll->min += Xrel;
    }
    
    if (pTmpWidget == pBeginGroupWidgetList) {
      break;
    }

    pTmpWidget = pTmpWidget->prev;
  }
}
示例#3
0
文件: gtk.c 项目: Airr/Claro
/* resize handler */
gint cgraphics_resized_handler( GtkWidget *widget, GdkEventConfigure *event, widget_t *w )
{
	widget_set_size( OBJECT(w), event->width, event->height, 1 );
	widget_set_content_size( OBJECT(w), event->width, event->height, 1 );
	widget_set_position( OBJECT(w), event->x, event->y, 1 );
	
	return 0;
}
示例#4
0
/****************************************************************************
  Really resize the main window.
****************************************************************************/
static void real_resize_window_callback(void *data)
{
    struct widget *widget;
    Uint32 flags = Main.screen->flags;

    if (gui_sdl_fullscreen) {
        flags |= SDL_FULLSCREEN;
    } else {
        flags &= ~SDL_FULLSCREEN;
    }
    set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height, flags);

    if (C_S_RUNNING == client_state()) {
        /* Move units window to botton-right corner. */
        set_new_unitinfo_window_pos();
        /* Move minimap window to botton-left corner. */
        set_new_minimap_window_pos();

        /* Move cooling/warming icons to botton-right corner. */
        widget = get_widget_pointer_form_main_list(ID_WARMING_ICON);
        widget_set_position(widget, (Main.screen->w - adj_size(10)
                                     - (widget->size.w * 2)), widget->size.y);

        widget = get_widget_pointer_form_main_list(ID_COOLING_ICON);
        widget_set_position(widget, (Main.screen->w - adj_size(10)
                                     - widget->size.w), widget->size.y);

        map_canvas_resized(Main.screen->w, Main.screen->h);
        update_info_label();
        update_unit_info_label(get_units_in_focus());
        center_on_something();      /* With redrawing full map. */
        update_order_widgets();
    } else {
        draw_intro_gfx();
        dirty_all();
    }
    flush_all();
}
示例#5
0
文件: gtk.c 项目: Airr/Claro
gint cgraphics_resized2_handler( GtkWidget *widget, GtkAllocation *event, widget_t *w )
{
	if ( !strcmp( w->object.type, "claro.graphics.widgets.container" ) ||
		 !strcmp( w->object.type, "claro.graphics.widgets.frame" ) ||
		 !strcmp( w->object.type, "claro.graphics.widgets.workspace.window" ) ||
		 !strcmp( w->object.type, "claro.graphics.widgets.window" )	)
	{
		if ( event->x == w->size.x && event->y == w->size.y &&
			 event->width == w->size.w && event->height == w->size.h )
			return 0;
		
		widget_set_size( OBJECT(w), event->width, event->height, 1 );
		widget_set_content_size( OBJECT(w), event->width, event->height, 1 );
		widget_set_position( OBJECT(w), event->x, event->y, 1 );
		
		widget_resized_handle( OBJECT(w), 0 );
	}
	
	return 0;
}
示例#6
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();
}
示例#7
0
文件: image.c 项目: Airr/Claro
LRESULT CALLBACK cg_win32_image_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	image_widget_t *iw;
	image_t *im;
	widget_t *w;
	PAINTSTRUCT ps;
	HDC hdc, oldbmp;
	
	w = cg_find_by_native( hWnd );
	
	if ( w == 0 )
		return DefWindowProc( hWnd, uMsg, wParam, lParam );
	
	iw = (image_widget_t *)w;
	im = iw->src;
	
	switch ( uMsg )
	{
		case WM_QUIT:
			return 1;
		case WM_CLOSE:
			DestroyWindow( hWnd );
			return 0;
		case WM_MOVE:
			widget_set_position( OBJECT(w), LOWORD(lParam), HIWORD(lParam), 1 );
			break;
		case WM_SIZE:
			widget_set_size( OBJECT(w), LOWORD(lParam), HIWORD(lParam), 1 );
			break;
		case WM_PAINT:
			if ( im == NULL )
				break;
			
			hdc = BeginPaint( hWnd, &ps );
			
			/*RECT rect;
			rect.left = rect.top = 0;
			rect.right = rect.bottom = 100;
			FillRect( hdc, &rect, RGB(255,0,0));*/
			
#ifdef IMAGES_USE_LIBPNG_FIXME
			if ( im->native3 == 0 )
			{
				/* Use alphablend, it's a PNG */
				oldbmp = SelectObject( im->native, im->native2 );
				BLENDFUNCTION pixelblend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
				AlphaBlend( hdc, 0, 0, im->width, im->height, im->native, 0, 0, im->width, im->height, pixelblend );
				SelectObject( im->native, oldbmp );
			}
			else
#endif
			{
				oldbmp = SelectObject( im->native, im->native2 );
				BitBlt( hdc, 0, 0, im->width, im->height, im->native, 0, 0, SRCCOPY );
				SelectObject( im->native, oldbmp );
			}
			
			EndPaint( hWnd, &ps );
			return 0;
	}
	
	return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
示例#8
0
/**************************************************************************
  Popup (or raise) the spaceship dialog for the given player.
**************************************************************************/
void popup_spaceship_dialog(struct player *pPlayer)
{
    struct SMALL_DLG *pSpaceShp;

    if(!(pSpaceShp = get_spaceship_dialog(pPlayer))) {
        struct widget *pBuf, *pWindow;
        SDL_String16 *pStr;
        char cBuf[128];
        SDL_Rect area;

        pSpaceShp = fc_calloc(1, sizeof(struct SMALL_DLG));

        fc_snprintf(cBuf, sizeof(cBuf), _("The %s Spaceship"),
                    nation_adjective_for_player(pPlayer));
        pStr = create_str16_from_char(cBuf, adj_font(12));
        pStr->style |= TTF_STYLE_BOLD;

        pWindow = create_window_skeleton(NULL, pStr, 0);

        pWindow->action = space_dialog_window_callback;
        set_wstate(pWindow, FC_WS_NORMAL);
        pWindow->data.player = pPlayer;
        pWindow->private_data.small_dlg = pSpaceShp;
        add_to_gui_list(ID_WINDOW, pWindow);
        pSpaceShp->pEndWidgetList = pWindow;

        area = pWindow->area;

        /* ---------- */
        /* create 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->data.player = pPlayer;
        pBuf->action = exit_space_dialog_callback;
        set_wstate(pBuf, FC_WS_NORMAL);
        pBuf->key = SDLK_ESCAPE;
        area.w = MAX(area.w, (pBuf->size.w + adj_size(10)));

        add_to_gui_list(ID_BUTTON, pBuf);

        pBuf = create_themeicon_button_from_chars(pTheme->OK_Icon, pWindow->dst,
                _("Launch"), adj_font(12), 0);

        pBuf->action = launch_spaceship_callback;
        area.w = MAX(area.w, pBuf->size.w);
        area.h += pBuf->size.h + adj_size(20);
        add_to_gui_list(ID_BUTTON, pBuf);

        pStr = create_str16_from_char(get_spaceship_descr(NULL), adj_font(12));
        pStr->bgcol = (SDL_Color) {
            0, 0, 0, 0
        };
        pBuf = create_iconlabel(NULL, pWindow->dst, pStr, WF_RESTORE_BACKGROUND);
        area.w = MAX(area.w, pBuf->size.w);
        area.h += pBuf->size.h + adj_size(20);
        add_to_gui_list(ID_LABEL, pBuf);

        pSpaceShp->pBeginWidgetList = pBuf;
        /* -------------------------------------------------------- */

        area.w = MAX(area.w, adj_size(300) - (pWindow->size.w - pWindow->area.w));

        resize_window(pWindow, NULL, NULL,
                      (pWindow->size.w - pWindow->area.w) + area.w,
                      (pWindow->size.h - pWindow->area.h) + area.h);

        area = pWindow->area;

        widget_set_position(pWindow,
                            (main_window_width() - pWindow->size.w) / 2,
                            (main_window_height() - 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);

        /* launch button */
        pBuf = pBuf->prev;
        pBuf->size.x = area.x + (area.w - pBuf->size.w) / 2;
        pBuf->size.y = area.y + area.h - pBuf->size.h - adj_size(7);

        /* info label */
        pBuf = pBuf->prev;
        pBuf->size.x = area.x + (area.w - pBuf->size.w) / 2;
        pBuf->size.y = area.y + adj_size(7);

        dialog_list_prepend(dialog_list, pSpaceShp);

        refresh_spaceship_dialog(pPlayer);
    } else {
        if (sellect_window_group_dialog(pSpaceShp->pBeginWidgetList,
                                        pSpaceShp->pEndWidgetList)) {
            widget_flush(pSpaceShp->pEndWidgetList);
        }
    }

}
示例#9
0
文件: plrdlg.c 项目: valisc/freeciv
/**************************************************************************
  Popup (or raise) the short player list dialog version.
**************************************************************************/
void popup_players_nations_dialog(void)
{
  struct widget *pWindow = NULL, *pBuf = NULL;
  SDL_Surface *pLogo = NULL;
  SDL_String16 *pStr;
  char cBuf[128], *state;
  int n = 0, w = 0, units_h = 0;
  const struct player_diplstate *pDS;
  SDL_Rect area;
  
  if (pShort_Players_Dlg) {
    return;
  }
     
  pShort_Players_Dlg = fc_calloc(1, sizeof(struct ADVANCED_DLG));
  
  /* TRANS: Nations report title */
  pStr = create_str16_from_char(_("Nations") , adj_font(12));
  pStr->style |= TTF_STYLE_BOLD;
  
  pWindow = create_window_skeleton(NULL, pStr, 0);
    
  pWindow->action = players_nations_window_dlg_callback;
  set_wstate(pWindow, FC_WS_NORMAL);
  
  add_to_gui_list(ID_WINDOW, pWindow);
  pShort_Players_Dlg->pEndWidgetList = pWindow;
  
  area = pWindow->area;
  
  /* ---------- */
  /* exit button */
  pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst,
                          WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND);
  pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"),
                                            adj_font(12));
  area.w = MAX(area.w, pBuf->size.w + adj_size(10));
  pBuf->action = exit_players_nations_dlg_callback;
  set_wstate(pBuf, FC_WS_NORMAL);
  pBuf->key = SDLK_ESCAPE;
  
  add_to_gui_list(ID_BUTTON, pBuf);
  /* ---------- */
  
  players_iterate(pPlayer) {
    if (pPlayer != client.conn.playing) {
      if(!pPlayer->is_alive || is_barbarian(pPlayer)) {
        continue;
      }
      
      pDS = player_diplstate_get(client.conn.playing, pPlayer);
            
      if(pPlayer->ai_controlled) {
	state = _("AI");
      } else {
        if (pPlayer->is_connected) {
          if (pPlayer->phase_done) {
      	    state = _("done");
          } else {
      	    state = _("moving");
          }
        } else {
          state = _("disconnected");
        }
      }
     
      if(pDS->type == DS_CEASEFIRE) {
	fc_snprintf(cBuf, sizeof(cBuf), "%s(%s) - %d %s",
                    nation_adjective_for_player(pPlayer),
                    state,
		pDS->turns_left, PL_("turn", "turns", pDS->turns_left));
      } else {
	fc_snprintf(cBuf, sizeof(cBuf), "%s(%s)",
                    nation_adjective_for_player(pPlayer),
                    state);
      }
      
      pStr = create_str16_from_char(cBuf, adj_font(10));
      pStr->style |= TTF_STYLE_BOLD;
   
      pLogo = get_nation_flag_surface(nation_of_player(pPlayer));
      
      pBuf = create_iconlabel(pLogo, pWindow->dst, pStr, 
    	(/*WF_FREE_THEME|*/WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE));
                      
      /* now add some eye candy ... */
      switch (pDS->type) {
	case DS_ARMISTICE:
	  pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE);
	  set_wstate(pBuf, FC_WS_NORMAL);
        break;
        case DS_WAR:
	  if(can_meet_with_player(pPlayer) || can_intel_with_player(pPlayer)) {
            set_wstate(pBuf, FC_WS_NORMAL);
	    pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR);
          } else {
	    pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_PLRDLG_WAR_RESTRICTED));
	  }
        break;
	case DS_CEASEFIRE:
	  pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE);
	  set_wstate(pBuf, FC_WS_NORMAL);
        break;
        case DS_PEACE:
	  pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE);
	  set_wstate(pBuf, FC_WS_NORMAL);
        break;
	case DS_ALLIANCE:
	  pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE);
	  set_wstate(pBuf, FC_WS_NORMAL);
        break;
	case DS_NO_CONTACT:
	  pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT));
	break;
        default:
	  set_wstate(pBuf, FC_WS_NORMAL);
        break;
      }
      
      pBuf->string16->bgcol = (SDL_Color) {0, 0, 0, 0};
    
      pBuf->data.player = pPlayer;
  
      pBuf->action = player_nation_callback;
            
  
      add_to_gui_list(ID_LABEL, pBuf);
    
      area.w = MAX(w, pBuf->size.w);
      area.h += pBuf->size.h;
    
      if (n > 19)
      {
        set_wflag(pBuf, WF_HIDDEN);
      }
      
      n++;  
    }
  } players_iterate_end;
  pShort_Players_Dlg->pBeginWidgetList = pBuf;
  pShort_Players_Dlg->pBeginActiveWidgetList = pShort_Players_Dlg->pBeginWidgetList;
  pShort_Players_Dlg->pEndActiveWidgetList = pWindow->prev->prev;
  pShort_Players_Dlg->pActiveWidgetList = pShort_Players_Dlg->pEndActiveWidgetList;
  
  
  /* ---------- */
  if (n > 20)
  {
     
    units_h = create_vertical_scrollbar(pShort_Players_Dlg, 1, 20, TRUE, TRUE);
    pShort_Players_Dlg->pScroll->count = n;
    
    n = units_h;
    area.w += n;
    
    units_h = 20 * pBuf->size.h;
    
  } else {
    units_h = area.h;
  }
        
  /* ---------- */
  
  area.h = units_h;

  resize_window(pWindow, NULL, NULL,
                (pWindow->size.w - pWindow->area.w) + area.w,
                (pWindow->size.h + pWindow->area.h) + area.h);
  
  area = pWindow->area;
  
  widget_set_position(pWindow,
    ((Main.event.motion.x + pWindow->size.w + adj_size(10) < Main.screen->w) ?
      (Main.event.motion.x + adj_size(10)) :
      (Main.screen->w - pWindow->size.w - adj_size(10))),
    ((Main.event.motion.y - adj_size(2) + pWindow->size.h < Main.screen->h) ?
      (Main.event.motion.y - adj_size(2)) :
      (Main.screen->h - pWindow->size.h - adj_size(10))));
  
  w = area.w;
  
  if (pShort_Players_Dlg->pScroll)
  {
    w -= n;
  }
  
  /* exit button */
  pBuf = pWindow->prev;
  pBuf->size.x = area.x + area.w - pBuf->size.w - 1;
  pBuf->size.y = pWindow->size.y + adj_size(2);
  
  /* cities */
  pBuf = pBuf->prev;
  setup_vertical_widgets_position(1,
	area.x, area.y,
	w, 0, pShort_Players_Dlg->pBeginActiveWidgetList, pBuf);
  
  if (pShort_Players_Dlg->pScroll)
  {
    setup_vertical_scrollbar_area(pShort_Players_Dlg->pScroll,
	area.x + area.w, area.y,
    	area.h, TRUE);
  }
  
  /* -------------------- */
  /* redraw */
  redraw_group(pShort_Players_Dlg->pBeginWidgetList, pWindow, 0);
  widget_mark_dirty(pWindow);
  
  flush_dirty();
}
示例#10
0
文件: plrdlg.c 项目: valisc/freeciv
/**************************************************************************
  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();
}
示例#11
0
/**************************************************************************
  ...
**************************************************************************/
static int spy_steal_popup(struct widget *pWidget)
{
  struct city *pVcity = pWidget->data.city;
  int id = MAX_ID - pWidget->ID;
  struct player *pVictim = NULL;
  struct CONTAINER *pCont;
  struct widget *pBuf = NULL;
  struct widget *pWindow;
  SDL_String16 *pStr;
  SDL_Surface *pSurf;
  int max_col, max_row, col, i, count = 0;
  SDL_Rect area;

  popdown_diplomat_dialog();
  
  if(pVcity)
  {
    pVictim = city_owner(pVcity);
  }
  
  if (pDiplomat_Dlg || !pVictim) {
    return 1;
  }
  
  count = 0;
  advance_index_iterate(A_FIRST, i) {
    if (player_invention_reachable(client.conn.playing, i, FALSE)
     && TECH_KNOWN == player_invention_state(pVictim, i)
     && (TECH_UNKNOWN == player_invention_state(client.conn.playing, i)
         || TECH_PREREQS_KNOWN ==
              player_invention_state(client.conn.playing, i))) {
      count++;
    }
  } advance_index_iterate_end;
  
  if(!count) {    
    /* if there is no known tech to steal then 
       send steal order at Spy's Discretion */
    int target_id = pVcity->id;

    request_diplomat_action(DIPLOMAT_STEAL, id, target_id, advance_count());
    return -1;
  }
    
  pCont = fc_calloc(1, sizeof(struct CONTAINER));
  pCont->id0 = pVcity->id;
  pCont->id1 = id;/* spy id */
  
  pDiplomat_Dlg = fc_calloc(1, sizeof(struct diplomat_dialog));
  pDiplomat_Dlg->diplomat_id = id;
  pDiplomat_Dlg->diplomat_target_id = pVcity->id;
  pDiplomat_Dlg->pdialog = fc_calloc(1, sizeof(struct ADVANCED_DLG));
      
  pStr = create_str16_from_char(_("Select Advance to Steal"), adj_font(12));
  pStr->style |= TTF_STYLE_BOLD;

  pWindow = create_window_skeleton(NULL, pStr, 0);
  
  pWindow->action = spy_steal_dlg_window_callback;
  set_wstate(pWindow , FC_WS_NORMAL);
  
  add_to_gui_list(ID_DIPLOMAT_DLG_WINDOW, pWindow);
  pDiplomat_Dlg->pdialog->pEndWidgetList = pWindow;
  
  area = pWindow->area;
  area.w = MAX(area.w, adj_size(8));  
  
  /* ------------------ */
  /* 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 = exit_spy_steal_dlg_callback;
  set_wstate(pBuf, FC_WS_NORMAL);
  pBuf->key = SDLK_ESCAPE;
  
  add_to_gui_list(ID_TERRAIN_ADV_DLG_EXIT_BUTTON, pBuf);  
  /* ------------------------- */
  
  count++; /* count + at Spy's Discretion */
  /* max col - 104 is steal tech widget width */
  max_col = (Main.screen->w - (pWindow->size.w - pWindow->area.w) - adj_size(2)) / adj_size(104);
  /* max row - 204 is steal tech widget height */
  max_row = (Main.screen->h - (pWindow->size.h - pWindow->area.h)) / adj_size(204);
  
  /* make space on screen for scrollbar */
  if (max_col * max_row < count) {
    max_col--;
  }

  if (count < max_col + 1) {
    col = count;
  } else {
    if (count < max_col + adj_size(3)) {
      col = max_col - adj_size(2);
    } else {
      if (count < max_col + adj_size(5)) {
        col = max_col - 1;
      } else {
        col = max_col;
      }
    }
  }
  
  pStr = create_string16(NULL, 0, adj_font(10));
  pStr->style |= (TTF_STYLE_BOLD | SF_CENTER);
  
  count = 0;
  advance_index_iterate(A_FIRST, i) {
    if (player_invention_reachable(client.conn.playing, i, FALSE)
     && TECH_KNOWN == player_invention_state(pVictim, i)
     && (TECH_UNKNOWN == player_invention_state(client.conn.playing, i)
         || TECH_PREREQS_KNOWN ==
              player_invention_state(client.conn.playing, i))) {
      count++;

      copy_chars_to_string16(pStr, advance_name_translation(advance_by_number(i)));
      pSurf = create_sellect_tech_icon(pStr, i, FULL_MODE);
      pBuf = create_icon2(pSurf, pWindow->dst,
      		WF_FREE_THEME | WF_RESTORE_BACKGROUND);

      set_wstate(pBuf, FC_WS_NORMAL);
      pBuf->action = spy_steal_callback;
      pBuf->data.cont = pCont;

      add_to_gui_list(MAX_ID - i, pBuf);
    
      if (count > (col * max_row)) {
        set_wflag(pBuf, WF_HIDDEN);
      }
    }
  } advance_index_iterate_end;
  
  /* get spy tech */
  i = advance_number(unit_type(game_unit_by_number(id))->require_advance);
  copy_chars_to_string16(pStr, _("At Spy's Discretion"));
  pSurf = create_sellect_tech_icon(pStr, i, FULL_MODE);
	
  pBuf = create_icon2(pSurf, pWindow->dst,
    	(WF_FREE_THEME | WF_RESTORE_BACKGROUND| WF_FREE_DATA));
  set_wstate(pBuf, FC_WS_NORMAL);
  pBuf->action = spy_steal_callback;
  pBuf->data.cont = pCont;
    
  add_to_gui_list(MAX_ID - advance_count(), pBuf);
  count++;
  
  /* --------------------------------------------------------- */
  FREESTRING16(pStr);
  pDiplomat_Dlg->pdialog->pBeginWidgetList = pBuf;
  pDiplomat_Dlg->pdialog->pBeginActiveWidgetList = pDiplomat_Dlg->pdialog->pBeginWidgetList;
  pDiplomat_Dlg->pdialog->pEndActiveWidgetList = pDiplomat_Dlg->pdialog->pEndWidgetList->prev->prev;
  
  /* -------------------------------------------------------------- */
  
  i = 0;
  if (count > col) {
    count = (count + (col - 1)) / col;
    if (count > max_row) {
      pDiplomat_Dlg->pdialog->pActiveWidgetList = pDiplomat_Dlg->pdialog->pEndActiveWidgetList;
      count = max_row;
      i = create_vertical_scrollbar(pDiplomat_Dlg->pdialog, col, count, TRUE, TRUE);  
    }
  } else {
    count = 1;
  }

  area.w = MAX(area.w, (col * pBuf->size.w + adj_size(2) + i));
  area.h = count * pBuf->size.h + adj_size(2);

  /* alloca window theme and win background buffer */
  pSurf = theme_get_background(theme, BACKGROUND_SPYSTEALDLG);
  if (resize_window(pWindow, pSurf, NULL,
                    (pWindow->size.w - pWindow->area.w) + area.w,
                    (pWindow->size.h - pWindow->area.h) + area.h))
  {
    FREESURFACE(pSurf);
  }
  
  area = pWindow->area;
  
  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);
  
  setup_vertical_widgets_position(col, area.x + 1,
		  area.y, 0, 0,
		  pDiplomat_Dlg->pdialog->pBeginActiveWidgetList,
  		  pDiplomat_Dlg->pdialog->pEndActiveWidgetList);
    
  if(pDiplomat_Dlg->pdialog->pScroll) {
    setup_vertical_scrollbar_area(pDiplomat_Dlg->pdialog->pScroll,
	area.x + area.w, area.y,
    	area.h, TRUE);
  }

  redraw_group(pDiplomat_Dlg->pdialog->pBeginWidgetList, pWindow, FALSE);
  widget_mark_dirty(pWindow);
  
  return -1;
}