本文整理汇总了C++中twindow::canvas方法的典型用法代码示例。如果您正苦于以下问题:C++ twindow::canvas方法的具体用法?C++ twindow::canvas怎么用?C++ twindow::canvas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twindow
的用法示例。
在下文中一共展示了twindow::canvas方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pre_show
void tstory_screen::pre_show(CVideo& video, twindow& window)
{
// set_restore(false);
window.set_click_dismiss(false);
window.set_enter_disabled(true);
window.set_escape_disabled(true);
if (!part_["story"].str().empty()) {
window.canvas()[0].set_variable("background_image", variant(part_["story"].str()));
} else {
window.canvas()[0].set_variable("background_image", variant(game_config::images::game_title));
}
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "next_tip", false)
, boost::bind(
&tstory_screen::update_tip
, this
, boost::ref(window)
, true));
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "previous_tip", false)
, boost::bind(
&tstory_screen::update_tip
, this
, boost::ref(window)
, false));
}
示例2: pre_show
/**
* @todo This function enables the wml markup for all items, but the interface
* is a bit hacky. Especially the fiddling in the internals of the listbox is
* ugly. There needs to be a clean interface to set whether a widget has a
* markup and what kind of markup. These fixes will be post 1.6.
*/
void twml_message_::pre_show(twindow& window)
{
set_restore(true);
window.canvas(1).set_variable("portrait_image", variant(portrait_));
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
// Set the markup
tlabel& title = find_widget<tlabel>(&window, "title", false);
title.set_label(title_);
title.set_use_markup(true);
title.set_can_wrap(true);
tcontrol& message = find_widget<tcontrol>(&window, "message", false);
message.set_label(message_);
message.set_use_markup(true);
// The message label might not always be a scroll_label but the capturing
// shouldn't hurt.
window.keyboard_capture(&message);
// Find the input box related fields.
tlabel& caption = find_widget<tlabel>(&window, "input_caption", false);
ttext_box& input = find_widget<ttext_box>(&window, "input", true);
if(has_input_) {
caption.set_label(input_caption_);
caption.set_use_markup(true);
input.set_value(*input_text_);
input.set_maximum_length(input_maximum_length_);
window.keyboard_capture(&input);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
} else {
caption.set_visible(twidget::tvisible::invisible);
input.set_visible(twidget::tvisible::invisible);
}
// Find the option list related fields.
tlistbox& options = find_widget<tlistbox>(&window, "input_list", true);
if(!option_list_.empty()) {
std::map<std::string, string_map> data;
BOOST_FOREACH(const twml_message_option& item, option_list_) {
// Add the data.
data["icon"]["label"] = item.image();
data["label"]["label"] = item.label();
data["label"]["use_markup"] = "true";
data["description"]["label"] = item.description();
data["description"]["use_markup"] = "true";
options.add_row(data);
}
示例3: pre_show
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
assert(!video_);
video_ = &video;
set_restore(false);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
window.canvas()[0].set_variable("revision_number",
variant(_("Version") + std::string(" ") + game_config::revision));
/**** Set the buttons ****/
// find_widget<tbutton>(&window, "addons", false).
// set_callback_mouse_left_click(show_dialog<gui2::taddon_connect>);
// Note changing the language doesn't upate the title screen...
find_widget<tbutton>(&window, "language", false).
set_callback_mouse_left_click(
show_dialog<gui2::tlanguage_selection>);
/**** Set the tip of the day ****/
/*
update_tip(window, true);
find_widget<tbutton>(&window, "next_tip", false).
set_callback_mouse_left_click(next_tip);
find_widget<tbutton>(&window, "previous_tip", false).
set_callback_mouse_left_click(previous_tip);
*/
/***** Select a random game_title *****/
std::vector<std::string> game_title_list =
utils::split(game_config::game_title
, ','
, utils::STRIP_SPACES | utils::REMOVE_EMPTY);
if(game_title_list.empty()) {
ERR_CF << "No title image defined\n";
} else {
window.canvas()[0].set_variable("background_image",
variant(game_title_list[rand()%game_title_list.size()]));
}
}
示例4: defined
void texample2::pre_show(CVideo& /*video*/, twindow& window)
{
// set backgroup image.
window.canvas()[0].set_variable("background_image", variant("dialogs/default-background.png"));
// prepare navigate bar.
std::vector<std::string> labels;
labels.push_back(_("Chat"));
labels.push_back(_("Preferences"));
navigate_ = find_widget<treport>(&window, "navigate", false, true);
navigate_->tabbar_init(true, "dusk_tab");
navigate_->set_boddy(find_widget<twidget>(&window, "main_panel", false, true));
int index = 0;
for (std::vector<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++ it) {
tcontrol* widget = navigate_->create_child(null_str, null_str, reinterpret_cast<void*>(index ++));
widget->set_label(*it);
navigate_->insert_child(*widget);
}
navigate_->select(start_page_);
navigate_->replacement_children();
page_panel_ = find_widget<tstacked_widget>(&window, "main_layers", false, true);
swap_page(window, start_page_, false);
// preferences grid
ttoggle_button* toggle = find_widget<ttoggle_button>(&window, "fullscreen_button", false, true);
#if (defined(__APPLE__) && TARGET_OS_IPHONE) || defined(ANDROID)
toggle->set_visible(twidget::INVISIBLE);
find_widget<tbutton>(&window, "video_mode_button", false).set_visible(twidget::INVISIBLE);
#else
toggle->set_callback_state_change(boost::bind(&texample2::fullscreen_toggled, this, _1));
toggle->set_value(preferences::fullscreen());
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "video_mode_button", false)
, boost::bind(
&texample2::video_mode_button
, this
, boost::ref(window)));
#endif
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "change_language_button", false)
, boost::bind(
&texample2::set_retval
, this
, boost::ref(window)
, (int)CHANGE_LANGUAGE));
}
示例5: pre_show
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
set_restore(false);
window.set_click_dismiss(false);
window.set_enter_disabled(true);
window.set_escape_disabled(true);
#ifdef DEBUG_TOOLTIP
window.connect_signal<event::SDL_MOUSE_MOTION>(
boost::bind(debug_tooltip, boost::ref(window), _3, _5),
event::tdispatcher::front_child);
#endif
/**** Set the version number ****/
if(tcontrol* control
= find_widget<tcontrol>(&window, "revision_number", false, false)) {
control->set_label(_("Version ") + game_config::revision);
}
window.canvas()[0].set_variable(
"revision_number",
variant(_("Version") + std::string(" ") + game_config::revision));
/**** Set the tip of the day ****/
tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);
std::vector<ttip> tips(settings::get_tips());
if(tips.empty()) {
WRN_CF << "There are not tips of day available." << std::endl;
}
FOREACH(const AUTO & tip, tips)
{
string_map widget;
std::map<std::string, string_map> page;
widget["label"] = tip.text();
widget["use_markup"] = "true";
page["tip"] = widget;
widget["label"] = tip.source();
widget["use_markup"] = "true";
page["source"] = widget;
tip_pages.add_page(page);
}
示例6: finish_duel
void tduel::finish_duel(twindow& window)
{
std::stringstream str;
// disable all button/toggle_button
for (int index2 = 0; index2 < setting_[0].count_; index2 ++) {
str.str("");
str << "lcard" << index2;
ttoggle_button* toggle = find_widget<ttoggle_button>(&window, str.str(), false, false);
toggle->set_value(false);
toggle->set_active(false);
for (int i = 0; i < 6; i ++) {
toggle->canvas()[i].set_variable("foreground", variant(""));
}
toggle->set_label("");
}
lskill0_->set_active(false);
lskill0_->set_value(false);
for (int i = 0; i < 6; i ++) {
lskill0_->canvas()[i].set_variable("image", variant(""));
}
lskill1_->set_active(false);
lskill1_->set_value(false);
for (int i = 0; i < 6; i ++) {
lskill1_->canvas()[i].set_variable("image", variant(""));
}
if (hp_ < TOTAL_HP / 2) {
window.canvas(1).set_variable("center_image", variant(right_.image(true)));
if (hp_ == 0) {
window.canvas(1).set_variable("left_image", variant(std::string(left_.image(true)) + "~GS()"));
}
window.canvas(1).set_variable("right_image", variant(""));
sound::play_music_once("defeat.ogg");
} else if (hp_ > TOTAL_HP / 2) {
window.canvas(1).set_variable("center_image", variant(left_.image(true)));
window.canvas(1).set_variable("left_image", variant(""));
if (hp_ == TOTAL_HP) {
window.canvas(1).set_variable("right_image", variant(std::string(right_.image(true)) + "~GS()"));
}
sound::play_music_once("victory.ogg");
}
endturn_->set_sound_button_click("");
finished_ = true;
}
示例7: pre_show
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
set_restore(false);
window.set_click_dismiss(false);
window.set_enter_disabled(true);
window.set_escape_disabled(true);
/**** Set the version number ****/
if(tcontrol* control
= find_widget<tcontrol>(&window, "revision_number", false, false)) {
control->set_label(_("Version ") + game_config::revision);
}
window.canvas()[0].set_variable("revision_number",
variant(_("Version") + std::string(" ") + game_config::revision));
/**** Set the tip of the day ****/
tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);
std::vector<ttip> tips(settings::get_tips());
if(tips.empty()) {
WRN_CF << "There are not tips of day available.\n";
}
foreach(const ttip& tip, tips) {
string_map widget;
std::map<std::string, string_map> page;
widget["label"] = tip.text();
widget["use_markup"] = "true";
page["tip"] = widget;
widget["label"] = tip.source();
widget["use_markup"] = "true";
page["source"] = widget;
tip_pages.add_page(page);
}
示例8: pre_show
/**
* @todo This function enables the wml markup for all items, but the interface
* is a bit hacky. Especially the fiddling in the internals of the listbox is
* ugly. There needs to be a clean interface to set whether a widget has a
* markup and what kind of markup. These fixes will be post 1.6.
*/
void twml_message_::pre_show(CVideo& /*video*/, twindow& window)
{
window.canvas(1).set_variable("portrait_image", variant(portrait_));
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
// Set the markup
tlabel& title = find_widget<tlabel>(&window, "title", false);
title.set_label(title_);
title.set_use_markup(true);
title.set_can_wrap(true);
tcontrol& message = find_widget<tcontrol>(&window, "message", false);
message.set_label(message_);
message.set_use_markup(true);
// The message label might not always be a scroll_label but the capturing
// shouldn't hurt.
window.keyboard_capture(&message);
// Find the input box related fields.
tlabel& caption = find_widget<tlabel>(&window, "input_caption", false);
ttext_box& input = find_widget<ttext_box>(&window, "input", true);
if(has_input_) {
caption.set_label(input_caption_);
caption.set_use_markup(true);
input.set_value(*input_text_);
input.set_maximum_length(input_maximum_length_);
window.keyboard_capture(&input);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
} else {
caption.set_visible(twidget::tvisible::invisible);
input.set_visible(twidget::tvisible::invisible);
}
// Find the option list related fields.
tlistbox& options = find_widget<tlistbox>(&window, "input_list", true);
if(!option_list_.empty()) {
std::map<std::string, string_map> data;
for(size_t i = 0; i < option_list_.size(); ++i) {
/**
* @todo This syntax looks like a bad hack, it would be nice to write
* a new syntax which doesn't use those hacks (also avoids the problem
* with special meanings for certain characters.
*/
tlegacy_menu_item item(option_list_[i]);
if(item.is_default()) {
// Number of items hasn't been increased yet so i is ok.
*chosen_option_ = i;
}
// Add the data.
data["icon"]["label"] = item.icon();
data["label"]["label"] = item.label();
data["label"]["use_markup"] = "true";
data["description"]["label"] = item.description();
data["description"]["use_markup"] = "true";
options.add_row(data);
}
// Avoid negative and 0 since item 0 is already selected.
if(*chosen_option_ > 0
&& static_cast<size_t>(*chosen_option_)
< option_list_.size()) {
options.select_row(*chosen_option_);
}
if(!has_input_) {
window.keyboard_capture(&options);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
} else {
window.add_to_keyboard_chain(&options);
// click_dismiss has been disabled due to the input.
}
} else {
options.set_visible(twidget::tvisible::invisible);
}
window.set_click_dismiss(!has_input_ && option_list_.empty());
}
示例9: pre_show
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
window_ = &window;
set_restore(false);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
std::stringstream strstr;
std::string color = game_config::local_only? "red": "green";
strstr.str("");
tlabel* label = find_widget<tlabel>(&window, "coin", true, true);
strstr << tintegrate::generate_format(group.coin(), color, 17);
label->set_label(strstr.str());
strstr.str("");
label = find_widget<tlabel>(&window, "score", true, true);
strstr << tintegrate::generate_format(group.score(), color, 17);
label->set_label(strstr.str());
strstr.str("");
label = find_widget<tlabel>(&window, "signin_data", true, true);
if (!game_config::local_only) {
strstr << tintegrate::generate_format(group.signin().continue_days, "green", 17) << "/";
if (!group.signin().break_days) {
color = "green";
} else if (group.signin().break_days < game_config::max_breaks) {
color = "yellow";
} else {
color = "red";
}
strstr << tintegrate::generate_format(group.signin().break_days, color, 17);
} else {
strstr << tintegrate::generate_format("---/-", "white", 17);
}
label->set_label(strstr.str());
tcontrol* control = find_widget<tcontrol>(&window, "icon_vip", true, true);
if (!preferences::vip2()) {
control->set_visible(twidget::INVISIBLE);
}
// Set the version number
control = find_widget<tcontrol>(&window, "revision_number", false, false);
if (control) {
control->set_label(_("V") + game_config::version);
// control->set_label(_("V") + game_config::version + "-alpha");
// control->set_label(_("v") + game_config::version + "-beta");
// control->set_label(_("v") + game_config::version + "-beta3");
}
window.canvas()[0].set_variable("revision_number", variant(_("Version") + std::string(" ") + game_config::version));
if (!game_config::images::game_title.empty()) {
window.canvas()[0].set_variable("background_image", variant(game_config::images::game_title));
}
/***** Set the logo *****/
tcontrol* logo = find_widget<tcontrol>(&window, "logo", false, false);
if (logo) {
logo->set_label(game_config::logo_png);
}
label = find_widget<tlabel>(&window, "player_name", false, true);
label->set_label(player_hero_.name());
tbutton* b;
for (int item = 0; item < nb_items; item ++) {
b = find_widget<tbutton>(&window, menu_items[item], false, false);
if (!b) {
continue;
}
std::string str;
if (!strcmp(menu_items[item], "player")) {
str = player_hero_.image(true);
} else if (!strcmp(menu_items[item], "signin")) {
if (group.signin().today) {
str = std::string("icons/") + "signin-ok" + ".png";
} else {
str = std::string("icons/") + "signin" + ".png";
}
} else {
if (!strcmp(menu_items[item], "message")) {
if (group.message_count()) {
b->set_label("misc/red-dot12.png");
}
}
str = std::string("icons/") + menu_items[item] + ".png";
}
for (int i = 0; i < 4; i ++) {
b->canvas()[i].set_variable("image", variant(str));
}
}
if (game_config::tiny_gui) {
b = find_widget<tbutton>(&window, "design", false, false);
if (b) {
//.........这里部分代码省略.........
示例10: pre_show
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
set_restore(false);
window.set_click_dismiss(false);
window.set_enter_disabled(true);
window.set_escape_disabled(true);
/**** Set the version number ****/
if (tcontrol* control
= find_widget<tcontrol>(&window, "revision_number", false, false)) {
control->set_label(_("Version ") + game_config::revision);
// control->set_label(_("Version ") + game_config::revision + "-alpha");
// control->set_label(_("Version ") + game_config::revision + "-beta");
}
window.canvas()[0].set_variable("revision_number", variant(_("Version") + std::string(" ") + game_config::revision));
if (game_config::images::game_title.empty()) {
} else {
window.canvas()[0].set_variable("background_image",
variant(game_config::images::game_title));
}
/***** Set the logo *****/
tcontrol* logo = find_widget<tcontrol>(&window, "logo", false, false);
if (logo) {
logo->set_label("misc/logo.png");
}
std::string player_name;
tbutton* b = find_widget<tbutton>(&window, "player", false, false);
if (b) {
for (int i = 0; i < 4; i ++) {
player_name = player_hero_.image(true);
b->canvas()[i].set_variable("image", variant(player_name));
}
}
player_name = player_hero_.name();
ttext_box* user_widget = find_widget<ttext_box>(&window, "player_name", false, true);
user_widget->set_value(player_name);
// user_widget->set_maximum_length(max_login_size);
user_widget->set_active(false);
for (int item = 0; item < nb_items; item ++) {
tbutton* b = find_widget<tbutton>(&window, menu_items[item], false, false);
if (!b) {
continue;
}
std::string str = std::string("icons/") + menu_items[item] + ".png";
int i;
for (i = 0; i < 4; i ++) {
b->canvas()[i].set_variable("image", variant(str));
}
}
if (game_config::tiny_gui) {
tbutton* b = find_widget<tbutton>(&window, "editor", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
b = find_widget<tbutton>(&window, "help", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
b = find_widget<tbutton>(&window, "credits", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
b = find_widget<tbutton>(&window, "quit", false, false);
if (b) {
// b->set_visible(twidget::INVISIBLE);
}
}
#if defined(__APPLE__) && TARGET_OS_IPHONE
b = find_widget<tbutton>(&window, "editor", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
b = find_widget<tbutton>(&window, "help", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
b = find_widget<tbutton>(&window, "quit", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
#endif
b = find_widget<tbutton>(&window, "tutorial", false, false);
if (b) {
b->set_visible(twidget::INVISIBLE);
}
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "player", false)
, boost::bind(
&ttitle_screen::player
, this
, boost::ref(window)));
//.........这里部分代码省略.........
示例11: pre_show
void tduel::pre_show(CVideo& /*video*/, twindow& window)
{
// Override the user value, to make sure it's set properly.
window.set_click_dismiss(false);
// ***** ***** ***** ***** Set up the widgets ***** ***** ***** *****
window.canvas(1).set_variable("left_image", variant(left_.image(true)));
window.canvas(1).set_variable("right_image", variant(right_.image(true)));
window.canvas(1).set_variable("center_image", variant(""));
window.canvas(1).set_variable("hp_left", variant("misc/hp-blue.png"));
window.canvas(1).set_variable("hp_right", variant("misc/hp-red.png"));
window.canvas(1).set_variable("percentage", variant((hp_ * 100) / TOTAL_HP));
std::stringstream str;
tbutton* b = find_widget<tbutton>(&window, "endturn", false, false);
for (int i = 0; i < 4; i ++) {
b->canvas()[i].set_variable("image", variant("misc/ok.png"));
}
find_widget<tcontrol>(&window, "lname", false, false)->set_label(left_.name());
find_widget<tcontrol>(&window, "rname", false, false)->set_label(right_.name());
tcontrol* control = find_widget<tcontrol>(&window, "lforce", false, false);
str.str("");
str << setting_[0].force_ << "(" << hero::adaptability_str2(left_.skill_[hero_skill_hero]).c_str() << ")";
control->set_label(str.str());
control = find_widget<tcontrol>(&window, "rforce", false, false);
str.str("");
str << setting_[1].force_ << "(" << hero::adaptability_str2(right_.skill_[hero_skill_hero]).c_str() << ")";;
control->set_label(str.str());
endturn_ = find_widget<tbutton>(&window, "endturn", false, false);
connect_signal_mouse_left_click(
*endturn_
, boost::bind(
&tduel::end_turn
, this
, boost::ref(window)));
endturn_->set_sound_button_click("hatchet.wav");
lskill0_ = find_widget<ttoggle_button>(&window, "lskill0", false, false);
connect_signal_mouse_left_click(
*lskill0_
, boost::bind(
&tduel::on_deadfight
, this
, boost::ref(window)));
lskill1_ = find_widget<ttoggle_button>(&window, "lskill1", false, false);
connect_signal_mouse_left_click(
*lskill1_
, boost::bind(
&tduel::on_fightback
, this
, boost::ref(window)));
find_widget<ttoggle_button>(&window, "lturn0", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn0_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<tlabel>(&window, "turn0", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn0", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn0_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn1", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn1_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<tlabel>(&window, "turn1", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn1", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn1_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn2", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn2_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<tlabel>(&window, "turn2", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn2", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn2_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn3", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn3_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<tlabel>(&window, "turn3", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn3", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn3_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn4", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "lturn4_skill", false, false)->set_visible(twidget::INVISIBLE);
find_widget<tlabel>(&window, "turn4", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn4", false, false)->set_visible(twidget::INVISIBLE);
find_widget<ttoggle_button>(&window, "rturn4_skill", false, false)->set_visible(twidget::INVISIBLE);
reset_turn(window);
}
示例12: pre_show
/**
* @todo This function enables the wml markup for all items, but the interface
* is a bit hacky. Especially the fiddling in the internals of the listbox is
* ugly. There needs to be a clean interface to set whether a widget has a
* markup and what kind of markup. These fixes will be post 1.6.
*/
void twml_message_::pre_show(CVideo& /*video*/, twindow& window)
{
window.canvas(1).set_variable("portrait_image", variant(portrait_));
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
// Set the markup
tlabel& title = find_widget<tlabel>(&window, "title", false);
title.set_label(title_);
title.set_use_markup(true);
tcontrol& message = find_widget<tcontrol>(&window, "message", false);
message.set_label(message_);
message.set_use_markup(true);
// The message label might not always be a scroll_label but the capturing
// shouldn't hurt.
window.keyboard_capture(&message);
// Find the input box related fields.
tlabel& caption = find_widget<tlabel>(&window, "input_caption", false);
ttext_box& input = find_widget<ttext_box>(&window, "input", true);
if(has_input_) {
caption.set_label(input_caption_);
caption.set_use_markup(true);
input.set_value(*input_text_);
input.set_maximum_length(input_maximum_lenght_);
window.keyboard_capture(&input);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
} else {
caption.set_visible(twidget::INVISIBLE);
input.set_visible(twidget::INVISIBLE);
}
// Find the option list related fields.
tlistbox& options = find_widget<tlistbox>(&window, "input_list", true);
/*
* The options have some special markup:
* A line starting with a * means select that line.
* A line starting with a & means more special markup.
* - The part until the = is the name of an image.
* - The part until the second = is the first column.
* - The rest is the third column (the wiki only specifies two columns
* so only implement two of them).
*/
/**
* @todo This syntax looks like a bad hack, it would be nice to write
* a new syntax which doesn't use those hacks (also avoids the problem
* with special meanings for certain characters.
*/
if(!option_list_.empty()) {
std::map<std::string, string_map> data;
for(size_t i = 0; i < option_list_.size(); ++i) {
std::string icon;
std::string label = option_list_[i];
std::string description;
// Handle selection.
if(!label.empty() && label[0] == '*') {
// Number of items hasn't been increased yet so i is ok.
*chosen_option_ = i;
label.erase(0, 1);
}
// Handle the special case with an image.
std::string::size_type pos = label.find('=');
if (pos != std::string::npos && (label[0] == '&' || pos == 0)) {
if (pos) icon = label.substr(1, pos - 1);
label.erase(0, pos + 1);
}
// Search for an '=' symbol that is not inside markup.
std::string::size_type prev = 0;
bool open = false;
while ((pos = label.find('=', prev)) != std::string::npos) {
for (std::string::size_type i = prev; i != pos; ++i) {
switch (label[i]) {
case '<': open = true; break;
case '>': open = false; break;
}
}
if (!open) break;
prev = pos + 1;
}
if (pos != std::string::npos) {
description = label.substr(pos + 1);
label.erase(pos);
}
// Add the data.
data["icon"]["label"] = icon;
data["label"]["label"] = label;
data["label"]["use_markup"] = "true";
//.........这里部分代码省略.........
示例13: pre_show
void ttitle_screen::pre_show(twindow& window)
{
set_restore(false);
window.set_click_dismiss(false);
window.set_enter_disabled(true);
window.set_escape_disabled(true);
#ifdef DEBUG_TOOLTIP
window.connect_signal<event::SDL_MOUSE_MOTION>(
std::bind(debug_tooltip, std::ref(window), _3, _5),
event::tdispatcher::front_child);
#endif
/**** Set the version number ****/
if(tcontrol* control
= find_widget<tcontrol>(&window, "revision_number", false, false)) {
control->set_label(_("Version ") + game_config::revision);
}
window.canvas()[0].set_variable(
"revision_number",
variant(_("Version") + std::string(" ") + game_config::revision));
/**** Set the tip of the day ****/
tmulti_page& tip_pages = find_widget<tmulti_page>(&window, "tips", false);
std::vector<ttip> tips(settings::get_tips());
if(tips.empty()) {
WRN_CF << "There are not tips of day available." << std::endl;
}
for(const auto & tip : tips)
{
string_map widget;
std::map<std::string, string_map> page;
widget["label"] = tip.text();
widget["use_markup"] = "true";
page["tip"] = widget;
widget["label"] = tip.source();
widget["use_markup"] = "true";
page["source"] = widget;
tip_pages.add_page(page);
}
update_tip(window, true);
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "next_tip", false),
std::bind(&ttitle_screen::update_tip,
this,
std::ref(window),
true));
connect_signal_mouse_left_click(
find_widget<tbutton>(&window, "previous_tip", false),
std::bind(&ttitle_screen::update_tip,
this,
std::ref(window),
false));
if(game_config::images::game_title.empty()) {
ERR_CF << "No title image defined" << std::endl;
} else {
window.canvas()[0].set_variable(
"title_image", variant(game_config::images::game_title));
}
if(game_config::images::game_title_background.empty()) {
ERR_CF << "No title background image defined" << std::endl;
} else {
window.canvas()[0].set_variable(
"background_image",
variant(game_config::images::game_title_background));
}
/***** Logo *****/
find_widget<timage>(&window, "logo", false).set_image("misc/logo.png");
/***** About dialog button *****/
tbutton& about = find_widget<tbutton>(&window, "about", false);
connect_signal_mouse_left_click(
about,
std::bind(&tgame_version::display, std::ref(window.video())));
/***** Set the clock button. *****/
tbutton& clock = find_widget<tbutton>(&window, "clock", false);
clock.set_visible(show_debug_clock_button ? twidget::tvisible::visible
: twidget::tvisible::invisible);
connect_signal_mouse_left_click(
clock,
std::bind(&ttitle_screen::show_debug_clock_window,
this,
std::ref(window.video())));
}
示例14: pre_show
/**
* @todo This function enables the wml markup for all items, but the interface
* is a bit hacky. Especially the fiddling in the internals of the listbox is
* ugly. There needs to be a clean interface to set whether a widget has a
* markup and what kind of markup. These fixes will be post 1.6.
*/
void twml_message_::pre_show(twindow& window)
{
set_restore(true);
window.canvas(1).set_variable("portrait_image", variant(portrait_));
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
// Set the markup
tlabel& title = find_widget<tlabel>(&window, "title", false);
title.set_label(title_);
title.set_use_markup(true);
title.set_can_wrap(true);
tcontrol& message = find_widget<tcontrol>(&window, "message", false);
message.set_label(message_);
message.set_use_markup(true);
// The message label might not always be a scroll_label but the capturing
// shouldn't hurt.
window.keyboard_capture(&message);
// Find the input box related fields.
tlabel& caption = find_widget<tlabel>(&window, "input_caption", false);
ttext_box& input = find_widget<ttext_box>(&window, "input", true);
if(has_input_) {
caption.set_label(input_caption_);
caption.set_use_markup(true);
input.set_value(*input_text_);
input.set_maximum_length(input_maximum_length_);
window.keyboard_capture(&input);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
} else {
caption.set_visible(twidget::tvisible::invisible);
input.set_visible(twidget::tvisible::invisible);
}
// Find the option list related fields.
tlistbox& options = find_widget<tlistbox>(&window, "input_list", true);
if(!option_list_.empty()) {
std::map<std::string, string_map> data;
for(const twml_message_option& item : option_list_) {
// Add the data.
data["icon"]["label"] = item.image();
data["label"]["label"] = item.label();
data["label"]["use_markup"] = "true";
data["description"]["label"] = item.description();
data["description"]["use_markup"] = "true";
options.add_row(data);
}
// Avoid negative and 0 since item 0 is already selected.
if(*chosen_option_ > 0 && static_cast<size_t>(*chosen_option_)
< option_list_.size()) {
options.select_row(*chosen_option_);
}
if(!has_input_) {
window.keyboard_capture(&options);
window.set_click_dismiss(false);
window.set_escape_disabled(true);
} else {
window.add_to_keyboard_chain(&options);
// click_dismiss has been disabled due to the input.
}
} else {
options.set_visible(twidget::tvisible::invisible);
}
window.set_click_dismiss(!has_input_ && option_list_.empty());
}