示例#1
0
void adjust_sizes(const display &disp, size_specs &sizes) {
	/** @todo Hardcoded coordinates for brush selection, make them themeable. */
	sizes.brush_x = disp.map_outside_area().w + 12;
	sizes.brush_y = (disp.h() >= 768) ? 340 : 270;
	/** @todo Hardcoded coordinates for terrain palette, make them themeable. */
	sizes.palette_x = disp.map_outside_area().w + 12;
	sizes.palette_y = sizes.brush_y + 33;
	sizes.palette_w = 174; // sizes.terrain_space * sizes.terrain_width;
	sizes.palette_h = disp.h() - sizes.palette_y;
}
示例#2
0
file_dialog::file_dialog(display &disp, const std::string& file_path,
		const std::string& title, bool show_directory_buttons) :
	gui::dialog(disp, title, file_path, gui::OK_CANCEL),
	show_directory_buttons_(show_directory_buttons),
	files_list_(NULL),
	last_selection_(-1),
	last_textbox_text_(),
	chosen_file_(".."),
    autocomplete_(true)
{
	files_list_ = new gui::file_menu(disp.video(), file_path);
	const unsigned file_list_height = (disp.h() / 2);
	const unsigned file_list_width = std::min<unsigned>(files_list_->width(), (disp.w() / 4));
	files_list_->set_measurements(file_list_width, file_list_height);
	files_list_->set_max_height(file_list_height);
	set_menu(files_list_);
	get_message().set_text(format_dirname(files_list_->get_directory()));
	set_textbox(_("File: "), format_filename(file_path), 100);
	if (show_directory_buttons_)
	{
		add_button( new gui::dialog_button(disp.video(), _("Delete File"),
					gui::button::TYPE_PRESS, gui::DELETE_ITEM), dialog::BUTTON_EXTRA);
		add_button( new gui::dialog_button(disp.video(), _("New Folder"),
					gui::button::TYPE_PRESS, gui::CREATE_ITEM), dialog::BUTTON_EXTRA_LEFT);
	}
}
示例#3
0
void adjust_sizes(const display &disp, size_specs &sizes) {
	/** @todo Hardcoded coordinates for brush selection, make it themeable. */
	sizes.brush_x = disp.map_outside_area().w + 10;
	sizes.brush_y = 212;
	/** @todo Hardcoded coordinates for terrain palette, make it themeable. */
	sizes.palette_x = disp.map_outside_area().w + 16;
	sizes.palette_y = sizes.brush_y + 72;
	sizes.palette_w = sizes.terrain_space * default_palette_width;
	sizes.palette_h = disp.h() - sizes.palette_y;
}
void show_hotkeys_dialog (display & disp, config *save_config)
{
	log_scope ("show_hotkeys_dialog");

	const events::event_context dialog_events_context;

	const int centerx = disp.w()/2;
	const int centery = disp.h()/2;
	const int width  = 700;
	const int height = disp.video().gety() < 600 ? 380 : 500;
	const int xpos = centerx  - width/2;
	const int ypos = centery  - height/2;

	gui::button close_button (disp.video(), _("Close"));
	std::vector<gui::button*> buttons;
	buttons.push_back(&close_button);

	gui::dialog_frame f(disp.video(),_("Hotkey Settings"),gui::dialog_frame::default_style,true,&buttons);
	f.layout(xpos,ypos,width,height);
	f.draw();

	SDL_Rect clip_rect = create_rect(0, 0, disp.w (), disp.h ());
	SDL_Rect text_size = font::draw_text(NULL, clip_rect, font::SIZE_LARGE,
					     font::NORMAL_COLOR,_("Press desired hotkey (Esc cancels)"),
					     0, 0);

	std::vector<std::string> menu_items;

	std::vector<hotkey::hotkey_item>& hotkeys = hotkey::get_hotkeys();
	for(std::vector<hotkey::hotkey_item>::iterator i = hotkeys.begin(); i != hotkeys.end(); ++i) {
		if(i->hidden() || !i->is_in_active_scope())
			continue;
		std::stringstream str,name;
		name << i->get_description();
		str << name.str();
		str << COLUMN_SEPARATOR;
		// This trick allows to display chars identical to markup characters
		str << font::NULL_MARKUP << i->get_name();
		menu_items.push_back(str.str());
	}

	std::ostringstream heading;
	heading << HEADING_PREFIX << _("Action") << COLUMN_SEPARATOR << _("Binding");
	menu_items.push_back(heading.str());

	gui::menu::basic_sorter sorter;
	sorter.set_alpha_sort(0).set_alpha_sort(1);

	gui::menu menu_(disp.video(), menu_items, false, height - font::relative_size(10), -1, &sorter, &gui::menu::bluebg_style);
	menu_.sort_by(0);
	menu_.reset_selection();
	menu_.set_width(font::relative_size(500));
	menu_.set_location(xpos + font::relative_size(10), ypos + font::relative_size(10));

	gui::button change_button (disp.video(), _("Change Hotkey"));
	change_button.set_location(xpos + width - change_button.width () - font::relative_size(30),ypos + font::relative_size(30));

	gui::button clear_button (disp.video(), _("Clear Hotkey"));
	clear_button.set_location(xpos + width - clear_button.width () - font::relative_size(30),ypos + font::relative_size(80));
//	gui::button save_button (disp.video(), _("Save Hotkeys"));
//	save_button.set_location(xpos + width - save_button.width () - font::relative_size(30),ypos + font::relative_size(130));

	escape_handler esc_hand;

	for(;;) {

		if (close_button.pressed() || esc_hand.escape_pressed())
		{
			if (save_config == NULL) {
				save_hotkeys();
			} else {
				hotkey::save_hotkeys(*save_config);
			}
			break;
		}

		if (change_button.pressed () || menu_.double_clicked()) {
			// Lets change this hotkey......
			SDL_Rect dlgr = create_rect(centerx - text_size.w / 2 - 30
					, centery - text_size.h / 2 - 16
					, text_size.w + 60
					, text_size.h + 32);

			surface_restorer restorer(&disp.video(),dlgr);
			gui::dialog_frame mini_frame(disp.video());
			mini_frame.layout(centerx-text_size.w/2 - 20,
									centery-text_size.h/2 - 6,
									text_size.w+40,
									text_size.h+12);
			mini_frame.draw_background();
			mini_frame.draw_border();
			font::draw_text (&disp.video(), clip_rect, font::SIZE_LARGE,font::NORMAL_COLOR,
				 _("Press desired hotkey (Esc cancels)"),centerx-text_size.w/2,
				 centery-text_size.h/2);
			disp.update_display();
			SDL_Event event;
			event.type = 0;
			int character = 0, keycode = 0, mod = 0; // Just to avoid warning
			int joystick = 0, button = 0, hat = 0, value = 0;
			const int any_mod = KMOD_CTRL | KMOD_ALT | KMOD_LMETA;

			while (event.type!=SDL_KEYDOWN && event.type!=SDL_JOYBUTTONDOWN && event.type!= SDL_JOYHATMOTION) SDL_PollEvent(&event);
			do {
				if (event.type==SDL_KEYDOWN)
				{
					keycode=event.key.keysym.sym;
					character=event.key.keysym.unicode;
					mod=event.key.keysym.mod;
				};
				if (event.type==SDL_JOYBUTTONDOWN) {
					joystick = event.jbutton.which;
					button = event.jbutton.button;
				}
				if (event.type==SDL_JOYHATMOTION) {
					joystick = event.jhat.which;
					hat = event.jhat.hat;
					value = event.jhat.value;
				}
				SDL_PollEvent(&event);
				disp.flip();
				disp.delay(10);
			} while (event.type!=SDL_KEYUP && event.type!=SDL_JOYBUTTONUP && event.type!=SDL_JOYHATMOTION);
			restorer.restore();
			disp.update_display();
			if (keycode == SDLK_ESCAPE && (mod & any_mod) == 0) {
				//cancel -- no action
			} else {
				const hotkey::hotkey_item& oldhk = hotkey::get_hotkey(character, keycode, (mod & KMOD_SHIFT) != 0,
						(mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);

				hotkey::hotkey_item& newhk = hotkey::get_visible_hotkey(menu_.selection());

				if(oldhk.get_id() != newhk.get_id() && !oldhk.null()) {
					std::stringstream msg;
					msg << "   " << oldhk.get_description() << " : " << oldhk.get_name();
					gui2::show_transient_message(disp.video(),_("This hotkey is already in use."),msg.str());
				} else {
					if (event.type == SDL_JOYHATMOTION) {
						const hotkey::hotkey_item& oldhkhat = hotkey::get_hotkey(joystick, hat, value);

						if(oldhkhat.get_id() != newhk.get_id() && !oldhkhat.null()) {
							std::stringstream msg;
							msg << "   " << oldhkhat.get_description() << " : " << oldhkhat.get_name();
							gui2::show_transient_message(disp.video(),_("This hotkey is already in use."),msg.str());
						} else {
							newhk.set_hat(joystick, hat, value);
							menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name());
						}
					} else
					if (event.type == SDL_JOYBUTTONUP) {
						const hotkey::hotkey_item& oldhkbtn = hotkey::get_hotkey(button, joystick);

						if(oldhkbtn.get_id() != newhk.get_id() && !oldhkbtn.null()) {
							std::stringstream msg;
							msg << "   " << oldhkbtn.get_description() << " : " << oldhkbtn.get_name();
							gui2::show_transient_message(disp.video(),_("This hotkey is already in use."),msg.str());
						} else {
							newhk.set_button(button, joystick);
							menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name());
						}
					} else {

						newhk.set_key(character, keycode, (mod & KMOD_SHIFT) != 0,
								(mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);

						menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name());

						if ((newhk.get_id() == hotkey::HOTKEY_SCREENSHOT
								|| newhk.get_id() == hotkey::HOTKEY_MAP_SCREENSHOT)
								&& (mod & any_mod) == 0) {
							gui2::show_transient_message(disp.video(), _("Warning"), _("Screenshot hotkeys should be combined with the Control, Alt or Meta modifiers to avoid problems."));
						}
					}
				}
			}
		}
//		if (save_button.pressed()) {
//			if (save_config == NULL) {
//				save_hotkeys();
//			} else {
//				hotkey::save_hotkeys(*save_config);
//			}
//		}

		if (clear_button.pressed()) {
			// clear hotkey
			hotkey::hotkey_item& newhk = hotkey::get_visible_hotkey(menu_.selection());
			newhk.clear_hotkey();
			menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name());
		}

		menu_.process();

		events::pump();
		events::raise_process_event();
		events::raise_draw_event();

		disp.update_display();

		disp.delay(10);
	}
}
示例#5
0
static network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))
{
	const size_t width = 300;
	const size_t height = 80;
	const size_t border = 20;
	const int left = disp.w()/2 - width/2;
	const int top  = disp.h()/2 - height/2;

	const events::event_context dialog_events_context;

	gui::button cancel_button(disp.video(),_("Cancel"));
	std::vector<gui::button*> buttons_ptr(1,&cancel_button);

	gui::dialog_frame frame(disp.video(), msg, gui::dialog_frame::default_style, true, &buttons_ptr);
	SDL_Rect centered_layout = frame.layout(left,top,width,height).interior;
	centered_layout.x = disp.w() / 2 - centered_layout.w / 2;
	centered_layout.y = disp.h() / 2 - centered_layout.h / 2;
	// HACK: otherwise we get an empty useless space in the dialog below the progressbar
	centered_layout.h = height;
	frame.layout(centered_layout);
	frame.draw();

	const SDL_Rect progress_rect = create_rect(centered_layout.x + border
			, centered_layout.y + border
			, centered_layout.w - border * 2
			, centered_layout.h - border * 2);

	gui::progress_bar progress(disp.video());
	progress.set_location(progress_rect);

	events::raise_draw_event();
	disp.flip();

	network::statistics old_stats = get_stats(connection_num);

	cfg.clear();
	for(;;) {
		const network::connection res = network::receive_data(cfg,connection_num,100);
		const network::statistics stats = get_stats(connection_num);
		if(stats.current_max != 0 && stats != old_stats) {
			old_stats = stats;
			progress.set_progress_percent((stats.current*100)/stats.current_max);
			std::ostringstream stream;
			stream << stats.current/1024 << "/" << stats.current_max/1024 << _("KB");
			progress.set_text(stream.str());
		}

		events::raise_draw_event();
		disp.flip();
		events::pump();

		if(res != 0) {
			return res;
		}


		if(cancel_button.pressed()) {
			return res;
		}
	}
}