const WRATHFontConfig::FontSpecification&
WRATHFontConfig::
fetch_font_entry_detailed(const InFontSpecification &spec)
{
  WRATHStaticInit();

  static FontSpecification null_value;
  WRATHFontFetch::font_handle hnd;
  FontList::const_iterator iter;

  hnd=fetch_font_entry(spec);
  iter=font_list().find(hnd);

  return (iter!=font_list().end())?
    iter->second:
    null_value;
}
示例#2
0
文件: label.cpp 项目: roSievers/anura
widget_settings_dialog* label::settings_dialog(int x, int y, int w, int h)
{
	widget_settings_dialog* d = widget::settings_dialog(x,y,w,h);

	grid_ptr g(new grid(2));

	text_editor_widget_ptr text_edit = new text_editor_widget(150, 30);
	text_edit->set_text(text());
	text_edit->set_on_user_change_handler([=](){set_text(text_edit->text());});
	g->add_col(new label("Text:", d->text_size(), d->font()))
		.add_col(text_edit);

	g->add_col(new label("Size:", d->text_size(), d->font())).
		add_col(new slider(120, [&](double f){set_font_size(int(f*72.0+6.0));}, (size()-6.0)/72.0, 1));

	std::vector<std::string> fonts = font::get_available_fonts();
	fonts.insert(fonts.begin(), "");
	dropdown_widget_ptr font_list(new dropdown_widget(fonts, 150, 28, dropdown_widget::DROPDOWN_LIST));
	font_list->set_font_size(14);
	font_list->set_dropdown_height(height());
	auto fit = std::find(fonts.begin(), fonts.end(), font());
	font_list->set_selection(fit == fonts.end() ? 0 : fit-fonts.begin());
	font_list->set_on_select_handler([&](int n, const std::string& s){set_font(s);});
	font_list->set_zorder(19);
	g->add_col(new label("Font:", d->text_size(), d->font()))
		.add_col(font_list);
	g->add_col(new label("Color:", d->text_size(), d->font()))
		.add_col(new button(new label("Choose...", d->text_size(), d->font()), [&](){
			int mx, my;
			SDL_GetMouseState(&mx, &my);
			mx = mx + 200 > preferences::actual_screen_width() ? preferences::actual_screen_width()-200 : mx;
			my = my + 600 > preferences::actual_screen_height() ? preferences::actual_screen_height()-600 : my;
			my -= d->y();
			color_picker* cp = new color_picker(rect(0, 0, 200, 600), [&](const graphics::color& color){set_color(color.as_sdl_color());});
			cp->set_primary_color(graphics::color(color_));

			grid_ptr gg = new grid(1);
			gg->allow_selection();
			gg->swallow_clicks();
			gg->set_show_background(true);
			gg->allow_draw_highlight(false);
			gg->register_selection_callback([=](int n){if(n != 0){d->remove_widget(gg); d->init();}});
			gg->set_zorder(100);
			gg->add_col(cp);
			d->add_widget(gg, d->x()-mx-100, my);
	}));

	d->add_widget(g);
	return d;
}